From 08d5ac715e5ce59eaec7c3c8e29da56dd2a57850 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Wed, 15 Sep 2021 22:00:17 +0200 Subject: [PATCH] Fix right, only super admin can change min length of comment to filter --- _define.php | 4 +-- _install.php | 8 +++-- inc/class.filter.duplicate.php | 63 +++++++++++++++++++++------------- locales/fr/main.lang.php | 16 +++++---- locales/fr/main.po | 20 ++++++----- 5 files changed, 69 insertions(+), 42 deletions(-) diff --git a/_define.php b/_define.php index ea470e2..cebd4d3 100644 --- a/_define.php +++ b/_define.php @@ -16,15 +16,15 @@ if (!defined('DC_RC_PATH')) { } $this->registerModule( - "dcFilterDuplicate", + "Duplicate filter", "Antispam for duplicate comments on multiblog", "Jean-Christian Denis, Pierre Van Glabeke", '0.8', [ + 'requires' => [['core', '2.19']], 'permissions' => 'admin', 'priority' => 200, 'type' => 'plugin', - 'dc_min' => '2.19', 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332947#p332947', 'details' => 'http://plugins.dotaddict.org/dc2/details/dcFilterDuplicate', 'repository' => 'https://raw.githubusercontent.com/JcDenis/dcFilterDuplicate/master/dcstore.xml' diff --git a/_install.php b/_install.php index 129f20e..009caf2 100644 --- a/_install.php +++ b/_install.php @@ -16,7 +16,6 @@ if (!defined('DC_CONTEXT_ADMIN')) { } # -- Module specs -- -$dc_min = '2.6'; $mod_id = 'dcFilterDuplicate'; $mod_conf = [[ 'dcfilterduplicate_minlen', @@ -31,12 +30,15 @@ try { if (version_compare( $core->getVersion($mod_id), $core->plugins->moduleInfo($mod_id, 'version'), - '>=')) { + '>=' + )) { return null; } # Check Dotclear version + $dc_min = $this->modules[$mod_id]['requires'][0][1]; if (!method_exists('dcUtils', 'versionsCompare') - || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { + || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false) + ) { throw new Exception(sprintf( '%s requires Dotclear %s', $mod_id, $dc_min )); diff --git a/inc/class.filter.duplicate.php b/inc/class.filter.duplicate.php index f718f5b..a90a04c 100644 --- a/inc/class.filter.duplicate.php +++ b/inc/class.filter.duplicate.php @@ -22,7 +22,7 @@ if (!defined('DC_RC_PATH')) { */ class dcFilterDuplicate extends dcSpamFilter { - public $name = 'Duplicate comment filter'; + public $name = 'Duplicate filter'; public $has_gui = true; protected function setInfo() @@ -36,7 +36,7 @@ class dcFilterDuplicate extends dcSpamFilter if ($type != 'comment') { return null; } - if (strlen($content) < abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen)) { + if (strlen($content) < abs((integer) $this->core->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen'))) { return null; } @@ -84,28 +84,45 @@ class dcFilterDuplicate extends dcSpamFilter public function gui($url) { - if (isset($_POST['dcfilterduplicate_minlen'])) { - $this->core->blog->settings->dcFilterDuplicate->put( - 'dcfilterduplicate_minlen', - abs((integer) $_POST['dcfilterduplicate_minlen']), - 'integer' - ); - dcPage::addSuccessNotice(__('Configuration successfully updated.')); - http::redirect($url); - } + if ($this->core->auth->isSuperAdmin()) { + $this->core->blog->settings->dcFilterDuplicate->drop('dcfilterduplicate_minlen'); + if (isset($_POST['dcfilterduplicate_minlen'])) { + $this->core->blog->settings->dcFilterDuplicate->put( + 'dcfilterduplicate_minlen', + abs((integer) $_POST['dcfilterduplicate_minlen']), + 'integer', + 'Minimum lenght of comment to filter', + true, + true + ); + dcPage::addSuccessNotice(__('Configuration successfully updated.')); + http::redirect($url); + } - return - '
' . - '

' . - '

' . - $this->core->formNonce() . '

' . - '
'; + return + '
' . + '

' . + '

' . + $this->core->formNonce() . '

' . + '
'; + } else { + return + '

' . sprintf( + __('Super administrator set the minimum length of comment content to %d chars.'), + $this->getMinlength() + ) . '

'; + } + } + + private function getMinLength() + { + return abs((integer) $this->core->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen')); } public function triggerOtherBlogs($content, $ip) diff --git a/locales/fr/main.lang.php b/locales/fr/main.lang.php index ef548a7..b460458 100644 --- a/locales/fr/main.lang.php +++ b/locales/fr/main.lang.php @@ -1,8 +1,8 @@