From 53df2f9c4a19e88146d437168995c51b00a5642f Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 27 Aug 2021 17:16:25 +0200 Subject: [PATCH] cleanup 2021 --- CHANGELOG | 29 ----- CHANGELOG.md | 32 ++++++ README.md | 11 ++ _define.php | 35 +++--- _install.php | 87 ++++++-------- _prepend.php | 7 +- _uninstall.php | 53 +++++---- dcstore.xml | 13 +++ inc/class.filter.duplicate.php | 200 ++++++++++++++++----------------- locales/fr/main.lang.php | 19 ++++ locales/fr/main.po | 20 ++-- 11 files changed, 262 insertions(+), 244 deletions(-) delete mode 100644 CHANGELOG create mode 100644 CHANGELOG.md create mode 100644 dcstore.xml create mode 100644 locales/fr/main.lang.php diff --git a/CHANGELOG b/CHANGELOG deleted file mode 100644 index 12a34b5..0000000 --- a/CHANGELOG +++ /dev/null @@ -1,29 +0,0 @@ -v0.6 - 22-04-2015 - Pierre Van Glabeke -* Modifs typo -* Ajout message -* Modif url support - -v0.5 - 2013-11-12 -* Clean up code - -v0.4 - 2011-01-20 -* Fixed call to blog object on prepend -* New year copyright - -v0.3.2 - 2010-11-12 -* Fixed install on nightly build - -v0.3.1 - 2010-06-22 -* Fixed me! - -v0.3 - 2010-06-05 -* Switched to DC 2.2 - -v0.2 - 2009-12-13 -* Fixed trigger blogs -* Enabled min length of comment to filter -* Prepared DC 2.2 Break -* Added versioning - -v0.1 - 2009-10-09 -* First lab release \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ec10858 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,32 @@ +v0.7 - 2021.08.27 +- cleanup (PSR2,short array, ...) + +v0.6 - 22-04-2015 - Pierre Van Glabeke +- Modifs typo +- Ajout message +- Modif url support + +v0.5 - 2013-11-12 +- Clean up code + +v0.4 - 2011-01-20 +- Fixed call to blog object on prepend +- New year copyright + +v0.3.2 - 2010-11-12 +- Fixed install on nightly build + +v0.3.1 - 2010-06-22 +- Fixed me! + +v0.3 - 2010-06-05 +- Switched to DC 2.2 + +v0.2 - 2009-12-13 +- Fixed trigger blogs +- Enabled min length of comment to filter +- Prepared DC 2.2 Break +- Added versioning + +v0.1 - 2009-10-09 +- First lab release \ No newline at end of file diff --git a/README.md b/README.md index 4ccd08d..60dacc8 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,14 @@ First install dcFilterDuplicate, manualy from a zip package or from Dotaddict repository. (See Dotclear's documentation to know how do this) Enable and configure "Dupicate comments filter" from antispam manager. + +## MORE + + * License : GNU GPL v2 + * Source & contribution : [GitHub Page](https://github.com/JcDenis/dcFilterDuplicate) + * Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/dcFilterDuplicate) + +## CONTRIBUTORS + + * Jean-Chirstian Denis + * Pierre Van Glabeke \ No newline at end of file diff --git a/_define.php b/_define.php index e913166..76b3781 100644 --- a/_define.php +++ b/_define.php @@ -3,7 +3,7 @@ # # This file is part of dcFilterDuplicate, a plugin for Dotclear 2. # -# Copyright (c) 2009-2015 Jean-Christian Denis and contributors +# Copyright (c) 2009-2021 Jean-Christian Denis and contributors # # Licensed under the GPL version 2.0 license. # A copy of this license is available in LICENSE file or at @@ -12,26 +12,21 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } $this->registerModule( - /* Name */ - "dcFilterDuplicate", - /* Description*/ - "Antispam for duplicate comments on multiblog", - /* Author */ - "Jean-Christian Denis, Pierre Van Glabeke", - /* Version */ - '0.6', - /* Properies */ - array( - 'permissions' => 'admin', - 'priority' => 200, - 'type' => 'plugin', - 'dc_min' => '2.6', - 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332947#p332947', - 'details' => 'http://plugins.dotaddict.org/dc2/details/dcFilterDuplicate' - ) + "dcFilterDuplicate", + "Antispam for duplicate comments on multiblog", + "Jean-Christian Denis, Pierre Van Glabeke", + '0.7', + [ + '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' + ] ); \ No newline at end of file diff --git a/_install.php b/_install.php index 5acc279..0c12c60 100644 --- a/_install.php +++ b/_install.php @@ -3,7 +3,7 @@ # # This file is part of dcFilterDuplicate, a plugin for Dotclear 2. # -# Copyright (c) 2009-2015 Jean-Christian Denis and contributors +# Copyright (c) 2009-2021 Jean-Christian Denis and contributors # # Licensed under the GPL version 2.0 license. # A copy of this license is available in LICENSE file or at @@ -12,63 +12,50 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_CONTEXT_ADMIN')) { - - return null; + return null; } # -- Module specs -- - $dc_min = '2.6'; $mod_id = 'dcFilterDuplicate'; -$mod_conf = array( - array( - 'dcfilterduplicate_minlen', - 'Minimum lenght of comment to filter', - 30, - 'integer' - ) -); +$mod_conf = [[ + 'dcfilterduplicate_minlen', + 'Minimum lenght of comment to filter', + 30, + 'integer' +]]; # -- Nothing to change below -- - try { - - # Check module version - if (version_compare( - $core->getVersion($mod_id), - $core->plugins->moduleInfo($mod_id, 'version'), - '>=' - )) { - - return null; - } - - # Check Dotclear version - if (!method_exists('dcUtils', 'versionsCompare') - || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { - throw new Exception(sprintf( - '%s requires Dotclear %s', $mod_id, $dc_min - )); - } - - # Set module settings - $core->blog->settings->addNamespace($mod_id); - foreach($mod_conf as $v) { - $core->blog->settings->{$mod_id}->put( - $v[0], $v[2], $v[3], $v[1], false, true - ); - } - - # Set module version - $core->setVersion( - $mod_id, - $core->plugins->moduleInfo($mod_id, 'version') - ); - - return true; + # Check module version + if (version_compare( + $core->getVersion($mod_id), + $core->plugins->moduleInfo($mod_id, 'version'), + '>=')) { + return null; + } + # Check Dotclear version + if (!method_exists('dcUtils', 'versionsCompare') + || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { + throw new Exception(sprintf( + '%s requires Dotclear %s', $mod_id, $dc_min + )); + } + # Set module settings + $core->blog->settings->addNamespace($mod_id); + foreach($mod_conf as $v) { + $core->blog->settings->{$mod_id}->put( + $v[0], $v[2], $v[3], $v[1], false, true + ); + } + # Set module version + $core->setVersion( + $mod_id, + $core->plugins->moduleInfo($mod_id, 'version') + ); + return true; } catch (Exception $e) { - $core->error->add($e->getMessage()); - - return false; + $core->error->add($e->getMessage()); + return false; } \ No newline at end of file diff --git a/_prepend.php b/_prepend.php index b4ace8b..3b84757 100644 --- a/_prepend.php +++ b/_prepend.php @@ -3,7 +3,7 @@ # # This file is part of dcFilterDuplicate, a plugin for Dotclear 2. # -# Copyright (c) 2009-2015 Jean-Christian Denis and contributors +# Copyright (c) 2009-2021 Jean-Christian Denis and contributors # # Licensed under the GPL version 2.0 license. # A copy of this license is available in LICENSE file or at @@ -12,11 +12,10 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } $__autoload['dcFilterDuplicate'] = - dirname(__FILE__).'/inc/class.filter.duplicate.php'; + dirname(__FILE__) . '/inc/class.filter.duplicate.php'; $core->spamfilters[] = 'dcFilterDuplicate'; \ No newline at end of file diff --git a/_uninstall.php b/_uninstall.php index db35cc9..1606f6a 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -3,7 +3,7 @@ # # This file is part of dcFilterDuplicate, a plugin for Dotclear 2. # -# Copyright (c) 2009-2015 Jean-Christian Denis and contributors +# Copyright (c) 2009-2021 Jean-Christian Denis and contributors # # Licensed under the GPL version 2.0 license. # A copy of this license is available in LICENSE file or at @@ -12,50 +12,49 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_CONTEXT_ADMIN')) { - - return null; + return null; } $mod_id = 'dcFilterDuplicate'; $this->addUserAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ $mod_id, - /* desc */ __('delete all settings') + /* 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') + /* 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') + /* 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) + /* 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) + /* 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) + /* type */ 'plugins', + /* action */ 'delete', + /* ns */ $mod_id, + /* desc */ sprintf(__('delete %s plugin files'), $mod_id) ); \ No newline at end of file diff --git a/dcstore.xml b/dcstore.xml new file mode 100644 index 0000000..d2b7b82 --- /dev/null +++ b/dcstore.xml @@ -0,0 +1,13 @@ + + +dcFilterDuplicate +0.7 +Jean-Christian Denis, Pierre Van Glabeke +Antispam for duplicate comments on multiblog +https://github.com/JcDenis/dcFilterDuplicate/releases/download/v0.7/plugin-dcFilterDuplicate.zip +2.19 +http://plugins.dotaddict.org/dc2/details/dcFilterDuplicate + +http://forum.dotclear.org/viewtopic.php?pid=332947#p332947 + + \ No newline at end of file diff --git a/inc/class.filter.duplicate.php b/inc/class.filter.duplicate.php index f5f6118..f762014 100644 --- a/inc/class.filter.duplicate.php +++ b/inc/class.filter.duplicate.php @@ -3,7 +3,7 @@ # # This file is part of dcFilterDuplicate, a plugin for Dotclear 2. # -# Copyright (c) 2009-2015 Jean-Christian Denis and contributors +# Copyright (c) 2009-2021 Jean-Christian Denis and contributors # # Licensed under the GPL version 2.0 license. # A copy of this license is available in LICENSE file or at @@ -12,8 +12,7 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } /** @@ -23,117 +22,106 @@ if (!defined('DC_RC_PATH')) { */ class dcFilterDuplicate extends dcSpamFilter { - public $name = 'Duplicate comment filter'; - public $has_gui = true; + public $name = 'Duplicate comment filter'; + public $has_gui = true; - protected function setInfo() - { - $this->name = __('dcFilterDuplicate'); - $this->description = __('Same comments on others blogs of a multiblog'); - } - - public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) - { - if ($type != 'comment') { + protected function setInfo() + { + $this->name = __('Duplicate'); + $this->description = __('Same comments on others blogs of a multiblog'); + } - return null; - } + public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) + { + if ($type != 'comment') { + return null; + } + if (strlen($content) < abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen)) { + return null; + } - $minlen = abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen); - if (strlen($content) < $minlen) { + try { + if ($this->isDuplicate($content, $ip)) { + $this->markDuplicate($content, $ip); + $status = 'Duplicate on other blog'; + return true; + } else { + return null; + } + } catch (Exception $e) { + throw new Exception($e->getMessage()); + } + } - return null; - } + public function isDuplicate($content, $ip) + { + $rs = $this->core->con->select( + 'SELECT C.comment_id '. + 'FROM ' . $this->core->prefix . 'comment C ' . + 'LEFT JOIN ' . $this->core->prefix . 'post P ON C.post_id=P.post_id ' . + "WHERE P.blog_id != '" . $this->core->blog->id . "' " . + "AND C.comment_content='" . $this->core->con->escape($content) . "' " . + "AND C.comment_ip='" . $ip . "' " + ); + return !$rs->isEmpty(); + } - try { - if ($this->isDuplicate($content, $ip)) { - $this->markDuplicate($content, $ip); - $status = 'Duplicate on other blog'; + public function markDuplicate($content, $ip) + { + $cur = $this->core->con->openCursor($this->core->prefix . 'comment'); + $this->core->con->writeLock($this->core->prefix . 'comment'); - return true; - } - else { + $cur->comment_status = -2; + $cur->comment_spam_status = 'Duplicate on other blog'; + $cur->comment_spam_filter = 'dcFilterDuplicate'; + $cur->update( + "WHERE comment_content='" . $this->core->con->escape($content) . "' " . + "AND comment_ip='" . $ip . "' " + ); + $this->core->con->unlock(); + $this->triggerOtherBlogs($content, $ip); + } - return null; - } - } - catch (Exception $e) { - throw new Exception($e->getMessage()); - } - } + 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); + } - public function isDuplicate($content, $ip) - { - $rs = $this->core->con->select( - 'SELECT C.comment_id '. - 'FROM '.$this->core->prefix.'comment C '. - 'LEFT JOIN '.$this->core->prefix.'post P ON C.post_id=P.post_id '. - "WHERE P.blog_id != '".$this->core->blog->id."' ". - "AND C.comment_content='".$this->core->con->escape($content)."' ". - "AND C.comment_ip='".$ip."' " - ); + return + '
' . + '

