2013-07-25 11:21:54 +02:00
|
|
|
<?php
|
|
|
|
if (IN_serendipity !== true) {
|
|
|
|
die ("Don't hack!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Probe for a language include with constants. Still include defines later on, if some constants were missing
|
|
|
|
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
|
|
|
|
if (file_exists($probelang)) {
|
|
|
|
include $probelang;
|
|
|
|
}
|
|
|
|
include dirname(__FILE__) . '/lang_en.inc.php';
|
|
|
|
|
|
|
|
class serendipity_event_spamblock_bayes extends serendipity_event {
|
|
|
|
|
|
|
|
function introspect(&$propbag) {
|
|
|
|
global $serendipity;
|
|
|
|
|
|
|
|
|
|
|
|
$this->title = PLUGIN_EVENT_SPAMBLOCK_BAYES_NAME;
|
|
|
|
$propbag->add ( 'description', PLUGIN_EVENT_SPAMBLOCK_BAYES_DESC);
|
|
|
|
$propbag->add ( 'name', $this->title);
|
2020-08-19 00:11:14 +02:00
|
|
|
$propbag->add ( 'version', '1.1' );
|
2013-07-25 11:21:54 +02:00
|
|
|
$propbag->add ( 'event_hooks', array ('frontend_saveComment' => true,
|
2020-08-09 11:10:41 +02:00
|
|
|
'backend_comments_top' => true,
|
2013-07-25 11:21:54 +02:00
|
|
|
'external_plugin' => true,
|
|
|
|
'backend_view_comment' => true,
|
|
|
|
'xmlrpc_comment_spam' => true,
|
|
|
|
'xmlrpc_comment_ham' => true,
|
2020-08-09 11:10:41 +02:00
|
|
|
'js_backend' => true,
|
|
|
|
'css_backend' => true,
|
|
|
|
'backend_sidebar_admin_appearance' => true,
|
|
|
|
'backend_sidebar_entries_event_display_spamblock_bayes' => true,
|
2013-07-25 11:21:54 +02:00
|
|
|
));
|
|
|
|
$propbag->add ( 'groups', array ('ANTISPAM' ) );
|
|
|
|
$propbag->add ( 'author', 'kleinerChemiker, Malte Paskuda, based upon b8 by Tobias Leupold');
|
|
|
|
$propbag->add('configuration', array(
|
|
|
|
'method',
|
2020-08-09 11:10:41 +02:00
|
|
|
'recycler'
|
2013-07-25 11:21:54 +02:00
|
|
|
));
|
2020-08-09 11:10:41 +02:00
|
|
|
$propbag->add('requirements', array(
|
|
|
|
'serendipity' => '2.1',
|
|
|
|
'php' => '7.0'
|
|
|
|
));
|
2018-04-05 14:17:19 +02:00
|
|
|
$propbag->add('legal', array(
|
|
|
|
'services' => array(
|
|
|
|
),
|
|
|
|
'frontend' => array(
|
|
|
|
'All user data and metadata (IP address, comment fields) can be logged to database or file'
|
|
|
|
),
|
|
|
|
'backend' => array(
|
|
|
|
),
|
|
|
|
'cookies' => array(
|
|
|
|
),
|
|
|
|
'stores_user_input' => true,
|
|
|
|
'stores_ip' => true,
|
2020-08-09 11:10:41 +02:00
|
|
|
'uses_ip' => true
|
2018-04-05 14:17:19 +02:00
|
|
|
));
|
|
|
|
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function introspect_config_item($name, &$propbag)
|
|
|
|
{
|
|
|
|
global $serendipity;
|
|
|
|
|
|
|
|
switch($name) {
|
|
|
|
case 'method':
|
|
|
|
$propbag->add('type', 'select');
|
|
|
|
$propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_METHOD);
|
|
|
|
$propbag->add('select_values', array(
|
|
|
|
'moderate' => PLUGIN_EVENT_SPAMBLOCK_BAYES_METHOD_MODERATE,
|
|
|
|
'block' => PLUGIN_EVENT_SPAMBLOCK_BAYES_METHOD_BLOCK,
|
|
|
|
));
|
|
|
|
$propbag->add('default', 'moderation');
|
|
|
|
break;
|
|
|
|
case 'recycler':
|
|
|
|
$propbag->add('type', 'boolean');
|
|
|
|
$propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_BAYES_MENU_RECYCLER);
|
|
|
|
$propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_BAYES_RECYCLER_DESC);
|
|
|
|
$propbag->add('default', true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function generate_content(&$title) {
|
|
|
|
$title = $this->title;
|
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
function setupDB() {
|
|
|
|
global $serendipity;
|
|
|
|
# b8 needs to one table for the tokens
|
|
|
|
$sql = 'CREATE TABLE IF NOT EXISTS b8_wordlist(
|
|
|
|
token varchar(255) {PRIMARY} NOT NULL,
|
|
|
|
count_ham int {UNSIGNED} default NULL,
|
|
|
|
count_spam int {UNSIGNED} default NULL
|
|
|
|
) {UTF_8}';
|
|
|
|
serendipity_db_schema_import($sql);
|
2013-07-25 11:21:54 +02:00
|
|
|
|
2015-12-11 23:53:33 +01:00
|
|
|
switch ($serendipity['dbType']) {
|
|
|
|
case 'mysql':
|
|
|
|
case 'mysqli':
|
2020-08-09 11:10:41 +02:00
|
|
|
$sql = "INSERT IGNORE INTO b8_wordlist (token, count_ham) VALUES ('b8*dbversion', 3);";
|
|
|
|
serendipity_db_query($sql);
|
|
|
|
$sql = "INSERT IGNORE INTO b8_wordlist (token, count_ham, count_spam) VALUES ('b8*texts', 0, 0);";
|
|
|
|
serendipity_db_query($sql);
|
|
|
|
|
|
|
|
# our recycler bin needs to copy the comments table
|
2015-12-11 23:53:33 +01:00
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS
|
|
|
|
{$serendipity['dbPrefix']}spamblock_bayes_recycler
|
|
|
|
LIKE
|
|
|
|
{$serendipity['dbPrefix']}comments";
|
2020-08-19 00:11:14 +02:00
|
|
|
serendipity_db_schema_import($sql);
|
2015-12-11 23:53:33 +01:00
|
|
|
break;
|
2015-12-13 14:17:48 +01:00
|
|
|
case 'sqlite':
|
|
|
|
case 'sqlite3':
|
|
|
|
case 'pdo-sqlite':
|
|
|
|
case 'pdo-sqliteoo':
|
2020-08-09 11:10:41 +02:00
|
|
|
$sql = "INSERT OR IGNORE INTO b8_wordlist (token, count_ham) VALUES ('b8*dbversion', 3);";
|
|
|
|
serendipity_db_query($sql);
|
|
|
|
$sql = "INSERT OR IGNORE INTO b8_wordlist (token, count_ham, count_spam) VALUES ('b8*texts', 0, 0);";
|
|
|
|
serendipity_db_query($sql);
|
|
|
|
|
|
|
|
# To get all column definitions we get the SQL used for creating the original table
|
2015-12-11 23:53:33 +01:00
|
|
|
$sql = "SELECT sql FROM sqlite_master WHERE type = 'table' AND name = '{$serendipity['dbPrefix']}comments';";
|
|
|
|
$sql = serendipity_db_query($sql);
|
|
|
|
if (is_array($sql)) {
|
|
|
|
$sql = $sql[0][0];
|
|
|
|
}
|
|
|
|
$sql = str_replace("{$serendipity['dbPrefix']}comments", "{$serendipity['dbPrefix']}spamblock_bayes_recycler", $sql);
|
2016-09-02 21:35:50 +02:00
|
|
|
if (strpos("sql", "NOT EXISTS") === false) {
|
|
|
|
$sql = str_replace("CREATE TABLE", "CREATE TABLE IF NOT EXISTS", $sql);
|
|
|
|
}
|
2020-08-19 00:11:14 +02:00
|
|
|
serendipity_db_schema_import($sql);
|
2015-12-11 23:53:33 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS
|
2013-07-25 11:21:54 +02:00
|
|
|
{$serendipity['dbPrefix']}spamblock_bayes_recycler
|
|
|
|
as SELECT * FROM
|
2015-12-11 23:53:33 +01:00
|
|
|
{$serendipity['dbPrefix']}comments ORDER BY id LIMIT 1 WITH NO DATA";
|
2020-08-19 00:11:14 +02:00
|
|
|
serendipity_db_schema_import($sql);
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function event_hook($event, &$bag, &$eventData, $addData = null) {
|
|
|
|
global $serendipity;
|
2020-08-09 11:10:41 +02:00
|
|
|
$hooks = &$bag->get('event_hooks');
|
2013-07-25 11:21:54 +02:00
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
if (isset($hooks[$event])) {
|
2013-07-25 11:21:54 +02:00
|
|
|
switch ($event) {
|
2020-08-09 11:10:41 +02:00
|
|
|
case 'external_plugin':
|
|
|
|
switch ($eventData) {
|
|
|
|
case 'bayes_learncomment':
|
2013-07-25 11:21:54 +02:00
|
|
|
if (!serendipity_checkPermission('adminComments')) {
|
|
|
|
break;
|
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
$category = $_REQUEST['category'];
|
|
|
|
$ids = $_REQUEST['id'];
|
2013-07-25 11:21:54 +02:00
|
|
|
$ids = explode(';', $ids);
|
|
|
|
foreach($ids as $id) {
|
2020-08-09 11:10:41 +02:00
|
|
|
$databaseComment = $this->getComment($id)[0];
|
|
|
|
print_r($databaseComment);
|
|
|
|
|
|
|
|
$comment = $databaseComment['url'] . ' ' . $databaseComment['body'] . ' ' . $databaseComment['author'] . ' ' . $databaseComment['email'];
|
|
|
|
|
|
|
|
$this->learn($comment, $category);
|
2013-07-25 11:21:54 +02:00
|
|
|
|
|
|
|
//Ham shall be approved, Spam deleted
|
|
|
|
if ($category == 'ham') {
|
2020-08-09 11:10:41 +02:00
|
|
|
serendipity_approveComment($id, $databaseComment['entry_id']);
|
|
|
|
}
|
|
|
|
if ($category == 'spam') {
|
2013-07-25 11:21:54 +02:00
|
|
|
if ($this->get_config('recycler', true)) {
|
2020-08-09 11:10:41 +02:00
|
|
|
$this->recycleComment($id, $databaseComment['entry_id']);
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
echo 'id: ';
|
|
|
|
print_r($id);
|
|
|
|
echo 'entry_id: ';
|
|
|
|
print_r($databaseComment['entry_id']);
|
|
|
|
serendipity_deleteComment($id, $databaseComment['entry_id']);
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-08-09 11:10:41 +02:00
|
|
|
case 'bayes_recycle':
|
2013-07-25 11:21:54 +02:00
|
|
|
if (!serendipity_checkPermission('adminComments')) {
|
|
|
|
break;
|
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
if (!empty($_REQUEST['serendipity']['selected'])) {
|
|
|
|
$ids = array_keys($_REQUEST['serendipity']['selected']);
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
if (isset($_REQUEST['restore'])) {
|
2020-08-09 11:10:41 +02:00
|
|
|
if (!empty($ids)) {
|
2013-07-25 11:21:54 +02:00
|
|
|
$this->restoreComments($ids);
|
|
|
|
|
|
|
|
if (count($ids) > 1) {
|
|
|
|
$msg = 'Comments '. implode(', ', $ids) .' restored';
|
|
|
|
} else {
|
|
|
|
$msg = 'Comment '. implode(', ', $ids) .' restored';
|
|
|
|
}
|
|
|
|
$msgtype = 'success';
|
|
|
|
} else {
|
|
|
|
$msg = 'No comment selected';
|
|
|
|
$msgtype = 'message';
|
|
|
|
}
|
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
|
2013-07-25 11:21:54 +02:00
|
|
|
if (isset($_REQUEST['empty'])) {
|
2020-08-09 11:10:41 +02:00
|
|
|
$this->emptyRecycler();
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
|
2013-07-25 11:21:54 +02:00
|
|
|
$redirect= '<meta http-equiv="REFRESH" content="0;url=';
|
|
|
|
$url = 'serendipity_admin.php?serendipity[adminModule]=event_display';
|
2020-08-09 11:10:41 +02:00
|
|
|
$url .= '&serendipity[adminAction]=spamblock_bayes">';
|
2013-07-25 11:21:54 +02:00
|
|
|
echo $redirect . $url;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-08-09 11:10:41 +02:00
|
|
|
|
|
|
|
case 'frontend_saveComment':
|
|
|
|
if (! is_array ( $eventData ) || serendipity_db_bool ( $eventData ['allow_comments'] )) {
|
|
|
|
if (!isset($serendipity['csuccess'])) {
|
|
|
|
$serendipity['csuccess'] = 'true';
|
|
|
|
}
|
2013-07-25 11:21:54 +02:00
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
$comment = $addData['url'] . ' ' . $addData['comment'] . ' ' . $addData['name'] . ' ' . $addData['email'];
|
2013-07-25 11:21:54 +02:00
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
echo $this->rate($comment);
|
|
|
|
if ($this->rate($comment) > 0.8) {
|
|
|
|
$method = $this->get_config('method', 'moderate');
|
|
|
|
if ($method == 'moderate') {
|
|
|
|
$this->moderate($eventData, $addData);
|
|
|
|
return false;
|
|
|
|
} elseif($method == 'block') {
|
|
|
|
$this->block($eventData, $addData);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'backend_view_comment':
|
|
|
|
$imgpath = $serendipity['baseURL'] . 'index.php?/plugin/';
|
|
|
|
|
|
|
|
$comment = $eventData['url'] . ' ' . $eventData['fullBody'] . ' ' . $eventData['name'] . ' ' . $eventData['email'];
|
|
|
|
|
|
|
|
$eventData['action_more'] = '<ul id="bayes_actions" class="plainList clearfix actions">
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
class="button_link spamblockBayesControls"
|
|
|
|
onclick="return ham('. $eventData['id'].');"
|
|
|
|
title="'. PLUGIN_EVENT_SPAMBLOCK_BAYES_NAME . ': ' . PLUGIN_EVENT_SPAMBLOCK_BAYES_HAM .'"
|
|
|
|
><span class="icon-ok-circled" aria-hidden="true"></span><span class="visuallyhidden"> ' . PLUGIN_EVENT_SPAMBLOCK_BAYES_HAM .'</span></a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
class="button_link spamblockBayesControls"
|
|
|
|
onclick="return spam('. $eventData['id'] .');"
|
|
|
|
title="'. PLUGIN_EVENT_SPAMBLOCK_BAYES_NAME . ': ' . PLUGIN_EVENT_SPAMBLOCK_BAYES_SPAM .'"
|
|
|
|
><span class="icon-cancel" aria-hidden="true"></span><span class="visuallyhidden"> ' . PLUGIN_EVENT_SPAMBLOCK_BAYES_SPAM .'</span></a>
|
|
|
|
</li>
|
|
|
|
<li class="bayes_spamrating">
|
|
|
|
<span id="' . $eventData['id'] . '_rating"> ' . preg_replace('/\..*/', '', $this->rate($comment) * 100) . '%</span>
|
|
|
|
</li>
|
|
|
|
</ul>';
|
2013-07-25 11:21:54 +02:00
|
|
|
break;
|
2020-08-09 11:10:41 +02:00
|
|
|
|
2013-07-25 11:21:54 +02:00
|
|
|
case 'xmlrpc_comment_spam':
|
|
|
|
$entry_id = $addData['id'];
|
|
|
|
$comment_id = $addData['cid'];
|
2020-08-09 11:10:41 +02:00
|
|
|
$comment = eventData['url'] . ' ' . $eventData['body'] . ' ' . $eventData['name'] . ' ' . $eventData['email'];
|
|
|
|
$this->learn($eventData, 'spam');
|
2013-07-25 11:21:54 +02:00
|
|
|
serendipity_deleteComment($comment_id, $entry_id);
|
2020-08-09 11:10:41 +02:00
|
|
|
break;
|
2013-07-25 11:21:54 +02:00
|
|
|
|
|
|
|
case 'xmlrpc_comment_ham':
|
|
|
|
$comment_id = $addData['cid'];
|
|
|
|
$entry_id = $addData['id'];
|
2020-08-09 11:10:41 +02:00
|
|
|
$comment = eventData['url'] . ' ' . $eventData['body'] . ' ' . $eventData['name'] . ' ' . $eventData['email'];
|
|
|
|
$this->learn($comment, 'ham');
|
2013-07-25 11:21:54 +02:00
|
|
|
//moderated ham-comments should be instantly approved, that's why they need an id:
|
|
|
|
serendipity_approveComment($comment_id, $entry_id);
|
2020-08-09 11:10:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'backend_sidebar_admin_appearance':
|
|
|
|
if (!serendipity_checkPermission('adminComments')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks">
|
|
|
|
<a href="?serendipity[adminModule]=event_display&serendipity[adminAction]=spamblock_bayes">
|
|
|
|
'. PLUGIN_EVENT_SPAMBLOCK_BAYES_NAME .'
|
|
|
|
</a>
|
|
|
|
</li>';
|
|
|
|
break;
|
2013-07-25 11:21:54 +02:00
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
case 'backend_sidebar_entries_event_display_spamblock_bayes':
|
|
|
|
if (!serendipity_checkPermission('adminComments')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->displayRecycler();
|
|
|
|
break;
|
2013-07-25 11:21:54 +02:00
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
|
|
|
|
case 'js_backend':
|
|
|
|
echo "var learncommentPath = '{$serendipity['baseURL']}index.php?/plugin/bayes_learncomment';";
|
|
|
|
echo file_get_contents(dirname(__FILE__). '/bayes_commentlist.js');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'css_backend':
|
|
|
|
echo '.spamblockBayesControls { cursor: pointer; }';
|
|
|
|
break;
|
2013-07-25 11:21:54 +02:00
|
|
|
default :
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
return true;
|
2013-07-25 11:21:54 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
# we init b8 in this function and not directly in the event hook, because in the event hook the SPL autoload gets triggered by smarty and fails
|
|
|
|
function initB8() {
|
2014-06-05 17:43:35 +02:00
|
|
|
global $serendipity;
|
2020-08-09 11:10:41 +02:00
|
|
|
if ($this->$b8 === null) {
|
2020-08-19 00:11:14 +02:00
|
|
|
$this->setupDB();
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
require_once(dirname(__FILE__) . '/b8/b8.php');
|
|
|
|
switch ($serendipity['dbType']) {
|
|
|
|
case 'mysql':
|
|
|
|
case 'mysqli':
|
|
|
|
$config_b8 = [ 'storage' => 'mysql' ];
|
2013-07-25 11:21:54 +02:00
|
|
|
break;
|
2020-08-09 11:10:41 +02:00
|
|
|
case 'sqlite':
|
|
|
|
case 'sqlite3':
|
|
|
|
case 'pdo-sqlite':
|
|
|
|
case 'pdo-sqliteoo':
|
|
|
|
$config_b8 = [ 'storage' => 'sqlite' ];
|
2013-07-25 11:21:54 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
|
|
|
|
$config_storage = [ 'resource' => $serendipity['dbConn'],
|
|
|
|
'table' => 'b8_wordlist' ];
|
|
|
|
$this->$b8 = new b8\b8($config_b8, $config_storage);
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
# Return the bayes rating reflecting the spamminess of the comment string. 0: ham, 1: spam
|
|
|
|
function rate($comment) {
|
|
|
|
$this->initB8();
|
|
|
|
return $this->$b8->classify($comment);
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
# Mark a comment text as ham or spam
|
|
|
|
function learn($comment, $category) {
|
|
|
|
$this->initB8();
|
|
|
|
if ($category == 'ham') {
|
|
|
|
$this->$b8->learn($comment, b8\b8::HAM);
|
|
|
|
}
|
|
|
|
if ($category == 'spam') {
|
|
|
|
$this->$b8->learn($comment, b8\b8::SPAM);
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
function block(&$eventData, &$addData) {
|
2013-07-25 11:21:54 +02:00
|
|
|
global $serendipity;
|
2020-08-09 11:10:41 +02:00
|
|
|
if ($this->get_config('recycler', true)) {
|
|
|
|
$this->throwInRecycler($eventData, $addData);
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
$eventData['allow_comments'] = false;
|
|
|
|
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_BAYES_ERROR;
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
function moderate(&$eventData, &$addData) {
|
2018-03-25 11:59:17 +02:00
|
|
|
global $serendipity;
|
2020-08-09 11:10:41 +02:00
|
|
|
$eventData['moderate_comments'] = true;
|
|
|
|
$serendipity['csuccess'] = 'moderate';
|
|
|
|
$serendipity['moderate_reason'] = sprintf(PLUGIN_EVENT_SPAMBLOCK_BAYES_MODERATE);
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
# id: id of a comment
|
2013-07-25 11:21:54 +02:00
|
|
|
function getComment($id) {
|
|
|
|
global $serendipity;
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
$sql = "SELECT id, body, entry_id, author, email, url, ip, referer FROM {$serendipity['dbPrefix']}comments
|
2013-07-25 11:21:54 +02:00
|
|
|
WHERE id = " . (int)$id;
|
2020-08-09 11:10:41 +02:00
|
|
|
|
2013-07-25 11:21:54 +02:00
|
|
|
$comments = serendipity_db_query($sql, false, 'assoc');
|
|
|
|
return $comments;
|
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
### Recycler functionality ###
|
|
|
|
|
|
|
|
function displayRecycler() {
|
2013-07-25 11:21:54 +02:00
|
|
|
global $serendipity;
|
2020-08-09 11:10:41 +02:00
|
|
|
$comments = $this->getAllRecyclerComments();
|
|
|
|
if (is_array($comments[0])) {
|
|
|
|
for ($i=0; $i < count($comments); $i++) {
|
|
|
|
$databaseComment = $comments[$i];
|
|
|
|
$comment = $databaseComment['url'] . ' ' . $databaseComment['body'] . ' ' . $databaseComment['author'] . ' ' . $databaseComment['email'];
|
|
|
|
|
|
|
|
$databaseComment['article_link'] = serendipity_archiveURL($databaseComment['entry_id'], 'comments', 'serendipityHTTPPath', true);
|
|
|
|
$databaseComment['article_title'] = $this->getEntryTitle($databaseComment['entry_id']);
|
|
|
|
$comments[$i] = $databaseComment;
|
2013-07-25 11:21:54 +02:00
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
}
|
2013-07-25 11:21:54 +02:00
|
|
|
} else {
|
2020-08-09 11:10:41 +02:00
|
|
|
$comments = array();
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
if (!is_object($serendipity['smarty'])) {
|
|
|
|
serendipity_smarty_init();
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
2020-08-09 11:10:41 +02:00
|
|
|
$serendipity['smarty']->assign('comments', $comments);
|
|
|
|
echo $this->parseTemplate('bayesRecyclermenu.tpl');
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
function getAllRecyclerComments() {
|
2013-07-25 11:21:54 +02:00
|
|
|
global $serendipity;
|
2020-08-09 11:10:41 +02:00
|
|
|
$sql = "SELECT * FROM {$serendipity['dbPrefix']}spamblock_bayes_recycler ORDER BY id DESC";
|
2013-07-25 11:21:54 +02:00
|
|
|
$comments = serendipity_db_query($sql, false, 'assoc');
|
|
|
|
|
|
|
|
return $comments;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Empty the Recycler
|
|
|
|
function emptyRecycler() {
|
|
|
|
global $serendipity;
|
|
|
|
$sql = "DELETE FROM
|
|
|
|
{$serendipity['dbPrefix']}spamblock_bayes_recycler";
|
|
|
|
return serendipity_db_query($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get the blocked comment and store it in the recycler-table
|
|
|
|
//Used when the comment is from a current happening event
|
|
|
|
function throwInRecycler(&$ca, &$commentInfo) {
|
|
|
|
global $serendipity;
|
|
|
|
|
|
|
|
#code copied from serendipity_insertComment. Changed: $id and $status
|
|
|
|
$id = (int)$ca['id'];
|
|
|
|
$type = $commentInfo['type'];
|
2020-05-29 14:38:17 +02:00
|
|
|
$email = serendipity_db_escape_string($commentInfo['email']);
|
2013-07-25 11:21:54 +02:00
|
|
|
if (isset($commentInfo['subscribe'])) {
|
|
|
|
if (!isset($serendipity['allowSubscriptionsOptIn']) || $serendipity['allowSubscriptionsOptIn']) {
|
|
|
|
$subscribe = 'false';
|
|
|
|
} else {
|
|
|
|
$subscribe = 'true';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$subscribe = 'false';
|
|
|
|
}
|
|
|
|
//'approved' cause only relevant after recovery
|
|
|
|
$dbstatus = 'approved';
|
|
|
|
|
|
|
|
$title = serendipity_db_escape_string($ca['title']);
|
|
|
|
$comments = $commentInfo['comment'];
|
|
|
|
$ip = serendipity_db_escape_string(isset($commentInfo['ip']) ? $commentInfo['ip'] : $_SERVER['REMOTE_ADDR']);
|
|
|
|
$commentsFixed = serendipity_db_escape_string($commentInfo['comment']);
|
|
|
|
$name = serendipity_db_escape_string($commentInfo['name']);
|
|
|
|
$url = serendipity_db_escape_string($commentInfo['url']);
|
|
|
|
$parentid = (isset($commentInfo['parent_id']) && is_numeric($commentInfo['parent_id'])) ? $commentInfo['parent_id'] : 0;
|
|
|
|
$status = serendipity_db_escape_string(isset($commentInfo['status']) ? $commentInfo['status'] : (serendipity_db_bool($ca['moderate_comments']) ? 'pending' : 'approved'));
|
|
|
|
$t = serendipity_db_escape_string(isset($commentInfo['time']) ? $commentInfo['time'] : time());
|
|
|
|
$referer = substr((isset($_SESSION['HTTP_REFERER']) ? serendipity_db_escape_string($_SESSION['HTTP_REFERER']) : ''), 0, 200);
|
|
|
|
|
|
|
|
$sql = "INSERT INTO
|
|
|
|
{$serendipity['dbPrefix']}spamblock_bayes_recycler (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)
|
|
|
|
VALUES ('$id', '$parentid', '$ip', '$name', '$email', '$url', '$commentsFixed', '$type', '$t', '$title', '$subscribe', '$dbstatus', '$referer')";
|
|
|
|
|
|
|
|
serendipity_db_query($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
function recycleComment($id, $entry_id) {
|
|
|
|
global $serendipity;
|
|
|
|
$sql = "INSERT INTO
|
|
|
|
{$serendipity['dbPrefix']}spamblock_bayes_recycler (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)
|
|
|
|
SELECT
|
|
|
|
entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer
|
|
|
|
FROM
|
|
|
|
{$serendipity['dbPrefix']}comments
|
|
|
|
WHERE
|
|
|
|
id = '$id' AND entry_id = '$entry_id';";
|
|
|
|
serendipity_db_query($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function restoreComments($ids) {
|
|
|
|
global $serendipity;
|
|
|
|
|
|
|
|
if (is_array($ids)) {
|
|
|
|
$sql = "INSERT INTO
|
|
|
|
{$serendipity['dbPrefix']}comments
|
|
|
|
(entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)
|
|
|
|
SELECT
|
|
|
|
entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer
|
|
|
|
FROM
|
|
|
|
{$serendipity['dbPrefix']}spamblock_bayes_recycler
|
|
|
|
WHERE " . serendipity_db_in_sql ( 'id', $ids );
|
|
|
|
} else {
|
|
|
|
$sql = "INSERT INTO
|
|
|
|
{$serendipity['dbPrefix']}comments
|
|
|
|
(entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)
|
|
|
|
SELECT
|
|
|
|
entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer
|
|
|
|
FROM
|
|
|
|
{$serendipity['dbPrefix']}spamblock_bayes_recycler
|
|
|
|
WHERE id = " . (int)$ids;
|
|
|
|
}
|
2015-12-11 23:53:33 +01:00
|
|
|
$result = serendipity_db_query($sql);
|
2013-07-25 11:21:54 +02:00
|
|
|
$this->deleteFromRecycler($ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteFromRecycler($ids) {
|
|
|
|
global $serendipity;
|
|
|
|
if (is_array($ids)) {
|
|
|
|
$sql = "DELETE FROM
|
|
|
|
{$serendipity['dbPrefix']}spamblock_bayes_recycler
|
|
|
|
WHERE " . serendipity_db_in_sql ( 'id', $ids );
|
|
|
|
} else {
|
|
|
|
$sql = "DELETE FROM
|
|
|
|
{$serendipity['dbPrefix']}spamblock_bayes_recycler
|
|
|
|
WHERE id = " . (int)$ids;
|
|
|
|
}
|
|
|
|
return serendipity_db_query($sql);
|
|
|
|
}
|
|
|
|
|
2020-08-09 11:10:41 +02:00
|
|
|
function getEntryTitle($id) {
|
2013-07-25 11:21:54 +02:00
|
|
|
global $serendipity;
|
2020-08-09 11:10:41 +02:00
|
|
|
$sql = "SELECT title FROM {$serendipity['dbPrefix']}entries WHERE id = '$id'";
|
|
|
|
$title = serendipity_db_query($sql, true, "assoc");
|
|
|
|
$title = $title['title'];
|
|
|
|
return $title;
|
2013-07-25 11:21:54 +02:00
|
|
|
}
|
|
|
|
|
2018-03-24 22:16:51 +01:00
|
|
|
}
|