move settings to blog pref

This commit is contained in:
Jean-Christian Paul Denis 2021-08-24 01:26:11 +02:00
parent 7ed5a1542c
commit 8e415c47ee
4 changed files with 78 additions and 109 deletions

View File

@ -1,6 +1,7 @@
periodical 2021.08.xx periodical 2021.08.xx
* update license * update license
* update php code to PSR-2 style and short array * update php code to PSR-2 style and short array
* move settings to blog pref
periodical 2013.11.11 periodical 2013.11.11
* Switch to Dotclear 2.6 * Switch to Dotclear 2.6

View File

@ -15,7 +15,16 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$core->blog->settings->addNamespace('periodical'); $core->blog->settings->addNamespace('periodical');
$core->addBehavior(
'adminBlogPreferencesForm',
['adminPeriodical', 'adminBlogPreferencesForm']
);
$core->addBehavior(
'adminBeforeBlogSettingsUpdate',
['adminPeriodical', 'adminBeforeBlogSettingsUpdate']
);
if ($core->blog->settings->periodical->periodical_active) { if ($core->blog->settings->periodical->periodical_active) {
@ -70,6 +79,73 @@ class adminPeriodical
{ {
public static $combo_period = null; public static $combo_period = null;
/**
* Add settings to blog preference
*
* @param dcCore $core dcCore instance
* @param dcSettings $blog_settings dcSettings instance
*/
public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings)
{
$sortby_combo = [
__('Create date') => 'post_creadt',
__('Date') => 'post_dt',
__('Id') => 'post_id'
];
$order_combo = [
__('Descending') => 'desc',
__('Ascending') => 'asc'
];
$s_active = (boolean) $blog_settings->periodical->periodical_active;
$s_upddate = (boolean) $blog_settings->periodical->periodical_upddate;
$s_updurl = (boolean) $blog_settings->periodical->periodical_updurl;
$e_order = (string) $blog_settings->periodical->periodical_pub_order;
$e_order = explode(' ', $e_order);
$s_sortby = in_array($e_order[0], $sortby_combo) ? $e_order[0] : 'post_dt';
$s_order = isset($e_order[1]) && strtolower($e_order[1]) == 'desc' ? 'desc' : 'asc';
echo
'<div class="fieldset"><h4 id="fac_params">' . __('Periodical') . '</h4>' .
'<div class="two-cols">' .
'<div class="col">' .
'<h5>' . __('Activation') . '</h5>' .
'<p><label class="classic" for="periodical_active">' .
form::checkbox('periodical_active', 1, $s_active) .
__('Enable plugin') . '</label></p>' .
'<h5>' . __('Dates of published entries') . '</h5>' .
'<p><label for="periodical_upddate">' .
form::checkbox('periodical_upddate', 1, $s_upddate) .
__('Update post date') . '</label></p>' .
'<p><label for="periodical_updurl">' .
form::checkbox('periodical_updurl', 1, $s_updurl) .
__('Update post url') . '</label></p>' .
'</div>' .
'<div class="col">' .
'<h5>' . __('Order of publication of entries') . '</h5>' .
'<p><label for="periodical_sortby">'.__('Order by:') . '</label>' .
form::combo('periodical_sortby', $sortby_combo, $s_sortby) . '</p>' .
'<p><label for="periodical_order">'.__('Sort:').'</label>' .
form::combo('periodical_order', $order_combo, $s_order) . '</p>' .
'</div>' .
'</div>' .
'<br class="clear" />' .
'</div>';
}
/**
* Save blog settings
*
* @param dcSettings $blog_settings dcSettings instance
*/
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
{
$blog_settings->periodical->put('periodical_active', !empty($_POST['periodical_active']));
$blog_settings->periodical->put('periodical_upddate', !empty($_POST['periodical_upddate']));
$blog_settings->periodical->put('periodical_updurl', !empty($_POST['periodical_updurl']));
$blog_settings->periodical->put('periodical_pub_order', $_POST['periodical_sortby'] . ' ' . $_POST['periodical_order']);
}
/** /**
* Favorites. * Favorites.
* *

View File

@ -1,105 +0,0 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of periodical, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_MODULE')) {
return null;
}
$redir = empty($_REQUEST['redir']) ?
$list->getURL() . '#plugins' : $_REQUEST['redir'];
# -- Combos --
$sortby_combo = [
__('Create date') => 'post_creadt',
__('Date') => 'post_dt',
__('Id') => 'post_id'
];
$order_combo = [
__('Descending') => 'desc',
__('Ascending') => 'asc'
];
# -- Get settings --
$core->blog->settings->addNamespace('periodical');
$s = $core->blog->settings->periodical;
$s_active = (boolean) $s->periodical_active;
$s_upddate = (boolean) $s->periodical_upddate;
$s_updurl = (boolean) $s->periodical_updurl;
$e_order = (string) $s->periodical_pub_order;
$e_order = explode(' ', $e_order);
$s_sortby = in_array($e_order[0], $sortby_combo) ? $e_order[0] : 'post_dt';
$s_order = isset($e_order[1]) && strtolower($e_order[1]) == 'desc' ? 'desc' : 'asc';
# -- Set settings --
if (!empty($_POST['save'])) {
try {
$s_active = !empty($_POST['s_active']);
$s_upddate = !empty($_POST['s_upddate']);
$s_updurl = !empty($_POST['s_updurl']);
$s_sortby = $_POST['s_sortby'];
$s_order = $_POST['s_order'];
$s->put('periodical_active', $s_active);
$s->put('periodical_upddate', $s_upddate);
$s->put('periodical_updurl', $s_updurl);
$s->put('periodical_pub_order', $s_sortby . ' ' . $s_order);
$core->blog->triggerBlog();
dcPage::addSuccessNotice(
__('Configuration has been successfully updated.')
);
http::redirect($list->getURL(
'module=periodical&conf=1&redir=' . $list->getRedir()
));
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
# -- Display form --
echo '
<div class="fieldset">
<h4>' . __('Activation') . '</h4>
<p><label class="classic" for="s_active">' .
form::checkbox('s_active', 1, $s_active) .
__('Enable plugin') . '</label></p>
</div>
<div class="fieldset">
<h4>' . __('Dates of published entries') . '</h4>
<p><label for="s_upddate">' .
form::checkbox('s_upddate', 1, $s_upddate) .
__('Update post date') . '</label></p>
<p><label for="s_updurl">' .
form::checkbox('s_updurl', 1, $s_updurl) .
__('Update post url') . '</label></p>
</div>
<div class="fieldset">
<h4>' . __('Order of publication of entries') . '</h4>
<p><label for="s_sortby">'.__('Order by:') . '</label>' .
form::combo('s_sortby', $sortby_combo, $s_sortby) . '</p>
<p><label for="s_order">'.__('Sort:').'</label>' .
form::combo('s_order', $order_combo, $s_order) . '</p>
</div>';

View File

@ -812,9 +812,6 @@ dcPage::helpBlock('periodical');
# Page footer # Page footer
echo echo
'<hr class="clear"/><p class="right modules"> '<hr class="clear"/><p class="right modules">
<a class="module-config" ' .
'href="plugins.php?module=periodical&amp;conf=1&amp;redir=' .
urlencode('plugin.php?p=periodical') . '">' . __('Configuration') . '</a> -
periodical - '. $core->plugins->moduleInfo('periodical', 'version') . '&nbsp; periodical - '. $core->plugins->moduleInfo('periodical', 'version') . '&nbsp;
<img alt="' . __('periodical') . '" src="index.php?pf=periodical/icon.png" /> <img alt="' . __('periodical') . '" src="index.php?pf=periodical/icon.png" />
</p> </p>