diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a79a62..bdd6004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +whiteListCom 1.4 - 2023.10.11 +=========================================================== +* Require Dotclear 2.27 +* Require PHP 8.1 +* Upgrade to Dotclear 2.28 + whiteListCom 1.3.1 - 2023.08.13 =========================================================== * Require Dotclear 2.27 diff --git a/README.md b/README.md index b0e0304..f9bcb2a 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,22 @@ # README -[![Release](https://img.shields.io/badge/release-1.3.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/whiteListCom/releases) -[![Date](https://img.shields.io/badge/date-2023.08.13-c44d58.svg)](https://git.dotclear.watch/JcDenis/whiteListCom/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/whiteListCom/releases) +![Date](https://img.shields.io/badge/date-2023.10.11-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/whiteListCom) [![License](https://img.shields.io/github/license/JcDenis/whiteListCom)](https://git.dotclear.watch/JcDenis/whiteListCom/blob/master/LICENSE) -## WHAT IS WHITELISTCOM ? +## ABOUT -_whiteListCom_ "White list for comments" is a plugin for the open-source -web publishing software called Dotclear. +_tinyPacker_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). -Set up a list of users which can publish comments without validation -and a list of reserved names (pair of nickname / email ). +> Set up a list of users which can publish comments without validation and a list of reserved names (pair of nickname / email ). ## REQUIREMENTS -_whiteListCom_ requires: - +* Dotclear 2.28 +* PHP 8.1+ * permissions to manage antispam -* Dotclear 2.27 -* PHP 7.4 ## USAGE @@ -33,12 +29,13 @@ Note: User must write a comment before able to be added to the list. ## 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/whiteListCom) or [GitHub Page](https://github.com/JcDenis/whiteListCom) -* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/whiteListCom/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/whiteListCom) +* [License](https://git.dotclear.watch/JcDenis/whiteListCom/src/branch/master/LICENSE) +* [Packages & details](https://git.dotclear.watch/JcDenis/whiteListCom/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/whiteListCom)) +* [Sources & contributions](https://git.dotclear.watch/JcDenis/whiteListCom) (or on [GitHub](https://github.com/JcDenis/whiteListCom)) +* [Issues & security](https://git.dotclear.watch/JcDenis/whiteListCom/issues) (or on [GitHub](https://github.com/JcDenis/whiteListCom/issues)) ## CONTRIBUTORS -* Jean-Christian Denis +* Jean-Christian Denis (author) You are welcome to contribute to this code. diff --git a/_define.php b/_define.php index 0a17894..83a240d 100644 --- a/_define.php +++ b/_define.php @@ -1,37 +1,33 @@ registerModule( 'Whitelist comments', 'Whitelists for comments moderation', 'Jean-Christian Denis and Contributors', - '1.3.1', + '1.4', [ 'requires' => [ - ['core', '2.27'], + ['core', '2.28'], ['antispam', '2.0'], ], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_USAGE, - dcCore::app()->auth::PERMISSION_CONTENT_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', + '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 5260b38..6c21ba2 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Whitelist comments - 1.3.1 + 1.4 Jean-Christian Denis and Contributors Whitelists for comments moderation - https://git.dotclear.watch/JcDenis/whiteListCom/releases/download/v1.3.1/plugin-whiteListCom.zip - 2.27 + https://git.dotclear.watch/JcDenis/whiteListCom/releases/download/v1.4/plugin-whiteListCom.zip + 2.28 https://git.dotclear.watch/JcDenis/whiteListCom/src/branch/master/README.md https://git.dotclear.watch/JcDenis/whiteListCom/issues diff --git a/src/Install.php b/src/Install.php index 0a4e855..ed5e8f9 100644 --- a/src/Install.php +++ b/src/Install.php @@ -1,27 +1,27 @@ > $mod_conf + */ private static array $mod_conf = [ [ 'unmoderated', @@ -66,7 +66,7 @@ class Install extends Process return true; } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); return false; } @@ -74,25 +74,25 @@ class Install extends Process public static function growUp(): void { - $current = dcCore::app()->getVersion(My::id()); + $current = App::version()->getVersion(My::id()); // Update settings id, ns if ($current && version_compare($current, '1.0', '<')) { - $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 = 'whiteListCom' " ); while ($record->fetch()) { if (preg_match('/^whiteListCom(.*?)$/', $record->f('setting_id'), $match)) { $value = @unserialize(@base64_decode($record->f('setting_value'))); - $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()); $cur->setField('setting_value', is_array($value) ? json_encode($value) : '[]'); $cur->update( "WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = 'whiteListCom' " . - 'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escapeStr((string) $record->f('blog_id')) . "' ")) + 'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . App::con()->escapeStr((string) $record->f('blog_id')) . "' ")) ); } } diff --git a/src/My.php b/src/My.php index 3ebb626..15a568b 100644 --- a/src/My.php +++ b/src/My.php @@ -1,15 +1,5 @@ spamfilters[] = UnmoderatedWhiteList::class; - dcCore::app()->spamfilters[] = ReservedWhiteList::class; + App::behavior()->addBehaviors([ + 'AntispamInitFilters' => function (ArrayObject $spamfilters): void { + $spamfilters[] = UnmoderatedWhiteList::class; + $spamfilters[] = ReservedWhiteList::class; + }, + 'publicAfterCommentCreate' => function (Cursor $cur, int $id): void { + if (!App::blog()->isDefined() || App::blog()->settings()->get('system')->get('comments_pub')) { + return; + } - dcCore::app()->addBehavior('publicAfterCommentCreate', function ($cur, $id): void { - if (dcCore::app()->blog === null - || dcCore::app()->blog->settings->get('system')->get('comments_pub')) { - return; - } + if ($cur->__get('comment_spam_filter') == 'UnmoderatedWhiteList' + && $cur->__get('comment_spam_status') == 'unmoderated') { + App::con()->writeLock(App::con()->prefix() . App::blog()::COMMENT_TABLE_NAME); - if ($cur->__get('comment_spam_filter') == 'UnmoderatedWhiteList' - && $cur->__get('comment_spam_status') == 'unmoderated') { - dcCore::app()->con->writeLock(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME); + $cur->__set('comment_status', 1); + $cur->__set('comment_spam_status', 0); + $cur->__set('comment_spam_filter', 0); + $cur->update('WHERE comment_id = ' . $id . ' '); - $cur->__set('comment_status', 1); - $cur->__set('comment_spam_status', 0); - $cur->__set('comment_spam_filter', 0); - $cur->update('WHERE comment_id = ' . $id . ' '); + App::con()->unlock(); - dcCore::app()->con->unlock(); - - dcCore::app()->blog->triggerComment($id); - dcCore::app()->blog->triggerBlog(); - } - }); + App::blog()->triggerComment($id); + App::blog()->triggerBlog(); + } + }, + ]); return true; } diff --git a/src/ReservedWhiteList.php b/src/ReservedWhiteList.php index c5343d9..7575a08 100644 --- a/src/ReservedWhiteList.php +++ b/src/ReservedWhiteList.php @@ -1,20 +1,10 @@ name = __('Reserved names'); $this->description = __('Whitelist of reserved names of users'); @@ -47,7 +36,7 @@ class ReservedWhiteList extends SpamFilter /** * @return void|null|bool */ - public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) + public function isSpam(string $type, ?string $author, ?string $email, ?string $site, ?string $ip, ?string $content, ?int $post_id, string &$status) { if ($type != 'comment') { return null; @@ -72,10 +61,7 @@ class ReservedWhiteList extends SpamFilter } } - /** - * @return string - */ - public function getStatusMessage($status, $comment_id) + public function getStatusMessage(string $status, ?int $comment_id): string { return __('This name is reserved to an other user.'); } @@ -97,7 +83,7 @@ class ReservedWhiteList extends SpamFilter $comments = Utils::getCommentsUsers(); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } $res = '
' . @@ -124,7 +110,7 @@ class ReservedWhiteList extends SpamFilter $res .= '' . '' . '

