Clean up code and fix some relative path

This commit is contained in:
Jean-Christian 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'),
$core->auth->check('admin',$core->blog->id) preg_match('/noodles(&.*)?$/', $_SERVER['REQUEST_URI']),
$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

@ -12,7 +12,7 @@
*/ */
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';
@ -21,14 +21,14 @@ $__autoload['noodlesLibImagePath'] = dirname(__FILE__) . '/inc/lib.image.path.ph
$core->blog->settings->addNamespace('noodles'); $core->blog->settings->addNamespace('noodles');
$core->url->register( $core->url->register(
'noodlesmodule', 'noodlesmodule',
'noodles', 'noodles',
'^noodles/(.+)$', '^noodles/(.+)$',
['urlNoodles', 'noodles'] ['urlNoodles', 'noodles']
); );
$core->url->register( $core->url->register(
'noodlesservice', 'noodlesservice',
'noodle', 'noodle',
'^noodle/$', '^noodle/$',
['urlNoodles', 'service'] ['urlNoodles', 'service']
); );

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

@ -25,23 +25,23 @@ 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],
}; ];
} }
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'
] ]
]; ];