From 8462d3d97dd3e639cb98efd148b5446d6c83a69a Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 30 Jul 2023 11:56:53 +0200 Subject: [PATCH] release 2023.07.30 --- CHANGELOG.md | 6 + README.md | 4 +- _define.php | 4 +- dcstore.xml | 6 +- src/Backend.php | 134 +++++++++-------- src/BackendList.php | 20 +-- src/Epc.php | 4 +- src/EpcFilter.php | 3 +- src/Frontend.php | 14 +- src/Install.php | 13 +- src/Manage.php | 343 ++++++++++++++++++++++++++------------------ src/My.php | 31 +--- src/Prepend.php | 10 +- src/Uninstall.php | 10 +- src/Widgets.php | 2 +- 15 files changed, 333 insertions(+), 271 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5516af7..933323d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ dev - [ ] add auto-find post title in content - [ ] add auto-find categorie +- [ ] use SQL statements + +2023.07.30 +- require Dotclear 2.27 +- require PHP 8.1+ +- update to Dotclear 2.27-dev 2023.05.13 - require Dotclear 2.26 diff --git a/README.md b/README.md index ccdd8fa..c1490eb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/enhancePostContent)](https://github.com/JcDenis/enhancePostContent/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/enhancePostContent)](https://github.com/JcDenis/enhancePostContent/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/enhancePostContent)](https://github.com/JcDenis/enhancePostContent/issues) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/enhancePostContent) [![License](https://img.shields.io/github/license/JcDenis/enhancePostContent)](https://github.com/JcDenis/enhancePostContent/blob/master/LICENSE) @@ -22,7 +22,7 @@ atgs, acronyms, abbreviations, definition, citation, link, etc... * admin permissions to set up plugin * content admin permissions to manage fitlers - * Dotclear 2.26 + * Dotclear 2.27 * PHP 8.1+ ## USAGE diff --git a/_define.php b/_define.php index 876142d..2ca817d 100644 --- a/_define.php +++ b/_define.php @@ -18,11 +18,11 @@ $this->registerModule( 'Enhance post content', 'Add features to words in post content', 'Jean-Christian Denis and Contributors', - '2023.05.13.1', + '2023.07.30', [ 'requires' => [ ['php', '8.1'], - ['core', '2.26'], + ['core', '2.27'], ], 'permissions' => dcCore::app()->auth->makePermissions([ dcAuth::PERMISSION_CONTENT_ADMIN, diff --git a/dcstore.xml b/dcstore.xml index aebfbed..a3d2844 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Enhance post content - 2023.05.13.1 + 2023.07.30 Jean-Christian Denis and Contributors Add features to words in post content - https://github.com/JcDenis/enhancePostContent/releases/download/v2023.05.13.1/plugin-enhancePostContent.zip - 2.26 + https://github.com/JcDenis/enhancePostContent/releases/download/v2023.07.30/plugin-enhancePostContent.zip + 2.27 https://plugins.dotaddict.org/dc2/details/enhancePostContent https://github.com/JcDenis/enhancePostContent diff --git a/src/Backend.php b/src/Backend.php index 99a75fd..33fc1a7 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -15,56 +15,45 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; use ArrayObject; -use dcAdmin; use dcCore; -use dcPage; -use dcFavorites; -use dcNsProcess; use dcSettings; +use Dotclear\Core\Backend\Favorites; +use Dotclear\Core\Process; use Dotclear\Helper\Html\Form\{ Checkbox, + Div, Input, Label, - Para + Link, + Note, + Para, + Text }; -class Backend extends dcNsProcess +class Backend extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) - && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), dcCore::app()->blog->id); - - return static::$init; + return self::status(My::checkContext(My::BACKEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } - // backend sidebar menu icon - dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( - My::name(), - dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), - dcPage::getPF(My::id() . '/icon.svg'), - preg_match('/' . preg_quote((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), - dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog?->id) - ); + My::addBackendMenuItem(); dcCore::app()->addBehaviors([ // backend user dashboard favorites icon - 'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { + 'adminDashboardFavoritesV2' => function (Favorites $favs): void { $favs->register(My::id(), [ 'title' => My::name(), - 'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), - 'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), - 'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), - 'permissions' => dcCore::app()->auth?->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), + 'url' => My::manageUrl(), + 'small-icon' => My::icons(), + 'large-icon' => My::icons(), + 'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), ]); }, // backend user preference form @@ -74,39 +63,64 @@ class Backend extends dcNsProcess $allowedpubpages = Epc::blogAllowedTemplatePage(); echo - '

' . My::name() . '

' . - '
' . - '
' . - // active - (new Para())->items([ - (new Checkbox('epc_active', $active))->value(1), - (new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))->for('epc_active')->class('classic'), - ])->render() . - '

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

' . - '

' . - __('Set content filters') . '

' . - '
' . - '
' . - '
' . __('Extra') . '
' . - '

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

' . - // allowedtplvalues - (new Para())->items([ - (new Label(__('Allowed DC template values:'), Label::OUTSIDE_LABEL_BEFORE))->for('epc_allowedtplvalues'), - (new Input('epc_allowedtplvalues'))->size(100)->maxlenght(0)->value(Epc::encodeMulti($allowedtplvalues)), - ])->render() . - '

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

' . - // allowedpubpages - (new Para())->items([ - (new Label(__('Allowed public pages:'), Label::OUTSIDE_LABEL_BEFORE))->for('epc_allowedpubpages'), - (new Input('epc_allowedpubpages'))->size(100)->maxlenght(0)->value(Epc::encodeMulti($allowedpubpages)), - ])->render() . - '

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

' . - '
' . - '
' . - '
' . - '
'; + (new Div()) + ->class('fieldset') + ->items([ + (new Text('h4', My::name())) + ->id('epc_params'), + (new Div()) + ->class('two-cols') + ->items([ + (new Div()) + ->class('col') + ->items([ + // active + (new Para()) + ->items([ + (new Checkbox('epc_active', $active)) + ->value(1), + (new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER)) + ->for('epc_active') + ->class('classic'), + ]), + (new Note()) + ->class('form-note') + ->text(__('This enable public widgets and contents filter.')), + (new Para()) + ->items([ + (new Link()) + ->href(My::manageUrl()) + ->text(__('Set content filters')), + ]), + ]), + (new Div()) + ->class('col') + ->items([ + (new Text('h5', __('Extra'))), + (new Para()) + ->text(__('This is a special feature to edit list of allowed template values and public pages where this plugin works.')), + // allowedtplvalues + (new Para())->items([ + (new Label(__('Allowed DC template values:'), Label::OUTSIDE_LABEL_BEFORE))->for('epc_allowedtplvalues'), + (new Input('epc_allowedtplvalues'))->size(100)->maxlenght(0)->value(Epc::encodeMulti($allowedtplvalues)), + ]), + (new Note()) + ->class('form-note') + ->text(__('Use "readable_name1:template_value1;readable_name2:template_value2;" like "entry content:EntryContent;entry excerpt:EntryExcerpt;".')), + // allowedpubpages + (new Para())->items([ + (new Label(__('Allowed public pages:'), Label::OUTSIDE_LABEL_BEFORE))->for('epc_allowedpubpages'), + (new Input('epc_allowedpubpages'))->size(100)->maxlenght(0)->value(Epc::encodeMulti($allowedpubpages)), + ]), + (new Note()) + ->class('form-note') + ->text(__('Use "readable_name1:template_page1;readable_name2:template_page2;" like "post page:post.html;home page:home.html;".')), + ]), + ]), + (new Text('br')) + ->class('clear'), + ]) + ->render(); }, // backend user preference save 'adminBeforeBlogSettingsUpdate' => function (dcSettings $blog_settings): void { diff --git a/src/BackendList.php b/src/BackendList.php index 588be4d..3635c1f 100644 --- a/src/BackendList.php +++ b/src/BackendList.php @@ -14,9 +14,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; -use adminGenericFilterV2; -use adminGenericListV2; -use dcPager; +use Dotclear\Core\Backend\Filter\Filters; +use Dotclear\Core\Backend\Listing\{ + Listing, + Pager +}; use Dotclear\Helper\Date; use Dotclear\Helper\Html\Form\Checkbox; use Dotclear\Helper\Html\Html; @@ -24,16 +26,16 @@ use Dotclear\Helper\Html\Html; /** * Backend filters values list. */ -class BackendList extends adminGenericListV2 +class BackendList extends Listing { /** * Display list. * - * @param adminGenericFilterV2 $filter The filter - * @param string $url The pager URL - * @param string $block The enclose bloc + * @param Filters $filter The filter + * @param string $url The pager URL + * @param string $block The enclose bloc */ - public function display(adminGenericFilterV2 $filter, string $url, string $block): void + public function display(Filters $filter, string $url, string $block): void { if ($this->rs->isEmpty()) { echo '

' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '

'; @@ -41,7 +43,7 @@ class BackendList extends adminGenericListV2 return; } - $pager = new dcPager($filter->value('page'), $this->rs_count, $filter->value('nb'), 10); + $pager = new Pager($filter->value('page'), $this->rs_count, $filter->value('nb'), 10); $pager->base_url = $url; $epc_id = []; diff --git a/src/Epc.php b/src/Epc.php index 90eb6a2..1c602e2 100644 --- a/src/Epc.php +++ b/src/Epc.php @@ -68,7 +68,7 @@ class Epc */ public static function blogAllowedTemplateValue(): array { - $list = json_decode((string) dcCore::app()->blog?->settings->get(My::id())->get('allowedtplvalues'), true); + $list = json_decode((string) My::settings()->get('allowedtplvalues'), true); return is_array($list) ? $list : self::defaultAllowedTemplateValue(); } @@ -130,7 +130,7 @@ class Epc */ public static function blogAllowedTemplatePage(): array { - $list = json_decode((string) dcCore::app()->blog?->settings->get(My::id())->get('allowedpubpages'), true); + $list = json_decode((string) My::settings()->get('allowedpubpages'), true); return is_array($list) ? $list : self::defaultAllowedTemplatePage(); } diff --git a/src/EpcFilter.php b/src/EpcFilter.php index fecce71..6521a6a 100644 --- a/src/EpcFilter.php +++ b/src/EpcFilter.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; use ArrayObject; -use dcCore; use Dotclear\Database\MetaRecord; use Dotclear\Plugin\widgets\WidgetsElement; use Exception; @@ -88,7 +87,7 @@ abstract class EpcFilter } // get blog settings - $s = json_decode((string) dcCore::app()->blog?->settings->get(My::id())->get($this->id), true); + $s = json_decode((string) My::settings()->get($this->id), true); if (empty($s)) { $s = []; } diff --git a/src/Frontend.php b/src/Frontend.php index 74cb2c5..f217419 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -15,25 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; use dcCore; -use dcNsProcess; use dcUtils; +use Dotclear\Core\Process; -class Frontend extends dcNsProcess +class Frontend extends Process { public static function init(): bool { - static::$init = defined('DC_RC_PATH'); - - return static::$init; + return self::status(My::checkContext(My::FRONTEND)); } public static function process(): bool { - if (!static::$init) { - return false; - } - - if (!dcCore::app()->blog?->settings->get(My::id())->get('active')) { + if (!self::status() || !My::settings()->get('active')) { return false; } diff --git a/src/Install.php b/src/Install.php index 3aa2db1..b763da8 100644 --- a/src/Install.php +++ b/src/Install.php @@ -16,23 +16,20 @@ namespace Dotclear\Plugin\enhancePostContent; use dcCore; use dcNamespace; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Database\Structure; use Exception; -class Install extends dcNsProcess +class Install extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); - - return static::$init; + return self::status(My::checkContext(My::INSTALL)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -61,7 +58,7 @@ class Install extends dcNsProcess self::growUp(); // Settings - $s = dcCore::app()->blog?->settings->get(My::id()); + $s = My::settings(); if (is_null($s)) { return false; } diff --git a/src/Manage.php b/src/Manage.php index 806c983..bc32d5f 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -14,11 +14,16 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; -use dcAdminFilters; -use adminGenericFilterV2; use dcCore; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\{ + Notices, + Page +}; +use Dotclear\Core\Backend\Filter\{ + Filters, + FiltersLibrary +}; use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -37,27 +42,16 @@ use Dotclear\Helper\Html\Html; use Dotclear\Helper\Network\Http; use Exception; -class Manage extends dcNsProcess +class Manage extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) - && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), dcCore::app()->blog->id); - - return static::$init; + return self::status(My::checkContext(My::MANAGE)); } public static function process(): bool { - if (!static::$init) { - return false; - } - - // nullsafe check - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (!self::status()) { return false; } @@ -93,16 +87,15 @@ class Manage extends dcNsProcess 'page' => (array) $_POST['filter_page'], ]; - dcCore::app()->blog->settings->get(My::id())->put($filter->id(), json_encode($f)); + My::settings()->put($filter->id(), json_encode($f)); dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Filter successfully updated.') ); - dcCore::app()->adminurl->redirect( - 'admin.plugin.' . My::id(), + My::redirect( ['part' => $filter->id()], '#settings' ); @@ -119,18 +112,17 @@ class Manage extends dcNsProcess $cur->setField('epc_value', Html::escapeHTML($_POST['new_value'])); if (EpcRecord::isRecord($cur->getField('epc_filter'), $cur->getField('epc_key'))) { - dcPage::addErrorNotice(__('Key already exists for this filter')); + Notices::addErrorNotice(__('Key already exists for this filter')); } else { EpcRecord::addRecord($cur); dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Filter successfully updated.') ); } - dcCore::app()->adminurl->redirect( - 'admin.plugin.' . My::id(), + My::redirect( ['part' => $filter->id()], '#record' ); @@ -148,15 +140,14 @@ class Manage extends dcNsProcess dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Filter successfully updated.') ); if (!empty($_REQUEST['redir'])) { Http::redirect($_REQUEST['redir']); } else { - dcCore::app()->adminurl->redirect( - 'admin.plugin.' . My::id(), + My::redirect( ['part' => $filter->id()], '#record' ); @@ -171,12 +162,7 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { - return; - } - - // nullsafe check - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (!self::status()) { return; } @@ -193,8 +179,8 @@ class Manage extends dcNsProcess // Prepare tabs and lists $header = ''; if ($filter->has_list) { - $sorts = new adminGenericFilterV2('epc'); - $sorts->add(dcAdminFilters::getPageFilter()); + $sorts = new Filters('epc'); + $sorts->add(FiltersLibrary::getPageFilter()); $sorts->add('part', $filter->id()); $params = $sorts->params(); @@ -208,14 +194,14 @@ class Manage extends dcNsProcess dcCore::app()->error->add($e->getMessage()); } - $header = $sorts->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => $filter->id()], '&') . '#record'); + $header = $sorts->js(My::manageUrl(['part' => $filter->id()], '&') . '#record'); } // display - dcPage::openModule( + Page::openModule( My::name(), - dcPage::jsPageTabs() . - dcPage::jsModuleLoad(My::id() . '/js/backend.js') . + Page::jsPageTabs() . + My::jsLoad('backend') . $header . # --BEHAVIOR-- enhancePostContentAdminHeader @@ -223,119 +209,184 @@ class Manage extends dcNsProcess ); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', My::name() => '', $filter->name => '', ]) . - dcPage::notices(); + Notices::getNotices(); // filters select menu echo - (new Form('filters_menu'))->method('get')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->fields([ - (new Para())->class('anchor-nav')->items([ - (new Select('part'))->items($filters->nid())->default($filter->id()), - (new Submit(['do']))->value(__('Ok')), - (new Hidden(['p'], My::id())), - ]), - ])->render(); - - // selected filter - echo - '

' . $filter->name . '

' . - '

' . $filter->description . '

'; + (new Form('filters_menu')) + ->method('get') + ->action(dcCore::app()->admin->getPageURL()) + ->fields([ + (new Para()) + ->class('anchor-nav') + ->items([ + (new Select('part')) + ->items($filters->nid()) + ->default($filter->id()), + (new Submit(['do'])) + ->value(__('Ok')), + ... My::hiddenFields(), + ]), + ]) + ->render(); // Filter settings $form_pages = [(new Text('h4', __('Pages to be filtered')))]; foreach (Epc::blogAllowedTemplatePage() as $k => $v) { - $form_pages[] = (new Para())->items([ - (new Checkbox(['filter_page[]', 'filter_page' . $v], in_array($v, $filter->page)))->value($v), - (new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_page' . $v)->class('classic'), - ]); + $form_pages[] = (new Para()) + ->items([ + (new Checkbox(['filter_page[]', 'filter_page' . $v], in_array($v, $filter->page))) + ->value($v), + (new Label(__($k), Label::OUTSIDE_LABEL_AFTER)) + ->for('filter_page' . $v) + ->class('classic'), + ]); } $form_values = [(new Text('h4', __('Contents to be filtered')))]; foreach (Epc::blogAllowedTemplateValue() as $k => $v) { - $form_values[] = (new Para())->items([ - (new Checkbox(['filter_template[]', 'filter_template' . $v], in_array($v, $filter->template)))->value($v), - (new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_template' . $v)->class('classic'), - ]); + $form_values[] = (new Para()) + ->items([ + (new Checkbox(['filter_template[]', 'filter_template' . $v], in_array($v, $filter->template))) + ->value($v), + (new Label(__($k), Label::OUTSIDE_LABEL_AFTER)) + ->for('filter_template' . $v) + ->class('classic'), + ]); } $form_styles = [(new Text('h4', __('Style')))]; foreach ($filter->class as $k => $v) { - $form_styles[] = (new Para())->items([ - (new Label(sprintf(__('Class "%s":'), $v), Label::OUTSIDE_LABEL_BEFORE))->for('filter_style' . $k), - (new Input(['filter_style[]', 'filter_style' . $k]))->size(60)->maxlenght(255)->value(Html::escapeHTML($filter->style[$k])), - ]); + $form_styles[] = (new Para()) + ->items([ + (new Label(sprintf(__('Class "%s":'), $v), Label::OUTSIDE_LABEL_BEFORE)) + ->for('filter_style' . $k), + (new Input(['filter_style[]', 'filter_style' . $k])) + ->size(60) + ->maxlenght(255) + ->value(Html::escapeHTML($filter->style[$k])), + ]); } echo - (new Div('setting'))->class('multi-part')->title(__('Settings'))->items([ - (new Form('setting_form'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#setting')->separator('')->fields([ - (new Div())->class('two-boxes even')->items($form_pages), - (new Div())->class('two-boxes odd')->items([ - (new Text('h4', __('Filtering'))), - (new Para())->items([ - (new Checkbox('filter_nocase', $filter->nocase))->value(1), - (new Label(__('Case insensitive'), Label::OUTSIDE_LABEL_AFTER))->for('filter_nocase')->class('classic'), - ]), - (new Para())->items([ - (new Checkbox('filter_plural', $filter->plural))->value(1), - (new Label(__('Also use the plural'), Label::OUTSIDE_LABEL_AFTER))->for('filter_plural')->class('classic'), - ]), - (new Para())->items([ - (new Label(__('Limit the number of replacement to:'), Label::OUTSIDE_LABEL_BEFORE))->for('filter_limit'), - (new Number('filter_limit'))->min(0)->max(99)->value((int) $filter->limit), - ]), - (new Note())->class('form-note')->text(__('Leave it blank or set it to 0 for no limit')), - ]), - (new Div())->class('two-boxes even')->items($form_values), - (new Div())->class('two-boxes odd')->items(array_merge($form_styles, [ - (new Note())->class('form-note')->text(sprintf(__('The inserted HTML tag looks like: %s'), Html::escapeHTML(str_replace('%s', '...', $filter->replace)))), - (new Para())->items([ - (new Label(__('Ignore HTML tags:'), Label::OUTSIDE_LABEL_BEFORE))->for('filter_notag'), - (new Input('filter_notag'))->size(60)->maxlenght(255)->value(Epc::encodeSingle($filter->notag)), - ]), - (new Note())->class('form-note')->text(__('This is the list of HTML tags where content will be ignored.') . '
' . (empty($filter->ignore) ? '' : sprintf(__('Tags "%s" will allways be ignored.'), Epc::encodeSingle($filter->ignore)))), + (new Div()) + ->items([ + (new Text('h3', $filter->name)), + (new Text('p', $filter->description)), - ])), - (new Div())->class('clear')->items([ - dcCore::app()->formNonce(false), - (new Hidden(['action'], 'savefiltersetting')), - (new Hidden(['part'], $filter->id())), - (new Submit(['save']))->value(__('Save')), - ]), - ]), - ])->render(); + (new Div('setting')) + ->class('multi-part') + ->title(__('Settings')) + ->items([ + (new Form('setting_form')) + ->method('post') + ->action(My::manageUrl() . '#setting') + ->separator('') + ->fields([ + (new Div()) + ->class('two-boxes even') + ->items($form_pages), + (new Div()) + ->class('two-boxes odd') + ->items([ + (new Text('h4', __('Filtering'))), + (new Para()) + ->items([ + (new Checkbox('filter_nocase', $filter->nocase)) + ->value(1), + (new Label(__('Case insensitive'), Label::OUTSIDE_LABEL_AFTER)) + ->for('filter_nocase') + ->class('classic'), + ]), + (new Para()) + ->items([ + (new Checkbox('filter_plural', $filter->plural)) + ->value(1), + (new Label(__('Also use the plural'), Label::OUTSIDE_LABEL_AFTER)) + ->for('filter_plural') + ->class('classic'), + ]), + (new Para()) + ->items([ + (new Label(__('Limit the number of replacement to:'), Label::OUTSIDE_LABEL_BEFORE)) + ->for('filter_limit'), + (new Number('filter_limit')) + ->min(0) + ->max(99) + ->value((int) $filter->limit), + ]), + (new Note()) + ->class('form-note') + ->text(__('Leave it blank or set it to 0 for no limit')), + ]), + (new Div()) + ->class('two-boxes even') + ->items($form_values), + (new Div()) + ->class('two-boxes odd') + ->items([ + ... $form_styles, + (new Note()) + ->class('form-note') + ->text(sprintf(__('The inserted HTML tag looks like: %s'), Html::escapeHTML(str_replace('%s', '...', $filter->replace)))), + (new Para()) + ->items([ + (new Label(__('Ignore HTML tags:'), Label::OUTSIDE_LABEL_BEFORE)) + ->for('filter_notag'), + (new Input('filter_notag')) + ->size(60) + ->maxlenght(255) + ->value(Epc::encodeSingle($filter->notag)), + ]), + (new Note()) + ->class('form-note') + ->text(__('This is the list of HTML tags where content will be ignored.') . '
' . (empty($filter->ignore) ? '' : sprintf(__('Tags "%s" will allways be ignored.'), Epc::encodeSingle($filter->ignore)))), + + ]), + (new Div()) + ->class('clear') + ->items([ + (new Submit(['save']))->value(__('Save')), + ... My::hiddenFields([ + 'action' => 'savefiltersetting', + 'part' => $filter->id(), + ]), + ]), + ]), + ]), + ]) + ->render(); // Filter records list (if any) if ($filter->has_list && isset($pager)) { - $pager_url = dcCore::app()->adminurl->get('admin.plugin.' . My::id(), array_diff_key($sorts->values(true), ['page' => ''])) . '&page=%s#record'; - echo '
'; - $sorts->display(['admin.plugin.' . My::id(), '#record'], (new Hidden('p', My::id()))->render() . (new Hidden('part', $filter->id()))->render()); + $sorts->display(['admin.plugin.' . My::id(), '#record'], (new Hidden('part', $filter->id()))->render()); $pager->display( $sorts, - $pager_url, - '
' . + My::manageUrl(array_merge($sorts->values(true), ['page' => '%s']), '#record'), + '' . '%s' . '
' . '

' . - (new Para())->class('col right')->items(array_merge( - dcCore::app()->adminurl->hiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $sorts->values(true))), - [ - dcCore::app()->formNonce(false), - (new Hidden('redir', dcCore::app()->adminurl->get('admin.plugin.' . My::id(), $sorts->values(true)))), - (new Hidden('action', 'deleterecords')), + (new Para())->class('col right') + ->items([ (new Submit(['save', 'del-action']))->value(__('Delete selected records')), - ] - ))->render() . + ... My::hiddenFields([ + ... $sorts->values(true), + 'redir' => My::manageUrl($sorts->values(true)), + 'action' => 'deleterecords', + ]), + ])->render() . '
' . '
' ); @@ -344,30 +395,50 @@ class Manage extends dcNsProcess // New record echo - (new Div('newrecord'))->class('multi-part')->title(__('New record'))->items([ - (new Form('form-create'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#record')->fields([ - (new Para())->items([ - (new Label(__('Key:'), Label::OUTSIDE_LABEL_BEFORE))->for('new_key'), - (new Input('new_key'))->size(60)->maxlenght(255)->required(true), - ]), - (new Para())->items([ - (new Label(__('Value:'), Label::OUTSIDE_LABEL_BEFORE))->for('new_value'), - (new Input('new_value'))->size(60)->maxlenght(255)->required(true), - ]), - (new Para())->class('clear')->items([ - dcCore::app()->formNonce(false), - (new Hidden(['action'], 'savenewrecord')), - (new Hidden(['part'], $filter->id())), - (new Submit(['save', 'new-action']))->value(__('Save')), - ]), - ]), - ])->render(); + (new Div('newrecord')) + ->class('multi-part') + ->title(__('New record')) + ->items([ + (new Form('form-create')) + ->method('post') + ->action(dcCore::app()->admin->getPageURL() . '#record') + ->fields([ + (new Para()) + ->items([ + (new Label(__('Key:'), Label::OUTSIDE_LABEL_BEFORE)) + ->for('new_key'), + (new Input('new_key')) + ->size(60) + ->maxlenght(255) + ->required(true), + ]), + (new Para()) + ->items([ + (new Label(__('Value:'), Label::OUTSIDE_LABEL_BEFORE)) + ->for('new_value'), + (new Input('new_value')) + ->size(60) + ->maxlenght(255) + ->required(true), + ]), + (new Para()) + ->class('clear') + ->items([ + (new Submit(['save', 'new-action'])) + ->value(__('Save')), + ... My::hiddenFields([ + 'action' => 'savenewrecord', + 'part' => $filter->id(), + ]), + ]), + ]), + ])->render(); } # --BEHAVIOR-- enhancePostContentAdminPage dcCore::app()->callBehavior('enhancePostContentAdminPage'); - dcPage::helpBlock('enhancePostContent'); - dcPage::closeModule(); + Page::helpBlock('enhancePostContent'); + Page::closeModule(); } } diff --git a/src/My.php b/src/My.php index 9847dca..53096fb 100644 --- a/src/My.php +++ b/src/My.php @@ -15,11 +15,12 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +class My extends MyPlugin { /** @var string Plugin table name */ public const TABLE_NAME = 'epc'; @@ -38,29 +39,11 @@ class My Filter\EpcFilterTwitter::class, ]; - /** - * This module id. - */ - public static function id(): string + public static function checkCustomContext(int $context): ?bool { - return basename(dirname(__DIR__)); - } - - /** - * This module name. - */ - public static function name(): string - { - $name = dcCore::app()->plugins->moduleInfo(self::id(), 'name'); - - return __(is_string($name) ? $name : self::id()); - } - - /** - * This module path. - */ - public static function path(): string - { - return dirname(__DIR__); + return !in_array($context, [My::BACKEND, My::MANAGE, My::MENU]) ? null : + dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ + dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, + ]), dcCore::app()->blog->id); } } diff --git a/src/Prepend.php b/src/Prepend.php index f91bdc3..a1d7036 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Helper\Html\Html; -class Prepend extends dcNsProcess +class Prepend extends Process { public static function init(): bool { - static::$init = defined('DC_RC_PATH'); - - return static::$init; + return self::status(My::checkContext(My::PREPEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } diff --git a/src/Uninstall.php b/src/Uninstall.php index 1e9dc3a..1e2983f 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Plugin\Uninstaller\Uninstaller; -class Uninstall extends dcNsProcess +class Uninstall extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN'); - - return static::$init; + return self::status(My::checkContext(My::UNINSTALL)); } public static function process(): bool { - if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { + if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) { return false; } diff --git a/src/Widgets.php b/src/Widgets.php index bd5b87f..2e8f348 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -93,7 +93,7 @@ class Widgets } # Page - if (!dcCore::app()->blog?->settings->get(My::id())->get('active') + if (!My::settings()->get('active') || !in_array(dcCore::app()->ctx?->__get('current_tpl'), ['post.html', 'page.html']) ) { return '';