cleanup 2021

This commit is contained in:
Jean-Christian Denis 2021-08-27 17:16:25 +02:00
parent 9b2f332ede
commit 53df2f9c4a
11 changed files with 262 additions and 244 deletions

View file

@ -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

32
CHANGELOG.md Normal file
View file

@ -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

View file

@ -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

View file

@ -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'
]
);

View file

@ -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;
}

View file

@ -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';

View file

@ -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)
);

13
dcstore.xml Normal file
View file

@ -0,0 +1,13 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="dcFilterDuplicate">
<name>dcFilterDuplicate</name>
<version>0.7</version>
<author>Jean-Christian Denis, Pierre Van Glabeke</author>
<desc>Antispam for duplicate comments on multiblog</desc>
<file>https://github.com/JcDenis/dcFilterDuplicate/releases/download/v0.7/plugin-dcFilterDuplicate.zip</file>
<da:dcmin>2.19</da:dcmin>
<da:details>http://plugins.dotaddict.org/dc2/details/dcFilterDuplicate</da:details>
<da:section></da:section>
<da:support>http://forum.dotclear.org/viewtopic.php?pid=332947#p332947</da:support>
</module>
</modules>

View file

@ -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
'<form action="' . html::escapeURL($url) . '" method="post">' .
'<p><label class="classic">' . __('Minimum content length before check for duplicate:') . '<br />' .
form::field(
['dcfilterduplicate_minlen'],
65,
255,
abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen)
) . '</label></p>' .
'<p><input type="submit" name="save" value="' . __('Save') . '" />' .
$this->core->formNonce() . '</p>' .
'</form>';
}
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 =
'<form action="'.html::escapeURL($url).'" method="post">'.
'<p><label class="classic">'.__('Minimum content length before check for duplicate:').'<br />'.
form::field(array('dcfilterduplicate_minlen'), 65, 255, $minlen).
'</label></p>'.
'<p><input type="submit" name="save" value="'.__('Save').'" />'.
$this->core->formNonce().'</p>'.
'</form>';
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);
}
}
}

19
locales/fr/main.lang.php Normal file
View file

@ -0,0 +1,19 @@
<?php
// Language: Français
// Module: dcFilterDuplicate - 0.7
// Date: 2021-08-27 15:14:22
// Translated with dcTranslater - 2021.08.18
#inc/class.filter.duplicate.php:30
$GLOBALS['__l10n']['Duplicate'] = 'Doublons';
#inc/class.filter.duplicate.php:31
$GLOBALS['__l10n']['Same comments on others blogs of a multiblog'] = 'Commentaires identiques sur les autres blogs du multiblog';
#inc/class.filter.duplicate.php:99
$GLOBALS['__l10n']['Minimum content length before check for duplicate:'] = 'Longueur minimum du contenu pour faire une vérification :';
$GLOBALS['__l10n']['Duplicate comment filter'] = 'Filtre de doublon de commentaires';
$GLOBALS['__l10n']['Antispam for duplicate comments on multiblog'] = 'Antispam contre les doublons de commentaires sur un multiblog';

View file

@ -1,31 +1,35 @@
# Language: Français
# Module: dcFilterDuplicate - 0.5
# Date: 2013-11-14 07:24:39
# Translated with translater 2013.05.11
# Module: dcFilterDuplicate - 0.7
# Date: 2021-08-27 15:14:22
# Translated with translater 2021.08.18
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: dcFilterDuplicate 0.5\n"
"Project-Id-Version: dcFilterDuplicate 0.7\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2013-11-14T07:24:39+00:00\n"
"PO-Revision-Date: 2021-08-27T15:14:22+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 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"