From 21b1cbbc16ddf7d93decd5b86c32f77886c33f8c Mon Sep 17 00:00:00 2001 From: brol Date: Wed, 22 Apr 2015 18:03:40 +0200 Subject: [PATCH] 0.6 --- CHANGELOG | 29 +++++++ LICENSE | 23 +++--- README.md | 24 +++++- _define.php | 37 +++++++++ _install.php | 74 ++++++++++++++++++ _prepend.php | 22 ++++++ _uninstall.php | 61 +++++++++++++++ inc/class.filter.duplicate.php | 139 +++++++++++++++++++++++++++++++++ locales/fr/main.po | 31 ++++++++ 9 files changed, 426 insertions(+), 14 deletions(-) create mode 100644 CHANGELOG create mode 100644 _define.php create mode 100644 _install.php create mode 100644 _prepend.php create mode 100644 _uninstall.php create mode 100644 inc/class.filter.duplicate.php create mode 100644 locales/fr/main.po diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..12a34b5 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,29 @@ +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/LICENSE b/LICENSE index 8cdb845..d511905 100644 --- a/LICENSE +++ b/LICENSE @@ -1,12 +1,12 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 - Copyright (C) 1989, 1991 Free Software Foundation, Inc., + Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public @@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - GNU GENERAL PUBLIC LICENSE + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains @@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - NO WARRANTY + NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN @@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - END OF TERMS AND CONDITIONS + END OF TERMS AND CONDITIONS - How to Apply These Terms to Your New Programs + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it @@ -290,8 +290,8 @@ to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - {description} - Copyright (C) {year} {fullname} + + Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -329,7 +329,7 @@ necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. - {signature of Ty Coon}, 1 April 1989 + , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into @@ -337,4 +337,3 @@ proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. - diff --git a/README.md b/README.md index 2517df3..4ccd08d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ -# dcFilterDuplicate -Antispam de commentaires en doublon sur un multiblog +# README + +## WHAT IS DCFILTERDUPLICATE ? + +dcFilterDuplicate "Dupicate comments filter" is a plugin for the +open-source web publishing software called Dotclear. + +Filter as spam same (duplicate) comments from multiple blogs of a Dotclear's install. + +## REQUIREMENTS + + dcFilterDuplicate requires: + + * permissions to manage antispam + * Dotclear 2.6 + +## USAGE + +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. diff --git a/_define.php b/_define.php new file mode 100644 index 0000000..4830718 --- /dev/null +++ b/_define.php @@ -0,0 +1,37 @@ +registerModule( + /* Name */ + "dcFilterDuplicate", + /* Description*/ + "Antispam for duplicate comments on multiblog", + /* Author */ + "Jean-Christian Denis", + /* 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' + ) +); \ No newline at end of file diff --git a/_install.php b/_install.php new file mode 100644 index 0000000..5acc279 --- /dev/null +++ b/_install.php @@ -0,0 +1,74 @@ +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; +} \ No newline at end of file diff --git a/_prepend.php b/_prepend.php new file mode 100644 index 0000000..b4ace8b --- /dev/null +++ b/_prepend.php @@ -0,0 +1,22 @@ +spamfilters[] = 'dcFilterDuplicate'; \ No newline at end of file diff --git a/_uninstall.php b/_uninstall.php new file mode 100644 index 0000000..db35cc9 --- /dev/null +++ b/_uninstall.php @@ -0,0 +1,61 @@ +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) +); \ No newline at end of file diff --git a/inc/class.filter.duplicate.php b/inc/class.filter.duplicate.php new file mode 100644 index 0000000..f5f6118 --- /dev/null +++ b/inc/class.filter.duplicate.php @@ -0,0 +1,139 @@ +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') { + + return null; + } + + $minlen = abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen); + if (strlen($content) < $minlen) { + + return null; + } + + 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()); + } + } + + 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(); + } + + public function markDuplicate($content, $ip) + { + $cur = $this->core->con->openCursor($this->core->prefix.'comment'); + $this->core->con->writeLock($this->core->prefix.'comment'); + + $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); + } + } +} \ No newline at end of file diff --git a/locales/fr/main.po b/locales/fr/main.po new file mode 100644 index 0000000..e9cb779 --- /dev/null +++ b/locales/fr/main.po @@ -0,0 +1,31 @@ +# Language: Français +# Module: dcFilterDuplicate - 0.5 +# Date: 2013-11-14 07:24:39 +# Translated with translater 2013.05.11 + +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Project-Id-Version: dcFilterDuplicate 0.5\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2013-11-14T07:24:39+00:00\n" +"Last-Translator: Jean-Christian Denis\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Transfer-Encoding: 8bit\n" + +#: inc/class.filter.duplicate.php:30 +msgid "Duplicate comment filter" +msgstr "Filtre de doublon de commentaires" + +#: 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 +msgid "Minimum content length before check for duplicate:" +msgstr "Longueur minimum du contenu pour faire une vérification :" + +msgid "Antispam for duplicate comments on multiblog" +msgstr "Antispam contre les doublons de commentaires sur un multiblog" +