diff --git a/admin/admin_attachments.php b/admin/admin_attachments.php index ccb05d22e..4f8a1ad0b 100644 --- a/admin/admin_attachments.php +++ b/admin/admin_attachments.php @@ -135,7 +135,9 @@ if ($search_imagick) { if (preg_match('/convert/i', $imagick)) { return true; - } elseif ($imagick != 'none') { + } + + if ($imagick != 'none') { if (!preg_match('/WIN/i', PHP_OS)) { $retval = @exec('whereis convert'); $paths = explode(' ', $retval); diff --git a/admin/admin_board.php b/admin/admin_board.php index 323a1630c..94d8f3442 100644 --- a/admin/admin_board.php +++ b/admin/admin_board.php @@ -15,7 +15,7 @@ if (!empty($setmodules)) { require __DIR__ . '/pagestart.php'; require INC_DIR . '/functions_selects.php'; -$mode = isset($_GET['mode']) ? $_GET['mode'] : ''; +$mode = $_GET['mode'] ?? ''; $return_links = array( 'index' => '

' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''), @@ -35,7 +35,7 @@ if (!$result = OLD_DB()->sql_query($sql)) { $config_value = $row['config_value']; $default_config[$config_name] = $config_value; - $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name]; + $new[$config_name] = $_POST[$config_name] ?? $default_config[$config_name]; if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name]) { if ($config_name == 'seed_bonus_points' || diff --git a/admin/admin_cron.php b/admin/admin_cron.php index fc004cca0..ab1c4115a 100644 --- a/admin/admin_cron.php +++ b/admin/admin_cron.php @@ -14,11 +14,11 @@ if (!empty($setmodules)) { return; } -$mode = isset($_GET['mode']) ? $_GET['mode'] : ''; +$mode = $_GET['mode'] ?? ''; $job_id = isset($_GET['id']) ? (int)$_GET['id'] : ''; $submit = isset($_POST['submit']); $jobs = isset($_POST['select']) ? implode(',', $_POST['select']) : ''; -$cron_action = isset($_POST['cron_action']) ? $_POST['cron_action'] : ''; +$cron_action = $_POST['cron_action'] ?? ''; if ($mode == 'run' && !$job_id) { define('BB_ROOT', './../'); @@ -43,7 +43,7 @@ foreach ($sql as $row) { $config_value = $row['config_value']; $default_config[$config_name] = $config_value; - $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name]; + $new[$config_name] = $_POST[$config_name] ?? $default_config[$config_name]; if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name]) { bb_update_config(array($config_name => $new[$config_name])); diff --git a/admin/admin_extensions.php b/admin/admin_extensions.php index 5b679c39b..2f920d787 100644 --- a/admin/admin_extensions.php +++ b/admin/admin_extensions.php @@ -371,7 +371,7 @@ if ($mode == 'groups') { $template->assign_vars(array( 'TPL_ATTACH_EXTENSION_GROUPS' => true, - 'ADD_GROUP_NAME' => isset($extension_group) ? $extension_group : '', + 'ADD_GROUP_NAME' => $extension_group ?? '', 'MAX_FILESIZE' => $max_add_filesize, 'S_FILESIZE' => size_select('add_size_select', $size), 'S_ADD_DOWNLOAD_MODE' => download_select('add_download_mode'), diff --git a/admin/admin_forums.php b/admin/admin_forums.php index 34cc5b02c..45dd66e0d 100644 --- a/admin/admin_forums.php +++ b/admin/admin_forums.php @@ -560,15 +560,17 @@ if ($mode) { $move_down_forum_id = false; $forums = $cat_forums[$cat_id]['f_ord']; $forum_order = $forum_info['forum_order']; - $prev_forum = isset($forums[$forum_order - 10]) ? $forums[$forum_order - 10] : false; - $next_forum = isset($forums[$forum_order + 10]) ? $forums[$forum_order + 10] : false; + $prev_forum = $forums[$forum_order - 10] ?? false; + $next_forum = $forums[$forum_order + 10] ?? false; // move selected forum ($forum_id) UP if ($move < 0 && $prev_forum) { 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; @@ -579,7 +581,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_groups.php b/admin/admin_groups.php index cf43a4312..564132d67 100644 --- a/admin/admin_groups.php +++ b/admin/admin_groups.php @@ -88,7 +88,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) { $release_group = isset($_POST['release_group']) ? (int)$_POST['release_group'] : 0; $group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : ''; $group_desc = isset($_POST['group_description']) ? trim($_POST['group_description']) : ''; - $group_moderator = isset($_POST['username']) ? $_POST['username'] : ''; + $group_moderator = $_POST['username'] ?? ''; if ($group_name === '') { bb_die($lang['NO_GROUP_NAME']); diff --git a/admin/admin_ranks.php b/admin/admin_ranks.php index cd44577ff..1b58087c2 100644 --- a/admin/admin_ranks.php +++ b/admin/admin_ranks.php @@ -15,7 +15,7 @@ if (!empty($setmodules)) { require __DIR__ . '/pagestart.php'; if (isset($_GET['mode']) || isset($_POST['mode'])) { - $mode = isset($_GET['mode']) ? $_GET['mode'] : $_POST['mode']; + $mode = $_GET['mode'] ?? $_POST['mode']; } else { // // These could be entered via a form button diff --git a/admin/admin_rebuild_search.php b/admin/admin_rebuild_search.php index 3ea7ee6c9..a8d24ad10 100644 --- a/admin/admin_rebuild_search.php +++ b/admin/admin_rebuild_search.php @@ -134,7 +134,7 @@ if ($mode == 'submit' || $mode == 'refresh') { } // get the db sizes - list($search_data_size, $search_index_size, $search_tables_size) = get_db_sizes(); + [$search_data_size, $search_index_size, $search_tables_size] = get_db_sizes(); // get the post subject/text of each post $result = OLD_DB()->query(" @@ -290,7 +290,7 @@ if ($mode == 'submit' || $mode == 'refresh') { } // get the db sizes - list($search_data_size, $search_index_size, $search_tables_size) = get_db_sizes(); + [$search_data_size, $search_index_size, $search_tables_size] = get_db_sizes(); // calculate the final (estimated) values $final_search_tables_size = ''; diff --git a/admin/admin_sitemap.php b/admin/admin_sitemap.php index 57e9efe85..a22db201e 100644 --- a/admin/admin_sitemap.php +++ b/admin/admin_sitemap.php @@ -25,7 +25,7 @@ if (!$result = OLD_DB()->sql_query($sql)) { $config_name = $row['config_name']; $config_value = $row['config_value']; $default_config[$config_name] = $config_value; - $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name]; + $new[$config_name] = $_POST[$config_name] ?? $default_config[$config_name]; if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name]) { $new_params[$config_name] = $new[$config_name]; diff --git a/admin/admin_smilies.php b/admin/admin_smilies.php index 827c4091f..689d8f2dc 100644 --- a/admin/admin_smilies.php +++ b/admin/admin_smilies.php @@ -16,7 +16,7 @@ require __DIR__ . '/pagestart.php'; // Check to see what mode we should operate in if (isset($_POST['mode']) || isset($_GET['mode'])) { - $mode = isset($_POST['mode']) ? $_POST['mode'] : $_GET['mode']; + $mode = $_POST['mode'] ?? $_GET['mode']; $mode = htmlspecialchars($mode); } else { $mode = ''; @@ -255,10 +255,10 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { break; case 'savenew': - $smile_code = isset($_POST['smile_code']) ? $_POST['smile_code'] : $_GET['smile_code']; - $smile_url = isset($_POST['smile_url']) ? $_POST['smile_url'] : $_GET['smile_url']; + $smile_code = $_POST['smile_code'] ?? $_GET['smile_code']; + $smile_url = $_POST['smile_url'] ?? $_GET['smile_url']; $smile_url = bb_ltrim(basename($smile_url), "'"); - $smile_emotion = isset($_POST['smile_emotion']) ? $_POST['smile_emotion'] : $_GET['smile_emotion']; + $smile_emotion = $_POST['smile_emotion'] ?? $_GET['smile_emotion']; $smile_code = trim($smile_code); $smile_url = trim($smile_url); $smile_emotion = trim($smile_emotion); diff --git a/bt/announce.php b/bt/announce.php index a8ae39d91..79a60548c 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -23,7 +23,7 @@ if (isset($_GET['event']) && $_GET['event'] === 'completed') { if (DBG_LOG) { dbg_log(' ', '!die-event-completed'); } - dummy_exit(mt_rand(600, 1200)); + dummy_exit(random_int(600, 1200)); } $announce_interval = $bb_cfg['announce_interval']; @@ -74,7 +74,7 @@ foreach ($input_vars_num as $var_name) { $$var_name = isset($_GET[$var_name]) ? (float)$_GET[$var_name] : null; } // Passkey -$passkey = isset($$passkey_key) ? $$passkey_key : null; +$passkey = $$passkey_key ?? null; // Verify request // Required params (info_hash, peer_id, port, uploaded, downloaded, left, passkey) diff --git a/common.php b/common.php index d826450f9..bf9814bbd 100644 --- a/common.php +++ b/common.php @@ -426,7 +426,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) { @@ -445,7 +445,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 07198fc67..eb2c6cdaa 100644 --- a/dl.php +++ b/dl.php @@ -182,27 +182,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 = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'); - $message = '
'; - $message .= $lang['CAPTCHA'] . ':'; - $message .= '
' . bb_captcha('get') . '
'; - $message .= ''; - $message .= '  '; - $message .= ''; - $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 = '
'; + $message .= $lang['CAPTCHA'] . ':'; + $message .= '
' . bb_captcha('get') . '
'; + $message .= ''; + $message .= '  '; + $message .= ''; + $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/feed.php b/feed.php index bd496608f..5440fae56 100644 --- a/feed.php +++ b/feed.php @@ -13,9 +13,9 @@ require __DIR__ . '/common.php'; $user->session_start(array('req_login' => true)); -$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : ''; -$type = isset($_POST['type']) ? $_POST['type'] : ''; -$id = isset($_POST['id']) ? $_POST['id'] : 0; +$mode = $_REQUEST['mode'] ?? ''; +$type = $_POST['type'] ?? ''; +$id = $_POST['id'] ?? 0; $timecheck = TIMENOW - 600; if (!$mode) { diff --git a/index.php b/index.php index a204d22c0..73bc5f8d6 100644 --- a/index.php +++ b/index.php @@ -238,7 +238,7 @@ foreach ($cat_forums as $cid => $c) { 'FORUM_DESC' => $f['forum_desc'], 'POSTS' => commify($f['forum_posts']), 'TOPICS' => commify($f['forum_topics']), - 'LAST_SF_ID' => isset($f['last_sf_id']) ? $f['last_sf_id'] : null, + 'LAST_SF_ID' => $f['last_sf_id'] ?? null, 'MODERATORS' => isset($moderators[$fid]) ? implode(', ', $moderators[$fid]) : '', 'FORUM_FOLDER_ALT' => ($new) ? $lang['NEW'] : $lang['OLD'], )); diff --git a/library/TorrentPier/TorrentPier/Legacy/Attach.php b/library/TorrentPier/TorrentPier/Legacy/Attach.php index 8bd1ef3aa..f3e02cf5b 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Attach.php +++ b/library/TorrentPier/TorrentPier/Legacy/Attach.php @@ -908,7 +908,7 @@ class Attach // Check Image Size, if it's an image if (!$error && !IS_ADMIN && $cat_id === IMAGE_CAT) { - list($width, $height) = image_getdimension($upload_dir . '/' . $this->attach_filename); + [$width, $height] = image_getdimension($upload_dir . '/' . $this->attach_filename); if ($width && $height && (int)$attach_config['img_max_width'] && (int)$attach_config['img_max_height']) { if ($width > (int)$attach_config['img_max_width'] || $height > (int)$attach_config['img_max_height']) { diff --git a/library/TorrentPier/TorrentPier/Legacy/Cache/Apc.php b/library/TorrentPier/TorrentPier/Legacy/Cache/Apc.php index f6ab498b7..4e150ebee 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Cache/Apc.php +++ b/library/TorrentPier/TorrentPier/Legacy/Cache/Apc.php @@ -60,9 +60,9 @@ class Apc extends Common $this->num_queries++; return apc_delete($this->prefix . $name); - } else { - return apc_clear_cache(); } + + return apc_clear_cache(); } public function is_installed() diff --git a/library/TorrentPier/TorrentPier/Legacy/Cache/Memcache.php b/library/TorrentPier/TorrentPier/Legacy/Cache/Memcache.php index fe72dfa42..0fe7d706f 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Cache/Memcache.php +++ b/library/TorrentPier/TorrentPier/Legacy/Cache/Memcache.php @@ -101,9 +101,9 @@ class Memcache extends Common $this->num_queries++; return ($this->connected) ? $this->memcache->delete($this->prefix . $name, 0) : false; - } else { - return ($this->connected) ? $this->memcache->flush() : false; } + + return ($this->connected) ? $this->memcache->flush() : false; } public function is_installed() diff --git a/library/TorrentPier/TorrentPier/Legacy/Cache/Redis.php b/library/TorrentPier/TorrentPier/Legacy/Cache/Redis.php index b7ab3d960..e500425d2 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Cache/Redis.php +++ b/library/TorrentPier/TorrentPier/Legacy/Cache/Redis.php @@ -85,9 +85,9 @@ class Redis extends Common $this->num_queries++; return true; - } else { - return false; } + + return false; } public function rm($name = '') @@ -104,9 +104,9 @@ class Redis extends Common $this->num_queries++; return ($this->connected) ? $this->redis->del($this->prefix . $name) : false; - } else { - return ($this->connected) ? $this->redis->flushDB() : false; } + + return ($this->connected) ? $this->redis->flushDB() : false; } public function is_installed() diff --git a/library/TorrentPier/TorrentPier/Legacy/Cache/Sqlite.php b/library/TorrentPier/TorrentPier/Legacy/Cache/Sqlite.php index ff31d611a..c8d4d00b7 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Cache/Sqlite.php +++ b/library/TorrentPier/TorrentPier/Legacy/Cache/Sqlite.php @@ -78,9 +78,9 @@ class Sqlite extends Common // return if (is_array($this->prefix . $name)) { return $cached_items; - } else { - return isset($cached_items[$name]) ? $cached_items[$name] : false; } + + return $cached_items[$name] ?? false; } public function set($name, $value, $ttl = 604800) diff --git a/library/TorrentPier/TorrentPier/Legacy/Cache/Xcache.php b/library/TorrentPier/TorrentPier/Legacy/Cache/Xcache.php index 54df788c4..bf864c599 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Cache/Xcache.php +++ b/library/TorrentPier/TorrentPier/Legacy/Cache/Xcache.php @@ -60,11 +60,11 @@ class Xcache extends Common $this->num_queries++; return xcache_unset($this->prefix . $name); - } else { - xcache_clear_cache(XC_TYPE_PHP, 0); - xcache_clear_cache(XC_TYPE_VAR, 0); - return; } + + xcache_clear_cache(XC_TYPE_PHP, 0); + xcache_clear_cache(XC_TYPE_VAR, 0); + return; } public function is_installed() diff --git a/library/TorrentPier/TorrentPier/Legacy/Caches.php b/library/TorrentPier/TorrentPier/Legacy/Caches.php index 9f8d08ec8..3a6e792c8 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Caches.php +++ b/library/TorrentPier/TorrentPier/Legacy/Caches.php @@ -102,9 +102,9 @@ class Caches { if (!empty($cfg['shard_type']) && $cfg['shard_type'] != 'none') { return $this->cfg['db_dir'] . $name . '_*' . $ext; - } else { - return $this->cfg['db_dir'] . $name . $ext; } + + return $this->cfg['db_dir'] . $name . $ext; } public function get_table_schema($cfg) diff --git a/library/TorrentPier/TorrentPier/Legacy/Common/Upload.php b/library/TorrentPier/TorrentPier/Legacy/Common/Upload.php index 9fa6a0574..58b15f956 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Common/Upload.php +++ b/library/TorrentPier/TorrentPier/Legacy/Common/Upload.php @@ -92,7 +92,7 @@ class Upload // img if ($this->cfg['max_width'] || $this->cfg['max_height']) { if ($img_info = getimagesize($this->file['tmp_name'])) { - list($width, $height, $type, $attr) = $img_info; + [$width, $height, $type, $attr] = $img_info; // redefine ext if (!$width || !$height || !$type || !isset($this->img_types[$type])) { @@ -137,9 +137,9 @@ class Upload if ($mode == 'attach') { $file_path = get_attach_path($params['topic_id']); return $this->_move($file_path); - } else { - trigger_error("Invalid upload mode: $mode", E_USER_ERROR); } + + trigger_error("Invalid upload mode: $mode", E_USER_ERROR); } /** diff --git a/library/TorrentPier/TorrentPier/Legacy/Common/User.php b/library/TorrentPier/TorrentPier/Legacy/Common/User.php index e446a1924..da65582b3 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Common/User.php +++ b/library/TorrentPier/TorrentPier/Legacy/Common/User.php @@ -407,7 +407,9 @@ class User cache_update_userdata($this->data); return $this->data; - } elseif ($new_session_userdata = $this->session_create($userdata, false)) { + } + + if ($new_session_userdata = $this->session_create($userdata, false)) { // Removing guest sessions from this IP OLD_DB()->query(" DELETE FROM " . BB_SESSIONS . " diff --git a/library/TorrentPier/TorrentPier/Legacy/SqlDb.php b/library/TorrentPier/TorrentPier/Legacy/SqlDb.php index d695c3414..cab427698 100644 --- a/library/TorrentPier/TorrentPier/Legacy/SqlDb.php +++ b/library/TorrentPier/TorrentPier/Legacy/SqlDb.php @@ -258,7 +258,7 @@ class SqlDb $row = mysqli_fetch_assoc($result); if ($field_name) { - return isset($row[$field_name]) ? $row[$field_name] : false; + return $row[$field_name] ?? false; } return $row; diff --git a/library/TorrentPier/TorrentPier/Legacy/Template.php b/library/TorrentPier/TorrentPier/Legacy/Template.php index a2c8c65fd..f14ecedc5 100644 --- a/library/TorrentPier/TorrentPier/Legacy/Template.php +++ b/library/TorrentPier/TorrentPier/Legacy/Template.php @@ -983,13 +983,13 @@ class Template // adding language variable (eg: "english" or "german") // can be used to make truly multi-lingual templates - $this->vars['LANG'] = isset($this->vars['LANG']) ? $this->vars['LANG'] : $bb_cfg['default_lang']; + $this->vars['LANG'] = $this->vars['LANG'] ?? $bb_cfg['default_lang']; // adding current template $tpl = $this->root . '/'; if (substr($tpl, 0, 2) === './') { $tpl = substr($tpl, 2, strlen($tpl)); } - $this->vars['TEMPLATE'] = isset($this->vars['TEMPLATE']) ? $this->vars['TEMPLATE'] : $tpl; - $this->vars['TEMPLATE_NAME'] = isset($this->vars['TEMPLATE_NAME']) ? $this->vars['TEMPLATE_NAME'] : $this->tpl; + $this->vars['TEMPLATE'] = $this->vars['TEMPLATE'] ?? $tpl; + $this->vars['TEMPLATE_NAME'] = $this->vars['TEMPLATE_NAME'] ?? $this->tpl; } } diff --git a/library/ajax/edit_user_profile.php b/library/ajax/edit_user_profile.php index 7b963cd3c..7d9396035 100644 --- a/library/ajax/edit_user_profile.php +++ b/library/ajax/edit_user_profile.php @@ -130,7 +130,7 @@ switch ($field) { foreach (array('KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4) as $s => $m) { if (strpos($this->request['value'], $s) !== false) { - $value *= pow(1024, $m); + $value *= 1024 ** $m; break; } } diff --git a/library/attach_mod/attachment_mod.php b/library/attach_mod/attachment_mod.php index df8caa11a..c0682b39f 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 30e39677d..55737296f 100644 --- a/library/attach_mod/displaying.php +++ b/library/attach_mod/displaying.php @@ -213,7 +213,7 @@ function display_attachments($post_id) if (@(int)$display_categories[$attachments['_' . $post_id][$i]['extension']] == IMAGE_CAT && (int)$attach_config['img_display_inlined']) { if ((int)$attach_config['img_link_width'] != 0 || (int)$attach_config['img_link_height'] != 0) { - list($width, $height) = image_getdimension($filename); + [$width, $height] = image_getdimension($filename); if ($width == 0 && $height == 0) { $image = true; diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index 2dce0e925..a2a917ffb 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -40,7 +40,7 @@ $template->assign_vars(array( // Define show peers mode (count only || user names with complete % || full details) $cfg_sp_mode = $bb_cfg['bt_show_peers_mode']; -$get_sp_mode = (isset($_GET['spmode'])) ? $_GET['spmode'] : ''; +$get_sp_mode = $_GET['spmode'] ?? ''; $s_mode = 'count'; @@ -167,7 +167,7 @@ if ($tor_reged && $tor_info) { $bt_userdata = OLD_DB()->fetch_row($sql); - $user_status = isset($bt_userdata['user_status']) ? $bt_userdata['user_status'] : null; + $user_status = $bt_userdata['user_status'] ?? null; if (($min_ratio_dl || $min_ratio_warn) && $user_status != DL_STATUS_COMPLETE && $bt_user_id != $poster_id && $tor_type != TOR_TYPE_GOLD) { if (($user_ratio = get_bt_ratio($bt_userdata)) !== null) { diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 0a4dc8fdf..0933c5e24 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -68,7 +68,7 @@ function base64_unpack($string) for ($i = 1; $i <= $length; $i++) { $pos = $length - $i; $operand = strpos($chars, $string[$pos]); - $exponent = pow($base, $i - 1); + $exponent = $base ** ($i - 1); $decValue = $operand * $exponent; $number += $decValue; } @@ -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; diff --git a/library/attach_mod/includes/functions_thumbs.php b/library/attach_mod/includes/functions_thumbs.php index 07b248d0d..f9ae58970 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; } /** @@ -103,13 +103,13 @@ function create_thumbnail($source, $new_file, $mimetype) return false; } - list($width, $height, $type, ) = getimagesize($source); + [$width, $height, $type,] = getimagesize($source); if (!$width || !$height) { return false; } - list($new_width, $new_height) = get_img_size_format($width, $height); + [$new_width, $new_height] = get_img_size_format($width, $height); $tmp_path = $old_file = ''; diff --git a/library/includes/functions.php b/library/includes/functions.php index 6f50f2e61..13b246183 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -14,21 +14,21 @@ if (!defined('BB_ROOT')) { function get_path_from_id($id, $ext_id, $base_path, $first_div, $sec_div) { global $bb_cfg; - $ext = isset($bb_cfg['file_id_ext'][$ext_id]) ? $bb_cfg['file_id_ext'][$ext_id] : ''; + $ext = $bb_cfg['file_id_ext'][$ext_id] ?? ''; return ($base_path ? "$base_path/" : '') . floor($id / $first_div) . '/' . ($id % $sec_div) . '/' . $id . ($ext ? ".$ext" : ''); } function get_avatar_path($id, $ext_id, $base_path = null, $first_div = 10000, $sec_div = 100) { global $bb_cfg; - $base_path = isset($base_path) ? $base_path : $bb_cfg['avatars']['upload_path']; + $base_path = $base_path ?? $bb_cfg['avatars']['upload_path']; return get_path_from_id($id, $ext_id, $base_path, $first_div, $sec_div); } function get_attach_path($id, $ext_id = '', $base_path = null, $first_div = 10000, $sec_div = 100) { global $bb_cfg; - $base_path = isset($base_path) ? $base_path : $bb_cfg['attach']['upload_path']; + $base_path = $base_path ?? $bb_cfg['attach']['upload_path']; return get_path_from_id($id, $ext_id, $base_path, $first_div, $sec_div); } @@ -104,8 +104,8 @@ function get_last_read($topic_id = 0, $forum_id = 0) { global $tracking_topics, $tracking_forums, $user; - $t = isset($tracking_topics[$topic_id]) ? $tracking_topics[$topic_id] : 0; - $f = isset($tracking_forums[$forum_id]) ? $tracking_forums[$forum_id] : 0; + $t = $tracking_topics[$topic_id] ?? 0; + $f = $tracking_forums[$forum_id] ?? 0; return max($t, $f, $user->data['user_lastvisit']); } @@ -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) @@ -678,7 +678,7 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false) if (!isset($_GET[$var_name]) && !isset($_POST[$var_name])) { return (is_array($default)) ? array() : $default; } - $_REQUEST[$var_name] = isset($_POST[$var_name]) ? $_POST[$var_name] : $_GET[$var_name]; + $_REQUEST[$var_name] = $_POST[$var_name] ?? $_GET[$var_name]; } if (!isset($_REQUEST[$var_name]) || (is_array($_REQUEST[$var_name]) && !is_array($default)) || (is_array($default) && !is_array($_REQUEST[$var_name]))) { @@ -689,13 +689,13 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false) if (!is_array($default)) { $type = gettype($default); } else { - list($key_type, $type) = $default; + [$key_type, $type] = $default; $type = gettype($type); $key_type = gettype($key_type); if ($type == 'array') { reset($default); $default = current($default); - list($sub_key_type, $sub_type) = $default; + [$sub_key_type, $sub_type] = $default; $sub_type = gettype($sub_type); $sub_type = ($sub_type == 'array') ? 'NULL' : $sub_type; $sub_key_type = gettype($sub_key_type); @@ -741,10 +741,10 @@ function get_username($user_id) $usernames[$row['user_id']] = $row['username']; } return $usernames; - } else { - $row = OLD_DB()->fetch_row("SELECT username FROM " . BB_USERS . " WHERE user_id = $user_id LIMIT 1"); - return $row['username']; } + + $row = OLD_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) @@ -1386,7 +1386,7 @@ function bb_realpath($path) function redirectToLogin($url = '') { - redirectToUrl(LOGIN_URL . '?redirect=' . (($url) ?: (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'))); + redirectToUrl(LOGIN_URL . '?redirect=' . (($url) ?: ($_SERVER['REQUEST_URI'] ?? '/'))); } function meta_refresh($url, $time = 5) @@ -1455,7 +1455,7 @@ function get_forum_display_sort_option($selected_row = 0, $action = 'list', $lis if ($action == 'list') { for ($i = 0, $iMax = count($listrow['lang_key']); $i < $iMax; $i++) { $selected = ($i == $selected_row) ? ' selected="selected"' : ''; - $l_value = (isset($lang[$listrow['lang_key'][$i]])) ? $lang[$listrow['lang_key'][$i]] : $listrow['lang_key'][$i]; + $l_value = $lang[$listrow['lang_key'][$i]] ?? $listrow['lang_key'][$i]; $res .= ''; } } else { @@ -1612,7 +1612,7 @@ function get_topic_icon($topic, $is_unread = null) global $bb_cfg, $images; $t_hot = ($topic['topic_replies'] >= $bb_cfg['hot_threshold']); - $is_unread = null === $is_unread ? is_unread($topic['topic_last_post_time'], $topic['topic_id'], $topic['forum_id']) : $is_unread; + $is_unread = $is_unread ?? is_unread($topic['topic_last_post_time'], $topic['topic_id'], $topic['forum_id']); if ($topic['topic_status'] == TOPIC_MOVED) { $folder_image = $images['folder']; diff --git a/library/includes/functions_admin_torrent.php b/library/includes/functions_admin_torrent.php index aec51a6b2..aedf086d7 100644 --- a/library/includes/functions_admin_torrent.php +++ b/library/includes/functions_admin_torrent.php @@ -77,9 +77,9 @@ function set_tpl_vars_lang($default_cfg) foreach ($default_cfg as $config_name => $config_value) { $template->assign_vars(array( - 'L_' . strtoupper($config_name) => isset($lang[$config_name]) ? $lang[$config_name] : '', - 'L_' . strtoupper($config_name) . '_EXPL' => isset($lang[$config_name . '_expl']) ? $lang[$config_name . '_expl'] : '', - 'L_' . strtoupper($config_name) . '_HEAD' => isset($lang[$config_name . '_head']) ? $lang[$config_name . '_head'] : '', + 'L_' . strtoupper($config_name) => $lang[$config_name] ?? '', + 'L_' . strtoupper($config_name) . '_EXPL' => $lang[$config_name . '_expl'] ?? '', + 'L_' . strtoupper($config_name) . '_HEAD' => $lang[$config_name . '_head'] ?? '', )); } } diff --git a/library/includes/functions_atom.php b/library/includes/functions_atom.php index 77e848442..7a17b185d 100644 --- a/library/includes/functions_atom.php +++ b/library/includes/functions_atom.php @@ -81,9 +81,9 @@ function update_forum_feed($forum_id, $forum_data) } if (create_atom($file_path, 'f', $forum_id, htmlCHR($forum_data['forum_name']), $topics)) { return true; - } else { - return false; } + + return false; } function update_user_feed($user_id, $username) @@ -127,9 +127,9 @@ function update_user_feed($user_id, $username) } if (create_atom($file_path, 'u', $user_id, wbr($username), $topics)) { return true; - } else { - return false; } + + return false; } function create_atom($file_path, $mode, $id, $title, $topics) diff --git a/library/includes/functions_torrent.php b/library/includes/functions_torrent.php index 6c05f373a..9fd21df9f 100644 --- a/library/includes/functions_torrent.php +++ b/library/includes/functions_torrent.php @@ -576,9 +576,9 @@ function get_registered_torrents($id, $mode) if ($rowset = @OLD_DB()->sql_fetchrowset($result)) { return $rowset; - } else { - return false; } + + return false; } function torrent_error_exit($message) diff --git a/library/includes/functions_validate.php b/library/includes/functions_validate.php index 61f7c4311..6e747cd34 100644 --- a/library/includes/functions_validate.php +++ b/library/includes/functions_validate.php @@ -24,7 +24,9 @@ function validate_username($username, $check_ban_and_taken = true) // Length if (mb_strlen($username, 'UTF-8') > USERNAME_MAX_LENGTH) { return $lang['USERNAME_TOO_LONG']; - } elseif (mb_strlen($username, 'UTF-8') < USERNAME_MIN_LENGTH) { + } + + if (mb_strlen($username, 'UTF-8') < USERNAME_MIN_LENGTH) { return $lang['USERNAME_TOO_SMALL']; } // Allowed symbols @@ -94,9 +96,9 @@ function validate_email($email, $check_ban_and_taken = true) if ($row = OLD_DB()->fetch_row("SELECT `user_email` FROM " . BB_USERS . " WHERE user_email = '$email_sql' LIMIT 1")) { if ($row['user_email'] == $userdata['user_email']) { return false; - } else { - return $lang['EMAIL_TAKEN']; } + + return $lang['EMAIL_TAKEN']; } } diff --git a/login.php b/login.php index b38598afe..7093071f2 100644 --- a/login.php +++ b/login.php @@ -37,7 +37,7 @@ if (preg_match('/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si', $_SERVER['QUERY_STRING } elseif (!empty($_POST['redirect'])) { $redirect_url = str_replace('&', '&', htmlspecialchars($_POST['redirect'])); } elseif (!empty($_SERVER['HTTP_REFERER']) && ($parts = @parse_url($_SERVER['HTTP_REFERER']))) { - $redirect_url = (isset($parts['path']) ? $parts['path'] : "index.php") . (isset($parts['query']) ? '?' . $parts['query'] : ''); + $redirect_url = ($parts['path'] ?? "index.php") . (isset($parts['query']) ? '?' . $parts['query'] : ''); } $redirect_url = str_replace('&admin=1', '', $redirect_url); @@ -56,8 +56,8 @@ if (isset($_REQUEST['admin']) && !IS_AM) { $mod_admin_login = (IS_AM && !$user->data['session_admin']); // login username & password -$login_username = ($mod_admin_login) ? $userdata['username'] : (isset($_POST['login_username']) ? $_POST['login_username'] : ''); -$login_password = isset($_POST['login_password']) ? $_POST['login_password'] : ''; +$login_username = ($mod_admin_login) ? $userdata['username'] : ($_POST['login_username'] ?? ''); +$login_password = $_POST['login_password'] ?? ''; // Проверка на неверную комбинацию логин/пароль $need_captcha = false; diff --git a/modcp.php b/modcp.php index 2e9681927..39119a67d 100644 --- a/modcp.php +++ b/modcp.php @@ -72,9 +72,9 @@ function validate_mode_condition($request_index, $mod_action = '') } // Obtain initial vars -$forum_id = isset($_REQUEST['f']) ? $_REQUEST['f'] : 0; -$topic_id = isset($_REQUEST['t']) ? $_REQUEST['t'] : 0; -$post_id = isset($_REQUEST['p']) ? $_REQUEST['p'] : 0; +$forum_id = $_REQUEST['f'] ?? 0; +$topic_id = $_REQUEST['t'] ?? 0; +$post_id = $_REQUEST['p'] ?? 0; $start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0; $confirmed = isset($_POST['confirm']); @@ -168,7 +168,7 @@ if (!$is_auth['auth_mod']) { // Redirect to login page if not admin session if ($is_moderator && !$userdata['session_admin']) { - $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : $_SERVER['REQUEST_URI']; + $redirect = $_POST['redirect'] ?? $_SERVER['REQUEST_URI']; redirectToUrl(LOGIN_URL . "?redirect=$redirect&admin=1"); } @@ -191,7 +191,7 @@ switch ($mode) { bb_die($lang['NONE_SELECTED']); } - $req_topics = isset($_POST['topic_id_list']) ? $_POST['topic_id_list'] : $topic_id; + $req_topics = $_POST['topic_id_list'] ?? $topic_id; validate_topics($forum_id, $req_topics, $topic_titles); if (!$req_topics || !($topic_csv = get_id_csv($req_topics))) { @@ -372,10 +372,10 @@ switch ($mode) { //mpd $delete_posts = isset($_POST['delete_posts']); $split = (isset($_POST['split_type_all']) || isset($_POST['split_type_beyond'])); - $posts = (isset($_POST['post_id_list'])) ? $_POST['post_id_list'] : array(); + $posts = $_POST['post_id_list'] ?? array(); $start = /* (isset($_POST['start'])) ? intval($_POST['start']) : */ 0; - $topic_first_post_id = (isset($topic_row['topic_first_post_id'])) ? $topic_row['topic_first_post_id'] : ''; + $topic_first_post_id = $topic_row['topic_first_post_id'] ?? ''; $post_id_sql = $req_post_id_sql = array(); diff --git a/posting.php b/posting.php index 2c4acdaab..6edc543fe 100644 --- a/posting.php +++ b/posting.php @@ -530,7 +530,7 @@ if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) { } } //bt -$topic_dl_type = (isset($post_info['topic_dl_type'])) ? $post_info['topic_dl_type'] : 0; +$topic_dl_type = $post_info['topic_dl_type'] ?? 0; if ($post_info['allow_reg_tracker'] && $post_data['first_post'] && ($topic_dl_type || $is_auth['auth_mod'])) { $sql = " diff --git a/privmsg.php b/privmsg.php index 5e87c9213..8df644ad9 100644 --- a/privmsg.php +++ b/privmsg.php @@ -1288,7 +1288,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 1f8e8b8f2..a726ade2f 100644 --- a/search.php +++ b/search.php @@ -70,7 +70,7 @@ $tracking_forums = get_tracks('forum'); if ($mode =& $_REQUEST['mode']) { // This handles the simple windowed user search functions called from various other scripts if ($mode == 'searchuser') { - $username = isset($_POST['search_username']) ? $_POST['search_username'] : ''; + $username = $_POST['search_username'] ?? ''; username_search($username); exit; } diff --git a/styles/templates/default/tpl_config.php b/styles/templates/default/tpl_config.php index 368620abe..4425c784d 100644 --- a/styles/templates/default/tpl_config.php +++ b/styles/templates/default/tpl_config.php @@ -26,7 +26,7 @@ global $bb_cfg, $page_cfg, $template, $images, $lang; $width = $height = array(); -$template_name = basename(dirname(__FILE__)); +$template_name = basename(__DIR__); $_img = BB_ROOT . 'styles/images/'; $_main = BB_ROOT . 'styles/' . basename(TEMPLATES_DIR) . '/' . $template_name . '/images/'; diff --git a/tracker.php b/tracker.php index f1849a06c..0d954945c 100644 --- a/tracker.php +++ b/tracker.php @@ -692,8 +692,8 @@ if ($allowed_forums) { $passkey = OLD_DB()->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$user_id . " LIMIT 1"); // Build torrents table foreach (OLD_DB()->fetch_rowset($sql) as $tor) { - $dl = isset($tor['speed_down']) ? $tor['speed_down'] : 0; - $ul = isset($tor['speed_up']) ? $tor['speed_up'] : 0; + $dl = $tor['speed_down'] ?? 0; + $ul = $tor['speed_up'] ?? 0; $seeds = $tor['seeders']; $leechs = $tor['leechers']; diff --git a/viewforum.php b/viewforum.php index dc39ae6c5..ea96d2c30 100644 --- a/viewforum.php +++ b/viewforum.php @@ -82,7 +82,7 @@ $mod_redirect_url = ''; $tor_status = -1; // all by default if ($is_auth['auth_mod']) { - $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : $_SERVER['REQUEST_URI']; + $redirect = $_POST['redirect'] ?? $_SERVER['REQUEST_URI']; $redirect = url_arg($redirect, 'mod', 1, '&'); $mod_redirect_url = LOGIN_URL . "?redirect=$redirect&admin=1"; @@ -456,7 +456,7 @@ foreach ($topic_rowset as $topic) { 'TOR_STATUS_ICON' => isset($topic['tor_status']) ? $bb_cfg['tor_icons'][$topic['tor_status']] : '', 'TOR_STATUS_TEXT' => isset($topic['tor_status']) ? $lang['TOR_STATUS_NAME'][$topic['tor_status']] : '', - 'ATTACH' => isset($topic['topic_attachment']) ? $topic['topic_attachment'] : false, + 'ATTACH' => $topic['topic_attachment'] ?? false, 'STATUS' => $topic['topic_status'], 'TYPE' => $topic['topic_type'], 'DL' => ($topic['topic_dl_type'] == TOPIC_DL_TYPE_DL && !$forum_data['allow_reg_tracker']), diff --git a/viewtopic.php b/viewtopic.php index 25b2f0da9..29760559a 100644 --- a/viewtopic.php +++ b/viewtopic.php @@ -182,7 +182,7 @@ $moderation = (!empty($_REQUEST['mod']) && $is_auth['auth_mod']); $mod_redirect_url = ''; if ($is_auth['auth_mod']) { - $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : @$_SERVER['REQUEST_URI']; + $redirect = $_POST['redirect'] ?? @$_SERVER['REQUEST_URI']; $redirect = url_arg($redirect, 'mod', 1, '&'); $mod_redirect_url = LOGIN_URL . "?redirect=$redirect&admin=1"; @@ -794,7 +794,7 @@ foreach ($is_auth as $name => $is) { } $template->assign_vars(array( - 'PG_ROW_CLASS' => isset($pg_row_class) ? $pg_row_class : 'row1', + 'PG_ROW_CLASS' => $pg_row_class ?? 'row1', )); if (IS_ADMIN) {