diff --git a/_admin.php b/_admin.php index f388a34..9521971 100644 --- a/_admin.php +++ b/_admin.php @@ -10,7 +10,6 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ - if (!defined('DC_CONTEXT_ADMIN')) { return; } diff --git a/_define.php b/_define.php index 678f850..d76943d 100644 --- a/_define.php +++ b/_define.php @@ -10,7 +10,6 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ - $this->registerModule( 'Noodles', 'Add users gravatars everywhere', @@ -24,7 +23,7 @@ $this->registerModule( 'details' => 'http://plugins.dotaddict.org/dc2/details/noodles', 'repository' => 'https://raw.githubusercontent.com/JcDenis/noodles/master/dcstore.xml', 'settings' => [ - 'self' => '' + 'self' => '' ] ] ); \ No newline at end of file diff --git a/_install.php b/_install.php index c545581..2dbf955 100644 --- a/_install.php +++ b/_install.php @@ -10,7 +10,6 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ - if (!defined('DC_CONTEXT_ADMIN')) { return null; } @@ -21,23 +20,46 @@ $old_version = $core->getVersion('noodles'); if (version_compare($old_version, $new_version, '>=')) { return null; } + try { $core->blog->settings->addNamespace('noodles'); $core->blog->settings->noodles->put( - 'noodles_active', false, 'boolean', 'Enable extension', false, true + 'noodles_active', + false, + 'boolean', + 'Enable extension', + false, + true ); $core->blog->settings->noodles->put( - 'noodles_api', 'http://www.gravatar.com/', 'string', 'external API to use', false, true + 'noodles_api', + 'http://www.gravatar.com/', + 'string', + 'external API to use', + false, + true ); $core->blog->settings->noodles->put( - 'noodles_image', '', 'string', 'Image filename', false, true + 'noodles_image', + '', + 'string', + 'Image filename', + false, + true ); $core->blog->settings->noodles->put( - 'noodles_object', '', 'string', 'Noodles behaviors', false, true + 'noodles_object', + '', + 'string', + 'Noodles behaviors', + false, + true ); $core->setVersion('noodles', $new_version); + return true; } catch (Exception $e) { $core->error->add($e->getMessage()); } + return false; \ No newline at end of file diff --git a/_prepend.php b/_prepend.php index b00507d..8f741fd 100644 --- a/_prepend.php +++ b/_prepend.php @@ -10,12 +10,11 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ - if (!defined('DC_RC_PATH')) { return null; } -$__autoload['noodlesImg'] = dirname(__FILE__) . '/inc/lib.noodles.img.php'; +$__autoload['noodlesImg'] = dirname(__FILE__) . '/inc/lib.noodles.img.php'; $__autoload['noodlesLibImagePath'] = dirname(__FILE__) . '/inc/lib.image.path.php'; $core->blog->settings->addNamespace('noodles'); diff --git a/_public.php b/_public.php index 9a6d91f..9af9770 100644 --- a/_public.php +++ b/_public.php @@ -10,7 +10,6 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ - if (!defined('DC_RC_PATH')) { return null; } @@ -35,7 +34,7 @@ if ($__noodles->isEmpty()) { //$GLOBALS['__noodles'] =& $__noodles; -foreach($__noodles->noodles() AS $noodle) { +foreach ($__noodles->noodles() as $noodle) { if ($noodle->active && $noodle->hasPhpCallback()) { $noodle->phpCallback($core); } @@ -47,7 +46,7 @@ class publicNoodles { echo dcUtils::cssLoad($core->blog->url . $core->url->getURLFor('noodlescss')) . - dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . "/js/jquery.noodles.js") . + dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . '/js/jquery.noodles.js') . dcUtils::jsLoad($core->blog->url . $core->url->getURLFor('noodlesjs')); } } @@ -59,7 +58,7 @@ class urlNoodles extends dcUrlHandlers global $core, $__noodles; $css = ''; - foreach($__noodles->noodles() AS $noodle) { + foreach ($__noodles->noodles() as $noodle) { if (!$noodle->active || !$noodle->hasJsCallback()) { continue; } @@ -78,12 +77,11 @@ class urlNoodles extends dcUrlHandlers global $core, $__noodles; $targets = []; - foreach($__noodles->noodles() AS $noodle) { + foreach ($__noodles->noodles() as $noodle) { if (!$noodle->active || !$noodle->hasJsCallback()) { continue; } - $targets[] = - '$(\'' . html::escapeJS($noodle->target) . '\').noodles({' . + $targets[] = '$(\'' . html::escapeJS($noodle->target) . '\').noodles({' . ' imgId:\'' . html::escapeJS($noodle->id()) . '\',' . ' imgPlace:\'' . html::escapeJS($noodle->place) . '\'' . '});'; @@ -91,7 +89,7 @@ class urlNoodles extends dcUrlHandlers header('Content-Type: text/javascript; charset=UTF-8'); - echo + echo "\$(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" . @@ -116,12 +114,14 @@ class urlNoodles extends dcUrlHandlers $rsp->status = 'failed'; $rsp->message(__('noodles is disabled on this blog')); echo $rsp->toXML(1); + return false; } if ($i === null || $c === null) { $rsp->status = 'failed'; $rsp->message(__('noodles failed because of missing informations')); echo $rsp->toXML(1); + return false; } @@ -131,10 +131,11 @@ class urlNoodles extends dcUrlHandlers 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; } @@ -142,13 +143,14 @@ class urlNoodles extends dcUrlHandlers $rsp->status = 'failed'; $rsp->message(__('Failed to load noodle')); echo $rsp->toXML(1); + return false; } $m = $__noodles->get($i)->jsCallback($__noodles->get($i), $c); $s = $__noodles->get($i)->size; $r = $__noodles->get($i)->rating; - $d = $core->blog->settings->noodles->noodles_image ? + $d = $core->blog->settings->noodles->noodles_image ? urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; $u = $core->blog->settings->noodles->noodles_api; @@ -165,10 +167,10 @@ class urlNoodles extends dcUrlHandlers $r = 'g'; } - $m = md5(strtolower(trim( $m))); - $im = new xmlTag('noodle'); + $m = md5(strtolower(trim($m))); + $im = new xmlTag('noodle'); $im->size = $s; - $im->src = sprintf('%savatar/%s?s=%s&r=%s&d=%s', $u, $m, $s, $r, $d); + $im->src = sprintf('%savatar/%s?s=%s&r=%s&d=%s', $u, $m, $s, $r, $d); $rsp->insertNode($im); $rsp->status = 'ok'; @@ -182,11 +184,13 @@ class urlNoodles extends dcUrlHandlers if (!$core->blog->settings->noodles->noodles_active) { self::p404(); + return; } if (!preg_match('#^(.*?)$#', $args, $m)) { self::p404(); + return; } @@ -194,12 +198,14 @@ class urlNoodles extends dcUrlHandlers if (!($f = self::searchTplFiles($f))) { self::p404(); + return; } $allowed_types = ['png', 'jpg', 'jpeg', 'gif', 'css', 'js', 'swf']; if (!in_array(files::getExtension($f), $allowed_types)) { self::p404(); + return; } $type = files::getMimeType($f); @@ -207,12 +213,12 @@ class urlNoodles extends dcUrlHandlers 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') . '/', + '#url\((?!(http:)|/)#', + 'url(' . $core->blog->url . $core->url->getBase('noodlesmodule') . '/', file_get_contents($f) ); } @@ -222,19 +228,20 @@ 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)) { + foreach ($paths as $path) { + if (preg_match('/tpl(\/|)$/', $path)) { $path = path::real($path . '/..'); } if (file_exists($path . '/' . $file)) { return $path . '/' . $file; } } + return false; } } \ No newline at end of file diff --git a/_uninstall.php b/_uninstall.php index e7c5ccf..970e389 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -10,35 +10,50 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ - if (!defined('DC_CONTEXT_ADMIN')) { return null; } $this->addUserAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ 'noodles', - /* description */ __('delete all settings') + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + 'noodles', + /* description */ + __('delete all settings') ); $this->addUserAction( - /* type */ 'plugins', - /* action */ 'delete', - /* ns */ 'noodles', - /* description */ __('delete plugin files') + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + 'noodles', + /* description */ + __('delete plugin files') ); $this->addDirectAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ 'noodles', - /* description */ sprintf(__('delete all %s settings'), 'noodles') + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + 'noodles', + /* description */ + sprintf(__('delete all %s settings'), 'noodles') ); $this->addDirectAction( - /* type */ 'plugins', - /* action */ 'delete', - /* ns */ 'noodles', - /* description */ sprintf(__('delete %s plugin files'), 'noodles') + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + 'noodles', + /* description */ + sprintf(__('delete %s plugin files'), 'noodles') ); \ No newline at end of file diff --git a/inc/_default_noodles.php b/inc/_default_noodles.php index 888b2e2..dc65f1d 100644 --- a/inc/_default_noodles.php +++ b/inc/_default_noodles.php @@ -10,7 +10,6 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ - if (!defined('DC_RC_PATH')) { return null; } @@ -18,7 +17,7 @@ if (!defined('DC_RC_PATH')) { require dirname(__FILE__) . '/class.noodles.php'; global $__default_noodles; -$__default_noodles = new noodles; +$__default_noodles = new noodles(); # Posts (by public behavior) $__default_noodles @@ -52,7 +51,7 @@ if ($core->plugins->moduleExists('widgets')) { ->target('.lastposts li a') ->css('margin-right:2px;'); - # Widget Last comments + # Widget Last comments $__default_noodles ->add('lastcomments', __('Last comments'), ['widgetsNoodles', 'lastcomments']) ->active(true) diff --git a/inc/_noodles_functions.php b/inc/_noodles_functions.php index b1e6f4a..a2bbdde 100644 --- a/inc/_noodles_functions.php +++ b/inc/_noodles_functions.php @@ -10,7 +10,6 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ - if (!defined('DC_RC_PATH')) { return null; } @@ -22,15 +21,16 @@ class genericNoodles 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]){ + $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; } } @@ -57,10 +57,10 @@ class othersNoodles $c = $__noodles->posts->css; $s = $__noodles->posts->size; $r = $__noodles->posts->rating; - $d = $core->blog->settings->noodles->noodles_image ? + $d = $core->blog->settings->noodles->noodles_image ? urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; - echo + echo ''; @@ -86,13 +86,13 @@ class othersNoodles $c = $__noodles->comments->css; $s = $__noodles->comments->size; $r = $__noodles->comments->rating; - $d = $core->blog->settings->noodles->noodles_image ? + $d = $core->blog->settings->noodles->noodles_image ? urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; - echo + echo ''; + '?s=' . $s . '&r=' . $r . '&d=' . $d . '" alt="" />'; } } @@ -111,6 +111,7 @@ class widgetsNoodles if (!$rs->isEmpty()) { return $rs->comment_email; } + return ''; } } @@ -130,6 +131,7 @@ class authormodeNoodles if ($rs->isEmpty()) { return ''; } + return $rs->user_email; } @@ -149,20 +151,20 @@ class authormodeNoodles } $id = $_ctx->users->user_id; - $u = $core->getUser($id); - $m = $u->user_email; - $c = $__noodles->author->css; - $s = $__noodles->author->size; - $r = $__noodles->author->rating; - $d = $core->blog->settings->noodles->noodles_image ? - urlencode(noodlesLibImagePath::getUrl($core,'noodles')) : ''; + $u = $core->getUser($id); + $m = $u->user_email; + $c = $__noodles->author->css; + $s = $__noodles->author->size; + $r = $__noodles->author->rating; + $d = $core->blog->settings->noodles->noodles_image ? + urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; - echo + echo '