From 208963952c3bc0705296d8dfba3186eada6ab878 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Wed, 11 Oct 2023 21:02:43 +0200 Subject: [PATCH] release 2023.10.11 --- README.md | 4 -- _define.php | 33 +++++++--------- _init.php | 20 ---------- dcstore.xml | 4 +- src/Backend.php | 20 +++++----- src/BackendList.php | 36 ++++++++--------- src/Epc.php | 59 ++++++++++++++++++++++++---- src/EpcFilter.php | 31 ++++++--------- src/EpcFilters.php | 19 ++++----- src/EpcRecord.php | 29 ++++++-------- src/Filter/EpcFilterAbbreviation.php | 20 +++++----- src/Filter/EpcFilterAcronym.php | 20 +++++----- src/Filter/EpcFilterCitation.php | 20 +++++----- src/Filter/EpcFilterDefinition.php | 20 +++++----- src/Filter/EpcFilterLink.php | 20 +++++----- src/Filter/EpcFilterReplace.php | 20 +++++----- src/Filter/EpcFilterSearch.php | 20 +++++----- src/Filter/EpcFilterTag.php | 20 +++++----- src/Filter/EpcFilterTwitter.php | 20 +++++----- src/Filter/EpcFilterUpdate.php | 20 +++++----- src/Frontend.php | 20 +++++----- src/Install.php | 32 +++++++-------- src/Manage.php | 8 ++++ src/My.php | 51 ++++++++---------------- src/Prepend.php | 22 +++++------ src/Uninstall.php | 24 ++++++----- src/Widgets.php | 21 ++++------ 27 files changed, 291 insertions(+), 342 deletions(-) delete mode 100644 _init.php diff --git a/README.md b/README.md index 3d6f889..c0e0cba 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,6 @@ you should also add widgets. ## LINKS -* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) -* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/enhancePostContent) or [GitHub Page](https://github.com/JcDenis/enhancePostContent) -* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/enhancePostContent/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/enhancePostContent) - * [License](https://git.dotclear.watch/JcDenis/enhancePostContent/src/branch/master/LICENSE) * [Packages & details](https://git.dotclear.watch/JcDenis/enhancePostContent/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/enhancePostContent)) * [Sources & contributions](https://git.dotclear.watch/JcDenis/enhancePostContent) (or on [GitHub](https://github.com/JcDenis/enhancePostContent)) diff --git a/_define.php b/_define.php index 0385378..041e56b 100644 --- a/_define.php +++ b/_define.php @@ -1,35 +1,30 @@ registerModule( 'Enhance post content', 'Add features to words in post content', 'Jean-Christian Denis and Contributors', - '2023.08.14', + '2023.10.11', [ - 'requires' => [ - ['php', '8.1'], - ['core', '2.28'], - ], - 'permissions' => App::auth()->makePermissions([ - App::auth()::PERMISSION_CONTENT_ADMIN, - ]), - 'settings' => [ + 'type' => 'plugin', + 'requires' => [['core', '2.28']], + 'permissions' => 'My', + 'settings' => [ + 'self' => '', 'blog' => '#params.epc_params', ], - 'type' => 'plugin', 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', diff --git a/_init.php b/_init.php deleted file mode 100644 index 75ec68c..0000000 --- a/_init.php +++ /dev/null @@ -1,20 +0,0 @@ - Enhance post content - 2023.10.08 + 2023.10.11 Jean-Christian Denis and Contributors Add features to words in post content - https://git.dotclear.watch/JcDenis/enhancePostContent/releases/download/v2023.10.08/plugin-enhancePostContent.zip + https://git.dotclear.watch/JcDenis/enhancePostContent/releases/download/v2023.10.11/plugin-enhancePostContent.zip 2.28 https://git.dotclear.watch/JcDenis/enhancePostContent/src/branch/master/README.md https://git.dotclear.watch/JcDenis/enhancePostContent/issues diff --git a/src/Backend.php b/src/Backend.php index a8b1070..07e23e4 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,15 +1,5 @@ value('page'), $this->rs_count, $filter->value('nb'), 10); + $pager = new Pager($filter->value('page'), (int) $this->rs_count, $filter->value('nb'), 10); $pager->base_url = $url; $epc_id = []; @@ -71,7 +67,7 @@ class BackendList extends Listing echo $pager->getLinks() . $blocks[0]; while ($this->rs->fetch()) { - $this->line(isset($epc_id[$this->rs->epc_id])); + $this->line(isset($epc_id[$this->rs->f('epc_id')])); } echo $blocks[1] . $blocks[2] . $pager->getLinks(); @@ -85,15 +81,15 @@ class BackendList extends Listing private function line(bool $checked): void { $cols = [ - 'check' => '' . (new Checkbox(['epc_id[]'], $checked))->value($this->rs->epc_id)->render() . '', - 'key' => '' . Html::escapeHTML($this->rs->epc_key) . '', - 'value' => '' . Html::escapeHTML($this->rs->epc_value) . '', - 'date' => '' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . '', + 'check' => '' . (new Checkbox(['epc_id[]'], $checked))->value($this->rs->f('epc_id'))->render() . '', + 'key' => '' . Html::escapeHTML($this->rs->f('epc_key')) . '', + 'value' => '' . Html::escapeHTML($this->rs->f('epc_value')) . '', + 'date' => '' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('epc_upddt')) . '', ]; echo - '' . + '' . implode($cols) . ''; } -} +} \ No newline at end of file diff --git a/src/Epc.php b/src/Epc.php index 73b2ae3..ad280fa 100644 --- a/src/Epc.php +++ b/src/Epc.php @@ -31,15 +31,60 @@ __('search results page'); __('atom feeds'); __('RSS feeds'); +/** + * @brief enhancePostContent main class. + * @ingroup enhancePostContent + * + * @author Jean-Christian Denis + * @copyright Jean-Christian Denis + * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html + */ class Epc { - /** @var string The temporary pattern to tag words to replace */ + /** + * Plugin table name. + * + * @var string TABLE_NAME + */ + public const TABLE_NAME = 'epc'; + + /** + * Distributed filters. + * + * @var array DEFAULT_FILTERS + */ + public const DEFAULT_FILTERS = [ + Filter\EpcFilterTag::class, + Filter\EpcFilterSearch::class, + Filter\EpcFilterAcronym::class, + Filter\EpcFilterAbbreviation::class, + Filter\EpcFilterDefinition::class, + Filter\EpcFilterCitation::class, + Filter\EpcFilterLink::class, + Filter\EpcFilterReplace::class, + Filter\EpcFilterUpdate::class, + Filter\EpcFilterTwitter::class, + ]; + + /** + * The temporary pattern to tag words to replace. + * + * @var string FLAGGER + */ public const FLAGGER = 'ççççç%sççççç'; - /** @var EpcFilters $filters THe filters stack */ + /** + * The filters stack. + * + * @var EpcFilters $filters + */ private static EpcFilters $filters; - /** @var array $limits The replacment limit per filtre */ + /** + * The replacment limit per filtre. + * + * @var array $limits + */ private static array $limits = []; /** @@ -76,7 +121,7 @@ class Epc /** * Get list of allowed templates name->[tag,callback] to list on epc widgets. * - * @return array The templates name->[id,cb] values + * @return array The templates name->[id,cb] values */ public static function widgetAllowedTemplateValue(): array { @@ -402,7 +447,7 @@ class Epc $content = ''; while (App::frontend()->ctx->__get('posts')?->fetch()) { - $content .= dApp::frontend()->ctx->__get('posts')->f('post_content'); + $content .= App::frontend()->ctx->__get('posts')->f('post_content'); } return $content; @@ -422,9 +467,9 @@ class Epc } $content = ''; - while (App::frontend()->ctx->__get('posts')?->fetch()) { + while (App::frontend()->ctx->__get('posts')->fetch()) { $comments = App::blog()->getComments(['post_id' => App::frontend()->ctx->__get('posts')->f('post_id')]); - while ($comments?->fetch()) { + while ($comments->fetch()) { $content .= $comments->__call('getContent', []); } } diff --git a/src/EpcFilter.php b/src/EpcFilter.php index 6521a6a..e5323a1 100644 --- a/src/EpcFilter.php +++ b/src/EpcFilter.php @@ -1,15 +1,5 @@ $ignore The filter disabled html tags (property) */ public readonly array $ignore; - /** @var array $class The css class that apply to filter (property) */ + /** @var array $class The css class that apply to filter (property) */ public readonly array $class; /** @var string $replace The filter replacement bloc in content (property) */ @@ -65,16 +60,16 @@ abstract class EpcFilter /** @var bool $plural The replacement limit per filter (settings) */ public readonly int $limit; - /** @var array $style The style applied to filter class (settings) */ + /** @var array $style The style applied to filter class (settings) */ public readonly array $style; - /** @var array $notag The filter disabled html tags (settings) */ + /** @var array $notag The filter disabled html tags (settings) */ public readonly array $notag; - /** @var array $template The extra template value to scan (settings) */ + /** @var array $template The extra template value to scan (settings) */ public readonly array $template; - /** @var array $page The extra frontend pages to scan (settings) */ + /** @var array $page The extra frontend pages to scan (settings) */ public readonly array $page; /** diff --git a/src/EpcFilters.php b/src/EpcFilters.php index 69fdfca..374cad5 100644 --- a/src/EpcFilters.php +++ b/src/EpcFilters.php @@ -1,23 +1,18 @@ prefix() . My::TABLE_NAME . ' E '; + $strReq .= 'FROM ' . App::con()->prefix() . Epc::TABLE_NAME . ' E '; if (!empty($params['from'])) { $strReq .= $params['from'] . ' '; @@ -121,7 +116,7 @@ class EpcRecord */ public static function addRecord(Cursor $cur): int { - App::con()->writeLock(App::con()->prefix() . My::TABLE_NAME); + App::con()->writeLock(App::con()->prefix() . Epc::TABLE_NAME); try { $cur->setField('epc_id', self::getNextId()); @@ -199,7 +194,7 @@ class EpcRecord App::behavior()->callBehavior('enhancePostContentbeforeDelRecord', $id); App::con()->execute( - 'DELETE FROM ' . App::con()->prefix() . My::TABLE_NAME . ' ' . + 'DELETE FROM ' . App::con()->prefix() . Epc::TABLE_NAME . ' ' . 'WHERE epc_id = ' . $id . ' ' . "AND blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' " ); @@ -215,7 +210,7 @@ class EpcRecord private static function getNextId(): int { return (int) App::con()->select( - 'SELECT MAX(epc_id) FROM ' . App::con()->prefix() . My::TABLE_NAME . ' ' + 'SELECT MAX(epc_id) FROM ' . App::con()->prefix() . Epc::TABLE_NAME . ' ' )->f(0) + 1; } @@ -226,7 +221,7 @@ class EpcRecord */ public static function openCursor(): Cursor { - return App::con()->openCursor(App::con()->prefix() . My::TABLE_NAME); + return App::con()->openCursor(App::con()->prefix() . Epc::TABLE_NAME); } /** diff --git a/src/Filter/EpcFilterAbbreviation.php b/src/Filter/EpcFilterAbbreviation.php index e336d2a..d0e8f55 100644 --- a/src/Filter/EpcFilterAbbreviation.php +++ b/src/Filter/EpcFilterAbbreviation.php @@ -1,15 +1,5 @@ prefix()); - $s->__get(My::TABLE_NAME) + $s->__get(Epc::TABLE_NAME) ->field('epc_id', 'bigint', 0, false) ->field('blog_id', 'varchar', 32, false) ->field('epc_type', 'varchar', 32, false, "'epc'") @@ -124,10 +122,10 @@ class Install extends Process $curlist = @unserialize($record->f('setting_value')); if (is_array($curlist)) { foreach ($curlist as $k => $v) { - $cur = App::con()->openCursor(App::con()->prefix() . My::TABLE_NAME); - App::con()->writeLock(App::con()->prefix() . My::TABLE_NAME); + $cur = App::con()->openCursor(App::con()->prefix() . Epc::TABLE_NAME); + App::con()->writeLock(App::con()->prefix() . Epc::TABLE_NAME); - $cur->setField('epc_id', (int) App::con()->select('SELECT MAX(epc_id) FROM ' . App::con()->prefix() . My::TABLE_NAME . ' ')->f(0) + 1); + $cur->setField('epc_id', (int) App::con()->select('SELECT MAX(epc_id) FROM ' . App::con()->prefix() . Epc::TABLE_NAME . ' ')->f(0) + 1); $cur->setField('blog_id', $record->f('blog_id')); $cur->setField('epc_filter', strtolower($m[1])); $cur->setField('epc_key', $k); @@ -150,9 +148,9 @@ class Install extends Process private static function upTo20211006(): void { # Move old filter name to filter id - $record = App::con()->select('SELECT epc_id, epc_filter FROM ' . App::con()->prefix() . My::TABLE_NAME); + $record = App::con()->select('SELECT epc_id, epc_filter FROM ' . App::con()->prefix() . Epc::TABLE_NAME); while ($record->fetch()) { - $cur = App::con()->openCursor(App::con()->prefix() . My::TABLE_NAME); + $cur = App::con()->openCursor(App::con()->prefix() . Epc::TABLE_NAME); $cur->setField('epc_filter', strtolower($record->f('epc_filter'))); diff --git a/src/Manage.php b/src/Manage.php index c7d5b59..7500012 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -42,6 +42,14 @@ use Dotclear\Helper\Html\Html; use Dotclear\Helper\Network\Http; use Exception; +/** + * @brief enhancePostContent manage class. + * @ingroup enhancePostContent + * + * @author Jean-Christian Denis + * @copyright Jean-Christian Denis + * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html + */ class Manage extends Process { public static function init(): bool diff --git a/src/My.php b/src/My.php index 8264d27..b6576c3 100644 --- a/src/My.php +++ b/src/My.php @@ -1,15 +1,5 @@ check(App::auth()->makePermissions([ - App::auth()::PERMISSION_CONTENT_ADMIN, - ]), App::blog()->id()); - } -} + return match ($context) { + // Limit main backend featrues to content admin + self::BACKEND, self::MANAGE, self::MENU => + App::auth()->check(App::auth()->makePermissions([ + App::auth()::PERMISSION_CONTENT_ADMIN, + ]), App::blog()->id()), + + default => null, + \ No newline at end of file diff --git a/src/Prepend.php b/src/Prepend.php index 81ec363..fa239ec 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -1,15 +1,5 @@ addBehavior('enhancePostContentFilters', function (EpcFilters $stack): void { - foreach (My::DEFAULT_FILTERS as $class) { + foreach (Epc::DEFAULT_FILTERS as $class) { $stack->add(new $class()); } }); diff --git a/src/Uninstall.php b/src/Uninstall.php index f1b6223..3429648 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -1,15 +1,5 @@ addUserAction( 'tables', 'delete', - My::TABLE_NAME + Epc::TABLE_NAME ) ->addUserAction( 'plugins', @@ -59,7 +57,7 @@ class Uninstall extends Process ->addDirectAction( 'tables', 'delete', - My::TABLE_NAME + Epc::TABLE_NAME ) ->addDirectAction( 'plugins', diff --git a/src/Widgets.php b/src/Widgets.php index 2b82e1b..1c8e3d3 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -1,15 +1,5 @@