Compare commits
10 Commits
7ff7b24f36
...
3327505500
Author | SHA1 | Date |
---|---|---|
Jean-Christian Paul Denis | 3327505500 | |
Jean-Christian Paul Denis | afe38af912 | |
Jean-Christian Paul Denis | 7057ffb7b9 | |
Jean-Christian Paul Denis | 21796045c7 | |
Jean-Christian Paul Denis | 7060e07b2c | |
Jean-Christian Paul Denis | d002399028 | |
Jean-Christian Paul Denis | 475e480bf5 | |
Jean-Christian Paul Denis | a365f601da | |
Jean-Christian Paul Denis | 3f42099051 | |
Jean-Christian Paul Denis | 6fbd4b4866 |
21
CHANGELOG.md
21
CHANGELOG.md
|
@ -1,3 +1,24 @@
|
|||
1.2 - 2023.08.03
|
||||
- require Dotclear 2.27
|
||||
- require PHP 7.4+
|
||||
- upgrade to Dotclear 2.27
|
||||
- move repository to gitea (testing)
|
||||
|
||||
1.2.1 - 2023.05.13
|
||||
- require dotclear 2.26
|
||||
- cleanup for dotclear 2.26 stable
|
||||
|
||||
1.2 - 2023.04.24
|
||||
- require dotclear 2.26
|
||||
- use latest dotclear namespace
|
||||
- use sql statement
|
||||
- use static methods for filters
|
||||
- fix comments without email
|
||||
- fix list display
|
||||
- fix nullsafe warnings
|
||||
- add dependencies to plugin antispam
|
||||
- add plugin Uninstaller features
|
||||
|
||||
1.1 - 2023.03.11
|
||||
- code review for Dotclear 2.25
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[![Release](https://img.shields.io/github/v/release/JcDenis/whiteListCom)](https://github.com/JcDenis/whiteListCom/releases)
|
||||
[![Date](https://img.shields.io/github/release-date/JcDenis/whiteListCom)](https://github.com/JcDenis/whiteListCom/releases)
|
||||
[![Issues](https://img.shields.io/github/issues/JcDenis/whiteListCom)](https://github.com/JcDenis/whiteListCom/issues)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.25-blue.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/whiteListCom)
|
||||
[![License](https://img.shields.io/github/license/JcDenis/whiteListCom)](https://github.com/JcDenis/whiteListCom/blob/master/LICENSE)
|
||||
|
||||
|
@ -20,7 +20,7 @@ and a list of reserved names (pair of nickname / email ).
|
|||
_whiteListCom_ requires:
|
||||
|
||||
* permissions to manage antispam
|
||||
* Dotclear 2.25
|
||||
* Dotclear 2.27
|
||||
|
||||
## USAGE
|
||||
|
||||
|
@ -34,8 +34,8 @@ Note: User must write a comment before able to be added to the list.
|
|||
## LINKS
|
||||
|
||||
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
|
||||
* Source & contribution : [GitHub Page](https://github.com/JcDenis/whiteListCom)
|
||||
* Packages & details : [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/whiteListCom)
|
||||
* Source & contribution : [Gitea Page](http://gitea.jcdenis.fr/Dotclear/whiteListCom) or [GitHub Page](https://github.com/JcDenis/whiteListCom)
|
||||
* Packages & details : [Gitea Page](http://gitea.jcdenis.fr/Dotclear/whiteListCom/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/whiteListCom)
|
||||
|
||||
## CONTRIBUTORS
|
||||
|
||||
|
|
17
_define.php
17
_define.php
|
@ -18,17 +18,20 @@ $this->registerModule(
|
|||
'Whitelist comments',
|
||||
'Whitelists for comments moderation',
|
||||
'Jean-Christian Denis and Contributors',
|
||||
'1.1',
|
||||
'1.3',
|
||||
[
|
||||
'requires' => [['core', '2.25']],
|
||||
'requires' => [
|
||||
['core', '2.27'],
|
||||
['antispam', '2.0'],
|
||||
],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcAuth::PERMISSION_USAGE,
|
||||
dcAuth::PERMISSION_CONTENT_ADMIN,
|
||||
dcCore::app()->auth::PERMISSION_USAGE,
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
||||
]),
|
||||
'priority' => 200,
|
||||
'type' => 'plugin',
|
||||
'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
|
||||
'details' => 'https://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
|
||||
'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
|
||||
'support' => 'http://gitea.jcdenis.fr/Dotclear/whiteListCom',
|
||||
'details' => 'http://gitea.jcdenis.fr/Dotclear/whiteListCom/src/branch/master/README.md',
|
||||
'repository' => 'http://gitea.jcdenis.fr/Dotclear/whiteListCom/raw/branch/master/dcstore.xml',
|
||||
]
|
||||
);
|
||||
|
|
10
dcstore.xml
10
dcstore.xml
|
@ -2,12 +2,12 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="whiteListCom">
|
||||
<name>Whitelist comments</name>
|
||||
<version>1.1</version>
|
||||
<version>1.3</version>
|
||||
<author>Jean-Christian Denis and Contributors</author>
|
||||
<desc>Whitelists for comments moderation</desc>
|
||||
<file>https://github.com/JcDenis/whiteListCom/releases/download/v1.1/plugin-whiteListCom.zip</file>
|
||||
<da:dcmin>2.25</da:dcmin>
|
||||
<da:details>https://plugins.dotaddict.org/dc2/details/whiteListCom</da:details>
|
||||
<da:support>https://github.com/JcDenis/whiteListCom</da:support>
|
||||
<file>https://gitea.jcdenis.fr/Dotclear/whiteListCom/releases/download/v1.3/plugin-whiteListCom.zip</file>
|
||||
<da:dcmin>2.27</da:dcmin>
|
||||
<da:details>http://gitea.jcdenis.fr/Dotclear/whiteListCom/src/branch/master/README.md</da:details>
|
||||
<da:support>http://gitea.jcdenis.fr/Dotclear/whiteListCom</da:support>
|
||||
</module>
|
||||
</modules>
|
||||
|
|
|
@ -9,16 +9,18 @@
|
|||
# DOT NOT MODIFY THIS FILE !
|
||||
#
|
||||
|
||||
l10n::$locales['Reserved names'] = 'Noms réservés';
|
||||
l10n::$locales['Whitelist of reserved names of users'] = 'Liste blanche des noms d\'utilisateurs réservés';
|
||||
l10n::$locales['This name is reserved to an other user.'] = 'Ce nom est réservé à un autre utilisateur.';
|
||||
l10n::$locales['Reserved names have been successfully updated.'] = 'Le noms réservés ont été mis à jour.';
|
||||
l10n::$locales['Check the users who can make comments without being moderated.'] = 'Cocher les utilisateurs qui peuvent faire des commentaires sans être modérés.';
|
||||
l10n::$locales['Comments authors list'] = 'Liste des auteurs de commentaires';
|
||||
l10n::$locales['Unmoderated authors'] = 'Auteurs non modérés';
|
||||
l10n::$locales['Whitelist of unmoderated authors'] = 'Liste blanche des auteurs non modérés';
|
||||
l10n::$locales['Unmoderated names have been successfully updated.'] = 'Les noms non modérés ont été mis à jour.';
|
||||
l10n::$locales['This filter is used only if comments are moderates'] = 'Ce filtre est utilisé seulement si les commentaires sont modérés.';
|
||||
l10n::$locales['Posts authors list'] = 'Liste des auteurs de billets';
|
||||
l10n::$locales['Whitelists for comments moderation'] = 'Listes blanches pour la modération de commentaires';
|
||||
l10n::$locales['Whitelist comments'] = 'Liste blanche des commentaires';
|
||||
use Dotclear\Helper\L10n;
|
||||
|
||||
L10n::$locales['Reserved names'] = 'Noms réservés';
|
||||
L10n::$locales['Whitelist of reserved names of users'] = 'Liste blanche des noms d\'utilisateurs réservés';
|
||||
L10n::$locales['This name is reserved to an other user.'] = 'Ce nom est réservé à un autre utilisateur.';
|
||||
L10n::$locales['Reserved names have been successfully updated.'] = 'Le noms réservés ont été mis à jour.';
|
||||
L10n::$locales['Check the users who can make comments without being moderated.'] = 'Cocher les utilisateurs qui peuvent faire des commentaires sans être modérés.';
|
||||
L10n::$locales['Comments authors list'] = 'Liste des auteurs de commentaires';
|
||||
L10n::$locales['Unmoderated authors'] = 'Auteurs non modérés';
|
||||
L10n::$locales['Whitelist of unmoderated authors'] = 'Liste blanche des auteurs non modérés';
|
||||
L10n::$locales['Unmoderated names have been successfully updated.'] = 'Les noms non modérés ont été mis à jour.';
|
||||
L10n::$locales['This filter is used only if comments are moderates'] = 'Ce filtre est utilisé seulement si les commentaires sont modérés.';
|
||||
L10n::$locales['Posts authors list'] = 'Liste des auteurs de billets';
|
||||
L10n::$locales['Whitelists for comments moderation'] = 'Listes blanches pour la modération de commentaires';
|
||||
L10n::$locales['Whitelist comments'] = 'Liste blanche des commentaires';
|
||||
|
|
173
src/Core.php
173
src/Core.php
|
@ -1,173 +0,0 @@
|
|||
<?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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\whiteListCom;
|
||||
|
||||
/* dotclear ns */
|
||||
use dcBlog;
|
||||
use dcCore;
|
||||
use dcUtils;
|
||||
|
||||
/**
|
||||
* @ingroup DC_PLUGIN_WHITELISTCOM
|
||||
* @brief White list filters methods
|
||||
* @since 2.6
|
||||
*/
|
||||
class Core
|
||||
{
|
||||
public $con;
|
||||
public $blog;
|
||||
public $settings;
|
||||
|
||||
private $unmoderated = [];
|
||||
private $reserved = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->con = dcCore::app()->con;
|
||||
$this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
|
||||
$this->settings = dcCore::app()->blog->settings->get(My::id());
|
||||
$this->unmoderated = self::decode($this->settings->get('unmoderated'));
|
||||
$this->reserved = self::decode($this->settings->get('reserved'));
|
||||
}
|
||||
|
||||
public function commit(): void
|
||||
{
|
||||
$this->settings->put(
|
||||
'unmoderated',
|
||||
self::encode($this->unmoderated),
|
||||
'string',
|
||||
'Whitelist of unmoderated users on comments',
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
$this->settings->put(
|
||||
'reserved',
|
||||
self::encode($this->reserved),
|
||||
'string',
|
||||
'Whitelist of reserved names on comments',
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
# Return
|
||||
# true if it is a reserved name with wrong email
|
||||
# false if it is not a reserved name
|
||||
# null if it is a reserved name with right email
|
||||
public function isReserved($author, $email): ?bool
|
||||
{
|
||||
if (!isset($this->reserved[$author])) {
|
||||
return false;
|
||||
} elseif ($this->reserved[$author] != $email) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
# You must do a commit to save this change
|
||||
public function addReserved($author, $email): bool
|
||||
{
|
||||
$this->reserved[$author] = $email;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
# You must do a commit to save this change
|
||||
public function emptyReserved(): void
|
||||
{
|
||||
$this->reserved = [];
|
||||
}
|
||||
|
||||
# Return
|
||||
# true if it is known as an unmoderated email else false
|
||||
public function isUnmoderated($email): bool
|
||||
{
|
||||
return in_array($email, $this->unmoderated);
|
||||
}
|
||||
|
||||
# You must do a commit to save this change
|
||||
public function addUnmoderated($email): ?bool
|
||||
{
|
||||
if (!in_array($email, $this->unmoderated)) {
|
||||
$this->unmoderated[] = $email;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
# You must do a commit to save this change
|
||||
public function emptyUnmoderated(): void
|
||||
{
|
||||
$this->unmoderated = [];
|
||||
}
|
||||
|
||||
public function getPostsUsers(): array
|
||||
{
|
||||
$users = [];
|
||||
$rs = dcCore::app()->blog->getPostsUsers();
|
||||
while ($rs->fetch()) {
|
||||
$name = dcUtils::getUserCN(
|
||||
$rs->f('user_id'),
|
||||
$rs->f('user_name'),
|
||||
$rs->f('user_firstname'),
|
||||
$rs->f('user_displayname')
|
||||
);
|
||||
$users[] = [
|
||||
'name' => $name,
|
||||
'email' => $rs->f('user_email'),
|
||||
];
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
public function getCommentsUsers(): array
|
||||
{
|
||||
$users = [];
|
||||
$rs = $this->con->select(
|
||||
'SELECT comment_author, comment_email ' .
|
||||
'FROM ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' C ' .
|
||||
'LEFT JOIN ' . dcCore::app()->prefix . 'post P ON C.post_id=P.post_id ' .
|
||||
"WHERE blog_id='" . $this->blog . "' AND comment_trackback=0 " .
|
||||
'GROUP BY comment_email, comment_author ' // Added author to fix postgreSql
|
||||
);
|
||||
while ($rs->fetch()) {
|
||||
$users[] = [
|
||||
'name' => $rs->f('comment_author'),
|
||||
'email' => $rs->f('comment_email'),
|
||||
];
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
public static function encode($x): string
|
||||
{
|
||||
$y = is_array($x) ? $x : [];
|
||||
|
||||
return json_encode($y);
|
||||
}
|
||||
|
||||
public static function decode($x): array
|
||||
{
|
||||
$y = json_decode($x, true);
|
||||
|
||||
return is_array($y) ? $y : [];
|
||||
}
|
||||
}
|
|
@ -14,18 +14,15 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\whiteListCom;
|
||||
|
||||
/* dotclear ns */
|
||||
use dcCore;
|
||||
use dcNamespace;
|
||||
use dcNsProcess;
|
||||
|
||||
/* php ns */
|
||||
use Dotclear\Core\Process;
|
||||
use Exception;
|
||||
|
||||
class Install extends dcNsProcess
|
||||
class Install extends Process
|
||||
{
|
||||
// Module specs
|
||||
private static $mod_conf = [
|
||||
private static array $mod_conf = [
|
||||
[
|
||||
'unmoderated',
|
||||
'[]',
|
||||
|
@ -42,14 +39,12 @@ class Install extends dcNsProcess
|
|||
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::INSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!sestaticlf::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -59,7 +54,7 @@ class Install extends dcNsProcess
|
|||
|
||||
// Set module settings
|
||||
foreach (self::$mod_conf as $v) {
|
||||
dcCore::app()->blog->settings->get(My::id())->put(
|
||||
My::settings()->put(
|
||||
$v[0],
|
||||
$v[1],
|
||||
$v[2],
|
||||
|
@ -89,15 +84,15 @@ class Install extends dcNsProcess
|
|||
);
|
||||
|
||||
while ($record->fetch()) {
|
||||
if (preg_match('/^whiteListCom(.*?)$/', $record->setting_id, $match)) {
|
||||
$value = @unserialize(@base64_decode($record->setting_value));
|
||||
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
||||
$cur->setting_id = $match[1];
|
||||
$cur->setting_ns = My::id();
|
||||
$cur->setting_value = is_array($value) ? json_encode($value) : '[]';
|
||||
if (preg_match('/^whiteListCom(.*?)$/', $record->f('setting_id'), $match)) {
|
||||
$value = @unserialize(@base64_decode($record->f('setting_value')));
|
||||
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
||||
$cur->setField('setting_id', $match[1]);
|
||||
$cur->setField('setting_ns', My::id());
|
||||
$cur->setField('setting_value', is_array($value) ? json_encode($value) : '[]');
|
||||
$cur->update(
|
||||
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'whiteListCom' " .
|
||||
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
|
||||
"WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = 'whiteListCom' " .
|
||||
'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escapeStr((string) $record->f('blog_id')) . "' "))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
21
src/My.php
21
src/My.php
|
@ -14,26 +14,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\whiteListCom;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* Plugin definitions
|
||||
* This module definitions.
|
||||
*/
|
||||
class My
|
||||
class My extends MyPlugin
|
||||
{
|
||||
/**
|
||||
* This module id
|
||||
*/
|
||||
public static function id(): string
|
||||
{
|
||||
return basename(dirname(__DIR__));
|
||||
}
|
||||
|
||||
/**
|
||||
* This module name
|
||||
*/
|
||||
public static function name(): string
|
||||
{
|
||||
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,20 +16,18 @@ namespace Dotclear\Plugin\whiteListCom;
|
|||
|
||||
use dcBlog;
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
class Prepend extends dcNsProcess
|
||||
class Prepend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = true;
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::PREPEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,14 +15,14 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\whiteListCom;
|
||||
|
||||
use dcCore;
|
||||
use dcPage;
|
||||
use dcSpamFilter;
|
||||
use Dotclear\Core\Backend\Notices;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Checkbox,
|
||||
Hidden
|
||||
};
|
||||
use Dotclear\Helper\Html\Html;
|
||||
use Dotclear\Helper\Network\Http;
|
||||
use Dotclear\Plugin\antispam\SpamFilter;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
|
@ -30,17 +30,23 @@ use Exception;
|
|||
* @brief Filter for reserved names.
|
||||
* @since 2.6
|
||||
*/
|
||||
class ReservedWhiteList extends dcSpamFilter
|
||||
class ReservedWhiteList extends SpamFilter
|
||||
{
|
||||
public $name = 'Reserved names';
|
||||
public $has_gui = true;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function setInfo()
|
||||
{
|
||||
$this->name = __('Reserved names');
|
||||
$this->description = __('Whitelist of reserved names of users');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void|null|bool
|
||||
*/
|
||||
public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
|
||||
{
|
||||
if ($type != 'comment') {
|
||||
|
@ -50,9 +56,7 @@ class ReservedWhiteList extends dcSpamFilter
|
|||
$throw = false;
|
||||
|
||||
try {
|
||||
$wlc = new Core();
|
||||
|
||||
if (true === $wlc->isReserved($author, $email)) {
|
||||
if (true === Utils::isReserved($author, $email)) {
|
||||
$status = 'reserved name';
|
||||
//return true;
|
||||
$throw = true;
|
||||
|
@ -68,6 +72,9 @@ class ReservedWhiteList extends dcSpamFilter
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatusMessage($status, $comment_id)
|
||||
{
|
||||
return __('This name is reserved to an other user.');
|
||||
|
@ -75,40 +82,41 @@ class ReservedWhiteList extends dcSpamFilter
|
|||
|
||||
public function gui(string $url): string
|
||||
{
|
||||
$wlc = new Core();
|
||||
$comments = [];
|
||||
|
||||
try {
|
||||
if (!empty($_POST['update_reserved'])) {
|
||||
$wlc->emptyReserved();
|
||||
Utils::emptyReserved();
|
||||
foreach ($_POST['reserved'] as $i => $name) {
|
||||
$wlc->addReserved($name, $_POST['reserved_email'][$i]);
|
||||
Utils::addReserved($name, $_POST['reserved_email'][$i]);
|
||||
}
|
||||
$wlc->commit();
|
||||
dcPage::addSuccessNotice(__('Reserved names have been successfully updated.'));
|
||||
Utils::commit();
|
||||
Notices::addSuccessNotice(__('Reserved names have been successfully updated.'));
|
||||
Http::redirect($url);
|
||||
}
|
||||
|
||||
$comments = $wlc->getCommentsUsers();
|
||||
$comments = Utils::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>' .
|
||||
'<div class="table-outer">' .
|
||||
'<table class="clear">' .
|
||||
'<caption>' . __('Comments authors list') . '</caption>' .
|
||||
'<thead><tr><th>' . __('Author') . '</th><th>' . __('Email') . '</th></tr></thead>' .
|
||||
'<tbody>';
|
||||
|
||||
$i = 0;
|
||||
foreach ($comments as $user) {
|
||||
$res .= '<tr class="line">' .
|
||||
$checked = null === Utils::isReserved($user['name'], $user['email']);
|
||||
$res .= '<tr class="line' . ($checked ? '' : ' offline') . '">' .
|
||||
'<td class="nowrap">' .
|
||||
(new Checkbox(['reserved[' . $i . ']'], (null === $wlc->isReserved($user['name'], $user['email']))))->value($user['name'])->render() .
|
||||
(new Checkbox(['reserved[' . $i . ']'], $checked))->value($user['name'])->render() .
|
||||
(new Hidden(['reserved_email[' . $i . ']'], $user['email']))->render() .
|
||||
' ' . $user['name'] . '</td>' .
|
||||
'<td class="nowrap">' . $user['email'] . '</td>' .
|
||||
'<td class="nowrap maximal">' . $user['email'] . '</td>' .
|
||||
'</tr>';
|
||||
$i++;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<?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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\whiteListCom;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Plugin\Uninstaller\Uninstaller;
|
||||
|
||||
class Uninstall extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
return self::status(My::checkContext(My::UNINSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Uninstaller::instance()
|
||||
->addUserAction(
|
||||
'settings',
|
||||
'delete_all',
|
||||
My::id()
|
||||
)
|
||||
->addUserAction(
|
||||
'plugins',
|
||||
'delete',
|
||||
My::id()
|
||||
)
|
||||
->addUserAction(
|
||||
'versions',
|
||||
'delete',
|
||||
My::id()
|
||||
)
|
||||
->addDirectAction(
|
||||
'settings',
|
||||
'delete_all',
|
||||
My::id()
|
||||
)
|
||||
->addDirectAction(
|
||||
'plugins',
|
||||
'delete',
|
||||
My::id()
|
||||
)
|
||||
->addDirectAction(
|
||||
'versions',
|
||||
'delete',
|
||||
My::id()
|
||||
)
|
||||
;
|
||||
|
||||
// no custom action
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -15,11 +15,11 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\whiteListCom;
|
||||
|
||||
use dcCore;
|
||||
use dcPage;
|
||||
use dcSpamFilter;
|
||||
use Dotclear\COre\Backend\Notices;
|
||||
use Dotclear\Helper\Html\Form\Checkbox;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
use Dotclear\Helper\Network\Http;
|
||||
use Dotclear\Plugin\antispam\SpamFilter;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
|
@ -29,17 +29,23 @@ use Exception;
|
|||
*
|
||||
* This filter is used only if comments are moderates
|
||||
*/
|
||||
class UnmoderatedWhiteList extends dcSpamFilter
|
||||
class UnmoderatedWhiteList extends SpamFilter
|
||||
{
|
||||
public $name = 'Unmoderated authors';
|
||||
public $has_gui = true;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function setInfo()
|
||||
{
|
||||
$this->name = __('Unmoderated authors');
|
||||
$this->description = __('Whitelist of unmoderated authors');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void|null|bool
|
||||
*/
|
||||
public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
|
||||
{
|
||||
if ($type != 'comment'
|
||||
|
@ -49,8 +55,7 @@ class UnmoderatedWhiteList extends dcSpamFilter
|
|||
}
|
||||
|
||||
try {
|
||||
$wlc = new Core();
|
||||
if ($wlc->isUnmoderated($email)) {
|
||||
if (Utils::isUnmoderated($email)) {
|
||||
$status = 'unmoderated';
|
||||
|
||||
# return true in order to change comment_status after
|
||||
|
@ -64,28 +69,28 @@ class UnmoderatedWhiteList extends dcSpamFilter
|
|||
|
||||
public function gui(string $url): string
|
||||
{
|
||||
$wlc = new Core();
|
||||
$wlc = new Utils();
|
||||
$posts = $comments = [];
|
||||
|
||||
try {
|
||||
if (!empty($_POST['update_unmoderated'])) {
|
||||
$wlc->emptyUnmoderated();
|
||||
Utils::emptyUnmoderated();
|
||||
foreach ($_POST['unmoderated'] as $email) {
|
||||
$wlc->addUnmoderated($email);
|
||||
Utils::addUnmoderated($email);
|
||||
}
|
||||
$wlc->commit();
|
||||
dcPage::addSuccessNotice(__('Unmoderated names have been successfully updated.'));
|
||||
Utils::commit();
|
||||
Notices::addSuccessNotice(__('Unmoderated names have been successfully updated.'));
|
||||
Http::redirect($url);
|
||||
}
|
||||
$posts = $wlc->getPostsUsers();
|
||||
$comments = $wlc->getCommentsUsers();
|
||||
$posts = Utils::getPostsUsers();
|
||||
$comments = Utils::getCommentsUsers();
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
|
||||
$res = '';
|
||||
|
||||
if (dcCore::app()->blog->settings->get('system')->get('comments_pub')) {
|
||||
if (!is_null(dcCore::app()->blog) && dcCore::app()->blog->settings->get('system')->get('comments_pub')) {
|
||||
$res .= '<p class="message">' .
|
||||
__('This filter is used only if comments are moderates') .
|
||||
'</p>';
|
||||
|
@ -93,42 +98,46 @@ class UnmoderatedWhiteList extends dcSpamFilter
|
|||
|
||||
$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>' .
|
||||
'<div class="two-boxes">' .
|
||||
'<div class="box odd">' .
|
||||
'<div class="table-outer">' .
|
||||
'<table class="clear">' .
|
||||
'<caption>' . __('Posts authors list') . '</caption>' .
|
||||
'<thead><tr><th>' . __('Name') . '</th><th>' . __('Email') . '</th></tr></thead>' .
|
||||
'<tbody>';
|
||||
|
||||
foreach ($posts as $user) {
|
||||
$res .= '<tr class="line">' .
|
||||
$checked = Utils::isUnmoderated($user['email']);
|
||||
$res .= '<tr class="line' . ($checked ? '' : ' offline') . '">' .
|
||||
'<td class="nowrap">' .
|
||||
(new Checkbox(['unmoderated[]'], $wlc->isUnmoderated($user['email'])))->value($user['email'])->render() .
|
||||
(new Checkbox(['unmoderated[]'], $checked))->value($user['email'])->render() .
|
||||
' ' . $user['name'] . '</td>' .
|
||||
'<td class="nowrap">' . $user['email'] . '</td>' .
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
$res .= '</tbody>' .
|
||||
'</table>' .
|
||||
'</table></div>' .
|
||||
'</div>' .
|
||||
'<div class="col">' .
|
||||
'<p>' . __('Comments authors list') . '</p>' .
|
||||
'<div class="box even">' .
|
||||
'<div class="table-outer">' .
|
||||
'<table class="clear">' .
|
||||
'<caption>' . __('Comments authors list') . '</caption>' .
|
||||
'<thead><tr><th>' . __('Author') . '</th><th>' . __('Email') . '</th></tr></thead>' .
|
||||
'<tbody>';
|
||||
|
||||
foreach ($comments as $user) {
|
||||
$res .= '<tr class="line">' .
|
||||
$checked = Utils::isUnmoderated($user['email']);
|
||||
$res .= '<tr class="line' . ($checked ? '' : ' offline') . '">' .
|
||||
'<td class="nowrap">' .
|
||||
(new Checkbox(['unmoderated[]'], $wlc->isUnmoderated($user['email'])))->value($user['email'])->render() .
|
||||
(new Checkbox(['unmoderated[]'], $checked))->value($user['email'])->render() .
|
||||
' ' . $user['name'] . '</td>' .
|
||||
'<td class="nowrap">' . $user['email'] . '</td>' .
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
$res .= '</tbody>' .
|
||||
'</table>' .
|
||||
'</table></div>' .
|
||||
'</div>' .
|
||||
'</div>' .
|
||||
'<p><input type="submit" id="update_unmoderated" name="update_unmoderated" value="' . __('Save') . '" />' .
|
||||
|
|
|
@ -0,0 +1,286 @@
|
|||
<?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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\whiteListCom;
|
||||
|
||||
use dcBlog;
|
||||
use dcCore;
|
||||
use dcUtils;
|
||||
use Dotclear\Database\Statement\{
|
||||
JoinStatement,
|
||||
SelectStatement,
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup DC_PLUGIN_WHITELISTCOM
|
||||
* @brief White list filters methods
|
||||
* @since 2.6
|
||||
*/
|
||||
class Utils
|
||||
{
|
||||
/** @var bool $init preload check */
|
||||
private static bool $init = false;
|
||||
|
||||
/** @var array $unmoderated List of unmoderated users */
|
||||
private static array $unmoderated = [];
|
||||
|
||||
/** @var array $unmoderated List of reserved name */
|
||||
private static array $reserved = [];
|
||||
|
||||
/**
|
||||
* Initialize properties.
|
||||
*/
|
||||
private static function init(): void
|
||||
{
|
||||
if (self::$init) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::$unmoderated = self::decode(My::settings()->get('unmoderated'));
|
||||
self::$reserved = self::decode(My::settings()->get('reserved'));
|
||||
|
||||
self::$init = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save changes.
|
||||
*/
|
||||
public static function commit(): void
|
||||
{
|
||||
self::init();
|
||||
|
||||
My::settings()->put(
|
||||
'unmoderated',
|
||||
self::encode(self::$unmoderated),
|
||||
'string',
|
||||
'Whitelist of unmoderated users on comments',
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
My::settings()->put(
|
||||
'reserved',
|
||||
self::encode(self::$reserved),
|
||||
'string',
|
||||
'Whitelist of reserved names on comments',
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a name is reserved.
|
||||
*
|
||||
* Return:
|
||||
* - true if it is a reserved name with wrong email
|
||||
* - false if it is not a reserved name
|
||||
* - null if it is a reserved name with right email
|
||||
*
|
||||
* @param string $author The author
|
||||
* @param string $email The email
|
||||
*
|
||||
* @return null|bool The reserved state
|
||||
*/
|
||||
public static function isReserved(string $author, string $email): ?bool
|
||||
{
|
||||
self::init();
|
||||
|
||||
if (!isset(self::$reserved[$author])) {
|
||||
return false;
|
||||
} elseif (self::$reserved[$author] != $email) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a reserved user.
|
||||
*
|
||||
* You must do a Utils::commit() to save this change
|
||||
*
|
||||
* @param string $author The author
|
||||
* @param string $email The email
|
||||
*/
|
||||
public static function addReserved(string $author, string $email): void
|
||||
{
|
||||
self::init();
|
||||
|
||||
self::$reserved[$author] = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean reserved names list.
|
||||
*
|
||||
* You must do a Utils::commit() to save this change
|
||||
*/
|
||||
public static function emptyReserved(): void
|
||||
{
|
||||
self::init();
|
||||
|
||||
self::$reserved = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an email is unmoderated.
|
||||
*
|
||||
* Return:
|
||||
* - true if it is known as an unmoderated email
|
||||
* - false else
|
||||
*
|
||||
* @param string $email The email
|
||||
*
|
||||
* @return bool The reserved state
|
||||
*/
|
||||
public static function isUnmoderated(string $email): bool
|
||||
{
|
||||
self::init();
|
||||
|
||||
return in_array($email, self::$unmoderated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a unmoderated user.
|
||||
*
|
||||
* You must do a Utils::commit() to save this change
|
||||
*
|
||||
* @param string $email The email
|
||||
*/
|
||||
public static function addUnmoderated(string $email): void
|
||||
{
|
||||
self::init();
|
||||
|
||||
if (!in_array($email, self::$unmoderated)) {
|
||||
self::$unmoderated[] = $email;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean unmoderated users list.
|
||||
*
|
||||
* You must do a Utils::commit() to save this change
|
||||
*/
|
||||
public static function emptyUnmoderated(): void
|
||||
{
|
||||
self::init();
|
||||
|
||||
self::$unmoderated = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts users.
|
||||
*
|
||||
* @return array The users name/email pairs
|
||||
*/
|
||||
public static function getPostsUsers(): array
|
||||
{
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rs = dcCore::app()->blog->getPostsUsers();
|
||||
if ($rs->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$users = [];
|
||||
while ($rs->fetch()) {
|
||||
$name = dcUtils::getUserCN(
|
||||
$rs->f('user_id'),
|
||||
$rs->f('user_name'),
|
||||
$rs->f('user_firstname'),
|
||||
$rs->f('user_displayname')
|
||||
);
|
||||
$users[] = [
|
||||
'name' => $name,
|
||||
'email' => $rs->f('user_email'),
|
||||
];
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get comments users.
|
||||
*
|
||||
* @return array The users name/email pairs
|
||||
*/
|
||||
public static function getCommentsUsers(): array
|
||||
{
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$sql = new SelectStatement();
|
||||
$rs = $sql->from($sql->as(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME, 'C'))
|
||||
->columns([
|
||||
'comment_author',
|
||||
'comment_email',
|
||||
])
|
||||
->join(
|
||||
(new JoinStatement())
|
||||
->left()
|
||||
->from($sql->as(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME, 'P'))
|
||||
->on('C.post_id = P.post_id')
|
||||
->statement()
|
||||
)
|
||||
->where('blog_id = ' . $sql->quote(dcCore::app()->blog->id))
|
||||
->and('comment_trackback = 0')
|
||||
->and("comment_email != ''")
|
||||
->group('comment_email, comment_author') // Added author to fix postgreSql
|
||||
->select();
|
||||
|
||||
if (is_null($rs) || $rs->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$users = [];
|
||||
while ($rs->fetch()) {
|
||||
$users[] = [
|
||||
'name' => $rs->f('comment_author'),
|
||||
'email' => $rs->f('comment_email'),
|
||||
];
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode settings.
|
||||
*
|
||||
* @param array|string $x The value to encode
|
||||
*
|
||||
* @return string The encoded value
|
||||
*/
|
||||
public static function encode($x): string
|
||||
{
|
||||
$y = is_array($x) ? $x : [];
|
||||
|
||||
return (string) json_encode($y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode settings.
|
||||
*
|
||||
* @param string $x The value to decode
|
||||
*
|
||||
* @return array The decoded value
|
||||
*/
|
||||
public static function decode($x): array
|
||||
{
|
||||
$y = json_decode($x, true);
|
||||
|
||||
return is_array($y) ? $y : [];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue