prepare to DC 2.24

This commit is contained in:
Jean-Christian Denis 2022-11-17 21:00:42 +01:00
parent f5493d6544
commit 10dcadb1dd
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
11 changed files with 175 additions and 185 deletions

View file

@ -14,10 +14,10 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return; return;
} }
$_menu['Plugins']->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Noodles'), __('Noodles'),
$core->adminurl->get('admin.plugin.noodles'), dcCore::app()->adminurl->get('admin.plugin.noodles'),
dcPage::getPF('noodles/icon.png'), dcPage::getPF('noodles/icon.png'),
preg_match('/noodles(&.*)?$/', $_SERVER['REQUEST_URI']), preg_match('/noodles(&.*)?$/', $_SERVER['REQUEST_URI']),
$core->auth->check('admin', $core->blog->id) dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id)
); );

View file

@ -14,16 +14,16 @@ $this->registerModule(
'Noodles', 'Noodles',
'Add users gravatars everywhere', 'Add users gravatars everywhere',
'Jean-Christian Denis and contributors', 'Jean-Christian Denis and contributors',
'0.8', '0.9',
[ [
'requires' => [['core', '2.19']], 'requires' => [['core', '2.24']],
'permissions' => 'admin', 'permissions' => dcAuth::PERMISSION_CONTENT_ADMIN,
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/noodles', 'support' => 'https://github.com/JcDenis/noodles',
'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

@ -14,16 +14,16 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$new_version = $core->plugins->moduleInfo('noodles', 'version'); $new_version = dcCore::app()->plugins->moduleInfo('noodles', 'version');
$old_version = $core->getVersion('noodles'); $old_version = dcCore::app()->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'); dcCore::app()->blog->settings->addNamespace('noodles');
$core->blog->settings->noodles->put( dcCore::app()->blog->settings->noodles->put(
'noodles_active', 'noodles_active',
false, false,
'boolean', 'boolean',
@ -31,7 +31,7 @@ try {
false, false,
true true
); );
$core->blog->settings->noodles->put( dcCore::app()->blog->settings->noodles->put(
'noodles_api', 'noodles_api',
'http://www.gravatar.com/', 'http://www.gravatar.com/',
'string', 'string',
@ -39,7 +39,7 @@ try {
false, false,
true true
); );
$core->blog->settings->noodles->put( dcCore::app()->blog->settings->noodles->put(
'noodles_image', 'noodles_image',
'', '',
'string', 'string',
@ -47,7 +47,7 @@ try {
false, false,
true true
); );
$core->blog->settings->noodles->put( dcCore::app()->blog->settings->noodles->put(
'noodles_object', 'noodles_object',
'', '',
'string', 'string',
@ -55,11 +55,11 @@ try {
false, false,
true true
); );
$core->setVersion('noodles', $new_version); dcCore::app()->setVersion('noodles', $new_version);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
return false; return false;

View file

@ -14,30 +14,30 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$__autoload['noodlesImg'] = dirname(__FILE__) . '/inc/lib.noodles.img.php'; Clearbricks::lib()->autoload(['noodlesImg' => __DIR__ . '/inc/lib.noodles.img.php']);
$__autoload['noodlesLibImagePath'] = dirname(__FILE__) . '/inc/lib.image.path.php'; Clearbricks::lib()->autoload(['noodlesLibImagePath' => __DIR__ . '/inc/lib.image.path.php']);
$core->blog->settings->addNamespace('noodles'); dcCore::app()->blog->settings->addNamespace('noodles');
$core->url->register( dcCore::app()->url->register(
'noodlesmodule', 'noodlesmodule',
'noodles', 'noodles',
'^noodles/(.+)$', '^noodles/(.+)$',
['urlNoodles', 'noodles'] ['urlNoodles', 'noodles']
); );
$core->url->register( dcCore::app()->url->register(
'noodlesservice', 'noodlesservice',
'noodle', 'noodle',
'^noodle/$', '^noodle/$',
['urlNoodles', 'service'] ['urlNoodles', 'service']
); );
$core->url->register( dcCore::app()->url->register(
'noodlescss', 'noodlescss',
'noodles.css', 'noodles.css',
'^noodles\.css', '^noodles\.css',
['urlNoodles', 'css'] ['urlNoodles', 'css']
); );
$core->url->register( dcCore::app()->url->register(
'noodlesjs', 'noodlesjs',
'noodles.js', 'noodles.js',
'^noodles\.js', '^noodles\.js',

View file

@ -14,19 +14,19 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
if (!$core->blog->settings->noodles->noodles_active) { if (!dcCore::app()->blog->settings->noodles->noodles_active) {
return null; return null;
} }
include dirname(__FILE__) . '/inc/_default_noodles.php'; include __DIR__ . '/inc/_default_noodles.php';
require_once dirname(__FILE__) . '/inc/_noodles_functions.php'; require_once __DIR__ . '/inc/_noodles_functions.php';
$core->addBehavior('publicHeadContent', ['publicNoodles', 'publicHeadContent']); dcCore::app()->addBehavior('publicHeadContent', ['publicNoodles', 'publicHeadContent']);
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__) . '/default-templates'); dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates');
global $__noodles; global $__noodles;
$__noodles = noodles::decode($core->blog->settings->noodles->noodles_object); $__noodles = noodles::decode(dcCore::app()->blog->settings->noodles->noodles_object);
if ($__noodles->isEmpty()) { if ($__noodles->isEmpty()) {
$__noodles = $__default_noodles; $__noodles = $__default_noodles;
@ -36,18 +36,18 @@ if ($__noodles->isEmpty()) {
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(dcCore::app());
} }
} }
class publicNoodles class publicNoodles
{ {
public static function publicHeadContent($core) public static function publicHeadContent()
{ {
echo echo
dcUtils::cssLoad($core->blog->url . $core->url->getURLFor('noodlescss')) . dcUtils::cssLoad(dcCore::app()->blog->url . dcCore::app()->url->getURLFor('noodlescss')) .
dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . '/js/jquery.noodles.js') . dcUtils::jsLoad(dcCore::app()->blog->url . dcCore::app()->url->getBase('noodlesmodule') . '/js/jquery.noodles.js') .
dcUtils::jsLoad($core->blog->url . $core->url->getURLFor('noodlesjs')); dcUtils::jsLoad(dcCore::app()->blog->url . dcCore::app()->url->getURLFor('noodlesjs'));
} }
} }
@ -55,7 +55,7 @@ class urlNoodles extends dcUrlHandlers
{ {
public static function css($args) public static function css($args)
{ {
global $core, $__noodles; global $__noodles;
$css = ''; $css = '';
foreach ($__noodles->noodles() as $noodle) { foreach ($__noodles->noodles() as $noodle) {
@ -74,7 +74,7 @@ class urlNoodles extends dcUrlHandlers
public static function js($args) public static function js($args)
{ {
global $core, $__noodles; global $__noodles;
$targets = []; $targets = [];
foreach ($__noodles->noodles() as $noodle) { foreach ($__noodles->noodles() as $noodle) {
@ -91,7 +91,7 @@ class urlNoodles extends dcUrlHandlers
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(dcCore::app()->blog->url . dcCore::app()->url->getBase('noodlesservice') . '/') . "'; \n" .
"\$.fn.noodles.defaults.service_func = '" . html::escapeJS('getNoodle') . "'; \n" . "\$.fn.noodles.defaults.service_func = '" . html::escapeJS('getNoodle') . "'; \n" .
implode("\n", $targets) . implode("\n", $targets) .
"})\n"; "})\n";
@ -101,8 +101,6 @@ class urlNoodles extends dcUrlHandlers
public static function service($args) public static function service($args)
{ {
global $core;
header('Content-Type: text/xml; charset=UTF-8'); header('Content-Type: text/xml; charset=UTF-8');
$rsp = new xmlTag('rsp'); $rsp = new xmlTag('rsp');
@ -110,23 +108,23 @@ class urlNoodles extends dcUrlHandlers
$i = !empty($_POST['noodleId']) ? $_POST['noodleId'] : null; $i = !empty($_POST['noodleId']) ? $_POST['noodleId'] : null;
$c = !empty($_POST['noodleContent']) ? $_POST['noodleContent'] : null; $c = !empty($_POST['noodleContent']) ? $_POST['noodleContent'] : null;
if (!$core->blog->settings->noodles->noodles_active) { if (!dcCore::app()->blog->settings->noodles->noodles_active) {
$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(true);
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(true);
return false; return false;
} }
try { try {
$__noodles = noodles::decode($core->blog->settings->noodles->noodles_object); $__noodles = noodles::decode(dcCore::app()->blog->settings->noodles->noodles_object);
if ($__noodles->isEmpty()) { if ($__noodles->isEmpty()) {
$__noodles = $GLOBALS['__default_noodles']; $__noodles = $GLOBALS['__default_noodles'];
@ -134,7 +132,7 @@ class urlNoodles extends dcUrlHandlers
} 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(true);
return false; return false;
} }
@ -142,7 +140,7 @@ class urlNoodles extends dcUrlHandlers
if (!$__noodles->exists($i)) { if (!$__noodles->exists($i)) {
$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(true);
return false; return false;
} }
@ -150,10 +148,10 @@ class urlNoodles extends dcUrlHandlers
$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 = dcCore::app()->blog->settings->noodles->noodles_image ?
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; urlencode(noodlesLibImagePath::getUrl('noodles')) : '';
$u = $core->blog->settings->noodles->noodles_api; $u = dcCore::app()->blog->settings->noodles->noodles_api;
if (empty($u)) { if (empty($u)) {
$u = 'http://www.gravatar.com/'; $u = 'http://www.gravatar.com/';
} }
@ -174,15 +172,13 @@ class urlNoodles extends dcUrlHandlers
$rsp->insertNode($im); $rsp->insertNode($im);
$rsp->status = 'ok'; $rsp->status = 'ok';
echo $rsp->toXML(1); echo $rsp->toXML(true);
exit; exit;
} }
public static function noodles($args) public static function noodles($args)
{ {
global $core; if (!dcCore::app()->blog->settings->noodles->noodles_active) {
if (!$core->blog->settings->noodles->noodles_active) {
self::p404(); self::p404();
return; return;
@ -213,12 +209,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' || dcCore::app()->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(' . dcCore::app()->blog->url . dcCore::app()->url->getBase('noodlesmodule') . '/',
file_get_contents($f) file_get_contents($f)
); );
} }
@ -231,7 +227,7 @@ class urlNoodles extends dcUrlHandlers
if (strstr($file, '..') !== false) { if (strstr($file, '..') !== false) {
return false; return false;
} }
$paths = $GLOBALS['core']->tpl->getPath(); $paths = dcCore::app()->tpl->getPath();
foreach ($paths as $path) { foreach ($paths as $path) {
if (preg_match('/tpl(\/|)$/', $path)) { if (preg_match('/tpl(\/|)$/', $path)) {

View file

@ -14,7 +14,7 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
require dirname(__FILE__) . '/class.noodles.php'; require __DIR__ . '/class.noodles.php';
global $__default_noodles; global $__default_noodles;
$__default_noodles = new noodles(); $__default_noodles = new noodles();
@ -38,7 +38,7 @@ $__default_noodles
->target('.post-title a') ->target('.post-title a')
->css('margin-right:2px;'); ->css('margin-right:2px;');
if ($core->plugins->moduleExists('widgets')) { if (dcCore::app()->plugins->moduleExists('widgets')) {
# Widget Selected entries # Widget Selected entries
$__default_noodles $__default_noodles
->add('bestof', __('Selected entries'), ['genericNoodles', 'postURL']) ->add('bestof', __('Selected entries'), ['genericNoodles', 'postURL'])
@ -60,8 +60,8 @@ if ($core->plugins->moduleExists('widgets')) {
} }
# Plugin auhtorMode # Plugin auhtorMode
if ($core->plugins->moduleExists('authorMode') if (dcCore::app()->plugins->moduleExists('authorMode')
&& $core->blog->settings->authormode->authormode_active && dcCore::app()->blog->settings->authormode->authormode_active
) { ) {
$__default_noodles $__default_noodles
->add('authorswidget', __('Authors widget'), ['authormodeNoodles', 'authors']) ->add('authorswidget', __('Authors widget'), ['authormodeNoodles', 'authors'])
@ -84,8 +84,8 @@ if ($core->plugins->moduleExists('authorMode')
} }
# Plugin rateIt # Plugin rateIt
if ($core->plugins->moduleExists('rateIt') if (dcCore::app()->plugins->moduleExists('rateIt')
&& $core->blog->settings->rateit->rateit_active && dcCore::app()->blog->settings->rateit->rateit_active
) { ) {
$__default_noodles $__default_noodles
->add('rateitpostsrank', __('Top rated entries'), ['genericNoodles', 'postURL']) ->add('rateitpostsrank', __('Top rated entries'), ['genericNoodles', 'postURL'])
@ -94,7 +94,7 @@ if ($core->plugins->moduleExists('rateIt')
} }
# Plugin lastpostsExtend # Plugin lastpostsExtend
if ($core->plugins->moduleExists('lastpostsExtend')) { if (dcCore::app()->plugins->moduleExists('lastpostsExtend')) {
$__default_noodles $__default_noodles
->add('lastpostsextend', __('Last entries (extend)'), ['genericNoodles', 'postURL']) ->add('lastpostsextend', __('Last entries (extend)'), ['genericNoodles', 'postURL'])
->target('.lastpostsextend ul li a') ->target('.lastpostsextend ul li a')
@ -102,4 +102,4 @@ if ($core->plugins->moduleExists('lastpostsExtend')) {
} }
# --BEHAVIOR-- initDefaultNoodles # --BEHAVIOR-- initDefaultNoodles
$core->callBehavior('initDefaultNoodles', $__default_noodles); dcCore::app()->callBehavior('initDefaultNoodles', $__default_noodles);

View file

@ -18,15 +18,13 @@ class genericNoodles
{ {
public static function postURL($noodle, $content = '') public static function postURL($noodle, $content = '')
{ {
global $core; $types = dcCore::app()->getPostTypes();
$reg = '@^' . str_replace('%s', '(.*?)', preg_quote(dcCore::app()->blog->url . $types['post']['public_url'])) . '$@';
$types = $core->getPostTypes();
$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 = dcCore::app()->blog->getPosts(['no_content' => 1, 'post_url' => urldecode($m[1]), 'limit' => 1]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return ''; return '';
} }
@ -38,7 +36,7 @@ class genericNoodles
# Miscellaneous # Miscellaneous
class othersNoodles class othersNoodles
{ {
public static function publicPosts($core, $noodle) public static function publicPosts($noodle)
{ {
if (!$noodle->active) { if (!$noodle->active) {
return null; return null;
@ -46,19 +44,19 @@ class othersNoodles
$bhv = $noodle->place == 'prepend' || $noodle->place == 'before' ? $bhv = $noodle->place == 'prepend' || $noodle->place == 'before' ?
'publicEntryBeforeContent' : 'publicEntryAfterContent'; 'publicEntryBeforeContent' : 'publicEntryAfterContent';
$core->addBehavior($bhv, ['othersNoodles', 'publicEntryContent']); dcCore::app()->addBehavior($bhv, ['othersNoodles', 'publicEntryContent']);
} }
public static function publicEntryContent() public static function publicEntryContent()
{ {
global $core,$_ctx,$__noodles; global $__noodles;
$m = $_ctx->posts->getAuthorEmail(false); $m = dcCore::app()->ctx->posts->getAuthorEmail(false);
$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 = dcCore::app()->blog->settings->noodles->noodles_image ?
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; urlencode(noodlesLibImagePath::getUrl('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 . '"' .
@ -66,7 +64,7 @@ class othersNoodles
'?s=' . $s . '&amp;r=' . $r . '&amp;d=' . $d . '" alt="" />'; '?s=' . $s . '&amp;r=' . $r . '&amp;d=' . $d . '" alt="" />';
} }
public static function publicComments($core, $noodle) public static function publicComments($noodle)
{ {
if (!$noodle->active) { if (!$noodle->active) {
return null; return null;
@ -75,19 +73,19 @@ class othersNoodles
$bhv = $noodle->place == 'prepend' || $noodle->place == 'before' ? $bhv = $noodle->place == 'prepend' || $noodle->place == 'before' ?
'publicCommentBeforeContent' : 'publicCommentAfterContent'; 'publicCommentBeforeContent' : 'publicCommentAfterContent';
$core->addBehavior($bhv, ['othersNoodles', 'publicCommentContent']); dcCore::app()->addBehavior($bhv, ['othersNoodles', 'publicCommentContent']);
} }
public static function publicCommentContent() public static function publicCommentContent()
{ {
global $core,$_ctx,$__noodles; global $__noodles;
$m = $_ctx->comments->getEmail(false); $m = dcCore::app()->ctx->comments->getEmail(false);
$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 = dcCore::app()->blog->settings->noodles->noodles_image ?
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; urlencode(noodlesLibImagePath::getUrl('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 . '"' .
@ -101,13 +99,11 @@ class widgetsNoodles
{ {
public static function lastcomments($noodle, $content = '') public static function lastcomments($noodle, $content = '')
{ {
global $core;
$ok = preg_match('@\#c([0-9]+)$@', urldecode($content), $m); $ok = preg_match('@\#c([0-9]+)$@', urldecode($content), $m);
if (!$ok || !$m[1]) { if (!$ok || !$m[1]) {
return ''; return '';
} }
$rs = $core->blog->getComments(['no_content' => 1, 'comment_id' => $m[1], 'limit' => 1]); $rs = dcCore::app()->blog->getComments(['no_content' => 1, 'comment_id' => $m[1], 'limit' => 1]);
if (!$rs->isEmpty()) { if (!$rs->isEmpty()) {
return $rs->comment_email; return $rs->comment_email;
} }
@ -121,13 +117,11 @@ class authormodeNoodles
{ {
public static function authors($noodle, $content = '') public static function authors($noodle, $content = '')
{ {
global $core;
$ok = preg_match('@\/([^\/]*?)$@', $content, $m); $ok = preg_match('@\/([^\/]*?)$@', $content, $m);
if (!$ok || !$m[1]) { if (!$ok || !$m[1]) {
return ''; return '';
} }
$rs = $core->getUser($m[1]); $rs = dcCore::app()->getUser($m[1]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return ''; return '';
} }
@ -135,29 +129,29 @@ class authormodeNoodles
return $rs->user_email; return $rs->user_email;
} }
public static function author($core, $noodle) public static function author($noodle)
{ {
if ($noodle->active) { if ($noodle->active) {
$core->addBehavior('publicHeadContent', ['authormodeNoodles', 'publicHeadContent']); dcCore::app()->addBehavior('publicHeadContent', ['authormodeNoodles', 'publicHeadContent']);
} }
} }
public static function publicHeadContent() public static function publicHeadContent()
{ {
global $core, $_ctx, $__noodles; global $__noodles;
if ($_ctx->current_tpl != 'author.html') { if (dcCore::app()->ctx->current_tpl != 'author.html') {
return null; return null;
} }
$id = $_ctx->users->user_id; $id = dcCore::app()->ctx->users->user_id;
$u = $core->getUser($id); $u = dcCore::app()->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 = dcCore::app()->blog->settings->noodles->noodles_image ?
urlencode(noodlesLibImagePath::getUrl($core, 'noodles')) : ''; urlencode(noodlesLibImagePath::getUrl('noodles')) : '';
echo echo
'<script type="text/javascript">' . "\n" . '<script type="text/javascript">' . "\n" .

View file

@ -87,7 +87,7 @@ class noodle
'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)
@ -122,13 +122,13 @@ class noodle
return !empty($this->js_callback); return !empty($this->js_callback);
} }
public function phpCallback($core) public function phpCallback()
{ {
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, $this);
} }
public function hasPhpCallback() public function hasPhpCallback()

View file

@ -18,10 +18,10 @@ class noodlesLibImagePath
{ {
public static $version = '1.1'; public static $version = '1.1';
public static function getArray($core, $m = '') public static function getArray($m = '')
{ {
if (!$core->plugins->moduleExists($m) if (!dcCore::app()->plugins->moduleExists($m)
|| !$core->url->getBase($m . 'module') || !dcCore::app()->url->getBase($m . 'module')
) { ) {
return [ return [
'theme' => ['dir' => null, 'url' => null], 'theme' => ['dir' => null, 'url' => null],
@ -32,23 +32,23 @@ class noodlesLibImagePath
return [ return [
'theme' => [ 'theme' => [
'dir' => path::real($core->blog->themes_path . '/' . $core->blog->settings->system->theme . '/img') . '/' . $m . '-default-image.png', 'dir' => path::real(dcCore::app()->blog->themes_path . '/' . dcCore::app()->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' => dcCore::app()->blog->settings->system->themes_url . dcCore::app()->blog->settings->system->theme . '/img/' . $m . '-default-image.png',
], ],
'public' => [ 'public' => [
'dir' => path::real($core->blog->public_path) . '/' . $m . '-default-image.png', 'dir' => path::real(dcCore::app()->blog->public_path) . '/' . $m . '-default-image.png',
'url' => $core->blog->host . path::clean($core->blog->settings->system->public_url) . '/' . $m . '-default-image.png' 'url' => dcCore::app()->blog->host . path::clean(dcCore::app()->blog->settings->system->public_url) . '/' . $m . '-default-image.png',
], ],
'module' => [ 'module' => [
'dir' => path::real($core->plugins->moduleRoot($m) . '/default-templates/img') . '/' . $m . '-default-image.png', 'dir' => path::real(dcCore::app()->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' => dcCore::app()->blog->url . dcCore::app()->url->getBase($m . 'module') . '/img/' . $m . '-default-image.png',
] ],
]; ];
} }
public static function getUrl($core, $m = '') public static function getUrl($m = '')
{ {
$files = self::getArray($core, $m); $files = self::getArray($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'];
@ -58,9 +58,9 @@ class noodlesLibImagePath
return null; return null;
} }
public static function getPath($core, $m = '') public static function getPath($m = '')
{ {
$files = self::getArray($core, $m); $files = self::getArray($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'];
@ -70,9 +70,9 @@ class noodlesLibImagePath
return null; return null;
} }
public static function getSize($core, $m = '') public static function getSize($m = '')
{ {
if (!($img = self::getPath($core, $m))) { if (!($img = self::getPath($m))) {
return ['w' => 16, 'h' => 16]; return ['w' => 16, 'h' => 16];
} }
$info = getimagesize($img); $info = getimagesize($img);

View file

@ -14,11 +14,11 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
dcPage::check('admin'); dcPage::check(dcAuth::PERMISSION_CONTENT_ADMIN);
include dirname(__FILE__) . '/inc/_default_noodles.php'; include __DIR__ . '/inc/_default_noodles.php';
$s = $core->blog->settings->noodles; $s = dcCore::app()->blog->settings->noodles;
$__noodles = noodles::decode($s->noodles_object); $__noodles = noodles::decode($s->noodles_object);
if ($__noodles->isEmpty()) { if ($__noodles->isEmpty()) {
@ -32,11 +32,11 @@ if ($__noodles->isEmpty()) {
$__noodles->set($id, $noodle); $__noodles->set($id, $noodle);
} }
} }
$public_path = path::real($core->blog->public_path); $public_path = path::real(dcCore::app()->blog->public_path);
if (!is_dir($public_path) || !is_writable($public_path)) { if (!is_dir($public_path) || !is_writable($public_path)) {
$public_path = false; $public_path = false;
} }
$default_images = files::scandir(dirname(__FILE__) . '/default-templates/img/'); $default_images = files::scandir(__DIR__ . '/default-templates/img/');
if (!is_array($default_images)) { if (!is_array($default_images)) {
$default_images = []; $default_images = [];
} }
@ -44,20 +44,20 @@ $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,
@ -68,7 +68,7 @@ $combo_size = [
'64px' => 64, '64px' => 64,
'92px' => 92, '92px' => 92,
'128px' => 128, '128px' => 128,
'256px' => 256 '256px' => 256,
]; ];
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
@ -130,24 +130,24 @@ if (!empty($_POST['save'])) {
} }
$s->put('noodles_object', $__noodles->encode(), 'string'); $s->put('noodles_object', $__noodles->encode(), 'string');
$core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice(__('Configuration successfully updated')); dcAdminNotices::addSuccessNotice(__('Configuration successfully updated'));
$core->adminurl->redirect('admin.plugin.noodles'); dcCore::app()->adminurl->redirect('admin.plugin.noodles');
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
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(dcCore::app()->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') . dcCore::app()->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>
@ -188,7 +188,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('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));
@ -197,7 +197,7 @@ if (null !== ($default_image_path = noodlesLibImagePath::getPath($core, 'noodles
<p>' . form::radio(['noodles_image', 'public_image'], 'existing', !empty($default_image)) . ' <p>' . form::radio(['noodles_image', 'public_image'], 'existing', !empty($default_image)) . '
<label class="classic" for="public_image">' . __('Blog default image') . '</label></p> <label class="classic" for="public_image">' . __('Blog default image') . '</label></p>
<div class="two-box"><div class="box"> <div class="two-box"><div class="box">
<p><img src="' . noodlesLibImagePath::getUrl($core, 'noodles') . '?' . rand() . '" alt="" /></p> <p><img src="' . noodlesLibImagePath::getUrl('noodles') . '?' . rand() . '" alt="" /></p>
</div><div class="box"> </div><div class="box">
<p>' . $sz[0] . 'x' . $sz[1] . '<br />' . $sz[2] . '</p> <p>' . $sz[0] . 'x' . $sz[1] . '<br />' . $sz[2] . '</p>
</div></div> </div></div>
@ -265,7 +265,7 @@ echo '
<p class="clear"> <p class="clear">
<input type="submit" value="' . __('Save') . ' (s)" accesskey="s" name="save" /> ' . <input type="submit" value="' . __('Save') . ' (s)" accesskey="s" name="save" /> ' .
$core->formNonce() . '</p> dcCore::app()->formNonce() . '</p>
</form> </form>
</body></html>'; </body></html>';