fix PSR coding style

This commit is contained in:
Jean-Christian Denis 2021-11-01 10:28:22 +01:00
parent d5d1f9bb1a
commit f5493d6544
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
11 changed files with 187 additions and 132 deletions

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return; return;
} }

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
$this->registerModule( $this->registerModule(
'Noodles', 'Noodles',
'Add users gravatars everywhere', 'Add users gravatars everywhere',
@ -24,7 +23,7 @@ $this->registerModule(
'details' => 'http://plugins.dotaddict.org/dc2/details/noodles', 'details' => 'http://plugins.dotaddict.org/dc2/details/noodles',
'repository' => 'https://raw.githubusercontent.com/JcDenis/noodles/master/dcstore.xml', 'repository' => 'https://raw.githubusercontent.com/JcDenis/noodles/master/dcstore.xml',
'settings' => [ 'settings' => [
'self' => '' 'self' => ''
] ]
] ]
); );

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -21,23 +20,46 @@ $old_version = $core->getVersion('noodles');
if (version_compare($old_version, $new_version, '>=')) { if (version_compare($old_version, $new_version, '>=')) {
return null; return null;
} }
try { try {
$core->blog->settings->addNamespace('noodles'); $core->blog->settings->addNamespace('noodles');
$core->blog->settings->noodles->put( $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( $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( $core->blog->settings->noodles->put(
'noodles_image', '', 'string', 'Image filename', false, true 'noodles_image',
'',
'string',
'Image filename',
false,
true
); );
$core->blog->settings->noodles->put( $core->blog->settings->noodles->put(
'noodles_object', '', 'string', 'Noodles behaviors', false, true 'noodles_object',
'',
'string',
'Noodles behaviors',
false,
true
); );
$core->setVersion('noodles', $new_version); $core->setVersion('noodles', $new_version);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
return false; return false;

View file

@ -10,12 +10,11 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; 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'; $__autoload['noodlesLibImagePath'] = dirname(__FILE__) . '/inc/lib.image.path.php';
$core->blog->settings->addNamespace('noodles'); $core->blog->settings->addNamespace('noodles');

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -35,7 +34,7 @@ if ($__noodles->isEmpty()) {
//$GLOBALS['__noodles'] =& $__noodles; //$GLOBALS['__noodles'] =& $__noodles;
foreach($__noodles->noodles() AS $noodle) { foreach ($__noodles->noodles() as $noodle) {
if ($noodle->active && $noodle->hasPhpCallback()) { if ($noodle->active && $noodle->hasPhpCallback()) {
$noodle->phpCallback($core); $noodle->phpCallback($core);
} }
@ -47,7 +46,7 @@ class publicNoodles
{ {
echo echo
dcUtils::cssLoad($core->blog->url . $core->url->getURLFor('noodlescss')) . 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')); dcUtils::jsLoad($core->blog->url . $core->url->getURLFor('noodlesjs'));
} }
} }
@ -59,7 +58,7 @@ class urlNoodles extends dcUrlHandlers
global $core, $__noodles; global $core, $__noodles;
$css = ''; $css = '';
foreach($__noodles->noodles() AS $noodle) { foreach ($__noodles->noodles() as $noodle) {
if (!$noodle->active || !$noodle->hasJsCallback()) { if (!$noodle->active || !$noodle->hasJsCallback()) {
continue; continue;
} }
@ -78,12 +77,11 @@ class urlNoodles extends dcUrlHandlers
global $core, $__noodles; global $core, $__noodles;
$targets = []; $targets = [];
foreach($__noodles->noodles() AS $noodle) { foreach ($__noodles->noodles() as $noodle) {
if (!$noodle->active || !$noodle->hasJsCallback()) { if (!$noodle->active || !$noodle->hasJsCallback()) {
continue; continue;
} }
$targets[] = $targets[] = '$(\'' . html::escapeJS($noodle->target) . '\').noodles({' .
'$(\'' . html::escapeJS($noodle->target) . '\').noodles({' .
' imgId:\'' . html::escapeJS($noodle->id()) . '\',' . ' imgId:\'' . html::escapeJS($noodle->id()) . '\',' .
' imgPlace:\'' . html::escapeJS($noodle->place) . '\'' . ' imgPlace:\'' . html::escapeJS($noodle->place) . '\'' .
'});'; '});';
@ -91,7 +89,7 @@ class urlNoodles extends dcUrlHandlers
header('Content-Type: text/javascript; charset=UTF-8'); header('Content-Type: text/javascript; charset=UTF-8');
echo echo
"\$(function(){if(!document.getElementById){return;} \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_url = '" . html::escapeJS($core->blog->url . $core->url->getBase('noodlesservice') . '/') . "'; \n" .
"\$.fn.noodles.defaults.service_func = '" . html::escapeJS('getNoodle') . "'; \n" . "\$.fn.noodles.defaults.service_func = '" . html::escapeJS('getNoodle') . "'; \n" .
@ -116,12 +114,14 @@ class urlNoodles extends dcUrlHandlers
$rsp->status = 'failed'; $rsp->status = 'failed';
$rsp->message(__('noodles is disabled on this blog')); $rsp->message(__('noodles is disabled on this blog'));
echo $rsp->toXML(1); echo $rsp->toXML(1);
return false; return false;
} }
if ($i === null || $c === null) { if ($i === null || $c === null) {
$rsp->status = 'failed'; $rsp->status = 'failed';
$rsp->message(__('noodles failed because of missing informations')); $rsp->message(__('noodles failed because of missing informations'));
echo $rsp->toXML(1); echo $rsp->toXML(1);
return false; return false;
} }
@ -131,10 +131,11 @@ class urlNoodles extends dcUrlHandlers
if ($__noodles->isEmpty()) { if ($__noodles->isEmpty()) {
$__noodles = $GLOBALS['__default_noodles']; $__noodles = $GLOBALS['__default_noodles'];
} }
} catch(Excetpion $e) { } catch (Excetpion $e) {
$rsp->status = 'failed'; $rsp->status = 'failed';
$rsp->message(__('Failed to load default noodles')); $rsp->message(__('Failed to load default noodles'));
echo $rsp->toXML(1); echo $rsp->toXML(1);
return false; return false;
} }
@ -142,13 +143,14 @@ class urlNoodles extends dcUrlHandlers
$rsp->status = 'failed'; $rsp->status = 'failed';
$rsp->message(__('Failed to load noodle')); $rsp->message(__('Failed to load noodle'));
echo $rsp->toXML(1); echo $rsp->toXML(1);
return false; return false;
} }
$m = $__noodles->get($i)->jsCallback($__noodles->get($i), $c); $m = $__noodles->get($i)->jsCallback($__noodles->get($i), $c);
$s = $__noodles->get($i)->size; $s = $__noodles->get($i)->size;
$r = $__noodles->get($i)->rating; $r = $__noodles->get($i)->rating;
$d = $core->blog->settings->noodles->noodles_image ? $d = $core->blog->settings->noodles->noodles_image ?
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : '';
$u = $core->blog->settings->noodles->noodles_api; $u = $core->blog->settings->noodles->noodles_api;
@ -165,10 +167,10 @@ class urlNoodles extends dcUrlHandlers
$r = 'g'; $r = 'g';
} }
$m = md5(strtolower(trim( $m))); $m = md5(strtolower(trim($m)));
$im = new xmlTag('noodle'); $im = new xmlTag('noodle');
$im->size = $s; $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->insertNode($im);
$rsp->status = 'ok'; $rsp->status = 'ok';
@ -182,11 +184,13 @@ class urlNoodles extends dcUrlHandlers
if (!$core->blog->settings->noodles->noodles_active) { if (!$core->blog->settings->noodles->noodles_active) {
self::p404(); self::p404();
return; return;
} }
if (!preg_match('#^(.*?)$#', $args, $m)) { if (!preg_match('#^(.*?)$#', $args, $m)) {
self::p404(); self::p404();
return; return;
} }
@ -194,12 +198,14 @@ class urlNoodles extends dcUrlHandlers
if (!($f = self::searchTplFiles($f))) { if (!($f = self::searchTplFiles($f))) {
self::p404(); self::p404();
return; return;
} }
$allowed_types = ['png', 'jpg', 'jpeg', 'gif', 'css', 'js', 'swf']; $allowed_types = ['png', 'jpg', 'jpeg', 'gif', 'css', 'js', 'swf'];
if (!in_array(files::getExtension($f), $allowed_types)) { if (!in_array(files::getExtension($f), $allowed_types)) {
self::p404(); self::p404();
return; return;
} }
$type = files::getMimeType($f); $type = files::getMimeType($f);
@ -207,12 +213,12 @@ class urlNoodles extends dcUrlHandlers
header('Content-Type: ' . $type . '; charset=UTF-8'); header('Content-Type: ' . $type . '; charset=UTF-8');
header('Content-Length: ' . filesize($f)); 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); readfile($f);
} else { } else {
echo preg_replace( echo preg_replace(
'#url\((?!(http:)|/)#', '#url\((?!(http:)|/)#',
'url(' . $core->blog->url . $core->url->getBase('noodlesmodule') . '/', 'url(' . $core->blog->url . $core->url->getBase('noodlesmodule') . '/',
file_get_contents($f) file_get_contents($f)
); );
} }
@ -222,19 +228,20 @@ class urlNoodles extends dcUrlHandlers
# Search noodles files like JS, CSS in default-templates subdirectories # Search noodles files like JS, CSS in default-templates subdirectories
private static function searchTplFiles($file) private static function searchTplFiles($file)
{ {
if (strstr($file,"..") !== false) { if (strstr($file, '..') !== false) {
return false; return false;
} }
$paths = $GLOBALS['core']->tpl->getPath(); $paths = $GLOBALS['core']->tpl->getPath();
foreach($paths as $path) { foreach ($paths as $path) {
if (preg_match('/tpl(\/|)$/',$path)) { if (preg_match('/tpl(\/|)$/', $path)) {
$path = path::real($path . '/..'); $path = path::real($path . '/..');
} }
if (file_exists($path . '/' . $file)) { if (file_exists($path . '/' . $file)) {
return $path . '/' . $file; return $path . '/' . $file;
} }
} }
return false; return false;
} }
} }

