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/display.php | 73 ++++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 43 deletions(-) (limited to 'inc/display.php') diff --git a/inc/display.php b/inc/display.php index f702d7f8..cbe2fb0e 100644 --- a/inc/display.php +++ b/inc/display.php @@ -14,7 +14,7 @@ if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) { http://www.php.net/manual/en/function.filesize.php#100097 */ function format_bytes($size) { - $units = array(' B', ' KB', ' MB', ' GB', ' TB'); + $units = [' B', ' KB', ' MB', ' GB', ' TB']; for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024; return round($size, 2).$units[$i]; } @@ -58,46 +58,33 @@ function doBoardListPart($list, $root, &$boards) { function createBoardlist($mod=false) { global $config; - if (!isset($config['boards'])) return array('top'=>'','bottom'=>''); + if (!isset($config['boards'])) return ['top'=>'', 'bottom'=>'']; $xboards = listBoards(); - $boards = array(); + $boards = []; foreach ($xboards as $val) { $boards[$val['uri']] = $val['title']; } $body = doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards); - if ($config['boardlist_wrap_bracket'] && !preg_match('/\] $/', $body)) + if ($config['boardlist_wrap_bracket'] && !preg_match('/\] $/', (string) $body)) $body = '[' . $body . ']'; - $body = trim($body); + $body = trim((string) $body); // Message compact-boardlist.js faster, so that page looks less ugly during loading $top = ""; - return array( - 'top' => '
' . $body . '
' . $top, - 'bottom' => '
' . $body . '
' - ); + return ['top' => '
' . $body . '
' . $top, 'bottom' => '
' . $body . '
']; } -function loginForm($error=false, $username=false, $redirect=false) { +function loginForm($error=false, $username=false, $redirect=false): never { global $config; - die(Element('page.html', array( - 'index' => $config['root'], - 'title' => _('Login'), - 'config' => $config, - 'body' => Element('login.html', array( - 'config'=>$config, - 'error'=>$error, - 'username'=>utf8tohtml($username), - 'redirect'=>$redirect - ) - ) - ))); + die(Element('page.html', ['index' => $config['root'], 'title' => _('Login'), 'config' => $config, 'body' => Element('login.html', ['config'=>$config, 'error'=>$error, 'username'=>utf8tohtml($username), 'redirect'=>$redirect] + )])); } function pm_snippet($body, $len=null) { @@ -143,7 +130,7 @@ function capcode($cap) { if (!$cap) return false; - $capcode = array(); + $capcode = []; if (isset($config['custom_capcode'][$cap])) { if (is_array($config['custom_capcode'][$cap])) { $capcode['cap'] = sprintf($config['custom_capcode'][$cap][0], $cap); @@ -183,7 +170,7 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) { $body = $m[0]; } - $body = mb_substr($body, 0, $max_chars); + $body = mb_substr((string) $body, 0, $max_chars); if ($body != $original_body) { // Remove any corrupt tags at the end @@ -192,15 +179,15 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) { // Open tags if (preg_match_all('/<([\w]+)[^>]*>/', $body, $open_tags)) { - $tags = array(); - for ($x=0;$x$/', $open_tags[0][$x])) + $tags = []; + for ($x=0;$x<(is_countable($open_tags[0]) ? count($open_tags[0]) : 0);$x++) { + if (!preg_match('/\/(\s+)?>$/', (string) $open_tags[0][$x])) $tags[] = $open_tags[1][$x]; } // List successfully closed tags if (preg_match_all('/(<\/([\w]+))>/', $body, $closed_tags)) { - for ($x=0;$x' . $text . ''; + return '' . $text . ''; } function secure_link($href) { return $href . '/' . make_secure_link_token($href); @@ -315,7 +302,7 @@ class Post { } if (isset($this->files) && $this->files) - $this->files = @json_decode($this->files); + $this->files = @json_decode((string) $this->files, null, 512, JSON_THROW_ON_ERROR); $this->subject = utf8tohtml($this->subject); $this->name = utf8tohtml($this->name); @@ -336,7 +323,7 @@ class Post { // Fix internal links // Very complicated regex $this->body = preg_replace( - '/name = utf8tohtml($this->name ?? ""); @@ -373,7 +360,7 @@ class Thread { $this->root = $root; $this->hr = $hr; - $this->posts = array(); + $this->posts = []; $this->omitted = 0; $this->omitted_images = 0; @@ -391,7 +378,7 @@ class Thread { // Fix internal links // Very complicated regex $this->body = preg_replace( - '/