From 2c69095a1edf7474073451285238659d0f62ce3f Mon Sep 17 00:00:00 2001 From: Appleman1234 Date: Sun, 25 Sep 2022 13:30:13 +1000 Subject: PHP8.1 fixes from Rector --- inc/anti-bot.php | 72 +++--- inc/api.php | 88 ++----- inc/bans.php | 52 ++-- inc/cache.php | 14 +- inc/config.php | 202 +++++----------- inc/controller.php | 10 +- inc/database.php | 32 +-- inc/display.php | 73 +++--- inc/error.php | 24 +- inc/events.php | 4 +- inc/filters.php | 33 +-- inc/functions.php | 550 +++++++++++++++++-------------------------- inc/image.php | 52 ++-- inc/lib/webm/ffmpeg.php | 36 +-- inc/lib/webm/matroska.php | 78 +++--- inc/lib/webm/posthandler.php | 8 +- inc/lib/webm/videodata.php | 18 +- inc/lock.php | 2 +- inc/mod/auth.php | 56 ++--- inc/mod/config-editor.php | 40 ++-- inc/mod/pages.php | 455 ++++++++++++++--------------------- inc/nntpchan/nntpchan.php | 31 +-- inc/polyfill.php | 13 +- inc/queue.php | 10 +- inc/remote.php | 6 +- inc/route.php | 6 +- inc/template.php | 58 ++--- 27 files changed, 786 insertions(+), 1237 deletions(-) (limited to 'inc') diff --git a/inc/anti-bot.php b/inc/anti-bot.php index 4c321176..db30ebf8 100644 --- a/inc/anti-bot.php +++ b/inc/anti-bot.php @@ -6,10 +6,10 @@ defined('TINYBOARD') or exit; -$hidden_inputs_twig = array(); +$hidden_inputs_twig = []; class AntiBot { - public $salt, $inputs = array(), $index = 0; + public $salt, $inputs = [], $index = 0; public static function randomString($length, $uppercase = false, $special_chars = false, $unicode_chars = false) { $chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; @@ -20,17 +20,17 @@ class AntiBot { if ($unicode_chars) { $len = strlen($chars) / 10; for ($n = 0; $n < $len; $n++) - $chars .= mb_convert_encoding('&#' . mt_rand(0x2600, 0x26FF) . ';', 'UTF-8', 'HTML-ENTITIES'); + $chars .= mb_convert_encoding('&#' . random_int(0x2600, 0x26FF) . ';', 'UTF-8', 'HTML-ENTITIES'); } $chars = preg_split('//u', $chars, -1, PREG_SPLIT_NO_EMPTY); - $ch = array(); + $ch = []; // fill up $ch until we reach $length while (count($ch) < $length) { $n = $length - count($ch); - $keys = array_rand($chars, $n > count($chars) ? count($chars) : $n); + $keys = array_rand($chars, $n > (is_countable($chars) ? count($chars) : 0) ? count($chars) : $n); if ($n == 1) { $ch[] = $chars[$keys]; break; @@ -46,19 +46,19 @@ class AntiBot { } public static function make_confusing($string) { - $chars = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY); + $chars = preg_split('//u', (string) $string, -1, PREG_SPLIT_NO_EMPTY); foreach ($chars as &$c) { - if (mt_rand(0, 3) != 0) + if (random_int(0, 3) != 0) $c = utf8tohtml($c); else - $c = mb_encode_numericentity($c, array(0, 0xffff, 0, 0xffff), 'UTF-8'); + $c = mb_encode_numericentity((string) $c, [0, 0xffff, 0, 0xffff], 'UTF-8'); } return implode('', $chars); } - public function __construct(array $salt = array()) { + public function __construct(array $salt = []) { global $config; if (!empty($salt)) { @@ -70,60 +70,48 @@ class AntiBot { shuffle($config['spam']['hidden_input_names']); - $input_count = mt_rand($config['spam']['hidden_inputs_min'], $config['spam']['hidden_inputs_max']); + $input_count = random_int($config['spam']['hidden_inputs_min'], $config['spam']['hidden_inputs_max']); $hidden_input_names_x = 0; for ($x = 0; $x < $input_count ; $x++) { - if ($hidden_input_names_x === false || mt_rand(0, 2) == 0) { + if ($hidden_input_names_x === false || random_int(0, 2) == 0) { // Use an obscure name - $name = $this->randomString(mt_rand(10, 40), false, false, $config['spam']['unicode']); + $name = static::randomString(random_int(10, 40), false, false, $config['spam']['unicode']); } else { // Use a pre-defined confusing name $name = $config['spam']['hidden_input_names'][$hidden_input_names_x++]; - if ($hidden_input_names_x >= count($config['spam']['hidden_input_names'])) + if ($hidden_input_names_x >= (is_countable($config['spam']['hidden_input_names']) ? count($config['spam']['hidden_input_names']) : 0)) $hidden_input_names_x = false; } - if (mt_rand(0, 2) == 0) { + if (random_int(0, 2) == 0) { // Value must be null $this->inputs[$name] = ''; - } elseif (mt_rand(0, 4) == 0) { + } elseif (random_int(0, 4) == 0) { // Numeric value - $this->inputs[$name] = (string)mt_rand(0, 100000); + $this->inputs[$name] = (string)random_int(0, 100000); } else { // Obscure value - $this->inputs[$name] = $this->randomString(mt_rand(5, 100), true, true, $config['spam']['unicode']); + $this->inputs[$name] = static::randomString(random_int(5, 100), true, true, $config['spam']['unicode']); } } } public static function space() { - if (mt_rand(0, 3) != 0) + if (random_int(0, 3) != 0) return ' '; - return str_repeat(' ', mt_rand(1, 3)); + return str_repeat(' ', random_int(1, 3)); } public function html($count = false) { global $config; - $elements = array( - '', - '', - '', - '', - '', - '', - '', - '
', - '
', - '', - '' - ); + $elements = ['', '', '', '', '', '', '', '
', '
', '', '']; $html = ''; if ($count === false) { - $count = mt_rand(1, (int)abs(count($this->inputs) / 15) + 1); + $count = random_int(1, (int)abs((is_countable($this->inputs) ? count($this->inputs) : 0) / 15) + 1); } if ($count === true) { @@ -139,9 +127,9 @@ class AntiBot { while (!$element) { $element = $elements[array_rand($elements)]; $element = str_replace(' ', self::space(), $element); - if (mt_rand(0, 5) == 0) + if (random_int(0, 5) == 0) $element = str_replace('>', self::space() . '>', $element); - if (strpos($element, 'textarea') !== false && $value == '') { + if (str_contains($element, 'textarea') && $value == '') { // There have been some issues with mobile web browsers and empty