From aa05e6e1b51acf5844ec2e7b50a807422506ad02 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 8 Oct 2023 00:35:35 +0200 Subject: [PATCH] release 2023.10.08 --- CHANGELOG.md | 6 ++++ README.md | 28 ++++++++-------- _define.php | 11 +++---- dcstore.xml | 6 ++-- src/Backend.php | 12 +++---- src/Epc.php | 30 ++++++++--------- src/EpcRecord.php | 60 +++++++++++++++++----------------- src/Filter/EpcFilterSearch.php | 6 ++-- src/Filter/EpcFilterTag.php | 14 ++++---- src/Frontend.php | 9 +++-- src/Install.php | 39 ++++++++++------------ src/Manage.php | 26 +++++++-------- src/My.php | 8 ++--- src/Prepend.php | 6 ++-- src/Uninstall.php | 3 +- src/Widgets.php | 4 +-- 16 files changed, 133 insertions(+), 135 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8758cb1..ae8bd74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +enhancePostContent 2023.10.08 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1 +* Upgrade to Dotclear 2.28 + enhancePostContent 2023.08.14 =========================================================== * Require Dotclear 2.27 diff --git a/README.md b/README.md index 5a9fc8d..3d6f889 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,22 @@ # README -[![Release](https://img.shields.io/badge/release-2023.08.14-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/enhancePostContent/releases) -[![Date](https://img.shields.io/badge/date-2023.08.14-c44d58.svg)](https://git.dotclear.watch/JcDenis/enhancePostContent/releases) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) +[![Release](https://img.shields.io/badge/release-2023.10.08-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/enhancePostContent/releases) +![Date](https://img.shields.io/badge/date-2023.10.08-c44d58.svg) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/enhancePostContent) -[![License](https://img.shields.io/github/license/JcDenis/enhancePostContent)](https://git.dotclear.watch/JcDenis/enhancePostContent/blob/master/LICENSE) +[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/enhancePostContent/src/branch/master/LICENSE) -## WHAT IS ENHANCEPOSTCONTENT ? +## ABOUT -"Enhance Post Content" is a plugin for the open-source -web publishing software called Dotclear. +_enhancePostContent_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). -It help to filter post content and extract or -show inline more info about words and expressions such as -atgs, acronyms, abbreviations, definition, citation, link, etc... +> It help to filter post content and extract or show inline more info about words and expressions such as tags, acronyms, abbreviations, definition, citation, link, etc... ## REQUIREMENTS -_enhancePostContent_ requires: - * admin permissions to set up plugin * content admin permissions to manage fitlers -* Dotclear 2.27 +* Dotclear 2.28 * PHP 8.1+ ## USAGE @@ -40,7 +35,12 @@ you should also add widgets. * 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) -* Discuss and help : [Dotclear Forum](http://forum.dotclear.org/viewtopic.php?id=40876) + +* [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)) +* [Issues & security](https://git.dotclear.watch/JcDenis/enhancePostContent/issues) (or on [GitHub](https://github.com/JcDenis/enhancePostContent/issues)) +* [Discuss and help](http://forum.dotclear.org/viewtopic.php?id=40876) ## CONTRIBUTORS diff --git a/_define.php b/_define.php index 61e4d54..0385378 100644 --- a/_define.php +++ b/_define.php @@ -10,9 +10,8 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_RC_PATH')) { - return null; -} + +use Dotclear\App; $this->registerModule( 'Enhance post content', @@ -22,10 +21,10 @@ $this->registerModule( [ 'requires' => [ ['php', '8.1'], - ['core', '2.27'], + ['core', '2.28'], ], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcAuth::PERMISSION_CONTENT_ADMIN, + 'permissions' => App::auth()->makePermissions([ + App::auth()::PERMISSION_CONTENT_ADMIN, ]), 'settings' => [ 'blog' => '#params.epc_params', diff --git a/dcstore.xml b/dcstore.xml index 02e069f..fd36c03 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Enhance post content - 2023.08.14 + 2023.10.08 Jean-Christian Denis and Contributors Add features to words in post content - https://git.dotclear.watch/JcDenis/enhancePostContent/releases/download/v2023.08.14/plugin-enhancePostContent.zip - 2.27 + https://git.dotclear.watch/JcDenis/enhancePostContent/releases/download/v2023.10.08/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 33fc1a7..a8b1070 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -15,9 +15,9 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; use ArrayObject; -use dcCore; -use dcSettings; +use Dotclear\App; use Dotclear\Core\Backend\Favorites; +use Dotclear\Core\BlogSettings; use Dotclear\Core\Process; use Dotclear\Helper\Html\Form\{ Checkbox, @@ -45,7 +45,7 @@ class Backend extends Process My::addBackendMenuItem(); - dcCore::app()->addBehaviors([ + App::behavior()->addBehaviors([ // backend user dashboard favorites icon 'adminDashboardFavoritesV2' => function (Favorites $favs): void { $favs->register(My::id(), [ @@ -53,11 +53,11 @@ class Backend extends Process 'url' => My::manageUrl(), 'small-icon' => My::icons(), 'large-icon' => My::icons(), - 'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), + 'permissions' => App::auth()->makePermissions([App::auth()::PERMISSION_CONTENT_ADMIN]), ]); }, // backend user preference form - 'adminBlogPreferencesFormV2' => function (dcSettings $blog_settings): void { + 'adminBlogPreferencesFormV2' => function (BlogSettings $blog_settings): void { $active = (bool) $blog_settings->get(My::id())->get('active'); $allowedtplvalues = Epc::blogAllowedTemplateValue(); $allowedpubpages = Epc::blogAllowedTemplatePage(); @@ -123,7 +123,7 @@ class Backend extends Process ->render(); }, // backend user preference save - 'adminBeforeBlogSettingsUpdate' => function (dcSettings $blog_settings): void { + 'adminBeforeBlogSettingsUpdate' => function (BlogSettings $blog_settings): void { $active = !empty($_POST['epc_active']); $allowedtplvalues = Epc::decodeMulti($_POST['epc_allowedtplvalues']); $allowedpubpages = Epc::decodeMulti($_POST['epc_allowedpubpages']); diff --git a/src/Epc.php b/src/Epc.php index 1c602e2..73b2ae3 100644 --- a/src/Epc.php +++ b/src/Epc.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; use ArrayObject; -use dcCore; +use Dotclear\App; use Dotclear\Helper\Html\Html; use Dotclear\Plugin\widgets\WidgetsElement; use Exception; @@ -56,7 +56,7 @@ class Epc ]); # --BEHAVIOR-- enhancePostContentAllowedTplValues : ArrayObject - dcCore::app()->callBehavior('enhancePostContentAllowedTplValues', $list); + App::behavior()->callBehavior('enhancePostContentAllowedTplValues', $list); return iterator_to_array($list, true); } @@ -96,7 +96,7 @@ class Epc ]); # --BEHAVIOR-- enhancePostContentAllowedWidgetValues : ArrayObject - dcCore::app()->callBehavior('enhancePostContentAllowedWidgetValues', $list); + App::behavior()->callBehavior('enhancePostContentAllowedWidgetValues', $list); return iterator_to_array($list, true); } @@ -118,7 +118,7 @@ class Epc ]); # --BEHAVIOR-- enhancePostContentAllowedPubPages : ArrayObject - dcCore::app()->callBehavior('enhancePostContentAllowedPubPages', $list); + App::behavior()->callBehavior('enhancePostContentAllowedPubPages', $list); return iterator_to_array($list, true); } @@ -149,9 +149,9 @@ class Epc try { # --BEHAVIOR-- enhancePostContentFilters : EpcFilters - dcCore::app()->callBehavior('enhancePostContentFilters', $filters); + App::behavior()->callBehavior('enhancePostContentFilters', $filters); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } self::$filters = $filters->sort(); @@ -375,13 +375,13 @@ class Epc */ public static function widgetContentEntryExcerpt(?WidgetsElement $widget = null): string { - if (is_null(dcCore::app()->ctx) || !dcCore::app()->ctx->exists('posts')) { + if (!App::frontend()->ctx->exists('posts')) { return ''; } $content = ''; - while (dcCore::app()->ctx->__get('posts')?->fetch()) { - $content .= dcCore::app()->ctx->__get('posts')->f('post_excerpt'); + while (App::frontend()->ctx->__get('posts')?->fetch()) { + $content .= App::frontend()->__get('posts')->f('post_excerpt'); } return $content; @@ -396,13 +396,13 @@ class Epc */ public static function widgetContentEntryContent(?WidgetsElement $widget = null): string { - if (is_null(dcCore::app()->ctx) || !dcCore::app()->ctx->exists('posts')) { + if (!App::frontend()->ctx->exists('posts')) { return ''; } $content = ''; - while (dcCore::app()->ctx->__get('posts')?->fetch()) { - $content .= dcCore::app()->ctx->__get('posts')->f('post_content'); + while (App::frontend()->ctx->__get('posts')?->fetch()) { + $content .= dApp::frontend()->ctx->__get('posts')->f('post_content'); } return $content; @@ -417,13 +417,13 @@ class Epc */ public static function widgetContentCommentContent(?WidgetsElement $widget = null): string { - if (is_null(dcCore::app()->ctx) || !dcCore::app()->ctx->exists('posts')) { + if (!App::frontend()->ctx->exists('posts')) { return ''; } $content = ''; - while (dcCore::app()->ctx->__get('posts')?->fetch()) { - $comments = dcCore::app()->blog?->getComments(['post_id' => dcCore::app()->ctx->__get('posts')->f('post_id')]); + while (App::frontend()->ctx->__get('posts')?->fetch()) { + $comments = App::blog()->getComments(['post_id' => App::frontend()->ctx->__get('posts')->f('post_id')]); while ($comments?->fetch()) { $content .= $comments->__call('getContent', []); } diff --git a/src/EpcRecord.php b/src/EpcRecord.php index d814c51..0f70cf3 100644 --- a/src/EpcRecord.php +++ b/src/EpcRecord.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; -use dcCore; +use Dotclear\App; use Dotclear\Database\{ Cursor, MetaRecord @@ -48,19 +48,19 @@ class EpcRecord 'E.epc_filter, E.epc_key, E.epc_value '; } - $strReq .= 'FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' E '; + $strReq .= 'FROM ' . App::con()->prefix() . My::TABLE_NAME . ' E '; if (!empty($params['from'])) { $strReq .= $params['from'] . ' '; } - $strReq .= "WHERE E.blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' "; + $strReq .= "WHERE E.blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' "; if (isset($params['epc_type'])) { if (is_array($params['epc_type']) && !empty($params['epc_type'])) { - $strReq .= 'AND E.epc_type ' . dcCore::app()->con->in($params['epc_type']); + $strReq .= 'AND E.epc_type ' . App::con()->in($params['epc_type']); } elseif ($params['epc_type'] != '') { - $strReq .= "AND E.epc_type = '" . dcCore::app()->con->escapeStr((string) $params['epc_type']) . "' "; + $strReq .= "AND E.epc_type = '" . App::con()->escapeStr((string) $params['epc_type']) . "' "; } } else { $strReq .= "AND E.epc_type = 'epc' "; @@ -68,9 +68,9 @@ class EpcRecord if (isset($params['epc_filter'])) { if (is_array($params['epc_filter']) && !empty($params['epc_filter'])) { - $strReq .= 'AND E.epc_filter ' . dcCore::app()->con->in($params['epc_filter']); + $strReq .= 'AND E.epc_filter ' . App::con()->in($params['epc_filter']); } elseif ($params['epc_filter'] != '') { - $strReq .= "AND E.epc_filter = '" . dcCore::app()->con->escapeStr((string) $params['epc_filter']) . "' "; + $strReq .= "AND E.epc_filter = '" . App::con()->escapeStr((string) $params['epc_filter']) . "' "; } } @@ -80,16 +80,16 @@ class EpcRecord } else { $params['epc_id'] = [(int) $params['epc_id']]; } - $strReq .= 'AND E.epc_id ' . dcCore::app()->con->in($params['epc_id']); + $strReq .= 'AND E.epc_id ' . App::con()->in($params['epc_id']); } elseif (isset($params['not_id']) && is_numeric($params['not_id'])) { $strReq .= "AND NOT E.epc_id = '" . $params['not_id'] . "' "; } if (isset($params['epc_key'])) { if (is_array($params['epc_key']) && !empty($params['epc_key'])) { - $strReq .= 'AND E.epc_key ' . dcCore::app()->con->in($params['epc_key']); + $strReq .= 'AND E.epc_key ' . App::con()->in($params['epc_key']); } elseif ($params['epc_key'] != '') { - $strReq .= "AND E.epc_key = '" . dcCore::app()->con->escapeStr((string) $params['epc_key']) . "' "; + $strReq .= "AND E.epc_key = '" . App::con()->escapeStr((string) $params['epc_key']) . "' "; } } @@ -99,17 +99,17 @@ class EpcRecord if (!$count_only) { if (!empty($params['order'])) { - $strReq .= 'ORDER BY ' . dcCore::app()->con->escapeStr((string) $params['order']) . ' '; + $strReq .= 'ORDER BY ' . App::con()->escapeStr((string) $params['order']) . ' '; } else { $strReq .= 'ORDER BY E.epc_key ASC '; } } if (!$count_only && !empty($params['limit'])) { - $strReq .= dcCore::app()->con->limit($params['limit']); + $strReq .= App::con()->limit($params['limit']); } - return new MetaRecord(dcCore::app()->con->select($strReq)); + return new MetaRecord(App::con()->select($strReq)); } /** @@ -121,26 +121,26 @@ class EpcRecord */ public static function addRecord(Cursor $cur): int { - dcCore::app()->con->writeLock(dcCore::app()->prefix . My::TABLE_NAME); + App::con()->writeLock(App::con()->prefix() . My::TABLE_NAME); try { $cur->setField('epc_id', self::getNextId()); - $cur->setField('blog_id', (string) dcCore::app()->blog?->id); + $cur->setField('blog_id', App::blog()->id()); $cur->setField('epc_upddt', date('Y-m-d H:i:s')); self::getCursor($cur); $cur->insert(); - dcCore::app()->con->unlock(); + App::con()->unlock(); } catch (Exception $e) { - dcCore::app()->con->unlock(); + App::con()->unlock(); throw $e; } - dcCore::app()->blog?->triggerBlog(); + App::blog()->triggerBlog(); # --BEHAVIOR-- enhancePostContentAfterAddRecord : Cursor - dcCore::app()->callBehavior('enhancePostContentAfterAddRecord', $cur); + App::behavior()->callBehavior('enhancePostContentAfterAddRecord', $cur); return (int) $cur->getField('epc_id'); } @@ -159,11 +159,11 @@ class EpcRecord $cur->setField('epc_upddt', date('Y-m-d H:i:s')); - $cur->update('WHERE epc_id = ' . $id . " AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' "); - dcCore::app()->blog?->triggerBlog(); + $cur->update('WHERE epc_id = ' . $id . " AND blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' "); + App::blog()->triggerBlog(); # --BEHAVIOR-- enhancePostContentAfterUpdRecord : Cursor, int - dcCore::app()->callBehavior('enhancePostContentAfterUpdRecord', $cur, $id); + App::behavior()->callBehavior('enhancePostContentAfterUpdRecord', $cur, $id); } /** @@ -196,15 +196,15 @@ class EpcRecord } # --BEHAVIOR-- enhancePostContentBeforeDelRecord, int - dcCore::app()->callBehavior('enhancePostContentbeforeDelRecord', $id); + App::behavior()->callBehavior('enhancePostContentbeforeDelRecord', $id); - dcCore::app()->con->execute( - 'DELETE FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' ' . + App::con()->execute( + 'DELETE FROM ' . App::con()->prefix() . My::TABLE_NAME . ' ' . 'WHERE epc_id = ' . $id . ' ' . - "AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' " + "AND blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' " ); - dcCore::app()->blog?->triggerBlog(); + App::blog()->triggerBlog(); } /** @@ -214,8 +214,8 @@ class EpcRecord */ private static function getNextId(): int { - return (int) dcCore::app()->con->select( - 'SELECT MAX(epc_id) FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' ' + return (int) App::con()->select( + 'SELECT MAX(epc_id) FROM ' . App::con()->prefix() . My::TABLE_NAME . ' ' )->f(0) + 1; } @@ -226,7 +226,7 @@ class EpcRecord */ public static function openCursor(): Cursor { - return dcCore::app()->con->openCursor(dcCore::app()->prefix . My::TABLE_NAME); + return App::con()->openCursor(App::con()->prefix() . My::TABLE_NAME); } /** diff --git a/src/Filter/EpcFilterSearch.php b/src/Filter/EpcFilterSearch.php index b499e53..6c22085 100644 --- a/src/Filter/EpcFilterSearch.php +++ b/src/Filter/EpcFilterSearch.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent\Filter; -use dcCore; +use Dotclear\App; use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\EpcFilter; @@ -48,11 +48,11 @@ class EpcFilterSearch extends EpcFilter public function publicContent(string $tag, array $args): void { - if (empty(dcCore::app()->public->search)) { + if (empty(App::frontend()->search)) { return; } - $searchs = explode(' ', dcCore::app()->public->search); + $searchs = explode(' ', App::frontend()->search); foreach ($searchs as $k => $v) { $args[0] = Epc::replaceString( diff --git a/src/Filter/EpcFilterTag.php b/src/Filter/EpcFilterTag.php index fecd735..a3eb4ab 100644 --- a/src/Filter/EpcFilterTag.php +++ b/src/Filter/EpcFilterTag.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent\Filter; use ArrayObject; -use dcCore; +use Dotclear\App; use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\widgets\WidgetsElement; @@ -49,16 +49,16 @@ class EpcFilterTag extends EpcFilter public function publicContent(string $tag, array $args): void { - if (!dcCore::app()->plugins->moduleExists('tags')) { + if (!App::plugins()->moduleExists('tags')) { return; } - $metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); + $metas = App::meta()->getMetadata(['meta_type' => 'tag']); while ($metas->fetch()) { $args[0] = Epc::replaceString( $metas->f('meta_id'), - sprintf($this->replace, dcCore::app()->blog?->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'), + sprintf($this->replace, App::blog()->url() . App::url()->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'), $args[0], $this ); @@ -67,16 +67,16 @@ class EpcFilterTag extends EpcFilter public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void { - if (!dcCore::app()->plugins->moduleExists('tags')) { + if (!App::plugins()->moduleExists('tags')) { return; } - $metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); + $metas = App::meta()->getMetadata(['meta_type' => 'tag']); while ($metas->fetch()) { $list[] = Epc::matchString( $metas->f('meta_id'), - sprintf($this->widget, dcCore::app()->blog?->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'), + sprintf($this->widget, App::blog()->url() . App::url()->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'), $content, $this ); diff --git a/src/Frontend.php b/src/Frontend.php index f217419..511065b 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -14,8 +14,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; -use dcCore; -use dcUtils; +use Dotclear\App; use Dotclear\Core\Process; class Frontend extends Process @@ -31,16 +30,16 @@ class Frontend extends Process return false; } - dcCore::app()->addBehaviors([ + App::behavior()->addBehaviors([ // Add CSS URL to frontend header 'publicHeadContent' => function (): void { - echo dcUtils::cssLoad(dcCore::app()->blog?->url . dcCore::app()->url->getURLFor('epccss')); + echo App::plugins()->cssLoad(App::blog()->url() . App::url()->getURLFor('epccss')); }, // Filter template blocks content 'publicBeforeContentFilterV2' => function (string $tag, array $args): void { foreach (Epc::getFilters()->dump() as $filter) { // test context - if (in_array((string) dcCore::app()->ctx?->__get('current_tpl'), $filter->page) + if (in_array((string) App::frontend()->ctx->__get('current_tpl'), $filter->page) && in_array($tag, $filter->template) && $args[0] != '' //content && empty($args['encode_xml']) diff --git a/src/Install.php b/src/Install.php index b763da8..41a5c47 100644 --- a/src/Install.php +++ b/src/Install.php @@ -14,8 +14,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; -use dcCore; -use dcNamespace; +use Dotclear\App; use Dotclear\Core\Process; use Dotclear\Database\Structure; use Exception; @@ -35,7 +34,7 @@ class Install extends Process try { // Database - $s = new Structure(dcCore::app()->con, dcCore::app()->prefix); + $s = new Structure(App::con(), App::con()->prefix()); $s->__get(My::TABLE_NAME) ->field('epc_id', 'bigint', 0, false) ->field('blog_id', 'varchar', 32, false) @@ -51,7 +50,7 @@ class Install extends Process ->index('idx_epc_filter', 'btree', 'epc_filter') ->index('idx_epc_key', 'btree', 'epc_key'); - (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s); + (new Structure(App::con(), App::con()->prefix()))->synchronize($s); $s = null; // Uppgrade @@ -59,10 +58,6 @@ class Install extends Process // Settings $s = My::settings(); - if (is_null($s)) { - return false; - } - $s->put('active', false, 'boolean', 'Enable enhancePostContent', false, true); $s->put('list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true); $s->put('list_order', 'desc', 'string', 'Admin records list order', false, true); @@ -86,7 +81,7 @@ class Install extends Process return true; } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); return false; } @@ -97,7 +92,7 @@ class Install extends Process */ public static function growUp(): void { - $current = dcCore::app()->getVersion(My::id()); + $current = App::version()->getVersion(My::id()); if ($current && version_compare($current, '0.6.6', '<=')) { self::upTo00060607(); @@ -122,27 +117,27 @@ class Install extends Process private static function upTo00060607(): void { # Move old filters lists from settings to database - $record = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL "); + $record = App::con()->select('SELECT * FROM ' . App::con()->prefix() . App::blogWorkspace()::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL "); while ($record->fetch()) { if (preg_match('#enhancePostContent_(.*?)List#', $record->f('setting_id'), $m)) { $curlist = @unserialize($record->f('setting_value')); if (is_array($curlist)) { foreach ($curlist as $k => $v) { - $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::TABLE_NAME); - dcCore::app()->con->writeLock(dcCore::app()->prefix . My::TABLE_NAME); + $cur = App::con()->openCursor(App::con()->prefix() . My::TABLE_NAME); + App::con()->writeLock(App::con()->prefix() . My::TABLE_NAME); - $cur->setField('epc_id', (int) dcCore::app()->con->select('SELECT MAX(epc_id) FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' ')->f(0) + 1); + $cur->setField('epc_id', (int) App::con()->select('SELECT MAX(epc_id) FROM ' . App::con()->prefix() . My::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); $cur->setField('epc_value', $v); $cur->insert(); - dcCore::app()->con->unlock(); + App::con()->unlock(); } } - dcCore::app()->con->execute('DELETE FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_id='" . $record->f('setting_id') . "' AND setting_ns='enhancePostContent' AND blog_id='" . $record->f('blog_id') . "' "); + App::con()->execute('DELETE FROM ' . App::con()->prefix() . App::blogWorkspace()::NS_TABLE_NAME . " WHERE setting_id='" . $record->f('setting_id') . "' AND setting_ns='enhancePostContent' AND blog_id='" . $record->f('blog_id') . "' "); } } } @@ -155,14 +150,14 @@ class Install extends Process private static function upTo20211006(): void { # Move old filter name to filter id - $record = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . My::TABLE_NAME); + $record = App::con()->select('SELECT epc_id, epc_filter FROM ' . App::con()->prefix() . My::TABLE_NAME); while ($record->fetch()) { - $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::TABLE_NAME); + $cur = App::con()->openCursor(App::con()->prefix() . My::TABLE_NAME); $cur->setField('epc_filter', strtolower($record->f('epc_filter'))); $cur->update('WHERE epc_id = ' . $record->f('epc_id') . ' '); - dcCore::app()->blog?->triggerBlog(); + App::blog()->triggerBlog(); } } @@ -185,15 +180,15 @@ class Install extends Process ); // get all enhancePostContent settings - $record = dcCore::app()->con->select( - 'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' . + $record = App::con()->select( + 'SELECT * FROM ' . App::con()->prefix() . App::blogWorkspace()::NS_TABLE_NAME . ' ' . "WHERE setting_ns = 'enhancePostContent' " ); // update settings id, ns, value while ($record->fetch()) { if (preg_match('/^enhancePostContent_(.*?)$/', $record->f('setting_id'), $match)) { - $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME); + $cur = App::blogWorkspace()->openBlogWorkspaceCursor(); $cur->setField('setting_id', $match[1]); $cur->setField('setting_ns', My::id()); diff --git a/src/Manage.php b/src/Manage.php index bc32d5f..c7d5b59 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; -use dcCore; +use Dotclear\App; use Dotclear\Core\Process; use Dotclear\Core\Backend\{ Notices, @@ -63,14 +63,14 @@ class Manage extends Process } // check errors - if (dcCore::app()->error->flag()) { + if (App::error()->flag()) { return true; } // open save to other plugins if (!empty($action)) { # --BEHAVIOR-- enhancePostContentAdminSave - dcCore::app()->callBehavior('enhancePostContentAdminSave'); + App::behavior()->callBehavior('enhancePostContentAdminSave'); } try { @@ -89,7 +89,7 @@ class Manage extends Process My::settings()->put($filter->id(), json_encode($f)); - dcCore::app()->blog->triggerBlog(); + App::blog()->triggerBlog(); Notices::addSuccessNotice( __('Filter successfully updated.') @@ -116,7 +116,7 @@ class Manage extends Process } else { EpcRecord::addRecord($cur); - dcCore::app()->blog->triggerBlog(); + App::blog()->triggerBlog(); Notices::addSuccessNotice( __('Filter successfully updated.') @@ -138,7 +138,7 @@ class Manage extends Process EpcRecord::delRecord((int) $id); } - dcCore::app()->blog->triggerBlog(); + App::blog()->triggerBlog(); Notices::addSuccessNotice( __('Filter successfully updated.') @@ -154,7 +154,7 @@ class Manage extends Process } } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } return true; @@ -191,7 +191,7 @@ class Manage extends Process $counter = EpcRecord::getRecords($params, true); $pager = new BackendList($list, (int) $counter->f(0)); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } $header = $sorts->js(My::manageUrl(['part' => $filter->id()], '&') . '#record'); @@ -205,7 +205,7 @@ class Manage extends Process $header . # --BEHAVIOR-- enhancePostContentAdminHeader - dcCore::app()->callBehavior('enhancePostContentAdminHeader') + App::behavior()->callBehavior('enhancePostContentAdminHeader') ); echo @@ -220,7 +220,7 @@ class Manage extends Process echo (new Form('filters_menu')) ->method('get') - ->action(dcCore::app()->admin->getPageURL()) + ->action(My::manageUrl()) ->fields([ (new Para()) ->class('anchor-nav') @@ -372,7 +372,7 @@ class Manage extends Process $pager->display( $sorts, My::manageUrl(array_merge($sorts->values(true), ['page' => '%s']), '#record'), - '
' . + '' . '%s' . '
' . @@ -401,7 +401,7 @@ class Manage extends Process ->items([ (new Form('form-create')) ->method('post') - ->action(dcCore::app()->admin->getPageURL() . '#record') + ->action(App::backend()->getPageURL() . '#record') ->fields([ (new Para()) ->items([ @@ -436,7 +436,7 @@ class Manage extends Process } # --BEHAVIOR-- enhancePostContentAdminPage - dcCore::app()->callBehavior('enhancePostContentAdminPage'); + App::behavior()->callBehavior('enhancePostContentAdminPage'); Page::helpBlock('enhancePostContent'); Page::closeModule(); diff --git a/src/My.php b/src/My.php index 53096fb..8264d27 100644 --- a/src/My.php +++ b/src/My.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; -use dcCore; +use Dotclear\App; use Dotclear\Module\MyPlugin; /** @@ -42,8 +42,8 @@ class My extends MyPlugin public static function checkCustomContext(int $context): ?bool { 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); + App::auth()->check(App::auth()->makePermissions([ + App::auth()::PERMISSION_CONTENT_ADMIN, + ]), App::blog()->id()); } } diff --git a/src/Prepend.php b/src/Prepend.php index a1d7036..81ec363 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; -use dcCore; +use Dotclear\App; use Dotclear\Core\Process; use Dotclear\Helper\Html\Html; @@ -32,14 +32,14 @@ class Prepend extends Process } // register epc filters - dcCore::app()->addBehavior('enhancePostContentFilters', function (EpcFilters $stack): void { + app::behavior()->addBehavior('enhancePostContentFilters', function (EpcFilters $stack): void { foreach (My::DEFAULT_FILTERS as $class) { $stack->add(new $class()); } }); // register epc filters frontend css - dcCore::app()->url->register( + App::url()->register( 'epccss', 'epc.css', '^epc\.css', diff --git a/src/Uninstall.php b/src/Uninstall.php index 1e2983f..f1b6223 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -14,7 +14,6 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; -use dcCore; use Dotclear\Core\Process; use Dotclear\Plugin\Uninstaller\Uninstaller; @@ -27,7 +26,7 @@ class Uninstall extends Process public static function process(): bool { - if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) { + if (!self::status()) { return false; } diff --git a/src/Widgets.php b/src/Widgets.php index 2e8f348..2b82e1b 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\enhancePostContent; use ArrayObject; -use dcCore; +use Dotclear\App; use Dotclear\Helper\Html\Html; use Dotclear\Plugin\widgets\WidgetsStack; use Dotclear\Plugin\widgets\WidgetsElement; @@ -94,7 +94,7 @@ class Widgets # Page if (!My::settings()->get('active') - || !in_array(dcCore::app()->ctx?->__get('current_tpl'), ['post.html', 'page.html']) + || !in_array(App::frontend()->ctx->__get('current_tpl'), ['post.html', 'page.html']) ) { return ''; }