release 2023.07.30

This commit is contained in:
Jean-Christian Denis 2023-07-30 11:56:53 +02:00
parent c9d8a62eaa
commit 8462d3d97d
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
15 changed files with 333 additions and 271 deletions

View file

@ -1,6 +1,12 @@
dev dev
- [ ] add auto-find post title in content - [ ] add auto-find post title in content
- [ ] add auto-find categorie - [ ] 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 2023.05.13
- require Dotclear 2.26 - require Dotclear 2.26

View file

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/enhancePostContent)](https://github.com/JcDenis/enhancePostContent/releases) [![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) [![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) [![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) [![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) [![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 * admin permissions to set up plugin
* content admin permissions to manage fitlers * content admin permissions to manage fitlers
* Dotclear 2.26 * Dotclear 2.27
* PHP 8.1+ * PHP 8.1+
## USAGE ## USAGE

View file

@ -18,11 +18,11 @@ $this->registerModule(
'Enhance post content', 'Enhance post content',
'Add features to words in post content', 'Add features to words in post content',
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'2023.05.13.1', '2023.07.30',
[ [
'requires' => [ 'requires' => [
['php', '8.1'], ['php', '8.1'],
['core', '2.26'], ['core', '2.27'],
], ],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN, dcAuth::PERMISSION_CONTENT_ADMIN,

View file

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="enhancePostContent"> <module id="enhancePostContent">
<name>Enhance post content</name> <name>Enhance post content</name>
<version>2023.05.13.1</version> <version>2023.07.30</version>
<author>Jean-Christian Denis and Contributors</author> <author>Jean-Christian Denis and Contributors</author>
<desc>Add features to words in post content</desc> <desc>Add features to words in post content</desc>
<file>https://github.com/JcDenis/enhancePostContent/releases/download/v2023.05.13.1/plugin-enhancePostContent.zip</file> <file>https://github.com/JcDenis/enhancePostContent/releases/download/v2023.07.30/plugin-enhancePostContent.zip</file>
<da:dcmin>2.26</da:dcmin> <da:dcmin>2.27</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/enhancePostContent</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/enhancePostContent</da:details>
<da:support>https://github.com/JcDenis/enhancePostContent</da:support> <da:support>https://github.com/JcDenis/enhancePostContent</da:support>
</module> </module>

View file

@ -15,56 +15,45 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use ArrayObject; use ArrayObject;
use dcAdmin;
use dcCore; use dcCore;
use dcPage;
use dcFavorites;
use dcNsProcess;
use dcSettings; use dcSettings;
use Dotclear\Core\Backend\Favorites;
use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Div,
Input, Input,
Label, Label,
Para Link,
Note,
Para,
Text
}; };
class Backend extends dcNsProcess class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::BACKEND));
&& !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;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
// backend sidebar menu icon My::addBackendMenuItem();
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)
);
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([
// backend user dashboard favorites icon // backend user dashboard favorites icon
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { 'adminDashboardFavoritesV2' => function (Favorites $favs): void {
$favs->register(My::id(), [ $favs->register(My::id(), [
'title' => My::name(), 'title' => My::name(),
'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), 'url' => My::manageUrl(),
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), 'small-icon' => My::icons(),
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), 'large-icon' => My::icons(),
'permissions' => dcCore::app()->auth?->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), 'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]),
]); ]);
}, },
// backend user preference form // backend user preference form
@ -74,39 +63,64 @@ class Backend extends dcNsProcess
$allowedpubpages = Epc::blogAllowedTemplatePage(); $allowedpubpages = Epc::blogAllowedTemplatePage();
echo echo
'<div class="fieldset"><h4 id="epc_params">' . My::name() . '</h4>' . (new Div())
'<div class="two-cols">' . ->class('fieldset')
'<div class="col">' . ->items([
// active (new Text('h4', My::name()))
(new Para())->items([ ->id('epc_params'),
(new Checkbox('epc_active', $active))->value(1), (new Div())
(new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))->for('epc_active')->class('classic'), ->class('two-cols')
])->render() . ->items([
'<p class="form-note">' . (new Div())
__('This enable public widgets and contents filter.') . ->class('col')
'</p>' . ->items([
'<p><a href="' . dcCore::app()->adminurl?->get('admin.plugin.' . My::id()) . '">' . // active
__('Set content filters') . '</a></p>' . (new Para())
'</div>' . ->items([
'<div class="col">' . (new Checkbox('epc_active', $active))
'<h5>' . __('Extra') . '</h5>' . ->value(1),
'<p>' . __('This is a special feature to edit list of allowed template values and public pages where this plugin works.') . '</p>' . (new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))
// allowedtplvalues ->for('epc_active')
(new Para())->items([ ->class('classic'),
(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())
])->render() . ->class('form-note')
'<p class="form-note">' . __('Use "readable_name1:template_value1;readable_name2:template_value2;" like "entry content:EntryContent;entry excerpt:EntryExcerpt;".') . '</p>' . ->text(__('This enable public widgets and contents filter.')),
// allowedpubpages (new Para())
(new Para())->items([ ->items([
(new Label(__('Allowed public pages:'), Label::OUTSIDE_LABEL_BEFORE))->for('epc_allowedpubpages'), (new Link())
(new Input('epc_allowedpubpages'))->size(100)->maxlenght(0)->value(Epc::encodeMulti($allowedpubpages)), ->href(My::manageUrl())
])->render() . ->text(__('Set content filters')),
'<p class="form-note">' . __('Use "readable_name1:template_page1;readable_name2:template_page2;" like "post page:post.html;home page:home.html;".') . '</p>' . ]),
'</div>' . ]),
'</div>' . (new Div())
'<br class="clear" />' . ->class('col')
'</div>'; ->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 // backend user preference save
'adminBeforeBlogSettingsUpdate' => function (dcSettings $blog_settings): void { 'adminBeforeBlogSettingsUpdate' => function (dcSettings $blog_settings): void {

View file

@ -14,9 +14,11 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use adminGenericFilterV2; use Dotclear\Core\Backend\Filter\Filters;
use adminGenericListV2; use Dotclear\Core\Backend\Listing\{
use dcPager; Listing,
Pager
};
use Dotclear\Helper\Date; use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Form\Checkbox; use Dotclear\Helper\Html\Form\Checkbox;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
@ -24,16 +26,16 @@ use Dotclear\Helper\Html\Html;
/** /**
* Backend filters values list. * Backend filters values list.
*/ */
class BackendList extends adminGenericListV2 class BackendList extends Listing
{ {
/** /**
* Display list. * Display list.
* *
* @param adminGenericFilterV2 $filter The filter * @param Filters $filter The filter
* @param string $url The pager URL * @param string $url The pager URL
* @param string $block The enclose bloc * @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()) { if ($this->rs->isEmpty()) {
echo '<p><strong>' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '</strong></p>'; echo '<p><strong>' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '</strong></p>';
@ -41,7 +43,7 @@ class BackendList extends adminGenericListV2
return; 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; $pager->base_url = $url;
$epc_id = []; $epc_id = [];

View file

@ -68,7 +68,7 @@ class Epc
*/ */
public static function blogAllowedTemplateValue(): array 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(); return is_array($list) ? $list : self::defaultAllowedTemplateValue();
} }
@ -130,7 +130,7 @@ class Epc
*/ */
public static function blogAllowedTemplatePage(): array 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(); return is_array($list) ? $list : self::defaultAllowedTemplatePage();
} }

View file

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use ArrayObject; use ArrayObject;
use dcCore;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
use Exception; use Exception;
@ -88,7 +87,7 @@ abstract class EpcFilter
} }
// get blog settings // 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)) { if (empty($s)) {
$s = []; $s = [];
} }

