diff --git a/admin/admin_attach_cp.php b/admin/admin_attach_cp.php index 47a8fbacd..a05774157 100644 --- a/admin/admin_attach_cp.php +++ b/admin/admin_attach_cp.php @@ -158,8 +158,8 @@ if ($confirm && count($delete_id_list) > 0) { $hidden_fields .= ''; $hidden_fields .= ''; - for ($i = 0, $iMax = count($delete_id_list); $i < $iMax; $i++) { - $hidden_fields .= ''; + foreach ($delete_id_list as $iValue) { + $hidden_fields .= ''; } print_confirmation(array( @@ -382,8 +382,8 @@ if ($view === 'attachments') { for ($i = 0, $iMax = count($attachments); $i < $iMax; $i++) { $delete_box = ''; - for ($j = 0, $jMax = count($delete_id_list); $j < $jMax; $j++) { - if ($delete_id_list[$j] == $attachments[$i]['attach_id']) { + foreach ($delete_id_list as $jValue) { + if ($jValue == $attachments[$i]['attach_id']) { $delete_box = ''; break; } diff --git a/admin/admin_attachments.php b/admin/admin_attachments.php index 0f615fe37..a2890b979 100644 --- a/admin/admin_attachments.php +++ b/admin/admin_attachments.php @@ -133,23 +133,25 @@ $select_pm_size_mode = size_select('pm_size', $pm_size); if ($search_imagick) { $imagick = ''; - if (preg_match('/convert/i', $imagick)) { + if (false !== stripos($imagick, "convert")) { return true; - } elseif ($imagick != 'none') { - if (!preg_match('/WIN/i', PHP_OS)) { + } + + if ($imagick != 'none') { + if (!false !== stripos(PHP_OS, "WIN")) { $retval = @exec('whereis convert'); $paths = explode(' ', $retval); if (is_array($paths)) { - for ($i = 0, $iMax = count($paths); $i < $iMax; $i++) { + foreach ($paths as $i => $iValue) { $path = basename($paths[$i]); if ($path == 'convert') { - $imagick = $paths[$i]; + $imagick = $iValue; } } } - } elseif (preg_match('/WIN/i', PHP_OS)) { + } elseif (false !== stripos(PHP_OS, "WIN")) { $path = 'c:/imagemagick/convert.exe'; if (!@file_exists(amod_realpath($path))) { @@ -344,7 +346,9 @@ if ($check_image_cat) { // Does the target directory exist, is it a directory and writeable if (!@file_exists(amod_realpath($upload_dir))) { - mkdir($upload_dir, 0755); + if (!mkdir($upload_dir, 0755) && !is_dir($upload_dir)) { + throw new \RuntimeException(sprintf('Directory "%s" was not created', $upload_dir)); + } @chmod($upload_dir, 0777); if (!@file_exists(amod_realpath($upload_dir))) { diff --git a/admin/admin_extensions.php b/admin/admin_extensions.php index ea4f61631..f40e548d9 100644 --- a/admin/admin_extensions.php +++ b/admin/admin_extensions.php @@ -238,9 +238,9 @@ if ($submit && $mode == 'groups') { $allowed_list = array(); - for ($i = 0, $iMax = count($group_allowed_list); $i < $iMax; $i++) { + foreach ($group_allowed_list as $iValue) { for ($j = 0, $jMax = count($group_change_list); $j < $jMax; $j++) { - if ($group_allowed_list[$i] == $group_change_list[$j]) { + if ($iValue == $group_change_list[$j]) { $allowed_list[$j] = 1; } } @@ -456,8 +456,8 @@ if ($add_forum && $e_mode == 'perm' && $group) { $add_forums_list = get_var('entries', array(0)); $add_all_forums = false; - for ($i = 0, $iMax = count($add_forums_list); $i < $iMax; $i++) { - if ($add_forums_list[$i] == 0) { + foreach ($add_forums_list as $iValue) { + if ($iValue == 0) { $add_all_forums = true; } } @@ -491,9 +491,9 @@ if ($add_forum && $e_mode == 'perm' && $group) { } // Generate array for Auth_Pack, do not add doubled forums - for ($i = 0, $iMax = count($add_forums_list); $i < $iMax; $i++) { + foreach ($add_forums_list as $i => $iValue) { if (!in_array($add_forums_list[$i], $auth_p)) { - $auth_p[] = $add_forums_list[$i]; + $auth_p[] = $iValue; } } @@ -528,9 +528,9 @@ if ($delete_forum && $e_mode == 'perm' && $group) { $auth_p = array(); // Generate array for Auth_Pack, delete the chosen ones - for ($i = 0, $iMax = count($auth_p2); $i < $iMax; $i++) { + foreach ($auth_p2 as $i => $iValue) { if (!in_array($auth_p2[$i], $delete_forums_list)) { - $auth_p[] = $auth_p2[$i]; + $auth_p[] = $iValue; } } diff --git a/admin/admin_forums.php b/admin/admin_forums.php index 6b541fdca..5ab972ed3 100644 --- a/admin/admin_forums.php +++ b/admin/admin_forums.php @@ -45,7 +45,7 @@ $forumname = ''; if (isset($_REQUEST['addforum']) || isset($_REQUEST['addcategory'])) { $mode = isset($_REQUEST['addforum']) ? 'addforum' : 'addcat'; - if ($mode == 'addforum' && isset($_POST['addforum']) && isset($_POST['forumname']) && is_array($_POST['addforum'])) { + if (isset($_POST['addforum'], $_POST['forumname']) && $mode == 'addforum' && is_array($_POST['addforum'])) { $req_cat_id = array_keys($_POST['addforum']); $cat_id = reset($req_cat_id); $forumname = stripslashes($_POST['forumname'][$cat_id]); @@ -567,7 +567,9 @@ if ($mode) { if ($forum_info['forum_parent'] && $prev_forum['forum_parent'] != $forum_info['forum_parent']) { $show_main_page = true; break; - } elseif ($move_down_forum_id = get_prev_root_forum_id($forums, $forum_order)) { + } + + if ($move_down_forum_id = get_prev_root_forum_id($forums, $forum_order)) { $move_up_forum_id = $forum_id; $move_down_ord_val = (get_sf_count($forum_id) + 1) * 10; $move_up_ord_val = ((get_sf_count($move_down_forum_id) + 1) * 10) + $move_down_ord_val; @@ -578,7 +580,9 @@ if ($mode) { if ($forum_info['forum_parent'] && $next_forum['forum_parent'] != $forum_info['forum_parent']) { $show_main_page = true; break; - } elseif ($move_up_forum_id = get_next_root_forum_id($forums, $forum_order)) { + } + + if ($move_up_forum_id = get_next_root_forum_id($forums, $forum_order)) { $move_down_forum_id = $forum_id; $move_down_forum_order = $forum_order; $move_down_ord_val = (get_sf_count($move_up_forum_id) + 1) * 10; diff --git a/admin/admin_phpinfo.php b/admin/admin_phpinfo.php index bad4a8286..dc909493f 100644 --- a/admin/admin_phpinfo.php +++ b/admin/admin_phpinfo.php @@ -14,4 +14,5 @@ if (!empty($setmodules)) { require __DIR__ . '/pagestart.php'; +/** @noinspection ForgottenDebugOutputInspection */ phpinfo(); diff --git a/admin/admin_smilies.php b/admin/admin_smilies.php index 856655200..196d209e2 100644 --- a/admin/admin_smilies.php +++ b/admin/admin_smilies.php @@ -77,7 +77,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { bb_die('Could not read smiley pak file'); } - for ($i = 0, $iMax = count($fcontents); $i < $iMax; $i++) { + foreach ($fcontents as $i => $iValue) { $smile_data = explode($delimeter, trim(addslashes($fcontents[$i]))); for ($j = 2, $jMax = count($smile_data); $j < $jMax; $j++) { @@ -239,8 +239,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { } // Convert < and > to proper htmlentities for parsing - $smile_code = str_replace('<', '<', $smile_code); - $smile_code = str_replace('>', '>', $smile_code); + $smile_code = str_replace(['<', '>'], ['<', '>'], $smile_code); // Proceed with updating the smiley table $sql = 'UPDATE ' . BB_SMILIES . " @@ -269,8 +268,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { } // Convert < and > to proper htmlentities for parsing - $smile_code = str_replace('<', '<', $smile_code); - $smile_code = str_replace('>', '>', $smile_code); + $smile_code = str_replace(['<', '>'], ['<', '>'], $smile_code); // Save the data to the smiley table $sql = 'INSERT INTO ' . BB_SMILIES . " (code, smile_url, emoticon) diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php index fd1d1f75d..26c87f280 100644 --- a/admin/admin_user_ban.php +++ b/admin/admin_user_ban.php @@ -44,7 +44,7 @@ if (isset($_POST['submit'])) { if (isset($_POST['ban_email'])) { $email_list_temp = explode(',', $_POST['ban_email']); - for ($i = 0, $iMax = count($email_list_temp); $i < $iMax; $i++) { + foreach ($email_list_temp as $i => $iValue) { if (preg_match('/^(([a-z0-9&\'\.\-_\+])|(\*))+@(([a-z0-9\-])|(\*))+\.([a-z0-9\-]+\.)*?[a-z]+$/is', trim($email_list_temp[$i]))) { $email_list[] = trim($email_list_temp[$i]); } diff --git a/admin/admin_user_search.php b/admin/admin_user_search.php index d9530856f..a467f6d27 100644 --- a/admin/admin_user_search.php +++ b/admin/admin_user_search.php @@ -251,7 +251,7 @@ if (!isset($_REQUEST['dosearch'])) { $text = sprintf($lang['SEARCH_FOR_USERNAME'], strip_tags(htmlspecialchars(stripslashes($username)))); - $username = preg_replace('/\*/', '%', trim(strip_tags(strtolower($username)))); + $username = str_replace("\*", '%', trim(strip_tags(strtolower($username)))); if (false !== strpos($username, '%')) { $op = 'LIKE'; @@ -272,7 +272,7 @@ if (!isset($_REQUEST['dosearch'])) { $text = sprintf($lang['SEARCH_FOR_EMAIL'], strip_tags(htmlspecialchars(stripslashes($email)))); - $email = preg_replace('/\*/', '%', trim(strip_tags(strtolower($email)))); + $email = str_replace("\*", '%', trim(strip_tags(strtolower($email)))); if (false !== strpos($email, '%')) { $op = 'LIKE'; @@ -340,7 +340,7 @@ if (!isset($_REQUEST['dosearch'])) { } $where_sql = ''; $where_sql .= ($ip_in_sql != '') ? "user_last_ip IN ($ip_in_sql)" : ''; - $where_sql .= ($ip_like_sql_flylast != '') ? ($where_sql != '') ? " OR $ip_like_sql_flylast" : "$ip_like_sql_flylast" : ''; + $where_sql .= ($ip_like_sql_flylast != '') ? ($where_sql != '') ? " OR $ip_like_sql_flylast" : (string)$ip_like_sql_flylast : ''; $sql = 'SELECT user_id FROM ' . BB_USERS . ' WHERE user_id <> ' . GUEST_UID . " AND ($where_sql) GROUP BY user_id"; if (!$result = DB()->sql_query($sql)) { bb_die('Could not count users #2'); @@ -357,7 +357,7 @@ if (!isset($_REQUEST['dosearch'])) { } $where_sql = ''; $where_sql .= ($ip_in_sql != '') ? "user_reg_ip IN ($ip_in_sql)" : ''; - $where_sql .= ($ip_like_sql_flyreg != '') ? ($where_sql != '') ? " OR $ip_like_sql_flyreg" : "$ip_like_sql_flyreg" : ''; + $where_sql .= ($ip_like_sql_flyreg != '') ? ($where_sql != '') ? " OR $ip_like_sql_flyreg" : (string)$ip_like_sql_flyreg : ''; $sql = 'SELECT user_id FROM ' . BB_USERS . ' WHERE user_id <> ' . GUEST_UID . " AND ($where_sql) GROUP BY user_id"; if (!$result = DB()->sql_query($sql)) { bb_die('Could not count users #3'); @@ -567,7 +567,7 @@ if (!isset($_REQUEST['dosearch'])) { $text = strip_tags(htmlspecialchars(stripslashes($userfield_value))); - $userfield_value = preg_replace('/\*/', '%', trim(strip_tags(strtolower($userfield_value)))); + $userfield_value = str_replace("\*", '%', trim(strip_tags(strtolower($userfield_value)))); if (false !== strpos($userfield_value, '%')) { $op = 'LIKE'; diff --git a/admin/index.php b/admin/index.php index 3f15ddd0a..5100a6c03 100644 --- a/admin/index.php +++ b/admin/index.php @@ -34,7 +34,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { ksort($module); foreach ($module as $cat => $action_array) { - $cat = (!empty($lang[$cat])) ? $lang[$cat] : preg_replace('/_/', ' ', $cat); + $cat = (!empty($lang[$cat])) ? $lang[$cat] : str_replace("_", ' ', $cat); $template->assign_block_vars('catrow', array( 'ADMIN_CATEGORY' => $cat, @@ -46,7 +46,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { foreach ($action_array as $action => $file) { $row_class = !($row_count % 2) ? 'row1' : 'row2'; - $action = (!empty($lang[$action])) ? $lang[$action] : preg_replace('/_/', ' ', $action); + $action = (!empty($lang[$action])) ? $lang[$action] : str_replace("_", ' ', $action); $template->assign_block_vars('catrow.modulerow', array( 'ROW_CLASS' => $row_class, diff --git a/bt/announce.php b/bt/announce.php index 2998e560f..704da8b8d 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -20,7 +20,7 @@ if (empty($_SERVER['HTTP_USER_AGENT'])) { // Ignore 'completed' event if (isset($_GET['event']) && $_GET['event'] === 'completed') { - dummy_exit(mt_rand(600, 1200)); + dummy_exit(random_int(600, 1200)); } $announce_interval = $bb_cfg['announce_interval']; diff --git a/common.php b/common.php index 2781a551f..f4f9ea4d2 100644 --- a/common.php +++ b/common.php @@ -461,7 +461,7 @@ function log_request($file = '', $prepend_str = false, $add_post = true) if (!defined('IN_TRACKER')) { require INC_DIR . '/init_bb.php'; } else { - define('DUMMY_PEER', pack('Nn', ip2long($_SERVER['REMOTE_ADDR']), !empty($_GET['port']) ? (int)$_GET['port'] : mt_rand(1000, 65000))); + define('DUMMY_PEER', pack('Nn', ip2long($_SERVER['REMOTE_ADDR']), !empty($_GET['port']) ? (int)$_GET['port'] : random_int(1000, 65000))); function dummy_exit($interval = 1800) { @@ -480,7 +480,7 @@ if (!defined('IN_TRACKER')) { if (!defined('IN_ADMIN')) { // Exit if tracker is disabled via ON/OFF trigger if (file_exists(BB_DISABLED)) { - dummy_exit(mt_rand(60, 2400)); + dummy_exit(random_int(60, 2400)); } } } diff --git a/dl.php b/dl.php index 2ad3914c0..d165c6273 100644 --- a/dl.php +++ b/dl.php @@ -128,7 +128,6 @@ for ($i = 0; $i < $num_auth_pages && $authorised == false; $i++) { $topic_id = $row['topic_id']; $forum_id = $row['forum_id']; - $is_auth = array(); $is_auth = auth(AUTH_ALL, $forum_id, $userdata); set_die_append_msg($forum_id, $topic_id); @@ -181,27 +180,27 @@ if ($download_mode == PHYSICAL_LINK) { $url = make_url($upload_dir . '/' . $attachment['physical_filename']); header('Location: ' . $url); exit; -} else { - if (IS_GUEST && !bb_captcha('check')) { - global $template; - - $redirect_url = $_POST['redirect_url'] ?? isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'; - $message = '
'; - - $template->assign_vars(array( - 'ERROR_MESSAGE' => $message, - )); - - require(PAGE_HEADER); - require(PAGE_FOOTER); - } - - send_file_to_browser($attachment, $upload_dir); - exit; } + +if (IS_GUEST && !bb_captcha('check')) { + global $template; + + $redirect_url = $_POST['redirect_url'] ?? $_SERVER['HTTP_REFERER'] ?? '/'; + $message = ''; + + $template->assign_vars(array( + 'ERROR_MESSAGE' => $message, + )); + + require(PAGE_HEADER); + require(PAGE_FOOTER); +} + +send_file_to_browser($attachment, $upload_dir); +exit; diff --git a/group.php b/group.php index 81dfb7d15..d60cab345 100644 --- a/group.php +++ b/group.php @@ -40,8 +40,6 @@ function generate_user_info(&$row, $date_format, $group_mod, &$from, &$posts, &$ } else { $www = ''; } - - return; } $user->session_start(array('req_login' => true)); diff --git a/library/ajax/manage_admin.php b/library/ajax/manage_admin.php index 5b5d04691..53599da40 100644 --- a/library/ajax/manage_admin.php +++ b/library/ajax/manage_admin.php @@ -47,7 +47,7 @@ switch ($mode) { $dir = $template->cachedir; $res = @opendir($dir); while (($file = readdir($res)) !== false) { - if (substr($file, 0, $match_len) === $match) { + if (0 === strpos($file, $match)) { @unlink($dir . $file); } } diff --git a/library/attach_mod/attachment_mod.php b/library/attach_mod/attachment_mod.php index d3f812b43..3ad95593d 100644 --- a/library/attach_mod/attachment_mod.php +++ b/library/attach_mod/attachment_mod.php @@ -31,11 +31,11 @@ function attach_mod_get_lang($language_file) $file = LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/' . $language_file . '.php'; if (file_exists($file)) { return $bb_cfg['default_lang']; - } else { - $file = LANG_ROOT_DIR . '/' . $attach_config['board_lang'] . '/' . $language_file . '.php'; - if (file_exists($file)) { - return $attach_config['board_lang']; - } + } + + $file = LANG_ROOT_DIR . '/' . $attach_config['board_lang'] . '/' . $language_file . '.php'; + if (file_exists($file)) { + return $attach_config['board_lang']; } bb_die('Attachment mod language file does not exist: language/' . $attach_config['board_lang'] . '/' . $language_file . '.php'); diff --git a/library/attach_mod/displaying.php b/library/attach_mod/displaying.php index f863a207f..85c5789f0 100644 --- a/library/attach_mod/displaying.php +++ b/library/attach_mod/displaying.php @@ -25,7 +25,7 @@ function init_complete_extensions_data() global $allowed_extensions, $display_categories, $download_modes, $upload_icons; if (!$extension_informations = get_extension_informations()) { - $extension_informations = $GLOBALS['datastore']->update('attach_extensions'); //get_extension_informations() + $GLOBALS['datastore']->update('attach_extensions'); $extension_informations = get_extension_informations(); } $allowed_extensions = array(); diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index 950dced75..d6d19c440 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -174,7 +174,7 @@ if ($tor_reged && $tor_info) { $dl_allowed = ($user_ratio > $min_ratio_dl); } - if ((isset($user_ratio) && isset($min_ratio_warn) && $user_ratio < $min_ratio_warn && TR_RATING_LIMITS) || ($bt_userdata['u_down_total'] < MIN_DL_FOR_RATIO)) { + if ((isset($user_ratio, $min_ratio_warn) && $user_ratio < $min_ratio_warn && TR_RATING_LIMITS) || ($bt_userdata['u_down_total'] < MIN_DL_FOR_RATIO)) { $template->assign_vars(array( 'SHOW_RATIO_WARN' => true, 'RATIO_WARN_MSG' => sprintf($lang['BT_RATIO_WARNING_MSG'], $min_ratio_dl, $bb_cfg['ratio_url_help']), diff --git a/library/attach_mod/includes/functions_admin.php b/library/attach_mod/includes/functions_admin.php index 931da93b6..ec8e8a2df 100644 --- a/library/attach_mod/includes/functions_admin.php +++ b/library/attach_mod/includes/functions_admin.php @@ -101,7 +101,7 @@ function sort_multi_array($sort_array, $key, $sort_order, $pre_string_sort = 0) for ($i = 0; $i < $last_element; $i++) { $num_iterations = $last_element - $i; - for ($j = 0; $j < $num_iterations; $j++) { + foreach ($sort_array as $j => $jValue) { // do checks based on key $switch = false; if (!$string_sort) { @@ -117,7 +117,7 @@ function sort_multi_array($sort_array, $key, $sort_order, $pre_string_sort = 0) } if ($switch) { - $temp = $sort_array[$j]; + $temp = $jValue; $sort_array[$j] = $sort_array[$j + 1]; $sort_array[$j + 1] = $temp; } diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 04ac91a59..daf1cb0d8 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -87,7 +87,7 @@ function auth_pack($auth_array) $one_char = $two_char = false; $auth_cache = ''; - for ($i = 0, $iMax = count($auth_array); $i < $iMax; $i++) { + foreach ($auth_array as $i => $iValue) { $val = base64_pack((int)$auth_array[$i]); if (strlen($val) == 1 && !$one_char) { $auth_cache .= $one_char_encoding; @@ -114,7 +114,7 @@ function auth_unpack($auth_cache) $auth = []; $auth_len = 1; - for ($pos = 0; $pos < strlen($auth_cache); $pos += $auth_len) { + for ($pos = 0, $posMax = strlen($auth_cache); $pos < $posMax; $pos += $auth_len) { $forum_auth = $auth_cache[$pos]; if ($forum_auth == $one_char_encoding) { $auth_len = 1; @@ -149,7 +149,7 @@ function is_forum_authed($auth_cache, $check_forum_id) $auth = []; $auth_len = 1; - for ($pos = 0; $pos < strlen($auth_cache); $pos += $auth_len) { + for ($pos = 0, $posMax = strlen($auth_cache); $pos < $posMax; $pos += $auth_len) { $forum_auth = $auth_cache[$pos]; if ($forum_auth == $one_char_encoding) { $auth_len = 1; @@ -266,7 +266,7 @@ function get_attachments_from_post($post_id_array) $post_id_array[] = $post_id; } - $post_id_array = implode(', ', array_map('intval', $post_id_array)); + $post_id_array = implode(', ', array_map('\intval', $post_id_array)); if ($post_id_array == '') { return $attachments; @@ -304,7 +304,7 @@ function get_total_attach_filesize($attach_ids) return 0; } - $attach_ids = implode(', ', array_map('intval', $attach_ids)); + $attach_ids = implode(', ', array_map('\intval', $attach_ids)); if (!$attach_ids) { return 0; @@ -412,7 +412,7 @@ function get_extension($filename) */ function delete_extension($filename) { - return substr($filename, 0, strrpos(strtolower(trim($filename)), '.')); + return substr($filename, 0, strripos(trim($filename), '.')); } /** @@ -535,7 +535,7 @@ function attach_mod_sql_escape($text) return DB()->escape_string($text); } - return str_replace("'", "''", str_replace('\\', '\\\\', $text)); + return str_replace(['\\', "'"], ['\\\\', "''"], $text); } /** diff --git a/library/attach_mod/includes/functions_delete.php b/library/attach_mod/includes/functions_delete.php index 03fc2fad5..07771dff1 100644 --- a/library/attach_mod/includes/functions_delete.php +++ b/library/attach_mod/includes/functions_delete.php @@ -27,7 +27,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, if (!is_array($attach_id_array)) { if (false !== strpos($attach_id_array, ', ')) { $attach_id_array = explode(', ', $attach_id_array); - } elseif (strstr($attach_id_array, ',')) { + } elseif (false !== strpos($attach_id_array, ',')) { $attach_id_array = explode(',', $attach_id_array); } else { $attach_id = (int)$attach_id_array; @@ -68,7 +68,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, if (false !== strpos($post_id_array, ', ')) { $post_id_array = explode(', ', $post_id_array); - } elseif (strstr($post_id_array, ',')) { + } elseif (false !== strpos($post_id_array, ',')) { $post_id_array = explode(',', $post_id_array); } else { $post_id = (int)$post_id_array; @@ -113,7 +113,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, if (!is_array($attach_id_array)) { if (false !== strpos($attach_id_array, ', ')) { $attach_id_array = explode(', ', $attach_id_array); - } elseif (strstr($attach_id_array, ',')) { + } elseif (false !== strpos($attach_id_array, ',')) { $attach_id_array = explode(',', $attach_id_array); } else { $attach_id = (int)$attach_id_array; @@ -171,7 +171,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } //bt end - for ($i = 0, $iMax = count($attach_id_array); $i < $iMax; $i++) { + foreach ($attach_id_array as $i => $iValue) { $sql = 'SELECT attach_id FROM ' . BB_ATTACHMENTS . ' WHERE attach_id = ' . (int)$attach_id_array[$i]; diff --git a/library/attach_mod/includes/functions_selects.php b/library/attach_mod/includes/functions_selects.php index a6ff64f55..aabee8713 100644 --- a/library/attach_mod/includes/functions_selects.php +++ b/library/attach_mod/includes/functions_selects.php @@ -188,7 +188,7 @@ function quota_limit_select($select_name, $default_quota = 0) } DB()->sql_freeresult($result); - for ($i = 0, $iMax = count($quota_name); $i < $iMax; $i++) { + foreach ($quota_name as $i => $iValue) { $selected = ($quota_name[$i]['quota_limit_id'] == $default_quota) ? ' selected="selected"' : ''; $quota_select .= ''; } @@ -219,7 +219,7 @@ function default_quota_limit_select($select_name, $default_quota = 0) } DB()->sql_freeresult($result); - for ($i = 0, $iMax = count($quota_name); $i < $iMax; $i++) { + foreach ($quota_name as $i => $iValue) { $selected = ($quota_name[$i]['quota_limit_id'] == $default_quota) ? ' selected="selected"' : ''; $quota_select .= ''; } diff --git a/library/attach_mod/includes/functions_thumbs.php b/library/attach_mod/includes/functions_thumbs.php index 374e69dc3..5700ae66e 100644 --- a/library/attach_mod/includes/functions_thumbs.php +++ b/library/attach_mod/includes/functions_thumbs.php @@ -26,12 +26,12 @@ function get_img_size_format($width, $height) round($width * ($max_width / $width)), round($height * ($max_width / $width)) ); - } else { - return array( - round($width * ($max_width / $height)), - round($height * ($max_width / $height)) - ); } + + return array( + round($width * ($max_width / $height)), + round($height * ($max_width / $height)) + ); } /** @@ -44,9 +44,9 @@ function is_imagick() if ($attach_config['img_imagick'] != '') { $imagick = $attach_config['img_imagick']; return true; - } else { - return false; } + + return false; } /** @@ -111,8 +111,6 @@ function create_thumbnail($source, $new_file, $mimetype) [$new_width, $new_height] = get_img_size_format($width, $height); - $tmp_path = $old_file = ''; - $used_imagick = false; if (is_imagick()) { diff --git a/library/config.php b/library/config.php index 708d011d2..0324a018e 100644 --- a/library/config.php +++ b/library/config.php @@ -456,7 +456,7 @@ $bb_cfg['use_ajax_posts'] = true; $bb_cfg['search_engine_type'] = 'mysql'; // none, mysql, sphinx $bb_cfg['sphinx_topic_titles_host'] = '127.0.0.1'; $bb_cfg['sphinx_topic_titles_port'] = 3312; -$bb_cfg['sphinx_config_path'] = realpath("../install/sphinx/sphinx.conf"); +$bb_cfg['sphinx_config_path'] = '../install/sphinx/sphinx.conf'; $bb_cfg['disable_ft_search_in_posts'] = false; // disable searching in post bodies $bb_cfg['disable_search_for_guest'] = true; $bb_cfg['allow_search_in_bool_mode'] = true; diff --git a/library/includes/bbcode.php b/library/includes/bbcode.php index fc88b7a10..a0d3ea9a6 100644 --- a/library/includes/bbcode.php +++ b/library/includes/bbcode.php @@ -338,9 +338,7 @@ function extract_search_words($text) $text = preg_replace('/(\w*?)?[0-9a-z]+;(\w*?)/iu', '', $text); // Remove URL's ((www|ftp)\.[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]*?) $text = preg_replace('#\b[a-z0-9]+://[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]+(/[0-9a-z\?\.%_\-\+=&/]+)?#u', ' ', $text); - $text = str_replace('[url=', ' ', $text); - $text = str_replace('?', ' ', $text); - $text = str_replace('!', ' ', $text); + $text = str_replace(['[url=', '?', '!'], ' ', $text); $text = strip_bbcode($text); diff --git a/library/includes/functions.php b/library/includes/functions.php index acbd25626..9c153ae62 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -587,9 +587,9 @@ function bt_show_ip($ip, $port = '') $ip = decode_ip($ip); $ip .= ($port) ? ":$port" : ''; return $ip; - } else { - return ($bb_cfg['bt_show_ip_only_moder']) ? false : decode_ip_xx($ip); } + + return ($bb_cfg['bt_show_ip_only_moder']) ? false : decode_ip_xx($ip); } function bt_show_port($port) @@ -598,9 +598,9 @@ function bt_show_port($port) if (IS_AM) { return $port; - } else { - return ($bb_cfg['bt_show_port_only_moder']) ? false : $port; } + + return ($bb_cfg['bt_show_port_only_moder']) ? false : $port; } function decode_ip_xx($ip) @@ -741,10 +741,10 @@ function get_username($user_id) $usernames[$row['user_id']] = $row['username']; } return $usernames; - } else { - $row = DB()->fetch_row("SELECT username FROM " . BB_USERS . " WHERE user_id = $user_id LIMIT 1"); - return $row['username']; } + + $row = DB()->fetch_row("SELECT username FROM " . BB_USERS . " WHERE user_id = $user_id LIMIT 1"); + return $row['username']; } function get_user_id($username) @@ -846,9 +846,9 @@ function get_attachments_dir($cfg = null) if ($cfg['upload_dir'][0] == '/' || ($cfg['upload_dir'][0] != '/' && $cfg['upload_dir'][1] == ':')) { return $cfg['upload_dir']; - } else { - return BB_ROOT . $cfg['upload_dir']; } + + return BB_ROOT . $cfg['upload_dir']; } function bb_get_config($table, $from_db = false, $update_cache = true) @@ -1453,9 +1453,9 @@ function get_forum_display_sort_option($selected_row = 0, $action = 'list', $lis // build list if ($action == 'list') { - for ($i = 0, $iMax = count($listrow['lang_key']); $i < $iMax; $i++) { + foreach ($listrow['lang_key'] as $i => $iValue) { $selected = ($i == $selected_row) ? ' selected="selected"' : ''; - $l_value = $lang[$listrow['lang_key'][$i]] ?? $listrow['lang_key'][$i]; + $l_value = $lang[$listrow['lang_key'][$i]] ?? $iValue; $res .= ''; } } else { @@ -1543,7 +1543,7 @@ if (!function_exists('array_intersect_key')) { // Check arrays $array_count = count($args); - for ($i = 0; $i !== $array_count; $i++) { + foreach ($args as $i => $iValue) { if (!is_array($args[$i])) { user_error('array_intersect_key() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); @@ -1789,8 +1789,7 @@ function clean_text_match($text, $ltrim_star = true, $die_if_empty = false) if ($bb_cfg['search_engine_type'] == 'sphinx') { $text = preg_replace('#(?<=\S)\-#u', ' ', $text); // "1-2-3" -> "1 2 3" $text = preg_replace('#[^0-9a-zA-Zа-яА-ЯёЁ\-_*|]#u', ' ', $text); // допустимые символы (кроме " которые отдельно) - $text = str_replace('-', ' -', $text); // - только в начале слова - $text = str_replace('*', '* ', $text); // * только в конце слова + $text = str_replace(['-', '*'], [' -', '* '], $text); // только в начале / конце слова $text = preg_replace('#\s*\|\s*#u', '|', $text); // "| " -> "|" $text = preg_replace('#\|+#u', ' | ', $text); // "||" -> "|" $text = preg_replace('#(?<=\s)[\-*]+\s#u', ' ', $text); // одиночные " - ", " * " @@ -1835,7 +1834,7 @@ function log_sphinx_error($err_type, $err_msg, $query = '') } } -function get_title_match_topics($title_match_sql, $forum_ids = []) +function get_title_match_topics($title_match_sql, array $forum_ids = []) { global $bb_cfg, $sphinx, $userdata, $title_match, $lang; @@ -2011,10 +2010,6 @@ function get_avatar($user_id, $ext_id, $allow_avatar = true, $size = true, $heig { global $bb_cfg; - if ($size) { - // TODO размеры: s, m, l + кеширование - } - $height = !$height ? 'height="' . $height . '"' : ''; $width = !$width ? 'width="' . $width . '"' : ''; diff --git a/library/includes/ucp/register.php b/library/includes/ucp/register.php index 78d0f44e5..8d654f586 100644 --- a/library/includes/ucp/register.php +++ b/library/includes/ucp/register.php @@ -331,14 +331,14 @@ foreach ($profile_fields as $field => $can_edit) { $update_user_opt = array( # 'user_opt_name' => ($reg_mode) ? #reg_value : #in_login_change - 'user_viewemail' => ($reg_mode) ? false : true, - 'user_viewonline' => ($reg_mode) ? false : true, - 'user_notify' => ($reg_mode) ? true : true, - 'user_notify_pm' => ($reg_mode) ? true : true, - 'user_porn_forums' => ($reg_mode) ? false : true, - 'user_dls' => ($reg_mode) ? false : true, - 'user_callseed' => ($reg_mode) ? true : true, - 'user_retracker' => ($reg_mode) ? true : true, + 'user_viewemail' => $reg_mode ? false : true, + 'user_viewonline' => $reg_mode ? false : true, + 'user_notify' => $reg_mode ? true : true, + 'user_notify_pm' => $reg_mode ? true : true, + 'user_porn_forums' => $reg_mode ? false : true, + 'user_dls' => $reg_mode ? false : true, + 'user_callseed' => $reg_mode ? true : true, + 'user_retracker' => $reg_mode ? true : true, ); foreach ($update_user_opt as $opt => $can_change_opt) { diff --git a/login.php b/login.php index a55420470..11f879520 100644 --- a/login.php +++ b/login.php @@ -40,8 +40,7 @@ if (preg_match('/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si', $_SERVER['QUERY_STRING $redirect_url = ($parts['path'] ?? "index.php") . (isset($parts['query']) ? '?' . $parts['query'] : ''); } -$redirect_url = str_replace('&admin=1', '', $redirect_url); -$redirect_url = str_replace('?admin=1', '', $redirect_url); +$redirect_url = str_replace(['&admin=1', '?admin=1'], '', $redirect_url); if (!$redirect_url || false !== strpos(urldecode($redirect_url), "\n") || false !== strpos(urldecode($redirect_url), "\r") || false !== strpos(urldecode($redirect_url), ';url')) { $redirect_url = "index.php"; diff --git a/memberlist.php b/memberlist.php index f2c93a141..44e8afe6c 100644 --- a/memberlist.php +++ b/memberlist.php @@ -147,7 +147,7 @@ $template->assign_vars(array( // per-letter selection end $sql = "SELECT username, user_id, user_rank, user_opt, user_posts, user_regdate, user_from, user_website, user_email FROM " . BB_USERS . " WHERE user_id NOT IN(" . EXCLUDED_USERS . ")"; if ($username) { - $username = preg_replace('/\*/', '%', clean_username($username)); + $username = str_replace("\*", '%', clean_username($username)); $letter_sql = "username LIKE '" . DB()->escape($username) . "'"; } $sql .= ($letter_sql) ? " AND $letter_sql" : ''; diff --git a/posting.php b/posting.php index 425176bd2..61bef54c8 100644 --- a/posting.php +++ b/posting.php @@ -324,7 +324,7 @@ if (($delete || $mode == 'delete') && !$confirm) { $username = (!empty($_POST['username'])) ? clean_username($_POST['username']) : ''; $subject = (!empty($_POST['subject'])) ? clean_title($_POST['subject']) : ''; $message = (!empty($_POST['message'])) ? prepare_message($_POST['message']) : ''; - $attach_rg_sig = (isset($_POST['attach_rg_sig']) && isset($_POST['poster_rg']) && $_POST['poster_rg'] != -1) ? 1 : 0; + $attach_rg_sig = (isset($_POST['attach_rg_sig'], $_POST['poster_rg']) && $_POST['poster_rg'] != -1) ? 1 : 0; $poster_rg_id = (isset($_POST['poster_rg']) && $_POST['poster_rg'] != -1) ? (int)$_POST['poster_rg'] : 0; \TorrentPier\Legacy\Post::prepare_post($mode, $post_data, $error_msg, $username, $subject, $message); diff --git a/privmsg.php b/privmsg.php index 51a2700be..0783bcd3e 100644 --- a/privmsg.php +++ b/privmsg.php @@ -1046,7 +1046,6 @@ if ($mode == 'read') { $replacement_word = array(); obtain_word_list($orig_word, $replacement_word); - $preview_message = htmlCHR($privmsg_message, false, ENT_NOQUOTES); $preview_message = bbcode2html($privmsg_message); if (count($orig_word)) { @@ -1287,7 +1286,7 @@ if ($mode == 'read') { $previous_days_text = array($lang['ALL_POSTS'], $lang['1_DAY'], $lang['7_DAYS'], $lang['2_WEEKS'], $lang['1_MONTH'], $lang['3_MONTHS'], $lang['6_MONTHS'], $lang['1_YEAR']); $select_msg_days = ''; - for ($i = 0; $i < count($previous_days); $i++) { + for ($i = 0, $iMax = count($previous_days); $i < $iMax; $i++) { $selected = ($msg_days == $previous_days[$i]) ? ' selected="selected"' : ''; $select_msg_days .= ''; } diff --git a/search.php b/search.php index 4123c23f0..7f0e4314c 100644 --- a/search.php +++ b/search.php @@ -918,7 +918,7 @@ function username_search($search_match) $username_list = ''; if (!empty($search_match)) { - $username_search = preg_replace('/\*/', '%', clean_username($search_match)); + $username_search = str_replace("\*", '%', clean_username($search_match)); $sql = " SELECT username diff --git a/src/Helpers/CronHelper.php b/src/Helpers/CronHelper.php index 2dd8c6cfd..4a8b2b8b7 100644 --- a/src/Helpers/CronHelper.php +++ b/src/Helpers/CronHelper.php @@ -107,8 +107,8 @@ class CronHelper */ public static function trackRunning($mode) { - if (!defined('START_MARK')) { - define('START_MARK', TRIGGERS_DIR . '/cron_started_at_' . date('Y-m-d_H-i-s') . '_by_pid_' . getmypid()); + if (!\defined('START_MARK')) { + \define('START_MARK', TRIGGERS_DIR . '/cron_started_at_' . date('Y-m-d_H-i-s') . '_by_pid_' . getmypid()); } if ($mode === 'start') { diff --git a/src/Legacy/Admin/Common.php b/src/Legacy/Admin/Common.php index 535a2968f..acd8e6268 100644 --- a/src/Legacy/Admin/Common.php +++ b/src/Legacy/Admin/Common.php @@ -239,9 +239,10 @@ class Common $where_sql "; - $topic_csv = array(); + $topic_csv = []; foreach (DB()->fetch_rowset($sql) as $row) { + /** @noinspection UnsupportedStringOffsetOperationsInspection */ $topic_csv[] = $row['topic_id']; $log_topics[] = $row; $sync_forums[$row['forum_id']] = true; @@ -660,7 +661,7 @@ class Common $log_action->admin('mod_post_delete', array( 'log_msg' => 'user: ' . self::get_usernames_for_log($user_id) . "$out"); } diff --git a/src/Legacy/TorrentFileList.php b/src/Legacy/TorrentFileList.php index 353b1958f..e02334450 100644 --- a/src/Legacy/TorrentFileList.php +++ b/src/Legacy/TorrentFileList.php @@ -62,7 +62,7 @@ class TorrentFileList $info['name'] =& $info['name.utf-8']; } - if (isset($info['files']) && is_array($info['files'])) { + if (isset($info['files']) && \is_array($info['files'])) { $this->root_dir = isset($info['name']) ? '../' . clean_tor_dirname($info['name']) : '...'; $this->multiple = true; @@ -70,13 +70,13 @@ class TorrentFileList if (isset($f['path.utf-8'])) { $f['path'] =& $f['path.utf-8']; } - if (!isset($f['path']) || !is_array($f['path'])) { + if (!isset($f['path']) || !\is_array($f['path'])) { continue; } array_deep($f['path'], 'clean_tor_dirname'); $length = isset($f['length']) ? (float)$f['length'] : 0; - $subdir_count = count($f['path']) - 1; + $subdir_count = \count($f['path']) - 1; if ($subdir_count > 0) { $name = array_pop($f['path']); @@ -91,7 +91,7 @@ class TorrentFileList $cur_files_ary =& $cur_files_ary[$subdir]; if ($j === $subdir_count) { - if (is_string($cur_files_ary)) { + if (\is_string($cur_files_ary)) { $GLOBALS['bnc_error'] = 1; break; } diff --git a/src/Legacy/Validate.php b/src/Legacy/Validate.php index 9ba3ee158..1f88bf02a 100644 --- a/src/Legacy/Validate.php +++ b/src/Legacy/Validate.php @@ -93,7 +93,7 @@ class Validate if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) { return $lang['EMAIL_INVALID']; } - if (strlen($email) > USEREMAIL_MAX_LENGTH) { + if (\strlen($email) > USEREMAIL_MAX_LENGTH) { return $lang['EMAIL_TOO_LONG']; } diff --git a/src/Legacy/WordsRate.php b/src/Legacy/WordsRate.php index 2e49009cb..4f535cb47 100644 --- a/src/Legacy/WordsRate.php +++ b/src/Legacy/WordsRate.php @@ -46,7 +46,7 @@ class WordsRate $this->del_text_hl = $text; // длинное сообщение - if (strlen($text) > 600) { + if (\strlen($text) > 600) { return $this->words_rate; } // вырезаем цитаты если содержит +1