2023-01-07 22:28:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @brief whiteListCom, a plugin for Dotclear 2
|
|
|
|
*
|
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis and Contributors
|
|
|
|
*
|
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-01-07 22:52:09 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\whiteListCom;
|
|
|
|
|
|
|
|
/* dotclear ns */
|
|
|
|
use dcCore;
|
2023-01-07 23:42:34 +00:00
|
|
|
use dcPage;
|
2023-01-07 22:52:09 +00:00
|
|
|
use dcSpamFilter;
|
|
|
|
|
|
|
|
/* clearbricks ns */
|
|
|
|
use form;
|
|
|
|
use html;
|
2023-01-07 23:42:34 +00:00
|
|
|
use http;
|
2023-01-07 22:52:09 +00:00
|
|
|
|
|
|
|
/* php ns */
|
|
|
|
use Exception;
|
2023-01-07 22:28:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup DC_PLUGIN_WHITELISTCOM
|
|
|
|
* @brief Filter for unmoderated authors.
|
|
|
|
* @since 2.6
|
|
|
|
*
|
|
|
|
* This filter is used only if comments are moderates
|
|
|
|
*/
|
2023-01-07 22:52:09 +00:00
|
|
|
class UnmoderatedWhiteList extends dcSpamFilter
|
2023-01-07 22:28:40 +00:00
|
|
|
{
|
|
|
|
public $name = 'Unmoderated authors';
|
|
|
|
public $has_gui = true;
|
|
|
|
|
|
|
|
protected function setInfo()
|
|
|
|
{
|
|
|
|
$this->name = __('Unmoderated authors');
|
|
|
|
$this->description = __('Whitelist of unmoderated authors');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
|
|
|
|
{
|
|
|
|
if ($type != 'comment'
|
|
|
|
|| dcCore::app()->blog === null
|
|
|
|
|| dcCore::app()->blog->settings->system->comments_pub) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-01-07 22:52:09 +00:00
|
|
|
$wlc = new Core();
|
2023-01-07 22:28:40 +00:00
|
|
|
if ($wlc->isUnmoderated($email)) {
|
|
|
|
$status = 'unmoderated';
|
|
|
|
|
|
|
|
# return true in order to change comment_status after
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function gui(string $url): string
|
|
|
|
{
|
2023-01-07 22:52:09 +00:00
|
|
|
$wlc = new Core();
|
2023-01-07 22:28:40 +00:00
|
|
|
$posts = $comments = [];
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!empty($_POST['update_unmoderated'])) {
|
|
|
|
$wlc->emptyUnmoderated();
|
|
|
|
foreach ($_POST['unmoderated'] as $email) {
|
|
|
|
$wlc->addUnmoderated($email);
|
|
|
|
}
|
|
|
|
$wlc->commit();
|
2023-01-07 23:42:34 +00:00
|
|
|
dcPage::addSuccessNotice(__('Unmoderated names have been successfully updated.'));
|
|
|
|
http::redirect($url);
|
2023-01-07 22:28:40 +00:00
|
|
|
}
|
|
|
|
$posts = $wlc->getPostsUsers();
|
|
|
|
$comments = $wlc->getCommentsUsers();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
$res = '';
|
|
|
|
|
|
|
|
if (dcCore::app()->blog->settings->system->comments_pub) {
|
|
|
|
$res .= '<p class="message">' .
|
|
|
|
__('This filter is used only if comments are moderates') .
|
|
|
|
'</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$res .= '<form action="' . html::escapeURL($url) . '" method="post">' .
|
|
|
|
'<p>' . __('Check the users who can make comments without being moderated.') . '</p>' .
|
|
|
|
'<div class="two-cols">' .
|
|
|
|
'<div class="col">' .
|
|
|
|
'<p>' . __('Posts authors list') . '</p>' .
|
|
|
|
'<table class="clear">' .
|
|
|
|
'<thead><tr><th>' . __('Name') . '</th><th>' . __('Email') . '</th></tr></thead>' .
|
|
|
|
'<tbody>';
|
|
|
|
|
|
|
|
foreach ($posts as $user) {
|
|
|
|
$res .= '<tr class="line">' .
|
|
|
|
'<td class="nowrap">' .
|
|
|
|
form::checkbox(
|
|
|
|
['unmoderated[]'],
|
|
|
|
$user['email'],
|
|
|
|
$wlc->isUnmoderated($user['email'])
|
|
|
|
) .
|
|
|
|
' ' . $user['name'] . '</td>' .
|
|
|
|
'<td class="nowrap">' . $user['email'] . '</td>' .
|
|
|
|
'</tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$res .= '</tbody>' .
|
|
|
|
'</table>' .
|
|
|
|
'</div>' .
|
|
|
|
'<div class="col">' .
|
|
|
|
'<p>' . __('Comments authors list') . '</p>' .
|
|
|
|
'<table class="clear">' .
|
|
|
|
'<thead><tr><th>' . __('Author') . '</th><th>' . __('Email') . '</th></tr></thead>' .
|
|
|
|
'<tbody>';
|
|
|
|
|
|
|
|
foreach ($comments as $user) {
|
|
|
|
$res .= '<tr class="line">' .
|
|
|
|
'<td class="nowrap">' .
|
|
|
|
form::checkbox(
|
|
|
|
['unmoderated[]'],
|
|
|
|
$user['email'],
|
|
|
|
$wlc->isUnmoderated($user['email'])
|
|
|
|
) .
|
|
|
|
' ' . $user['name'] . '</td>' .
|
|
|
|
'<td class="nowrap">' . $user['email'] . '</td>' .
|
|
|
|
'</tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$res .= '</tbody>' .
|
|
|
|
'</table>' .
|
|
|
|
'</div>' .
|
|
|
|
'</div>' .
|
2023-01-07 23:37:34 +00:00
|
|
|
'<p><input type="submit" id="update_unmoderated" name="update_unmoderated" value="' . __('Save') . '" />' .
|
2023-01-07 22:28:40 +00:00
|
|
|
dcCore::app()->formNonce() . '</p>' .
|
|
|
|
'</form>';
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
}
|