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:37: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:37: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 reserved names.
|
|
|
|
* @since 2.6
|
|
|
|
*/
|
2023-01-07 23:37:34 +00:00
|
|
|
class ReservedWhiteList extends dcSpamFilter
|
2023-01-07 22:28:40 +00:00
|
|
|
{
|
|
|
|
public $name = 'Reserved names';
|
|
|
|
public $has_gui = true;
|
|
|
|
|
|
|
|
protected function setInfo()
|
|
|
|
{
|
|
|
|
$this->name = __('Reserved names');
|
|
|
|
$this->description = __('Whitelist of reserved names of users');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
|
|
|
|
{
|
|
|
|
if ($type != 'comment') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$throw = false;
|
|
|
|
|
|
|
|
try {
|
2023-01-07 22:52:09 +00:00
|
|
|
$wlc = new Core();
|
2023-01-07 22:28:40 +00:00
|
|
|
|
|
|
|
if (true === $wlc->isReserved($author, $email)) {
|
|
|
|
$status = 'reserved name';
|
|
|
|
//return true;
|
|
|
|
$throw = true;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
# This message is show to author even if comments are moderated, comment is not saved
|
|
|
|
if ($throw) {
|
|
|
|
throw new Exception(__('This name is reserved to an other user.'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStatusMessage($status, $comment_id)
|
|
|
|
{
|
|
|
|
return __('This name is reserved to an other user.');
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
$comments = [];
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!empty($_POST['update_reserved'])) {
|
|
|
|
$wlc->emptyReserved();
|
2023-01-07 23:37:34 +00:00
|
|
|
foreach ($_POST['reserved'] as $i => $name) {
|
|
|
|
$wlc->addReserved($name, $_POST['reserved_email'][$i]);
|
2023-01-07 22:28:40 +00:00
|
|
|
}
|
|
|
|
$wlc->commit();
|
2023-01-07 23:42:34 +00:00
|
|
|
dcPage::addSuccessNotice(__('Reserved names have been successfully updated.'));
|
2023-01-07 23:37:34 +00:00
|
|
|
http::redirect($url);
|
2023-01-07 22:28:40 +00:00
|
|
|
}
|
2023-01-07 23:37:34 +00:00
|
|
|
|
2023-01-07 22:28:40 +00:00
|
|
|
$comments = $wlc->getCommentsUsers();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
$res = '<form action="' . html::escapeURL($url) . '" method="post">' .
|
|
|
|
'<p>' . __('Check the users who can make comments without being moderated.') . '</p>' .
|
|
|
|
'<p>' . __('Comments authors list') . '</p>' .
|
|
|
|
'<table class="clear">' .
|
|
|
|
'<thead><tr><th>' . __('Author') . '</th><th>' . __('Email') . '</th></tr></thead>' .
|
|
|
|
'<tbody>';
|
|
|
|
|
2023-01-07 23:37:34 +00:00
|
|
|
$i = 0;
|
2023-01-07 22:28:40 +00:00
|
|
|
foreach ($comments as $user) {
|
|
|
|
$res .= '<tr class="line">' .
|
|
|
|
'<td class="nowrap">' .
|
|
|
|
form::checkbox(
|
2023-01-07 23:37:34 +00:00
|
|
|
['reserved[' . $i . ']'],
|
2023-01-07 22:28:40 +00:00
|
|
|
$user['name'],
|
|
|
|
(null === $wlc->isReserved($user['name'], $user['email']))
|
|
|
|
) .
|
2023-01-07 23:37:34 +00:00
|
|
|
form::hidden(['reserved_email[' . $i . ']'], $user['email']) .
|
2023-01-07 22:28:40 +00:00
|
|
|
' ' . $user['name'] . '</td>' .
|
|
|
|
'<td class="nowrap">' . $user['email'] . '</td>' .
|
|
|
|
'</tr>';
|
2023-01-07 23:37:34 +00:00
|
|
|
$i++;
|
2023-01-07 22:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$res .= '</tbody>' .
|
|
|
|
'</table>' .
|
|
|
|
'<p><input type="submit" name="update_reserved" value="' . __('Save') . '" />' .
|
|
|
|
dcCore::app()->formNonce() . '</p>' .
|
|
|
|
'</form>';
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
}
|