From 7c7711a3677c86166918ee68edf995b9ff0ed006 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 11 Mar 2023 22:50:36 +0100 Subject: [PATCH] release 1.1 --- CHANGELOG.md | 3 ++ README.md | 4 +-- _define.php | 14 ++++----- _install.php | 20 ------------ _prepend.php | 22 -------------- dcstore.xml | 6 ++-- locales/fr/main.po | 4 +-- {inc => src}/Core.php | 44 +++++++++++++-------------- {inc => src}/Install.php | 18 +++++------ src/My.php | 39 ++++++++++++++++++++++++ {inc => src}/Prepend.php | 34 +++++---------------- {inc => src}/ReservedWhiteList.php | 0 {inc => src}/UnmoderatedWhiteList.php | 4 +-- 13 files changed, 94 insertions(+), 118 deletions(-) delete mode 100644 _install.php delete mode 100644 _prepend.php rename {inc => src}/Core.php (76%) rename {inc => src}/Install.php (84%) create mode 100644 src/My.php rename {inc => src}/Prepend.php (64%) rename {inc => src}/ReservedWhiteList.php (100%) rename {inc => src}/UnmoderatedWhiteList.php (96%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 416e8c0..9200047 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +1.1 - 2023.03.11 +- code review for Dotclear 2.25 + 1.0 - 2023.01.08 - use abstract plugin id - use anonymous functions diff --git a/README.md b/README.md index 410e4d2..60e1dde 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/whiteListCom)](https://github.com/JcDenis/whiteListCom/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/whiteListCom)](https://github.com/JcDenis/whiteListCom/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/whiteListCom)](https://github.com/JcDenis/whiteListCom/issues) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.25-blue.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/whiteListCom) [![License](https://img.shields.io/github/license/JcDenis/whiteListCom)](https://github.com/JcDenis/whiteListCom/blob/master/LICENSE) @@ -20,7 +20,7 @@ and a list of reserved names (pair of nickname / email ). _whiteListCom_ requires: * permissions to manage antispam - * Dotclear 2.24 + * Dotclear 2.25 ## USAGE diff --git a/_define.php b/_define.php index b3af75d..a068599 100644 --- a/_define.php +++ b/_define.php @@ -18,17 +18,17 @@ $this->registerModule( 'Whitelist comments', 'Whitelists for comments moderation', 'Jean-Christian Denis and Contributors', - '1.0', + '1.1', [ - 'requires' => [['core', '2.24']], + 'requires' => [['core', '2.25']], 'permissions' => dcCore::app()->auth->makePermissions([ dcAuth::PERMISSION_USAGE, dcAuth::PERMISSION_CONTENT_ADMIN, ]), - 'priority' => 200, - 'type' => 'plugin', - 'support' => 'https://github.com/JcDenis/' . basename(__DIR__), - 'details' => 'https://plugins.dotaddict.org/dc2/details/' . basename(__DIR__), - 'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml', + 'priority' => 200, + 'type' => 'plugin', + 'support' => 'https://github.com/JcDenis/' . basename(__DIR__), + 'details' => 'https://plugins.dotaddict.org/dc2/details/' . basename(__DIR__), + 'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml', ] ); diff --git a/_install.php b/_install.php deleted file mode 100644 index 24d3123..0000000 --- a/_install.php +++ /dev/null @@ -1,20 +0,0 @@ - Whitelist comments - 1.0 + 1.1 Jean-Christian Denis and Contributors Whitelists for comments moderation - https://github.com/JcDenis/whiteListCom/releases/download/v1.0/plugin-whiteListCom.zip - 2.24 + https://github.com/JcDenis/whiteListCom/releases/download/v1.1/plugin-whiteListCom.zip + 2.25 https://plugins.dotaddict.org/dc2/details/whiteListCom https://github.com/JcDenis/whiteListCom diff --git a/locales/fr/main.po b/locales/fr/main.po index 1e4cb50..290f9ab 100644 --- a/locales/fr/main.po +++ b/locales/fr/main.po @@ -1,9 +1,9 @@ msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n" -"Project-Id-Version: whiteListCom 1.0\n" +"Project-Id-Version: whiteListCom 1.1\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2023-01-07T23:39:35+00:00\n" +"PO-Revision-Date: 2023-03-11T21:46:05+00:00\n" "Last-Translator: Jean-Christian Denis\n" "Language-Team: \n" "MIME-Version: 1.0\n" diff --git a/inc/Core.php b/src/Core.php similarity index 76% rename from inc/Core.php rename to src/Core.php index 6010cd6..154c06f 100644 --- a/inc/Core.php +++ b/src/Core.php @@ -37,14 +37,12 @@ class Core { $this->con = dcCore::app()->con; $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); - $this->settings = dcCore::app()->blog->settings->get(basename(dirname(__DIR__))); - $unmoderated = $this->settings->get('unmoderated'); - $this->unmoderated = self::decode($unmoderated); - $reserved = $this->settings->get('reserved'); - $this->reserved = self::decode($reserved); + $this->settings = dcCore::app()->blog->settings->get(My::id()); + $this->unmoderated = self::decode($this->settings->get('unmoderated')); + $this->reserved = self::decode($this->settings->get('reserved')); } - public function commit() + public function commit(): void { $this->settings->put( 'unmoderated', @@ -69,7 +67,7 @@ class Core # true if it is a reserved name with wrong email # false if it is not a reserved name # null if it is a reserved name with right email - public function isReserved($author, $email) + public function isReserved($author, $email): ?bool { if (!isset($this->reserved[$author])) { return false; @@ -81,7 +79,7 @@ class Core } # You must do a commit to save this change - public function addReserved($author, $email) + public function addReserved($author, $email): bool { $this->reserved[$author] = $email; @@ -89,20 +87,20 @@ class Core } # You must do a commit to save this change - public function emptyReserved() + public function emptyReserved(): void { $this->reserved = []; } # Return # true if it is known as an unmoderated email else false - public function isUnmoderated($email) + public function isUnmoderated($email): bool { return in_array($email, $this->unmoderated); } # You must do a commit to save this change - public function addUnmoderated($email) + public function addUnmoderated($email): ?bool { if (!in_array($email, $this->unmoderated)) { $this->unmoderated[] = $email; @@ -114,32 +112,32 @@ class Core } # You must do a commit to save this change - public function emptyUnmoderated() + public function emptyUnmoderated(): void { $this->unmoderated = []; } - public function getPostsUsers() + public function getPostsUsers(): array { $users = []; $rs = dcCore::app()->blog->getPostsUsers(); while ($rs->fetch()) { $name = dcUtils::getUserCN( - $rs->__get('user_id'), - $rs->__get('user_name'), - $rs->__get('user_firstname'), - $rs->__get('user_displayname') + $rs->f('user_id'), + $rs->f('user_name'), + $rs->f('user_firstname'), + $rs->f('user_displayname') ); $users[] = [ 'name' => $name, - 'email' => $rs->__get('user_email'), + 'email' => $rs->f('user_email'), ]; } return $users; } - public function getCommentsUsers() + public function getCommentsUsers(): array { $users = []; $rs = $this->con->select( @@ -151,22 +149,22 @@ class Core ); while ($rs->fetch()) { $users[] = [ - 'name' => $rs->__get('comment_author'), - 'email' => $rs->__get('comment_email'), + 'name' => $rs->f('comment_author'), + 'email' => $rs->f('comment_email'), ]; } return $users; } - public static function encode($x) + public static function encode($x): string { $y = is_array($x) ? $x : []; return json_encode($y); } - public static function decode($x) + public static function decode($x): array { $y = json_decode($x, true); diff --git a/inc/Install.php b/src/Install.php similarity index 84% rename from inc/Install.php rename to src/Install.php index d7aedf2..58aa550 100644 --- a/inc/Install.php +++ b/src/Install.php @@ -17,11 +17,12 @@ namespace Dotclear\Plugin\whiteListCom; /* dotclear ns */ use dcCore; use dcNamespace; +use dcNsProcess; /* php ns */ use Exception; -class Install +class Install extends dcNsProcess { // Module specs private static $mod_conf = [ @@ -39,19 +40,14 @@ class Install ], ]; - // Nothing to change below - private static $pid = ''; - protected static $init = false; - public static function init(): bool { - self::$pid = basename(dirname(__DIR__)); - self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(self::$pid, dcCore::app()->plugins->moduleInfo(self::$pid, 'version')); + self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); return self::$init; } - public static function process(): ?bool + public static function process(): bool { if (!self::$init) { return false; @@ -63,7 +59,7 @@ class Install // Set module settings foreach (self::$mod_conf as $v) { - dcCore::app()->blog->settings->__get(self::$pid)->put( + dcCore::app()->blog->settings->get(My::id())->put( $v[0], $v[1], $v[2], @@ -83,7 +79,7 @@ class Install public static function growUp(): void { - $current = dcCore::app()->getVersion(self::$pid); + $current = dcCore::app()->getVersion(My::id()); // Update settings id, ns if ($current && version_compare($current, '1.0', '<')) { @@ -97,7 +93,7 @@ class Install $value = @unserialize(@base64_decode($record->setting_value)); $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME); $cur->setting_id = $match[1]; - $cur->setting_ns = self::$pid; + $cur->setting_ns = My::id(); $cur->setting_value = is_array($value) ? json_encode($value) : '[]'; $cur->update( "WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'whiteListCom' " . diff --git a/src/My.php b/src/My.php new file mode 100644 index 0000000..f47fc9e --- /dev/null +++ b/src/My.php @@ -0,0 +1,39 @@ +plugins->moduleInfo(self::id(), 'name')); + } +} diff --git a/inc/Prepend.php b/src/Prepend.php similarity index 64% rename from inc/Prepend.php rename to src/Prepend.php index 4ec2385..a40703a 100644 --- a/inc/Prepend.php +++ b/src/Prepend.php @@ -14,50 +14,32 @@ declare(strict_types=1); namespace Dotclear\Plugin\whiteListCom; -/* dotclear ns */ use dcBlog; use dcCore; +use dcNsProcess; -/* clearbricks ns */ -use Clearbricks; - -class Prepend +class Prepend extends dcNsProcess { - private const LIBS = [ - 'Core', - 'UnmoderatedWhiteList', - 'ReservedWhiteList', - 'Install', - 'Prepend', - ]; - protected static $init = false; - public static function init(): bool { - self::$init = defined('DC_RC_PATH'); + self::$init = true; return self::$init; } - public static function process(): ?bool + public static function process(): bool { if (!self::$init) { return false; } - foreach (self::LIBS as $lib) { - Clearbricks::lib()->autoload([ - __NAMESPACE__ . '\\' . $lib => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php', - ]); - } + dcCore::app()->spamfilters[] = UnmoderatedWhiteList::class; + dcCore::app()->spamfilters[] = ReservedWhiteList::class; - dcCore::app()->spamfilters[] = __NAMESPACE__ . '\\' . 'UnmoderatedWhiteList'; - dcCore::app()->spamfilters[] = __NAMESPACE__ . '\\' . 'ReservedWhiteList'; - - dcCore::app()->addBehavior('publicAfterCommentCreate', function ($cur, $id) { + dcCore::app()->addBehavior('publicAfterCommentCreate', function ($cur, $id): void { if (dcCore::app()->blog === null || dcCore::app()->blog->settings->get('system')->get('comments_pub')) { - return null; + return; } if ($cur->__get('comment_spam_filter') == 'UnmoderatedWhiteList' diff --git a/inc/ReservedWhiteList.php b/src/ReservedWhiteList.php similarity index 100% rename from inc/ReservedWhiteList.php rename to src/ReservedWhiteList.php diff --git a/inc/UnmoderatedWhiteList.php b/src/UnmoderatedWhiteList.php similarity index 96% rename from inc/UnmoderatedWhiteList.php rename to src/UnmoderatedWhiteList.php index 047b007..bfa30be 100644 --- a/inc/UnmoderatedWhiteList.php +++ b/src/UnmoderatedWhiteList.php @@ -49,7 +49,7 @@ class UnmoderatedWhiteList extends dcSpamFilter { if ($type != 'comment' || dcCore::app()->blog === null - || dcCore::app()->blog->settings->system->comments_pub) { + || dcCore::app()->blog->settings->get('system')->get('comments_pub')) { return null; } @@ -90,7 +90,7 @@ class UnmoderatedWhiteList extends dcSpamFilter $res = ''; - if (dcCore::app()->blog->settings->system->comments_pub) { + if (dcCore::app()->blog->settings->get('system')->get('comments_pub')) { $res .= '

' . __('This filter is used only if comments are moderates') . '

';