' . + '

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

' . + '
'; + } - return !$rs->isEmpty(); - } - - public function markDuplicate($content, $ip) - { - $cur = $this->core->con->openCursor($this->core->prefix.'comment'); - $this->core->con->writeLock($this->core->prefix.'comment'); + public function triggerOtherBlogs($content, $ip) + { + $rs = $this->core->con->select( + 'SELECT P.blog_id ' . + 'FROM ' . $this->core->prefix . 'comment C ' . + 'LEFT JOIN ' . $this->core->prefix . 'post P ON C.post_id=P.post_id ' . + "WHERE C.comment_content='" . $this->core->con->escape($content) . "' " . + "AND C.comment_ip='" . $ip . "' " + ); - $cur->comment_status = -2; - $cur->comment_spam_status = 'Duplicate on other blog'; - $cur->comment_spam_filter = 'dcFilterDuplicate'; - - $cur->update( - "WHERE comment_content='".$this->core->con->escape($content)."' ". - "AND comment_ip='".$ip."' " - ); - $this->core->con->unlock(); - - $this->triggerOtherBlogs($content, $ip); - } - - public function gui($url) - { - $minlen = abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen); - if (isset($_POST['dcfilterduplicate_minlen'])) { - $minlen = abs((integer) $_POST['dcfilterduplicate_minlen']); - $this->core->blog->settings->dcFilterDuplicate->put( - 'dcfilterduplicate_minlen', - $minlen, - 'integer' - ); - dcPage::addSuccessNotice(__('Configuration successfully updated.')); - http::redirect($url); - } - - $res = - '
'. - '

