pages.php: use modern array syntax

This commit is contained in:
Zankaria 2024-11-04 23:10:54 +01:00
parent 5fa893655d
commit f7fd639d2d

View file

@ -99,7 +99,7 @@ function mod_logout() {
function mod_dashboard() { function mod_dashboard() {
global $config, $mod; global $config, $mod;
$args = array(); $args = [];
$args['boards'] = listBoards(); $args['boards'] = listBoards();
@ -239,7 +239,7 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
$query = str_replace('`', '!`', $query); $query = str_replace('`', '!`', $query);
// Array of phrases to match // Array of phrases to match
$match = array(); $match = [];
// Exact phrases ("like this") // Exact phrases ("like this")
if (preg_match_all('/"(.+?)"/', $query, $exact_phrases)) { if (preg_match_all('/"(.+?)"/', $query, $exact_phrases)) {
@ -772,7 +772,7 @@ function mod_board_log($board, $page_no = 1, $hide_names = false, $public = fals
function mod_view_catalog($boardName) { function mod_view_catalog($boardName) {
global $config, $mod; global $config, $mod;
require_once($config['dir']['themes'].'/catalog/theme.php'); require_once($config['dir']['themes'].'/catalog/theme.php');
$settings = array(); $settings = [];
$settings['boards'] = $boardName; $settings['boards'] = $boardName;
$settings['update_on_posts'] = true; $settings['update_on_posts'] = true;
$settings['title'] = 'Catalog'; $settings['title'] = 'Catalog';
@ -1109,7 +1109,7 @@ function mod_bans() {
if (!hasPermission($config['mod']['unban'])) if (!hasPermission($config['mod']['unban']))
error($config['error']['noaccess']); error($config['error']['noaccess']);
$unban = array(); $unban = [];
foreach ($_POST as $name => $unused) { foreach ($_POST as $name => $unused) {
if (preg_match('/^ban_(\d+)$/', $name, $match)) if (preg_match('/^ban_(\d+)$/', $name, $match))
$unban[] = $match[1]; $unban[] = $match[1];
@ -1198,16 +1198,16 @@ function mod_ban_appeals() {
$query = query(sprintf("SELECT `num_files`, `files` FROM ``posts_%s`` WHERE `id` = " . $query = query(sprintf("SELECT `num_files`, `files` FROM ``posts_%s`` WHERE `id` = " .
(int)$ban['post']['id'], $board['uri'])); (int)$ban['post']['id'], $board['uri']));
if ($_post = $query->fetch(PDO::FETCH_ASSOC)) { if ($_post = $query->fetch(PDO::FETCH_ASSOC)) {
$_post['files'] = $_post['files'] ? json_decode($_post['files']) : array(); $_post['files'] = $_post['files'] ? json_decode($_post['files']) : [];
$ban['post'] = array_merge($ban['post'], $_post); $ban['post'] = array_merge($ban['post'], $_post);
} else { } else {
$ban['post']['files'] = array(array()); $ban['post']['files'] = array([]);
$ban['post']['files'][0]['file'] = 'deleted'; $ban['post']['files'][0]['file'] = 'deleted';
$ban['post']['files'][0]['thumb'] = false; $ban['post']['files'][0]['thumb'] = false;
$ban['post']['num_files'] = 1; $ban['post']['num_files'] = 1;
} }
} else { } else {
$ban['post']['files'] = array(array()); $ban['post']['files'] = array([]);
$ban['post']['files'][0]['file'] = 'deleted'; $ban['post']['files'][0]['file'] = 'deleted';
$ban['post']['files'][0]['thumb'] = false; $ban['post']['files'][0]['thumb'] = false;
$ban['post']['num_files'] = 1; $ban['post']['num_files'] = 1;
@ -1505,7 +1505,7 @@ function mod_move($originBoard, $postID) {
$query->bindValue(':id', $postID, PDO::PARAM_INT); $query->bindValue(':id', $postID, PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
$replies = array(); $replies = [];
while ($post = $query->fetch(PDO::FETCH_ASSOC)) { while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$post['mod'] = true; $post['mod'] = true;
@ -1572,7 +1572,7 @@ function mod_move($originBoard, $postID) {
if (!empty($post['tracked_cites'])) { if (!empty($post['tracked_cites'])) {
$insert_rows = array(); $insert_rows = [];
foreach ($post['tracked_cites'] as $cite) { foreach ($post['tracked_cites'] as $cite) {
$insert_rows[] = '(' . $insert_rows[] = '(' .
$pdo->quote($board['uri']) . ', ' . $newPostID . ', ' . $pdo->quote($board['uri']) . ', ' . $newPostID . ', ' .
@ -1770,7 +1770,7 @@ function mod_merge($originBoard, $postID) {
$query->bindValue(':id', $postID, PDO::PARAM_INT); $query->bindValue(':id', $postID, PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
$replies = array(); $replies = [];
while ($post = $query->fetch(PDO::FETCH_ASSOC)) { while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$post['mod'] = true; $post['mod'] = true;
@ -1833,7 +1833,7 @@ function mod_merge($originBoard, $postID) {
if (!empty($post['tracked_cites'])) { if (!empty($post['tracked_cites'])) {
$insert_rows = array(); $insert_rows = [];
foreach ($post['tracked_cites'] as $cite) { foreach ($post['tracked_cites'] as $cite) {
$insert_rows[] = '(' . $insert_rows[] = '(' .
$pdo->quote($board['uri']) . ', ' . $newPostID . ', ' . $pdo->quote($board['uri']) . ', ' . $newPostID . ', ' .
@ -1954,7 +1954,7 @@ function mod_ban_post($board, $delete, $post, $token = false) {
$name = $mypost["name"]; $name = $mypost["name"];
$subject = $mypost["subject"]; $subject = $mypost["subject"];
$filehash = $mypost["filehash"]; $filehash = $mypost["filehash"];
$mypost['files'] = $mypost['files'] ? json_decode($mypost['files']) : array(); $mypost['files'] = $mypost['files'] ? json_decode($mypost['files']) : [];
// For each file append file name // For each file append file name
for ($file_count = 0; $file_count < $mypost["num_files"];$file_count++){ for ($file_count = 0; $file_count < $mypost["num_files"];$file_count++){
$filename .= $mypost['files'][$file_count]->name . "\r\n"; $filename .= $mypost['files'][$file_count]->name . "\r\n";
@ -2065,7 +2065,7 @@ function mod_warning_post($board,$post, $token = false) {
$name = $mypost["name"]; $name = $mypost["name"];
$subject = $mypost["subject"]; $subject = $mypost["subject"];
$filehash = $mypost["filehash"]; $filehash = $mypost["filehash"];
$mypost['files'] = $mypost['files'] ? json_decode($mypost['files']) : array(); $mypost['files'] = $mypost['files'] ? json_decode($mypost['files']) : [];
// For each file append file name // For each file append file name
for ($file_count = 0; $file_count < $mypost["num_files"];$file_count++){ for ($file_count = 0; $file_count < $mypost["num_files"];$file_count++){
$filename .= $mypost['files'][$file_count]->name . "\r\n"; $filename .= $mypost['files'][$file_count]->name . "\r\n";
@ -2217,7 +2217,7 @@ function mod_delete($board, $post) {
$name = $mypost["name"]; $name = $mypost["name"];
$subject = $mypost["subject"]; $subject = $mypost["subject"];
$filehash = $mypost["filehash"]; $filehash = $mypost["filehash"];
$mypost['files'] = $mypost['files'] ? json_decode($mypost['files']) : array(); $mypost['files'] = $mypost['files'] ? json_decode($mypost['files']) : [];
// For each file append file name // For each file append file name
for ($file_count = 0; $file_count < $mypost["num_files"];$file_count++){ for ($file_count = 0; $file_count < $mypost["num_files"];$file_count++){
$filename .= $mypost['files'][$file_count]->name . "\r\n"; $filename .= $mypost['files'][$file_count]->name . "\r\n";
@ -2364,9 +2364,9 @@ function mod_deletebyip($boardName, $post, $global = false) {
@set_time_limit($config['mod']['rebuild_timelimit']); @set_time_limit($config['mod']['rebuild_timelimit']);
$boards_to_rebuild = array(); $boards_to_rebuild = [];
$threads_to_rebuild = array(); $threads_to_rebuild = [];
$threads_deleted = array(); $threads_deleted = [];
while ($post = $query->fetch(PDO::FETCH_ASSOC)) { while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$boards_to_rebuild[$post['board']] = true; $boards_to_rebuild[$post['board']] = true;
openBoard($post['board']); openBoard($post['board']);
@ -2388,7 +2388,7 @@ function mod_deletebyip($boardName, $post, $global = false) {
$name = $mypost["name"]; $name = $mypost["name"];
$subject = $mypost["subject"]; $subject = $mypost["subject"];
$filehash = $mypost["filehash"]; $filehash = $mypost["filehash"];
$mypost['files'] = $mypost['files'] ? json_decode($mypost['files']) : array(); $mypost['files'] = $mypost['files'] ? json_decode($mypost['files']) : [];
// For each file append file name // For each file append file name
for ($file_count = 0; $file_count < $mypost["num_files"];$file_count++){ for ($file_count = 0; $file_count < $mypost["num_files"];$file_count++){
$filename .= $mypost['files'][$file_count]->name . "\r\n"; $filename .= $mypost['files'][$file_count]->name . "\r\n";
@ -2466,7 +2466,7 @@ function mod_user($uid) {
$board = $board['uri']; $board = $board['uri'];
} }
$boards = array(); $boards = [];
foreach ($_POST as $name => $value) { foreach ($_POST as $name => $value) {
if (preg_match('/^board_(' . $config['board_regex'] . ')$/u', $name, $matches) && in_array($matches[1], $_boards)) if (preg_match('/^board_(' . $config['board_regex'] . ')$/u', $name, $matches) && in_array($matches[1], $_boards))
$boards[] = $matches[1]; $boards[] = $matches[1];
@ -2557,7 +2557,7 @@ function mod_user($uid) {
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
$log = $query->fetchAll(PDO::FETCH_ASSOC); $log = $query->fetchAll(PDO::FETCH_ASSOC);
} else { } else {
$log = array(); $log = [];
} }
$user['boards'] = explode(',', $user['boards']); $user['boards'] = explode(',', $user['boards']);
@ -2590,7 +2590,7 @@ function mod_user_new() {
$board = $board['uri']; $board = $board['uri'];
} }
$boards = array(); $boards = [];
foreach ($_POST as $name => $value) { foreach ($_POST as $name => $value) {
if (preg_match('/^board_(' . $config['board_regex'] . ')$/u', $name, $matches) && in_array($matches[1], $_boards)) if (preg_match('/^board_(' . $config['board_regex'] . ')$/u', $name, $matches) && in_array($matches[1], $_boards))
$boards[] = $matches[1]; $boards[] = $matches[1];
@ -2823,9 +2823,9 @@ function mod_rebuild() {
if (isset($_POST['rebuild'])) { if (isset($_POST['rebuild'])) {
@set_time_limit($config['mod']['rebuild_timelimit']); @set_time_limit($config['mod']['rebuild_timelimit']);
$log = array(); $log = [];
$boards = listBoards(); $boards = listBoards();
$rebuilt_scripts = array(); $rebuilt_scripts = [];
if (isset($_POST['rebuild_cache'])) { if (isset($_POST['rebuild_cache'])) {
if ($config['cache']['enabled']) { if ($config['cache']['enabled']) {
@ -2897,16 +2897,16 @@ function mod_reports() {
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
$reports = $query->fetchAll(PDO::FETCH_ASSOC); $reports = $query->fetchAll(PDO::FETCH_ASSOC);
$report_queries = array(); $report_queries = [];
foreach ($reports as $report) { foreach ($reports as $report) {
if (!isset($report_queries[$report['board']])) if (!isset($report_queries[$report['board']]))
$report_queries[$report['board']] = array(); $report_queries[$report['board']] = [];
$report_queries[$report['board']][] = $report['post']; $report_queries[$report['board']][] = $report['post'];
} }
$report_posts = array(); $report_posts = [];
foreach ($report_queries as $board => $posts) { foreach ($report_queries as $board => $posts) {
$report_posts[$board] = array(); $report_posts[$board] = [];
$query = query(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error()); $query = query(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error());
while ($post = $query->fetch(PDO::FETCH_ASSOC)) { while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
@ -2918,7 +2918,7 @@ function mod_reports() {
$body = ''; $body = '';
foreach ($reports as $report) { foreach ($reports as $report) {
if (!isset($report_posts[$report['board']][$report['post']])) { if (!isset($report_posts[$report['board']][$report['post']])) {
// // Invalid report (post has since been deleted) // Invalid report (post has since been deleted)
$query = prepare("DELETE FROM ``reports`` WHERE `post` = :id AND `board` = :board"); $query = prepare("DELETE FROM ``reports`` WHERE `post` = :id AND `board` = :board");
$query->bindValue(':id', $report['post'], PDO::PARAM_INT); $query->bindValue(':id', $report['post'], PDO::PARAM_INT);
$query->bindValue(':board', $report['board']); $query->bindValue(':board', $report['board']);
@ -3014,7 +3014,7 @@ function mod_recent_posts($lim,$board_list = false,$json=false) {
$limit = (is_numeric($lim))? $lim : 25; $limit = (is_numeric($lim))? $lim : 25;
$last_time = (isset($_GET['last']) && is_numeric($_GET['last'])) ? $_GET['last'] : 0; $last_time = (isset($_GET['last']) && is_numeric($_GET['last'])) ? $_GET['last'] : 0;
$mod_boards = array(); $mod_boards = [];
$boards = listBoards(); $boards = listBoards();
//if not all boards //if not all boards
@ -3028,7 +3028,7 @@ function mod_recent_posts($lim,$board_list = false,$json=false) {
} }
if ($board_list != false){ if ($board_list != false){
$board_array = explode(",",$board_list); $board_array = explode(",",$board_list);
$new_board_array = array(); $new_board_array = [];
foreach ($board_array as $board) { foreach ($board_array as $board) {
if (array_key_exists($board,$config['boards_alias'])){ if (array_key_exists($board,$config['boards_alias'])){
$newboard = $config['boards_alias'][$board]; $newboard = $config['boards_alias'][$board];
@ -3038,7 +3038,7 @@ function mod_recent_posts($lim,$board_list = false,$json=false) {
} }
$new_board_array[] = $newboard; $new_board_array[] = $newboard;
} }
$mod_boards = array(); $mod_boards = [];
foreach ($boards as $board) { foreach ($boards as $board) {
if (in_array($board['uri'], $new_board_array)){ if (in_array($board['uri'], $new_board_array)){
$mod_boards[] = $board; $mod_boards[] = $board;
@ -3059,7 +3059,7 @@ function mod_recent_posts($lim,$board_list = false,$json=false) {
$posts = $query->fetchAll(PDO::FETCH_ASSOC); $posts = $query->fetchAll(PDO::FETCH_ASSOC);
if ($config['api']['enabled']) { if ($config['api']['enabled']) {
$apithreads = array(); $apithreads = [];
} }
foreach ($posts as &$post) { foreach ($posts as &$post) {
@ -3215,7 +3215,7 @@ function mod_config($board_config = false) {
if ($config['minify_html']) if ($config['minify_html'])
$config_append = str_replace("\n", '&#010;', $config_append); $config_append = str_replace("\n", '&#010;', $config_append);
$page = array(); $page = [];
$page['title'] = 'Cannot write to file!'; $page['title'] = 'Cannot write to file!';
$page['config'] = $config; $page['config'] = $config;
$page['body'] = ' $page['body'] = '
@ -3258,7 +3258,7 @@ function mod_themes_list() {
$themes_in_use = $query->fetchAll(PDO::FETCH_COLUMN); $themes_in_use = $query->fetchAll(PDO::FETCH_COLUMN);
// Scan directory for themes // Scan directory for themes
$themes = array(); $themes = [];
while ($file = readdir($dir)) { while ($file = readdir($dir)) {
if ($file[0] != '.' && is_dir($config['dir']['themes'] . '/' . $file)) { if ($file[0] != '.' && is_dir($config['dir']['themes'] . '/' . $file)) {
$themes[$file] = loadThemeConfig($file); $themes[$file] = loadThemeConfig($file);
@ -3553,7 +3553,7 @@ function mod_pages($board = false) {
function mod_debug_antispam() { function mod_debug_antispam() {
global $pdo, $config; global $pdo, $config;
$args = array(); $args = [];
if (isset($_POST['board'], $_POST['thread'])) { if (isset($_POST['board'], $_POST['thread'])) {
$where = '`board` = ' . $pdo->quote($_POST['board']); $where = '`board` = ' . $pdo->quote($_POST['board']);
@ -3657,7 +3657,7 @@ function mod_debug_apc() {
$cache_info = apc_cache_info('user'); $cache_info = apc_cache_info('user');
// $cached_vars = new APCIterator('user', '/^' . $config['cache']['prefix'] . '/'); // $cached_vars = new APCIterator('user', '/^' . $config['cache']['prefix'] . '/');
$cached_vars = array(); $cached_vars = [];
foreach ($cache_info['cache_list'] as $var) { foreach ($cache_info['cache_list'] as $var) {
if ($config['cache']['prefix'] != '' && strpos(isset($var['key']) ? $var['key'] : $var['info'], $config['cache']['prefix']) !== 0) if ($config['cache']['prefix'] != '' && strpos(isset($var['key']) ? $var['key'] : $var['info'], $config['cache']['prefix']) !== 0)
continue; continue;