diff --git a/src/Backend.php b/src/Backend.php index c54b6e5..71f0cac 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -45,8 +45,6 @@ class Backend extends Process 'UninstallerCleanersConstruct' => function ($uninstaller_stack) { UninstallCleaner::init($uninstaller_stack); }, - 'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'], - 'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'], ]); // not active diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 2d1ab64..e70387c 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -16,18 +16,12 @@ namespace Dotclear\Plugin\zoneclearFeedServer; use ArrayObject; use dcCore; -use dcSettings; use Dotclear\Core\Backend\Favorites; use Dotclear\Database\MetaRecord; use Dotclear\Helper\Html\Form\{ - Checkbox, Div, - Input, - Label, Link, - Number, Para, - Select, Text }; use Dotclear\Helper\Html\Html; @@ -37,196 +31,6 @@ use Dotclear\Helper\Html\Html; */ 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') . ' ') - ->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. */ diff --git a/src/Config.php b/src/Config.php index ec6e239..5c0101c 100644 --- a/src/Config.php +++ b/src/Config.php @@ -21,6 +21,16 @@ use Dotclear\Core\Backend\{ Page }; use Dotclear\Core\Process; +use Dotclear\Helper\Html\Form\{ + Checkbox, + Div, + Label, + Link, + Number, + Para, + Select, + Text +}; use Exception; /** @@ -45,7 +55,17 @@ class Config extends Process } 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( __('Configuration has been successfully updated.') @@ -68,7 +88,162 @@ class Config extends Process 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') . ' ') + ->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'); }