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 --- templates/themes/basic/info.php | 38 ++------- templates/themes/basic/theme.php | 7 +- templates/themes/calendar/calendarpost.php | 2 +- templates/themes/calendar/info.php | 27 ++---- templates/themes/calendar/theme.php | 6 +- templates/themes/catalog/info.php | 87 ++++---------------- templates/themes/catalog/theme.php | 96 ++++++++-------------- templates/themes/categories-uboachan/info.php | 20 ++--- templates/themes/categories-uboachan/theme.php | 9 +- templates/themes/categories/info.php | 47 +++-------- templates/themes/categories/theme.php | 17 +--- templates/themes/donate/donate.html | 2 +- templates/themes/donate/info.php | 79 +----------------- templates/themes/donate/theme.php | 4 +- templates/themes/faq/info.php | 27 ++---- templates/themes/faq/theme.php | 6 +- templates/themes/frameset/info.php | 53 +++--------- templates/themes/frameset/theme.php | 14 +--- templates/themes/irc/info.php | 37 +-------- templates/themes/irc/theme.php | 4 +- templates/themes/public_banlist/info.php | 20 +---- templates/themes/public_banlist/theme.php | 28 +++---- templates/themes/radio/info.php | 57 +------------ templates/themes/radio/theme.php | 4 +- templates/themes/rand/info.php | 40 ++------- templates/themes/rand/theme.php | 28 ++----- templates/themes/recent/info.php | 74 ++++------------- templates/themes/recent/theme.php | 27 +++--- templates/themes/rss/info.php | 58 +++---------- templates/themes/rss/theme.php | 32 +++----- templates/themes/rules/info.php | 22 +---- templates/themes/rules/theme.php | 6 +- templates/themes/semirand/info.php | 66 +++------------ templates/themes/semirand/theme.php | 42 +++------- templates/themes/sitemap/info.php | 50 ++--------- templates/themes/sitemap/theme.php | 13 +-- templates/themes/staffapplication/info.php | 27 ++---- .../staffapplication/staffapplicationpost.php | 8 +- templates/themes/staffapplication/theme.php | 6 +- templates/themes/stream/info.php | 90 ++++---------------- templates/themes/stream/theme.php | 6 +- templates/themes/ukko/info.php | 42 ++-------- templates/themes/ukko/theme.php | 45 ++++------ templates/themes/ukko2/info.php | 42 ++-------- templates/themes/ukko2/theme.php | 45 ++++------ templates/themes/ukko3/info.php | 42 ++-------- templates/themes/ukko3/theme.php | 45 ++++------ templates/themes/ukko4/info.php | 42 ++-------- templates/themes/ukko4/theme.php | 45 ++++------ templates/themes/zine/info.php | 22 +---- templates/themes/zine/theme.php | 4 +- 51 files changed, 352 insertions(+), 1308 deletions(-) (limited to 'templates') diff --git a/templates/themes/basic/info.php b/templates/themes/basic/info.php index 0b8ba98b..982010ef 100644 --- a/templates/themes/basic/info.php +++ b/templates/themes/basic/info.php @@ -1,44 +1,22 @@ 'Site title', - 'name' => 'title', - 'type' => 'text' - ); + $theme['config'][] = ['title' => 'Site title', 'name' => 'title', 'type' => 'text']; - $theme['config'][] = Array( - 'title' => 'Slogan', - 'name' => 'subtitle', - 'type' => 'text', - 'comment' => '(optional)' - ); + $theme['config'][] = ['title' => 'Slogan', 'name' => 'subtitle', 'type' => 'text', 'comment' => '(optional)']; - $theme['config'][] = Array( - 'title' => 'File', - 'name' => 'file', - 'type' => 'text', - 'default' => $config['file_index'], - 'comment' => '(eg. "index.html")' - ); + $theme['config'][] = ['title' => 'File', 'name' => 'file', 'type' => 'text', 'default' => $config['file_index'], 'comment' => '(eg. "index.html")']; - $theme['config'][] = Array( - 'title' => '# of recent entries', - 'name' => 'no_recent', - 'type' => 'text', - 'default' => 0, - 'size' => 3, - 'comment' => '(number of recent news entries to display; "0" is infinite)' - ); + $theme['config'][] = ['title' => '# of recent entries', 'name' => 'no_recent', 'type' => 'text', 'default' => 0, 'size' => 3, 'comment' => '(number of recent news entries to display; "0" is infinite)']; // Unique function name for building everything $theme['build_function'] = 'basic_build'; @@ -47,7 +25,7 @@ if (!function_exists('build_install')) { function build_install($settings) { if (!is_numeric($settings['no_recent']) || $settings['no_recent'] < 0) - return Array(false, '' . utf8tohtml($settings['no_recent']) . ' is not a non-negative integer.'); + return [false, '' . utf8tohtml($settings['no_recent']) . ' is not a non-negative integer.']; } } diff --git a/templates/themes/basic/theme.php b/templates/themes/basic/theme.php index 6ba09ce6..4d79d73f 100644 --- a/templates/themes/basic/theme.php +++ b/templates/themes/basic/theme.php @@ -28,12 +28,7 @@ $query = query("SELECT * FROM ``news`` ORDER BY `time` DESC" . ($settings['no_recent'] ? ' LIMIT ' . $settings['no_recent'] : '')) or error(db_error()); $news = $query->fetchAll(PDO::FETCH_ASSOC); - return Element('themes/basic/index.html', Array( - 'settings' => $settings, - 'config' => $config, - 'boardlist' => createBoardlist(), - 'news' => $news - )); + return Element('themes/basic/index.html', ['settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'news' => $news]); } }; diff --git a/templates/themes/calendar/calendarpost.php b/templates/themes/calendar/calendarpost.php index 5293a881..ac2c1a72 100644 --- a/templates/themes/calendar/calendarpost.php +++ b/templates/themes/calendar/calendarpost.php @@ -51,7 +51,7 @@ $method = $_SERVER['REQUEST_METHOD']; } elseif ($method == 'GET') { // Method is GET $query = query("SELECT * FROM calendar_events ORDER BY id") or error(db_error()); - echo json_encode($query->fetchAll(PDO::FETCH_ASSOC)); + echo json_encode($query->fetchAll(PDO::FETCH_ASSOC), JSON_THROW_ON_ERROR); } ?> diff --git a/templates/themes/calendar/info.php b/templates/themes/calendar/info.php index 0687a26d..6d770601 100644 --- a/templates/themes/calendar/info.php +++ b/templates/themes/calendar/info.php @@ -1,35 +1,20 @@ 'Site title', - 'name' => 'title', - 'type' => 'text' - ); + $theme['config'][] = ['title' => 'Site title', 'name' => 'title', 'type' => 'text']; - $theme['config'][] = Array( - 'title' => 'Slogan', - 'name' => 'subtitle', - 'type' => 'text', - 'comment' => '(optional)' - ); + $theme['config'][] = ['title' => 'Slogan', 'name' => 'subtitle', 'type' => 'text', 'comment' => '(optional)']; - $theme['config'][] = Array( - 'title' => 'File', - 'name' => 'file', - 'type' => 'text', - 'default' => $config['file_index'], - 'comment' => '(eg. "index.html")' - ); + $theme['config'][] = ['title' => 'File', 'name' => 'file', 'type' => 'text', 'default' => $config['file_index'], 'comment' => '(eg. "index.html")']; // Unique function name for building everything $theme['build_function'] = 'calendar_build'; diff --git a/templates/themes/calendar/theme.php b/templates/themes/calendar/theme.php index 8e9d32db..b39729ed 100644 --- a/templates/themes/calendar/theme.php +++ b/templates/themes/calendar/theme.php @@ -24,11 +24,7 @@ public static function htmlpage($settings) { global $config; - return Element('themes/calendar/calendar.html', Array( - 'settings' => $settings, - 'config' => $config, - 'boardlist' => createBoardlist() - )); + return Element('themes/calendar/calendar.html', ['settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist()]); } public static function phppage($settings) { global $config; diff --git a/templates/themes/catalog/info.php b/templates/themes/catalog/info.php index bc0e7eb5..cf0d42ab 100644 --- a/templates/themes/catalog/info.php +++ b/templates/themes/catalog/info.php @@ -1,96 +1,37 @@ 'Title', - 'name' => 'title', - 'type' => 'text', - 'default' => 'Catalog' - ); + $theme['config'][] = ['title' => 'Title', 'name' => 'title', 'type' => 'text', 'default' => \Catalog::class]; $__boards = listBoards(); - $__default_boards = Array(); + $__default_boards = []; foreach ($__boards as $__board) $__default_boards[] = $__board['uri']; - $theme['config'][] = Array( - 'title' => 'Included boards', - 'name' => 'boards', - 'type' => 'text', - 'comment' => '(space seperated)', - 'default' => implode(' ', $__default_boards) - ); + $theme['config'][] = ['title' => 'Included boards', 'name' => 'boards', 'type' => 'text', 'comment' => '(space seperated)', 'default' => implode(' ', $__default_boards)]; - $theme['config'][] = Array( - 'title' => 'Update on new posts', - 'name' => 'update_on_posts', - 'type' => 'checkbox', - 'default' => false, - 'comment' => 'Without this checked, the catalog only updates on new threads.' - ); + $theme['config'][] = ['title' => 'Update on new posts', 'name' => 'update_on_posts', 'type' => 'checkbox', 'default' => false, 'comment' => 'Without this checked, the catalog only updates on new threads.']; - $theme['config'][] = Array( - 'title' => 'Enable Ukko catalog', - 'name' => 'enable_ukko', - 'type' => 'checkbox', - 'default' => false, - 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko theme to be enabled.' - ); + $theme['config'][] = ['title' => 'Enable Ukko catalog', 'name' => 'enable_ukko', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko theme to be enabled.']; - $theme['config'][] = Array( - 'title' => 'Enable Ukko2 catalog', - 'name' => 'enable_ukko2', - 'type' => 'checkbox', - 'default' => false, - 'comment' => 'Enable catalog for the Ukko2 theme. This requires the Ukko2 theme to be enabled.' - ); + $theme['config'][] = ['title' => 'Enable Ukko2 catalog', 'name' => 'enable_ukko2', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Ukko2 theme. This requires the Ukko2 theme to be enabled.']; - $theme['config'][] = Array( - 'title' => 'Enable Ukko3 catalog', - 'name' => 'enable_ukko3', - 'type' => 'checkbox', - 'default' => false, - 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko3 theme to be enabled.' - ); - $theme['config'][] = Array( - 'title' => 'Enable Ukko4 catalog', - 'name' => 'enable_ukko4', - 'type' => 'checkbox', - 'default' => false, - 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko4 theme to be enabled.' - ); + $theme['config'][] = ['title' => 'Enable Ukko3 catalog', 'name' => 'enable_ukko3', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko3 theme to be enabled.']; + $theme['config'][] = ['title' => 'Enable Ukko4 catalog', 'name' => 'enable_ukko4', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko4 theme to be enabled.']; - $theme['config'][] = Array( - 'title' => 'Enable Rand catalog', - 'name' => 'enable_rand', - 'type' => 'checkbox', - 'default' => false, - 'comment' => 'Enable catalog for the Rand theme. This requires the Rand theme to be enabled.' - ); - $theme['config'][] = Array( - 'title' => 'Use tooltipster', - 'name' => 'use_tooltipster', - 'type' => 'checkbox', - 'default' => true, - 'comment' => 'Check this if you wish to show a nice tooltip with info about the thread on mouse over.' - ); + $theme['config'][] = ['title' => 'Enable Rand catalog', 'name' => 'enable_rand', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Rand theme. This requires the Rand theme to be enabled.']; + $theme['config'][] = ['title' => 'Use tooltipster', 'name' => 'use_tooltipster', 'type' => 'checkbox', 'default' => true, 'comment' => 'Check this if you wish to show a nice tooltip with info about the thread on mouse over.']; - $theme['config'][] = Array( - 'title' => 'Base URL', - 'name' => 'base_url', - 'type' => 'text', - 'default' => 'http://test.com', - 'comment' => '(eg. "http://test.com")' - ); + $theme['config'][] = ['title' => 'Base URL', 'name' => 'base_url', 'type' => 'text', 'default' => 'http://test.com', 'comment' => '(eg. "http://test.com")']; // Unique function name for building everything $theme['build_function'] = 'catalog_build'; diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index 1b55d56e..f4c59681 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -5,7 +5,7 @@ global $config; $b = new Catalog($settings); - $boards = explode(' ', $settings['boards']); + $boards = explode(' ', (string) $settings['boards']); // Possible values for $action: // - all (rebuild everything, initialization) @@ -17,7 +17,7 @@ foreach ($boards as $board) { $b = new Catalog($settings); - $action = generation_strategy("sb_catalog", array($board)); + $action = generation_strategy("sb_catalog", [$board]); if ($action == 'delete') { file_unlink($config['dir']['home'] . $board . '/catalog.html'); file_unlink($config['dir']['home'] . $board . '/index.rss'); @@ -30,7 +30,7 @@ || $action == 'sticky' || ($action == 'lock' && in_array($board, $boards))) { $b = new Catalog($settings); - $action = generation_strategy("sb_catalog", array($board)); + $action = generation_strategy("sb_catalog", [$board]); if ($action == 'delete') { file_unlink($config['dir']['home'] . $board . '/catalog.html'); file_unlink($config['dir']['home'] . $board . '/index.rss'); @@ -82,13 +82,12 @@ // Wrap functions in a class so they don't interfere with normal Tinyboard operations class Catalog { - private $settings; // Cache for threads from boards that have already been processed - private $threadsCache = array(); + private array $threadsCache = []; - public function __construct($settings) { - $this->settings = $settings; - } + public function __construct(private $settings) + { + } /** * Build and save the HTML of the catalog for the Ukko theme @@ -97,10 +96,10 @@ global $config; $ukkoSettings = themeSettings('ukko'); - $queries = array(); - $threads = array(); + $queries = []; + $threads = []; - $exclusions = explode(' ', $ukkoSettings['exclude']); + $exclusions = explode(' ', (string) $ukkoSettings['exclude']); $boards = array_diff(listBoards(true), $exclusions); foreach ($boards as $b) { @@ -119,9 +118,7 @@ } // Sort in bump order - usort($threads, function($a, $b) { - return strcmp($b['bump'], $a['bump']); - }); + usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump'])); // Generate data for the template $recent_posts = $this->generateRecentPosts($threads); @@ -134,10 +131,10 @@ public function buildUkko2() { global $config; $ukkoSettings = themeSettings('ukko2'); - $queries = array(); - $threads = array(); + $queries = []; + $threads = []; - $inclusions = explode(' ', $ukkoSettings['include']); + $inclusions = explode(' ', (string) $ukkoSettings['include']); $boards = array_intersect(listBoards(true), $inclusions); foreach ($boards as $b) { @@ -156,9 +153,7 @@ } // Sort in bump order - usort($threads, function($a, $b) { - return strcmp($b['bump'], $a['bump']); - }); + usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump'])); // Generate data for the template $recent_posts = $this->generateRecentPosts($threads); @@ -173,10 +168,10 @@ global $config; $ukkoSettings = themeSettings('ukko3'); - $queries = array(); - $threads = array(); + $queries = []; + $threads = []; - $inclusions = explode(' ', $ukkoSettings['include']); + $inclusions = explode(' ', (string) $ukkoSettings['include']); $boards = array_intersect(listBoards(true), $inclusions); foreach ($boards as $b) { @@ -195,9 +190,7 @@ } // Sort in bump order - usort($threads, function($a, $b) { - return strcmp($b['bump'], $a['bump']); - }); + usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump'])); // Generate data for the template $recent_posts = $this->generateRecentPosts($threads); @@ -212,10 +205,10 @@ global $config; $ukkoSettings = themeSettings('ukko4'); - $queries = array(); - $threads = array(); + $queries = []; + $threads = []; - $exclusions = explode(' ', $ukkoSettings['exclude']); + $exclusions = explode(' ', (string) $ukkoSettings['exclude']); $boards = array_diff(listBoards(true), $exclusions); foreach ($boards as $b) { @@ -234,9 +227,7 @@ } // Sort in bump order - usort($threads, function($a, $b) { - return strcmp($b['bump'], $a['bump']); - }); + usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump'])); // Generate data for the template $recent_posts = $this->generateRecentPosts($threads); @@ -250,10 +241,10 @@ global $config; $randSettings = themeSettings('rand'); - $queries = array(); - $threads = array(); + $queries = []; + $threads = []; - $exclusions = explode(' ', $randSettings['exclude']); + $exclusions = explode(' ', (string) $randSettings['exclude']); $boards = array_diff(listBoards(true), $exclusions); foreach ($boards as $b) { @@ -272,9 +263,7 @@ } // Sort in bump order - usort($threads, function($a, $b) { - return strcmp($b['bump'], $a['bump']); - }); + usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump'])); // Generate data for the template $recent_posts = $this->generateRecentPosts($threads); @@ -321,7 +310,7 @@ private function generateRecentPosts($threads) { global $config, $board; - $posts = array(); + $posts = []; foreach ($threads as $post) { if ($board['uri'] !== $post['board']) { openBoard($post['board']); @@ -330,16 +319,16 @@ $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post); $post['board_name'] = $board['name']; - if ($post['embed'] && preg_match('/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) { + if ($post['embed'] && preg_match('/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i', (string) $post['embed'], $matches)) { $post['youtube'] = $matches[2]; } if (isset($post['files']) && $post['files']) { - $files = json_decode($post['files']); + $files = json_decode((string) $post['files'], null, 512, JSON_THROW_ON_ERROR); if ($files[0]) { if ($files[0]->file == 'deleted') { - if (count($files) > 1) { + if ((is_countable($files) ? count($files) : 0) > 1) { foreach ($files as $file) { if (($file == $files[0]) || ($file->file == 'deleted')) continue; @@ -378,8 +367,7 @@ $board_link = $config['root'] . $board['dir']; } - $required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js', - 'js/catalog.js'); + $required_scripts = ['js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js']; // Include scripts that haven't been yet included foreach($required_scripts as $i => $s) { @@ -387,22 +375,8 @@ $config['additional_javascript'][] = $s; } - file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', Array( - 'settings' => $this->settings, - 'config' => $config, - 'boardlist' => createBoardlist(), - 'recent_images' => array(), - 'recent_posts' => $recent_posts, - 'stats' => array(), - 'board' => $board_name, - 'link' => $board_link - ))); - - file_write($config['dir']['home'] . $board_name . '/index.rss', Element('themes/catalog/index.rss', Array( - 'settings' => $this->settings, - 'config' => $config, - 'recent_posts' => $recent_posts, - 'board' => $board - ))); + file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', ['settings' => $this->settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => [], 'recent_posts' => $recent_posts, 'stats' => [], 'board' => $board_name, 'link' => $board_link])); + + file_write($config['dir']['home'] . $board_name . '/index.rss', Element('themes/catalog/index.rss', ['settings' => $this->settings, 'config' => $config, 'recent_posts' => $recent_posts, 'board' => $board])); } } diff --git a/templates/themes/categories-uboachan/info.php b/templates/themes/categories-uboachan/info.php index 3ef9871f..99177e8f 100644 --- a/templates/themes/categories-uboachan/info.php +++ b/templates/themes/categories-uboachan/info.php @@ -1,5 +1,5 @@ 'Title', - 'name' => 'title', - 'type' => 'text' - ); + $theme['config'][] = ['title' => 'Title', 'name' => 'title', 'type' => 'text']; - $theme['config'][] = Array( - 'title' => 'Slogan', - 'name' => 'subtitle', - 'type' => 'text' - ); + $theme['config'][] = ['title' => 'Slogan', 'name' => 'subtitle', 'type' => 'text']; // Unique function name for building everything $theme['build_function'] = 'categories_build'; @@ -34,8 +26,8 @@ Requires $config[\'boards\'] and $config[\'categories\'].'; global $config; if(!isset($config['boards']) || !isset($config['categories'])) { - return Array(false, '

Prerequisites not met!

' . - 'This theme requires $config[\'boards\'] and $config[\'categories\'] to be set.'); + return [false, '

Prerequisites not met!

' . + 'This theme requires $config[\'boards\'] and $config[\'categories\'] to be set.']; } } } diff --git a/templates/themes/categories-uboachan/theme.php b/templates/themes/categories-uboachan/theme.php index 296e0d06..3c735ec4 100644 --- a/templates/themes/categories-uboachan/theme.php +++ b/templates/themes/categories-uboachan/theme.php @@ -105,7 +105,7 @@ openBoard($post['board']); $body .= '' . $board['name'] . ': '; $snip = pm_snippet($post['body'], 95); if($snip === "") @@ -136,10 +136,7 @@ : '' ) . - ($news['subject'] ? - $news['subject'] - : - 'no subject' + ($news['subject'] ?: 'no subject' ) . ' — by ' . $news['name'] . @@ -190,7 +187,7 @@ '
  • [YB] [Y] [U] [UG] [RZ]
  • '. ''; - for($cat = 0; $cat < count($config['categories']); $cat++) { + for($cat = 0; $cat < (is_countable($config['categories']) ? count($config['categories']) : 0); $cat++) { $body .= '
    ' . $config['categories'][$cat] . '