limit settings to super admin only

master
Jean-Christian Paul Denis 2023-08-20 11:26:08 +02:00
parent 7f0cae3b8f
commit b25c9819c6
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 177 additions and 200 deletions

View File

@ -45,8 +45,6 @@ class Backend extends Process
'UninstallerCleanersConstruct' => function ($uninstaller_stack) { 'UninstallerCleanersConstruct' => function ($uninstaller_stack) {
UninstallCleaner::init($uninstaller_stack); UninstallCleaner::init($uninstaller_stack);
}, },
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'],
]); ]);
// not active // not active

View File

@ -16,18 +16,12 @@ namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject; use ArrayObject;
use dcCore; use dcCore;
use dcSettings;
use Dotclear\Core\Backend\Favorites; use Dotclear\Core\Backend\Favorites;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox,
Div, Div,
Input,
Label,
Link, Link,
Number,
Para, Para,
Select,
Text Text
}; };
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
@ -37,196 +31,6 @@ use Dotclear\Helper\Html\Html;
*/ */
class BackendBehaviors class BackendBehaviors
{ {
/**
* Module settings save.
*
* Used in blog settings and module config.
*/
public static function adminBeforeBlogSettingsUpdate(?dcSettings $blog_settings): void
{
// read settings
$s = ZoneclearFeedServer::instance()->settings;
// write settings
foreach ($s->dump() as $key => $value) {
$s->set($key, $_POST[My::id() . $key] ?? $value);
}
}
/**
* Module settings form.
*
* Used in blog settings and module config.
*/
public static function adminBlogPreferencesFormV2(?dcSettings $blog_settings): void
{
// nullsafe
if (is_null(dcCore::app()->blog)) {
return;
}
$z = ZoneclearFeedServer::instance();
$s = $z->settings;
$msg = [];
if (!is_writable(DC_TPL_CACHE)) {
$msg[] = (new Para())
->class('error')
->text(__('Dotclear cache is not writable or not well configured!'));
}
if ($s->pub_active) {
$msg[] = (new Para())
->items([
(new Link())
->class('onblog_link outgoing')
->text(__('View the public list of feeds') . ' <img alt="" src="images/outgoing-link.svg">')
->href(dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage')),
]);
}
$titles = [];
foreach ($z->getPublicUrlTypes() as $k => $v) {
$titles[] = (new Para(null, 'li'))
->items([
(new Checkbox([My::id() . 'post_title_redir[]', My::id() . 'post_title_redir_' . $v], in_array($v, $s->post_title_redir)))
->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'post_title_redir_' . $v),
]);
}
$contents = [];
foreach ($z->getPublicUrlTypes() as $k => $v) {
$contents[] = (new Para(null, 'li'))
->items([
(new Checkbox([My::id() . 'post_full_tpl_[]', My::id() . 'post_full_tpl_' . $v], in_array($v, $s->post_full_tpl)))
->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'post_full_tpl_' . $v),
]);
}
echo
(new Div())->class('fieldset')
->items([
!is_null($blog_settings) ?
(new Text('h4', My::name()))
->id('disclaimerParam') :
(new Text()),
(new Div())
->items($msg),
(new Para())
->items([
(new Checkbox(My::id() . 'active', $s->active))
->value(1),
(new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'active'),
]),
(new Div())
->class('clear two-cols')
->items([
(new Div())
->class('fieldset col')
->items([
(new Para())
->items([
(new Label(__('Status of new posts:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'post_status_new'),
(new Select(My::id() . 'post_status_new'))
->items(Combo::postsStatus())
->default((string) $s->post_status_new),
]),
(new Para())
->items([
(new Label(__('Owner of entries created by the feed server:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'user'),
(new Select(My::id() . 'user'))
->items($z->getAllBlogAdmins())
->default($s->user),
]),
(new Para())
->items([
(new Label(__('How to transform imported tags:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'tag_case'),
(new Select(My::id() . 'tag_case'))
->items(Combo::tagCase())
->default((string) $s->tag_case),
]),
]),
(new Div())
->class('fieldset col')
->items([
(new Para())
->items([
(new Label(__('Update feeds on public side:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'bhv_pub_upd'),
(new Select(My::id() . 'bhv_pub_upd'))
->items(Combo::pubUpdate())
->default((string) $s->bhv_pub_upd),
]),
(new Para())
->items([
(new Label(__('Number of feeds to update at one time:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'update_limit'),
(new Number(My::id() . 'update_limit'))
->min(0)
->max(20)
->value($s->update_limit),
]),
(new Para())
->items([
(new Checkbox(My::id() . 'keep_empty_feed', $s->keep_empty_feed))
->value(1),
(new Label(__('Keep active empty feeds'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'keep_empty_feed'),
]),
(new Para())
->items([
(new Checkbox(My::id() . 'pub_active', $s->pub_active))
->value(1),
(new Label(__('Enable public page'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'pub_active'),
]),
]),
]),
(new Div())
->class('two-cols')
->items([
(new Div())
->class('fieldset col')
->items([
(new Text('p', __('Redirect to original post on:'))),
(new Para(null, 'ul'))
->items($titles),
]),
(new Div())
->class('fieldset col')
->items([
(new Text('p', __('Show full content on:'))),
(new Para(null, 'ul'))
->items($contents),
]),
]),
(new Div())->class('clear')->items(
!is_null($blog_settings) && $s->active ?
[(new Para())
->items([
(new Link())
->href(My::manageUrl())
->text(__('Configure feeds')),
])] :
[],
),
(new Div())->class('clear'),
])
->render();
}
/** /**
* User dashboard favorites icon. * User dashboard favorites icon.
*/ */

View File

@ -21,6 +21,16 @@ use Dotclear\Core\Backend\{
Page Page
}; };
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
Label,
Link,
Number,
Para,
Select,
Text
};
use Exception; use Exception;
/** /**
@ -45,7 +55,17 @@ class Config extends Process
} }
try { try {
BackendBehaviors::adminBeforeBlogSettingsUpdate(null); // read settings
$s = ZoneclearFeedServer::instance()->settings;
// write settings
foreach ($s->dump() as $key => $value) {
if (is_bool($value)) {
$s->set($key, !empty($_POST[My::id() . $key]));
} else {
$s->set($key, $_POST[My::id() . $key] ?: $value);
}
}
Notices::addSuccessNotice( Notices::addSuccessNotice(
__('Configuration has been successfully updated.') __('Configuration has been successfully updated.')
@ -68,7 +88,162 @@ class Config extends Process
return; return;
} }
BackendBehaviors::adminBlogPreferencesFormV2(null); $z = ZoneclearFeedServer::instance();
$s = $z->settings;
$msg = [];
if (!is_writable(DC_TPL_CACHE)) {
$msg[] = (new Para())
->class('error')
->text(__('Dotclear cache is not writable or not well configured!'));
}
if ($s->pub_active) {
$msg[] = (new Para())
->items([
(new Link())
->class('onblog_link outgoing')
->text(__('View the public list of feeds') . ' <img alt="" src="images/outgoing-link.svg">')
->href(dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage')),
]);
}
$titles = [];
foreach ($z->getPublicUrlTypes() as $k => $v) {
$titles[] = (new Para(null, 'li'))
->items([
(new Checkbox([My::id() . 'post_title_redir[]', My::id() . 'post_title_redir_' . $v], in_array($v, $s->post_title_redir)))
->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'post_title_redir_' . $v),
]);
}
$contents = [];
foreach ($z->getPublicUrlTypes() as $k => $v) {
$contents[] = (new Para(null, 'li'))
->items([
(new Checkbox([My::id() . 'post_full_tpl[]', My::id() . 'post_full_tpl_' . $v], in_array($v, $s->post_full_tpl)))
->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'post_full_tpl_' . $v),
]);
}
echo
(new Div())
->items([
(new Div())
->items($msg),
(new Para())
->items([
(new Checkbox(My::id() . 'active', $s->active))
->value(1),
(new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'active'),
]),
(new Div())
->class('clear two-cols')
->items([
(new Div())
->class('fieldset col')
->items([
(new Para())
->items([
(new Label(__('Status of new posts:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'post_status_new'),
(new Select(My::id() . 'post_status_new'))
->items(Combo::postsStatus())
->default((string) $s->post_status_new),
]),
(new Para())
->items([
(new Label(__('Owner of entries created by the feed server:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'user'),
(new Select(My::id() . 'user'))
->items($z->getAllBlogAdmins())
->default($s->user),
]),
(new Para())
->items([
(new Label(__('How to transform imported tags:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'tag_case'),
(new Select(My::id() . 'tag_case'))
->items(Combo::tagCase())
->default((string) $s->tag_case),
]),
]),
(new Div())
->class('fieldset col')
->items([
(new Para())
->items([
(new Label(__('Update feeds on public side:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'bhv_pub_upd'),
(new Select(My::id() . 'bhv_pub_upd'))
->items(Combo::pubUpdate())
->default((string) $s->bhv_pub_upd),
]),
(new Para())
->items([
(new Label(__('Number of feeds to update at one time:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'update_limit'),
(new Number(My::id() . 'update_limit'))
->min(0)
->max(20)
->value($s->update_limit),
]),
(new Para())
->items([
(new Checkbox(My::id() . 'keep_empty_feed', $s->keep_empty_feed))
->value(1),
(new Label(__('Keep active empty feeds'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'keep_empty_feed'),
]),
(new Para())
->items([
(new Checkbox(My::id() . 'pub_active', $s->pub_active))
->value(1),
(new Label(__('Enable public page'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'pub_active'),
]),
]),
]),
(new Div())
->class('two-cols')
->items([
(new Div())
->class('fieldset col')
->items([
(new Text('p', __('Redirect to original post on:'))),
(new Para(null, 'ul'))
->items($titles),
]),
(new Div())
->class('fieldset col')
->items([
(new Text('p', __('Show full content on:'))),
(new Para(null, 'ul'))
->items($contents),
]),
]),
(new Div())->class('clear')->items(
$s->active ?
[(new Para())
->items([
(new Link())
->href(My::manageUrl())
->text(__('Configure feeds')),
])] :
[],
),
(new Div())->class('clear'),
])
->render();
Page::helpBlock('zoneclearFeedServer'); Page::helpBlock('zoneclearFeedServer');
} }