From bd6be9295800ee0c1dd6ef3ca59b2c22fecaab46 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Thu, 9 Sep 2021 22:28:17 +0200 Subject: [PATCH] Clean up code and fix some relative path --- _admin.php | 12 +++++++----- _install.php | 6 ++++++ _prepend.php | 14 +++++++------- _public.php | 13 +++++++------ .../img/noodles-default-image.png | Bin 2215 -> 4330 bytes inc/class.noodles.php | 16 +++++++++++++--- inc/lib.image.path.php | 10 +++++----- 7 files changed, 45 insertions(+), 26 deletions(-) diff --git a/_admin.php b/_admin.php index f45b7b4..f388a34 100644 --- a/_admin.php +++ b/_admin.php @@ -11,12 +11,14 @@ * @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; +} -# Admin menu $_menu['Plugins']->addItem( __('Noodles'), - 'plugin.php?p=noodles','index.php?pf=noodles/icon.png', - preg_match('/plugin.php\?p=noodles(&.*)?$/',$_SERVER['REQUEST_URI']), - $core->auth->check('admin',$core->blog->id) + $core->adminurl->get('admin.plugin.noodles'), + dcPage::getPF('noodles/icon.png'), + preg_match('/noodles(&.*)?$/', $_SERVER['REQUEST_URI']), + $core->auth->check('admin', $core->blog->id) ); \ No newline at end of file diff --git a/_install.php b/_install.php index 9f9b5f8..730d346 100644 --- a/_install.php +++ b/_install.php @@ -26,6 +26,12 @@ try { $core->blog->settings->noodles->put( 'noodles_active', false, 'boolean', 'Enable extension', false, true ); + $core->blog->settings->noodles->put( + 'noodles_image', '', 'string', 'Image filename', false, true + ); + $core->blog->settings->noodles->put( + 'noodles_object', '', 'string', 'Noodles behaviors', false, true + ); $core->setVersion('noodles', $new_version); return true; } catch (Exception $e) { diff --git a/_prepend.php b/_prepend.php index e70a441..537bd36 100644 --- a/_prepend.php +++ b/_prepend.php @@ -12,7 +12,7 @@ */ if (!defined('DC_RC_PATH')) { - return null; + return null; } $__autoload['noodlesImg'] = dirname(__FILE__) . '/inc/lib.noodles.img.php'; @@ -21,14 +21,14 @@ $__autoload['noodlesLibImagePath'] = dirname(__FILE__) . '/inc/lib.image.path.ph $core->blog->settings->addNamespace('noodles'); $core->url->register( - 'noodlesmodule', - 'noodles', - '^noodles/(.+)$', + 'noodlesmodule', + 'noodles', + '^noodles/(.+)$', ['urlNoodles', 'noodles'] ); $core->url->register( - 'noodlesservice', - 'noodle', - '^noodle/$', + 'noodlesservice', + 'noodle', + '^noodle/$', ['urlNoodles', 'service'] ); \ No newline at end of file diff --git a/_public.php b/_public.php index dc1a04e..af4e3d0 100644 --- a/_public.php +++ b/_public.php @@ -83,6 +83,8 @@ class publicNoodles class urlNoodles extends dcUrlHandlers { + public static $api_url = 'http://www.gravatar.com/avatar/%s?s=%s&r=%s&d=%s'; + public static function service($args) { global $core; @@ -127,9 +129,9 @@ class urlNoodles extends dcUrlHandlers return false; } - $m = $__noodles->{$i}->jsCallback($__noodles->{$i}, $c); - $s = $__noodles->{$i}->size; - $r = $__noodles->{$i}->rating; + $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 ? urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; @@ -143,11 +145,10 @@ class urlNoodles extends dcUrlHandlers $r = 'g'; } - $m = mb_strtolower($m); - $m = md5($m); + $m = md5(strtolower(trim( $m))); $im = new xmlTag('noodle'); $im->size = $s; - $im->src = 'http://www.gravatar.com/avatar/' . $m . '?s=' . $s . '&r=' . $r . '&d=' . $d; + $im->src = sprintf(self::$api_url, $m, $s, $r, $d); $rsp->insertNode($im); $rsp->status = 'ok'; diff --git a/default-templates/img/noodles-default-image.png b/default-templates/img/noodles-default-image.png index 1a5310553f4d5ea366042e48ac2b168a5375766b..8e6c007a6fd932c5da52cd1ab272b1fdc61304c4 100644 GIT binary patch literal 4330 zcmbVP2{@E{+ka$NB1DdZY1A=>Suw^i7)I7X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#U#KlODRQvBsZC^k0Zyq+bhxU$Wsz= zh;4W#{w$2*lNX1rm-{jlfCbLYi9Ho1#1}mJ&Bl32n=g(O5g!U|dC{c7!W0IeoXChf zHxWXbaOFox&2*2_v4u}8K)N{QSP<+etlx@I2(5*ZC%B zqi?Fbp_bj+cZ$A?S2ysDFHpjTjwsPesP~-OZB(h#m2GdHekX6A3vlgvbG)XLQ6TNW zMa}mwOHp&<*kfA=`B})!%LWaj#>ZG48OBUqR&HSPY(IRjebQGEE516L!Tkl>re}V^ zyQPulr5D1oI~UVeQN}GtJu{y?oSM_Lfak;^4!C3*-+NQ1z~QHjX9hLuvC=ytNJXT qI~LNJ2hS;q!EY(dUilftKXMD@7E-Y1))Dyb2jhfraj3rPANwy2b-H)} diff --git a/inc/class.noodles.php b/inc/class.noodles.php index 5391cb8..2bc43a7 100644 --- a/inc/class.noodles.php +++ b/inc/class.noodles.php @@ -22,7 +22,7 @@ class noodles public static function decode($s) { $o = @unserialize(base64_decode($s)); - if ($o instanceof self) { + if ($o instanceof noodles) { return $o; } return new self; @@ -39,16 +39,26 @@ class noodles return $this->noodles[$id]; } - public function __get($id) + public function get($id) { return isset($this->noodles[$id]) ? $this->noodles[$id] : null; } - public function __set($id, $noodle) + public function __get($id) + { + return $this->get($id); + } + + public function set($id, $module) { return $this->noodles[$id] = $noodle; } + public function __set($id, $noodle) + { + return $this->set($id, $noodle); + } + public function exists($id) { return isset($this->noodles[$id]); diff --git a/inc/lib.image.path.php b/inc/lib.image.path.php index d4cb727..0046923 100644 --- a/inc/lib.image.path.php +++ b/inc/lib.image.path.php @@ -25,23 +25,23 @@ class noodlesLibImagePath || !$core->url->getBase($m . 'module') ) { return [ - 'theme' => ['dir' = >null, 'url' = >null], + 'theme' => ['dir' => null, 'url' => null], 'public' => ['dir' => null, 'url' => null], 'module' => ['dir' => null, 'url' => null], - }; + ]; } return [ 'theme' => [ - 'dir' => $core->blog->themes_path . '/' . $core->blog->settings->system->theme . '/img/' . $m . '-default-image.png', + 'dir' => path::real($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', + 'dir' => path::real($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', + 'dir' => path::real($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' ] ];