From 1788d0324e33ec7304cdff08f35f1039dcdfa4fb Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 24 Aug 2021 22:50:53 +0200 Subject: [PATCH] move settings from plugin config to blog pref --- CHANGELOG.md | 4 +- README.md | 3 +- _admin.php | 89 +++++++++++++++++++++++++++++++++++ _config.php | 130 --------------------------------------------------- _define.php | 2 +- 5 files changed, 93 insertions(+), 135 deletions(-) delete mode 100644 _config.php diff --git a/CHANGELOG.md b/CHANGELOG.md index e897ccc..5639cee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,14 @@ enhancePostContent xxxx.xx.xx * Not added priority on filters for replacement order * Not added priority on lists of filters for replacement order * Not added auto-find post title in content - * move settings from plugin to blog -enhancePostContent 2021.08.xx +enhancePostContent 2021.08.24 * switch to Dotclear 2.19 * switch to php 7.3+ and php 8.0.x * switch to Github * update license * update php code to PSR-2 and short array + * move settings from plugin to blog enhancePostContent 2013.11.08 * Switch to Dotclear 2.6 (admin styles and settings) diff --git a/README.md b/README.md index b7ffbcb..0747c91 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,7 @@ atgs, acronyms, abbreviations, definition, citation, link, etc... First install enhancePostContent, manualy from a zip package or from Dotaddict repository. (See Dotclear's documentation to know how do this) -Go to ''plugins manager'', expand enhancePostContent information then -go to ''configure plugin'', fill in form. +Go to ''blog preference'' => fieldset ''plugin preference', fill in form. Once it's done you can manage filters from menu ''Enhance Post Content'' on sidebar or you can add dashboard icon, diff --git a/_admin.php b/_admin.php index a6b1a91..e05faae 100644 --- a/_admin.php +++ b/_admin.php @@ -15,6 +15,8 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } +$core->blog->settings->addNamespace('enhancePostContent'); + require dirname(__FILE__) . '/_widgets.php'; # Admin menu @@ -33,6 +35,14 @@ $core->addBehavior( 'adminDashboardFavorites', ['epcAdminBehaviors', 'adminDashboardFavorites'] ); +$core->addBehavior( + 'adminBlogPreferencesForm', + ['epcAdminBehaviors', 'adminBlogPreferencesForm'] +); +$core->addBehavior( + 'adminBeforeBlogSettingsUpdate', + ['epcAdminBehaviors', 'adminBeforeBlogSettingsUpdate'] +); class epcAdminBehaviors { @@ -57,4 +67,83 @@ class epcAdminBehaviors && isset($params['p']) && $params['p'] == 'enhancePostContent'; } + + public static function sortbyCombo() + { + return [ + __('Date') => 'epc_upddt', + __('Key') => 'epc_key', + __('Value') => 'epc_value', + __('ID') => 'epc_id' + ]; + } + + public static function orderCombo() + { + return [ + __('Ascending') => 'asc', + __('Descending') => 'desc' + ]; + } + + public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings) + { + $active = (boolean) $blog_settings->enhancePostContent->enhancePostContent_active; + $list_sortby = (string) $blog_settings->enhancePostContent->enhancePostContent_list_sortby; + $list_order = (string) $blog_settings->enhancePostContent->enhancePostContent_list_order; + $list_nb = (integer) $blog_settings->enhancePostContent->enhancePostContent_list_nb; + $_filters = libEPC::blogFilters(); + $allowedtplvalues = libEPC::blogAllowedTplValues(); + $allowedpubpages = libEPC::blogAllowedPubPages(); + + echo + '

' . __('Enhance post content') .'

' . + '
' . + '
' . + '

' . + '

' . + __('This enable public widgets and contents filter.') . + '

' . + '
' . __('Record list') . '
' . + '

' . __('This is the default order of records lists.') . '

' . + '

' . + form::combo('epc_list_sortby', self::sortbyCombo(), $list_sortby) . '

' . + '

' . + form::combo('epc_list_order', self::orderCombo(), $list_order) . '

' . + '

' . + form::field('epc_list_nb', 3, 3, $list_nb) . '

' . + '
' . + '
' . + '
' . __('Extra') . '
' . + '

' . __('This is a special feature to edit list of allowed template values and public pages where this plugin works.') . '

' . + '

' . + form::field('epc_allowedtplvalues', 100, 0, libEPC::implode($allowedtplvalues)) . '

' . + '

' . __('Use "readable_name1:template_value1;readable_name2:template_value2;" like "entry content:EntryContent;entry excerpt:EntryExcerpt;".') . '

' . + '

' . + form::field('epc_allowedpubpages', 100, 0, libEPC::implode($allowedpubpages)) . '

' . + '

' . __('Use "readable_name1:template_page1;readable_name2:template_page2;" like "post page:post.html;home page:home.html;".') . '

' . + '
' . + '
' . + '
' . + '
'; + } + + public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings) + { + $active = !empty($_POST['epc_active']); + $list_sortby = in_array($_POST['epc_list_sortby'], self::sortbyCombo()) ? $_POST['epc_list_sortby'] : 'epc_id'; + $list_order = in_array($_POST['epc_list_order'], self::orderCombo()) ? $_POST['epc_list_order'] : 'desc'; + $list_nb = isset($_POST['epc_list_nb']) && $_POST['epc_list_nb'] > 0 ? $_POST['epc_list_nb'] : 20; + $allowedtplvalues = libEPC::explode($_POST['epc_allowedtplvalues']); + $allowedpubpages = libEPC::explode($_POST['epc_allowedpubpages']); + + $blog_settings->enhancePostContent->put('enhancePostContent_active', $active); + $blog_settings->enhancePostContent->put('enhancePostContent_list_sortby', $list_sortby); + $blog_settings->enhancePostContent->put('enhancePostContent_list_order', $list_order); + $blog_settings->enhancePostContent->put('enhancePostContent_list_nb', $list_nb); + $blog_settings->enhancePostContent->put('enhancePostContent_allowedtplvalues', serialize($allowedtplvalues)); + $blog_settings->enhancePostContent->put('enhancePostContent_allowedpubpages', serialize($allowedpubpages)); + } } \ No newline at end of file diff --git a/_config.php b/_config.php deleted file mode 100644 index fc8b59e..0000000 --- a/_config.php +++ /dev/null @@ -1,130 +0,0 @@ -getURL().'#plugins' : $_REQUEST['redir']; - -# -- Form combos -- -$sortby_combo = array( - __('Date') => 'epc_upddt', - __('Key') => 'epc_key', - __('Value') => 'epc_value', - __('ID') => 'epc_id' -); - -$order_combo = array( - __('Ascending') => 'asc', - __('Descending') => 'desc' -); - -# -- Get settings -- -$core->blog->settings->addNamespace('enhancePostContent'); -$s = $core->blog->settings->enhancePostContent; -$active = (boolean) $s->enhancePostContent_active; -$list_sortby = (string) $s->enhancePostContent_list_sortby; -$list_order = (string) $s->enhancePostContent_list_order; -$list_nb = (integer) $s->enhancePostContent_list_nb; -$_filters = libEPC::blogFilters(); -$allowedtplvalues = libEPC::blogAllowedTplValues(); -$allowedpubpages = libEPC::blogAllowedPubPages(); - -# -- Set settings -- -if (!empty($_POST['save'])) { - - try { - $active = !empty($_POST['active']); - $list_sortby = in_array($_POST['list_sortby'], $sortby_combo) ? - $_POST['list_sortby'] : 'epc_id'; - $list_order = in_array($_POST['list_order'], $order_combo) ? - $_POST['list_order'] : 'desc'; - $list_nb = isset($_POST['list_nb']) && $_POST['list_nb'] > 0 ? - $_POST['list_nb'] : 20; - - $s->put('enhancePostContent_active', $active); - $s->put('enhancePostContent_list_sortby', $list_sortby); - $s->put('enhancePostContent_list_order', $list_order); - $s->put('enhancePostContent_list_nb', $list_nb); - - $allowedtplvalues = libEPC::explode($_POST['allowedtplvalues']); - $allowedpubpages = libEPC::explode($_POST['allowedpubpages']); - - $s->put( - 'enhancePostContent_allowedtplvalues', - serialize($allowedtplvalues) - ); - $s->put( - 'enhancePostContent_allowedpubpages', - serialize($allowedpubpages) - ); - - $core->blog->triggerBlog(); - - dcPage::addSuccessNotice( - __('Configuration has been successfully updated.') - ); - http::redirect( - $list->getURL('module=enhancePostContent&conf=1&redir='. - $list->getRedir()) - ); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } -} - -# -- Display form -- -echo ' - -
-

'.__('General').'

-

'.__('This enable public widgets and contents filter.').'

- -

- -
- -
-

'.__('Record list').'

-

'.__('This is the default order of records lists.').'

- -

'. -form::combo('list_sortby', $sortby_combo, $list_sortby).'

- -

'. -form::combo('list_order', $order_combo, $list_order).'

- -

'. -form::field('list_nb', 3, 3, $list_nb).'

- -
- -
-

'.__('Extra').'

-

'.__('This is a special feature to edit list of allowed template values and public pages where this plugin works.').'

- -

'. -form::field('allowedtplvalues', 100,0, libEPC::implode($allowedtplvalues)).'

-

'.__('Use "readable_name1:template_value1;readable_name2:template_value2;" like "entry content:EntryContent;entry excerpt:EntryExcerpt;".').'

- -

'. -form::field('allowedpubpages', 100, 0, libEPC::implode($allowedpubpages)).'

-

'.__('Use "readable_name1:template_page1;readable_name2:template_page2;" like "post page:post.html;home page:home.html;".').'

- -
'; diff --git a/_define.php b/_define.php index c167698..e6a43fd 100644 --- a/_define.php +++ b/_define.php @@ -19,7 +19,7 @@ $this->registerModule( 'Enhance post content', 'Add features to words in post content', 'Jean-Christian Denis and Contributors', - '2021.08.0', + '2021.08.24', [ 'permissions' => 'contentadmin', 'type' => 'plugin',