use abstract plugin and settings name

This commit is contained in:
Jean-Christian Denis 2022-12-17 17:02:30 +01:00
parent f1dc193c81
commit 057d865766
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
4 changed files with 18 additions and 18 deletions

View file

@ -14,11 +14,11 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return; return;
} }
# widget
require_once __DIR__ . '/_widgets.php';
# settings namespace # settings namespace
dcCore::app()->blog->settings->addNamespace('saba'); dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
# widget
require __DIR__ . '/_widgets.php';
# behaviors # behaviors
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function ($blog_settings) { dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function ($blog_settings) {
@ -26,10 +26,10 @@ dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function ($blog_setting
'<div class="fieldset">' . '<div class="fieldset">' .
'<h4 id="saba_params">' . __('Search Across Blog Archive') . '</h4>' . '<h4 id="saba_params">' . __('Search Across Blog Archive') . '</h4>' .
'<p><label class="classic">' . '<p><label class="classic">' .
form::checkbox('saba_active', '1', (bool) $blog_settings->saba->active) . form::checkbox('saba_active', '1', (bool) $blog_settings->__get(basename(__DIR__))->active) .
__('Enable advanced search on this blog') . '</label></p>' . __('Enable advanced search on this blog') . '</label></p>' .
'<p><label class="classic">' . '<p><label class="classic">' .
form::checkbox('saba_error', '1', (bool) $blog_settings->saba->error) . form::checkbox('saba_error', '1', (bool) $blog_settings->_get(basename(__DIR__))->error) .
__('Enable suggestion for page 404') . '</label></p>' . __('Enable suggestion for page 404') . '</label></p>' .
'<p class="form-note">' . '<p class="form-note">' .
__('This suggests visitors some posts on page 404.') . __('This suggests visitors some posts on page 404.') .
@ -38,6 +38,6 @@ dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function ($blog_setting
}); });
dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function ($blog_settings) { dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function ($blog_settings) {
$blog_settings->saba->put('active', !empty($_POST['saba_active'])); $blog_settings->__get(basename(__DIR__))->put('active', !empty($_POST['saba_active']));
$blog_settings->saba->put('error', !empty($_POST['saba_error'])); $blog_settings->__get(basename(__DIR__))->put('error', !empty($_POST['saba_error']));
}); });

View file

@ -25,8 +25,8 @@ $this->registerModule(
dcAuth::PERMISSION_ADMIN, dcAuth::PERMISSION_ADMIN,
]), ]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/saba', 'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
'details' => 'https://plugins.dotaddict.org/dc2/details/saba', 'details' => 'https://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
'repository' => 'https://raw.githubusercontent.com/JcDenis/saba/master/dcstore.xml', 'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
] ]
); );

View file

@ -15,9 +15,9 @@ if (!defined('DC_RC_PATH')) {
} }
# setting # setting
dcCore::app()->blog->settings->addNamespace('saba'); dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
if (!dcCore::app()->blog->settings->saba->active) { if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active) {
return null; return null;
} }
@ -25,7 +25,7 @@ if (!dcCore::app()->blog->settings->saba->active) {
l10n::set(__DIR__ . '/locales/' . dcCore::app()->lang . '/public'); l10n::set(__DIR__ . '/locales/' . dcCore::app()->lang . '/public');
# widget # widget
require_once __DIR__ . '/_widgets.php'; require __DIR__ . '/_widgets.php';
# template path # template path
dcCore::app()->tpl->setPath( dcCore::app()->tpl->setPath(
@ -48,7 +48,7 @@ dcCore::app()->addBehavior(
); );
# url # url
if (dcCore::app()->blog->settings->saba->error) { if (dcCore::app()->blog->settings->__get(basename(__DIR__))->error) {
dcCore::app()->url->registerError(['urlSaba', 'error']); dcCore::app()->url->registerError(['urlSaba', 'error']);
} }

View file

@ -76,10 +76,10 @@ class sabaWidget
public static function getWidget($w) public static function getWidget($w)
{ {
dcCore::app()->blog->settings->addNamespace('saba'); dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
if (!dcCore::app()->blog->settings->saba->active if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active
|| !dcCore::app()->blog->settings->saba->error && dcCore::app()->url->type == '404' || !dcCore::app()->blog->settings->__get(basename(__DIR__))->error && dcCore::app()->url->type == '404'
|| $w->offline || $w->offline
) { ) {
return; return;