Clean up code and fix some relative path

master
Jean-Christian Paul Denis 2021-09-09 22:28:17 +02:00
parent f40e9cf174
commit bd6be92958
7 changed files with 45 additions and 26 deletions

View File

@ -11,12 +11,14 @@
* @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')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
# Admin menu
$_menu['Plugins']->addItem( $_menu['Plugins']->addItem(
__('Noodles'), __('Noodles'),
'plugin.php?p=noodles','index.php?pf=noodles/icon.png', $core->adminurl->get('admin.plugin.noodles'),
preg_match('/plugin.php\?p=noodles(&.*)?$/',$_SERVER['REQUEST_URI']), dcPage::getPF('noodles/icon.png'),
preg_match('/noodles(&.*)?$/', $_SERVER['REQUEST_URI']),
$core->auth->check('admin', $core->blog->id) $core->auth->check('admin', $core->blog->id)
); );

View File

@ -26,6 +26,12 @@ try {
$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(
'noodles_image', '', 'string', 'Image filename', false, true
);
$core->blog->settings->noodles->put(
'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) {

View File

@ -83,6 +83,8 @@ class publicNoodles
class urlNoodles extends dcUrlHandlers 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) public static function service($args)
{ {
global $core; global $core;
@ -127,9 +129,9 @@ class urlNoodles extends dcUrlHandlers
return false; return false;
} }
$m = $__noodles->{$i}->jsCallback($__noodles->{$i}, $c); $m = $__noodles->get($i)->jsCallback($__noodles->get($i), $c);
$s = $__noodles->{$i}->size; $s = $__noodles->get($i)->size;
$r = $__noodles->{$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')) : '';
@ -143,11 +145,10 @@ class urlNoodles extends dcUrlHandlers
$r = 'g'; $r = 'g';
} }
$m = mb_strtolower($m); $m = md5(strtolower(trim( $m)));
$m = md5($m);
$im = new xmlTag('noodle'); $im = new xmlTag('noodle');
$im->size = $s; $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->insertNode($im);
$rsp->status = 'ok'; $rsp->status = 'ok';

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -22,7 +22,7 @@ class noodles
public static function decode($s) public static function decode($s)
{ {
$o = @unserialize(base64_decode($s)); $o = @unserialize(base64_decode($s));
if ($o instanceof self) { if ($o instanceof noodles) {
return $o; return $o;
} }
return new self; return new self;
@ -39,16 +39,26 @@ class noodles
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 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; return $this->noodles[$id] = $noodle;
} }
public function __set($id, $noodle)
{
return $this->set($id, $noodle);
}
public function exists($id) public function exists($id)
{ {
return isset($this->noodles[$id]); return isset($this->noodles[$id]);

View File

@ -28,20 +28,20 @@ class noodlesLibImagePath
'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],
}; ];
} }
return [ return [
'theme' => [ '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' 'url' => $core->blog->settings->system->themes_url . $core->blog->settings->system->theme . '/img/' . $m . '-default-image.png'
], ],
'public' => [ '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' 'url' => $core->blog->host . path::clean($core->blog->settings->system->public_url) . '/' . $m . '-default-image.png'
], ],
'module' => [ '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' 'url' => $core->blog->url . $core->url->getBase($m . 'module') . '/img/' . $m . '-default-image.png'
] ]
]; ];