' . - dcCore::app()->formNonce() . '

' . + App::nonce()->getFormNonce() . '

' . '
'; return $res; diff --git a/src/Uninstall.php b/src/Uninstall.php index f411ecb..5099c62 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -1,23 +1,19 @@ plugins->moduleExists('Uninstaller')) { + if (!self::status()) { return false; } diff --git a/src/UnmoderatedWhiteList.php b/src/UnmoderatedWhiteList.php index 5dfb455..e471297 100644 --- a/src/UnmoderatedWhiteList.php +++ b/src/UnmoderatedWhiteList.php @@ -1,21 +1,11 @@ name = __('Unmoderated authors'); $this->description = __('Whitelist of unmoderated authors'); @@ -46,11 +33,11 @@ class UnmoderatedWhiteList extends SpamFilter /** * @return void|null|bool */ - public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) + public function isSpam(string $type, ?string $author, ?string $email, ?string $site, ?string $ip, ?string $content, ?int $post_id, string &$status) { if ($type != 'comment' - || dcCore::app()->blog === null - || dcCore::app()->blog->settings->get('system')->get('comments_pub')) { + || !App::blog()->isDefined() + || App::blog()->settings()->get('system')->get('comments_pub')) { return null; } @@ -85,12 +72,12 @@ class UnmoderatedWhiteList extends SpamFilter $posts = Utils::getPostsUsers(); $comments = Utils::getCommentsUsers(); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } $res = ''; - if (!is_null(dcCore::app()->blog) && dcCore::app()->blog->settings->get('system')->get('comments_pub')) { + if (App::blog()->isDefined() && App::blog()->settings()->get('system')->get('comments_pub')) { $res .= '

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

'; @@ -141,7 +128,7 @@ class UnmoderatedWhiteList extends SpamFilter '' . '' . '

' . - dcCore::app()->formNonce() . '

' . + App::nonce()->getFormNonce() . '

' . ''; return $res; diff --git a/src/Utils.php b/src/Utils.php index dd4975b..0bb9b26 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -1,41 +1,43 @@ $unmoderated + */ private static array $unmoderated = []; - /** @var array $unmoderated List of reserved name */ + /** + * List of reserved name. + * + * @var array $reserved + */ private static array $reserved = []; /** @@ -185,18 +187,18 @@ class Utils */ public static function getPostsUsers(): array { - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return []; } - $rs = dcCore::app()->blog->getPostsUsers(); + $rs = App::blog()->getPostsUsers(); if ($rs->isEmpty()) { return []; } $users = []; while ($rs->fetch()) { - $name = dcUtils::getUserCN( + $name = App::users()->getUserCN( $rs->f('user_id'), $rs->f('user_name'), $rs->f('user_firstname'), @@ -218,12 +220,12 @@ class Utils */ public static function getCommentsUsers(): array { - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return []; } $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')) ->columns([ 'comment_author', 'comment_email', @@ -231,11 +233,11 @@ class Utils ->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('blog_id = ' . $sql->quote(dcCore::app()->blog->id)) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->and('comment_trackback = 0') ->and("comment_email != ''") ->group('comment_email, comment_author') // Added author to fix postgreSql