View file

@ -15,25 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use dcCore; use dcCore;
use dcNsProcess;
use dcUtils; use dcUtils;
use Dotclear\Core\Process;
class Frontend extends dcNsProcess class Frontend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_RC_PATH'); return self::status(My::checkContext(My::FRONTEND));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status() || !My::settings()->get('active')) {
return false;
}
if (!dcCore::app()->blog?->settings->get(My::id())->get('active')) {
return false; return false;
} }

View file

@ -16,23 +16,20 @@ namespace Dotclear\Plugin\enhancePostContent;
use dcCore; use dcCore;
use dcNamespace; use dcNamespace;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Exception; use Exception;
class Install extends dcNsProcess class Install extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::INSTALL));
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
@ -61,7 +58,7 @@ class Install extends dcNsProcess
self::growUp(); self::growUp();
// Settings // Settings
$s = dcCore::app()->blog?->settings->get(My::id()); $s = My::settings();
if (is_null($s)) { if (is_null($s)) {
return false; return false;
} }

View file

@ -14,11 +14,16 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use dcAdminFilters;
use adminGenericFilterV2;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use dcPage; use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Core\Backend\Filter\{
Filters,
FiltersLibrary
};
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Div, Div,
@ -37,27 +42,16 @@ use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Network\Http; use Dotclear\Helper\Network\Http;
use Exception; use Exception;
class Manage extends dcNsProcess class Manage extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::MANAGE));
&& !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;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false;
}
// nullsafe check
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false; return false;
} }
@ -93,16 +87,15 @@ class Manage extends dcNsProcess
'page' => (array) $_POST['filter_page'], '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(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Filter successfully updated.') __('Filter successfully updated.')
); );
dcCore::app()->adminurl->redirect( My::redirect(
'admin.plugin.' . My::id(),
['part' => $filter->id()], ['part' => $filter->id()],
'#settings' '#settings'
); );
@ -119,18 +112,17 @@ class Manage extends dcNsProcess
$cur->setField('epc_value', Html::escapeHTML($_POST['new_value'])); $cur->setField('epc_value', Html::escapeHTML($_POST['new_value']));
if (EpcRecord::isRecord($cur->getField('epc_filter'), $cur->getField('epc_key'))) { 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 { } else {
EpcRecord::addRecord($cur); EpcRecord::addRecord($cur);
dcCore::app()->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Filter successfully updated.') __('Filter successfully updated.')
); );
} }
dcCore::app()->adminurl->redirect( My::redirect(
'admin.plugin.' . My::id(),
['part' => $filter->id()], ['part' => $filter->id()],
'#record' '#record'
); );
@ -148,15 +140,14 @@ class Manage extends dcNsProcess
dcCore::app()->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Filter successfully updated.') __('Filter successfully updated.')
); );
if (!empty($_REQUEST['redir'])) { if (!empty($_REQUEST['redir'])) {
Http::redirect($_REQUEST['redir']); Http::redirect($_REQUEST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect( My::redirect(
'admin.plugin.' . My::id(),
['part' => $filter->id()], ['part' => $filter->id()],
'#record' '#record'
); );
@ -171,12 +162,7 @@ class Manage extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return;
}
// nullsafe check
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return; return;
} }
@ -193,8 +179,8 @@ class Manage extends dcNsProcess
// Prepare tabs and lists // Prepare tabs and lists
$header = ''; $header = '';
if ($filter->has_list) { if ($filter->has_list) {
$sorts = new adminGenericFilterV2('epc'); $sorts = new Filters('epc');
$sorts->add(dcAdminFilters::getPageFilter()); $sorts->add(FiltersLibrary::getPageFilter());
$sorts->add('part', $filter->id()); $sorts->add('part', $filter->id());
$params = $sorts->params(); $params = $sorts->params();
@ -208,14 +194,14 @@ class Manage extends dcNsProcess
dcCore::app()->error->add($e->getMessage()); 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 // display
dcPage::openModule( Page::openModule(
My::name(), My::name(),
dcPage::jsPageTabs() . Page::jsPageTabs() .
dcPage::jsModuleLoad(My::id() . '/js/backend.js') . My::jsLoad('backend') .
$header . $header .
# --BEHAVIOR-- enhancePostContentAdminHeader # --BEHAVIOR-- enhancePostContentAdminHeader
@ -223,119 +209,184 @@ class Manage extends dcNsProcess
); );
echo echo
dcPage::breadcrumb([ Page::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
My::name() => '', My::name() => '',
$filter->name => '', $filter->name => '',
]) . ]) .
dcPage::notices(); Notices::getNotices();
// filters select menu // filters select menu
echo echo
(new Form('filters_menu'))->method('get')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->fields([ (new Form('filters_menu'))
(new Para())->class('anchor-nav')->items([ ->method('get')
(new Select('part'))->items($filters->nid())->default($filter->id()), ->action(dcCore::app()->admin->getPageURL())
(new Submit(['do']))->value(__('Ok')), ->fields([
(new Hidden(['p'], My::id())), (new Para())
]), ->class('anchor-nav')
])->render(); ->items([
(new Select('part'))
// selected filter ->items($filters->nid())
echo ->default($filter->id()),
'<h3>' . $filter->name . '</h3>' . (new Submit(['do']))
'<p>' . $filter->description . '</p>'; ->value(__('Ok')),
... My::hiddenFields(),
]),
])
->render();
// Filter settings // Filter settings
$form_pages = [(new Text('h4', __('Pages to be filtered')))]; $form_pages = [(new Text('h4', __('Pages to be filtered')))];
foreach (Epc::blogAllowedTemplatePage() as $k => $v) { foreach (Epc::blogAllowedTemplatePage() as $k => $v) {
$form_pages[] = (new Para())->items([ $form_pages[] = (new Para())
(new Checkbox(['filter_page[]', 'filter_page' . $v], in_array($v, $filter->page)))->value($v), ->items([
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_page' . $v)->class('classic'), (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')))]; $form_values = [(new Text('h4', __('Contents to be filtered')))];
foreach (Epc::blogAllowedTemplateValue() as $k => $v) { foreach (Epc::blogAllowedTemplateValue() as $k => $v) {
$form_values[] = (new Para())->items([ $form_values[] = (new Para())
(new Checkbox(['filter_template[]', 'filter_template' . $v], in_array($v, $filter->template)))->value($v), ->items([
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_template' . $v)->class('classic'), (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')))]; $form_styles = [(new Text('h4', __('Style')))];
foreach ($filter->class as $k => $v) { foreach ($filter->class as $k => $v) {
$form_styles[] = (new Para())->items([ $form_styles[] = (new Para())
(new Label(sprintf(__('Class "%s":'), $v), Label::OUTSIDE_LABEL_BEFORE))->for('filter_style' . $k), ->items([
(new Input(['filter_style[]', 'filter_style' . $k]))->size(60)->maxlenght(255)->value(Html::escapeHTML($filter->style[$k])), (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 echo
(new Div('setting'))->class('multi-part')->title(__('Settings'))->items([ (new Div())
(new Form('setting_form'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#setting')->separator('')->fields([ ->items([
(new Div())->class('two-boxes even')->items($form_pages), (new Text('h3', $filter->name)),
(new Div())->class('two-boxes odd')->items([ (new Text('p', $filter->description)),
(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.') . '<br />' . (empty($filter->ignore) ? '' : sprintf(__('Tags "%s" will allways be ignored.'), Epc::encodeSingle($filter->ignore)))),
])), (new Div('setting'))
(new Div())->class('clear')->items([ ->class('multi-part')
dcCore::app()->formNonce(false), ->title(__('Settings'))
(new Hidden(['action'], 'savefiltersetting')), ->items([
(new Hidden(['part'], $filter->id())), (new Form('setting_form'))
(new Submit(['save']))->value(__('Save')), ->method('post')
]), ->action(My::manageUrl() . '#setting')
]), ->separator('')
])->render(); ->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.') . '<br />' . (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) // Filter records list (if any)
if ($filter->has_list && isset($pager)) { 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 ' echo '
<div class="multi-part" id="record" title="' . __('Records') . '">'; <div class="multi-part" id="record" title="' . __('Records') . '">';
$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( $pager->display(
$sorts, $sorts,
$pager_url, My::manageUrl(array_merge($sorts->values(true), ['page' => '%s']), '#record'),
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#record" method="post" id="form-records">' . '<form action="' . dcCore::app()->admin->getPageURL() . '#record" method="post" id="form-records">' .
'%s' . '%s' .
'<div class="two-cols">' . '<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' . '<p class="col checkboxes-helpers"></p>' .
(new Para())->class('col right')->items(array_merge( (new Para())->class('col right')
dcCore::app()->adminurl->hiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $sorts->values(true))), ->items([
[
dcCore::app()->formNonce(false),
(new Hidden('redir', dcCore::app()->adminurl->get('admin.plugin.' . My::id(), $sorts->values(true)))),
(new Hidden('action', 'deleterecords')),
(new Submit(['save', 'del-action']))->value(__('Delete selected records')), (new Submit(['save', 'del-action']))->value(__('Delete selected records')),
] ... My::hiddenFields([
))->render() . ... $sorts->values(true),
'redir' => My::manageUrl($sorts->values(true)),
'action' => 'deleterecords',
]),
])->render() .
'</div>' . '</div>' .
'</form>' '</form>'
); );
@ -344,30 +395,50 @@ class Manage extends dcNsProcess
// New record // New record
echo echo
(new Div('newrecord'))->class('multi-part')->title(__('New record'))->items([ (new Div('newrecord'))
(new Form('form-create'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#record')->fields([ ->class('multi-part')
(new Para())->items([ ->title(__('New record'))
(new Label(__('Key:'), Label::OUTSIDE_LABEL_BEFORE))->for('new_key'), ->items([
(new Input('new_key'))->size(60)->maxlenght(255)->required(true), (new Form('form-create'))
]), ->method('post')
(new Para())->items([ ->action(dcCore::app()->admin->getPageURL() . '#record')
(new Label(__('Value:'), Label::OUTSIDE_LABEL_BEFORE))->for('new_value'), ->fields([
(new Input('new_value'))->size(60)->maxlenght(255)->required(true), (new Para())
]), ->items([
(new Para())->class('clear')->items([ (new Label(__('Key:'), Label::OUTSIDE_LABEL_BEFORE))
dcCore::app()->formNonce(false), ->for('new_key'),
(new Hidden(['action'], 'savenewrecord')), (new Input('new_key'))
(new Hidden(['part'], $filter->id())), ->size(60)
(new Submit(['save', 'new-action']))->value(__('Save')), ->maxlenght(255)
]), ->required(true),
]), ]),
])->render(); (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 # --BEHAVIOR-- enhancePostContentAdminPage
dcCore::app()->callBehavior('enhancePostContentAdminPage'); dcCore::app()->callBehavior('enhancePostContentAdminPage');
dcPage::helpBlock('enhancePostContent'); Page::helpBlock('enhancePostContent');
dcPage::closeModule(); Page::closeModule();
} }
} }

View file

@ -15,11 +15,12 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use dcCore; use dcCore;
use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My class My extends MyPlugin
{ {
/** @var string Plugin table name */ /** @var string Plugin table name */
public const TABLE_NAME = 'epc'; public const TABLE_NAME = 'epc';
@ -38,29 +39,11 @@ class My
Filter\EpcFilterTwitter::class, Filter\EpcFilterTwitter::class,
]; ];
/** public static function checkCustomContext(int $context): ?bool
* This module id.
*/
public static function id(): string
{ {
return basename(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);
* 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__);
} }
} }

View file

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
class Prepend extends dcNsProcess class Prepend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_RC_PATH'); return self::status(My::checkContext(My::PREPEND));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }

View file

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
class Uninstall extends dcNsProcess class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::UNINSTALL));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }

View file

@ -93,7 +93,7 @@ class Widgets
} }
# Page # 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']) || !in_array(dcCore::app()->ctx?->__get('current_tpl'), ['post.html', 'page.html'])
) { ) {
return ''; return '';