clean up code
This commit is contained in:
parent
7b63f7f111
commit
e78f1507a8
10 changed files with 344 additions and 296 deletions
34
_install.php
34
_install.php
|
@ -11,30 +11,24 @@
|
|||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')){return;}
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$new_version = $core->plugins->moduleInfo('noodles','version');
|
||||
$new_version = $core->plugins->moduleInfo('noodles', 'version');
|
||||
$old_version = $core->getVersion('noodles');
|
||||
|
||||
if (version_compare($old_version,$new_version,'>=')) return;
|
||||
|
||||
try
|
||||
{
|
||||
if (version_compare(DC_VERSION,'2.2-beta','<'))
|
||||
{
|
||||
throw new Exception('noodles requires Dotclear 2.2');
|
||||
}
|
||||
|
||||
$core->blog->settings->addNamespace('noodles');
|
||||
|
||||
$core->blog->settings->noodles->put('noodles_active',false,'boolean','Enable extension',false,true);
|
||||
|
||||
$core->setVersion('noodles',$new_version);
|
||||
|
||||
return true;
|
||||
if (version_compare($old_version, $new_version, '>=')) {
|
||||
return null;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
try {
|
||||
$core->blog->settings->addNamespace('noodles');
|
||||
$core->blog->settings->noodles->put(
|
||||
'noodles_active', false, 'boolean', 'Enable extension', false, true
|
||||
);
|
||||
$core->setVersion('noodles', $new_version);
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
return false;
|
26
_prepend.php
26
_prepend.php
|
@ -11,16 +11,24 @@
|
|||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')){return;}
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
global $__autoload, $core;
|
||||
|
||||
$__autoload['noodlesImg'] = dirname(__FILE__).'/inc/lib.noodles.img.php';
|
||||
$__autoload['noodlesLibImagePath'] = dirname(__FILE__).'/inc/lib.image.path.php';
|
||||
$__autoload['noodlesImg'] = dirname(__FILE__) . '/inc/lib.noodles.img.php';
|
||||
$__autoload['noodlesLibImagePath'] = dirname(__FILE__) . '/inc/lib.image.path.php';
|
||||
|
||||
$core->blog->settings->addNamespace('noodles');
|
||||
|
||||
$core->url->register('noodlesmodule','noodles','^noodles/(.+)$',
|
||||
array('urlNoodles','noodles'));
|
||||
$core->url->register('noodlesservice','noodle','^noodle/$',
|
||||
array('urlNoodles','service'));
|
||||
$core->url->register(
|
||||
'noodlesmodule',
|
||||
'noodles',
|
||||
'^noodles/(.+)$',
|
||||
['urlNoodles', 'noodles']
|
||||
);
|
||||
$core->url->register(
|
||||
'noodlesservice',
|
||||
'noodle',
|
||||
'^noodle/$',
|
||||
['urlNoodles', 'service']
|
||||
);
|
155
_public.php
155
_public.php
|
@ -11,29 +11,34 @@
|
|||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')){return;}
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$core->blog->settings->noodles->noodles_active) return;
|
||||
if (!$core->blog->settings->noodles->noodles_active) {
|
||||
return null;
|
||||
}
|
||||
|
||||
include dirname(__FILE__).'/inc/_default_noodles.php';
|
||||
require_once dirname(__FILE__).'/inc/_noodles_functions.php';
|
||||
include dirname(__FILE__) . '/inc/_default_noodles.php';
|
||||
require_once dirname(__FILE__) . '/inc/_noodles_functions.php';
|
||||
|
||||
$core->addBehavior('publicHeadContent',
|
||||
array('publicNoodles','publicHeadContent'));
|
||||
$core->addBehavior('publicHeadContent', ['publicNoodles', 'publicHeadContent']);
|
||||
|
||||
$core->tpl->setPath($core->tpl->getPath(),dirname(__FILE__).'/default-templates');
|
||||
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__) . '/default-templates');
|
||||
|
||||
global $__noodles;
|
||||
$__noodles = noodles::decode($core->blog->settings->noodles->noodles_object);
|
||||
|
||||
if ($__noodles->isEmpty())
|
||||
if ($__noodles->isEmpty()) {
|
||||
$__noodles = $__default_noodles;
|
||||
}
|
||||
|
||||
//$GLOBALS['__noodles'] =& $__noodles;
|
||||
|
||||
foreach($__noodles->noodles() AS $noodle) {
|
||||
if ($noodle->active && $noodle->hasPhpCallback())
|
||||
if ($noodle->active && $noodle->hasPhpCallback()) {
|
||||
$noodle->phpCallback($core);
|
||||
}
|
||||
}
|
||||
|
||||
class publicNoodles
|
||||
|
@ -45,34 +50,33 @@ class publicNoodles
|
|||
$css = "\n";
|
||||
$targets = array();
|
||||
foreach($__noodles->noodles() AS $noodle) {
|
||||
|
||||
if (!$noodle->active || !$noodle->hasJsCallback()) continue;
|
||||
|
||||
$css .= '.noodles-'.$noodle->id().'{'.$noodle->css.'}'."\n";
|
||||
|
||||
if (!$noodle->active || !$noodle->hasJsCallback()) {
|
||||
continue;
|
||||
}
|
||||
$css .= '.noodles-' . $noodle->id() . '{' . $noodle->css . '}' . "\n";
|
||||
$targets[] =
|
||||
' $(\''.html::escapeJS($noodle->target).'\').noodles({'.
|
||||
'imgId:\''.html::escapeJS($noodle->id()).'\','.
|
||||
'imgPlace:\''.html::escapeJS($noodle->place).'\''.
|
||||
' $(\'' . html::escapeJS($noodle->target) . '\').noodles({' .
|
||||
'imgId:\'' . html::escapeJS($noodle->id()) . '\',' .
|
||||
'imgPlace:\'' . html::escapeJS($noodle->place) . '\'' .
|
||||
'});';
|
||||
}
|
||||
|
||||
if (empty($targets)) return;
|
||||
if (empty($targets)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
echo
|
||||
"\n<!-- CSS for noodles --> \n".
|
||||
'<style type="text/css">'.html::escapeHTML($css).'</style>'.
|
||||
"\n<!-- JS for noodles --> \n".
|
||||
"<script type=\"text/javascript\" src=\"".
|
||||
$core->blog->url.$core->url->getBase('noodlesmodule')."/js/jquery.noodles.js\"></script> \n".
|
||||
"<script type=\"text/javascript\"> \n".
|
||||
"//<![CDATA[\n".
|
||||
" \$(function(){if(!document.getElementById){return;} \n".
|
||||
" \$.fn.noodles.defaults.service_url = '".html::escapeJS($core->blog->url.$core->url->getBase('noodlesservice').'/')."'; \n".
|
||||
" \$.fn.noodles.defaults.service_func = '".html::escapeJS('getNoodle')."'; \n".
|
||||
implode("\n",$targets)."\n".
|
||||
"})\n".
|
||||
"\n//]]>\n".
|
||||
"\n<!-- CSS for noodles --> \n" .
|
||||
'<style type="text/css">' . html::escapeHTML($css) . '</style>' .
|
||||
"\n<!-- JS for noodles --> \n" .
|
||||
dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . "/js/jquery.noodles.js") .
|
||||
"<script type=\"text/javascript\"> \n" .
|
||||
"//<![CDATA[\n" .
|
||||
" \$(function(){if(!document.getElementById){return;} \n" .
|
||||
" \$.fn.noodles.defaults.service_url = '" . html::escapeJS($core->blog->url . $core->url->getBase('noodlesservice') . '/') . "'; \n" .
|
||||
" \$.fn.noodles.defaults.service_func = '" . html::escapeJS('getNoodle') . "'; \n" .
|
||||
implode("\n", $targets) ."\n" .
|
||||
"})\n" .
|
||||
"\n//]]>\n" .
|
||||
"</script>\n";
|
||||
}
|
||||
}
|
||||
|
@ -90,64 +94,60 @@ class urlNoodles extends dcUrlHandlers
|
|||
$i = !empty($_POST['noodleId']) ? $_POST['noodleId'] : null;
|
||||
$c = !empty($_POST['noodleContent']) ? $_POST['noodleContent'] : null;
|
||||
|
||||
if (!$core->blog->settings->noodles->noodles_active)
|
||||
{
|
||||
if (!$core->blog->settings->noodles->noodles_active) {
|
||||
$rsp->status = 'failed';
|
||||
$rsp->message(__('noodles is disabled on this blog'));
|
||||
echo $rsp->toXML(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($i === null || $c === null)
|
||||
{
|
||||
if ($i === null || $c === null) {
|
||||
$rsp->status = 'failed';
|
||||
$rsp->message(__('noodles failed because of missing informations'));
|
||||
echo $rsp->toXML(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
$__noodles = noodles::decode($core->blog->settings->noodles->noodles_object);
|
||||
|
||||
if ($__noodles->isEmpty())
|
||||
{
|
||||
if ($__noodles->isEmpty()) {
|
||||
$__noodles = $GLOBALS['__default_noodles'];
|
||||
}
|
||||
}
|
||||
catch(Excetpion $e)
|
||||
{
|
||||
} catch(Excetpion $e) {
|
||||
$rsp->status = 'failed';
|
||||
$rsp->message(__('Failed to load default noodles'));
|
||||
echo $rsp->toXML(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$__noodles->exists($i))
|
||||
{
|
||||
if (!$__noodles->exists($i)) {
|
||||
$rsp->status = 'failed';
|
||||
$rsp->message(__('Failed to load noodle'));
|
||||
echo $rsp->toXML(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
$m = $__noodles->{$i}->jsCallback($__noodles->{$i},$c);
|
||||
|
||||
$m = $__noodles->{$i}->jsCallback($__noodles->{$i}, $c);
|
||||
$s = $__noodles->{$i}->size;
|
||||
$r = $__noodles->{$i}->rating;
|
||||
$d = $core->blog->settings->noodles->noodles_image ?
|
||||
urlencode(noodlesLibImagePath::getUrl($core,'noodles')) : '';
|
||||
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : '';
|
||||
|
||||
if (!$m) $m = 'nobody@nowhere.tld';
|
||||
if (!$s) $s = 32;
|
||||
if (!$r) $r = 'g';
|
||||
if (!$m) {
|
||||
$m = 'nobody@nowhere.tld';
|
||||
}
|
||||
if (!$s) {
|
||||
$s = 32;
|
||||
}
|
||||
if (!$r) {
|
||||
$r = 'g';
|
||||
}
|
||||
|
||||
$m = mb_strtolower($m);
|
||||
$m = md5($m);
|
||||
|
||||
$im = new xmlTag('noodle');
|
||||
$im->size = $s;
|
||||
$im->src = 'http://www.gravatar.com/avatar/'.$m.'?s='.$s.'&r='.$r.'&d='.$d;
|
||||
$im->src = 'http://www.gravatar.com/avatar/' . $m . '?s=' . $s . '&r=' . $r . '&d=' . $d;
|
||||
$rsp->insertNode($im);
|
||||
|
||||
$rsp->status = 'ok';
|
||||
|
@ -159,44 +159,41 @@ class urlNoodles extends dcUrlHandlers
|
|||
{
|
||||
global $core;
|
||||
|
||||
if (!$core->blog->settings->noodles->noodles_active)
|
||||
{
|
||||
if (!$core->blog->settings->noodles->noodles_active) {
|
||||
self::p404();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preg_match('#^(.*?)$#',$args,$m))
|
||||
{
|
||||
if (!preg_match('#^(.*?)$#', $args, $m)) {
|
||||
self::p404();
|
||||
return;
|
||||
}
|
||||
|
||||
$f = $m[1];
|
||||
|
||||
if (!($f = self::searchTplFiles($f)))
|
||||
{
|
||||
if (!($f = self::searchTplFiles($f))) {
|
||||
self::p404();
|
||||
return;
|
||||
}
|
||||
|
||||
$allowed_types = array('png','jpg','jpeg','gif','css','js','swf');
|
||||
if (!in_array(files::getExtension($f),$allowed_types))
|
||||
{
|
||||
$allowed_types = ['png', 'jpg', 'jpeg', 'gif', 'css', 'js', 'swf'];
|
||||
if (!in_array(files::getExtension($f), $allowed_types)) {
|
||||
self::p404();
|
||||
return;
|
||||
}
|
||||
$type = files::getMimeType($f);
|
||||
|
||||
header('Content-Type: '.$type.'; charset=UTF-8');
|
||||
header('Content-Length: '.filesize($f));
|
||||
header('Content-Type: ' . $type . '; charset=UTF-8');
|
||||
header('Content-Length: ' . filesize($f));
|
||||
|
||||
if ($type != "text/css" || $core->blog->settings->system->url_scan == 'path_info')
|
||||
{
|
||||
if ($type != "text/css" || $core->blog->settings->system->url_scan == 'path_info') {
|
||||
readfile($f);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo preg_replace('#url\((?!(http:)|/)#','url('.$core->blog->url.$core->url->getBase('noodlesmodule').'/',file_get_contents($f));
|
||||
} else {
|
||||
echo preg_replace(
|
||||
'#url\((?!(http:)|/)#',
|
||||
'url(' . $core->blog->url . $core->url->getBase('noodlesmodule') . '/',
|
||||
file_get_contents($f)
|
||||
);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
@ -204,21 +201,17 @@ class urlNoodles extends dcUrlHandlers
|
|||
# Search noodles files like JS, CSS in default-templates subdirectories
|
||||
private static function searchTplFiles($file)
|
||||
{
|
||||
if (strstr($file,"..") !== false)
|
||||
{
|
||||
if (strstr($file,"..") !== false) {
|
||||
return false;
|
||||
}
|
||||
$paths = $GLOBALS['core']->tpl->getPath();
|
||||
|
||||
foreach($paths as $path)
|
||||
{
|
||||
if (preg_match('/tpl(\/|)$/',$path))
|
||||
{
|
||||
$path = path::real($path.'/..');
|
||||
foreach($paths as $path) {
|
||||
if (preg_match('/tpl(\/|)$/',$path)) {
|
||||
$path = path::real($path . '/..');
|
||||
}
|
||||
if (file_exists($path.'/'.$file))
|
||||
{
|
||||
return $path.'/'.$file;
|
||||
if (file_exists($path . '/' . $file)) {
|
||||
return $path . '/' . $file;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')){return;}
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->addUserAction(
|
||||
/* type */ 'settings',
|
||||
|
@ -31,12 +33,12 @@ $this->addDirectAction(
|
|||
/* type */ 'settings',
|
||||
/* action */ 'delete_all',
|
||||
/* ns */ 'noodles',
|
||||
/* description */ sprintf(__('delete all %s settings'),'noodles')
|
||||
/* description */ sprintf(__('delete all %s settings'), 'noodles')
|
||||
);
|
||||
|
||||
$this->addDirectAction(
|
||||
/* type */ 'plugins',
|
||||
/* action */ 'delete',
|
||||
/* ns */ 'noodles',
|
||||
/* description */ sprintf(__('delete %s plugin files'),'noodles')
|
||||
/* description */ sprintf(__('delete %s plugin files'), 'noodles')
|
||||
);
|
12
dcstore.xml
Normal file
12
dcstore.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="noodles">
|
||||
<name>Noodles</name>
|
||||
<version>0.6.1</version>
|
||||
<author>Jean-Christian Denis and contributors</author>
|
||||
<desc>Add users gravatars everywhere</desc>
|
||||
<file>https://github.com/JcDenis/noodles/releases/download/v0.6.1/plugin-noodles.zip</file>
|
||||
<da:dcmin>2.19</da:dcmin>
|
||||
<da:details>http://plugins.dotaddict.org/dc2/details/noodles</da:details>
|
||||
<da:support>https://github.com/JcDenis/noodles</da:support>
|
||||
</module>
|
||||
</modules>
|
|
@ -1,14 +1,3 @@
|
|||
/* -- BEGIN LICENSE BLOCK ----------------------------------
|
||||
* This file is part of noodles, a plugin for Dotclear 2.
|
||||
*
|
||||
* Copyright (c) 2009 JC Denis and contributors
|
||||
* jcdenis@gdwd.com
|
||||
*
|
||||
* Licensed under the GPL version 2.0 license.
|
||||
* A copy of this license is available in LICENSE file or at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* -- END LICENSE BLOCK ------------------------------------*/
|
||||
|
||||
;if(window.jQuery) (function($) {
|
||||
|
||||
$.fn.noodles = function(options) {
|
||||
|
|
|
@ -11,85 +11,96 @@
|
|||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')){return;}
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
require dirname(__FILE__).'/class.noodles.php';
|
||||
require dirname(__FILE__) . '/class.noodles.php';
|
||||
|
||||
global $__default_noodles;
|
||||
$__default_noodles = new noodles();
|
||||
$__default_noodles = new noodles;
|
||||
|
||||
# Posts (by public behavior)
|
||||
$__default_noodles->add('posts',__('Entries'),'',array('othersNoodles','publicPosts'));
|
||||
$__default_noodles->posts->size = 48;
|
||||
$__default_noodles->posts->css = 'float:right;margin:4px;';
|
||||
$__default_noodles
|
||||
->add('posts', __('Entries'), '', ['othersNoodles', 'publicPosts'])
|
||||
->size(48)
|
||||
->css('float:right;margin:4px;');
|
||||
|
||||
# Comments (by public behavior)
|
||||
$__default_noodles->add('comments',__('Comments'),'',array('othersNoodles','publicComments'));
|
||||
$__default_noodles->comments->active = true;
|
||||
$__default_noodles->comments->size = 48;
|
||||
$__default_noodles->comments->css = 'float:left;margin:4px;';
|
||||
$__default_noodles
|
||||
->add('comments', __('Comments'), '', ['othersNoodles', 'publicComments'])
|
||||
->active(true)
|
||||
->size(48)
|
||||
->css('float:left;margin:4px;');
|
||||
|
||||
# Block with post title link (like homepage posts)
|
||||
$__default_noodles->add('titlesposts',__('Entries titles'),array('genericNoodles','postURL'));
|
||||
$__default_noodles->titlesposts->target = '.post-title a';
|
||||
$__default_noodles->titlesposts->css = 'margin-right:2px;';
|
||||
$__default_noodles
|
||||
->add('titlesposts', __('Entries titles'), ['genericNoodles', 'postURL'])
|
||||
->target('.post-title a')
|
||||
->css('margin-right:2px;');
|
||||
|
||||
if ($core->plugins->moduleExists('widgets')) {
|
||||
|
||||
# Widget Selected entries
|
||||
$__default_noodles->add('bestof',__('Selected entries'),array('genericNoodles','postURL'));
|
||||
$__default_noodles->bestof->target = '.selected li a';
|
||||
$__default_noodles->bestof->css = 'margin-right:2px;';
|
||||
$__default_noodles
|
||||
->add('bestof', __('Selected entries'), ['genericNoodles', 'postURL'])
|
||||
->target('.selected li a')
|
||||
->css('margin-right:2px;');
|
||||
|
||||
# Widget Last entries
|
||||
$__default_noodles->add('lastposts',__('Last entries'),array('genericNoodles','postURL'));
|
||||
$__default_noodles->lastposts->target = '.lastposts li a';
|
||||
$__default_noodles->lastposts->css = 'margin-right:2px;';
|
||||
$__default_noodles
|
||||
->add('lastposts', __('Last entries'), ['genericNoodles', 'postURL'])
|
||||
->target('.lastposts li a')
|
||||
->css('margin-right:2px;');
|
||||
|
||||
# Widget Last comments
|
||||
$__default_noodles->add('lastcomments',__('Last comments'),array('widgetsNoodles','lastcomments'));
|
||||
$__default_noodles->lastcomments->active = true;
|
||||
$__default_noodles->lastcomments->target = '.lastcomments li a';
|
||||
$__default_noodles->lastcomments->css = 'margin-right:2px;';
|
||||
$__default_noodles
|
||||
->add('lastcomments', __('Last comments'), ['widgetsNoodles', 'lastcomments'])
|
||||
->active(true)
|
||||
->target('.lastcomments li a')
|
||||
->css('margin-right:2px;');
|
||||
}
|
||||
|
||||
# Plugin auhtorMode
|
||||
if ($core->plugins->moduleExists('authorMode')
|
||||
&& $core->blog->settings->authormode->authormode_active) {
|
||||
&& $core->blog->settings->authormode->authormode_active
|
||||
) {
|
||||
$__default_noodles
|
||||
->add('authorswidget', __('Authors widget'), ['authormodeNoodles', 'authors'])
|
||||
->target('#authors ul li a')
|
||||
->css('margin-right:2px;');
|
||||
|
||||
$__default_noodles->add('authorswidget',__('Authors widget'),array('authormodeNoodles','authors'));
|
||||
$__default_noodles->authorswidget->target = '#authors ul li a';
|
||||
$__default_noodles->authorswidget->css = 'margin-right:2px;';
|
||||
$__default_noodles
|
||||
->add('author', __('Author'), '', ['authormodeNoodles', 'author'])
|
||||
->active(true)
|
||||
->size(48)
|
||||
->target('.dc-author #content-info h2')
|
||||
->css('clear:left; float:left;margin-right:2px;');
|
||||
|
||||
$__default_noodles->add('author',__('Author'),'',array('authormodeNoodles','author'));
|
||||
$__default_noodles->author->active = true;
|
||||
$__default_noodles->author->size = 48;
|
||||
$__default_noodles->author->target = '.dc-author #content-info h2';
|
||||
$__default_noodles->author->css = 'clear:left; float:left;margin-right:2px;';
|
||||
|
||||
$__default_noodles->add('authors',__('Authors'),array('authormodeNoodles','authors'));
|
||||
$__default_noodles->authors->active = true;
|
||||
$__default_noodles->authors->size = 32;
|
||||
$__default_noodles->authors->target = '.dc-authors .author-info h2 a';
|
||||
$__default_noodles->authors->css = 'clear:left; float:left; margin:4px;';
|
||||
$__default_noodles
|
||||
->add('authors', __('Authors'), ['authormodeNoodles', 'authors'])
|
||||
->active(true)
|
||||
->size(32)
|
||||
->target('.dc-authors .author-info h2 a')
|
||||
->css('clear:left; float:left; margin:4px;');
|
||||
}
|
||||
|
||||
# Plugin rateIt
|
||||
if ($core->plugins->moduleExists('rateIt')
|
||||
&& $core->blog->settings->rateit->rateit_active) {
|
||||
|
||||
$__default_noodles->add('rateitpostsrank',__('Top rated entries'),array('genericNoodles','postURL'));
|
||||
$__default_noodles->rateitpostsrank->target = '.rateitpostsrank.rateittypepost ul li a'; // Only "post" type
|
||||
$__default_noodles->rateitpostsrank->css = 'margin-right:2px;';
|
||||
&& $core->blog->settings->rateit->rateit_active
|
||||
) {
|
||||
$__default_noodles
|
||||
->add('rateitpostsrank', __('Top rated entries'), ['genericNoodles', 'postURL'])
|
||||
->target('.rateitpostsrank.rateittypepost ul li a') // Only "post" type
|
||||
->css('margin-right:2px;');
|
||||
}
|
||||
|
||||
# Plugin lastpostsExtend
|
||||
if ($core->plugins->moduleExists('lastpostsExtend')) {
|
||||
|
||||
$__default_noodles->add('lastpostsextend',__('Last entries (extend)'),array('genericNoodles','postURL'));
|
||||
$__default_noodles->lastpostsextend->target = '.lastpostsextend ul li a';
|
||||
$__default_noodles->lastpostsextend->css = 'margin-right:2px;';
|
||||
$__default_noodles
|
||||
->add('lastpostsextend', __('Last entries (extend)'), ['genericNoodles', 'postURL'])
|
||||
->target('.lastpostsextend ul li a')
|
||||
->css('margin-right:2px;');
|
||||
}
|
||||
|
||||
# --BEHAVIOR-- initDefaultNoodles
|
||||
$core->callBehavior('initDefaultNoodles',$__default_noodles);
|
||||
$core->callBehavior('initDefaultNoodles', $__default_noodles);
|
|
@ -11,28 +11,26 @@
|
|||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')){return;}
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
class genericNoodles
|
||||
{
|
||||
public static function postURL($noodle,$content='')
|
||||
public static function postURL($noodle, $content = '')
|
||||
{
|
||||
global $core;
|
||||
|
||||
$types = $core->getPostTypes();
|
||||
$reg = '@^'.str_replace('%s','(.*?)',
|
||||
preg_quote($core->blog->url.$types['post']['public_url'])).'$@';
|
||||
|
||||
$ok = preg_match($reg,$content,$m);
|
||||
|
||||
if (!$ok || !$m[1]) return '';
|
||||
|
||||
$rs = $core->blog->getPosts(
|
||||
array('no_content'=>1,'post_url'=>urldecode($m[1]),'limit'=>1)
|
||||
);
|
||||
|
||||
if ($rs->isEmpty()) return '';
|
||||
|
||||
$reg = '@^' . str_replace('%s', '(.*?)', preg_quote($core->blog->url . $types['post']['public_url'])) . '$@';
|
||||
$ok = preg_match($reg, $content, $m);
|
||||
if (!$ok || !$m[1]){
|
||||
return '';
|
||||
}
|
||||
$rs = $core->blog->getPosts(['no_content' => 1, 'post_url' => urldecode($m[1]), 'limit' => 1]);
|
||||
if ($rs->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
return $rs->user_email;
|
||||
}
|
||||
}
|
||||
|
@ -40,14 +38,15 @@ class genericNoodles
|
|||
# Miscellaneous
|
||||
class othersNoodles
|
||||
{
|
||||
public static function publicPosts($core,$noodle)
|
||||
public static function publicPosts($core, $noodle)
|
||||
{
|
||||
if (!$noodle->active) return;
|
||||
|
||||
if (!$noodle->active) {
|
||||
return null;
|
||||
}
|
||||
$bhv = $noodle->place == 'prepend' || $noodle->place == 'before' ?
|
||||
'publicEntryBeforeContent' : 'publicEntryAfterContent';
|
||||
|
||||
$core->addBehavior($bhv,array('othersNoodles','publicEntryContent'));
|
||||
$core->addBehavior($bhv, ['othersNoodles', 'publicEntryContent']);
|
||||
}
|
||||
|
||||
public static function publicEntryContent()
|
||||
|
@ -59,22 +58,24 @@ class othersNoodles
|
|||
$s = $__noodles->posts->size;
|
||||
$r = $__noodles->posts->rating;
|
||||
$d = $core->blog->settings->noodles->noodles_image ?
|
||||
urlencode(noodlesLibImagePath::getUrl($core,'noodles')) : '';
|
||||
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : '';
|
||||
|
||||
echo
|
||||
'<img class="noodles-posts" style="width:'.$s.'px;height:'.$s.'px;'.$c.'"'.
|
||||
'src="http://www.gravatar.com/avatar/'.md5($m).
|
||||
'?s='.$s.'&r='.$r.'&d='.$d.'" alt="" />';
|
||||
'<img class="noodles-posts" style="width:' . $s . 'px;height:' . $s . 'px;' . $c . '"' .
|
||||
'src="http://www.gravatar.com/avatar/' . md5($m) .
|
||||
'?s=' . $s . '&r=' . $r . '&d=' . $d . '" alt="" />';
|
||||
}
|
||||
|
||||
public static function publicComments($core,$noodle)
|
||||
public static function publicComments($core, $noodle)
|
||||
{
|
||||
if (!$noodle->active) return;
|
||||
if (!$noodle->active) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$bhv = $noodle->place == 'prepend' || $noodle->place == 'before' ?
|
||||
'publicCommentBeforeContent' : 'publicCommentAfterContent';
|
||||
|
||||
$core->addBehavior($bhv,array('othersNoodles','publicCommentContent'));
|
||||
$core->addBehavior($bhv, ['othersNoodles', 'publicCommentContent']);
|
||||
}
|
||||
|
||||
public static function publicCommentContent()
|
||||
|
@ -86,32 +87,30 @@ class othersNoodles
|
|||
$s = $__noodles->comments->size;
|
||||
$r = $__noodles->comments->rating;
|
||||
$d = $core->blog->settings->noodles->noodles_image ?
|
||||
urlencode(noodlesLibImagePath::getUrl($core,'noodles')) : '';
|
||||
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : '';
|
||||
|
||||
echo
|
||||
'<img class="noodles-comments" style="width:'.$s.'px;height:'.$s.'px;'.$c.'"'.
|
||||
'src="http://www.gravatar.com/avatar/'.md5($m).
|
||||
'?s='.$s.'&r='.$r.'&d='.$d.'" alt="" />';
|
||||
'<img class="noodles-comments" style="width:' . $s . 'px;height:' . $s . 'px;' . $c . '"' .
|
||||
'src="http://www.gravatar.com/avatar/' . md5($m) .
|
||||
'?s=' . $s . '&r=' . $r .'&d=' . $d . '" alt="" />';
|
||||
}
|
||||
}
|
||||
|
||||
# Plugin Widgets
|
||||
class widgetsNoodles
|
||||
{
|
||||
public static function lastcomments($noodle,$content='')
|
||||
public static function lastcomments($noodle, $content = '')
|
||||
{
|
||||
global $core;
|
||||
|
||||
$ok = preg_match('@\#c([0-9]+)$@',urldecode($content),$m);
|
||||
|
||||
if (!$ok || !$m[1]) return '';
|
||||
|
||||
$rs = $core->blog->getComments(
|
||||
array('no_content'=>1,'comment_id'=>$m[1],'limit'=>1)
|
||||
);
|
||||
|
||||
if (!$rs->isEmpty()) return $rs->comment_email;
|
||||
|
||||
$ok = preg_match('@\#c([0-9]+)$@', urldecode($content), $m);
|
||||
if (!$ok || !$m[1]) {
|
||||
return '' null;
|
||||
}
|
||||
$rs = $core->blog->getComments(['no_content' => 1, 'comment_id' => $m[1], 'limit' => 1]);
|
||||
if (!$rs->isEmpty()) {
|
||||
return $rs->comment_email;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@ -119,34 +118,35 @@ class widgetsNoodles
|
|||
# Plugin authorMode
|
||||
class authormodeNoodles
|
||||
{
|
||||
public static function authors($noodle,$content='')
|
||||
public static function authors($noodle, $content = '')
|
||||
{
|
||||
global $core;
|
||||
$ok = preg_match('@\/([^\/]*?)$@',$content,$m);
|
||||
|
||||
if (!$ok || !$m[1]) return '';
|
||||
|
||||
$ok = preg_match('@\/([^\/]*?)$@', $content, $m);
|
||||
if (!$ok || !$m[1]) {
|
||||
return '';
|
||||
}
|
||||
$rs = $core->getUser($m[1]);
|
||||
|
||||
if ($rs->isEmpty()) return '';
|
||||
|
||||
if ($rs->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
return $rs->user_email;
|
||||
}
|
||||
|
||||
public static function author($core,$noodle)
|
||||
public static function author($core, $noodle)
|
||||
{
|
||||
if ($noodle->active)
|
||||
{
|
||||
$core->addBehavior('publicHeadContent',
|
||||
array('authormodeNoodles','publicHeadContent'));
|
||||
if ($noodle->active) {
|
||||
$core->addBehavior('publicHeadContent', ['authormodeNoodles', 'publicHeadContent']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function publicHeadContent()
|
||||
{
|
||||
global $core,$_ctx,$__noodles;
|
||||
global $core, $_ctx, $__noodles;
|
||||
|
||||
if ($_ctx->current_tpl != 'author.html') return;
|
||||
if ($_ctx->current_tpl != 'author.html') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$id = $_ctx->users->user_id;
|
||||
$u = $core->getUser($id);
|
||||
|
@ -158,15 +158,15 @@ class authormodeNoodles
|
|||
urlencode(noodlesLibImagePath::getUrl($core,'noodles')) : '';
|
||||
|
||||
echo
|
||||
'<script type="text/javascript">'."\n".
|
||||
"//<![CDATA[\n".
|
||||
"$(function(){if(!document.getElementById){return;}\n".
|
||||
"$('".$__noodles->author->target."').".$__noodles->author->place."('".
|
||||
'<img class="noodles-comments" style="width:'.$s.'px;height:'.$s.'px;'.$c.'"'.
|
||||
'src="http://www.gravatar.com/avatar/'.md5($m).
|
||||
'?s='.$s.'&r='.$r.'&d='.$d.'" alt="" />'.
|
||||
"');});".
|
||||
"\n//]]>\n".
|
||||
'<script type="text/javascript">' . "\n" .
|
||||
"//<![CDATA[\n" .
|
||||
"$(function(){if(!document.getElementById){return;}\n" .
|
||||
"$('" . $__noodles->author->target . "')." . $__noodles->author->place . "('" .
|
||||
'<img class="noodles-comments" style="width:' . $s . 'px;height:' . $s . 'px;' . $c .'"' .
|
||||
'src="http://www.gravatar.com/avatar/' . md5($m) .
|
||||
'?s=' . $s . '&r=' . $r . '&d=' . $d . '" alt="" />' .
|
||||
"');});" .
|
||||
"\n//]]>\n" .
|
||||
"</script>\n";
|
||||
}
|
||||
}
|
|
@ -11,16 +11,20 @@
|
|||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')){return;}
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
class noodles
|
||||
{
|
||||
private $noodles = array();
|
||||
private $noodles = [];
|
||||
|
||||
public static function decode($s)
|
||||
{
|
||||
$o = @unserialize(base64_decode($s));
|
||||
if ($o instanceof self) return $o;
|
||||
if ($o instanceof self) {
|
||||
return $o;
|
||||
}
|
||||
return new self;
|
||||
}
|
||||
|
||||
|
@ -29,9 +33,10 @@ class noodles
|
|||
return base64_encode(serialize($this));
|
||||
}
|
||||
|
||||
public function add($id,$name,$js_callback,$php_callback=null)
|
||||
public function add($id, $name, $js_callback, $php_callback = null)
|
||||
{
|
||||
$this->noodles[$id] = new noodle($id,$name,$js_callback,$php_callback);
|
||||
$this->noodles[$id] = new noodle($id, $name, $js_callback, $php_callback);
|
||||
return $this->noodles[$id];
|
||||
}
|
||||
|
||||
public function __get($id)
|
||||
|
@ -39,7 +44,7 @@ class noodles
|
|||
return isset($this->noodles[$id]) ? $this->noodles[$id] : null;
|
||||
}
|
||||
|
||||
public function __set($id,$noodle)
|
||||
public function __set($id, $noodle)
|
||||
{
|
||||
return $this->noodles[$id] = $noodle;
|
||||
}
|
||||
|
@ -66,15 +71,15 @@ class noodle
|
|||
private $name;
|
||||
private $js_callback;
|
||||
private $php_callback;
|
||||
private $settings = array(
|
||||
private $settings = [
|
||||
'active' => 0,
|
||||
'rating' => 'g',
|
||||
'size' => 16,
|
||||
'target' => '',
|
||||
'place' => 'prepend'
|
||||
);
|
||||
];
|
||||
|
||||
public function __construct($id,$name,$js_callback,$php_callback=null)
|
||||
public function __construct($id, $name, $js_callback, $php_callback = null)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
|
@ -92,10 +97,12 @@ class noodle
|
|||
return $this->name;
|
||||
}
|
||||
|
||||
public function jsCallback($g,$content='')
|
||||
public function jsCallback($g, $content = '')
|
||||
{
|
||||
if (!is_callable($this->js_callback)) return null;
|
||||
return call_user_func($this->js_callback,$g,$content);
|
||||
if (!is_callable($this->js_callback)) {
|
||||
return null;
|
||||
}
|
||||
return call_user_func($this->js_callback, $g, $content);
|
||||
}
|
||||
|
||||
public function hasJsCallback()
|
||||
|
@ -105,8 +112,10 @@ class noodle
|
|||
|
||||
public function phpCallback($core)
|
||||
{
|
||||
if (!is_callable($this->php_callback)) return null;
|
||||
return call_user_func($this->php_callback,$core,$this);
|
||||
if (!is_callable($this->php_callback)) {
|
||||
return null;
|
||||
}
|
||||
return call_user_func($this->php_callback, $core, $this);
|
||||
}
|
||||
|
||||
public function hasPhpCallback()
|
||||
|
@ -114,44 +123,69 @@ class noodle
|
|||
return !empty($this->php_callback);
|
||||
}
|
||||
|
||||
public function set($type,$value)
|
||||
public function set($type, $value)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'active':
|
||||
$this->settings['active'] = abs((integer) $value);
|
||||
$this->settings['active'] = abs((integer) $value);
|
||||
break;
|
||||
|
||||
case 'rating':
|
||||
$this->settings['rating'] = in_array($value,array('g','pg','r','x')) ?
|
||||
$value : 'g';
|
||||
$this->settings['rating'] = in_array($value, ['g', 'pg', 'r', 'x']) ? $value : 'g';
|
||||
break;
|
||||
|
||||
case 'size':
|
||||
$this->settings['size'] =
|
||||
in_array($value,array(16,24,32,48,56,64,92,128,256)) ?
|
||||
$value : 16;
|
||||
$this->settings['size'] = in_array($value, [16, 24, 32, 48, 56, 64, 92, 128, 256]) ? $value : 16;
|
||||
break;
|
||||
|
||||
case 'css':
|
||||
$this->settings['css'] = (string) $value;
|
||||
$this->settings['css'] = (string) $value;
|
||||
break;
|
||||
|
||||
case 'target':
|
||||
$this->settings['target'] = (string) $value;
|
||||
$this->settings['target'] = (string) $value;
|
||||
break;
|
||||
|
||||
case 'place':
|
||||
$this->settings['place'] =
|
||||
in_array($value,array('append','prepend','before','after')) ?
|
||||
$value : 'prepend';
|
||||
$this->settings['place'] = in_array($value, ['append', 'prepend', 'before', 'after']) ? $value : 'prepend';
|
||||
break;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __set($type,$value)
|
||||
public function active($value)
|
||||
{
|
||||
$this->set($type,$value);
|
||||
return $this->set('active', $value);
|
||||
}
|
||||
|
||||
public function rating($value)
|
||||
{
|
||||
return $this->set('rating', $value);
|
||||
}
|
||||
|
||||
public function size($value)
|
||||
{
|
||||
return $this->set('size', $value);
|
||||
}
|
||||
|
||||
public function css($value)
|
||||
{
|
||||
return $this->set('css', $value);
|
||||
}
|
||||
|
||||
public function target($value)
|
||||
{
|
||||
return $this->set('target', $value);
|
||||
}
|
||||
|
||||
public function place($value)
|
||||
{
|
||||
return $this->set('place', $value);
|
||||
}
|
||||
|
||||
public function __set($type, $value)
|
||||
{
|
||||
$this->set($type, $value);
|
||||
}
|
||||
|
||||
public function get($type)
|
||||
|
|
|
@ -11,40 +11,45 @@
|
|||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
class noodlesLibImagePath
|
||||
{
|
||||
public static $version = '1.1';
|
||||
|
||||
public static function getArray($core,$m='')
|
||||
public static function getArray($core, $m = '')
|
||||
{
|
||||
if (!$core->plugins->moduleExists($m)
|
||||
|| !$core->url->getBase($m.'module')) {
|
||||
return array(
|
||||
'theme'=>array('dir'=>null,'url'=>null),
|
||||
'public'=>array('dir'=>null,'url'=>null),
|
||||
'module'=>array('dir'=>null,'url'=>null),
|
||||
);
|
||||
|| !$core->url->getBase($m . 'module')
|
||||
) {
|
||||
return [
|
||||
'theme' => ['dir' = >null, 'url' = >null],
|
||||
'public' => ['dir' => null, 'url' => null],
|
||||
'module' => ['dir' => null, 'url' => null],
|
||||
};
|
||||
}
|
||||
|
||||
return array(
|
||||
'theme' => array(
|
||||
'dir' => $core->blog->themes_path.'/'.$core->blog->settings->system->theme.'/img/'.$m.'-default-image.png',
|
||||
'url' => $core->blog->settings->system->themes_url.$core->blog->settings->system->theme.'/img/'.$m.'-default-image.png'
|
||||
),
|
||||
'public' => array(
|
||||
'dir' => $core->blog->public_path.'/'.$m.'-default-image.png',
|
||||
'url' => $core->blog->host.path::clean($core->blog->settings->system->public_url).'/'.$m.'-default-image.png'
|
||||
),
|
||||
'module' => array(
|
||||
'dir' => $core->plugins->moduleRoot($m).'/default-templates/img/'.$m.'-default-image.png',
|
||||
'url' => $core->blog->url.$core->url->getBase($m.'module').'/img/'.$m.'-default-image.png'
|
||||
)
|
||||
);
|
||||
return [
|
||||
'theme' => [
|
||||
'dir' => $core->blog->themes_path . '/' . $core->blog->settings->system->theme . '/img/' . $m . '-default-image.png',
|
||||
'url' => $core->blog->settings->system->themes_url . $core->blog->settings->system->theme . '/img/' . $m . '-default-image.png'
|
||||
],
|
||||
'public' => [
|
||||
'dir' => $core->blog->public_path . '/' . $m . '-default-image.png',
|
||||
'url' => $core->blog->host . path::clean($core->blog->settings->system->public_url) . '/' . $m . '-default-image.png'
|
||||
],
|
||||
'module' => [
|
||||
'dir' => $core->plugins->moduleRoot($m) . '/default-templates/img/' . $m . '-default-image.png',
|
||||
'url' => $core->blog->url . $core->url->getBase($m . 'module') . '/img/' . $m . '-default-image.png'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public static function getUrl($core,$m='')
|
||||
public static function getUrl($core, $m = '')
|
||||
{
|
||||
$files = self::getArray($core,$m);
|
||||
$files = self::getArray($core, $m);
|
||||
foreach($files as $k => $file) {
|
||||
if (file_exists($files[$k]['dir']))
|
||||
return $files[$k]['url'];
|
||||
|
@ -52,9 +57,9 @@ class noodlesLibImagePath
|
|||
return null;
|
||||
}
|
||||
|
||||
public static function getPath($core,$m='')
|
||||
public static function getPath($core, $m = '')
|
||||
{
|
||||
$files = self::getArray($core,$m);
|
||||
$files = self::getArray($core, $m);
|
||||
foreach($files as $k => $file) {
|
||||
if (file_exists($files[$k]['dir']))
|
||||
return $files[$k]['dir'];
|
||||
|
@ -62,13 +67,13 @@ class noodlesLibImagePath
|
|||
return null;
|
||||
}
|
||||
|
||||
public static function getSize($core,$m='')
|
||||
public static function getSize($core, $m = '')
|
||||
{
|
||||
if (!($img = self::getPath($core,$m)))
|
||||
return array('w'=>16,'h'=>16);
|
||||
if (!($img = self::getPath($core, $m)))
|
||||
return ['w' => 16, 'h' => 16];
|
||||
else {
|
||||
$info = getimagesize($img);
|
||||
return array('w'=>$info[0],'h'=>floor($info[1] /3));
|
||||
return ['w' => $info[0], 'h' => floor($info[1] /3)];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue