misc: Minor improvements

This commit is contained in:
Roman Kelesidis 2025-05-04 19:38:38 +03:00
commit 0d58bb12ea
3 changed files with 10 additions and 19 deletions

View file

@ -2154,10 +2154,7 @@ function getBanInfo(?int $userId = null): ?array
global $datastore; global $datastore;
// Get bans info from datastore // Get bans info from datastore
if (!$bans = $datastore->get('ban_list')) {
$datastore->update('ban_list');
$bans = $datastore->get('ban_list'); $bans = $datastore->get('ban_list');
}
if (!isset($userId)) { if (!isset($userId)) {
return $bans; return $bans;

View file

@ -41,10 +41,7 @@ class Censor
} }
// Get censored words // Get censored words
if (!$censoredWords = $datastore->get('censor')) {
$datastore->update('censor');
$censoredWords = $datastore->get('censor'); $censoredWords = $datastore->get('censor');
}
foreach ($censoredWords as $word) { foreach ($censoredWords as $word) {
$this->words[] = '#(?<![\p{Nd}\p{L}_])(' . str_replace('\*', '[\p{Nd}\p{L}_]*?', preg_quote($word['word'], '#')) . ')(?![\p{Nd}\p{L}_])#iu'; $this->words[] = '#(?<![\p{Nd}\p{L}_])(' . str_replace('\*', '[\p{Nd}\p{L}_]*?', preg_quote($word['word'], '#')) . ')(?![\p{Nd}\p{L}_])#iu';

View file

@ -19,7 +19,7 @@ class BBCode
public array $tpl = []; public array $tpl = [];
/** @var array $smilies Replacements for smilies */ /** @var array $smilies Replacements for smilies */
public array $smilies; public array $smilies = [];
/** @var array $tidy_cfg Tidy preprocessor configuration */ /** @var array $tidy_cfg Tidy preprocessor configuration */
public array $tidy_cfg = [ public array $tidy_cfg = [
@ -336,11 +336,9 @@ class BBCode
{ {
global $datastore; global $datastore;
if (!$this->smilies = $datastore->get('smile_replacements')) {
$datastore->update('smile_replacements');
$this->smilies = $datastore->get('smile_replacements'); $this->smilies = $datastore->get('smile_replacements');
}
if (!empty($this->smilies)) {
if (defined('IN_ADMIN')) { if (defined('IN_ADMIN')) {
foreach ($this->smilies['repl'] as &$smile) { foreach ($this->smilies['repl'] as &$smile) {
$smile = preg_replace('/src="([^"]+)"/', 'src="./../$1"', $smile); $smile = preg_replace('/src="([^"]+)"/', 'src="./../$1"', $smile);
@ -348,7 +346,6 @@ class BBCode
unset($smile); unset($smile);
} }
if ($this->smilies) {
/** @noinspection NestedPositiveIfStatementsInspection */ /** @noinspection NestedPositiveIfStatementsInspection */
if ($parsed_text = preg_replace($this->smilies['orig'], $this->smilies['repl'], $text)) { if ($parsed_text = preg_replace($this->smilies['orig'], $this->smilies['repl'], $text)) {
return $parsed_text; return $parsed_text;