move settings to blog pref

master
Jean-Christian Paul Denis 2021-10-30 10:02:04 +02:00
parent f49ad89d6c
commit 1d91b68081
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
4 changed files with 34 additions and 69 deletions

View File

@ -28,6 +28,8 @@ if ($core->blog->settings->postwidgettext->postwidgettext_active) {
);
$core->addBehavior('adminDashboardFavorites', ['postWidgetTextDashboard', 'favorites']);
$core->addBehavior('adminBlogPreferencesForm', ['postWidgetTextAdmin', 'adminBlogPreferencesForm']);
$core->addBehavior('adminBeforeBlogSettingsUpdate', ['postWidgetTextAdmin', 'adminBeforeBlogSettingsUpdate']);
}
# Pref
$core->addBehavior('adminFiltersLists', ['postWidgetTextAdmin', 'adminFiltersLists']);

View File

@ -1,68 +0,0 @@
<?php
/**
* @brief postWidgetText, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_MODULE')) {
return null;
}
dcPage::check('admin');
$redir = empty($_REQUEST['redir']) ?
$list->getURL().'#plugins' : $_REQUEST['redir'];
# -- Get settings --
$core->blog->settings->addNamespace('postwidgettext');
$s = $core->blog->settings->postwidgettext;
$active = (boolean) $s->postwidgettext_active;
$importexport_active = (boolean) $s->postwidgettext_importexport_active;
# -- Set settings --
if (!empty($_POST['save'])) {
try {
$active = !empty($_POST['active']);
$importexport_active = !empty($_POST['importexport_active']);
$s->put('postwidgettext_active', $active);
$s->put('postwidgettext_importexport_active', $importexport_active);
$core->blog->triggerBlog();
dcPage::addSuccessNotice(
__('Configuration successfully updated')
);
http::redirect(
$list->getURL('module=postWidgetText&conf=1&redir='.
$list->getRedir())
);
}
catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
# -- Display form --
echo '
<div class="fieldset">
<h4>'.__('Activation').'</h4>
<p><label for="active">'.
form::checkbox('active', 1, $active).
__('Enable plugin').'</label></p>
<p><label for="importexport_active">'.
form::checkbox('importexport_active', 1, $importexport_active).
__('Enable import/export behaviors').'</label></p>
</div>';

View File

@ -26,6 +26,9 @@ $this->registerModule(
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/postWidgetText',
'details' => 'https://plugins.dotaddict.org/dc2/details/postWidgetText',
'repository' => 'https://raw.githubusercontent.com/JcDenis/postWidgetText/master/dcstore.xml'
'repository' => 'https://raw.githubusercontent.com/JcDenis/postWidgetText/master/dcstore.xml',
'settings' => [
'blog' => '#params.pwt_params'
]
]
);

View File

@ -43,6 +43,34 @@ class postWidgetTextAdmin
];
}
public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings)
{
echo '
<div class="fieldset">
<h4 id="pwt_params">' . __('Post widget text') . '</h4>
<div class="two-cols">
<div class="col">
<p><label for="active">' .
form::checkbox('active', 1, (boolean) $blog_settings->postwidgettext->postwidgettext_active).
__('Enable plugin') . '</label></p>
</div>
<div class="col">
<p><label for="importexport_active">' .
form::checkbox('importexport_active', 1, (boolean) $blog_settings->postwidgettext->postwidgettext_importexport_active).
__('Enable import/export behaviors') . '</label></p>
</div>
</div>
<br class="clear" />
</div>';
}
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
{
$blog_settings->postwidgettext->put('postwidgettext_active', !empty($_POST['active']));
$blog_settings->postwidgettext->put('postwidgettext_importexport_active', !empty($_POST['importexport_active']));
}
public static function headers()
{
return dcPage::jsLoad(dcPage::getPF('postWidgetText/js/post.js'));