code review for Dotclear 2.25

This commit is contained in:
Jean-Christian Paul Denis 2023-03-11 23:11:29 +01:00
parent 38d84e78ae
commit 5d92ae7bde
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
10 changed files with 252 additions and 141 deletions

View File

@ -1,3 +1,7 @@
1.0 - 2023.03.11
- update to dotclear 2.25
- use namespace
0.9.1 - 2022.12.20
- fix permission
- fix install

View File

@ -19,7 +19,7 @@ Filter as spam same (duplicate) comments from multiple blogs of a Dotclear's ins
dcFilterDuplicate requires:
* permissions to manage antispam
* Dotclear 2.24
* Dotclear 2.25
## USAGE

View File

@ -24,10 +24,10 @@ $this->registerModule(
'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_ADMIN,
]),
'priority' => 200,
'type' => 'plugin',
'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332947#p332947',
'details' => 'http://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
'priority' => 200,
'type' => 'plugin',
'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332947#p332947',
'details' => 'http://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
]
);

17
locales/fr/main.lang.php Normal file
View File

@ -0,0 +1,17 @@
<?php
/**
* @package Dotclear
*
* @copyright Olivier Meunier & Association Dotclear
* @copyright GPL-2.0-only
*/
#
# DOT NOT MODIFY THIS FILE !
#
l10n::$locales['Duplicate'] = 'Doublons';
l10n::$locales['Same comments on others blogs of a multiblog'] = 'Commentaires identiques sur les autres blogs du multiblog';
l10n::$locales['Minimum content length before check for duplicate:'] = 'Longueur minimum du contenu pour faire une vérification :';
l10n::$locales['Super administrator set the minimum length of comment content to %d chars.'] = 'Un super administrateur a régler la longueur minimum d\'un commentaire à surveiller à %d caractères.';
l10n::$locales['Antispam for duplicate comments on multiblog'] = 'Antispam contre les doublons de commentaires sur un multiblog';
l10n::$locales['Duplicate filter'] = 'Filtre de doublons';

View File

@ -1,33 +1,24 @@
# Language: Français
# Module: dcFilterDuplicate - 0.8
# Date: 2021-09-15 19:57:37
# Translated with translater 2021.09.02.1
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: dcFilterDuplicate 0.8\n"
"Project-Id-Version: dcFilterDuplicate 0.9.1\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2021-09-15T19:57:37+00:00\n"
"PO-Revision-Date: 2023-03-11T22:08:21+00:00\n"
"Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: inc/class.filter.duplicate.php:30
msgid "Duplicate"
msgstr "Doublons"
#: inc/class.filter.duplicate.php:31
msgid "Same comments on others blogs of a multiblog"
msgstr "Commentaires identiques sur les autres blogs du multiblog"
#: inc/class.filter.duplicate.php:104
msgid "Minimum content length before check for duplicate:"
msgstr "Longueur minimum du contenu pour faire une vérification :"
#: inc/class.filter.duplicate.php:117
msgid "Super administrator set the minimum length of comment content to %d chars."
msgstr "Un super administrateur a régler la longueur minimum d'un commentaire à surveiller à %d caractères."

View File