View file

@ -10,35 +10,50 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$this->addUserAction( $this->addUserAction(
/* type */ 'settings', /* type */
/* action */ 'delete_all', 'settings',
/* ns */ 'noodles', /* action */
/* description */ __('delete all settings') 'delete_all',
/* ns */
'noodles',
/* description */
__('delete all settings')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ 'noodles', /* action */
/* description */ __('delete plugin files') 'delete',
/* ns */
'noodles',
/* description */
__('delete plugin files')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'settings', /* type */
/* action */ 'delete_all', 'settings',
/* ns */ 'noodles', /* action */
/* description */ sprintf(__('delete all %s settings'), 'noodles') 'delete_all',
/* ns */
'noodles',
/* description */
sprintf(__('delete all %s settings'), 'noodles')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ 'noodles', /* action */
/* description */ sprintf(__('delete %s plugin files'), 'noodles') 'delete',
/* ns */
'noodles',
/* description */
sprintf(__('delete %s plugin files'), 'noodles')
); );

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -18,7 +17,7 @@ if (!defined('DC_RC_PATH')) {
require dirname(__FILE__) . '/class.noodles.php'; require dirname(__FILE__) . '/class.noodles.php';
global $__default_noodles; global $__default_noodles;
$__default_noodles = new noodles; $__default_noodles = new noodles();
# Posts (by public behavior) # Posts (by public behavior)
$__default_noodles $__default_noodles
@ -52,7 +51,7 @@ if ($core->plugins->moduleExists('widgets')) {
->target('.lastposts li a') ->target('.lastposts li a')
->css('margin-right:2px;'); ->css('margin-right:2px;');
# Widget Last comments # Widget Last comments
$__default_noodles $__default_noodles
->add('lastcomments', __('Last comments'), ['widgetsNoodles', 'lastcomments']) ->add('lastcomments', __('Last comments'), ['widgetsNoodles', 'lastcomments'])
->active(true) ->active(true)

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -22,15 +21,16 @@ class genericNoodles
global $core; global $core;
$types = $core->getPostTypes(); $types = $core->getPostTypes();
$reg = '@^' . str_replace('%s', '(.*?)', preg_quote($core->blog->url . $types['post']['public_url'])) . '$@'; $reg = '@^' . str_replace('%s', '(.*?)', preg_quote($core->blog->url . $types['post']['public_url'])) . '$@';
$ok = preg_match($reg, $content, $m); $ok = preg_match($reg, $content, $m);
if (!$ok || !$m[1]){ if (!$ok || !$m[1]) {
return ''; return '';
} }
$rs = $core->blog->getPosts(['no_content' => 1, 'post_url' => urldecode($m[1]), 'limit' => 1]); $rs = $core->blog->getPosts(['no_content' => 1, 'post_url' => urldecode($m[1]), 'limit' => 1]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return ''; return '';
} }
return $rs->user_email; return $rs->user_email;
} }
} }
@ -57,10 +57,10 @@ class othersNoodles
$c = $__noodles->posts->css; $c = $__noodles->posts->css;
$s = $__noodles->posts->size; $s = $__noodles->posts->size;
$r = $__noodles->posts->rating; $r = $__noodles->posts->rating;
$d = $core->blog->settings->noodles->noodles_image ? $d = $core->blog->settings->noodles->noodles_image ?
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : '';
echo echo
'<img class="noodles-posts" style="width:' . $s . 'px;height:' . $s . 'px;' . $c . '"' . '<img class="noodles-posts" style="width:' . $s . 'px;height:' . $s . 'px;' . $c . '"' .
'src="http://www.gravatar.com/avatar/' . md5($m) . 'src="http://www.gravatar.com/avatar/' . md5($m) .
'?s=' . $s . '&amp;r=' . $r . '&amp;d=' . $d . '" alt="" />'; '?s=' . $s . '&amp;r=' . $r . '&amp;d=' . $d . '" alt="" />';
@ -86,13 +86,13 @@ class othersNoodles
$c = $__noodles->comments->css; $c = $__noodles->comments->css;
$s = $__noodles->comments->size; $s = $__noodles->comments->size;
$r = $__noodles->comments->rating; $r = $__noodles->comments->rating;
$d = $core->blog->settings->noodles->noodles_image ? $d = $core->blog->settings->noodles->noodles_image ?
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : '';
echo echo
'<img class="noodles-comments" style="width:' . $s . 'px;height:' . $s . 'px;' . $c . '"' . '<img class="noodles-comments" style="width:' . $s . 'px;height:' . $s . 'px;' . $c . '"' .
'src="http://www.gravatar.com/avatar/' . md5($m) . 'src="http://www.gravatar.com/avatar/' . md5($m) .
'?s=' . $s . '&amp;r=' . $r .'&amp;d=' . $d . '" alt="" />'; '?s=' . $s . '&amp;r=' . $r . '&amp;d=' . $d . '" alt="" />';
} }
} }
@ -111,6 +111,7 @@ class widgetsNoodles
if (!$rs->isEmpty()) { if (!$rs->isEmpty()) {
return $rs->comment_email; return $rs->comment_email;
} }
return ''; return '';
} }
} }
@ -130,6 +131,7 @@ class authormodeNoodles
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return ''; return '';
} }
return $rs->user_email; return $rs->user_email;
} }
@ -149,20 +151,20 @@ class authormodeNoodles
} }
$id = $_ctx->users->user_id; $id = $_ctx->users->user_id;
$u = $core->getUser($id); $u = $core->getUser($id);
$m = $u->user_email; $m = $u->user_email;
$c = $__noodles->author->css; $c = $__noodles->author->css;
$s = $__noodles->author->size; $s = $__noodles->author->size;
$r = $__noodles->author->rating; $r = $__noodles->author->rating;
$d = $core->blog->settings->noodles->noodles_image ? $d = $core->blog->settings->noodles->noodles_image ?
urlencode(noodlesLibImagePath::getUrl($core,'noodles')) : ''; urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : '';
echo echo
'<script type="text/javascript">' . "\n" . '<script type="text/javascript">' . "\n" .
"//<![CDATA[\n" . "//<![CDATA[\n" .
"$(function(){if(!document.getElementById){return;}\n" . "$(function(){if(!document.getElementById){return;}\n" .
"$('" . $__noodles->author->target . "')." . $__noodles->author->place . "('" . "$('" . $__noodles->author->target . "')." . $__noodles->author->place . "('" .
'<img class="noodles-comments" style="width:' . $s . 'px;height:' . $s . 'px;' . $c .'"' . '<img class="noodles-comments" style="width:' . $s . 'px;height:' . $s . 'px;' . $c . '"' .
'src="http://www.gravatar.com/avatar/' . md5($m) . 'src="http://www.gravatar.com/avatar/' . md5($m) .
'?s=' . $s . '&amp;r=' . $r . '&amp;d=' . $d . '" alt="" />' . '?s=' . $s . '&amp;r=' . $r . '&amp;d=' . $d . '" alt="" />' .
"');});" . "');});" .

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -25,7 +24,8 @@ class noodles
if ($o instanceof noodles) { if ($o instanceof noodles) {
return $o; return $o;
} }
return new self;
return new self();
} }
public function encode() public function encode()
@ -36,12 +36,13 @@ class noodles
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]; return $this->noodles[$id];
} }
public function get($id) public function get($id)
{ {
return isset($this->noodles[$id]) ? $this->noodles[$id] : null; return $this->noodles[$id] ?? null;
} }
public function __get($id) public function __get($id)
@ -84,16 +85,16 @@ class noodle
private $settings = [ private $settings = [
'active' => 0, 'active' => 0,
'rating' => 'g', 'rating' => 'g',
'size' => 16, 'size' => 16,
'target' => '', 'target' => '',
'place' => 'prepend' '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->id = $id;
$this->name = $name; $this->name = $name;
$this->js_callback = $js_callback; $this->js_callback = $js_callback;
$this->php_callback = $php_callback; $this->php_callback = $php_callback;
} }
@ -112,6 +113,7 @@ class noodle
if (!is_callable($this->js_callback)) { if (!is_callable($this->js_callback)) {
return null; return null;
} }
return call_user_func($this->js_callback, $g, $content); return call_user_func($this->js_callback, $g, $content);
} }
@ -125,6 +127,7 @@ class noodle
if (!is_callable($this->php_callback)) { if (!is_callable($this->php_callback)) {
return null; return null;
} }
return call_user_func($this->php_callback, $core, $this); return call_user_func($this->php_callback, $core, $this);
} }
@ -137,29 +140,36 @@ class noodle
{ {
switch ($type) { switch ($type) {
case 'active': case 'active':
$this->settings['active'] = abs((integer) $value); $this->settings['active'] = abs((int) $value);
break; break;
case 'rating': case 'rating':
$this->settings['rating'] = in_array($value, ['g', 'pg', 'r', 'x']) ? $value : 'g'; $this->settings['rating'] = in_array($value, ['g', 'pg', 'r', 'x']) ? $value : 'g';
break; break;
case 'size': case 'size':
$this->settings['size'] = in_array($value, [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; break;
case 'css': case 'css':
$this->settings['css'] = (string) $value; $this->settings['css'] = (string) $value;
break; break;
case 'target': case 'target':
$this->settings['target'] = (string) $value; $this->settings['target'] = (string) $value;
break; break;
case 'place': case 'place':
$this->settings['place'] = in_array($value, ['append', 'prepend', 'before', 'after']) ? $value : 'prepend'; $this->settings['place'] = in_array($value, ['append', 'prepend', 'before', 'after']) ? $value : 'prepend';
break; break;
} }
return $this; return $this;
} }
@ -200,7 +210,7 @@ class noodle
public function get($type) public function get($type)
{ {
return isset($this->settings[$type]) ? $this->settings[$type] : null; return $this->settings[$type] ?? null;
} }
public function __get($type) public function __get($type)

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -25,7 +24,7 @@ class noodlesLibImagePath
|| !$core->url->getBase($m . 'module') || !$core->url->getBase($m . 'module')
) { ) {
return [ return [
'theme' => ['dir' => null, 'url' => null], 'theme' => ['dir' => null, 'url' => null],
'public' => ['dir' => null, 'url' => null], 'public' => ['dir' => null, 'url' => null],
'module' => ['dir' => null, 'url' => null], 'module' => ['dir' => null, 'url' => null],
]; ];
@ -50,30 +49,34 @@ class noodlesLibImagePath
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) { foreach ($files as $k => $file) {
if (file_exists($files[$k]['dir'])) if (file_exists($files[$k]['dir'])) {
return $files[$k]['url']; return $files[$k]['url'];
}
} }
return null; 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) { foreach ($files as $k => $file) {
if (file_exists($files[$k]['dir'])) if (file_exists($files[$k]['dir'])) {
return $files[$k]['dir']; return $files[$k]['dir'];
}
} }
return null; return null;
} }
public static function getSize($core, $m = '') public static function getSize($core, $m = '')
{ {
if (!($img = self::getPath($core, $m))) if (!($img = self::getPath($core, $m))) {
return ['w' => 16, 'h' => 16]; return ['w' => 16, 'h' => 16];
else {
$info = getimagesize($img);
return ['w' => $info[0], 'h' => floor($info[1] /3)];
} }
$info = getimagesize($img);
return ['w' => $info[0], 'h' => floor($info[1] / 3)];
} }
} }

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -26,7 +25,7 @@ if ($__noodles->isEmpty()) {
$__noodles = $__default_noodles; $__noodles = $__default_noodles;
} else { } else {
$default_noodles_array = $__default_noodles->noodles(); $default_noodles_array = $__default_noodles->noodles();
foreach($default_noodles_array AS $id => $noodle) { foreach ($default_noodles_array as $id => $noodle) {
if ($__noodles->exists($id)) { if ($__noodles->exists($id)) {
continue; continue;
} }
@ -44,30 +43,30 @@ if (!is_array($default_images)) {
$default_image = $s->noodles_image; $default_image = $s->noodles_image;
$combo_api = [ $combo_api = [
'gravatar' => 'http://www.gravatar.com/', 'gravatar' => 'http://www.gravatar.com/',
'libravatar' => 'http://cdn.libravatar.org/' 'libravatar' => 'http://cdn.libravatar.org/'
]; ];
$combo_place = [ $combo_place = [
__('Begin') => 'prepend', __('Begin') => 'prepend',
__('End') => 'append', __('End') => 'append',
__('Before') => 'before', __('Before') => 'before',
__('After') => 'after' __('After') => 'after'
]; ];
$combo_rating = [ $combo_rating = [
'G' => 'g', 'G' => 'g',
'PG' => 'pg', 'PG' => 'pg',
'R' => 'r', 'R' => 'r',
'X' => 'x' 'X' => 'x'
]; ];
$combo_size = [ $combo_size = [
'16px' => 16, '16px' => 16,
'24px' => 24, '24px' => 24,
'32px' => 32, '32px' => 32,
'48px' => 48, '48px' => 48,
'56px' => 56, '56px' => 56,
'64px' => 64, '64px' => 64,
'92px' => 92, '92px' => 92,
'128px' => 128, '128px' => 128,
'256px' => 256 '256px' => 256
]; ];
@ -95,7 +94,7 @@ if (!empty($_POST['save'])) {
throw new Exception(__('Failed to save image')); throw new Exception(__('Failed to save image'));
} }
// Default gravatar.com avatar // Default gravatar.com avatar
} elseif ($_POST['noodles_image'] == 'gravatar.com') { } elseif ($_POST['noodles_image'] == 'gravatar.com') {
$s->put('noodles_image', 0, 'boolean'); $s->put('noodles_image', 0, 'boolean');
@ -113,13 +112,13 @@ if (!empty($_POST['save'])) {
$s->put('noodles_image', 1, 'boolean'); $s->put('noodles_image', 1, 'boolean');
} }
// Default gravatar.com avatar // Default gravatar.com avatar
} else { //if ($_POST['noodles_image'] == 'gravatar.com') { } else { //if ($_POST['noodles_image'] == 'gravatar.com') {
$s->put('noodles_image', 0, 'boolean'); $s->put('noodles_image', 0, 'boolean');
} }
// behaviors // behaviors
foreach($_POST['noodle'] as $id => $bloc) { foreach ($_POST['noodle'] as $id => $bloc) {
$__noodles->get($id) $__noodles->get($id)
->set('active', !empty($bloc['active'])) ->set('active', !empty($bloc['active']))
->set('rating', $bloc['rating'] ?? 'g') ->set('rating', $bloc['rating'] ?? 'g')
@ -141,19 +140,19 @@ if (!empty($_POST['save'])) {
echo '<html><head><title>' . __('Noodles') . '</title></head><body>' . echo '<html><head><title>' . __('Noodles') . '</title></head><body>' .
dcPage::breadcrumb([ dcPage::breadcrumb([
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
__('Noodles') => '', __('Noodles') => '',
__('Plugin configuration') => '' __('Plugin configuration') => ''
]) . ]) .
dcPage::notices() . ' dcPage::notices() . '
<form id="module_config" action="' . <form id="module_config" action="' .
$core->adminurl->get('admin.plugin.noodles') . $core->adminurl->get('admin.plugin.noodles') .
'" method="post" enctype="multipart/form-data"> '" method="post" enctype="multipart/form-data">
<h3>' . sprintf(__('Configure "%s"'), __('Noodles')) . '</h3> <h3>' . sprintf(__('Configure "%s"'), __('Noodles')) . '</h3>
<div class="fieldset"><h4>' . __('Activation') . '</h4> <div class="fieldset"><h4>' . __('Activation') . '</h4>
<p><label for="noodles_active">' . <p><label for="noodles_active">' .
form::checkbox('noodles_active', 1, $s->noodles_active) . form::checkbox('noodles_active', 1, $s->noodles_active) .
__('Enable plugin noodles on this blog') . '</label></p> __('Enable plugin noodles on this blog') . '</label></p>
<p><label for="noodles_api" class="classic">' . __('API:') . ' </label>' . <p><label for="noodles_api" class="classic">' . __('API:') . ' </label>' .
form::combo('noodles_api', $combo_api, $s->noodles_api) . '</p> form::combo('noodles_api', $combo_api, $s->noodles_api) . '</p>
@ -165,12 +164,12 @@ if (!empty($public_path)) {
echo '<div class="one-box">'; echo '<div class="one-box">';
sort($default_images); sort($default_images);
$i = 0; $i = 0;
foreach($default_images AS $f) { foreach ($default_images as $f) {
if (!preg_match('/gravatar-[0-9]+.png/', $f)) { if (!preg_match('/gravatar-[0-9]+.png/', $f)) {
continue; continue;
} }
$i++; $i++;
$sz = getimagesize(dirname(__FILE__) . '/default-templates/img/' . $f); $sz = getimagesize(dirname(__FILE__) . '/default-templates/img/' . $f);
$sz[2] = files::size(filesize(dirname(__FILE__) . '/default-templates/img/' . $f)); $sz[2] = files::size(filesize(dirname(__FILE__) . '/default-templates/img/' . $f));
echo ' echo '
@ -190,7 +189,7 @@ if (!empty($public_path)) {
echo '<div class="one-box">'; echo '<div class="one-box">';
if (null !== ($default_image_path = noodlesLibImagePath::getPath($core, 'noodles'))) { if (null !== ($default_image_path = noodlesLibImagePath::getPath($core, 'noodles'))) {
$sz = getimagesize($default_image_path); $sz = getimagesize($default_image_path);
$sz[2] = files::size(filesize($default_image_path)); $sz[2] = files::size(filesize($default_image_path));
echo ' echo '
@ -217,8 +216,8 @@ if (!empty($public_path)) {
} }
echo ' echo '
<div class="fieldset box"> <div class="fieldset box">
<p>'. form::radio(['noodles_image', 'com_image'], 'gravatar.com', empty($default_image)) . ' <p>' . form::radio(['noodles_image', 'com_image'], 'gravatar.com', empty($default_image)) . '
<label class="classic">' . __('API default image').'</label></p> <label class="classic">' . __('API default image') . '</label></p>
</div>'; </div>';
if (empty($public_path)) { if (empty($public_path)) {
@ -230,31 +229,32 @@ echo '
<div class="fieldset"><h4>' . __('Behaviors') . '</h4> <div class="fieldset"><h4>' . __('Behaviors') . '</h4>
<div class="table-outer"> <div class="table-outer">
<table><caption class="hidden">' . __('Behaviors list') . '</caption><tbody><tr> <table><caption class="hidden">' . __('Behaviors list') . '</caption><tbody><tr>
<th colspan="2" class="first">'.__('Search area').'</th> <th colspan="2" class="first">' . __('Search area') . '</th>
<th scope="col">'.__('Size').'</th> <th scope="col">' . __('Size') . '</th>
<th scope="col">'.__('Rating').'</th> <th scope="col">' . __('Rating') . '</th>
<th scope="col">'.__('PHP').'</th> <th scope="col">' . __('PHP') . '</th>
<th scope="col">'.__('JS').'</th> <th scope="col">' . __('JS') . '</th>
<th scope="col">'.__('Target').'</th> <th scope="col">' . __('Target') . '</th>
<th scope="col">'.__('Place').'</th> <th scope="col">' . __('Place') . '</th>
<th colspan="2" scope="col">'.__('Adjust avatar CSS').'</th> <th colspan="2" scope="col">' . __('Adjust avatar CSS') . '</th>
</tr>'; </tr>';
foreach($__noodles->noodles() as $noodle) { foreach ($__noodles->noodles() as $noodle) {
echo ' echo '
<tr class="line"> <tr class="line">
<td>' . form::checkbox(['noodle[' . $noodle->id() . '][active]', 'ck_' . $noodle->id()], 1, $noodle->active) . '</td> <td>' . form::checkbox(['noodle[' . $noodle->id() . '][active]', 'ck_' . $noodle->id()], 1, $noodle->active) . '</td>
<td class="nowrap" scope="row"><label for="ck_' . $noodle->id() .'">' . $noodle->name() . '</label></td> <td class="nowrap" scope="row"><label for="ck_' . $noodle->id() . '">' . $noodle->name() . '</label></td>
<td>' . form::combo(['noodle[' . $noodle->id() . '][size]'], $combo_size, $noodle->size) . '</td> <td>' . form::combo(['noodle[' . $noodle->id() . '][size]'], $combo_size, $noodle->size) . '</td>
<td>' . form::combo(['noodle[' . $noodle->id() . '][rating]'], $combo_rating, $noodle->rating) . '</td> <td>' . form::combo(['noodle[' . $noodle->id() . '][rating]'], $combo_rating, $noodle->rating) . '</td>
<td>' . ($noodle->hasPhpCallback() ? <td>' . (
'<img alt="ok" src="images/check-on.png" />' : $noodle->hasPhpCallback() ?
'<img alt="ok" src="images/check-on.png" />' :
'<img alt="nok" src="images/check-off.png" />' '<img alt="nok" src="images/check-off.png" />'
) . '</td> ) . '</td>
<td><img alt="ok" src="images/check-on.png" /></td> <td><img alt="ok" src="images/check-on.png" /></td>
<td>' . form::field(['noodle[' . $noodle->id() . '][target]'], 20, 255, $noodle->target) . '</td> <td>' . form::field(['noodle[' . $noodle->id() . '][target]'], 20, 255, $noodle->target) . '</td>
<td>' . form::combo(['noodle[' . $noodle->id() . '][place]'], $combo_place, $noodle->place).'</td> <td>' . form::combo(['noodle[' . $noodle->id() . '][place]'], $combo_place, $noodle->place) . '</td>
<td>' . form::field(['noodle[' . $noodle->id() . '][css]'], 50, 255, $noodle->css).'</td> <td>' . form::field(['noodle[' . $noodle->id() . '][css]'], 50, 255, $noodle->css) . '</td>
<td> .noodles-' . $noodle->id() . '{}</td> <td> .noodles-' . $noodle->id() . '{}</td>
</tr>'; </tr>';
} }