diff --git a/src/Install.php b/src/Install.php index bd52aa6..a408a1e 100644 --- a/src/Install.php +++ b/src/Install.php @@ -14,18 +14,15 @@ declare(strict_types=1); namespace Dotclear\Plugin\whiteListCom; -/* dotclear ns */ use dcCore; use dcNamespace; use dcNsProcess; - -/* php ns */ use Exception; class Install extends dcNsProcess { // Module specs - private static $mod_conf = [ + private static array $mod_conf = [ [ 'unmoderated', '[]', @@ -49,7 +46,11 @@ class Install extends dcNsProcess public static function process(): bool { - if (!sestaticlf::$init) { + if (!static::$init) { + return false; + } + + if (is_null(dcCore::app()->blog)) { return false; } @@ -89,15 +90,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')) . "' ")) ); } } diff --git a/src/ReservedWhiteList.php b/src/ReservedWhiteList.php index d0da001..9ce891a 100644 --- a/src/ReservedWhiteList.php +++ b/src/ReservedWhiteList.php @@ -16,13 +16,13 @@ namespace Dotclear\Plugin\whiteListCom; use dcCore; use dcPage; -use dcSpamFilter; 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 Utils(); - - 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 Utils(); $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(); + Utils::commit(); dcPage::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 = '