rename files and class

master
Jean-Christian Paul Denis 2023-01-07 23:52:09 +01:00
parent 88e2d6c3b2
commit 9924e82e51
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
5 changed files with 137 additions and 64 deletions

View File

@ -1,46 +1,11 @@
<?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
*/
if (!defined('DC_RC_PATH')) {
return null;
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();
}
Clearbricks::lib()->autoload([
'whiteListCom' => __DIR__ . '/inc/Core.php',
'whiteListComReservedFilter' => __DIR__ . '/inc/ReservedFilter.php',
'whiteListComModeratedFilter' => __DIR__ . '/inc/ModeratedFilter.php',
]);
dcCore::app()->spamfilters[] = 'whiteListComModeratedFilter';
dcCore::app()->spamfilters[] = 'whiteListComReservedFilter';
dcCore::app()->addBehavior('publicAfterCommentCreate', function ($cur, $id) {
if (dcCore::app()->blog === null
|| dcCore::app()->blog->settings->get('system')->get('comments_pub')) {
return null;
}
if ($cur->__get('comment_spam_filter') == 'whiteListComModeratedFilter'
&& $cur->__get('comment_spam_status') == 'unmoderated') {
dcCore::app()->con->writeLock(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME);
$cur->__set('comment_status', 1);
$cur->__set('comment_spam_status', 0);
$cur->__set('comment_spam_filter', 0);
$cur->update('WHERE comment_id = ' . $id . ' ');
dcCore::app()->con->unlock();
dcCore::app()->blog->triggerComment($id);
dcCore::app()->blog->triggerBlog();
}
});

View File

@ -10,16 +10,21 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
declare(strict_types=1);
namespace Dotclear\Plugin\whiteListCom;
/* dotclear ns */
use dcCore;
use dcUtils;
/**
* @ingroup DC_PLUGIN_WHITELISTCOM
* @brief White list filters methods
* @since 2.6
*/
class whiteListCom
class Core
{
public $con;
public $blog;
@ -32,17 +37,17 @@ class whiteListCom
{
$this->con = dcCore::app()->con;
$this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
$this->settings = dcCore::app()->blog->settings->whiteListCom;
$unmoderated = $this->settings->whiteListCom_unmoderated;
$this->settings = dcCore::app()->blog->settings->get(basename(dirname(__DIR__)));
$unmoderated = $this->settings->get('unmoderated');
$this->unmoderated = self::decode($unmoderated);
$reserved = $this->settings->whiteListCom_reserved;
$reserved = $this->settings->get('reserved');
$this->reserved = self::decode($reserved);
}
public function commit()
{
$this->settings->put(
'whiteListCom_unmoderated',
'unmoderated',
self::encode($this->unmoderated),
'string',
'Whitelist of unmoderated users on comments',
@ -51,7 +56,7 @@ class whiteListCom
);
$this->settings->put(
'whiteListCom_reserved',
'reserved',
self::encode($this->reserved),
'string',
'Whitelist of reserved names on comments',
@ -158,12 +163,12 @@ class whiteListCom
{
$y = is_array($x) ? $x : [];
return base64_encode(serialize($y));
return json_encode($y);
}
public static function decode($x)
{
$y = @unserialize(@base64_decode($x));
$y = json_decode($x);
return is_array($y) ? $y : [];
}

80
inc/Prepend.php 100644
View File

@ -0,0 +1,80 @@
<?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 dcCore;
/* clearbricks ns */
use Clearbricks;
class Prepend
{
private const LIBS = [
'Core',
'UnmoderatedWhiteList',
'ReservedWhiteList',
'Prepend',
];
protected static $init = false;
public static function init(): bool
{
self::$init = defined('DC_RC_PATH');
return self::$init;
}
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';
dcCore::app()->spamfilters[] = 'ReservedWhiteList';
dcCore::app()->addBehavior('publicAfterCommentCreate', function ($cur, $id) {
if (dcCore::app()->blog === null
|| dcCore::app()->blog->settings->get('system')->get('comments_pub')) {
return null;
}
if ($cur->__get('comment_spam_filter') == 'UnmoderatedWhiteList'
&& $cur->__get('comment_spam_status') == 'unmoderated') {
dcCore::app()->con->writeLock(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME);
$cur->__set('comment_status', 1);
$cur->__set('comment_spam_status', 0);
$cur->__set('comment_spam_filter', 0);
$cur->update('WHERE comment_id = ' . $id . ' ');
dcCore::app()->con->unlock();
dcCore::app()->blog->triggerComment($id);
dcCore::app()->blog->triggerBlog();
}
});
return true;
}
}

View File

@ -10,9 +10,21 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
declare(strict_types=1);
namespace Dotclear\Plugin\whiteListCom;
/* dotclear ns */
use dcCore;
use dcSpamFilter;
/* clearbricks ns */
use form;
use html;
/* php ns */
use Exception;
/**
* @ingroup DC_PLUGIN_WHITELISTCOM
@ -39,7 +51,7 @@ class whiteListComReservedFilter extends dcSpamFilter
$throw = false;
try {
$wlc = new whiteListCom();
$wlc = new Core();
if (true === $wlc->isReserved($author, $email)) {
$status = 'reserved name';
@ -64,7 +76,7 @@ class whiteListComReservedFilter extends dcSpamFilter
public function gui(string $url): string
{
$wlc = new whiteListCom();
$wlc = new Core();
$comments = [];
try {

View File

@ -10,9 +10,20 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
declare(strict_types=1);
namespace Dotclear\Plugin\whiteListCom;
/* dotclear ns */
use dcCore;
use dcSpamFilter;
/* clearbricks ns */
use form;
use html;
/* php ns */
use Exception;
/**
* @ingroup DC_PLUGIN_WHITELISTCOM
@ -21,7 +32,7 @@ if (!defined('DC_RC_PATH')) {
*
* This filter is used only if comments are moderates
*/
class whiteListComModeratedFilter extends dcSpamFilter
class UnmoderatedWhiteList extends dcSpamFilter
{
public $name = 'Unmoderated authors';
public $has_gui = true;
@ -41,7 +52,7 @@ class whiteListComModeratedFilter extends dcSpamFilter
}
try {
$wlc = new whiteListCom();
$wlc = new Core();
if ($wlc->isUnmoderated($email)) {
$status = 'unmoderated';
@ -56,7 +67,7 @@ class whiteListComModeratedFilter extends dcSpamFilter
public function gui(string $url): string
{
$wlc = new whiteListCom();
$wlc = new Core();
$posts = $comments = [];
try {