From abb7b14ccba5a7a09211830cee0d80bbd3060285 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 15 Oct 2023 22:42:41 +0200 Subject: [PATCH] upgrade to Dotclear 2.28 --- CHANGELOG.md | 6 ++++ README.md | 35 +++++++++++---------- _define.php | 36 +++++++++++----------- dcstore.xml | 6 ++-- src/FilterDuplicate.php | 68 ++++++++++++++++++----------------------- src/Install.php | 23 ++++++-------- src/My.php | 26 ++++++++-------- src/Prepend.php | 26 ++++++++-------- src/Uninstall.php | 22 ++++++------- 9 files changed, 117 insertions(+), 131 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 743f5f1..79f9b03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +dcFilterDuplicate 1.4 - 2023.10.15 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1 +* Upgrade to Dotclear 2.28 + dcFilterDuplicate 1.3 - 2023.08.06 =========================================================== * Require Dotclear 2.27 diff --git a/README.md b/README.md index a26c06c..4187241 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,22 @@ # README -[![Release](https://img.shields.io/badge/release-1.3-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/dcFilterDuplicate/releases) -[![Date](https://img.shields.io/badge/date-2023.08.06-c44d58.svg)](https://git.dotclear.watch/JcDenis/dcFilterDuplicate/releases) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) +[![Release](https://img.shields.io/badge/release-1.4-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/dcFilterDuplicate/releases) +![Date](https://img.shields.io/badge/date-2023.10.15-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/dcFilterDuplicate) -[![License](https://img.shields.io/github/license/JcDenis/dcFilterDuplicate)](https://git.dotclear.watch/JcDenis/dcFilterDuplicate/blob/master/LICENSE) +[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/dcFilterDuplicate/src/branch/master/LICENSE) -## WHAT IS DCFILTERDUPLICATE ? +## ABOUT -dcFilterDuplicate "Dupicate comments filter" is a plugin for the -open-source web publishing software called Dotclear. +_dcFilterDuplicate_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). -Filter as spam same (duplicate) comments from multiple blogs of a Dotclear's install. +> Filter as spam same (duplicate) comments from multiple blogs of a Dotclear's install. ## REQUIREMENTS - dcFilterDuplicate requires: - - * permissions to manage antispam - * Dotclear 2.27 +* Dotclear 2.28 +* PHP 8.1 +* Dotclear permissions to manage antispam ## USAGE @@ -29,13 +27,14 @@ Enable and configure "Dupicate comments filter" from antispam manager. ## MORE - * License : GNU GPL v2 - * Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/dcFilterDuplicate) or [GitHub Page](https://github.com/JcDenis/dcFilterDuplicate) - * Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/dcFilterDuplicate/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/dcFilterDuplicate) +* [License](https://git.dotclear.watch/JcDenis/dcFilterDuplicate/src/branch/master/LICENSE) +* [Packages & details](https://git.dotclear.watch/JcDenis/dcFilterDuplicate/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/dcFilterDuplicate)) +* [Sources & contributions](https://git.dotclear.watch/JcDenis/dcFilterDuplicate) (or on [GitHub](https://github.com/JcDenis/dcFilterDuplicate)) +* [Issues & security](https://git.dotclear.watch/JcDenis/dcFilterDuplicate/issues) (or on [GitHub](https://github.com/JcDenis/dcFilterDuplicate/issues)) ## CONTRIBUTORS - * Jean-Chirstian Denis - * Pierre Van Glabeke +* Jean-Chirstian Denis (author) +* Pierre Van Glabeke -You are welcome to contribute to this code. \ No newline at end of file +You are welcome to contribute to this code. diff --git a/_define.php b/_define.php index ce59fc8..93ffed5 100644 --- a/_define.php +++ b/_define.php @@ -1,33 +1,31 @@ registerModule( 'Duplicate filter', 'Antispam for duplicate comments on multiblog', 'Jean-Christian Denis, Pierre Van Glabeke', - '1.3', + '1.4', [ - 'requires' => [['core', '2.27']], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_ADMIN, - ]), - 'priority' => 200, - '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', + 'requires' => [['core', '2.28']], + 'permissions' => 'My', + 'priority' => 200, + '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/dcstore.xml b/dcstore.xml index f9e5e07..d8e150f 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Duplicate filter - 1.3 + 1.4 Jean-Christian Denis, Pierre Van Glabeke Antispam for duplicate comments on multiblog - https://git.dotclear.watch/JcDenis/dcFilterDuplicate/releases/download/v1.3/plugin-dcFilterDuplicate.zip - 2.27 + https://git.dotclear.watch/JcDenis/dcFilterDuplicate/releases/download/v1.4/plugin-dcFilterDuplicate.zip + 2.28 https://git.dotclear.watch/JcDenis/dcFilterDuplicate/src/branch/master/README.md https://git.dotclear.watch/JcDenis/dcFilterDuplicate/issues diff --git a/src/FilterDuplicate.php b/src/FilterDuplicate.php index a24df89..c4a53ea 100644 --- a/src/FilterDuplicate.php +++ b/src/FilterDuplicate.php @@ -1,21 +1,10 @@ description = __('Same comments on others blogs of a multiblog'); } - public function isSpam(string $type, ?string $author, ?string $email, ?string $site, ?string $ip, ?string $content, ?int $post_id, string &$status): ?bool + public function isSpam(string $type, ?string $author, ?string $email, ?string $site, ?string $ip, ?string $content, ?int $post_id, string &$status) { if ($type != 'comment' || is_null($content) || is_null($ip)) { return null; @@ -74,21 +65,20 @@ class FilterDuplicate extends SpamFilter public function isDuplicate(string $content, string $ip): bool { - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return false; } $sql = new SelectStatement(); - $rs = $sql->from($sql->as(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME, 'C')) + $rs = $sql->from($sql->as(App::con()->prefix() . App::blog()::COMMENT_TABLE_NAME, 'C')) ->join( (new JoinStatement()) ->left() - ->from($sql->as(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME, 'P')) + ->from($sql->as(App::con()->prefix() . App::blog()::POST_TABLE_NAME, 'P')) ->on('C.post_id = P.post_id') ->statement() ) - ->where('P.blog_id != ' . $sql->quote(dcCore::app()->blog->id)) + ->where('P.blog_id != ' . $sql->quote(App::blog()->id())) ->and('C.comment_content = ' . $sql->quote($content)) ->and('C.comment_ip=' . $sql->quote($ip)) ->select(); @@ -98,28 +88,27 @@ class FilterDuplicate extends SpamFilter public function markDuplicate(string $content, string $ip): void { - $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME); - dcCore::app()->con->writeLock(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME); + $cur = App::blog()->openCommentCursor(); + App::con()->writeLock(App::con()->prefix() . App::blog()::COMMENT_TABLE_NAME); $cur->setField('comment_status', -2); $cur->setField('comment_spam_status', 'Duplicate on other blog'); $cur->setField('comment_spam_filter', My::id()); $cur->update( - "WHERE comment_content='" . dcCore::app()->con->escapeStr($content) . "' " . + "WHERE comment_content='" . App::con()->escapeStr($content) . "' " . "AND comment_ip='" . $ip . "' " ); - dcCore::app()->con->unlock(); + App::con()->unlock(); $this->triggerOtherBlogs($content, $ip); } public function gui(string $url): string { - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return ''; } - if (dcCore::app()->auth->isSuperAdmin()) { + if (App::auth()->isSuperAdmin()) { My::settings()->drop(My::SETTING_PREFIX . 'minlen'); if (isset($_POST[My::SETTING_PREFIX . 'minlen'])) { My::settings()->put( @@ -142,7 +131,7 @@ class FilterDuplicate extends SpamFilter ]), (new Para())->items([ (new Submit('save'))->value(__('Save')), - dcCore::app()->formNonce(false), + App::nonce()->formNonce(), ]), ])->render(); } @@ -156,8 +145,7 @@ class FilterDuplicate extends SpamFilter private function getMinLength(): int { - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return 0; } @@ -167,12 +155,12 @@ class FilterDuplicate extends SpamFilter public function triggerOtherBlogs(string $content, string $ip): void { $sql = new SelectStatement(); - $rs = $sql->from($sql->as(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME, 'C')) + $rs = $sql->from($sql->as(App::con()->prefix() . App::blog()::COMMENT_TABLE_NAME, 'C')) ->column('P.blog_id') ->join( (new JoinStatement()) ->left() - ->from($sql->as(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME, 'P')) + ->from($sql->as(App::con()->prefix() . App::blog()::POST_TABLE_NAME, 'P')) ->on('C.post_id = P.post_id') ->statement() ) @@ -184,10 +172,12 @@ class FilterDuplicate extends SpamFilter return; } + $old = App::blog()->id(); + while ($rs->fetch()) { - $b = new dcBlog($rs->f('blog_id')); - $b->triggerBlog(); - unset($b); + App::blog()->loadFromBlog($rs->f('blog_id'))->triggerBlog(); } + + App::blog()->loadFromBlog($old); } } diff --git a/src/Install.php b/src/Install.php index 02393f0..d964231 100644 --- a/src/Install.php +++ b/src/Install.php @@ -1,23 +1,20 @@ error->add($e->getMessage()); + App::error()->add($e->getMessage()); return false; } diff --git a/src/My.php b/src/My.php index ffa6066..4825f89 100644 --- a/src/My.php +++ b/src/My.php @@ -1,15 +1,5 @@ spamfilters[] = FilterDuplicate::class; + App::behavior()->addBehavior('AntispamInitFilters', function (ArrayObject $spamfilters): void { + $spamfilters[] = FilterDuplicate::class; + }); return true; } diff --git a/src/Uninstall.php b/src/Uninstall.php index 6224185..fab19cf 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -1,23 +1,19 @@ plugins->moduleExists('Uninstaller')) { + if (!self::status()) { return false; }