'. - '

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

'. - '
'; - - return $res; - } - - public function triggerOtherBlogs($content, $ip) - { - $rs = $this->core->con->select( - 'SELECT P.blog_id '. - 'FROM '.$this->core->prefix.'comment C '. - 'LEFT JOIN '.$this->core->prefix.'post P ON C.post_id=P.post_id '. - "WHERE C.comment_content='".$this->core->con->escape($content)."' ". - "AND C.comment_ip='".$ip."' " - ); - - while ($rs->fetch()) { - $b = new dcBlog($this, $rs->blog_id); - $b->triggerBlog(); - unset($b); - } - } + while ($rs->fetch()) { + $b = new dcBlog($this, $rs->blog_id); + $b->triggerBlog(); + unset($b); + } + } } \ No newline at end of file diff --git a/locales/fr/main.lang.php b/locales/fr/main.lang.php new file mode 100644 index 0000000..6f6e70c --- /dev/null +++ b/locales/fr/main.lang.php @@ -0,0 +1,19 @@ + 1);\n" #: inc/class.filter.duplicate.php:30 -msgid "Duplicate comment filter" -msgstr "Filtre de doublon de commentaires" +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:110 +#: inc/class.filter.duplicate.php:99 msgid "Minimum content length before check for duplicate:" msgstr "Longueur minimum du contenu pour faire une vérification :" +msgid "Duplicate comment filter" +msgstr "Filtre de doublon de commentaires" + msgid "Antispam for duplicate comments on multiblog" msgstr "Antispam contre les doublons de commentaires sur un multiblog"