release 1.1
parent
0d2b8e4aff
commit
7c7711a367
|
@ -1,3 +1,6 @@
|
|||
1.1 - 2023.03.11
|
||||
- code review for Dotclear 2.25
|
||||
|
||||
1.0 - 2023.01.08
|
||||
- use abstract plugin id
|
||||
- use anonymous functions
|
||||
|
|
|
@ -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.24-blue.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.25-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.24
|
||||
* Dotclear 2.25
|
||||
|
||||
## USAGE
|
||||
|
||||
|
|
14
_define.php
14
_define.php
|
@ -18,17 +18,17 @@ $this->registerModule(
|
|||
'Whitelist comments',
|
||||
'Whitelists for comments moderation',
|
||||
'Jean-Christian Denis and Contributors',
|
||||
'1.0',
|
||||
'1.1',
|
||||
[
|
||||
'requires' => [['core', '2.24']],
|
||||
'requires' => [['core', '2.25']],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcAuth::PERMISSION_USAGE,
|
||||
dcAuth::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',
|
||||
'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',
|
||||
]
|
||||
);
|
||||
|
|
20
_install.php
20
_install.php
|
@ -1,20 +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);
|
||||
|
||||
$install = implode('\\', ['Dotclear', 'Plugin', basename(__DIR__), 'Install']);
|
||||
if ($install::init()) {
|
||||
return $install::process();
|
||||
}
|
||||
|
||||
return null;
|
22
_prepend.php
22
_prepend.php
|
@ -1,22 +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);
|
||||
|
||||
$prepend = implode('\\', ['Dotclear', 'Plugin', basename(__DIR__), 'Prepend']);
|
||||
if (!class_exists($prepend)) {
|
||||
require implode(DIRECTORY_SEPARATOR, [__DIR__, 'inc', 'Prepend.php']);
|
||||
|
||||
if ($prepend::init()) {
|
||||
$prepend::process();
|
||||
}
|
||||
}
|
|
@ -2,11 +2,11 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="whiteListCom">
|
||||
<name>Whitelist comments</name>
|
||||
<version>1.0</version>
|
||||
<version>1.1</version>
|
||||
<author>Jean-Christian Denis and Contributors</author>
|
||||
<desc>Whitelists for comments moderation</desc>
|
||||
<file>https://github.com/JcDenis/whiteListCom/releases/download/v1.0/plugin-whiteListCom.zip</file>
|
||||
<da:dcmin>2.24</da:dcmin>
|
||||
<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>
|
||||
</module>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Project-Id-Version: whiteListCom 1.0\n"
|
||||
"Project-Id-Version: whiteListCom 1.1\n"
|
||||
"POT-Creation-Date: \n"
|
||||
"PO-Revision-Date: 2023-01-07T23:39:35+00:00\n"
|
||||
"PO-Revision-Date: 2023-03-11T21:46:05+00:00\n"
|
||||
"Last-Translator: Jean-Christian Denis\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
|
|
|
@ -37,14 +37,12 @@ class Core
|
|||
{
|
||||
$this->con = dcCore::app()->con;
|
||||
$this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
|
||||
$this->settings = dcCore::app()->blog->settings->get(basename(dirname(__DIR__)));
|
||||
$unmoderated = $this->settings->get('unmoderated');
|
||||
$this->unmoderated = self::decode($unmoderated);
|
||||
$reserved = $this->settings->get('reserved');
|
||||
$this->reserved = self::decode($reserved);
|
||||
$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()
|
||||
public function commit(): void
|
||||
{
|
||||
$this->settings->put(
|
||||
'unmoderated',
|
||||
|
@ -69,7 +67,7 @@ class Core
|
|||
# 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)
|
||||
public function isReserved($author, $email): ?bool
|
||||
{
|
||||
if (!isset($this->reserved[$author])) {
|
||||
return false;
|
||||
|
@ -81,7 +79,7 @@ class Core
|
|||
}
|
||||
|
||||
# You must do a commit to save this change
|
||||
public function addReserved($author, $email)
|
||||
public function addReserved($author, $email): bool
|
||||
{
|
||||
$this->reserved[$author] = $email;
|
||||
|
||||
|
@ -89,20 +87,20 @@ class Core
|
|||
}
|
||||
|
||||
# You must do a commit to save this change
|
||||
public function emptyReserved()
|
||||
public function emptyReserved(): void
|
||||
{
|
||||
$this->reserved = [];
|
||||
}
|
||||
|
||||
# Return
|
||||
# true if it is known as an unmoderated email else false
|
||||
public function isUnmoderated($email)
|
||||
public function isUnmoderated($email): bool
|
||||
{
|
||||
return in_array($email, $this->unmoderated);
|
||||
}
|
||||
|
||||
# You must do a commit to save this change
|
||||
public function addUnmoderated($email)
|
||||
public function addUnmoderated($email): ?bool
|
||||
{
|
||||
if (!in_array($email, $this->unmoderated)) {
|
||||
$this->unmoderated[] = $email;
|
||||
|
@ -114,32 +112,32 @@ class Core
|
|||
}
|
||||
|
||||
# You must do a commit to save this change
|
||||
public function emptyUnmoderated()
|
||||
public function emptyUnmoderated(): void
|
||||
{
|
||||
$this->unmoderated = [];
|
||||
}
|
||||
|
||||
public function getPostsUsers()
|
||||
public function getPostsUsers(): array
|
||||
{
|
||||
$users = [];
|
||||
$rs = dcCore::app()->blog->getPostsUsers();
|
||||
while ($rs->fetch()) {
|
||||
$name = dcUtils::getUserCN(
|
||||
$rs->__get('user_id'),
|
||||
$rs->__get('user_name'),
|
||||
$rs->__get('user_firstname'),
|
||||
$rs->__get('user_displayname')
|
||||
$rs->f('user_id'),
|
||||
$rs->f('user_name'),
|
||||
$rs->f('user_firstname'),
|
||||
$rs->f('user_displayname')
|
||||
);
|
||||
$users[] = [
|
||||
'name' => $name,
|
||||
'email' => $rs->__get('user_email'),
|
||||
'email' => $rs->f('user_email'),
|
||||
];
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
public function getCommentsUsers()
|
||||
public function getCommentsUsers(): array
|
||||
{
|
||||
$users = [];
|
||||
$rs = $this->con->select(
|
||||
|
@ -151,22 +149,22 @@ class Core
|
|||
);
|
||||
while ($rs->fetch()) {
|
||||
$users[] = [
|
||||
'name' => $rs->__get('comment_author'),
|
||||
'email' => $rs->__get('comment_email'),
|
||||
'name' => $rs->f('comment_author'),
|
||||
'email' => $rs->f('comment_email'),
|
||||
];
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
public static function encode($x)
|
||||
public static function encode($x): string
|
||||
{
|
||||
$y = is_array($x) ? $x : [];
|
||||
|
||||
return json_encode($y);
|
||||
}
|
||||
|
||||
public static function decode($x)
|
||||
public static function decode($x): array
|
||||
{
|
||||
$y = json_decode($x, true);
|
||||
|
|
@ -17,11 +17,12 @@ namespace Dotclear\Plugin\whiteListCom;
|
|||
/* dotclear ns */
|
||||
use dcCore;
|
||||
use dcNamespace;
|
||||
use dcNsProcess;
|
||||
|
||||
/* php ns */
|
||||
use Exception;
|
||||
|
||||
class Install
|
||||
class Install extends dcNsProcess
|
||||
{
|
||||
// Module specs
|
||||
private static $mod_conf = [
|
||||
|
@ -39,19 +40,14 @@ class Install
|
|||
],
|
||||
];
|
||||
|
||||
// Nothing to change below
|
||||
private static $pid = '';
|
||||
protected static $init = false;
|
||||
|
||||
public static function init(): bool
|
||||
{
|
||||
self::$pid = basename(dirname(__DIR__));
|
||||
self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(self::$pid, dcCore::app()->plugins->moduleInfo(self::$pid, 'version'));
|
||||
self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
||||
|
||||
return self::$init;
|
||||
}
|
||||
|
||||
public static function process(): ?bool
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::$init) {
|
||||
return false;
|
||||
|
@ -63,7 +59,7 @@ class Install
|
|||
|
||||
// Set module settings
|
||||
foreach (self::$mod_conf as $v) {
|
||||
dcCore::app()->blog->settings->__get(self::$pid)->put(
|
||||
dcCore::app()->blog->settings->get(My::id())->put(
|
||||
$v[0],
|
||||
$v[1],
|
||||
$v[2],
|
||||
|
@ -83,7 +79,7 @@ class Install
|
|||
|
||||
public static function growUp(): void
|
||||
{
|
||||
$current = dcCore::app()->getVersion(self::$pid);
|
||||
$current = dcCore::app()->getVersion(My::id());
|
||||
|
||||
// Update settings id, ns
|
||||
if ($current && version_compare($current, '1.0', '<')) {
|
||||
|
@ -97,7 +93,7 @@ class Install
|
|||
$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 = self::$pid;
|
||||
$cur->setting_ns = My::id();
|
||||
$cur->setting_value = is_array($value) ? json_encode($value) : '[]';
|
||||
$cur->update(
|
||||
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'whiteListCom' " .
|
|
@ -0,0 +1,39 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* Plugin definitions
|
||||
*/
|
||||
class My
|
||||
{
|
||||
/**
|
||||
* 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'));
|
||||
}
|
||||
}
|
|
@ -14,50 +14,32 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\whiteListCom;
|
||||
|
||||
/* dotclear ns */
|
||||
use dcBlog;
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
|
||||
/* clearbricks ns */
|
||||
use Clearbricks;
|
||||
|
||||
class Prepend
|
||||
class Prepend extends dcNsProcess
|
||||
{
|
||||
private const LIBS = [
|
||||
'Core',
|
||||
'UnmoderatedWhiteList',
|
||||
'ReservedWhiteList',
|
||||
'Install',
|
||||
'Prepend',
|
||||
];
|
||||
protected static $init = false;
|
||||
|
||||
public static function init(): bool
|
||||
{
|
||||
self::$init = defined('DC_RC_PATH');
|
||||
self::$init = true;
|
||||
|
||||
return self::$init;
|
||||
}
|
||||
|
||||
public static function process(): ?bool
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (self::LIBS as $lib) {
|
||||
Clearbricks::lib()->autoload([
|
||||
__NAMESPACE__ . '\\' . $lib => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php',
|
||||
]);
|
||||
}
|
||||
dcCore::app()->spamfilters[] = UnmoderatedWhiteList::class;
|
||||
dcCore::app()->spamfilters[] = ReservedWhiteList::class;
|
||||
|
||||
dcCore::app()->spamfilters[] = __NAMESPACE__ . '\\' . 'UnmoderatedWhiteList';
|
||||
dcCore::app()->spamfilters[] = __NAMESPACE__ . '\\' . 'ReservedWhiteList';
|
||||
|
||||
dcCore::app()->addBehavior('publicAfterCommentCreate', function ($cur, $id) {
|
||||
dcCore::app()->addBehavior('publicAfterCommentCreate', function ($cur, $id): void {
|
||||
if (dcCore::app()->blog === null
|
||||
|| dcCore::app()->blog->settings->get('system')->get('comments_pub')) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($cur->__get('comment_spam_filter') == 'UnmoderatedWhiteList'
|
|
@ -49,7 +49,7 @@ class UnmoderatedWhiteList extends dcSpamFilter
|
|||
{
|
||||
if ($type != 'comment'
|
||||
|| dcCore::app()->blog === null
|
||||
|| dcCore::app()->blog->settings->system->comments_pub) {
|
||||
|| dcCore::app()->blog->settings->get('system')->get('comments_pub')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ class UnmoderatedWhiteList extends dcSpamFilter
|
|||
|
||||
$res = '';
|
||||
|
||||
if (dcCore::app()->blog->settings->system->comments_pub) {
|
||||
if (dcCore::app()->blog->settings->get('system')->get('comments_pub')) {
|
||||
$res .= '<p class="message">' .
|
||||
__('This filter is used only if comments are moderates') .
|
||||
'</p>';
|
Loading…
Reference in New Issue