prepare to DC 2.24

master
Jean-Christian Paul Denis 2022-11-16 22:22:48 +01:00
parent f6881f8f11
commit 71fde26ae6
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
4 changed files with 113 additions and 167 deletions

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -19,14 +18,14 @@ $this->registerModule(
'Whitelist comments', 'Whitelist comments',
'Whitelists for comments moderation', 'Whitelists for comments moderation',
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'0.8', '0.9',
[ [
'requires' => [['core', '2.19']], 'requires' => [['core', '2.24']],
'permissions' => 'admin', 'permissions' => dcAuth::PERMISSION_ADMIN,
'priority' => 200, 'priority' => 200,
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/whiteListCom', 'support' => 'https://github.com/JcDenis/whiteListCom',
'details' => 'https://plugins.dotaddict.org/dc2/details/whiteListCom', 'details' => 'https://plugins.dotaddict.org/dc2/details/whiteListCom',
'repository' => 'https://raw.githubusercontent.com/JcDenis/whiteListCom/master/dcstore.xml' 'repository' => 'https://raw.githubusercontent.com/JcDenis/whiteListCom/master/dcstore.xml',
] ]
); );

View File

@ -10,23 +10,22 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$d = dirname(__FILE__).'/inc/lib.whitelistcom.php'; $d = __DIR__ . '/inc/lib.whitelistcom.php';
$__autoload['whiteListCom'] = $d; Clearbricks::lib()->autoload(['whiteListCom' => $d]);
$__autoload['whiteListComBehaviors'] = $d; Clearbricks::lib()->autoload(['whiteListComBehaviors' => $d]);
$__autoload['whiteListComReservedFilter'] = $d; Clearbricks::lib()->autoload(['whiteListComReservedFilter' => $d]);
$__autoload['whiteListComModeratedFilter'] = $d; Clearbricks::lib()->autoload(['whiteListComModeratedFilter' => $d]);
$core->spamfilters[] = 'whiteListComModeratedFilter'; dcCore::app()->spamfilters[] = 'whiteListComModeratedFilter';
$core->addBehavior( dcCore::app()->addBehavior(
'publicAfterCommentCreate', 'publicAfterCommentCreate',
['whiteListComBehaviors', 'switchStatus'] ['whiteListComBehaviors', 'switchStatus']
); );
$core->spamfilters[] = 'whiteListComReservedFilter'; dcCore::app()->spamfilters[] = 'whiteListComReservedFilter';

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -36,31 +35,29 @@ class whiteListComModeratedFilter extends dcSpamFilter
public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
{ {
if ($type != 'comment' if ($type != 'comment'
|| $this->core->blog === null || dcCore::app()->blog === null
|| $this->core->blog->settings->system->comments_pub) { || dcCore::app()->blog->settings->system->comments_pub) {
return null; return null;
} }
try { try {
$wlc = new whiteListCom($this->core); $wlc = new whiteListCom();
if ($wlc->isUnmoderated($email)) { if ($wlc->isUnmoderated($email)) {
$status = 'unmoderated'; $status = 'unmoderated';
# return true in order to change comment_status after # return true in order to change comment_status after
return true; return true;
} else { }
return null; return null;
}
} catch (Exception $e) { } catch (Exception $e) {
} }
} }
public function gui($url) public function gui(string $url): string
{ {
try { try {
$wlc = new whiteListCom($this->core); $wlc = new whiteListCom();
if (!empty($_POST['update_unmoderated'])) { if (!empty($_POST['update_unmoderated'])) {
$wlc->emptyUnmoderated(); $wlc->emptyUnmoderated();
@ -72,20 +69,18 @@ class whiteListComModeratedFilter extends dcSpamFilter
$posts = $wlc->getPostsUsers(); $posts = $wlc->getPostsUsers();
$comments = $wlc->getCommentsUsers(); $comments = $wlc->getCommentsUsers();
} catch (Exception $e) { } catch (Exception $e) {
$this->core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
$res = ''; $res = '';
if ($this->core->blog->settings->system->comments_pub) { if (dcCore::app()->blog->settings->system->comments_pub) {
$res .= $res .= '<p class="message">' .
'<p class="message">' .
__('This filter is used only if comments are moderates') . __('This filter is used only if comments are moderates') .
'</p>'; '</p>';
} }
$res .= $res .= '<form action="' . html::escapeURL($url) . '" method="post">' .
'<form action="' . html::escapeURL($url) . '" method="post">' .
'<p>' . __('Check the users who can make comments without being moderated.') . '</p>' . '<p>' . __('Check the users who can make comments without being moderated.') . '</p>' .
'<div class="two-cols">' . '<div class="two-cols">' .
'<div class="col">' . '<div class="col">' .
@ -95,11 +90,10 @@ class whiteListComModeratedFilter extends dcSpamFilter
'<tbody>'; '<tbody>';
foreach ($posts as $user) { foreach ($posts as $user) {
$res .= $res .= '<tr class="line">' .
'<tr class="line">' .
'<td class="nowrap">' . '<td class="nowrap">' .
form::checkbox( form::checkbox(
array('unmoderated[]'), ['unmoderated[]'],
$user['email'], $user['email'],
$wlc->isUnmoderated($user['email']) $wlc->isUnmoderated($user['email'])
) . ) .
@ -108,8 +102,7 @@ class whiteListComModeratedFilter extends dcSpamFilter
'</tr>'; '</tr>';
} }
$res .= $res .= '</tbody>' .
'</tbody>' .
'</table>' . '</table>' .
'</div>' . '</div>' .
'<div class="col">' . '<div class="col">' .
@ -119,11 +112,10 @@ class whiteListComModeratedFilter extends dcSpamFilter
'<tbody>'; '<tbody>';
foreach ($comments as $user) { foreach ($comments as $user) {
$res .= $res .= '<tr class="line">' .
'<tr class="line">' .
'<td class="nowrap">' . '<td class="nowrap">' .
form::checkbox( form::checkbox(
array('unmoderated[]'), ['unmoderated[]'],
$user['email'], $user['email'],
$wlc->isUnmoderated($user['email']) $wlc->isUnmoderated($user['email'])
) . ) .
@ -132,13 +124,12 @@ class whiteListComModeratedFilter extends dcSpamFilter
'</tr>'; '</tr>';
} }
$res .= $res .= '</tbody>' .
'</tbody>' .
'</table>' . '</table>' .
'</div>' . '</div>' .
'</div>' . '</div>' .
'<p><input type="submit" name="update_unmoderated" value="' . __('Save') . '" />' . '<p><input type="submit" name="update_unmoderated" value="' . __('Save') . '" />' .
$this->core->formNonce() . '</p>' . dcCore::app()->formNonce() . '</p>' .
'</form>'; '</form>';
return $res; return $res;
@ -168,8 +159,9 @@ class whiteListComReservedFilter extends dcSpamFilter
} }
$throw = false; $throw = false;
try { try {
$wlc = new whiteListCom($this->core); $wlc = new whiteListCom();
if (true === $wlc->isReserved($author, $email)) { if (true === $wlc->isReserved($author, $email)) {
$status = 'reserved name'; $status = 'reserved name';
@ -179,7 +171,6 @@ class whiteListComReservedFilter extends dcSpamFilter
return null; return null;
} }
} catch (Exception $e) { } catch (Exception $e) {
} }
# This message is show to author even if comments are moderated, comment is not saved # This message is show to author even if comments are moderated, comment is not saved
@ -193,10 +184,10 @@ class whiteListComReservedFilter extends dcSpamFilter
return __('This name is reserved to an other user.'); return __('This name is reserved to an other user.');
} }
public function gui($url) public function gui(string $url): string
{ {
try { try {
$wlc = new whiteListCom($this->core); $wlc = new whiteListCom();
if (!empty($_POST['update_reserved'])) { if (!empty($_POST['update_reserved'])) {
$wlc->emptyReserved(); $wlc->emptyReserved();
@ -207,11 +198,10 @@ class whiteListComReservedFilter extends dcSpamFilter
} }
$comments = $wlc->getCommentsUsers(); $comments = $wlc->getCommentsUsers();
} catch (Exception $e) { } catch (Exception $e) {
$this->core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
$res = $res = '<form action="' . html::escapeURL($url) . '" method="post">' .
'<form action="' . html::escapeURL($url) . '" method="post">' .
'<p>' . __('Check the users who can make comments without being moderated.') . '</p>' . '<p>' . __('Check the users who can make comments without being moderated.') . '</p>' .
'<p>' . __('Comments authors list') . '</p>' . '<p>' . __('Comments authors list') . '</p>' .
'<table class="clear">' . '<table class="clear">' .
@ -219,11 +209,10 @@ class whiteListComReservedFilter extends dcSpamFilter
'<tbody>'; '<tbody>';
foreach ($comments as $user) { foreach ($comments as $user) {
$res .= $res .= '<tr class="line">' .
'<tr class="line">' .
'<td class="nowrap">' . '<td class="nowrap">' .
form::checkbox( form::checkbox(
array('reserved[' . $user['email'] . ']'), ['reserved[' . $user['email'] . ']'],
$user['name'], $user['name'],
(null === $wlc->isReserved($user['name'], $user['email'])) (null === $wlc->isReserved($user['name'], $user['email']))
) . ) .
@ -232,11 +221,10 @@ class whiteListComReservedFilter extends dcSpamFilter
'</tr>'; '</tr>';
} }
$res .= $res .= '</tbody>' .
'</tbody>' .
'</table>' . '</table>' .
'<p><input type="submit" name="update_reserved" value="' . __('Save') . '" />' . '<p><input type="submit" name="update_reserved" value="' . __('Save') . '" />' .
$this->core->formNonce() . '</p>' . dcCore::app()->formNonce() . '</p>' .
'</form>'; '</form>';
return $res; return $res;
@ -250,22 +238,20 @@ class whiteListComReservedFilter extends dcSpamFilter
*/ */
class whiteListCom class whiteListCom
{ {
public $core;
public $con; public $con;
public $blog; public $blog;
public $settings; public $settings;
private $unmoderated = array(); private $unmoderated = [];
private $reserved = array(); private $reserved = [];
public function __construct($core) public function __construct()
{ {
$this->core = $core; $this->con = dcCore::app()->con;
$this->con = $core->con; $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
$this->blog = $core->con->escape($core->blog->id);
$core->blog->settings->addNamespace('whiteListCom'); dcCore::app()->blog->settings->addNamespace('whiteListCom');
$this->settings = $core->blog->settings->whiteListCom; $this->settings = dcCore::app()->blog->settings->whiteListCom;
$unmoderated = $this->settings->whiteListCom_unmoderated; $unmoderated = $this->settings->whiteListCom_unmoderated;
$this->unmoderated = self::decode($unmoderated); $this->unmoderated = self::decode($unmoderated);
@ -281,7 +267,8 @@ class whiteListCom
self::encode($this->unmoderated), self::encode($this->unmoderated),
'string', 'string',
'Whitelist of unmoderated users on comments', 'Whitelist of unmoderated users on comments',
true,false true,
false
); );
$this->settings->put( $this->settings->put(
@ -289,7 +276,8 @@ class whiteListCom
self::encode($this->reserved), self::encode($this->reserved),
'string', 'string',
'Whitelist of reserved names on comments', 'Whitelist of reserved names on comments',
true,false true,
false
); );
} }
@ -303,22 +291,23 @@ class whiteListCom
return false; return false;
} elseif ($this->reserved[$author] != $email) { } elseif ($this->reserved[$author] != $email) {
return true; return true;
} else {
return null;
} }
return null;
} }
# You must do a commit to save this change # You must do a commit to save this change
public function addReserved($author, $email) public function addReserved($author, $email)
{ {
$this->reserved[$author] = $email; $this->reserved[$author] = $email;
return true; return true;
} }
# You must do a commit to save this change # You must do a commit to save this change
public function emptyReserved() public function emptyReserved()
{ {
$this->reserved = array(); $this->reserved = [];
} }
# Return # Return
@ -343,13 +332,13 @@ class whiteListCom
# You must do a commit to save this change # You must do a commit to save this change
public function emptyUnmoderated() public function emptyUnmoderated()
{ {
$this->unmoderated = array(); $this->unmoderated = [];
} }
public function getPostsUsers() public function getPostsUsers()
{ {
$users = array(); $users = [];
$rs = $this->core->blog->getPostsUsers(); $rs = dcCore::app()->blog->getPostsUsers();
while ($rs->fetch()) { while ($rs->fetch()) {
$name = dcUtils::getUserCN( $name = dcUtils::getUserCN(
$rs->user_id, $rs->user_id,
@ -357,10 +346,10 @@ class whiteListCom
$rs->user_firstname, $rs->user_firstname,
$rs->user_displayname $rs->user_displayname
); );
$users[] = array( $users[] = [
'name' => $name, 'name' => $name,
'email' => $rs->user_email 'email' => $rs->user_email,
); ];
} }
return $users; return $users;
@ -368,19 +357,19 @@ class whiteListCom
public function getCommentsUsers() public function getCommentsUsers()
{ {
$users = array(); $users = [];
$rs = $this->con->select( $rs = $this->con->select(
'SELECT comment_author, comment_email ' . 'SELECT comment_author, comment_email ' .
'FROM ' . $this->core->prefix . 'comment C ' . 'FROM ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' C ' .
'LEFT JOIN ' . $this->core->prefix . 'post P ON C.post_id=P.post_id ' . 'LEFT JOIN ' . dcCore::app()->prefix . 'post P ON C.post_id=P.post_id ' .
"WHERE blog_id='" . $this->blog . "' AND comment_trackback=0 " . "WHERE blog_id='" . $this->blog . "' AND comment_trackback=0 " .
'GROUP BY comment_email, comment_author ' // Added author to fix postgreSql 'GROUP BY comment_email, comment_author ' // Added author to fix postgreSql
); );
while ($rs->fetch()) { while ($rs->fetch()) {
$users[] = array( $users[] = [
'name' => $rs->comment_author, 'name' => $rs->comment_author,
'email' => $rs->comment_email 'email' => $rs->comment_email,
); ];
} }
return $users; return $users;
@ -388,7 +377,7 @@ class whiteListCom
public static function encode($x) public static function encode($x)
{ {
$y = is_array($x) ? $x : array(); $y = is_array($x) ? $x : [];
return base64_encode(serialize($y)); return base64_encode(serialize($y));
} }
@ -397,7 +386,7 @@ class whiteListCom
{ {
$y = @unserialize(@base64_decode($x)); $y = @unserialize(@base64_decode($x));
return is_array($y) ? $y : array(); return is_array($y) ? $y : [];
} }
} }
@ -411,26 +400,24 @@ class whiteListComBehaviors
# from behavior publicAfterCommentCreate # from behavior publicAfterCommentCreate
public static function switchStatus($cur, $id) public static function switchStatus($cur, $id)
{ {
global $core; if (dcCore::app()->blog === null
|| dcCore::app()->blog->settings->system->comments_pub) {
if ($core->blog === null
|| $core->blog->settings->system->comments_pub) {
return null; return null;
} }
if ($cur->comment_spam_filter == 'whiteListComModeratedFilter' if ($cur->comment_spam_filter == 'whiteListComModeratedFilter'
&& $cur->comment_spam_status == 'unmoderated') { && $cur->comment_spam_status == 'unmoderated') {
$core->con->writeLock($core->prefix.'comment'); dcCore::app()->con->writeLock(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME);
$cur->comment_status = 1; $cur->comment_status = 1;
$cur->comment_spam_status = 0; $cur->comment_spam_status = 0;
$cur->comment_spam_filter = 0; $cur->comment_spam_filter = 0;
$cur->update('WHERE comment_id = ' . $id . ' '); $cur->update('WHERE comment_id = ' . $id . ' ');
$core->con->unlock(); dcCore::app()->con->unlock();
$core->blog->triggerComment($id); dcCore::app()->blog->triggerComment($id);
$core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
} }
} }
} }

View File

@ -1,39 +0,0 @@
<?php
// Language: Français
// Module: whiteListCom - 0.6
// Date: 2013-11-13 08:01:13
// Translated with dcTranslater - 2013.05.11
#inc/lib.whitelistcom.php:34
$GLOBALS['__l10n']['Unmoderated authors'] = 'Auteurs non modérés';
#inc/lib.whitelistcom.php:35
$GLOBALS['__l10n']['Whitelist of unmoderated authors'] = 'Liste blanche des auteurs non modérés';
#inc/lib.whitelistcom.php:87
$GLOBALS['__l10n']['This filter is used only if comments are moderates'] = 'Ce filtre est utilisé seulement si les commentaires sont modérés.';
#inc/lib.whitelistcom.php:93
#inc/lib.whitelistcom.php:216
$GLOBALS['__l10n']['Check the users who can make comments without being moderated.'] = 'Cocher les utilisateurs qui peuvent faire des commentaires sans être modérés.';
#inc/lib.whitelistcom.php:96
$GLOBALS['__l10n']['Posts authors list'] = 'Liste des auteurs de billets';
#inc/lib.whitelistcom.php:117
#inc/lib.whitelistcom.php:217
$GLOBALS['__l10n']['Comments authors list'] = 'Liste des auteurs de commentaires';
#inc/lib.whitelistcom.php:158
$GLOBALS['__l10n']['Reserved names'] = 'Noms réservés';
#inc/lib.whitelistcom.php:159
$GLOBALS['__l10n']['Whitelist of reserved names of users'] = 'Liste blanche des noms d\'utilisateurs réservés';
#inc/lib.whitelistcom.php:187
#inc/lib.whitelistcom.php:193
$GLOBALS['__l10n']['This name is reserved to an other user.'] = 'Ce nom est réservé à un autre utilisateur.';
$GLOBALS['__l10n']['Whitelists for comments moderation'] = 'Listes blanches pour la modération de commentaires';
$GLOBALS['__l10n']['Whitelist comments'] = 'Liste blanche des commentaires';