@ -10,27 +10,36 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
declare(strict_types=1);
namespace Dotclear\Plugin\dcFilterDuplicate;
use dcBlog;
use dcCore;
use dcPage;
use dcSpamFilter;
use Exception;
use form;
use html;
use http;
/**
* @ingroup DC_PLUGIN_DCFILTERDUPLICATE
* @brief Filter duplicate comments on multiblogs.
* @since 2.6
*/
class dcFilterDuplicate extends dcSpamFilter
class FilterDuplicate extends dcSpamFilter
{
public $name = 'Duplicate filter';
public $has_gui = true;
protected function setInfo()
protected function setInfo(): void
{
$this->name = __('Duplicate');
$this->description = __('Same comments on others blogs of a multiblog');
}
public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status): ?bool
{
if ($type != 'comment') {
return null;
@ -53,7 +62,7 @@ class dcFilterDuplicate extends dcSpamFilter
}
}
public function isDuplicate($content, $ip)
public function isDuplicate($content, $ip): bool
{
$rs = dcCore::app()->con->select(
'SELECT C.comment_id ' .
@ -67,7 +76,7 @@ class dcFilterDuplicate extends dcSpamFilter
return !$rs->isEmpty();
}
public function markDuplicate($content, $ip)
public function markDuplicate($content, $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);
@ -86,9 +95,9 @@ class dcFilterDuplicate extends dcSpamFilter
public function gui(string $url): string
{
if (dcCore::app()->auth->isSuperAdmin()) {
dcCore::app()->blog->settings->dcFilterDuplicate->drop('dcfilterduplicate_minlen');
dcCore::app()->blog->settings->get(My::id())->drop('dcfilterduplicate_minlen');
if (isset($_POST['dcfilterduplicate_minlen'])) {
dcCore::app()->blog->settings->dcFilterDuplicate->put(
dcCore::app()->blog->settings->get(My::id())->put(
'dcfilterduplicate_minlen',
abs((int) $_POST['dcfilterduplicate_minlen']),
'integer',
@ -121,12 +130,12 @@ class dcFilterDuplicate extends dcSpamFilter
) . '</p>';
}
private function getMinLength()
private function getMinLength(): int
{
return abs((int) dcCore::app()->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen'));
return abs((int) dcCore::app()->blog->settings->get('dcFilterDuplicate')->getGlobal('dcfilterduplicate_minlen'));
}
public function triggerOtherBlogs($content, $ip)
public function triggerOtherBlogs($content, $ip): void
{
$rs = dcCore::app()->con->select(
'SELECT P.blog_id ' .
@ -137,7 +146,7 @@ class dcFilterDuplicate extends dcSpamFilter
);
while ($rs->fetch()) {
$b = new dcBlog($rs->blog_id);
$b = new dcBlog($rs->f('blog_id'));
$b->triggerBlog();
unset($b);
}

View File

@ -10,43 +10,55 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
declare(strict_types=1);
# -- Module specs --
$mod_conf = [[
'dcfilterduplicate_minlen',
'Minimum lenght of comment to filter',
30,
'integer',
]];
namespace Dotclear\Plugin\dcFilterDuplicate;
# -- Nothing to change below --
try {
# Check module version
if (!dcCore::app()->newVersion(
basename(__DIR__),
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
)) {
return null;
}
# Set module settings
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
foreach ($mod_conf as $v) {
dcCore::app()->blog->settings->__get(basename(__DIR__))->put(
$v[0],
$v[2],
$v[3],
$v[1],
false,
true
);
use dcCore;
use dcNsProcess;
use Exception;
class Install extends dcNsProcess
{
# -- Module specs --
private static $mod_conf = [[
'dcfilterduplicate_minlen',
'Minimum lenght of comment to filter',
30,
'integer',
]];
public static function init(): bool
{
self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return self::$init;
}
return true;
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
public static function process(): bool
{
if (!self::$init) {
return false;
}
return false;
try {
# Set module settings
foreach (self::$mod_conf as $v) {
dcCore::app()->blog->settings->get(My::id())->put(
$v[0],
$v[2],
$v[3],
$v[1],
false,
true
);
}
return true;
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
return false;
}
}
}

39
src/My.php Normal file
View File

@ -0,0 +1,39 @@
<?php
/**
* @brief dcFilterDuplicate, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\dcFilterDuplicate;
use dcCore;
/**
* Plugin definitions
*/
class My
{
/**
* This module id
*/
public static function id(): string
{
return basename(dirname(__DIR__));
}
/**
* This module name
*/
public static function name(): string
{
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
}
}

View File

@ -10,10 +10,30 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
declare(strict_types=1);
namespace Dotclear\Plugin\dcFilterDuplicate;
use dcCore;
use dcNsProcess;
class Prepend extends dcNsProcess
{
public static function init(): bool
{
self::$init = true;
return self::$init;
}
public static function process(): bool
{
if (!self::$init) {
return false;
}
dcCore::app()->spamfilters[] = FilterDuplicate::class;
return true;
}
}
Clearbricks::lib()->autoload(['dcFilterDuplicate' => __DIR__ . '/inc/class.filter.duplicate.php']);
dcCore::app()->spamfilters[] = 'dcFilterDuplicate';

View File

@ -10,74 +10,93 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
declare(strict_types=1);
namespace Dotclear\Plugin\dcFilterDuplicate;
class Uninstall
{
protected static $init = false;
public static function init(): bool
{
self::$init = defined('DC_RC_PATH');
return self::$init;
}
public static function process($uninstaller): ?bool
{
if (!self::$init) {
return false;
}
$uninstaller->addUserAction(
/* type */
'settings',
/* action */
'delete_all',
/* ns */
My::id(),
/* desc */
__('delete all settings')
);
$uninstaller->addUserAction(
/* type */
'plugins',
/* action */
'delete',
/* ns */
My::id(),
/* desc */
__('delete plugin files')
);
$uninstaller->addUserAction(
/* type */
'versions',
/* action */
'delete',
/* ns */
My::id(),
/* desc */
__('delete the version number')
);
$uninstaller->addDirectAction(
/* type */
'settings',
/* action */
'delete_all',
/* ns */
My::id(),
/* desc */
sprintf(__('delete all %s settings'), My::id())
);
$uninstaller->addDirectAction(
/* type */
'versions',
/* action */
'delete',
/* ns */
My::id(),
/* desc */
sprintf(__('delete %s version number'), My::id())
);
$uninstaller->addDirectAction(
/* type */
'plugins',
/* action */
'delete',
/* ns */
My::id(),
/* desc */
sprintf(__('delete %s plugin files'), My::id())
);
return true;
}
}
$mod_id = 'dcFilterDuplicate';
$this->addUserAction(
/* type */
'settings',
/* action */
'delete_all',
/* ns */
$mod_id,
/* desc */
__('delete all settings')
);
$this->addUserAction(
/* type */
'plugins',
/* action */
'delete',
/* ns */
$mod_id,
/* desc */
__('delete plugin files')
);
$this->addUserAction(
/* type */
'versions',
/* action */
'delete',
/* ns */
$mod_id,
/* desc */
__('delete the version number')
);
$this->addDirectAction(
/* type */
'settings',
/* action */
'delete_all',
/* ns */
$mod_id,
/* desc */
sprintf(__('delete all %s settings'), $mod_id)
);
$this->addDirectAction(
/* type */
'versions',
/* action */
'delete',
/* ns */
$mod_id,
/* desc */
sprintf(__('delete %s version number'), $mod_id)
);
$this->addDirectAction(
/* type */
'plugins',
/* action */
'delete',
/* ns */
$mod_id,
/* desc */
sprintf(__('delete %s plugin files'), $mod_id)
);