release 2023.07.30
This commit is contained in:
parent
c9d8a62eaa
commit
8462d3d97d
15 changed files with 333 additions and 271 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="enhancePostContent">
|
||||
<name>Enhance post content</name>
|
||||
<version>2023.05.13.1</version>
|
||||
<version>2023.07.30</version>
|
||||
<author>Jean-Christian Denis and Contributors</author>
|
||||
<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>
|
||||
<da:dcmin>2.26</da:dcmin>
|
||||
<file>https://github.com/JcDenis/enhancePostContent/releases/download/v2023.07.30/plugin-enhancePostContent.zip</file>
|
||||
<da:dcmin>2.27</da:dcmin>
|
||||
<da:details>https://plugins.dotaddict.org/dc2/details/enhancePostContent</da:details>
|
||||
<da:support>https://github.com/JcDenis/enhancePostContent</da:support>
|
||||
</module>
|
||||
|
|
134
src/Backend.php
134
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
|
||||
'<div class="fieldset"><h4 id="epc_params">' . My::name() . '</h4>' .
|
||||
'<div class="two-cols">' .
|
||||
'<div class="col">' .
|
||||
// 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() .
|
||||
'<p class="form-note">' .
|
||||
__('This enable public widgets and contents filter.') .
|
||||
'</p>' .
|
||||
'<p><a href="' . dcCore::app()->adminurl?->get('admin.plugin.' . My::id()) . '">' .
|
||||
__('Set content filters') . '</a></p>' .
|
||||
'</div>' .
|
||||
'<div class="col">' .
|
||||
'<h5>' . __('Extra') . '</h5>' .
|
||||
'<p>' . __('This is a special feature to edit list of allowed template values and public pages where this plugin works.') . '</p>' .
|
||||
// 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() .
|
||||
'<p class="form-note">' . __('Use "readable_name1:template_value1;readable_name2:template_value2;" like "entry content:EntryContent;entry excerpt:EntryExcerpt;".') . '</p>' .
|
||||
// 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() .
|
||||
'<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>' .
|
||||
'<br class="clear" />' .
|
||||
'</div>';
|
||||
(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 {
|
||||
|
|
|
@ -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 '<p><strong>' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '</strong></p>';
|
||||
|
@ -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 = [];
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 = [];
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
343
src/Manage.php
343
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
|
||||
'<h3>' . $filter->name . '</h3>' .
|
||||
'<p>' . $filter->description . '</p>';
|
||||
(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.') . '<br />' . (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.') . '<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)
|
||||
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 '
|
||||
<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(
|
||||
$sorts,
|
||||
$pager_url,
|
||||
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#record" method="post" id="form-records">' .
|
||||
My::manageUrl(array_merge($sorts->values(true), ['page' => '%s']), '#record'),
|
||||
'<form action="' . dcCore::app()->admin->getPageURL() . '#record" method="post" id="form-records">' .
|
||||
'%s' .
|
||||
|
||||
'<div class="two-cols">' .
|
||||
'<p class="col checkboxes-helpers"></p>' .
|
||||
|
||||
(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() .
|
||||
'</div>' .
|
||||
'</form>'
|
||||
);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
31
src/My.php
31
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 '';
|
||||
|
|
Loading…
Reference in a new issue