2015-04-22 16:03:40 +00:00
|
|
|
<?php
|
2021-09-02 14:30:40 +00:00
|
|
|
/**
|
|
|
|
* @brief dcFilterDuplicate, a plugin for Dotclear 2
|
2022-11-16 21:48:46 +00:00
|
|
|
*
|
2021-09-02 14:30:40 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2022-11-16 21:48:46 +00:00
|
|
|
*
|
2021-09-02 14:30:40 +00:00
|
|
|
* @author Jean-Christian Denis, Pierre Van Glabeke
|
2022-11-16 21:48:46 +00:00
|
|
|
*
|
2021-09-02 14:30:40 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2015-04-22 16:03:40 +00:00
|
|
|
if (!defined('DC_RC_PATH')) {
|
2021-08-27 15:16:25 +00:00
|
|
|
return null;
|
2015-04-22 16:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup DC_PLUGIN_DCFILTERDUPLICATE
|
|
|
|
* @brief Filter duplicate comments on multiblogs.
|
|
|
|
* @since 2.6
|
|
|
|
*/
|
|
|
|
class dcFilterDuplicate extends dcSpamFilter
|
|
|
|
{
|
2022-11-16 21:48:46 +00:00
|
|
|
public $name = 'Duplicate filter';
|
2021-08-27 15:16:25 +00:00
|
|
|
public $has_gui = true;
|
|
|
|
|
|
|
|
protected function setInfo()
|
|
|
|
{
|
2022-11-16 21:48:46 +00:00
|
|
|
$this->name = __('Duplicate');
|
2021-08-27 15:16:25 +00:00
|
|
|
$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;
|
|
|
|
}
|
2022-11-16 21:48:46 +00:00
|
|
|
if (strlen($content) < $this->getMinLength()) {
|
2021-08-27 15:16:25 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if ($this->isDuplicate($content, $ip)) {
|
|
|
|
$this->markDuplicate($content, $ip);
|
|
|
|
$status = 'Duplicate on other blog';
|
2022-11-16 21:48:46 +00:00
|
|
|
|
2021-08-27 15:16:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-11-16 21:48:46 +00:00
|
|
|
|
|
|
|
return null;
|
2021-08-27 15:16:25 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isDuplicate($content, $ip)
|
|
|
|
{
|
2022-11-16 21:48:46 +00:00
|
|
|
$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) . "' " .
|
2021-08-27 15:16:25 +00:00
|
|
|
"AND C.comment_ip='" . $ip . "' "
|
|
|
|
);
|
2022-11-16 21:48:46 +00:00
|
|
|
|
2021-08-27 15:16:25 +00:00
|
|
|
return !$rs->isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function markDuplicate($content, $ip)
|
|
|
|
{
|
2022-11-16 21:48:46 +00:00
|
|
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME);
|
|
|
|
dcCore::app()->con->writeLock(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME);
|
2021-08-27 15:16:25 +00:00
|
|
|
|
2022-11-16 21:48:46 +00:00
|
|
|
$cur->comment_status = -2;
|
2021-08-27 15:16:25 +00:00
|
|
|
$cur->comment_spam_status = 'Duplicate on other blog';
|
|
|
|
$cur->comment_spam_filter = 'dcFilterDuplicate';
|
|
|
|
$cur->update(
|
2022-11-16 21:48:46 +00:00
|
|
|
"WHERE comment_content='" . dcCore::app()->con->escape($content) . "' " .
|
2021-08-27 15:16:25 +00:00
|
|
|
"AND comment_ip='" . $ip . "' "
|
|
|
|
);
|
2022-11-16 21:48:46 +00:00
|
|
|
dcCore::app()->con->unlock();
|
2021-08-27 15:16:25 +00:00
|
|
|
$this->triggerOtherBlogs($content, $ip);
|
|
|
|
}
|
|
|
|
|
2022-11-16 21:48:46 +00:00
|
|
|
public function gui(string $url): string
|
2021-08-27 15:16:25 +00:00
|
|
|
{
|
2022-11-16 21:48:46 +00:00
|
|
|
if (dcCore::app()->auth->isSuperAdmin()) {
|
|
|
|
dcCore::app()->blog->settings->dcFilterDuplicate->drop('dcfilterduplicate_minlen');
|
2021-09-15 20:00:17 +00:00
|
|
|
if (isset($_POST['dcfilterduplicate_minlen'])) {
|
2022-11-16 21:48:46 +00:00
|
|
|
dcCore::app()->blog->settings->dcFilterDuplicate->put(
|
2021-09-15 20:00:17 +00:00
|
|
|
'dcfilterduplicate_minlen',
|
2022-11-16 21:48:46 +00:00
|
|
|
abs((int) $_POST['dcfilterduplicate_minlen']),
|
2021-09-15 20:00:17 +00:00
|
|
|
'integer',
|
|
|
|
'Minimum lenght of comment to filter',
|
|
|
|
true,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
dcPage::addSuccessNotice(__('Configuration successfully updated.'));
|
|
|
|
http::redirect($url);
|
|
|
|
}
|
|
|
|
|
2022-11-16 21:48:46 +00:00
|
|
|
return
|
2021-09-15 20:00:17 +00:00
|
|
|
'<form action="' . html::escapeURL($url) . '" method="post">' .
|
|
|
|
'<p><label class="classic">' . __('Minimum content length before check for duplicate:') . '<br />' .
|
|
|
|
form::field(
|
2022-11-16 21:48:46 +00:00
|
|
|
['dcfilterduplicate_minlen'],
|
|
|
|
65,
|
|
|
|
255,
|
2021-09-15 20:00:17 +00:00
|
|
|
$this->getMinlength(),
|
|
|
|
) . '</label></p>' .
|
|
|
|
'<p><input type="submit" name="save" value="' . __('Save') . '" />' .
|
2022-11-16 21:48:46 +00:00
|
|
|
dcCore::app()->formNonce() . '</p>' .
|
2021-09-15 20:00:17 +00:00
|
|
|
'</form>';
|
2021-08-27 15:16:25 +00:00
|
|
|
}
|
2022-11-16 21:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
'<p class="info">' . sprintf(
|
|
|
|
__('Super administrator set the minimum length of comment content to %d chars.'),
|
|
|
|
$this->getMinlength()
|
|
|
|
) . '</p>';
|
2021-09-15 20:00:17 +00:00
|
|
|
}
|
2021-08-27 15:16:25 +00:00
|
|
|
|
2021-09-15 20:00:17 +00:00
|
|
|
private function getMinLength()
|
|
|
|
{
|
2022-11-16 21:48:46 +00:00
|
|
|
return abs((int) dcCore::app()->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen'));
|
2021-08-27 15:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function triggerOtherBlogs($content, $ip)
|
|
|
|
{
|
2022-11-16 21:48:46 +00:00
|
|
|
$rs = dcCore::app()->con->select(
|
2021-08-27 15:16:25 +00:00
|
|
|
'SELECT P.blog_id ' .
|
2022-11-16 21:48:46 +00:00
|
|
|
'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) . "' " .
|
2021-08-27 15:16:25 +00:00
|
|
|
"AND C.comment_ip='" . $ip . "' "
|
|
|
|
);
|
|
|
|
|
|
|
|
while ($rs->fetch()) {
|
2022-11-16 21:48:46 +00:00
|
|
|
$b = new dcBlog($rs->blog_id);
|
2021-08-27 15:16:25 +00:00
|
|
|
$b->triggerBlog();
|
|
|
|
unset($b);
|
|
|
|
}
|
|
|
|
}
|
2022-11-16 21:48:46 +00:00
|
|
|
}
|