prepare to DC 2.24

This commit is contained in:
Jean-Christian Paul Denis 2022-11-16 22:48:46 +01:00
parent 1929c00f40
commit 5a25109675
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
6 changed files with 146 additions and 139 deletions

View File

@ -1,32 +1,31 @@
<?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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
$this->registerModule(
"Duplicate filter",
"Antispam for duplicate comments on multiblog",
"Jean-Christian Denis, Pierre Van Glabeke",
'0.8',
'Duplicate filter',
'Antispam for duplicate comments on multiblog',
'Jean-Christian Denis, Pierre Van Glabeke',
'0.9',
[
'requires' => [['core', '2.19']],
'permissions' => 'admin',
'priority' => 200,
'type' => 'plugin',
'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'
'requires' => [['core', '2.24']],
'permissions' => dcAuth::PERMISSION_ADMIN,
'priority' => 200,
'type' => 'plugin',
'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

@ -1,63 +1,70 @@
<?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
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
# -- Module specs --
$mod_id = 'dcFilterDuplicate';
$mod_id = 'dcFilterDuplicate';
$mod_conf = [[
'dcfilterduplicate_minlen',
'Minimum lenght of comment to filter',
30,
'integer'
'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'),
dcCore::app()->getVersion($mod_id),
dcCore::app()->plugins->moduleInfo($mod_id, 'version'),
'>='
)) {
return null;
}
# Check Dotclear version
$dc_min = $this->modules[$mod_id]['requires'][0][1];
if (!method_exists('dcUtils', 'versionsCompare')
if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)
) {
throw new Exception(sprintf(
'%s requires Dotclear %s', $mod_id, $dc_min
'%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
dcCore::app()->blog->settings->addNamespace($mod_id);
foreach ($mod_conf as $v) {
dcCore::app()->blog->settings->{$mod_id}->put(
$v[0],
$v[2],
$v[3],
$v[1],
false,
true
);
}
# Set module version
$core->setVersion(
dcCore::app()->setVersion(
$mod_id,
$core->plugins->moduleInfo($mod_id, 'version')
dcCore::app()->plugins->moduleInfo($mod_id, 'version')
);
return true;
}
catch (Exception $e) {
$core->error->add($e->getMessage());
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
return false;
}
}

View File

@ -1,21 +1,19 @@
<?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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
$__autoload['dcFilterDuplicate'] =
dirname(__FILE__) . '/inc/class.filter.duplicate.php';
Clearbricks::lib()->autoload(['dcFilterDuplicate' => __DIR__ . '/inc/class.filter.duplicate.php']);
$core->spamfilters[] = 'dcFilterDuplicate';
dcCore::app()->spamfilters[] = 'dcFilterDuplicate';

View File

@ -1,16 +1,15 @@
<?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
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
@ -18,43 +17,67 @@ if (!defined('DC_CONTEXT_ADMIN')) {
$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)
);

View File

@ -1,16 +1,15 @@
<?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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
@ -22,12 +21,12 @@ if (!defined('DC_RC_PATH')) {
*/
class dcFilterDuplicate extends dcSpamFilter
{
public $name = 'Duplicate filter';
public $name = 'Duplicate filter';
public $has_gui = true;
protected function setInfo()
{
$this->name = __('Duplicate');
$this->name = __('Duplicate');
$this->description = __('Same comments on others blogs of a multiblog');
}
@ -36,7 +35,7 @@ class dcFilterDuplicate extends dcSpamFilter
if ($type != 'comment') {
return null;
}
if (strlen($content) < abs((integer) $this->core->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen'))) {
if (strlen($content) < $this->getMinLength()) {
return null;
}
@ -44,10 +43,11 @@ class dcFilterDuplicate extends dcSpamFilter
if ($this->isDuplicate($content, $ip)) {
$this->markDuplicate($content, $ip);
$status = 'Duplicate on other blog';
return true;
} else {
return null;
}
return null;
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
@ -55,41 +55,42 @@ class dcFilterDuplicate extends dcSpamFilter
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) . "' " .
$rs = dcCore::app()->con->select(
'SELECT C.comment_id ' .
'FROM ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' C ' .
'LEFT JOIN ' . dcCore::app()->prefix . 'post P ON C.post_id=P.post_id ' .
"WHERE P.blog_id != '" . dcCore::app()->blog->id . "' " .
"AND C.comment_content='" . dcCore::app()->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 = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME);
dcCore::app()->con->writeLock(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME);
$cur->comment_status = -2;
$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) . "' " .
"WHERE comment_content='" . dcCore::app()->con->escape($content) . "' " .
"AND comment_ip='" . $ip . "' "
);
$this->core->con->unlock();
dcCore::app()->con->unlock();
$this->triggerOtherBlogs($content, $ip);
}
public function gui($url)
public function gui(string $url): string
{
if ($this->core->auth->isSuperAdmin()) {
$this->core->blog->settings->dcFilterDuplicate->drop('dcfilterduplicate_minlen');
if (dcCore::app()->auth->isSuperAdmin()) {
dcCore::app()->blog->settings->dcFilterDuplicate->drop('dcfilterduplicate_minlen');
if (isset($_POST['dcfilterduplicate_minlen'])) {
$this->core->blog->settings->dcFilterDuplicate->put(
dcCore::app()->blog->settings->dcFilterDuplicate->put(
'dcfilterduplicate_minlen',
abs((integer) $_POST['dcfilterduplicate_minlen']),
abs((int) $_POST['dcfilterduplicate_minlen']),
'integer',
'Minimum lenght of comment to filter',
true,
@ -99,46 +100,46 @@ class dcFilterDuplicate extends dcSpamFilter
http::redirect($url);
}
return
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,
['dcfilterduplicate_minlen'],
65,
255,
$this->getMinlength(),
) . '</label></p>' .
'<p><input type="submit" name="save" value="' . __('Save') . '" />' .
$this->core->formNonce() . '</p>' .
dcCore::app()->formNonce() . '</p>' .
'</form>';
} else {
return
'<p class="info">' . sprintf(
__('Super administrator set the minimum length of comment content to %d chars.'),
$this->getMinlength()
) . '</p>';
}
return
'<p class="info">' . sprintf(
__('Super administrator set the minimum length of comment content to %d chars.'),
$this->getMinlength()
) . '</p>';
}
private function getMinLength()
{
return abs((integer) $this->core->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen'));
return abs((int) dcCore::app()->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen'));
}
public function triggerOtherBlogs($content, $ip)
{
$rs = $this->core->con->select(
$rs = dcCore::app()->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) . "' " .
'FROM ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' C ' .
'LEFT JOIN ' . dcCore::app()->prefix . 'post P ON C.post_id=P.post_id ' .
"WHERE C.comment_content='" . dcCore::app()->con->escape($content) . "' " .
"AND C.comment_ip='" . $ip . "' "
);
while ($rs->fetch()) {
$b = new dcBlog($this, $rs->blog_id);
$b = new dcBlog($rs->blog_id);
$b->triggerBlog();
unset($b);
}
}
}
}

View File

@ -1,21 +0,0 @@
<?php
// Language: Français
// Module: dcFilterDuplicate - 0.8
// Date: 2021-09-15 19:57:37
// Translated with dcTranslater - 2021.09.02.1
#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:104
$GLOBALS['__l10n']['Minimum content length before check for duplicate:'] = 'Longueur minimum du contenu pour faire une vérification :';
#inc/class.filter.duplicate.php:117
$GLOBALS['__l10n']['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.';
$GLOBALS['__l10n']['Antispam for duplicate comments on multiblog'] = 'Antispam contre les doublons de commentaires sur un multiblog';
$GLOBALS['__l10n']['Duplicate filter'] = 'Filtre de doublons';