From 609696d0d0bba80257af97910dda5756aede1ff1 Mon Sep 17 00:00:00 2001 From: Vasily Komrakov Date: Sun, 7 May 2017 18:13:32 +0300 Subject: [PATCH 01/32] Fix require file. --- admin/admin_attachments.php | 2 +- admin/admin_extensions.php | 3 ++- admin/admin_forum_prune.php | 3 ++- admin/admin_forumauth.php | 3 ++- admin/admin_forumauth_list.php | 3 ++- admin/admin_log.php | 3 ++- admin/admin_mass_email.php | 3 ++- admin/admin_phpinfo.php | 3 ++- admin/admin_ranks.php | 3 ++- admin/admin_smilies.php | 3 ++- admin/admin_user_ban.php | 3 ++- admin/admin_words.php | 3 ++- admin/index.php | 2 +- bt/announce.php | 3 +-- bt/scrape.php | 3 +-- 15 files changed, 26 insertions(+), 17 deletions(-) diff --git a/admin/admin_attachments.php b/admin/admin_attachments.php index e15666c83..5ecaebd7c 100644 --- a/admin/admin_attachments.php +++ b/admin/admin_attachments.php @@ -30,7 +30,7 @@ if (!empty($setmodules)) { $module['ATTACHMENTS']['QUOTA_LIMITS'] = $filename . '?mode=quota'; return; } -require('./pagestart.php'); +require __DIR__ . '/pagestart.php'; $error = false; diff --git a/admin/admin_extensions.php b/admin/admin_extensions.php index 9fc0910b0..d754f6890 100644 --- a/admin/admin_extensions.php +++ b/admin/admin_extensions.php @@ -29,7 +29,8 @@ if (!empty($setmodules)) { $module['ATTACHMENTS']['EXTENSION_GROUP_MANAGE'] = $filename . '?mode=groups'; return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; function update_attach_extensions() { diff --git a/admin/admin_forum_prune.php b/admin/admin_forum_prune.php index 90d3dee82..bc73c9774 100644 --- a/admin/admin_forum_prune.php +++ b/admin/admin_forum_prune.php @@ -27,7 +27,8 @@ if (!empty($setmodules)) { $module['FORUMS']['PRUNE'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; $all_forums = -1; $pruned_total = 0; diff --git a/admin/admin_forumauth.php b/admin/admin_forumauth.php index 34a3f2c9e..cb365e203 100644 --- a/admin/admin_forumauth.php +++ b/admin/admin_forumauth.php @@ -27,7 +27,8 @@ if (!empty($setmodules)) { $module['FORUMS']['PERMISSIONS'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; $forum_auth_fields = array( 'auth_view', diff --git a/admin/admin_forumauth_list.php b/admin/admin_forumauth_list.php index 613563f78..df3e268fe 100644 --- a/admin/admin_forumauth_list.php +++ b/admin/admin_forumauth_list.php @@ -27,7 +27,8 @@ if (!empty($setmodules)) { $module['FORUMS']['PERMISSIONS_LIST'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; // View Read Post Reply Edit Delete Sticky Announce Vote Poll PostAttach Download $simple_auth_ary = array( diff --git a/admin/admin_log.php b/admin/admin_log.php index 3452a403b..980e11381 100644 --- a/admin/admin_log.php +++ b/admin/admin_log.php @@ -27,7 +27,8 @@ if (!empty($setmodules)) { $module['USERS']['ACTIONS_LOG'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; $datastore->enqueue(array( 'moderators', diff --git a/admin/admin_mass_email.php b/admin/admin_mass_email.php index 4e6fd805d..5e4225127 100644 --- a/admin/admin_mass_email.php +++ b/admin/admin_mass_email.php @@ -27,7 +27,8 @@ if (!empty($setmodules)) { $module['MODS']['MASS_EMAIL'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; @set_time_limit(1200); diff --git a/admin/admin_phpinfo.php b/admin/admin_phpinfo.php index f2a86a541..a88ce9293 100644 --- a/admin/admin_phpinfo.php +++ b/admin/admin_phpinfo.php @@ -27,6 +27,7 @@ if (!empty($setmodules)) { $module['GENERAL']['PHP_INFO'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; phpinfo(); diff --git a/admin/admin_ranks.php b/admin/admin_ranks.php index 75bec2f52..9a2ceab7c 100644 --- a/admin/admin_ranks.php +++ b/admin/admin_ranks.php @@ -27,7 +27,8 @@ if (!empty($setmodules)) { $module['USERS']['RANKS'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; $_POST['special_rank'] = 1; $_POST['min_posts'] = -1; diff --git a/admin/admin_smilies.php b/admin/admin_smilies.php index 1e69fb524..e7c7e7859 100644 --- a/admin/admin_smilies.php +++ b/admin/admin_smilies.php @@ -27,7 +27,8 @@ if (!empty($setmodules)) { $module['GENERAL']['SMILIES'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; // Check to see what mode we should operate in if (isset($_POST['mode']) || isset($_GET['mode'])) { diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php index f1fb850a6..0a5be1865 100644 --- a/admin/admin_user_ban.php +++ b/admin/admin_user_ban.php @@ -27,7 +27,8 @@ if (!empty($setmodules)) { $module['USERS']['BAN_MANAGEMENT'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; if (isset($_POST['submit'])) { $user_bansql = ''; diff --git a/admin/admin_words.php b/admin/admin_words.php index 23891efe0..a09abd6c5 100644 --- a/admin/admin_words.php +++ b/admin/admin_words.php @@ -27,7 +27,8 @@ if (!empty($setmodules)) { $module['GENERAL']['WORD_CENSOR'] = basename(__FILE__); return; } -require('./pagestart.php'); + +require __DIR__ . '/pagestart.php'; if (!$bb_cfg['use_word_censor']) { bb_die('Word censor disabled

($bb_cfg[\'use_word_censor\'] in config.php)'); diff --git a/admin/index.php b/admin/index.php index 5e838b41a..598e3c9fe 100644 --- a/admin/index.php +++ b/admin/index.php @@ -23,7 +23,7 @@ * SOFTWARE. */ -require('./pagestart.php'); +require __DIR__ . '/pagestart.php'; // Generate relevant output if (isset($_GET['pane']) && $_GET['pane'] == 'left') { diff --git a/bt/announce.php b/bt/announce.php index 5cc2471bb..44cab0307 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -188,8 +188,7 @@ function msg_die($msg) } // Start announcer -define('TR_ROOT', './'); -require(TR_ROOT . 'includes/init_tr.php'); +require __DIR__ . '/includes/init_tr.php'; $seeder = ($left == 0) ? 1 : 0; $stopped = ($event === 'stopped'); diff --git a/bt/scrape.php b/bt/scrape.php index d30a6dac9..5d561d327 100644 --- a/bt/scrape.php +++ b/bt/scrape.php @@ -59,8 +59,7 @@ function msg_die($msg) die($output); } -define('TR_ROOT', './'); -require(TR_ROOT . 'includes/init_tr.php'); +require __DIR__ . '/includes/init_tr.php'; $info_hash_sql = rtrim(DB()->escape($info_hash), ' '); From 3f0504912ffc969c527f4ef0887b7353a8b68c76 Mon Sep 17 00:00:00 2001 From: Vasily Komrakov Date: Sun, 7 May 2017 18:14:26 +0300 Subject: [PATCH 02/32] Fix sql. Remove excess "group by". --- library/attach_mod/displaying_torrent.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index 2acd53104..8d59562d8 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -297,7 +297,6 @@ if ($tor_reged && $tor_info) { FROM " . BB_BT_TRACKER . " tr, " . BB_USERS . " u WHERE tr.topic_id = $tor_id AND u.user_id = tr.user_id - GROUP BY tr.ip, tr.user_id, tr.port, tr.seeder ORDER BY u.username LIMIT $show_peers_limit"; } else { @@ -308,7 +307,6 @@ if ($tor_reged && $tor_info) { FROM " . BB_BT_TRACKER . " tr LEFT JOIN " . BB_USERS . " u ON u.user_id = tr.user_id WHERE tr.topic_id = $tor_id - GROUP BY tr.ip, tr.user_id, tr.port, tr.seeder ORDER BY $full_mode_order $full_mode_sort_dir LIMIT $show_peers_limit"; } From 2aa166ea08df1c4161225da9ec5193a3a6de1c81 Mon Sep 17 00:00:00 2001 From: Vasily Komrakov Date: Sun, 7 May 2017 18:14:47 +0300 Subject: [PATCH 03/32] Fix check version php. --- library/includes/init_bb.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index e04f2276a..f3341898e 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -26,7 +26,7 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -if (PHP_VERSION < '5.3') { +if (version_compare(PHP_VERSION, '5.3', '<')) { die('TorrentPier requires PHP version 5.3+. Your PHP version ' . PHP_VERSION); } if (!defined('BB_SCRIPT')) { From 7e29eb925f3801fb30973ed8ca3d7d87cb73963a Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 00:47:38 +0300 Subject: [PATCH 04/32] Binary-unsafe 'fopen(...)' usage (cherry picked from commit b9686af) --- admin/admin_attachments.php | 4 ++-- library/includes/classes/emailer.php | 2 +- library/includes/functions_atom.php | 2 +- library/includes/functions_torrent.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/admin/admin_attachments.php b/admin/admin_attachments.php index 5ecaebd7c..098e8785d 100644 --- a/admin/admin_attachments.php +++ b/admin/admin_attachments.php @@ -220,7 +220,7 @@ if ($check_upload) { } if (!$error) { - if (!($fp = @fopen($upload_dir . '/0_000000.000', 'w'))) { + if (!($fp = @fopen($upload_dir . '/0_000000.000', 'wb'))) { $error = true; $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $attach_config['upload_dir']) . '
'; } else { @@ -375,7 +375,7 @@ if ($check_image_cat) { } if (!$error) { - if (!($fp = @fopen($upload_dir . '/0_000000.000', 'w'))) { + if (!($fp = @fopen($upload_dir . '/0_000000.000', 'wb'))) { $error = true; $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $upload_dir) . '
'; } else { diff --git a/library/includes/classes/emailer.php b/library/includes/classes/emailer.php index a315e807a..966a07a40 100644 --- a/library/includes/classes/emailer.php +++ b/library/includes/classes/emailer.php @@ -130,7 +130,7 @@ class emailer } } - if (!($fd = @fopen($tpl_file, 'r'))) { + if (!($fd = @fopen($tpl_file, 'rb'))) { bb_die('Failed opening template file :: ' . $tpl_file); } diff --git a/library/includes/functions_atom.php b/library/includes/functions_atom.php index e3e5e613c..a0ecf1e46 100644 --- a/library/includes/functions_atom.php +++ b/library/includes/functions_atom.php @@ -211,7 +211,7 @@ function create_atom($file_path, $mode, $id, $title, $topics) } $atom .= ""; @unlink($file_path); - $fp = fopen($file_path, "w"); + $fp = fopen($file_path, 'wb'); fwrite($fp, $atom); fclose($fp); return true; diff --git a/library/includes/functions_torrent.php b/library/includes/functions_torrent.php index fc9df9c85..7d7a11f88 100644 --- a/library/includes/functions_torrent.php +++ b/library/includes/functions_torrent.php @@ -286,7 +286,7 @@ function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED if ($bb_cfg['bt_disable_dht']) { $tor['info']['private'] = (int)1; - $fp = fopen($filename, 'w+'); + $fp = fopen($filename, 'wb+'); fwrite($fp, bencode($tor)); fclose($fp); } From f8d84bc917cf798394589f4ca17d2c044958e488 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 00:48:38 +0300 Subject: [PATCH 05/32] 'safe_mode' is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0). (cherry picked from commit 85bd60e) --- admin/admin_rebuild_search.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/admin/admin_rebuild_search.php b/admin/admin_rebuild_search.php index 538b6da56..11c7d4eda 100644 --- a/admin/admin_rebuild_search.php +++ b/admin/admin_rebuild_search.php @@ -115,17 +115,6 @@ if (isset($_REQUEST['time_limit'])) { $time_limit = $def_time_limit; $time_limit_explain = $lang['TIME_LIMIT_EXPLAIN']; - // check for safe mode timeout - if (ini_get('safe_mode')) { - // get execution time - $max_execution_time = ini_get('max_execution_time'); - $time_limit_explain .= '
' . sprintf($lang['TIME_LIMIT_EXPLAIN_SAFE'], $max_execution_time); - - if ($time_limit > $max_execution_time) { - $time_limit = $max_execution_time; - } - } - // check for webserver timeout (IE returns null) if (isset($_SERVER["HTTP_KEEP_ALIVE"])) { // get webserver timeout From b9330f6aae8c085941057465a77d3f04f97869ad Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 00:51:10 +0300 Subject: [PATCH 06/32] Unit of measure 'px' is redundant. (cherry picked from commit ca6d622) --- library/includes/core/mysql.php | 4 ++-- library/includes/functions_dev.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/includes/core/mysql.php b/library/includes/core/mysql.php index d5b7b1b20..69b0b3a24 100644 --- a/library/includes/core/mysql.php +++ b/library/includes/core/mysql.php @@ -1010,14 +1010,14 @@ class sql_db $dbg = $this->dbg[$id]; $this->explain_out .= ' - +
 ' . $dbg['src'] . '  [' . sprintf('%.4f', $dbg['time']) . ' s]  ' . $dbg['info'] . ' ' . "$this->db_server.$this->selected_db" . ' :: Query #' . ($this->num_queries + 1) . ' 
' . $this->explain_hold . '
-
' . short_query($dbg['sql'], true) . '  
+
' . short_query($dbg['sql'], true) . '  

'; break; diff --git a/library/includes/functions_dev.php b/library/includes/functions_dev.php index 28a7d56e7..6c31a0a03 100644 --- a/library/includes/functions_dev.php +++ b/library/includes/functions_dev.php @@ -70,7 +70,7 @@ function get_sql_log_html($db_obj, $log_name) . '' . $time . ' ' . '' . $perc . '' . ' ' - . '' . $sql . '' + . '' . $sql . '' . ' # ' . $info . ' ' . '' . "\n"; From 75990902ae5b4e60cf4957bf9da546f4ce6779c6 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 00:52:25 +0300 Subject: [PATCH 07/32] If-return-return could be simplified. (cherry picked from commit bcf57cd) --- library/attach_mod/includes/functions_attach.php | 6 +----- library/includes/functions_torrent.php | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 106d42404..5dac8ccc6 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -454,11 +454,7 @@ function user_in_group($user_id, $group_id) $num_rows = DB()->num_rows($result); DB()->sql_freeresult($result); - if ($num_rows == 0) { - return false; - } - - return true; + return !($num_rows == 0); } /** diff --git a/library/includes/functions_torrent.php b/library/includes/functions_torrent.php index 7d7a11f88..4cb1b9ae6 100644 --- a/library/includes/functions_torrent.php +++ b/library/includes/functions_torrent.php @@ -624,11 +624,7 @@ function ocelot_update_tracker($action, $updates) $max_attempts = 3; $err = false; - if (ocelot_send_request($get, $max_attempts, $err) === false) { - return false; - } - - return true; + return !(ocelot_send_request($get, $max_attempts, $err) === false); } function ocelot_send_request($get, $max_attempts = 1, &$err = false) From dcd19e54a9d716358c333a0289bf38337bc73a52 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 00:53:16 +0300 Subject: [PATCH 08/32] One-time use variables. (cherry picked from commit 95575e1) --- library/attach_mod/includes/functions_attach.php | 4 +--- library/attach_mod/includes/functions_filetypes.php | 8 ++------ library/includes/functions.php | 4 +--- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 5dac8ccc6..82145d92c 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -196,9 +196,7 @@ function unlink_attach($filename, $mode = false) $filename = $upload_dir . '/' . $filename; } - $deleted = @unlink($filename); - - return $deleted; + return @unlink($filename); } /** diff --git a/library/attach_mod/includes/functions_filetypes.php b/library/attach_mod/includes/functions_filetypes.php index 7d3ac79d6..aa7e06bef 100644 --- a/library/attach_mod/includes/functions_filetypes.php +++ b/library/attach_mod/includes/functions_filetypes.php @@ -49,9 +49,7 @@ function read_word($fp) { $data = fread($fp, 2); - $value = ord($data[1]) * 256 + ord($data[0]); - - return $value; + return ord($data[1]) * 256 + ord($data[0]); } /** @@ -61,9 +59,7 @@ function read_byte($fp) { $data = fread($fp, 1); - $value = ord($data); - - return $value; + return ord($data); } /** diff --git a/library/includes/functions.php b/library/includes/functions.php index 274e2032f..0953a4190 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -1442,9 +1442,7 @@ function setup_style() require TEMPLATES_DIR . '/' . $tpl_dir_name . '/tpl_config.php'; - $theme = array('template_name' => $tpl_dir_name); - - return $theme; + return array('template_name' => $tpl_dir_name); } // Create date / time with format and friendly date From fc8d71de5cee2242db6c2db5463e2bfa9f74a6be Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 00:55:41 +0300 Subject: [PATCH 09/32] Strings normalization. (cherry picked from commit 72f9ddd) --- admin/admin_user_search.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/admin/admin_user_search.php b/admin/admin_user_search.php index 294d51c98..18e116feb 100644 --- a/admin/admin_user_search.php +++ b/admin/admin_user_search.php @@ -437,7 +437,7 @@ if (!isset($_REQUEST['dosearch'])) { case 'search_joindate': $base_url .= '&search_joindate=true&date_type=' . rawurlencode($date_type) . '&date_day=' . rawurlencode($date_day) . '&date_month=' . rawurlencode($date_month) . '&date_year=' . rawurlencode(stripslashes($date_year)); - $date_type = trim(strtolower($date_type)); + $date_type = strtolower(trim($date_type)); if ($date_type != 'before' && $date_type != 'after') { bb_die($lang['SEARCH_INVALID_DATE']); @@ -543,8 +543,8 @@ if (!isset($_REQUEST['dosearch'])) { break; case 'search_postcount': - $postcount_type = trim(strtolower($postcount_type)); - $postcount_value = trim(strtolower($postcount_value)); + $postcount_type = strtolower(trim($postcount_type)); + $postcount_value = strtolower(trim($postcount_value)); $base_url .= '&search_postcount=true&postcount_type=' . rawurlencode($postcount_type) . '&postcount_value=' . rawurlencode(stripslashes($postcount_value)); @@ -634,7 +634,7 @@ if (!isset($_REQUEST['dosearch'])) { bb_die($lang['SEARCH_INVALID_USERFIELD']); } - $userfield_type = trim(strtolower($userfield_type)); + $userfield_type = strtolower(trim($userfield_type)); switch ($userfield_type) { case 'icq': @@ -679,7 +679,7 @@ if (!isset($_REQUEST['dosearch'])) { break; case 'search_lastvisited': - $lastvisited_type = trim(strtolower($lastvisited_type)); + $lastvisited_type = strtolower(trim($lastvisited_type)); $lastvisited_days = intval($lastvisited_days); $base_url .= '&search_lastvisited=true&lastvisited_type=' . rawurlencode(stripslashes($lastvisited_type)) . '&lastvisited_days=' . rawurlencode($lastvisited_days); @@ -718,7 +718,7 @@ if (!isset($_REQUEST['dosearch'])) { case 'search_language': $base_url .= '&search_language=true&language_type=' . rawurlencode(stripslashes($language_type)); - $language_type = trim(strtolower(stripslashes($language_type))); + $language_type = strtolower(trim(stripslashes($language_type))); if ($language_type == '') { bb_die($lang['SEARCH_INVALID_LANGUAGE']); @@ -789,7 +789,7 @@ if (!isset($_REQUEST['dosearch'])) { case 'search_misc': default: - $misc = trim(strtolower($misc)); + $misc = strtolower(trim($misc)); $base_url .= '&search_misc=true&misc=' . rawurlencode(stripslashes($misc)); From 02a06e68c910e7410b73afbbeac86843a5face4c Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 00:56:01 +0300 Subject: [PATCH 10/32] Ternary operator could be simplified. (cherry picked from commit 57f0cd7) --- index.php | 2 +- library/attach_mod/includes/functions_attach.php | 2 +- library/includes/template.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 330a627f9..805d2681b 100644 --- a/index.php +++ b/index.php @@ -211,7 +211,7 @@ foreach ($cat_forums as $cid => $c) { )); $template->assign_vars(array( - 'H_C_AL_MESS' => ($hide_cat_opt && !$showhide) ? true : false, + 'H_C_AL_MESS' => ($hide_cat_opt && !$showhide), )); if (!$showhide && isset($hide_cat_user[$cid]) && !$viewcat) { diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 82145d92c..fac3e87eb 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -253,7 +253,7 @@ function physical_filename_already_stored($filename) $num_rows = DB()->num_rows($result); DB()->sql_freeresult($result); - return ($num_rows == 0) ? false : true; + return $num_rows != 0; } /** diff --git a/library/includes/template.php b/library/includes/template.php index a2351c624..2147df9f1 100644 --- a/library/includes/template.php +++ b/library/includes/template.php @@ -774,7 +774,7 @@ class template if (!$count_if) { $keyword_type = XS_TAG_IF; } - $str = $this->compile_tag_if($params_str, $keyword_type == XS_TAG_IF ? false : true); + $str = $this->compile_tag_if($params_str, $keyword_type != XS_TAG_IF); if ($str) { $compiled[] = ''; if ($keyword_type == XS_TAG_IF) { From 6eed2e8a7618b275ce345897459dfb4dd2307ddc Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 00:56:13 +0300 Subject: [PATCH 11/32] 'unset(...)' calls could be merged. (cherry picked from commit 8b3d5e7) --- modcp.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modcp.php b/modcp.php index 89fe8f640..eda8b14ec 100644 --- a/modcp.php +++ b/modcp.php @@ -174,8 +174,7 @@ if ($mode == 'ip') { $is_auth['auth_mod'] = true; $_POST['insert_bot_msg'] = 1; - unset($_POST['topic_id_list']); - unset($_POST['move_leave_shadow']); + unset($_POST['topic_id_list'], $_POST['move_leave_shadow']); } } From 6abd9babc96038dac689fcfe90b1bc8ac1608867 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 00:57:55 +0300 Subject: [PATCH 12/32] Alias functions usage. (cherry picked from commit 4a79c08) --- admin/admin_attach_cp.php | 2 +- admin/admin_attachments.php | 6 +-- admin/admin_extensions.php | 22 +++++----- admin/admin_forum_prune.php | 2 +- admin/admin_log.php | 8 ++-- admin/admin_mass_email.php | 4 +- admin/index.php | 2 +- admin/stats/tracker.php | 6 +-- bt/includes/init_tr.php | 2 +- callseed.php | 2 +- common.php | 6 +-- dl_list.php | 2 +- group.php | 2 +- index.php | 6 +-- install/upgrade/r583-convert_avatars.php | 2 +- library/ajax/group_membership.php | 2 +- library/ajax/index_data.php | 6 +-- library/attach_mod/displaying.php | 8 ++-- .../attach_mod/includes/functions_admin.php | 6 +-- .../attach_mod/includes/functions_attach.php | 10 ++--- .../attach_mod/includes/functions_delete.php | 10 ++--- .../attach_mod/includes/functions_selects.php | 14 +++---- library/includes/bbcode.php | 10 ++--- library/includes/cache/sqlite.php | 2 +- library/includes/core/mysql.php | 38 +++++++++--------- library/includes/cron/cron_run.php | 4 +- .../includes/cron/jobs/attach_maintenance.php | 12 +++--- library/includes/cron/jobs/clean_dlstat.php | 2 +- library/includes/cron/jobs/tr_maintenance.php | 4 +- .../includes/cron/jobs/tr_make_snapshot.php | 8 ++-- .../includes/datastore/build_cat_forums.php | 4 +- library/includes/datastore/sqlite.php | 2 +- library/includes/functions.php | 8 ++-- library/includes/functions_admin.php | 4 +- library/includes/functions_admin_torrent.php | 2 +- library/includes/functions_group.php | 4 +- library/includes/functions_post.php | 4 +- library/includes/functions_validate.php | 4 +- library/includes/online_userlist.php | 12 +++--- library/includes/page_header.php | 2 +- library/includes/sessions.php | 4 +- library/includes/smtp.php | 40 +++++++++---------- library/includes/template.php | 18 ++++----- library/includes/ucp/email.php | 2 +- library/includes/ucp/register.php | 4 +- library/includes/ucp/viewprofile.php | 4 +- login.php | 2 +- modcp.php | 8 ++-- posting.php | 4 +- privmsg.php | 14 +++---- search.php | 16 ++++---- tracker.php | 16 ++++---- viewforum.php | 6 +-- 53 files changed, 197 insertions(+), 197 deletions(-) diff --git a/admin/admin_attach_cp.php b/admin/admin_attach_cp.php index c7efa9a77..622461c39 100644 --- a/admin/admin_attach_cp.php +++ b/admin/admin_attach_cp.php @@ -394,7 +394,7 @@ if ($view === 'attachments') { $attachments = search_attachments($order_by, $total_rows); } - if (sizeof($attachments) > 0) { + if (count($attachments) > 0) { for ($i = 0, $iMax = count($attachments); $i < $iMax; $i++) { $delete_box = ''; diff --git a/admin/admin_attachments.php b/admin/admin_attachments.php index 098e8785d..ef5a9734a 100644 --- a/admin/admin_attachments.php +++ b/admin/admin_attachments.php @@ -288,7 +288,7 @@ if ($mode == 'cats') { $row = DB()->sql_fetchrowset($result); DB()->sql_freeresult($result); - for ($i = 0; $i < sizeof($row); $i++) { + for ($i = 0; $i < count($row); $i++) { if ($row[$i]['cat_id'] == IMAGE_CAT) { $s_assigned_group_images[] = $row[$i]['group_name']; } @@ -399,7 +399,7 @@ if ($submit && $mode == 'quota') { $allowed_list = array(); - for ($i = 0; $i < sizeof($quota_change_list); $i++) { + for ($i = 0; $i < count($quota_change_list); $i++) { $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : (($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i]); $sql = 'UPDATE ' . BB_QUOTA_LIMITS . " @@ -504,7 +504,7 @@ if ($mode == 'quota') { $rows = DB()->sql_fetchrowset($result); DB()->sql_freeresult($result); - for ($i = 0; $i < sizeof($rows); $i++) { + for ($i = 0; $i < count($rows); $i++) { $size_format = ($rows[$i]['quota_limit'] >= 1048576) ? 'mb' : (($rows[$i]['quota_limit'] >= 1024) ? 'kb' : 'b'); if ($rows[$i]['quota_limit'] >= 1048576) { diff --git a/admin/admin_extensions.php b/admin/admin_extensions.php index d754f6890..c3e380093 100644 --- a/admin/admin_extensions.php +++ b/admin/admin_extensions.php @@ -84,7 +84,7 @@ if ($submit && $mode == 'extensions') { // Generate correct Change List $extensions = array(); - for ($i = 0; $i < sizeof($extension_change_list); $i++) { + for ($i = 0; $i < count($extension_change_list); $i++) { $extensions['_' . $extension_change_list[$i]]['comment'] = $extension_explain_list[$i]; $extensions['_' . $extension_change_list[$i]]['group_id'] = intval($group_select_list[$i]); } @@ -99,7 +99,7 @@ if ($submit && $mode == 'extensions') { DB()->sql_freeresult($result); if ($num_rows > 0) { - for ($i = 0; $i < sizeof($extension_row); $i++) { + for ($i = 0; $i < count($extension_row); $i++) { if ($extension_row[$i]['comment'] != $extensions['_' . $extension_row[$i]['ext_id']]['comment'] || intval($extension_row[$i]['group_id']) != intval($extensions['_' . $extension_row[$i]['ext_id']]['group_id'])) { $sql_ary = array( 'comment' => (string)$extensions['_' . $extension_row[$i]['ext_id']]['comment'], @@ -251,15 +251,15 @@ if ($submit && $mode == 'groups') { $allowed_list = array(); - for ($i = 0; $i < sizeof($group_allowed_list); $i++) { - for ($j = 0; $j < sizeof($group_change_list); $j++) { + for ($i = 0; $i < count($group_allowed_list); $i++) { + for ($j = 0; $j < count($group_change_list); $j++) { if ($group_allowed_list[$i] == $group_change_list[$j]) { $allowed_list[$j] = 1; } } } - for ($i = 0; $i < sizeof($group_change_list); $i++) { + for ($i = 0; $i < count($group_change_list); $i++) { $allowed = (isset($allowed_list[$i])) ? 1 : 0; $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : (($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i]); @@ -472,7 +472,7 @@ if (@$add_forum && $e_mode == 'perm' && $group) { $add_forums_list = get_var('entries', array(0)); $add_all_forums = false; - for ($i = 0; $i < sizeof($add_forums_list); $i++) { + for ($i = 0; $i < count($add_forums_list); $i++) { if ($add_forums_list[$i] == 0) { $add_all_forums = true; } @@ -507,7 +507,7 @@ if (@$add_forum && $e_mode == 'perm' && $group) { } // Generate array for Auth_Pack, do not add doubled forums - for ($i = 0; $i < sizeof($add_forums_list); $i++) { + for ($i = 0; $i < count($add_forums_list); $i++) { if (!in_array($add_forums_list[$i], $auth_p)) { $auth_p[] = $add_forums_list[$i]; } @@ -544,13 +544,13 @@ if (@$delete_forum && $e_mode == 'perm' && $group) { $auth_p = array(); // Generate array for Auth_Pack, delete the chosen ones - for ($i = 0; $i < sizeof($auth_p2); $i++) { + for ($i = 0; $i < count($auth_p2); $i++) { if (!in_array($auth_p2[$i], $delete_forums_list)) { $auth_p[] = $auth_p2[$i]; } } - $auth_bitstream = (sizeof($auth_p) > 0) ? auth_pack($auth_p) : ''; + $auth_bitstream = (count($auth_p) > 0) ? auth_pack($auth_p) : ''; $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . attach_mod_sql_escape($auth_bitstream) . "' WHERE group_id = " . (int)$group; @@ -597,7 +597,7 @@ if ($e_mode == 'perm' && $group) { } } - for ($i = 0; $i < sizeof($forum_perm); $i++) { + for ($i = 0; $i < count($forum_perm); $i++) { $template->assign_block_vars('allow_option_values', array( 'VALUE' => $forum_perm[$i]['forum_id'], 'OPTION' => htmlCHR($forum_perm[$i]['forum_name'])) @@ -676,7 +676,7 @@ if ($e_mode == 'perm' && $group) { $message .= ($message == '') ? $forum_name : '
' . $forum_name; } - if (sizeof($empty_perm_forums) > 0) { + if (count($empty_perm_forums) > 0) { $template->assign_vars(array('ERROR_MESSAGE' => $lang['NOTE_ADMIN_EMPTY_GROUP_PERMISSIONS'] . $message)); } } diff --git a/admin/admin_forum_prune.php b/admin/admin_forum_prune.php index bc73c9774..a60ff1914 100644 --- a/admin/admin_forum_prune.php +++ b/admin/admin_forum_prune.php @@ -43,7 +43,7 @@ if (isset($_REQUEST['submit'])) { } $prunetime = TIMENOW - 86400 * $prunedays; - $forum_csv = in_array($all_forums, $f_selected) ? $all_forums : join(',', $f_selected); + $forum_csv = in_array($all_forums, $f_selected) ? $all_forums : implode(',', $f_selected); $where_sql = ($forum_csv != $all_forums) ? "WHERE forum_id IN($forum_csv)" : ''; diff --git a/admin/admin_log.php b/admin/admin_log.php index 980e11381..19b523ca3 100644 --- a/admin/admin_log.php +++ b/admin/admin_log.php @@ -107,7 +107,7 @@ if ($var =& $_REQUEST[$type_key]) { if (in_array($all_types, $type_selected)) { $type_selected = array($all_types); } - $type_csv = join(',', $type_selected); + $type_csv = implode(',', $type_selected); $url = ($type_csv != $def_types) ? url_arg($url, $type_key, $type_csv) : $url; } @@ -121,7 +121,7 @@ if ($var =& $_REQUEST[$user_key]) { if (in_array($all_users, $user_selected)) { $user_selected = array($all_users); } - $user_csv = join(',', $user_selected); + $user_csv = implode(',', $user_selected); $url = ($user_csv != $def_users) ? url_arg($url, $user_key, $user_csv) : $url; } @@ -135,7 +135,7 @@ if ($var =& $_REQUEST[$forum_key]) { if (in_array($all_forums, $forum_selected)) { $forum_selected = array($all_forums); } - $forum_csv = join(',', $forum_selected); + $forum_csv = implode(',', $forum_selected); $url = ($forum_csv != $def_forums) ? url_arg($url, $forum_key, $forum_csv) : $url; } @@ -145,7 +145,7 @@ $topic_csv = ''; if ($var =& $_REQUEST[$topic_key]) { $topic_selected = get_id_ary($var); - $topic_csv = join(',', $topic_selected); + $topic_csv = implode(',', $topic_selected); $url = ($topic_csv) ? url_arg($url, $topic_key, $topic_csv) : $url; } diff --git a/admin/admin_mass_email.php b/admin/admin_mass_email.php index 5e4225127..7ac3dde06 100644 --- a/admin/admin_mass_email.php +++ b/admin/admin_mass_email.php @@ -55,7 +55,7 @@ if (isset($_POST['submit'])) { foreach ($sql as $row) { $user_id_sql[] = ',' . $row['ban_userid']; } - $user_id_sql = join('', $user_id_sql); + $user_id_sql = implode('', $user_id_sql); if ($group_id != -1) { $user_list = DB()->fetch_rowset(" @@ -114,7 +114,7 @@ $template->assign_vars(array( 'MESSAGE' => $message, 'SUBJECT' => $subject, - 'ERROR_MESSAGE' => ($errors) ? join('
', array_unique($errors)) : '', + 'ERROR_MESSAGE' => ($errors) ? implode('
', array_unique($errors)) : '', 'S_USER_ACTION' => 'admin_mass_email.php', 'S_GROUP_SELECT' => build_select(POST_GROUPS_URL, $groups), diff --git a/admin/index.php b/admin/index.php index 598e3c9fe..5cce9d73c 100644 --- a/admin/index.php +++ b/admin/index.php @@ -263,7 +263,7 @@ print_page('index.tpl', 'admin'); // Functions function inarray($needle, $haystack) { - for ($i = 0; $i < sizeof($haystack); $i++) { + for ($i = 0; $i < count($haystack); $i++) { if ($haystack[$i] == $needle) { return true; } diff --git a/admin/stats/tracker.php b/admin/stats/tracker.php index 2e892f4dc..cd7a6eb4a 100644 --- a/admin/stats/tracker.php +++ b/admin/stats/tracker.php @@ -131,11 +131,11 @@ echo "\n \n"; -echo "\n peers: in last " . join(' / ', $peers_in_last_minutes) . " min\n"; -echo "\n" . join(' / ', $peers_in_last_min) . "\n"; +echo "\n peers: in last " . implode(' / ', $peers_in_last_minutes) . " min\n"; +echo "\n" . implode(' / ', $peers_in_last_min) . "\n"; echo "\n peers in last $peers_in_last_sec_limit sec
[ per second, DESC order --> ]
last peer: $stat[last_peer_time] seconds ago
" . date("j M H:i:s [T O]") . " \n"; -echo '
 ' . join(' ', $peers_in_last_sec) . "
\n"; +echo '
 ' . implode(' ', $peers_in_last_sec) . "
\n"; echo ''; diff --git a/bt/includes/init_tr.php b/bt/includes/init_tr.php index c177255d0..a73ff89c7 100644 --- a/bt/includes/init_tr.php +++ b/bt/includes/init_tr.php @@ -53,7 +53,7 @@ function tracker_exit() $str[] = sprintf('%.4f' . LOG_SEPR . '%02d%%', $DBS->sql_timetotal, $sql_total_perc); $str[] = $DBS->num_queries; $str[] = sprintf('%.1f', sys('la')); - $str = join(LOG_SEPR, $str) . LOG_LF; + $str = implode(LOG_SEPR, $str) . LOG_LF; dbg_log($str, '!!gentime'); } } diff --git a/callseed.php b/callseed.php index fc8976768..d71714316 100644 --- a/callseed.php +++ b/callseed.php @@ -51,7 +51,7 @@ $sql = DB()->fetch_rowset("SELECT ban_userid FROM " . BB_BANLIST . " WHERE ban_u foreach ($sql as $row) { $ban_user_id[] = ',' . $row['ban_userid']; } -$ban_user_id = join('', $ban_user_id); +$ban_user_id = implode('', $ban_user_id); $user_list = DB()->fetch_rowset(" SELECT DISTINCT dl.user_id, u.user_opt, tr.user_id as active_dl diff --git a/common.php b/common.php index 79a13a9c9..54eaf5c6e 100644 --- a/common.php +++ b/common.php @@ -213,7 +213,7 @@ function utime() function bb_log($msg, $file_name) { if (is_array($msg)) { - $msg = join(LOG_LF, $msg); + $msg = implode(LOG_LF, $msg); } $file_name .= (LOG_EXT) ? '.' . LOG_EXT : ''; return file_write($msg, LOG_DIR . '/' . $file_name); @@ -411,7 +411,7 @@ function sys($param) { switch ($param) { case 'la': - return function_exists('sys_getloadavg') ? join(' ', sys_getloadavg()) : 0; + return function_exists('sys_getloadavg') ? implode(' ', sys_getloadavg()) : 0; break; case 'mem': return function_exists('memory_get_usage') ? memory_get_usage() : 0; @@ -473,7 +473,7 @@ function log_request($file = '', $prepend_str = false, $add_post = true) if (!empty($_POST) && $add_post) { $str[] = "post: " . str_compact(urldecode(http_build_query($_POST))); } - $str = join("\t", $str) . "\n"; + $str = implode("\t", $str) . "\n"; bb_log($str, $file); } diff --git a/dl_list.php b/dl_list.php index f9828ed77..8378029e5 100644 --- a/dl_list.php +++ b/dl_list.php @@ -128,7 +128,7 @@ if ($mode == 'set_topics_dl_status') { } // Get existing topics -if ($req_topics_sql = join(',', $req_topics_ary)) { +if ($req_topics_sql = implode(',', $req_topics_ary)) { $sql = "SELECT topic_id FROM " . BB_TOPICS . " WHERE topic_id IN($req_topics_sql)"; foreach (DB()->fetch_rowset($sql) as $row) { diff --git a/group.php b/group.php index 8a5961198..493c98684 100644 --- a/group.php +++ b/group.php @@ -281,7 +281,7 @@ if (!$group_id) { foreach ($members as $members_id) { $sql_in[] = (int)$members_id; } - if (!$sql_in = join(',', $sql_in)) { + if (!$sql_in = implode(',', $sql_in)) { bb_die($lang['NONE_SELECTED']); } diff --git a/index.php b/index.php index 805d2681b..ed60a32bf 100644 --- a/index.php +++ b/index.php @@ -255,7 +255,7 @@ foreach ($cat_forums as $cid => $c) { 'POSTS' => commify($f['forum_posts']), 'TOPICS' => commify($f['forum_topics']), 'LAST_SF_ID' => isset($f['last_sf_id']) ? $f['last_sf_id'] : null, - 'MODERATORS' => isset($moderators[$fid]) ? join(', ', $moderators[$fid]) : '', + 'MODERATORS' => isset($moderators[$fid]) ? implode(', ', $moderators[$fid]) : '', 'FORUM_FOLDER_ALT' => ($new) ? $lang['NEW'] : $lang['OLD'], )); @@ -365,7 +365,7 @@ if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) { $week_list[] = profile_url($week) . ' (' . birthday_age($week['user_birthday'] - 1) . ')'; } $week_all = ($week_all) ? ' ...' : ''; - $week_list = sprintf($lang['BIRTHDAY_WEEK'], $bb_cfg['birthday_check_day'], join(', ', $week_list)) . $week_all; + $week_list = sprintf($lang['BIRTHDAY_WEEK'], $bb_cfg['birthday_check_day'], implode(', ', $week_list)) . $week_all; } else { $week_list = sprintf($lang['NOBIRTHDAY_WEEK'], $bb_cfg['birthday_check_day']); } @@ -380,7 +380,7 @@ if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) { $today_list[] = profile_url($today) . ' (' . birthday_age($today['user_birthday']) . ')'; } $today_all = ($today_all) ? ' ...' : ''; - $today_list = $lang['BIRTHDAY_TODAY'] . join(', ', $today_list) . $today_all; + $today_list = $lang['BIRTHDAY_TODAY'] . implode(', ', $today_list) . $today_all; } else { $today_list = $lang['NOBIRTHDAY_TODAY']; } diff --git a/install/upgrade/r583-convert_avatars.php b/install/upgrade/r583-convert_avatars.php index c7b028607..60b938a42 100644 --- a/install/upgrade/r583-convert_avatars.php +++ b/install/upgrade/r583-convert_avatars.php @@ -80,7 +80,7 @@ if ($confirm) { DB()->query("UPDATE " . BB_USERS . " SET avatar_ext_id = {$upload->file_ext_id} WHERE user_id = {$row['user_id']} LIMIT 1"); $avatars_ok++; } else { - echo "{$row['user_id']}: ", join("\n{$row['user_id']}: ", $upload->errors), "\n"; + echo "{$row['user_id']}: ", implode("\n{$row['user_id']}: ", $upload->errors), "\n"; $avatars_err++; } } diff --git a/library/ajax/group_membership.php b/library/ajax/group_membership.php index ed4551dc3..5c99a2534 100644 --- a/library/ajax/group_membership.php +++ b/library/ajax/group_membership.php @@ -71,7 +71,7 @@ switch ($mode) { } } if ($html) { - $this->response['group_list_html'] = '
  • ' . join('
  • ', $html) . '
'; + $this->response['group_list_html'] = '
  • ' . implode('
  • ', $html) . '
'; } else { $this->response['group_list_html'] = $lang['GROUP_LIST_HIDDEN']; } diff --git a/library/ajax/index_data.php b/library/ajax/index_data.php index 872cac13f..52f76bf25 100644 --- a/library/ajax/index_data.php +++ b/library/ajax/index_data.php @@ -43,7 +43,7 @@ switch ($mode) { foreach ($stats['birthday_week_list'] as $week) { $html[] = profile_url($week) . ' (' . birthday_age($week['user_birthday']) . ')'; } - $html = sprintf($lang['BIRTHDAY_WEEK'], $bb_cfg['birthday_check_day'], join(', ', $html)); + $html = sprintf($lang['BIRTHDAY_WEEK'], $bb_cfg['birthday_check_day'], implode(', ', $html)); } else { $html = sprintf($lang['NOBIRTHDAY_WEEK'], $bb_cfg['birthday_check_day']); } @@ -59,7 +59,7 @@ switch ($mode) { foreach ($stats['birthday_today_list'] as $today) { $html[] = profile_url($today) . ' (' . birthday_age($today['user_birthday']) . ')'; } - $html = $lang['BIRTHDAY_TODAY'] . join(', ', $html); + $html = $lang['BIRTHDAY_TODAY'] . implode(', ', $html); } else { $html = $lang['NOBIRTHDAY_TODAY']; } @@ -88,7 +88,7 @@ switch ($mode) { } $html = ': '; - $html .= ($moderators) ? join(', ', $moderators) : $lang['NONE']; + $html .= ($moderators) ? implode(', ', $moderators) : $lang['NONE']; unset($moderators, $mod); $datastore->rm('moderators'); break; diff --git a/library/attach_mod/displaying.php b/library/attach_mod/displaying.php index 943b5e1e4..bb8f26f00 100644 --- a/library/attach_mod/displaying.php +++ b/library/attach_mod/displaying.php @@ -46,7 +46,7 @@ function init_complete_extensions_data() } $allowed_extensions = array(); - for ($i = 0, $size = sizeof($extension_informations); $i < $size; $i++) { + for ($i = 0, $size = count($extension_informations); $i < $size; $i++) { $extension = strtolower(trim($extension_informations[$i]['extension'])); $allowed_extensions[] = $extension; $display_categories[$extension] = intval($extension_informations[$i]['cat_id']); @@ -140,12 +140,12 @@ function init_display_post_attachments($switch_attachment) } } - if (sizeof($post_id_array) == 0) { + if (count($post_id_array) == 0) { return; } $rows = get_attachments_from_post($post_id_array); - $num_rows = sizeof($rows); + $num_rows = count($rows); if ($num_rows == 0) { return; @@ -183,7 +183,7 @@ function display_attachments($post_id) { global $template, $upload_dir, $userdata, $allowed_extensions, $display_categories, $download_modes, $lang, $attachments, $upload_icons, $attach_config; - $num_attachments = @sizeof($attachments['_' . $post_id]); + $num_attachments = @count($attachments['_' . $post_id]); if ($num_attachments == 0) { return; diff --git a/library/attach_mod/includes/functions_admin.php b/library/attach_mod/includes/functions_admin.php index 51280986f..fd142fc46 100644 --- a/library/attach_mod/includes/functions_admin.php +++ b/library/attach_mod/includes/functions_admin.php @@ -106,7 +106,7 @@ function process_quota_settings($mode, $id, $quota_type, $quota_limit_id = 0) */ function sort_multi_array($sort_array, $key, $sort_order, $pre_string_sort = 0) { - $last_element = sizeof($sort_array) - 1; + $last_element = count($sort_array) - 1; if (!$pre_string_sort) { $string_sort = (!is_numeric(@$sort_array[$last_element - 1][$key])) ? true : false; @@ -266,7 +266,7 @@ function search_attachments($order_by, &$total_rows) $sql = 'SELECT a.*, t.post_id, p.post_time, p.topic_id FROM ' . BB_ATTACHMENTS . ' t, ' . BB_ATTACHMENTS_DESC . ' a, ' . BB_POSTS . ' p WHERE '; - if (sizeof($where_sql) > 0) { + if (count($where_sql) > 0) { $sql .= implode('AND', $where_sql) . ' AND '; } @@ -309,7 +309,7 @@ function search_attachments($order_by, &$total_rows) function limit_array($array, $start, $pagelimit) { // array from start - start+pagelimit - $limit = (sizeof($array) < ($start + $pagelimit)) ? sizeof($array) : $start + $pagelimit; + $limit = (count($array) < ($start + $pagelimit)) ? count($array) : $start + $pagelimit; $limit_array = []; diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index fac3e87eb..e09944163 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -101,7 +101,7 @@ function auth_pack($auth_array) $one_char = $two_char = false; $auth_cache = ''; - for ($i = 0; $i < sizeof($auth_array); $i++) { + for ($i = 0; $i < count($auth_array); $i++) { $val = base64_pack(intval($auth_array[$i])); if (strlen($val) == 1 && !$one_char) { $auth_cache .= $one_char_encoding; @@ -310,7 +310,7 @@ function get_attachments_from_post($post_id_array) */ function get_total_attach_filesize($attach_ids) { - if (!is_array($attach_ids) || !sizeof($attach_ids)) { + if (!is_array($attach_ids) || !count($attach_ids)) { return 0; } @@ -350,7 +350,7 @@ function get_extension_informations() function attachment_sync_topic($topics) { if (is_array($topics)) { - $topics = join(',', $topics); + $topics = implode(',', $topics); } $posts_without_attach = $topics_without_attach = array(); @@ -366,7 +366,7 @@ function attachment_sync_topic($topics) foreach ($rowset as $row) { $posts_without_attach[] = $row['post_id']; } - if ($posts_sql = join(',', $posts_without_attach)) { + if ($posts_sql = implode(',', $posts_without_attach)) { DB()->query("UPDATE " . BB_POSTS . " SET post_attachment = 0 WHERE post_id IN($posts_sql)"); } } @@ -393,7 +393,7 @@ function attachment_sync_topic($topics) foreach ($rowset as $row) { $topics_without_attach[] = $row['topic_id']; } - if ($topics_sql = join(',', $topics_without_attach)) { + if ($topics_sql = implode(',', $topics_without_attach)) { DB()->query("UPDATE " . BB_TOPICS . " SET topic_attachment = 0 WHERE topic_id IN($topics_sql)"); } } diff --git a/library/attach_mod/includes/functions_delete.php b/library/attach_mod/includes/functions_delete.php index 228db7451..cee349b4e 100644 --- a/library/attach_mod/includes/functions_delete.php +++ b/library/attach_mod/includes/functions_delete.php @@ -94,7 +94,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } } - if (!sizeof($post_id_array)) { + if (!count($post_id_array)) { return; } @@ -139,13 +139,13 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } } - if (!sizeof($attach_id_array)) { + if (!count($attach_id_array)) { return; } $sql_id = 'post_id'; - if (sizeof($post_id_array) && sizeof($attach_id_array)) { + if (count($post_id_array) && count($attach_id_array)) { $sql = 'DELETE FROM ' . BB_ATTACHMENTS . ' WHERE attach_id IN (' . implode(', ', $attach_id_array) . ") AND $sql_id IN (" . implode(', ', $post_id_array) . ')'; @@ -187,7 +187,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } //bt end - for ($i = 0; $i < sizeof($attach_id_array); $i++) { + for ($i = 0; $i < count($attach_id_array); $i++) { $sql = 'SELECT attach_id FROM ' . BB_ATTACHMENTS . ' WHERE attach_id = ' . (int)$attach_id_array[$i]; @@ -236,7 +236,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } // Now Sync the Topic/PM - if (sizeof($post_id_array)) { + if (count($post_id_array)) { $sql = 'SELECT topic_id FROM ' . BB_POSTS . ' WHERE post_id IN (' . implode(', ', $post_id_array) . ') diff --git a/library/attach_mod/includes/functions_selects.php b/library/attach_mod/includes/functions_selects.php index 1a771aa8a..286448ab9 100644 --- a/library/attach_mod/includes/functions_selects.php +++ b/library/attach_mod/includes/functions_selects.php @@ -50,7 +50,7 @@ function group_select($select_name, $default_group = 0) $group_name[$num_rows]['group_id'] = 0; $group_name[$num_rows]['group_name'] = $lang['NOT_ASSIGNED']; - for ($i = 0; $i < sizeof($group_name); $i++) { + for ($i = 0; $i < count($group_name); $i++) { if (!$default_group) { $selected = ($i == 0) ? ' selected="selected"' : ''; } else { @@ -93,7 +93,7 @@ function download_select($select_name, $group_id = 0) $group_select = ''; - for ($i = 0; $i < sizeof($types); $i++) { + for ($i = 0; $i < count($types); $i++) { if (!$group_id) { $selected = ($types[$i] == NONE_CAT) ? ' selected="selected"' : ''; } else { @@ -172,7 +172,7 @@ function size_select($select_name, $size_compare) $select_field = ''; + $s_hidden = ''; $template->assign_block_vars('switch_user_based', array()); @@ -354,7 +354,7 @@ if ($view === 'attachments') { $sql = "SELECT attach_id FROM " . BB_ATTACHMENTS . " - WHERE user_id_1 = " . intval($uid) . " + WHERE user_id_1 = " . (int)$uid . " GROUP BY attach_id"; if (!($result = DB()->sql_query($sql))) { @@ -374,7 +374,7 @@ if ($view === 'attachments') { $attach_id = array(); for ($j = 0; $j < $num_attach_ids; $j++) { - $attach_id[] = intval($attach_ids[$j]['attach_id']); + $attach_id[] = (int)$attach_ids[$j]['attach_id']; } $sql = "SELECT a.* @@ -396,11 +396,11 @@ if ($view === 'attachments') { if (count($attachments) > 0) { for ($i = 0, $iMax = count($attachments); $i < $iMax; $i++) { - $delete_box = ''; + $delete_box = ''; for ($j = 0, $iMax = count($delete_id_list); $j < $iMax; $j++) { if ($delete_id_list[$j] == $attachments[$i]['attach_id']) { - $delete_box = ''; + $delete_box = ''; break; } } @@ -413,7 +413,7 @@ if ($view === 'attachments') { $sql = "SELECT * FROM " . BB_ATTACHMENTS . " - WHERE attach_id = " . intval($attachments[$i]['attach_id']); + WHERE attach_id = " . (int)$attachments[$i]['attach_id']; if (!($result = DB()->sql_query($sql))) { bb_die('Could not query attachments #3'); @@ -427,7 +427,7 @@ if ($view === 'attachments') { if ($ids[$j]['post_id'] != 0) { $sql = "SELECT t.topic_title FROM " . BB_TOPICS . " t, " . BB_POSTS . " p - WHERE p.post_id = " . intval($ids[$j]['post_id']) . " AND p.topic_id = t.topic_id + WHERE p.post_id = " . (int)$ids[$j]['post_id'] . " AND p.topic_id = t.topic_id GROUP BY t.topic_id, t.topic_title"; if (!($result = DB()->sql_query($sql))) { @@ -452,7 +452,7 @@ if ($view === 'attachments') { $post_titles = implode('
', $post_titles); - $hidden_field = ''; + $hidden_field = ''; $template->assign_block_vars('attachrow', array( 'ROW_NUMBER' => $i + (@$_GET['start'] + 1), diff --git a/admin/admin_attachments.php b/admin/admin_attachments.php index ef5a9734a..fc77f7ab6 100644 --- a/admin/admin_attachments.php +++ b/admin/admin_attachments.php @@ -248,8 +248,8 @@ if ($mode == 'manage') { 'S_FILESIZE' => $select_size_mode, 'S_FILESIZE_QUOTA' => $select_quota_size_mode, 'S_FILESIZE_PM' => $select_pm_size_mode, - 'S_DEFAULT_UPLOAD_LIMIT' => default_quota_limit_select('default_upload_quota', intval(trim($new_attach['default_upload_quota']))), - 'S_DEFAULT_PM_LIMIT' => default_quota_limit_select('default_pm_quota', intval(trim($new_attach['default_pm_quota']))), + 'S_DEFAULT_UPLOAD_LIMIT' => default_quota_limit_select('default_upload_quota', (int)trim($new_attach['default_upload_quota'])), + 'S_DEFAULT_PM_LIMIT' => default_quota_limit_select('default_pm_quota', (int)trim($new_attach['default_pm_quota'])), 'UPLOAD_DIR' => $new_attach['upload_dir'], 'ATTACHMENT_IMG_PATH' => $new_attach['upload_img'], diff --git a/admin/admin_disallow.php b/admin/admin_disallow.php index ad86b28fd..36695ec6c 100644 --- a/admin/admin_disallow.php +++ b/admin/admin_disallow.php @@ -54,7 +54,7 @@ if (isset($_POST['add_name'])) { bb_die($message); } elseif (isset($_POST['delete_name'])) { - $disallowed_id = (isset($_POST['disallowed_id'])) ? intval($_POST['disallowed_id']) : intval($_GET['disallowed_id']); + $disallowed_id = (isset($_POST['disallowed_id'])) ? (int)$_POST['disallowed_id'] : (int)$_GET['disallowed_id']; $sql = "DELETE FROM " . BB_DISALLOW . " WHERE disallow_id = $disallowed_id"; $result = DB()->sql_query($sql); diff --git a/admin/admin_extensions.php b/admin/admin_extensions.php index c3e380093..1cfe16076 100644 --- a/admin/admin_extensions.php +++ b/admin/admin_extensions.php @@ -86,7 +86,7 @@ if ($submit && $mode == 'extensions') { for ($i = 0; $i < count($extension_change_list); $i++) { $extensions['_' . $extension_change_list[$i]]['comment'] = $extension_explain_list[$i]; - $extensions['_' . $extension_change_list[$i]]['group_id'] = intval($group_select_list[$i]); + $extensions['_' . $extension_change_list[$i]]['group_id'] = (int)$group_select_list[$i]; } $sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY ext_id'; @@ -100,7 +100,7 @@ if ($submit && $mode == 'extensions') { if ($num_rows > 0) { for ($i = 0; $i < count($extension_row); $i++) { - if ($extension_row[$i]['comment'] != $extensions['_' . $extension_row[$i]['ext_id']]['comment'] || intval($extension_row[$i]['group_id']) != intval($extensions['_' . $extension_row[$i]['ext_id']]['group_id'])) { + if ($extension_row[$i]['comment'] != $extensions['_' . $extension_row[$i]['ext_id']]['comment'] || (int)$extension_row[$i]['group_id'] != (int)$extensions['_' . $extension_row[$i]['ext_id']]['group_id']) { $sql_ary = array( 'comment' => (string)$extensions['_' . $extension_row[$i]['ext_id']]['comment'], 'group_id' => (int)$extensions['_' . $extension_row[$i]['ext_id']]['group_id'] @@ -490,7 +490,7 @@ if (@$add_forum && $e_mode == 'perm' && $group) { if (!$add_all_forums) { $sql = 'SELECT forum_permissions FROM ' . BB_EXTENSION_GROUPS . ' - WHERE group_id = ' . intval($group) . ' + WHERE group_id = ' . (int)$group . ' LIMIT 1'; if (!($result = DB()->sql_query($sql))) { @@ -530,7 +530,7 @@ if (@$delete_forum && $e_mode == 'perm' && $group) { // Get the current Forums $sql = 'SELECT forum_permissions FROM ' . BB_EXTENSION_GROUPS . ' - WHERE group_id = ' . intval($group) . ' + WHERE group_id = ' . (int)$group . ' LIMIT 1'; if (!($result = DB()->sql_query($sql))) { @@ -563,7 +563,7 @@ if (@$delete_forum && $e_mode == 'perm' && $group) { if ($e_mode == 'perm' && $group) { $sql = 'SELECT group_name, forum_permissions FROM ' . BB_EXTENSION_GROUPS . ' - WHERE group_id = ' . intval($group) . ' + WHERE group_id = ' . (int)$group . ' LIMIT 1'; if (!($result = DB()->sql_query($sql))) { @@ -619,7 +619,7 @@ if ($e_mode == 'perm' && $group) { } while ($row = DB()->sql_fetchrow($result)) { - $forum_option_values[intval($row['forum_id'])] = $row['forum_name']; + $forum_option_values[(int)$row['forum_id']] = $row['forum_name']; } DB()->sql_freeresult($result); diff --git a/admin/admin_forum_prune.php b/admin/admin_forum_prune.php index a60ff1914..a96874b38 100644 --- a/admin/admin_forum_prune.php +++ b/admin/admin_forum_prune.php @@ -38,7 +38,7 @@ if (isset($_REQUEST['submit'])) { if (!$var =& $_REQUEST['f'] or !$f_selected = get_id_ary($var)) { bb_die('Forum not selected'); } - if (!$var =& $_REQUEST['prunedays'] or !$prunedays = abs(intval($var))) { + if (!$var =& $_REQUEST['prunedays'] or !$prunedays = abs((int)$var)) { bb_die($lang['NOT_DAYS']); } diff --git a/admin/admin_forumauth.php b/admin/admin_forumauth.php index cb365e203..36ab405f1 100644 --- a/admin/admin_forumauth.php +++ b/admin/admin_forumauth.php @@ -90,7 +90,7 @@ if (@$_REQUEST[POST_FORUM_URL]) { } if (isset($_GET['adv'])) { - $adv = intval($_GET['adv']); + $adv = (int)$_GET['adv']; } else { unset($adv); } @@ -103,7 +103,7 @@ if (isset($_POST['submit'])) { if (!empty($forum_id)) { if (isset($_POST['simpleauth'])) { - $simple_ary = $simple_auth_ary[intval($_POST['simpleauth'])]; + $simple_ary = $simple_auth_ary[(int)$_POST['simpleauth']]; for ($i = 0; $i < count($simple_ary); $i++) { $sql .= (($sql != '') ? ', ' : '') . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i]; @@ -114,7 +114,7 @@ if (isset($_POST['submit'])) { } } else { for ($i = 0; $i < count($forum_auth_fields); $i++) { - $value = intval($_POST[$forum_auth_fields[$i]]); + $value = (int)$_POST[$forum_auth_fields[$i]]; if ($forum_auth_fields[$i] == 'auth_vote') { if ($_POST['auth_vote'] == AUTH_ALL) { diff --git a/admin/admin_forumauth_list.php b/admin/admin_forumauth_list.php index df3e268fe..4a6e270f9 100644 --- a/admin/admin_forumauth_list.php +++ b/admin/admin_forumauth_list.php @@ -82,7 +82,7 @@ $forum_auth_levels = array('ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN'); $forum_auth_const = array(AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN); if (isset($_GET[POST_FORUM_URL]) || isset($_POST[POST_FORUM_URL])) { - $forum_id = (isset($_POST[POST_FORUM_URL])) ? intval($_POST[POST_FORUM_URL]) : intval($_GET[POST_FORUM_URL]); + $forum_id = (isset($_POST[POST_FORUM_URL])) ? (int)$_POST[POST_FORUM_URL] : (int)$_GET[POST_FORUM_URL]; $forum_sql = "AND forum_id = $forum_id"; } else { unset($forum_id); @@ -90,7 +90,7 @@ if (isset($_GET[POST_FORUM_URL]) || isset($_POST[POST_FORUM_URL])) { } if (isset($_GET[POST_CAT_URL]) || isset($_POST[POST_CAT_URL])) { - $cat_id = (isset($_POST[POST_CAT_URL])) ? intval($_POST[POST_CAT_URL]) : intval($_GET[POST_CAT_URL]); + $cat_id = (isset($_POST[POST_CAT_URL])) ? (int)$_POST[POST_CAT_URL] : (int)$_GET[POST_CAT_URL]; $cat_sql = "AND c.cat_id = $cat_id"; } else { unset($cat_id); @@ -98,7 +98,7 @@ if (isset($_GET[POST_CAT_URL]) || isset($_POST[POST_CAT_URL])) { } if (isset($_GET['adv'])) { - $adv = intval($_GET['adv']); + $adv = (int)$_GET['adv']; } else { unset($adv); } @@ -111,7 +111,7 @@ if (isset($_POST['submit'])) { if (!empty($forum_id)) { if (isset($_POST['simpleauth'])) { - $simple_ary = $simple_auth_ary[intval($_POST['simpleauth'])]; + $simple_ary = $simple_auth_ary[(int)$_POST['simpleauth']]; for ($i = 0; $i < count($simple_ary); $i++) { $sql .= (($sql != '') ? ', ' : '') . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i]; @@ -122,7 +122,7 @@ if (isset($_POST['submit'])) { } } else { for ($i = 0; $i < count($forum_auth_fields); $i++) { - $value = intval($_POST[$forum_auth_fields[$i]]); + $value = (int)$_POST[$forum_auth_fields[$i]]; if ($forum_auth_fields[$i] == 'auth_vote') { if ($_POST['auth_vote'] == AUTH_ALL) { @@ -146,7 +146,7 @@ if (isset($_POST['submit'])) { $adv = 0; } elseif (!empty($cat_id)) { for ($i = 0; $i < count($forum_auth_fields); $i++) { - $value = intval($_POST[$forum_auth_fields[$i]]); + $value = (int)$_POST[$forum_auth_fields[$i]]; if ($forum_auth_fields[$i] == 'auth_vote') { if ($_POST['auth_vote'] == AUTH_ALL) { diff --git a/admin/admin_forums.php b/admin/admin_forums.php index 312777813..eb452c8e3 100644 --- a/admin/admin_forums.php +++ b/admin/admin_forums.php @@ -85,7 +85,7 @@ if ($mode) { $newmode = 'modforum'; $buttonvalue = $lang['UPDATE']; - $forum_id = intval($_GET[POST_FORUM_URL]); + $forum_id = (int)$_GET[POST_FORUM_URL]; $row = get_info('forum', $forum_id); @@ -121,7 +121,7 @@ if ($mode) { } if (isset($_REQUEST['forum_parent'])) { - $forum_parent = intval($_REQUEST['forum_parent']); + $forum_parent = (int)$_REQUEST['forum_parent']; if ($parent = get_forum_data($forum_parent)) { $cat_id = $parent['cat_id']; @@ -179,18 +179,18 @@ if ($mode) { // // Create a forum in the DB // - $cat_id = intval($_POST[POST_CAT_URL]); + $cat_id = (int)$_POST[POST_CAT_URL]; $forum_name = (string)$_POST['forumname']; $forum_desc = (string)$_POST['forumdesc']; - $forum_status = intval($_POST['forumstatus']); + $forum_status = (int)$_POST['forumstatus']; - $prune_days = intval($_POST['prune_days']); + $prune_days = (int)$_POST['prune_days']; - $forum_parent = ($_POST['forum_parent'] != -1) ? intval($_POST['forum_parent']) : 0; - $show_on_index = ($forum_parent) ? intval($_POST['show_on_index']) : 1; + $forum_parent = ($_POST['forum_parent'] != -1) ? (int)$_POST['forum_parent'] : 0; + $show_on_index = ($forum_parent) ? (int)$_POST['show_on_index'] : 1; - $forum_display_sort = intval($_POST['forum_display_sort']); - $forum_display_order = intval($_POST['forum_display_order']); + $forum_display_sort = (int)$_POST['forum_display_sort']; + $forum_display_order = (int)$_POST['forum_display_order']; $forum_tpl_id = (int)$_POST['forum_tpl_select']; $allow_reg_tracker = (int)$_POST['allow_reg_tracker']; @@ -242,18 +242,18 @@ if ($mode) { // // Modify a forum in the DB // - $cat_id = intval($_POST[POST_CAT_URL]); - $forum_id = intval($_POST[POST_FORUM_URL]); + $cat_id = (int)$_POST[POST_CAT_URL]; + $forum_id = (int)$_POST[POST_FORUM_URL]; $forum_name = (string)$_POST['forumname']; $forum_desc = (string)$_POST['forumdesc']; - $forum_status = intval($_POST['forumstatus']); - $prune_days = intval($_POST['prune_days']); + $forum_status = (int)$_POST['forumstatus']; + $prune_days = (int)$_POST['prune_days']; - $forum_parent = ($_POST['forum_parent'] != -1) ? intval($_POST['forum_parent']) : 0; - $show_on_index = ($forum_parent) ? intval($_POST['show_on_index']) : 1; + $forum_parent = ($_POST['forum_parent'] != -1) ? (int)$_POST['forum_parent'] : 0; + $show_on_index = ($forum_parent) ? (int)$_POST['show_on_index'] : 1; - $forum_display_order = intval($_POST['forum_display_order']); - $forum_display_sort = intval($_POST['forum_display_sort']); + $forum_display_order = (int)$_POST['forum_display_order']; + $forum_display_sort = (int)$_POST['forum_display_sort']; $forum_tpl_id = (int)$_POST['forum_tpl_select']; $allow_reg_tracker = (int)$_POST['allow_reg_tracker']; $allow_porno_topic = (int)$_POST['allow_porno_topic']; @@ -565,8 +565,8 @@ if ($mode) { case 'forum_order': // Change order of forums - $move = intval($_GET['move']); - $forum_id = intval($_GET[POST_FORUM_URL]); + $move = (int)$_GET['move']; + $forum_id = (int)$_GET[POST_FORUM_URL]; $forum_info = get_info('forum', $forum_id); renumber_order('forum', $forum_info['cat_id']); @@ -652,7 +652,7 @@ if ($mode) { break; case 'forum_sync': - sync('forum', intval($_GET['f'])); + sync('forum', (int)$_GET['f']); $datastore->update('cat_forums'); CACHE('bb_cache')->rm(); @@ -910,7 +910,7 @@ function get_cat_forums($cat_id = false) $forums = array(); $where_sql = ''; - if ($cat_id = intval($cat_id)) { + if ($cat_id = (int)$cat_id) { $where_sql = "AND f.cat_id = $cat_id"; } @@ -1082,7 +1082,7 @@ function get_max_forum_order($cat_id) WHERE cat_id = $cat_id "); - return intval($row['max_forum_order']); + return (int)$row['max_forum_order']; } function check_name_dup($mode, $name, $die_on_error = true) diff --git a/admin/admin_groups.php b/admin/admin_groups.php index b671bfa87..b6610dbf1 100644 --- a/admin/admin_groups.php +++ b/admin/admin_groups.php @@ -30,8 +30,8 @@ if (!empty($setmodules)) { require __DIR__ . '/pagestart.php'; require INC_DIR . '/functions_group.php'; -$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL]) : 0; -$mode = isset($_REQUEST['mode']) ? strval($_REQUEST['mode']) : ''; +$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? (int)$_REQUEST[POST_GROUPS_URL] : 0; +$mode = isset($_REQUEST['mode']) ? (string)$_REQUEST['mode'] : ''; attachment_quota_settings('group', isset($_POST['group_update']), $mode); @@ -100,8 +100,8 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) { bb_die($message); } else { - $group_type = isset($_POST['group_type']) ? intval($_POST['group_type']) : GROUP_OPEN; - $release_group = isset($_POST['release_group']) ? intval($_POST['release_group']) : 0; + $group_type = isset($_POST['group_type']) ? (int)$_POST['group_type'] : GROUP_OPEN; + $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'] : ''; diff --git a/admin/admin_log.php b/admin/admin_log.php index 19b523ca3..db6a6f4a6 100644 --- a/admin/admin_log.php +++ b/admin/admin_log.php @@ -95,7 +95,7 @@ $f_data = $forums['f']; unset($forums); // Start -$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; +$start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0; // Type $type_selected = array($def_types); @@ -165,7 +165,7 @@ $datetime_val = $def_datetime; $daysback_val = $def_days; if ($var =& $_REQUEST[$daysback_key] && $var != $def_days) { - $daysback_val = max(intval($var), 1); + $daysback_val = max((int)$var, 1); $url = url_arg($url, $daysback_key, $daysback_val); } if ($var =& $_REQUEST[$datetime_key] && $var != $def_datetime) { diff --git a/admin/admin_ranks.php b/admin/admin_ranks.php index 9a2ceab7c..7b7b28e19 100644 --- a/admin/admin_ranks.php +++ b/admin/admin_ranks.php @@ -53,7 +53,7 @@ if ($mode != '') { // // They want to add a new rank, show the form. // - $rank_id = (isset($_GET['id'])) ? intval($_GET['id']) : 0; + $rank_id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0; $s_hidden_fields = ''; @@ -97,11 +97,11 @@ if ($mode != '') { // Ok, they sent us our info, let's update it. // - $rank_id = (isset($_POST['id'])) ? intval($_POST['id']) : 0; + $rank_id = (isset($_POST['id'])) ? (int)$_POST['id'] : 0; $rank_title = (isset($_POST['title'])) ? trim($_POST['title']) : ''; $rank_style = (isset($_POST['style'])) ? trim($_POST['style']) : ''; $special_rank = ($_POST['special_rank'] == 1) ? true : 0; - $min_posts = (isset($_POST['min_posts'])) ? intval($_POST['min_posts']) : -1; + $min_posts = (isset($_POST['min_posts'])) ? (int)$_POST['min_posts'] : -1; $rank_image = ((isset($_POST['rank_image']))) ? trim($_POST['rank_image']) : ''; if ($rank_title == '') { @@ -160,7 +160,7 @@ if ($mode != '') { // if (isset($_POST['id']) || isset($_GET['id'])) { - $rank_id = (isset($_POST['id'])) ? intval($_POST['id']) : intval($_GET['id']); + $rank_id = (isset($_POST['id'])) ? (int)$_POST['id'] : (int)$_GET['id']; } else { $rank_id = 0; } diff --git a/admin/admin_rebuild_search.php b/admin/admin_rebuild_search.php index 11c7d4eda..89081bcb3 100644 --- a/admin/admin_rebuild_search.php +++ b/admin/admin_rebuild_search.php @@ -70,7 +70,7 @@ if (isset($_REQUEST['cancel_button'])) { } // from which post to start processing -$start = abs(intval(@$_REQUEST['start'])); +$start = abs((int)(@$_REQUEST['start'])); // get the total number of posts in the db $total_posts = get_total_posts(); @@ -86,7 +86,7 @@ $session_posts_processed = ($mode == 'refresh') ? get_processed_posts('session') $total_posts_processing = $total_posts - $total_posts_processed; // how many posts to process in this session -if ($session_posts_processing = @intval($_REQUEST['session_posts_processing'])) { +if ($session_posts_processing = @(int)$_REQUEST['session_posts_processing']) { if ($mode == 'submit') { // check if we passed over total_posts just after submitting if ($session_posts_processing + $total_posts_processed > $total_posts) { @@ -118,7 +118,7 @@ if (isset($_REQUEST['time_limit'])) { // check for webserver timeout (IE returns null) if (isset($_SERVER["HTTP_KEEP_ALIVE"])) { // get webserver timeout - $webserver_timeout = intval($_SERVER["HTTP_KEEP_ALIVE"]); + $webserver_timeout = (int)$_SERVER["HTTP_KEEP_ALIVE"]; $time_limit_explain .= '
' . sprintf($lang['TIME_LIMIT_EXPLAIN_WEBSERVER'], $webserver_timeout); if ($time_limit > $webserver_timeout) { @@ -196,7 +196,7 @@ if ($mode == 'submit' || $mode == 'refresh') { } // find how much time the last cycle took - $last_cycle_time = intval(TIMENOW - $start_time); + $last_cycle_time = (int)(TIMENOW - $start_time); // check if we had any data if ($num_rows != 0) { diff --git a/admin/admin_smilies.php b/admin/admin_smilies.php index e7c7e7859..d95d93bc6 100644 --- a/admin/admin_smilies.php +++ b/admin/admin_smilies.php @@ -191,7 +191,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { switch ($mode) { case 'delete': $smiley_id = (!empty($_POST['id'])) ? $_POST['id'] : $_GET['id']; - $smiley_id = intval($smiley_id); + $smiley_id = (int)$smiley_id; $sql = "DELETE FROM " . BB_SMILIES . " WHERE smilies_id = " . $smiley_id; $result = DB()->sql_query($sql); @@ -205,7 +205,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { case 'edit': $smiley_id = (!empty($_POST['id'])) ? $_POST['id'] : $_GET['id']; - $smiley_id = intval($smiley_id); + $smiley_id = (int)$smiley_id; $sql = "SELECT * FROM " . BB_SMILIES . " WHERE smilies_id = " . $smiley_id; $result = DB()->sql_query($sql); @@ -245,7 +245,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { $smile_url = (isset($_POST['smile_url'])) ? trim($_POST['smile_url']) : trim($_GET['smile_url']); $smile_url = bb_ltrim(basename($smile_url), "'"); $smile_emotion = (isset($_POST['smile_emotion'])) ? trim($_POST['smile_emotion']) : trim($_GET['smile_emotion']); - $smile_id = (isset($_POST['smile_id'])) ? intval($_POST['smile_id']) : intval($_GET['smile_id']); + $smile_id = (isset($_POST['smile_id'])) ? (int)$_POST['smile_id'] : (int)$_GET['smile_id']; // If no code was entered complain if ($smile_code == '' || $smile_url == '') { diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php index 0a5be1865..0e3693e65 100644 --- a/admin/admin_user_ban.php +++ b/admin/admin_user_ban.php @@ -204,7 +204,7 @@ if (isset($_POST['submit'])) { for ($i = 0; $i < count($user_list); $i++) { if ($user_list[$i] != -1) { - $where_sql .= (($where_sql != '') ? ', ' : '') . intval($user_list[$i]); + $where_sql .= (($where_sql != '') ? ', ' : '') . (int)$user_list[$i]; } } } diff --git a/admin/admin_user_search.php b/admin/admin_user_search.php index 6b8febb98..b8ef65f8b 100644 --- a/admin/admin_user_search.php +++ b/admin/admin_user_search.php @@ -443,19 +443,19 @@ if (!isset($_REQUEST['dosearch'])) { bb_die($lang['SEARCH_INVALID_DATE']); } - $date_day = intval($date_day); + $date_day = (int)$date_day; if (!preg_match('/^([1-9]|[0-2][0-9]|3[0-1])$/', $date_day)) { bb_die($lang['SEARCH_INVALID_DAY']); } - $date_month = intval($date_month); + $date_month = (int)$date_month; if (!preg_match('/^(0?[1-9]|1[0-2])$/', $date_month)) { bb_die($lang['SEARCH_INVALID_MONTH']); } - $date_year = intval($date_year); + $date_year = (int)$date_year; if (!preg_match('/^(20[0-9]{2}|19[0-9]{2})$/', $date_year)) { bb_die($lang['SEARCH_INVALID_YEAR']); @@ -476,7 +476,7 @@ if (!isset($_REQUEST['dosearch'])) { break; case 'search_group': - $group_id = intval($group_id); + $group_id = (int)$group_id; $base_url .= '&search_group=true&group_id=' . rawurlencode($group_id); @@ -511,7 +511,7 @@ if (!isset($_REQUEST['dosearch'])) { break; case 'search_rank': - $rank_id = intval($rank_id); + $rank_id = (int)$rank_id; $base_url .= '&search_rank=true&rank_id=' . rawurlencode($rank_id); @@ -550,7 +550,7 @@ if (!isset($_REQUEST['dosearch'])) { switch ($postcount_type) { case 'greater': - $postcount_value = intval($postcount_value); + $postcount_value = (int)$postcount_value; $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_GREATER'], $postcount_value); @@ -563,7 +563,7 @@ if (!isset($_REQUEST['dosearch'])) { AND u.user_id <> " . GUEST_UID; break; case 'lesser': - $postcount_value = intval($postcount_value); + $postcount_value = (int)$postcount_value; $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_LESSER'], $postcount_value); @@ -580,8 +580,8 @@ if (!isset($_REQUEST['dosearch'])) { if (strstr($postcount_value, '-')) { $range = preg_split('/[-\s]+/', $postcount_value); - $range_begin = intval($range[0]); - $range_end = intval($range[1]); + $range_begin = (int)$range[0]; + $range_end = (int)$range[1]; if ($range_begin > $range_end) { bb_die($lang['SEARCH_INVALID_POSTCOUNT']); @@ -599,7 +599,7 @@ if (!isset($_REQUEST['dosearch'])) { AND u.user_posts <= $range_end AND u.user_id <> " . GUEST_UID; } else { - $postcount_value = intval($postcount_value); + $postcount_value = (int)$postcount_value; $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_EQUALS'], $postcount_value); @@ -680,7 +680,7 @@ if (!isset($_REQUEST['dosearch'])) { case 'search_lastvisited': $lastvisited_type = strtolower(trim($lastvisited_type)); - $lastvisited_days = intval($lastvisited_days); + $lastvisited_days = (int)$lastvisited_days; $base_url .= '&search_lastvisited=true&lastvisited_type=' . rawurlencode(stripslashes($lastvisited_type)) . '&lastvisited_days=' . rawurlencode($lastvisited_days); @@ -739,7 +739,7 @@ if (!isset($_REQUEST['dosearch'])) { $base_url .= '&search_timezone=true&timezone_type=' . rawurlencode(stripslashes($timezone_type)); $text = sprintf($lang['SEARCH_FOR_TIMEZONE'], strip_tags(htmlspecialchars(stripslashes($timezone_type)))); - $timezone_type = intval($timezone_type); + $timezone_type = (int)$timezone_type; $total_sql .= "SELECT COUNT(user_id) AS total FROM " . BB_USERS . " @@ -752,7 +752,7 @@ if (!isset($_REQUEST['dosearch'])) { case 'search_moderators': $base_url .= '&search_moderators=true&moderators_forum=' . rawurlencode(stripslashes($moderators_forum)); - $moderators_forum = intval($moderators_forum); + $moderators_forum = (int)$moderators_forum; $sql = "SELECT forum_name FROM " . BB_FORUMS . " WHERE forum_id = " . $moderators_forum; @@ -888,7 +888,7 @@ if (!isset($_REQUEST['dosearch'])) { $select_sql .= " $order"; - $page = (isset($_GET['page'])) ? intval($_GET['page']) : intval(trim(@$_POST['page'])); + $page = (isset($_GET['page'])) ? (int)$_GET['page'] : (int)trim(@$_POST['page']); if ($page < 1) { $page = 1; diff --git a/admin/admin_words.php b/admin/admin_words.php index a09abd6c5..a76ec50bd 100644 --- a/admin/admin_words.php +++ b/admin/admin_words.php @@ -45,7 +45,7 @@ if (isset($_POST['add'])) { if ($mode != '') { if ($mode == 'edit' || $mode == 'add') { - $word_id = intval(request_var('id', 0)); + $word_id = (int)request_var('id', 0); $s_hidden_fields = $word = $replacement = ''; @@ -73,7 +73,7 @@ if ($mode != '') { 'S_HIDDEN_FIELDS' => $s_hidden_fields, )); } elseif ($mode == 'save') { - $word_id = intval(request_var('id', 0)); + $word_id = (int)request_var('id', 0); $word = trim(request_var('word', '')); $replacement = trim(request_var('replacement', '')); @@ -101,7 +101,7 @@ if ($mode != '') { bb_die($message); } elseif ($mode == 'delete') { - $word_id = intval(request_var('id', 0)); + $word_id = (int)request_var('id', 0); if ($word_id) { $sql = "DELETE FROM " . BB_WORDS . " WHERE word_id = $word_id"; diff --git a/admin/index.php b/admin/index.php index 5cce9d73c..96c3c4324 100644 --- a/admin/index.php +++ b/admin/index.php @@ -104,11 +104,11 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $avatar_dir_size = $lang['NOT_AVAILABLE']; } - if (intval($posts_per_day) > $total_posts) { + if ((int)$posts_per_day > $total_posts) { $posts_per_day = $total_posts; } - if (intval($topics_per_day) > $total_topics) { + if ((int)$topics_per_day > $total_topics) { $topics_per_day = $total_topics; } diff --git a/admin/stats/tracker.php b/admin/stats/tracker.php index cd7a6eb4a..a3e2ec78d 100644 --- a/admin/stats/tracker.php +++ b/admin/stats/tracker.php @@ -36,7 +36,7 @@ if (!IS_ADMIN) { $peers_in_last_minutes = array(30, 15, 5, 1); $peers_in_last_sec_limit = 300; -$announce_interval = intval($bb_cfg['announce_interval']); +$announce_interval = (int)$bb_cfg['announce_interval']; $stat = array(); define('TMP_TRACKER_TABLE', 'tmp_tracker'); diff --git a/bt/announce.php b/bt/announce.php index 44cab0307..1cc50abd6 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -437,7 +437,7 @@ if (!$output) { foreach ($rowset as $peer) { $peers[] = array( 'ip' => decode_ip($peer['ip']), - 'port' => intval($peer['port']), + 'port' => (int)$peer['port'], ); } } diff --git a/common.php b/common.php index f90e15ff2..4d0257045 100644 --- a/common.php +++ b/common.php @@ -268,9 +268,9 @@ function mkdir_rec($path, $mode) { if (is_dir($path)) { return ($path !== '.' && $path !== '..') ? is_writable($path) : false; - } else { - return (mkdir_rec(dirname($path), $mode)) ? @mkdir($path, $mode) : false; } + + return (mkdir_rec(dirname($path), $mode)) ? @mkdir($path, $mode) : false; } function verify_id($id, $length) @@ -342,40 +342,42 @@ function bencode($var) { if (is_string($var)) { return strlen($var) . ':' . $var; - } elseif (is_int($var)) { + } + + if (is_int($var)) { return 'i' . $var . 'e'; } elseif (is_float($var)) { return 'i' . sprintf('%.0f', $var) . 'e'; } elseif (is_array($var)) { if (count($var) == 0) { return 'de'; - } else { - $assoc = false; + } - foreach ($var as $key => $val) { - if (!is_int($key)) { - $assoc = true; - break; - } - } + $assoc = false; - if ($assoc) { - ksort($var, SORT_REGULAR); - $ret = 'd'; - - foreach ($var as $key => $val) { - $ret .= bencode($key) . bencode($val); - } - return $ret . 'e'; - } else { - $ret = 'l'; - - foreach ($var as $val) { - $ret .= bencode($val); - } - return $ret . 'e'; + foreach ($var as $key => $val) { + if (!is_int($key)) { + $assoc = true; + break; } } + + if ($assoc) { + ksort($var, SORT_REGULAR); + $ret = 'd'; + + foreach ($var as $key => $val) { + $ret .= bencode($key) . bencode($val); + } + return $ret . 'e'; + } + + $ret = 'l'; + + foreach ($var as $val) { + $ret .= bencode($val); + } + return $ret . 'e'; } else { trigger_error('bencode error: wrong data type', E_USER_ERROR); } @@ -482,7 +484,7 @@ if (defined('IN_FORUM')) { require INC_DIR . '/init_bb.php'; } // Tracker init elseif (defined('IN_TRACKER')) { - define('DUMMY_PEER', pack('Nn', ip2long($_SERVER['REMOTE_ADDR']), !empty($_GET['port']) ? intval($_GET['port']) : mt_rand(1000, 65000))); + define('DUMMY_PEER', pack('Nn', ip2long($_SERVER['REMOTE_ADDR']), !empty($_GET['port']) ? (int) $_GET['port'] : mt_rand(1000, 65000))); function dummy_exit($interval = 1800) { diff --git a/dl.php b/dl.php index df1dbbe87..ab0e472e6 100644 --- a/dl.php +++ b/dl.php @@ -131,7 +131,7 @@ $auth_pages = DB()->sql_fetchrowset($result); $num_auth_pages = DB()->num_rows($result); for ($i = 0; $i < $num_auth_pages && $authorised == false; $i++) { - $auth_pages[$i]['post_id'] = intval($auth_pages[$i]['post_id']); + $auth_pages[$i]['post_id'] = (int)$auth_pages[$i]['post_id']; if ($auth_pages[$i]['post_id'] != 0) { $sql = 'SELECT forum_id, topic_id FROM ' . BB_POSTS . ' WHERE post_id = ' . (int)$auth_pages[$i]['post_id']; @@ -178,7 +178,7 @@ if (!in_array($attachment['extension'], $allowed_extensions) && !IS_ADMIN) { bb_die(sprintf($lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension'])); } -$download_mode = intval($download_mode[$attachment['extension']]); +$download_mode = (int)$download_mode[$attachment['extension']]; if ($thumbnail) { $attachment['physical_filename'] = THUMB_DIR . '/t_' . $attachment['physical_filename']; diff --git a/group.php b/group.php index 1858a4976..0696b53ad 100644 --- a/group.php +++ b/group.php @@ -66,8 +66,8 @@ $user->session_start(array('req_login' => true)); set_die_append_msg(); -$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL]) : null; -$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; +$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? (int)$_REQUEST[POST_GROUPS_URL] : null; +$start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0; $per_page = $bb_cfg['group_members_per_page']; $view_mode = isset($_REQUEST['view']) ? (string)$_REQUEST['view'] : null; $rel_limit = 50; diff --git a/group_edit.php b/group_edit.php index d770940eb..3d1c6bcf9 100644 --- a/group_edit.php +++ b/group_edit.php @@ -34,7 +34,7 @@ $page_cfg['include_bbcode_js'] = true; // Start session management $user->session_start(array('req_login' => true)); -$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL]) : null; +$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? (int)$_REQUEST[POST_GROUPS_URL] : null; $group_info = array(); $is_moderator = false; diff --git a/library/ajax/change_user_rank.php b/library/ajax/change_user_rank.php index 5cfe3aa48..78d3f8174 100644 --- a/library/ajax/change_user_rank.php +++ b/library/ajax/change_user_rank.php @@ -30,9 +30,9 @@ if (!defined('IN_AJAX')) { global $datastore, $lang; $ranks = $datastore->get('ranks'); -$rank_id = intval($this->request['rank_id']); +$rank_id = (int)$this->request['rank_id']; -if (!$user_id = intval($this->request['user_id']) or !$profiledata = get_userdata($user_id)) { +if (!$user_id = (int)$this->request['user_id'] or !$profiledata = get_userdata($user_id)) { $this->ajax_die("invalid user_id: $user_id"); } diff --git a/library/ajax/edit_group_profile.php b/library/ajax/edit_group_profile.php index 12778c893..da4556659 100644 --- a/library/ajax/edit_group_profile.php +++ b/library/ajax/edit_group_profile.php @@ -29,7 +29,7 @@ if (!defined('IN_AJAX')) { global $bb_cfg, $userdata, $lang; -if (!$group_id = intval($this->request['group_id']) or !$group_info = get_group_data($group_id)) { +if (!$group_id = (int)$this->request['group_id'] or !$group_info = get_group_data($group_id)) { $this->ajax_die($lang['NO_GROUP_ID_SPECIFIED']); } if (!$mode = (string)$this->request['mode']) { diff --git a/library/ajax/edit_user_profile.php b/library/ajax/edit_user_profile.php index 6f78ead49..ed7aeb90c 100644 --- a/library/ajax/edit_user_profile.php +++ b/library/ajax/edit_user_profile.php @@ -29,7 +29,7 @@ if (!defined('IN_AJAX')) { global $bb_cfg, $lang; -if (!$user_id = intval($this->request['user_id']) or !$profiledata = get_userdata($user_id)) { +if (!$user_id = (int)$this->request['user_id'] or !$profiledata = get_userdata($user_id)) { $this->ajax_die($lang['NO_USER_ID_SPECIFIED']); } if (!$field = (string)$this->request['field']) { diff --git a/library/ajax/group_membership.php b/library/ajax/group_membership.php index 5c99a2534..7a54ccb18 100644 --- a/library/ajax/group_membership.php +++ b/library/ajax/group_membership.php @@ -29,7 +29,7 @@ if (!defined('IN_AJAX')) { global $lang, $user; -if (!$user_id = intval($this->request['user_id']) or !$profiledata = get_userdata($user_id)) { +if (!$user_id = (int)$this->request['user_id'] or !$profiledata = get_userdata($user_id)) { $this->ajax_die("invalid user_id: $user_id"); } diff --git a/library/ajax/topic_tpl.php b/library/ajax/topic_tpl.php index f355dce10..97b1feb24 100644 --- a/library/ajax/topic_tpl.php +++ b/library/ajax/topic_tpl.php @@ -103,7 +103,7 @@ switch ($mode) { $this->response['val']['tpl-last-edit-tst'] = $tpl_data['tpl_last_edit_tm']; $this->response['html']['tpl-name-old-save'] = $tpl_data['tpl_name']; $this->response['html']['tpl-last-edit-time'] = bb_date($tpl_data['tpl_last_edit_tm'], 'd-M-y H:i'); - $this->response['html']['tpl-last-edit-by'] = get_username(intval($tpl_data['tpl_last_edit_by'])); + $this->response['html']['tpl-last-edit-by'] = get_username((int)$tpl_data['tpl_last_edit_by']); $this->response['tpl_rules_href'] = POST_URL . $tpl_data['tpl_rules_post_id'] . '#' . $tpl_data['tpl_rules_post_id']; break; @@ -137,7 +137,7 @@ switch ($mode) { // сохранение изменений case 'save': if ($tpl_data['tpl_last_edit_tm'] > $this->request['tpl_l_ed_tst'] && $tpl_data['tpl_last_edit_by'] != $userdata['user_id']) { - $last_edit_by_username = get_username(intval($tpl_data['tpl_last_edit_by'])); + $last_edit_by_username = get_username((int)$tpl_data['tpl_last_edit_by']); $msg = "Изменения не были сохранены!\n\n"; $msg .= 'Шаблон был отредактирован: ' . html_entity_decode($last_edit_by_username) . ', ' . delta_time($tpl_data['tpl_last_edit_tm']) . " назад\n\n"; $this->ajax_die($msg); diff --git a/library/attach_mod/displaying.php b/library/attach_mod/displaying.php index bb8f26f00..1b84c2a21 100644 --- a/library/attach_mod/displaying.php +++ b/library/attach_mod/displaying.php @@ -49,8 +49,8 @@ function init_complete_extensions_data() for ($i = 0, $size = count($extension_informations); $i < $size; $i++) { $extension = strtolower(trim($extension_informations[$i]['extension'])); $allowed_extensions[] = $extension; - $display_categories[$extension] = intval($extension_informations[$i]['cat_id']); - $download_modes[$extension] = intval($extension_informations[$i]['download_mode']); + $display_categories[$extension] = (int)$extension_informations[$i]['cat_id']; + $download_modes[$extension] = (int)$extension_informations[$i]['download_mode']; $upload_icons[$extension] = trim($extension_informations[$i]['upload_icon']); } } @@ -107,7 +107,7 @@ function display_post_attachments($post_id, $switch_attachment) { global $attach_config, $is_auth; - if (intval($switch_attachment) == 0 || intval($attach_config['disable_mod'])) { + if ((int)$switch_attachment == 0 || (int)$attach_config['disable_mod']) { return; } @@ -127,7 +127,7 @@ function init_display_post_attachments($switch_attachment) $switch_attachment = $forum_row['topic_attachment']; } - if (intval($switch_attachment) == 0 || intval($attach_config['disable_mod']) || (!($is_auth['auth_download'] && $is_auth['auth_view']))) { + if ((int)$switch_attachment == 0 || (int)$attach_config['disable_mod'] || (!($is_auth['auth_download'] && $is_auth['auth_view']))) { init_display_template('body', '{postrow.ATTACHMENTS}', 'viewtopic_attach_guest.tpl'); return; } @@ -227,14 +227,14 @@ function display_attachments($post_id) $thumbnail = false; $link = false; - if (@intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && intval($attach_config['img_display_inlined'])) { - if (intval($attach_config['img_link_width']) != 0 || intval($attach_config['img_link_height']) != 0) { + 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); if ($width == 0 && $height == 0) { $image = true; } else { - if ($width <= intval($attach_config['img_link_width']) && $height <= intval($attach_config['img_link_height'])) { + if ($width <= (int)$attach_config['img_link_width'] && $height <= (int)$attach_config['img_link_height']) { $image = true; } } @@ -243,7 +243,7 @@ function display_attachments($post_id) } } - if (@intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && $attachments['_' . $post_id][$i]['thumbnail'] == 1) { + if (@(int)$display_categories[$attachments['_' . $post_id][$i]['extension']] == IMAGE_CAT && $attachments['_' . $post_id][$i]['thumbnail'] == 1) { $thumbnail = true; $image = false; } @@ -304,7 +304,7 @@ function display_attachments($post_id) if ($link && ($attachments['_' . $post_id][$i]['extension'] === TORRENT_EXT)) { include ATTACH_DIR . '/displaying_torrent.php'; } elseif ($link) { - $target_blank = ((@intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT)) ? 'target="_blank"' : ''; + $target_blank = ((@(int)$display_categories[$attachments['_' . $post_id][$i]['extension']] == IMAGE_CAT)) ? 'target="_blank"' : ''; // display attachment $template->assign_block_vars('postrow.attach.attachrow', array( diff --git a/library/attach_mod/includes/functions_admin.php b/library/attach_mod/includes/functions_admin.php index fd142fc46..111412187 100644 --- a/library/attach_mod/includes/functions_admin.php +++ b/library/attach_mod/includes/functions_admin.php @@ -121,17 +121,13 @@ function sort_multi_array($sort_array, $key, $sort_order, $pre_string_sort = 0) // do checks based on key $switch = false; if (!$string_sort) { - if ( - ($sort_order == 'DESC' && intval(@$sort_array[$j][$key]) < intval(@$sort_array[$j + 1][$key])) || - ($sort_order == 'ASC' && intval(@$sort_array[$j][$key]) > intval(@$sort_array[$j + 1][$key])) - ) { + if (($sort_order == 'DESC' && intval(@$sort_array[$j][$key]) < intval(@$sort_array[$j + 1][$key])) || + ($sort_order == 'ASC' && intval(@$sort_array[$j][$key]) > intval(@$sort_array[$j + 1][$key]))) { $switch = true; } } else { - if ( - ($sort_order == 'DESC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) < 0) || - ($sort_order == 'ASC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) > 0) - ) { + if (($sort_order == 'DESC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) < 0) || + ($sort_order == 'ASC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) > 0)) { $switch = true; } } @@ -209,7 +205,7 @@ function search_attachments($order_by, &$total_rows) $matching_userids = ''; if ($row = DB()->sql_fetchrow($result)) { do { - $matching_userids .= (($matching_userids != '') ? ', ' : '') . intval($row['user_id']); + $matching_userids .= (($matching_userids != '') ? ', ' : '') . $row['user_id']; } while ($row = DB()->sql_fetchrow($result)); DB()->sql_freeresult($result); @@ -260,7 +256,7 @@ function search_attachments($order_by, &$total_rows) // Search Forum $search_forum = get_var('search_forum', ''); if ($search_forum) { - $where_sql[] = ' (p.forum_id = ' . intval($search_forum) . ') '; + $where_sql[] = ' (p.forum_id = ' . (int)$search_forum . ') '; } $sql = 'SELECT a.*, t.post_id, p.post_time, p.topic_id diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 0384240e4..5f0b371e0 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -102,7 +102,7 @@ function auth_pack($auth_array) $auth_cache = ''; for ($i = 0; $i < count($auth_array); $i++) { - $val = base64_pack(intval($auth_array[$i])); + $val = base64_pack((int)$auth_array[$i]); if (strlen($val) == 1 && !$one_char) { $auth_cache .= $one_char_encoding; $one_char = true; @@ -141,7 +141,7 @@ function auth_unpack($auth_cache) $forum_auth = substr($auth_cache, $pos, $auth_len); $forum_id = base64_unpack($forum_auth); - $auth[] = intval($forum_id); + $auth[] = (int)$forum_id; } return $auth; } @@ -270,7 +270,7 @@ function get_attachments_from_post($post_id_array) return $attachments; } - $post_id = intval($post_id_array); + $post_id = (int)$post_id_array; $post_id_array = array(); $post_id_array[] = $post_id; @@ -282,7 +282,7 @@ function get_attachments_from_post($post_id_array) return $attachments; } - $display_order = (intval($attach_config['display_order']) == 0) ? 'DESC' : 'ASC'; + $display_order = ((int)$attach_config['display_order'] == 0) ? 'DESC' : 'ASC'; $sql = 'SELECT a.post_id, d.* FROM ' . BB_ATTACHMENTS . ' a, ' . BB_ATTACHMENTS_DESC . " d @@ -574,7 +574,7 @@ function attach_mod_sql_build_array($query, $assoc_ary = false) } elseif (is_array($var) && is_string($var[0])) { $values[] = $var[0]; } else { - $values[] = (is_bool($var)) ? intval($var) : $var; + $values[] = (is_bool($var)) ? (int)$var : $var; } } @@ -589,7 +589,7 @@ function attach_mod_sql_build_array($query, $assoc_ary = false) } elseif (is_string($var)) { $values[] = "'" . attach_mod_sql_escape($var) . "'"; } else { - $values[] = (is_bool($var)) ? intval($var) : $var; + $values[] = (is_bool($var)) ? (int)$var : $var; } } $ary[] = '(' . implode(', ', $values) . ')'; @@ -604,7 +604,7 @@ function attach_mod_sql_build_array($query, $assoc_ary = false) } elseif (is_string($var)) { $values[] = "$key = '" . attach_mod_sql_escape($var) . "'"; } else { - $values[] = (is_bool($var)) ? "$key = " . intval($var) : "$key = $var"; + $values[] = (is_bool($var)) ? "$key = " . (int)$var : "$key = $var"; } } $query = implode(($query == 'UPDATE') ? ', ' : ' AND ', $values); diff --git a/library/attach_mod/includes/functions_delete.php b/library/attach_mod/includes/functions_delete.php index cee349b4e..20affee97 100644 --- a/library/attach_mod/includes/functions_delete.php +++ b/library/attach_mod/includes/functions_delete.php @@ -46,7 +46,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } elseif (strstr($attach_id_array, ',')) { $attach_id_array = explode(',', $attach_id_array); } else { - $attach_id = intval($attach_id_array); + $attach_id = (int)$attach_id_array; $attach_id_array = array(); $attach_id_array[] = $attach_id; } @@ -72,7 +72,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } while ($row = DB()->sql_fetchrow($result)) { - $post_id_array[] = intval($row[$p_id]); + $post_id_array[] = (int)$row[$p_id]; } DB()->sql_freeresult($result); } @@ -87,7 +87,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } elseif (strstr($post_id_array, ',')) { $post_id_array = explode(',', $post_id_array); } else { - $post_id = intval($post_id_array); + $post_id = (int)$post_id_array; $post_id_array = array(); $post_id_array[] = $post_id; @@ -132,7 +132,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } elseif (strstr($attach_id_array, ',')) { $attach_id_array = explode(',', $attach_id_array); } else { - $attach_id = intval($attach_id_array); + $attach_id = (int)$attach_id_array; $attach_id_array = array(); $attach_id_array[] = $attach_id; @@ -218,7 +218,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, for ($j = 0; $j < $num_attach; $j++) { unlink_attach($attachments[$j]['physical_filename']); - if (intval($attachments[$j]['thumbnail']) == 1) { + if ((int)$attachments[$j]['thumbnail'] == 1) { unlink_attach($attachments[$j]['physical_filename'], MODE_THUMBNAIL); } diff --git a/library/attach_mod/includes/functions_filetypes.php b/library/attach_mod/includes/functions_filetypes.php index aa7e06bef..4270caf58 100644 --- a/library/attach_mod/includes/functions_filetypes.php +++ b/library/attach_mod/includes/functions_filetypes.php @@ -175,7 +175,7 @@ function image_getdimension($file) $tmp_str = fread($fp, 4); $w1 = read_word($fp); - if (intval($w1) < 16) { + if ((int)$w1 < 16) { $error = true; } @@ -183,7 +183,7 @@ function image_getdimension($file) $tmp_str = fread($fp, 4); if ($tmp_str == 'JFIF') { $o_byte = fread($fp, 1); - if (intval($o_byte) != 0) { + if ((int)$o_byte != 0) { $error = true; } diff --git a/library/attach_mod/includes/functions_includes.php b/library/attach_mod/includes/functions_includes.php index 35a0f6b0e..1de52403b 100644 --- a/library/attach_mod/includes/functions_includes.php +++ b/library/attach_mod/includes/functions_includes.php @@ -30,7 +30,7 @@ function attach_build_auth_levels($is_auth, &$s_auth_can) { global $lang, $attach_config; - if (intval($attach_config['disable_mod'])) { + if ((int)$attach_config['disable_mod']) { return; } diff --git a/library/includes/classes/utf8.php b/library/includes/classes/utf8.php index f8da0f87e..ac7ab98e6 100644 --- a/library/includes/classes/utf8.php +++ b/library/includes/classes/utf8.php @@ -3152,8 +3152,8 @@ class utf8 return $s; } - $length = intval($length); - $glue = strval($glue); + $length = (int)$length; + $glue = (string)$glue; if ($length < 1) { $length = 76; } @@ -3632,7 +3632,7 @@ class utf8 return $s; } - $length = ($length === null) ? 1 : intval($length); + $length = ($length === null) ? 1 : (int)$length; if ($length < 1) { return false; } @@ -3766,7 +3766,7 @@ class utf8 #optimization block (speed improve) #{{{ - $ascii_int = intval(self::is_ascii($s)) + intval(self::is_ascii($needle)); + $ascii_int = (int)self::is_ascii($s) + (int)self::is_ascii($needle); if ($ascii_int === 1) { return false; } @@ -4224,13 +4224,13 @@ class utf8 if ($type == STR_PAD_LEFT) { $repeat_num = ceil($pad_len / $pad_str_len); - return self::substr(str_repeat($pad_str, $repeat_num), 0, intval(floor($pad_len))) . $s; + return self::substr(str_repeat($pad_str, $repeat_num), 0, (int)floor($pad_len)) . $s; } if ($type == STR_PAD_BOTH) { $pad_len /= 2; - $pad_amount_left = intval(floor($pad_len)); - $pad_amount_right = intval(ceil($pad_len)); + $pad_amount_left = (int)floor($pad_len); + $pad_amount_right = (int)ceil($pad_len); $repeat_times_left = ceil($pad_amount_left / $pad_str_len); $repeat_times_right = ceil($pad_amount_right / $pad_str_len); diff --git a/library/includes/cron/jobs/board_maintenance.php b/library/includes/cron/jobs/board_maintenance.php index 2a495f804..1221c3219 100644 --- a/library/includes/cron/jobs/board_maintenance.php +++ b/library/includes/cron/jobs/board_maintenance.php @@ -64,6 +64,6 @@ if ($poll_max_days = (int)$bb_cfg['poll_max_days']) { DB()->query("UPDATE " . BB_USERS . " SET user_newpasswd = '' WHERE user_lastvisit < " . (TIMENOW - 7 * 86400)); // Чистка кеша постов -if ($posts_days = intval($bb_cfg['posts_cache_days_keep'])) { +if ($posts_days = (int)$bb_cfg['posts_cache_days_keep']) { DB()->query("DELETE FROM " . BB_POSTS_HTML . " WHERE post_html_time < DATE_SUB(NOW(), INTERVAL $posts_days DAY)"); } diff --git a/library/includes/cron/jobs/clean_dlstat.php b/library/includes/cron/jobs/clean_dlstat.php index 859fc3a3c..8b7701b02 100644 --- a/library/includes/cron/jobs/clean_dlstat.php +++ b/library/includes/cron/jobs/clean_dlstat.php @@ -67,7 +67,7 @@ DB()->query(" "); // Tor-Stats cleanup -if ($torstat_days_keep = intval($bb_cfg['torstat_days_keep'])) { +if ($torstat_days_keep = (int)$bb_cfg['torstat_days_keep']) { DB()->query("DELETE QUICK FROM " . BB_BT_TORSTAT . " WHERE last_modified_torstat < DATE_SUB(NOW(), INTERVAL $torstat_days_keep DAY)"); } diff --git a/library/includes/cron/jobs/prune_inactive_users.php b/library/includes/cron/jobs/prune_inactive_users.php index f3c5d6379..eb6b92daf 100644 --- a/library/includes/cron/jobs/prune_inactive_users.php +++ b/library/includes/cron/jobs/prune_inactive_users.php @@ -36,7 +36,7 @@ while (true) { $prune_users = $not_activated_users = $not_active_users = array(); - if ($not_activated_days = intval($bb_cfg['user_not_activated_days_keep'])) { + if ($not_activated_days = (int)$bb_cfg['user_not_activated_days_keep']) { $sql = DB()->fetch_rowset("SELECT user_id FROM " . BB_USERS . " WHERE user_level = 0 AND user_lastvisit = 0 @@ -50,7 +50,7 @@ while (true) { } } - if ($not_active_days = intval($bb_cfg['user_not_active_days_keep'])) { + if ($not_active_days = (int)$bb_cfg['user_not_active_days_keep']) { $sql = DB()->fetch_rowset("SELECT user_id FROM " . BB_USERS . " WHERE user_level = 0 AND user_posts = 0 diff --git a/library/includes/cron/jobs/sessions_cleanup.php b/library/includes/cron/jobs/sessions_cleanup.php index e67aff133..2424120e0 100644 --- a/library/includes/cron/jobs/sessions_cleanup.php +++ b/library/includes/cron/jobs/sessions_cleanup.php @@ -27,10 +27,10 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -$user_session_expire_time = TIMENOW - intval($bb_cfg['user_session_duration']); -$admin_session_expire_time = TIMENOW - intval($bb_cfg['admin_session_duration']); +$user_session_expire_time = TIMENOW - (int)$bb_cfg['user_session_duration']; +$admin_session_expire_time = TIMENOW - (int)$bb_cfg['admin_session_duration']; -$user_session_gc_time = $user_session_expire_time - intval($bb_cfg['user_session_gc_ttl']); +$user_session_gc_time = $user_session_expire_time - (int)$bb_cfg['user_session_gc_ttl']; $admin_session_gc_time = $admin_session_expire_time; // ############################ Tables LOCKED ################################ diff --git a/library/includes/cron/jobs/tr_cleanup_and_dlstat.php b/library/includes/cron/jobs/tr_cleanup_and_dlstat.php index a261ea667..144106d73 100644 --- a/library/includes/cron/jobs/tr_cleanup_and_dlstat.php +++ b/library/includes/cron/jobs/tr_cleanup_and_dlstat.php @@ -81,8 +81,8 @@ DB()->query(" // Clean peers table if ($tr_cfg['autoclean']) { - $announce_interval = max(intval($bb_cfg['announce_interval']), 60); - $expire_factor = max(floatval($tr_cfg['expire_factor']), 1); + $announce_interval = max((int)$bb_cfg['announce_interval'], 60); + $expire_factor = max((float)$tr_cfg['expire_factor'], 1); $peer_expire_time = TIMENOW - floor($announce_interval * $expire_factor); DB()->query("DELETE FROM " . BB_BT_TRACKER . " WHERE update_time < $peer_expire_time"); diff --git a/library/includes/functions.php b/library/includes/functions.php index 3e884d398..2e4b78697 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -838,7 +838,7 @@ function declension($int, $expressions, $format = '%1$s %2$s') if (count($expressions) < 3) { $expressions[2] = $expressions[1]; } - $count = intval($int) % 100; + $count = (int)$int % 100; if ($count >= 5 && $count <= 20) { $result = $expressions['2']; @@ -969,7 +969,7 @@ function select_get_val($key, &$val, $options_ary, $default, $num = true) if (isset($_REQUEST[$key]) && is_string($_REQUEST[$key])) { if (isset($options_ary[$_REQUEST[$key]])) { - $val = ($num) ? intval($_REQUEST[$key]) : $_REQUEST[$key]; + $val = ($num) ? (int)$_REQUEST[$key] : $_REQUEST[$key]; } } elseif (isset($previous_settings[$key])) { $val = $previous_settings[$key]; @@ -1100,7 +1100,7 @@ function str_short($text, $max_length, $space = ' ') if ($max_length && mb_strlen($text, 'UTF-8') > $max_length) { $text = mb_substr($text, 0, $max_length, 'UTF-8'); - if ($last_space_pos = $max_length - intval(strpos(strrev($text), $space))) { + if ($last_space_pos = $max_length - (int)strpos(strrev($text), $space)) { if ($last_space_pos > round($max_length * 3 / 4)) { $last_space_pos--; $text = mb_substr($text, 0, $last_space_pos, 'UTF-8'); @@ -1300,7 +1300,7 @@ function get_userdata($u, $force_name = false, $allow_guest = false) return false; } - if (intval($u) == GUEST_UID && $allow_guest) { + if ((int)$u == GUEST_UID && $allow_guest) { if ($u_data = CACHE('bb_cache')->get('guest_userdata')) { return $u_data; } diff --git a/library/includes/functions_admin_torrent.php b/library/includes/functions_admin_torrent.php index d2fb5d931..0100be6e5 100644 --- a/library/includes/functions_admin_torrent.php +++ b/library/includes/functions_admin_torrent.php @@ -43,7 +43,7 @@ function update_table_bool($table_name, $key, $field_name, $field_def_val) $in_sql = array(); foreach ($_POST[$field_name] as $i => $val) { - $in_sql[] = intval($val); + $in_sql[] = (int)$val; } // Update status @@ -109,7 +109,7 @@ function update_config_table($table_name, $default_cfg, $cfg, $type) } elseif ($type == 'bool') { $config_value = ($_POST[$config_name]) ? 1 : 0; } elseif ($type == 'num') { - $config_value = abs(intval($_POST[$config_name])); + $config_value = abs((int)$_POST[$config_name]); } else { return; } diff --git a/library/includes/functions_torrent.php b/library/includes/functions_torrent.php index 4cb1b9ae6..181604f7b 100644 --- a/library/includes/functions_torrent.php +++ b/library/includes/functions_torrent.php @@ -31,7 +31,7 @@ function get_torrent_info($attach_id) { global $lang; - $attach_id = intval($attach_id); + $attach_id = (int)$attach_id; $sql = " SELECT @@ -162,7 +162,7 @@ function delete_torrent($attach_id, $mode = '') { global $lang, $reg_mode, $topic_id; - $attach_id = intval($attach_id); + $attach_id = (int)$attach_id; $reg_mode = $mode; if (!$torrent = get_torrent_info($attach_id)) { @@ -223,7 +223,7 @@ function change_tor_type($attach_id, $tor_status_gold) } $topic_id = $torrent['topic_id']; - $tor_status_gold = intval($tor_status_gold); + $tor_status_gold = (int)$tor_status_gold; $info_hash = null; DB()->query("UPDATE " . BB_BT_TORRENTS . " SET tor_type = $tor_status_gold WHERE topic_id = $topic_id LIMIT 1"); @@ -241,7 +241,7 @@ function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED { global $bb_cfg, $lang, $reg_mode, $tr_cfg; - $attach_id = intval($attach_id); + $attach_id = (int)$attach_id; $reg_mode = $mode; if (!$torrent = get_torrent_info($attach_id)) { @@ -462,7 +462,7 @@ function send_torrent_with_passkey($filename) bb_die('This is not a bencoded file'); } - $announce = $bb_cfg['ocelot']['enabled'] ? strval($bb_cfg['ocelot']['url'] . $passkey_val . "/announce") : strval($ann_url . "?$passkey_key=$passkey_val"); + $announce = $bb_cfg['ocelot']['enabled'] ? (string)($bb_cfg['ocelot']['url'] . $passkey_val . "/announce") : (string)($ann_url . "?$passkey_key=$passkey_val"); // Replace original announce url with tracker default if ($bb_cfg['bt_replace_ann_url'] || !isset($tor['announce'])) { @@ -494,13 +494,13 @@ function send_torrent_with_passkey($filename) $publisher_name = $bb_cfg['server_name']; $publisher_url = make_url(TOPIC_URL . $topic_id); - $tor['publisher'] = strval($publisher_name); + $tor['publisher'] = (string)$publisher_name; unset($tor['publisher.utf-8']); - $tor['publisher-url'] = strval($publisher_url); + $tor['publisher-url'] = (string)$publisher_url; unset($tor['publisher-url.utf-8']); - $tor['comment'] = strval($publisher_url); + $tor['comment'] = (string)$publisher_url; unset($tor['comment.utf-8']); // Send torrent diff --git a/library/includes/page_header.php b/library/includes/page_header.php index d16bd911a..a3117f812 100644 --- a/library/includes/page_header.php +++ b/library/includes/page_header.php @@ -153,7 +153,7 @@ $template->assign_vars(array( 'FULL_URL' => FULL_URL, 'CURRENT_TIME' => sprintf($lang['CURRENT_TIME'], bb_date(TIMENOW, $bb_cfg['last_visit_date_format'], false)), - 'S_TIMEZONE' => preg_replace('/\(.*?\)/', '', sprintf($lang['ALL_TIMES'], $lang['TZ'][str_replace(',', '.', floatval($bb_cfg['board_timezone']))])), + 'S_TIMEZONE' => preg_replace('/\(.*?\)/', '', sprintf($lang['ALL_TIMES'], $lang['TZ'][str_replace(',', '.', (float)$bb_cfg['board_timezone'])])), 'BOARD_TIMEZONE' => $bb_cfg['board_timezone'], 'PM_INFO' => $pm_info, diff --git a/library/includes/posting_tpl.php b/library/includes/posting_tpl.php index 0cf8e54b8..63e41ed5b 100644 --- a/library/includes/posting_tpl.php +++ b/library/includes/posting_tpl.php @@ -90,7 +90,7 @@ if ($edit_tpl_mode) { 'TPL_COMMENT' => $tpl_data['tpl_comment'], 'TPL_RULES_POST_ID' => $tpl_data['tpl_rules_post_id'], 'TPL_LAST_EDIT_TIME' => bb_date($tpl_data['tpl_last_edit_tm'], 'd-M-y H:i'), - 'TPL_LAST_EDIT_USER' => get_username(intval($tpl_data['tpl_last_edit_by'])), + 'TPL_LAST_EDIT_USER' => get_username((int)$tpl_data['tpl_last_edit_by']), 'TPL_LAST_EDIT_TIMESTAMP' => $tpl_data['tpl_last_edit_tm'], )); } diff --git a/library/includes/sessions.php b/library/includes/sessions.php index ad3f7bcd2..077bc1a5c 100644 --- a/library/includes/sessions.php +++ b/library/includes/sessions.php @@ -183,7 +183,7 @@ class user_common $login = false; $user_id = ($bb_cfg['allow_autologin'] && $this->sessiondata['uk'] && $this->sessiondata['uid']) ? $this->sessiondata['uid'] : GUEST_UID; - if ($userdata = get_userdata(intval($user_id), false, true)) { + if ($userdata = get_userdata((int)$user_id, false, true)) { if ($userdata['user_id'] != GUEST_UID && $userdata['user_active']) { if (verify_id($this->sessiondata['uk'], LOGIN_KEY_LENGTH) && $this->verify_autologin_id($userdata, true, false)) { $login = ($userdata['autologin_id'] && $this->sessiondata['uk'] === $userdata['autologin_id']); @@ -431,7 +431,7 @@ class user_common } // user_id if (!empty($sd_resv['uid'])) { - $this->sessiondata['uid'] = intval($sd_resv['uid']); + $this->sessiondata['uid'] = (int)$sd_resv['uid']; } // sid if (!empty($sd_resv['sid']) && verify_id($sd_resv['sid'], SID_LENGTH)) { diff --git a/library/includes/ucp/activate.php b/library/includes/ucp/activate.php index 4320822a2..588571dd7 100644 --- a/library/includes/ucp/activate.php +++ b/library/includes/ucp/activate.php @@ -33,7 +33,7 @@ if (empty($_GET['u']) || empty($_GET['act_key'])) { $sql = "SELECT user_active, user_id, username, user_email, user_newpasswd, user_lang, user_actkey FROM " . BB_USERS . " - WHERE user_id = " . intval($_GET[POST_USERS_URL]); + WHERE user_id = " . (int)$_GET[POST_USERS_URL]; if (!($result = DB()->sql_query($sql))) { bb_die('Could not obtain user information'); } diff --git a/library/includes/ucp/email.php b/library/includes/ucp/email.php index 0059089e9..1b89d4fa0 100644 --- a/library/includes/ucp/email.php +++ b/library/includes/ucp/email.php @@ -35,7 +35,7 @@ if (!$bb_cfg['board_email_form']) { set_die_append_msg(); if (!empty($_GET[POST_USERS_URL]) || !empty($_POST[POST_USERS_URL])) { - $user_id = (!empty($_GET[POST_USERS_URL])) ? intval($_GET[POST_USERS_URL]) : intval($_POST[POST_USERS_URL]); + $user_id = (!empty($_GET[POST_USERS_URL])) ? (int)$_GET[POST_USERS_URL] : (int)$_POST[POST_USERS_URL]; } else { bb_die($lang['NO_USER_SPECIFIED']); } diff --git a/library/includes/ucp/topic_watch.php b/library/includes/ucp/topic_watch.php index 73e5f6411..97180a529 100644 --- a/library/includes/ucp/topic_watch.php +++ b/library/includes/ucp/topic_watch.php @@ -32,7 +32,7 @@ $page_cfg['include_bbcode_js'] = true; $tracking_topics = get_tracks('topic'); $user_id = $userdata['user_id']; -$start = isset($_GET['start']) ? abs(intval($_GET['start'])) : 0; +$start = isset($_GET['start']) ? abs((int)$_GET['start']) : 0; $per_page = $bb_cfg['topics_per_page']; if (isset($_POST['topic_id_list'])) { diff --git a/memberlist.php b/memberlist.php index c84d7e6cd..4a2793188 100644 --- a/memberlist.php +++ b/memberlist.php @@ -32,7 +32,7 @@ $page_cfg['use_tablesorter'] = true; $user->session_start(array('req_login' => true)); -$start = abs(intval(request_var('start', 0))); +$start = abs((int)request_var('start', 0)); $mode = (string)request_var('mode', 'joined'); $sort_order = (request_var('order', 'ASC') == 'ASC') ? 'ASC' : 'DESC'; $username = request_var('username', ''); diff --git a/modcp.php b/modcp.php index 42c9066a6..3dc445ffe 100644 --- a/modcp.php +++ b/modcp.php @@ -93,7 +93,7 @@ $forum_id = isset($_REQUEST['f']) ? $_REQUEST['f'] : 0; $topic_id = isset($_REQUEST['t']) ? $_REQUEST['t'] : 0; $post_id = isset($_REQUEST['p']) ? $_REQUEST['p'] : 0; -$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; +$start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0; $confirmed = isset($_POST['confirm']); $mode = $topic_title = ''; @@ -398,7 +398,7 @@ switch ($mode) { if (($split || $delete_posts) && ($posts && $topic_id && $forum_id && $topic_first_post_id) && $confirmed) { foreach ($posts as $post_id) { - if ($pid = intval($post_id)) { + if ($pid = (int)$post_id) { $req_post_id_sql[] = $pid; } } @@ -441,8 +441,8 @@ switch ($mode) { $user_id_sql = ''; $post_id_sql = ''; do { - $user_id_sql .= (($user_id_sql != '') ? ', ' : '') . intval($row['poster_id']); - $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']); + $user_id_sql .= (($user_id_sql != '') ? ', ' : '') . (int)$row['poster_id']; + $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . (int)$row['post_id']; } while ($row = DB()->sql_fetchrow($result)); $post_subject = clean_title($_POST['subject']); @@ -450,7 +450,7 @@ switch ($mode) { bb_die($lang['EMPTY_SUBJECT']); } - $new_forum_id = intval($_POST['new_forum_id']); + $new_forum_id = (int)$_POST['new_forum_id']; $topic_time = TIMENOW; $sql = 'SELECT forum_id FROM ' . BB_FORUMS . ' WHERE forum_id = ' . $new_forum_id; diff --git a/poll.php b/poll.php index 614cb21d0..79652d1de 100644 --- a/poll.php +++ b/poll.php @@ -34,7 +34,7 @@ $forum_id = (int)@$_POST['forum_id']; $vote_id = (int)@$_POST['vote_id']; $return_topic_url = TOPIC_URL . $topic_id; -$return_topic_url .= !empty($_POST['start']) ? "&start=" . intval($_POST['start']) : ''; +$return_topic_url .= !empty($_POST['start']) ? "&start=" . (int)$_POST['start'] : ''; set_die_append_msg($forum_id, $topic_id); diff --git a/posting.php b/posting.php index f49263339..61e36ec14 100644 --- a/posting.php +++ b/posting.php @@ -281,7 +281,7 @@ execute_posting_attachment_handling(); $topic_has_new_posts = false; if (!IS_GUEST && $mode != 'newtopic' && ($submit || $preview || $mode == 'quote' || $mode == 'reply') && isset($_COOKIE[COOKIE_TOPIC])) { - if ($topic_last_read = max(intval(@$tracking_topics[$topic_id]), intval(@$tracking_forums[$forum_id]))) { + if ($topic_last_read = max((int)(@$tracking_topics[$topic_id]), (int)(@$tracking_forums[$forum_id]))) { $sql = "SELECT p.*, pt.post_text, u.username, u.user_rank FROM " . BB_POSTS . " p, " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u WHERE p.topic_id = " . (int)$topic_id . " diff --git a/privmsg.php b/privmsg.php index e0115af93..12dac9eb8 100644 --- a/privmsg.php +++ b/privmsg.php @@ -100,10 +100,10 @@ if ($cancel) { // // Var definitions // -$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; +$start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0; if (isset($_POST[POST_POST_URL]) || isset($_GET[POST_POST_URL])) { - $privmsg_id = (isset($_POST[POST_POST_URL])) ? intval($_POST[POST_POST_URL]) : intval($_GET[POST_POST_URL]); + $privmsg_id = (isset($_POST[POST_POST_URL])) ? (int)$_POST[POST_POST_URL] : (int)$_GET[POST_POST_URL]; } else { $privmsg_id = ''; } @@ -126,7 +126,7 @@ $template->assign_var('POSTING_SUBJECT'); if ($mode == 'read') { if (!empty($_GET[POST_POST_URL])) { - $privmsgs_id = intval($_GET[POST_POST_URL]); + $privmsgs_id = (int)$_GET[POST_POST_URL]; } else { bb_die($lang['NO_PM_ID']); } @@ -463,7 +463,7 @@ if ($mode == 'read') { if (!$delete_all) { for ($i = 0; $i < count($mark_list); $i++) { - $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]); + $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . (int)$mark_list[$i]; } $delete_sql_id = "AND privmsgs_id IN ($delete_sql_id)"; } @@ -505,7 +505,7 @@ if ($mode == 'read') { if (count($mark_list)) { $delete_sql_id = ''; for ($i = 0; $i < count($mark_list); $i++) { - $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]); + $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . (int)$mark_list[$i]; } if ($folder == 'inbox' || $folder == 'outbox') { @@ -664,7 +664,7 @@ if ($mode == 'read') { $saved_sql_id = ''; for ($i = 0; $i < count($mark_list); $i++) { - $saved_sql_id .= (($saved_sql_id != '') ? ', ' : '') . intval($mark_list[$i]); + $saved_sql_id .= (($saved_sql_id != '') ? ', ' : '') . (int)$mark_list[$i]; } // Process request @@ -992,7 +992,7 @@ if ($mode == 'read') { } if (!empty($_GET[POST_USERS_URL])) { - $user_id = intval($_GET[POST_USERS_URL]); + $user_id = (int)$_GET[POST_USERS_URL]; $sql = "SELECT username FROM " . BB_USERS . " WHERE user_id = $user_id AND user_id <> " . GUEST_UID; if (!($result = DB()->sql_query($sql))) { @@ -1277,7 +1277,7 @@ if ($mode == 'read') { // Show messages over previous x days/months // if ($submit_msgdays && (!empty($_POST['msgdays']) || !empty($_GET['msgdays']))) { - $msg_days = (!empty($_POST['msgdays'])) ? intval($_POST['msgdays']) : intval($_GET['msgdays']); + $msg_days = (!empty($_POST['msgdays'])) ? (int)$_POST['msgdays'] : (int)$_GET['msgdays']; $min_msg_time = TIMENOW - ($msg_days * 86400); $limit_msg_time_total = " AND privmsgs_date > $min_msg_time"; diff --git a/search.php b/search.php index bf5ef4b77..389e5e081 100644 --- a/search.php +++ b/search.php @@ -103,7 +103,7 @@ $max_forum_name_len = 60; // inside forum select box $text_match_max_len = 60; $poster_name_max_len = 25; -$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; +$start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0; $url = basename(__FILE__); $anon_id = GUEST_UID; diff --git a/tracker.php b/tracker.php index f62266a71..e6833db62 100644 --- a/tracker.php +++ b/tracker.php @@ -59,7 +59,7 @@ $date_format = 'j-M-y'; $row_class_1 = 'row1'; $row_class_2 = 'row2'; -$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; +$start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0; $set_default = isset($_GET['def']); $user_id = $userdata['user_id']; @@ -402,7 +402,7 @@ if (!$set_default) { $req_poster_id = ''; if (isset($_GET[$poster_id_key]) && !$search_id) { - $req_poster_id = intval($_GET[$poster_id_key]); + $req_poster_id = (int)$_GET[$poster_id_key]; } elseif (isset($_POST[$poster_name_key]) && !$search_id) { if ($req_poster_name = clean_username($_POST[$poster_name_key])) { $poster_name_sql = str_replace("\\'", "''", $req_poster_name); @@ -416,7 +416,7 @@ if (!$set_default) { } } } elseif ($search_id && $previous_settings[$poster_id_key]) { - $poster_id_val = intval($previous_settings[$poster_id_key]); + $poster_id_val = (int)$previous_settings[$poster_id_key]; $poster_name_val = ($previous_settings[$poster_name_key]) ?: ''; } @@ -470,10 +470,10 @@ $poster_id = (bool)$poster_id_val; $title_match = (bool)$title_match_sql; $tor_type = (bool)$tor_type_val; -$hide_cat = intval(!$show_cat_val); -$hide_forum = intval(!$show_forum_val); -$hide_author = intval(!$show_author_val); -$hide_speed = intval(!$show_speed_val); +$hide_cat = (int)(!$show_cat_val); +$hide_forum = (int)(!$show_forum_val); +$hide_author = (int)(!$show_author_val); +$hide_speed = (int)(!$show_speed_val); $only_new = ($new_val && !IS_GUEST); $only_active = ($active_val || $seed_exist); diff --git a/viewforum.php b/viewforum.php index 2b674599b..cd020a9b6 100644 --- a/viewforum.php +++ b/viewforum.php @@ -42,7 +42,7 @@ $page_cfg['load_tpl_vars'] = array( // Init request vars $forum_id = (int)request_var('f', ''); -$start = abs(intval(request_var('start', ''))); +$start = abs((int)request_var('start', '')); $mark_read = (request_var('mark', '') === 'topics'); $anon = GUEST_UID; @@ -233,7 +233,7 @@ $topics_per_page = $bb_cfg['topics_per_page']; $select_tpp = ''; if ($is_auth['auth_mod']) { - if ($req_tpp = abs(intval(@$_REQUEST['tpp'])) and in_array($req_tpp, $bb_cfg['allowed_topics_per_page'])) { + if ($req_tpp = abs((int)(@$_REQUEST['tpp'])) and in_array($req_tpp, $bb_cfg['allowed_topics_per_page'])) { $topics_per_page = $req_tpp; } @@ -259,7 +259,7 @@ $sel_previous_days = array( ); if (!empty($_REQUEST['topicdays'])) { - if ($req_topic_days = abs(intval($_REQUEST['topicdays'])) and isset($sel_previous_days[$req_topic_days])) { + if ($req_topic_days = abs((int)$_REQUEST['topicdays']) and isset($sel_previous_days[$req_topic_days])) { $sql = " SELECT COUNT(*) AS forum_topics FROM " . BB_TOPICS . " diff --git a/viewtopic.php b/viewtopic.php index 4c53ab47e..9cfc60f2a 100644 --- a/viewtopic.php +++ b/viewtopic.php @@ -40,7 +40,7 @@ $page_cfg['load_tpl_vars'] = array( ); $newest = $next_topic_id = 0; -$start = isset($_GET['start']) ? abs(intval($_GET['start'])) : 0; +$start = isset($_GET['start']) ? abs((int)$_GET['start']) : 0; $topic_id = isset($_GET[POST_TOPIC_URL]) ? (int)$_GET[POST_TOPIC_URL] : 0; $post_id = (!$topic_id && isset($_GET[POST_POST_URL])) ? (int)$_GET[POST_POST_URL] : 0; @@ -54,7 +54,7 @@ $posts_per_page = $bb_cfg['posts_per_page']; $select_ppp = ''; if ($userdata['session_admin']) { - if ($req_ppp = abs(intval(@$_REQUEST['ppp'])) and in_array($req_ppp, $bb_cfg['allowed_posts_per_page'])) { + if ($req_ppp = abs((int)(@$_REQUEST['ppp'])) and in_array($req_ppp, $bb_cfg['allowed_posts_per_page'])) { $posts_per_page = $req_ppp; } From 8d2c7b258b3663db3dea411c74e0e1a400d5fa84 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:00:57 +0300 Subject: [PATCH 18/32] 'array_push(...)' misused. (cherry picked from commit 897445b) --- library/includes/bbcode.php | 2 +- library/includes/template.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/includes/bbcode.php b/library/includes/bbcode.php index adda1a992..8ed6e7577 100644 --- a/library/includes/bbcode.php +++ b/library/includes/bbcode.php @@ -256,7 +256,7 @@ function strip_quotes($text) if ($stacksize == 0) { $newtext .= substr($text, $substr_pos, $pos - $substr_pos); } - array_push($stack, $pos); + $stack[] = $pos; } else { // pop off the latest opened tag if ($stacksize) { diff --git a/library/includes/template.php b/library/includes/template.php index bcde7748a..45395a134 100644 --- a/library/includes/template.php +++ b/library/includes/template.php @@ -907,7 +907,7 @@ class template break; case '(': - array_push($is_arg_stack, $i); + $is_arg_stack[] = $i; break; case 'is': From 4dcb1139607f79320801691af97072b6d2836141 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:01:15 +0300 Subject: [PATCH 19/32] 'file(...)' misused. (cherry picked from commit 9a96dc6) --- library/attach_mod/displaying.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/attach_mod/displaying.php b/library/attach_mod/displaying.php index 1b84c2a21..0a010d9f6 100644 --- a/library/attach_mod/displaying.php +++ b/library/attach_mod/displaying.php @@ -74,7 +74,7 @@ function init_display_template($template_var, $replacement, $filename = 'viewtop $filename_2 = $template->files[$template_var]; - $str = implode('', @file($filename_2)); + $str = file_get_contents($filename_2); if (empty($str)) { die("Template->loadfile(): File $filename_2 for handle $template_var is empty"); } @@ -91,7 +91,7 @@ function init_display_template($template_var, $replacement, $filename = 'viewtop die("Template->make_filename(): Error - file $complete_filename does not exist"); } - $content = implode('', file($complete_filename)); + $content = file_get_contents($complete_filename); if (empty($content)) { die('Template->loadfile(): File ' . $complete_filename . ' is empty'); } From 5dd290f2b2aae876a31ebb641521016be512cefa Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:01:29 +0300 Subject: [PATCH 20/32] '(mb_)substr(...)' used as index-based access. (cherry picked from commit e89f017) --- library/attach_mod/displaying.php | 2 +- .../attach_mod/includes/functions_attach.php | 40 ++++++++++--------- library/includes/classes/correct.php | 4 +- library/includes/smtp.php | 2 +- library/includes/template.php | 2 +- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/library/attach_mod/displaying.php b/library/attach_mod/displaying.php index 0a010d9f6..6d2b91f44 100644 --- a/library/attach_mod/displaying.php +++ b/library/attach_mod/displaying.php @@ -83,7 +83,7 @@ function init_display_template($template_var, $replacement, $filename = 'viewtop } $complete_filename = $filename; - if (substr($complete_filename, 0, 1) != '/') { + if ($complete_filename[0] != '/') { $complete_filename = $template->root . '/' . $complete_filename; } diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 5f0b371e0..54a71347b 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -49,7 +49,9 @@ function base64_pack($number) if ($number > 4096) { return; - } elseif ($number < $base) { + } + + if ($number < $base) { return $chars[$number]; } @@ -81,7 +83,7 @@ function base64_unpack($string) for ($i = 1; $i <= $length; $i++) { $pos = $length - $i; - $operand = strpos($chars, substr($string, $pos, 1)); + $operand = strpos($chars, $string[$pos]); $exponent = pow($base, $i - 1); $decValue = $operand * $exponent; $number += $decValue; @@ -129,11 +131,13 @@ function auth_unpack($auth_cache) $auth_len = 1; for ($pos = 0; $pos < strlen($auth_cache); $pos += $auth_len) { - $forum_auth = substr($auth_cache, $pos, 1); + $forum_auth = $auth_cache[$pos]; if ($forum_auth == $one_char_encoding) { $auth_len = 1; continue; - } elseif ($forum_auth == $two_char_encoding) { + } + + if ($forum_auth == $two_char_encoding) { $auth_len = 2; $pos--; continue; @@ -162,11 +166,13 @@ function is_forum_authed($auth_cache, $check_forum_id) $auth_len = 1; for ($pos = 0; $pos < strlen($auth_cache); $pos += $auth_len) { - $forum_auth = substr($auth_cache, $pos, 1); + $forum_auth = $auth_cache[$pos]; if ($forum_auth == $one_char_encoding) { $auth_len = 1; continue; - } elseif ($forum_auth == $two_char_encoding) { + } + + if ($forum_auth == $two_char_encoding) { $auth_len = 2; $pos--; continue; @@ -210,9 +216,9 @@ function attachment_exists($filename) if (!@file_exists(@amod_realpath($upload_dir . '/' . $filename))) { return false; - } else { - return true; } + + return true; } /** @@ -226,9 +232,9 @@ function thumbnail_exists($filename) if (!@file_exists(@amod_realpath($upload_dir . '/' . THUMB_DIR . '/t_' . $filename))) { return false; - } else { - return true; } + + return true; } /** @@ -412,9 +418,9 @@ function get_extension($filename) $extension = strtolower(trim($extension)); if (is_array($extension)) { return ''; - } else { - return $extension; } + + return $extension; } /** @@ -495,11 +501,9 @@ function _set_var(&$result, $var, $type, $multibyte = false) */ function get_var($var_name, $default, $multibyte = false) { - if ( - !isset($_REQUEST[$var_name]) || + if (!isset($_REQUEST[$var_name]) || (is_array($_REQUEST[$var_name]) && !is_array($default)) || - (is_array($default) && !is_array($_REQUEST[$var_name])) - ) { + (is_array($default) && !is_array($_REQUEST[$var_name]))) { return (is_array($default)) ? [] : $default; } @@ -544,9 +548,9 @@ function attach_mod_sql_escape($text) { if (function_exists('mysqli_real_escape_string')) { return DB()->escape_string($text); - } else { - return str_replace("'", "''", str_replace('\\', '\\\\', $text)); } + + return str_replace("'", "''", str_replace('\\', '\\\\', $text)); } /** diff --git a/library/includes/classes/correct.php b/library/includes/classes/correct.php index 14ceb602c..cd0c42150 100644 --- a/library/includes/classes/correct.php +++ b/library/includes/classes/correct.php @@ -2956,7 +2956,7 @@ class Text_LangCorrect */ #0a. английский --> русский: - if (substr($word, 1, 1) === '.' #оптимизация + if ($word[1] === '.' #оптимизация && preg_match('/^ ( ' . $this->en_similar_uc . '\. #первый инициал (?:' . $this->en_similar_uc . '\.)? #второй инициал (необязательно) ) #1 инициалы @@ -2973,7 +2973,7 @@ class Text_LangCorrect } #0b. русский --> английский: - if (substr($word, 2, 1) === '.' #оптимизация + if ($word[2] === '.' #оптимизация && preg_match('/^ ( ' . $this->ru_similar_uc . '\. #первый инициал (?:' . $this->ru_similar_uc . '\.)? #второй инициал (необязательно) ) #1 инициалы diff --git a/library/includes/smtp.php b/library/includes/smtp.php index 672fbbb5e..c138bca1e 100644 --- a/library/includes/smtp.php +++ b/library/includes/smtp.php @@ -32,7 +32,7 @@ define('SMTP_INCLUDED', 1); function server_parse($socket, $response, $line = __LINE__) { $server_response = ''; - while (substr($server_response, 3, 1) != ' ') { + while ($server_response[3] != ' ') { if (!($server_response = fgets($socket, 256))) { bb_die('Could not get mail server response codes'); } diff --git a/library/includes/template.php b/library/includes/template.php index 45395a134..eae67b601 100644 --- a/library/includes/template.php +++ b/library/includes/template.php @@ -173,7 +173,7 @@ class template $filename = $this->replace[$filename]; } // Check if it's an absolute or relative path. - if ((substr($filename, 0, 1) !== '/') && (substr($filename, 1, 1) !== ':')) { + if (($filename[0] !== '/') && ($filename[1] !== ':')) { return $this->root . '/' . $filename; } else { return $filename; From 8e5338e5d34ecce94a5676c19171ccf23d11a7b9 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:01:48 +0300 Subject: [PATCH 21/32] 'str(i)str(...)' could be replaced with 'str(i)pos(...)'. (cherry picked from commit b4d079f) --- admin/admin_user_search.php | 8 ++++---- dl.php | 2 +- library/attach_mod/includes/functions_attach.php | 2 +- library/attach_mod/includes/functions_delete.php | 6 +++--- library/includes/functions.php | 2 +- library/includes/init_bb.php | 2 +- library/includes/template.php | 2 +- login.php | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/admin/admin_user_search.php b/admin/admin_user_search.php index b8ef65f8b..1d8029885 100644 --- a/admin/admin_user_search.php +++ b/admin/admin_user_search.php @@ -271,7 +271,7 @@ if (!isset($_REQUEST['dosearch'])) { $username = preg_replace('/\*/', '%', trim(strip_tags(strtolower($username)))); - if (strstr($username, '%')) { + if (false !== strpos($username, '%')) { $op = 'LIKE'; } else { $op = '='; @@ -292,7 +292,7 @@ if (!isset($_REQUEST['dosearch'])) { $email = preg_replace('/\*/', '%', trim(strip_tags(strtolower($email)))); - if (strstr($email, '%')) { + if (false !== strpos($email, '%')) { $op = 'LIKE'; } else { $op = '='; @@ -577,7 +577,7 @@ if (!isset($_REQUEST['dosearch'])) { break; case 'equals': // looking for a - - if (strstr($postcount_value, '-')) { + if (false !== strpos($postcount_value, '-')) { $range = preg_split('/[-\s]+/', $postcount_value); $range_begin = (int)$range[0]; @@ -624,7 +624,7 @@ if (!isset($_REQUEST['dosearch'])) { $userfield_value = preg_replace('/\*/', '%', trim(strip_tags(strtolower($userfield_value)))); - if (strstr($userfield_value, '%')) { + if (false !== strpos($userfield_value, '%')) { $op = 'LIKE'; } else { $op = '='; diff --git a/dl.php b/dl.php index ab0e472e6..6e8223518 100644 --- a/dl.php +++ b/dl.php @@ -54,7 +54,7 @@ function send_file_to_browser($attachment, $upload_dir) // Correct the mime type - we force application/octet-stream for all files, except images // Please do not change this, it is a security precaution - if (!strstr($attachment['mimetype'], 'image')) { + if (false === strpos($attachment['mimetype'], 'image')) { $attachment['mimetype'] = 'application/octet-stream'; } diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 54a71347b..b6584432a 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -410,7 +410,7 @@ function attachment_sync_topic($topics) */ function get_extension($filename) { - if (!stristr($filename, '.')) { + if (false === stripos($filename, '.')) { return ''; } $extension = strrchr(strtolower($filename), '.'); diff --git a/library/attach_mod/includes/functions_delete.php b/library/attach_mod/includes/functions_delete.php index 20affee97..3e0badfa4 100644 --- a/library/attach_mod/includes/functions_delete.php +++ b/library/attach_mod/includes/functions_delete.php @@ -41,7 +41,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, $post_id_array = array(); if (!is_array($attach_id_array)) { - if (strstr($attach_id_array, ', ')) { + if (false !== strpos($attach_id_array, ', ')) { $attach_id_array = explode(', ', $attach_id_array); } elseif (strstr($attach_id_array, ',')) { $attach_id_array = explode(',', $attach_id_array); @@ -82,7 +82,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, return; } - if (strstr($post_id_array, ', ')) { + if (false !== strpos($post_id_array, ', ')) { $post_id_array = explode(', ', $post_id_array); } elseif (strstr($post_id_array, ',')) { $post_id_array = explode(',', $post_id_array); @@ -127,7 +127,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } if (!is_array($attach_id_array)) { - if (strstr($attach_id_array, ', ')) { + if (false !== strpos($attach_id_array, ', ')) { $attach_id_array = explode(', ', $attach_id_array); } elseif (strstr($attach_id_array, ',')) { $attach_id_array = explode(',', $attach_id_array); diff --git a/library/includes/functions.php b/library/includes/functions.php index 2e4b78697..2e1914d6e 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -1741,7 +1741,7 @@ function redirect($url) trigger_error("Headers already sent in $filename($linenum)", E_USER_ERROR); } - if (strstr(urldecode($url), "\n") || strstr(urldecode($url), "\r") || strstr(urldecode($url), ';url')) { + if (false !== strpos(urldecode($url), "\n") || false !== strpos(urldecode($url), "\r") || false !== strpos(urldecode($url), ';url')) { bb_die('Tried to redirect to potentially insecure url'); } diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index f3341898e..43a086c25 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -378,7 +378,7 @@ define('SELECT', 6); if (!empty($banned_user_agents)) { foreach ($banned_user_agents as $agent) { - if (strstr(USER_AGENT, $agent)) { + if (false !== strpos(USER_AGENT, $agent)) { $filename = 'Download files by using browser'; $output = '@'; header('Content-Type: text/plain'); diff --git a/library/includes/template.php b/library/includes/template.php index eae67b601..d7dc15839 100644 --- a/library/includes/template.php +++ b/library/includes/template.php @@ -393,7 +393,7 @@ class template */ public function assign_block_vars($blockname, $vararray) { - if (strstr($blockname, '.')) { + if (false !== strpos($blockname, '.')) { // Nested block. $blocks = explode('.', $blockname); $blockcount = count($blocks) - 1; diff --git a/login.php b/login.php index af077e1b3..f5222e9ca 100644 --- a/login.php +++ b/login.php @@ -48,7 +48,7 @@ $login_errors = array(); if (preg_match('/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si', $_SERVER['QUERY_STRING'], $matches)) { $redirect_url = $matches[1]; - if (!strstr($redirect_url, '?') && $first_amp = strpos($redirect_url, '&')) { + if (false === strpos($redirect_url, '?') && $first_amp = strpos($redirect_url, '&')) { $redirect_url[$first_amp] = '?'; } } elseif (!empty($_POST['redirect'])) { @@ -60,7 +60,7 @@ if (preg_match('/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si', $_SERVER['QUERY_STRING $redirect_url = str_replace('&admin=1', '', $redirect_url); $redirect_url = str_replace('?admin=1', '', $redirect_url); -if (!$redirect_url || strstr(urldecode($redirect_url), "\n") || strstr(urldecode($redirect_url), "\r") || strstr(urldecode($redirect_url), ';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"; } From 05442c42138b3395da748ed5e11876a859fb180e Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:01:59 +0300 Subject: [PATCH 22/32] 'stristr(...)/stripos(...)/strripos(...)' could be replaced with 'strstr(...)/strpos()/strrpos()'. (cherry picked from commit eba06c0) --- library/attach_mod/includes/functions_attach.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index b6584432a..cb9288af5 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -410,7 +410,7 @@ function attachment_sync_topic($topics) */ function get_extension($filename) { - if (false === stripos($filename, '.')) { + if (false === strstr($filename, '.')) { return ''; } $extension = strrchr(strtolower($filename), '.'); From 99c79f264b8fa8fe7f63a423eebd54bd234b51fd Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:04:13 +0300 Subject: [PATCH 23/32] Insecure 'uniqid(...)' usage (Insufficient Entropy Vulnerability). (cherry picked from commit 8d1a7d4) --- library/includes/classes/emailer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/includes/classes/emailer.php b/library/includes/classes/emailer.php index 966a07a40..91c80490f 100644 --- a/library/includes/classes/emailer.php +++ b/library/includes/classes/emailer.php @@ -198,7 +198,7 @@ class emailer // Build header $type = ($email_format == 'html') ? 'html' : 'plain'; - $this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $bb_cfg['board_email'] . "\n") . "Return-Path: " . $bb_cfg['board_email'] . "\nMessage-ID: <" . md5(uniqid(TIMENOW)) . "@" . $bb_cfg['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/$type; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', TIMENOW) . "\nX-Priority: 0\nX-MSMail-Priority: Normal\nX-Mailer: Microsoft Office Outlook, Build 11.0.5510\nX-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441\nX-Sender: " . $bb_cfg['board_email'] . "\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '') . (($bcc != '') ? "Bcc: $bcc\n" : ''); + $this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $bb_cfg['board_email'] . "\n") . "Return-Path: " . $bb_cfg['board_email'] . "\nMessage-ID: <" . md5(uniqid(TIMENOW, true)) . "@" . $bb_cfg['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/$type; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', TIMENOW) . "\nX-Priority: 0\nX-MSMail-Priority: Normal\nX-Mailer: Microsoft Office Outlook, Build 11.0.5510\nX-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441\nX-Sender: " . $bb_cfg['board_email'] . "\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '') . (($bcc != '') ? "Bcc: $bcc\n" : ''); // Send message if ($this->use_smtp) { From 5d6039d1c567d7a46c37e06382f4cfaffe6113da Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:05:10 +0300 Subject: [PATCH 24/32] Parameter could be declared as array. (cherry picked from commit 07c6fd4) --- library/includes/functions.php | 8 ++++---- library/includes/functions_upload.php | 6 ++++-- library/includes/sessions.php | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/library/includes/functions.php b/library/includes/functions.php index 2e1914d6e..708941c8d 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -348,7 +348,7 @@ function setbit(&$int, $bit_num, $on) forum auth levels, this will prevent the auth function having to do its own lookup */ -function auth($type, $forum_id, $ug_data, $f_access = array(), $group_perm = UG_PERM_BOTH) +function auth($type, $forum_id, $ug_data, array $f_access = array(), $group_perm = UG_PERM_BOTH) { global $lang, $bf, $datastore; @@ -1973,7 +1973,7 @@ class log_action } } - public function mod($type_name, $args = array()) + public function mod($type_name, array $args = array()) { global $userdata; @@ -2021,7 +2021,7 @@ class log_action DB()->query("INSERT INTO " . BB_LOG . " $sql_args"); } - public function admin($type_name, $args = array()) + public function admin($type_name, array $args = array()) { $this->mod($type_name, $args); } @@ -2255,7 +2255,7 @@ function log_sphinx_error($err_type, $err_msg, $query = '') } } -function get_title_match_topics($title_match_sql, $forum_ids = array()) +function get_title_match_topics($title_match_sql, array $forum_ids = array()) { global $bb_cfg, $sphinx, $userdata, $title_match, $lang; diff --git a/library/includes/functions_upload.php b/library/includes/functions_upload.php index e15af4044..cebdaee8a 100644 --- a/library/includes/functions_upload.php +++ b/library/includes/functions_upload.php @@ -129,13 +129,15 @@ class upload_common return true; } - public function store($mode = '', $params = array()) + public function store($mode = '', array $params = array()) { if ($mode == 'avatar') { delete_avatar($params['user_id'], $params['avatar_ext_id']); $file_path = get_avatar_path($params['user_id'], $this->file_ext_id); return $this->_move($file_path); - } elseif ($mode == 'attach') { + } + + if ($mode == 'attach') { $file_path = get_attach_path($params['topic_id']); return $this->_move($file_path); } else { diff --git a/library/includes/sessions.php b/library/includes/sessions.php index 077bc1a5c..2815b7877 100644 --- a/library/includes/sessions.php +++ b/library/includes/sessions.php @@ -103,7 +103,7 @@ class user_common /** * Start session (restore existent session or create new) */ - public function session_start($cfg = array()) + public function session_start(array $cfg = array()) { global $bb_cfg; From 335195365f81aa3d9ca7e04b4c4568ab9ae8ed12 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:05:42 +0300 Subject: [PATCH 25/32] Class property initialization flaws. (cherry picked from commit cf5285f) --- ajax.php | 2 +- library/includes/bbcode.php | 4 ++-- library/includes/cache/apc.php | 2 +- library/includes/cache/common.php | 2 +- library/includes/cache/file.php | 4 ++-- library/includes/cache/memcache.php | 6 +++--- library/includes/cache/redis.php | 6 +++--- library/includes/cache/sqlite.php | 6 +++--- library/includes/cache/xcache.php | 2 +- library/includes/core/mysql.php | 8 ++++---- library/includes/datastore/apc.php | 2 +- library/includes/datastore/common.php | 2 +- library/includes/datastore/file.php | 4 ++-- library/includes/datastore/memcache.php | 6 +++--- library/includes/datastore/redis.php | 6 +++--- library/includes/datastore/sqlite.php | 4 ++-- library/includes/datastore/xcache.php | 2 +- library/includes/functions.php | 2 +- library/includes/sessions.php | 2 +- 19 files changed, 36 insertions(+), 36 deletions(-) diff --git a/ajax.php b/ajax.php index 2f14061d6..8bf17a936 100644 --- a/ajax.php +++ b/ajax.php @@ -129,7 +129,7 @@ class ajax_common 'index_data' => array('guest'), ); - public $action = null; + public $action; /** * Constructor diff --git a/library/includes/bbcode.php b/library/includes/bbcode.php index 8ed6e7577..eae6514fb 100644 --- a/library/includes/bbcode.php +++ b/library/includes/bbcode.php @@ -406,8 +406,8 @@ function add_search_words($post_id, $post_message, $topic_title = '', $only_retu class bbcode { public $tpl = array(); // шаблоны для замены тегов - public $smilies = null; // смайлы - public $found_spam = null; // найденные спам "слова" + public $smilies; // смайлы + public $found_spam; // найденные спам "слова" public $del_words = array(); // см. get_words_rate() public $tidy_cfg = array( 'drop-empty-paras' => false, diff --git a/library/includes/cache/apc.php b/library/includes/cache/apc.php index da475beb3..2fa961be7 100644 --- a/library/includes/cache/apc.php +++ b/library/includes/cache/apc.php @@ -31,7 +31,7 @@ class cache_apc extends cache_common { public $used = true; public $engine = 'APC'; - public $prefix = null; + public $prefix; public function __construct($prefix = null) { diff --git a/library/includes/cache/common.php b/library/includes/cache/common.php index 42ce97b44..3732475a4 100644 --- a/library/includes/cache/common.php +++ b/library/includes/cache/common.php @@ -67,7 +67,7 @@ class cache_common public $dbg = array(); public $dbg_id = 0; public $dbg_enabled = false; - public $cur_query = null; + public $cur_query; public function debug($mode, $cur_query = null) { diff --git a/library/includes/cache/file.php b/library/includes/cache/file.php index d1a4c559e..cccaecfaa 100644 --- a/library/includes/cache/file.php +++ b/library/includes/cache/file.php @@ -31,8 +31,8 @@ class cache_file extends cache_common { public $used = true; public $engine = 'Filecache'; - public $dir = null; - public $prefix = null; + public $dir; + public $prefix; public function __construct($dir, $prefix = null) { diff --git a/library/includes/cache/memcache.php b/library/includes/cache/memcache.php index 6a3dc3269..92314cb12 100644 --- a/library/includes/cache/memcache.php +++ b/library/includes/cache/memcache.php @@ -31,9 +31,9 @@ class cache_memcache extends cache_common { public $used = true; public $engine = 'Memcache'; - public $cfg = null; - public $prefix = null; - public $memcache = null; + public $cfg; + public $prefix; + public $memcache; public $connected = false; public function __construct($cfg, $prefix = null) diff --git a/library/includes/cache/redis.php b/library/includes/cache/redis.php index 64598fabb..cb002c33d 100644 --- a/library/includes/cache/redis.php +++ b/library/includes/cache/redis.php @@ -31,9 +31,9 @@ class cache_redis extends cache_common { public $used = true; public $engine = 'Redis'; - public $cfg = null; - public $redis = null; - public $prefix = null; + public $cfg; + public $redis; + public $prefix; public $connected = false; public function __construct($cfg, $prefix = null) diff --git a/library/includes/cache/sqlite.php b/library/includes/cache/sqlite.php index e59f11bef..8304e4c86 100644 --- a/library/includes/cache/sqlite.php +++ b/library/includes/cache/sqlite.php @@ -30,8 +30,8 @@ if (!defined('BB_ROOT')) { class cache_sqlite extends cache_common { public $used = true; - public $db = null; - public $prefix = null; + public $db; + public $prefix; public $cfg = array( 'db_file_path' => '/path/to/cache.db.sqlite', 'table_name' => 'cache', @@ -137,7 +137,7 @@ class sqlite_common extends cache_common 'shard_val' => 0, # для string - кол. начальных символов, для int - делитель (будет использован остаток от деления) ); public $engine = 'SQLite'; - public $dbh = null; + public $dbh; public $connected = false; public $shard_val = false; diff --git a/library/includes/cache/xcache.php b/library/includes/cache/xcache.php index f762c43ac..0f201d154 100644 --- a/library/includes/cache/xcache.php +++ b/library/includes/cache/xcache.php @@ -31,7 +31,7 @@ class cache_xcache extends cache_common { public $used = true; public $engine = 'XCache'; - public $prefix = null; + public $prefix; public function __construct($prefix = null) { diff --git a/library/includes/core/mysql.php b/library/includes/core/mysql.php index ad5107b03..bdf647789 100644 --- a/library/includes/core/mysql.php +++ b/library/includes/core/mysql.php @@ -34,10 +34,10 @@ class sql_db { public $cfg = []; public $cfg_keys = ['dbhost', 'dbname', 'dbuser', 'dbpasswd', 'charset', 'persist']; - private $link = null; - public $result = null; + private $link; + public $result; public $db_server = ''; - public $selected_db = null; + public $selected_db; public $inited = false; public $locked = false; @@ -53,7 +53,7 @@ class sql_db public $dbg = []; public $dbg_id = 0; public $dbg_enabled = false; - public $cur_query = null; + public $cur_query; public $do_explain = false; public $explain_hold = ''; diff --git a/library/includes/datastore/apc.php b/library/includes/datastore/apc.php index b4053b59e..4ee1e0171 100644 --- a/library/includes/datastore/apc.php +++ b/library/includes/datastore/apc.php @@ -30,7 +30,7 @@ if (!defined('BB_ROOT')) { class datastore_apc extends datastore_common { public $engine = 'APC'; - public $prefix = null; + public $prefix; public function __construct($prefix = null) { diff --git a/library/includes/datastore/common.php b/library/includes/datastore/common.php index 8626718fc..b2a8111b0 100644 --- a/library/includes/datastore/common.php +++ b/library/includes/datastore/common.php @@ -149,7 +149,7 @@ class datastore_common public $dbg = array(); public $dbg_id = 0; public $dbg_enabled = false; - public $cur_query = null; + public $cur_query; public function debug($mode, $cur_query = null) { diff --git a/library/includes/datastore/file.php b/library/includes/datastore/file.php index 9941383f7..b8905b4e2 100644 --- a/library/includes/datastore/file.php +++ b/library/includes/datastore/file.php @@ -29,8 +29,8 @@ if (!defined('BB_ROOT')) { class datastore_file extends datastore_common { - public $dir = null; - public $prefix = null; + public $dir; + public $prefix; public $engine = 'Filecache'; public function __construct($dir, $prefix = null) diff --git a/library/includes/datastore/memcache.php b/library/includes/datastore/memcache.php index b31e543f4..eba2fd6b9 100644 --- a/library/includes/datastore/memcache.php +++ b/library/includes/datastore/memcache.php @@ -29,11 +29,11 @@ if (!defined('BB_ROOT')) { class datastore_memcache extends datastore_common { - public $cfg = null; - public $memcache = null; + public $cfg; + public $memcache; public $connected = false; public $engine = 'Memcache'; - public $prefix = null; + public $prefix; public function __construct($cfg, $prefix = null) { diff --git a/library/includes/datastore/redis.php b/library/includes/datastore/redis.php index e218bf67f..b3c5256eb 100644 --- a/library/includes/datastore/redis.php +++ b/library/includes/datastore/redis.php @@ -29,9 +29,9 @@ if (!defined('BB_ROOT')) { class datastore_redis extends datastore_common { - public $cfg = null; - public $redis = null; - public $prefix = null; + public $cfg; + public $redis; + public $prefix; public $connected = false; public $engine = 'Redis'; diff --git a/library/includes/datastore/sqlite.php b/library/includes/datastore/sqlite.php index 33526fe6d..06fd90d59 100644 --- a/library/includes/datastore/sqlite.php +++ b/library/includes/datastore/sqlite.php @@ -30,8 +30,8 @@ if (!defined('BB_ROOT')) { class datastore_sqlite extends datastore_common { public $engine = 'SQLite'; - public $db = null; - public $prefix = null; + public $db; + public $prefix; public $cfg = array( 'db_file_path' => '/path/to/datastore.db.sqlite', 'table_name' => 'datastore', diff --git a/library/includes/datastore/xcache.php b/library/includes/datastore/xcache.php index a0ccb770d..fdb688eae 100644 --- a/library/includes/datastore/xcache.php +++ b/library/includes/datastore/xcache.php @@ -29,7 +29,7 @@ if (!defined('BB_ROOT')) { class datastore_xcache extends datastore_common { - public $prefix = null; + public $prefix; public $engine = 'XCache'; public function __construct($prefix = null) diff --git a/library/includes/functions.php b/library/includes/functions.php index 708941c8d..e780be376 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -676,7 +676,7 @@ class html_common { public $options = ''; public $attr = array(); - public $cur_attr = null; + public $cur_attr; public $max_length = HTML_SELECT_MAX_LENGTH; public $selected = array(); diff --git a/library/includes/sessions.php b/library/includes/sessions.php index 2815b7877..bc3943b29 100644 --- a/library/includes/sessions.php +++ b/library/includes/sessions.php @@ -85,7 +85,7 @@ class user_common /** * Shortcuts */ - public $id = null; + public $id; /** * Misc From a1ca9a0466ce34d295d09008bd05a0db755cad59 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:06:39 +0300 Subject: [PATCH 26/32] Callable name case mismatched in a call. (cherry picked from commit 43f3e91) --- library/includes/functions.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/library/includes/functions.php b/library/includes/functions.php index e780be376..754c093ff 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2235,9 +2235,9 @@ function init_sphinx() if (!isset($sphinx)) { $sphinx = \Sphinx\SphinxClient::create(); - $sphinx->SetConnectTimeout(5); - $sphinx->SetRankingMode($sphinx::SPH_RANK_NONE); - $sphinx->SetMatchMode($sphinx::SPH_MATCH_BOOLEAN); + $sphinx->setConnectTimeout(5); + $sphinx->setRankingMode($sphinx::SPH_RANK_NONE); + $sphinx->setMatchMode($sphinx::SPH_MATCH_BOOLEAN); } return $sphinx; @@ -2270,24 +2270,24 @@ function get_title_match_topics($title_match_sql, array $forum_ids = array()) $where = ($title_match) ? 'topics' : 'posts'; - $sphinx->SetServer($bb_cfg['sphinx_topic_titles_host'], $bb_cfg['sphinx_topic_titles_port']); + $sphinx->setServer($bb_cfg['sphinx_topic_titles_host'], $bb_cfg['sphinx_topic_titles_port']); if ($forum_ids) { - $sphinx->SetFilter('forum_id', $forum_ids, false); + $sphinx->setFilter('forum_id', $forum_ids, false); } if (preg_match('#^"[^"]+"$#u', $title_match_sql)) { - $sphinx->SetMatchMode($sphinx::SPH_MATCH_PHRASE); + $sphinx->setMatchMode($sphinx::SPH_MATCH_PHRASE); } - if ($result = $sphinx->Query($title_match_sql, $where, $userdata['username'] . ' (' . CLIENT_IP . ')')) { + if ($result = $sphinx->query($title_match_sql, $where, $userdata['username'] . ' (' . CLIENT_IP . ')')) { if (!empty($result['matches'])) { $where_ids = array_keys($result['matches']); } - } elseif ($error = $sphinx->GetLastError()) { + } elseif ($error = $sphinx->getLastError()) { if (strpos($error, 'errno=110')) { bb_die($lang['SEARCH_ERROR']); } log_sphinx_error('ERR', $error, $title_match_sql); } - if ($warning = $sphinx->GetLastWarning()) { + if ($warning = $sphinx->getLastWarning()) { log_sphinx_error('wrn', $warning, $title_match_sql); } } elseif ($bb_cfg['search_engine_type'] == 'mysql') { From 748476b8025ef131be91b2c02fe85c21e453276c Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:07:02 +0300 Subject: [PATCH 27/32] Prefixed increment/decrement equivalent. (cherry picked from commit a4965bf) --- library/includes/classes/sitemap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/includes/classes/sitemap.php b/library/includes/classes/sitemap.php index 5290117aa..4c280a287 100644 --- a/library/includes/classes/sitemap.php +++ b/library/includes/classes/sitemap.php @@ -123,7 +123,7 @@ class sitemap $this->priority = $this->topic_priority; if ($page) { - $page = $page - 1; + --$page; $page = $page * 40000; $this->limit = " LIMIT {$page},40000"; } else { From 1daec3c319d8c94ead40b8e54a43902a4d5e161b Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:07:16 +0300 Subject: [PATCH 28/32] Short syntax for applied operation. (cherry picked from commit a391e21) --- admin/admin_forums.php | 4 ++-- library/includes/classes/correct.php | 2 +- library/includes/classes/reflection.php | 2 +- library/includes/classes/sitemap.php | 2 +- library/includes/functions.php | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/admin/admin_forums.php b/admin/admin_forums.php index eb452c8e3..8c710c553 100644 --- a/admin/admin_forums.php +++ b/admin/admin_forums.php @@ -960,7 +960,7 @@ function get_prev_root_forum_id($forums, $curr_forum_order) if (isset($forums[$i]) && !$forums[$i]['forum_parent']) { return $forums[$i]['forum_id']; } - $i = $i - 10; + $i -= 10; } return false; @@ -975,7 +975,7 @@ function get_next_root_forum_id($forums, $curr_forum_order) if (isset($forums[$i]) && !$forums[$i]['forum_parent']) { return $forums[$i]['forum_id']; } - $i = $i + 10; + $i += 10; } return false; diff --git a/library/includes/classes/correct.php b/library/includes/classes/correct.php index cd0c42150..4a22f710a 100644 --- a/library/includes/classes/correct.php +++ b/library/includes/classes/correct.php @@ -3175,7 +3175,7 @@ class Text_LangCorrect $ss = ' ' . $ss; } #beginning of word elseif ($pos === $limit - 1) { - $ss = $ss . ' '; + $ss .= ' '; } #ending of word if (array_key_exists($ss, $this->bigrams)) { return true; diff --git a/library/includes/classes/reflection.php b/library/includes/classes/reflection.php index 13e11d4f5..364c87ec6 100644 --- a/library/includes/classes/reflection.php +++ b/library/includes/classes/reflection.php @@ -170,7 +170,7 @@ class ReflectionTypeHint // Dummy frame before call_user_func*() frames. if (!isset($t['file']) && $next) { $t['over_function'] = $trace[$i + 1]['function']; - $t = $t + $trace[$i + 1]; + $t += $trace[$i + 1]; $trace[$i + 1] = null; // skip call_user_func on next iteration } diff --git a/library/includes/classes/sitemap.php b/library/includes/classes/sitemap.php index 4c280a287..505e45f33 100644 --- a/library/includes/classes/sitemap.php +++ b/library/includes/classes/sitemap.php @@ -124,7 +124,7 @@ class sitemap if ($page) { --$page; - $page = $page * 40000; + $page *= 40000; $this->limit = " LIMIT {$page},40000"; } else { if ($this->limit < 1) { diff --git a/library/includes/functions.php b/library/includes/functions.php index 754c093ff..06737cd8c 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -843,7 +843,7 @@ function declension($int, $expressions, $format = '%1$s %2$s') if ($count >= 5 && $count <= 20) { $result = $expressions['2']; } else { - $count = $count % 10; + $count %= 10; if ($count == 1) { $result = $expressions['0']; } elseif ($count >= 2 && $count <= 4) { @@ -901,12 +901,12 @@ function humn_size($size, $rounder = null, $min = null, $space = ' ') $rnd = $rounders[0]; if ($min == 'KB' && $size < 1024) { - $size = $size / 1024; + $size /= 1024; $ext = 'KB'; $rounder = 1; } else { for ($i = 1, $cnt = count($sizes); ($i < $cnt && $size >= 1024); $i++) { - $size = $size / 1024; + $size /= 1024; $ext = $sizes[$i]; $rnd = $rounders[$i]; } From 4e021d06d40d36b286104f500e49ad76216d313b Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:07:26 +0300 Subject: [PATCH 29/32] Static methods invocation via '->'. (cherry picked from commit da1e5a5) --- library/includes/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/includes/bbcode.php b/library/includes/bbcode.php index eae6514fb..117de8e12 100644 --- a/library/includes/bbcode.php +++ b/library/includes/bbcode.php @@ -524,7 +524,7 @@ class bbcode global $bb_cfg; $text = " $text "; - $text = $this->clean_up($text); + $text = static::clean_up($text); $text = $this->spam_filter($text); // Tag parse From 32ca1d66fcb059ab09e9ca96007ce023ea74f747 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:11:11 +0300 Subject: [PATCH 30/32] Unnecessary semicolon. (cherry picked from commit fe79d6c) --- library/language/en/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/language/en/main.php b/library/language/en/main.php index 35920cfd1..609897008 100644 --- a/library/language/en/main.php +++ b/library/language/en/main.php @@ -2422,7 +2422,7 @@ $lang['REPAIR_CRON'] = 'Repair Cron'; $lang['CRON_EDIT_HEAD_EDIT'] = 'Edit job'; $lang['CRON_EDIT_HEAD_ADD'] = 'Add job'; -$lang['CRON_SCRIPT_EXPL'] = 'name of the script from "includes/cron/jobs/"';; +$lang['CRON_SCRIPT_EXPL'] = 'name of the script from "includes/cron/jobs/"'; $lang['SCHEDULE'] = array( 'select' => '» Select start', 'hourly' => 'hourly', From 56540c893aee33469b31575ba574e55862b712b8 Mon Sep 17 00:00:00 2001 From: Vasily Komrakov Date: Sun, 7 May 2017 20:59:35 +0300 Subject: [PATCH 31/32] Change for with count. --- admin/admin_attachments.php | 6 ++-- admin/admin_disallow.php | 2 +- admin/admin_extensions.php | 18 ++++++------ admin/admin_forumauth.php | 12 ++++---- admin/admin_forumauth_list.php | 26 ++++++++--------- admin/admin_smilies.php | 14 +++++----- admin/admin_user_ban.php | 28 +++++++++---------- admin/admin_user_search.php | 2 +- admin/index.php | 8 +++--- .../attach_mod/includes/functions_attach.php | 2 +- .../attach_mod/includes/functions_delete.php | 2 +- .../attach_mod/includes/functions_selects.php | 14 +++++----- library/includes/functions.php | 2 +- library/includes/ucp/topic_watch.php | 2 +- memberlist.php | 2 +- privmsg.php | 6 ++-- 16 files changed, 73 insertions(+), 73 deletions(-) diff --git a/admin/admin_attachments.php b/admin/admin_attachments.php index fc77f7ab6..188657c60 100644 --- a/admin/admin_attachments.php +++ b/admin/admin_attachments.php @@ -288,7 +288,7 @@ if ($mode == 'cats') { $row = DB()->sql_fetchrowset($result); DB()->sql_freeresult($result); - for ($i = 0; $i < count($row); $i++) { + for ($i = 0, $iMax = count($row); $i < $iMax; $i++) { if ($row[$i]['cat_id'] == IMAGE_CAT) { $s_assigned_group_images[] = $row[$i]['group_name']; } @@ -399,7 +399,7 @@ if ($submit && $mode == 'quota') { $allowed_list = array(); - for ($i = 0; $i < count($quota_change_list); $i++) { + for ($i = 0, $iMax = count($quota_change_list); $i < $iMax; $i++) { $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : (($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i]); $sql = 'UPDATE ' . BB_QUOTA_LIMITS . " @@ -504,7 +504,7 @@ if ($mode == 'quota') { $rows = DB()->sql_fetchrowset($result); DB()->sql_freeresult($result); - for ($i = 0; $i < count($rows); $i++) { + for ($i = 0, $iMax = count($rows); $i < $iMax; $i++) { $size_format = ($rows[$i]['quota_limit'] >= 1048576) ? 'mb' : (($rows[$i]['quota_limit'] >= 1024) ? 'kb' : 'b'); if ($rows[$i]['quota_limit'] >= 1048576) { diff --git a/admin/admin_disallow.php b/admin/admin_disallow.php index 36695ec6c..c429e0265 100644 --- a/admin/admin_disallow.php +++ b/admin/admin_disallow.php @@ -87,7 +87,7 @@ $disallow_select = ''; - for ($j = 0; $j < count($simple_auth_types); $j++) { + for ($j = 0, $jMax = count($simple_auth_types); $j < $iMax; $j++) { $selected = ($matched_type == $j) ? ' selected="selected"' : ''; $simple_auth .= ''; } @@ -207,10 +207,10 @@ if (empty($forum_id)) { // Output values of individual // fields // - for ($j = 0; $j < count($forum_auth_fields); $j++) { + for ($j = 0, $jMax = count($forum_auth_fields); $j < $iMax; $j++) { $custom_auth[$j] = ' '; - for ($k = 0; $k < count($forum_auth_levels); $k++) { + for ($k = 0, $kMax = count($forum_auth_levels); $k < $iMax; $k++) { $selected = (!empty($forum_rows) && $forum_rows[0][$forum_auth_fields[$j]] == $forum_auth_const[$k]) ? ' selected="selected"' : ''; $custom_auth[$j] .= ''; } diff --git a/admin/admin_smilies.php b/admin/admin_smilies.php index d95d93bc6..c84c83860 100644 --- a/admin/admin_smilies.php +++ b/admin/admin_smilies.php @@ -79,7 +79,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { $cur_smilies = DB()->sql_fetchrowset($result); - for ($i = 0; $i < count($cur_smilies); $i++) { + for ($i = 0, $iMax = count($cur_smilies); $i < $iMax; $i++) { $k = $cur_smilies[$i]['code']; $smiles[$k] = 1; } @@ -91,10 +91,10 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { bb_die('Could not read smiley pak file'); } - for ($i = 0; $i < count($fcontents); $i++) { + for ($i = 0, $iMax = count($fcontents); $i < $iMax; $i++) { $smile_data = explode($delimeter, trim(addslashes($fcontents[$i]))); - for ($j = 2; $j < count($smile_data); $j++) { + for ($j = 2, $jMax = count($smile_data); $j < $iMax; $j++) { // Replace > and < with the proper html_entities for matching $smile_data[$j] = str_replace('<', '<', $smile_data[$j]); $smile_data[$j] = str_replace('>', '>', $smile_data[$j]); @@ -156,7 +156,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { $resultset = DB()->sql_fetchrowset($result); $smile_pak = ''; - for ($i = 0; $i < count($resultset); $i++) { + for ($i = 0, $iMax = count($resultset); $i < $iMax; $i++) { $smile_pak .= $resultset[$i]['smile_url'] . $delimeter; $smile_pak .= $resultset[$i]['emoticon'] . $delimeter; $smile_pak .= $resultset[$i]['code'] . "\n"; @@ -173,7 +173,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { bb_die(sprintf($lang['EXPORT_SMILES'], '', '') . '

' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', '') . '

' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); } elseif (isset($_POST['add']) || isset($_GET['add'])) { $filename_list = ''; - for ($i = 0; $i < count($smiley_images); $i++) { + for ($i = 0, $iMax = count($smiley_images); $i < $iMax; $i++) { $filename_list .= ''; } @@ -215,7 +215,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { $smile_data = DB()->sql_fetchrow($result); $filename_list = ''; - for ($i = 0; $i < count($smiley_images); $i++) { + for ($i = 0, $iMax = count($smiley_images); $i < $iMax; $i++) { if ($smiley_images[$i] == $smile_data['smile_url']) { $smiley_selected = 'selected="selected"'; $smiley_edit_img = $smiley_images[$i]; @@ -314,7 +314,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { )); // Loop throuh the rows of smilies setting block vars for the template - for ($i = 0; $i < count($smilies); $i++) { + for ($i = 0, $iMax = count($smilies); $i < $iMax; $i++) { // Replace htmlentites for < and > with actual character $smilies[$i]['code'] = str_replace('<', '<', $smilies[$i]['code']); $smilies[$i]['code'] = str_replace('>', '>', $smilies[$i]['code']); diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php index 0e3693e65..ef195c01f 100644 --- a/admin/admin_user_ban.php +++ b/admin/admin_user_ban.php @@ -49,7 +49,7 @@ if (isset($_POST['submit'])) { if (isset($_POST['ban_ip'])) { $ip_list_temp = explode(',', $_POST['ban_ip']); - for ($i = 0; $i < count($ip_list_temp); $i++) { + for ($i = 0, $iMax = count($ip_list_temp); $i < $iMax; $i++) { if (preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})[ ]*\-[ ]*([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/', trim($ip_list_temp[$i]), $ip_range_explode)) { $ip_1_counter = $ip_range_explode[1]; $ip_1_end = $ip_range_explode[5]; @@ -100,7 +100,7 @@ if (isset($_POST['submit'])) { } elseif (preg_match('/^([\w\-_]\.?){2,}$/is', trim($ip_list_temp[$i]))) { $ip = gethostbynamel(trim($ip_list_temp[$i])); - for ($j = 0; $j < count($ip); $j++) { + for ($j = 0, $jMax = count($ip); $j < $iMax; $j++) { if (!empty($ip[$j])) { $ip_list[] = encode_ip($ip[$j]); } @@ -115,7 +115,7 @@ if (isset($_POST['submit'])) { if (isset($_POST['ban_email'])) { $email_list_temp = explode(',', $_POST['ban_email']); - for ($i = 0; $i < count($email_list_temp); $i++) { + for ($i = 0, $iMax = count($email_list_temp); $i < $iMax; $i++) { 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]); } @@ -131,9 +131,9 @@ if (isset($_POST['submit'])) { DB()->sql_freeresult($result); $kill_session_sql = ''; - for ($i = 0; $i < count($user_list); $i++) { + for ($i = 0, $iMax = count($user_list); $i < $iMax; $i++) { $in_banlist = false; - for ($j = 0; $j < count($current_banlist); $j++) { + for ($j = 0, $jMax = count($current_banlist); $j < $iMax; $j++) { if ($user_list[$i] == $current_banlist[$j]['ban_userid']) { $in_banlist = true; } @@ -149,9 +149,9 @@ if (isset($_POST['submit'])) { } } - for ($i = 0; $i < count($ip_list); $i++) { + for ($i = 0, $iMax = count($ip_list); $i < $iMax; $i++) { $in_banlist = false; - for ($j = 0; $j < count($current_banlist); $j++) { + for ($j = 0, $jMax = count($current_banlist); $j < $iMax; $j++) { if ($ip_list[$i] == $current_banlist[$j]['ban_ip']) { $in_banlist = true; } @@ -181,9 +181,9 @@ if (isset($_POST['submit'])) { } } - for ($i = 0; $i < count($email_list); $i++) { + for ($i = 0, $iMax = count($email_list); $i < $iMax; $i++) { $in_banlist = false; - for ($j = 0; $j < count($current_banlist); $j++) { + for ($j = 0, $jMax = count($current_banlist); $j < $iMax; $j++) { if ($email_list[$i] == $current_banlist[$j]['ban_email']) { $in_banlist = true; } @@ -202,7 +202,7 @@ if (isset($_POST['submit'])) { if (isset($_POST['unban_user'])) { $user_list = $_POST['unban_user']; - for ($i = 0; $i < count($user_list); $i++) { + for ($i = 0, $iMax = count($user_list); $i < $iMax; $i++) { if ($user_list[$i] != -1) { $where_sql .= (($where_sql != '') ? ', ' : '') . (int)$user_list[$i]; } @@ -212,7 +212,7 @@ if (isset($_POST['submit'])) { if (isset($_POST['unban_ip'])) { $ip_list = $_POST['unban_ip']; - for ($i = 0; $i < count($ip_list); $i++) { + for ($i = 0, $iMax = count($ip_list); $i < $iMax; $i++) { if ($ip_list[$i] != -1) { $where_sql .= (($where_sql != '') ? ', ' : '') . DB()->escape($ip_list[$i]); } @@ -222,7 +222,7 @@ if (isset($_POST['submit'])) { if (isset($_POST['unban_email'])) { $email_list = $_POST['unban_email']; - for ($i = 0; $i < count($email_list); $i++) { + for ($i = 0, $iMax = count($email_list); $i < $iMax; $i++) { if ($email_list[$i] != -1) { $where_sql .= (($where_sql != '') ? ', ' : '') . DB()->escape($email_list[$i]); } @@ -260,7 +260,7 @@ if (isset($_POST['submit'])) { DB()->sql_freeresult($result); $select_userlist = ''; - for ($i = 0; $i < count($user_list); $i++) { + for ($i = 0, $iMax = count($user_list); $i < $iMax; $i++) { $select_userlist .= ''; $userban_count++; } @@ -282,7 +282,7 @@ if (isset($_POST['submit'])) { $select_iplist = ''; $select_emaillist = ''; - for ($i = 0; $i < count($banlist); $i++) { + for ($i = 0, $iMax = count($banlist); $i < $iMax; $i++) { $ban_id = $banlist[$i]['ban_id']; if (!empty($banlist[$i]['ban_ip'])) { diff --git a/admin/admin_user_search.php b/admin/admin_user_search.php index 1d8029885..a5b651f06 100644 --- a/admin/admin_user_search.php +++ b/admin/admin_user_search.php @@ -970,7 +970,7 @@ if (!isset($_REQUEST['dosearch'])) { $banned[$row['user_id']] = true; } - for ($i = 0; $i < count($rowset); $i++) { + for ($i = 0, $iMax = count($rowset); $i < $iMax; $i++) { $row_class = !($i % 2) ? 'row1' : 'row2'; $template->assign_block_vars('userrow', array( diff --git a/admin/index.php b/admin/index.php index 96c3c4324..b356f4b6f 100644 --- a/admin/index.php +++ b/admin/index.php @@ -130,7 +130,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $tabledata_ary = DB()->sql_fetchrowset($result); $dbsize = 0; - for ($i = 0; $i < count($tabledata_ary); $i++) { + for ($i = 0, $iMax = count($tabledata_ary); $i < $iMax; $i++) { if (@$tabledata_ary[$i]['Type'] != 'MRG_MYISAM') { $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length']; } @@ -192,7 +192,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { if (count($onlinerow_reg)) { $registered_users = $hidden_users = 0; - for ($i = 0, $cnt = count($onlinerow_reg); $i < $cnt; $i++) { + for ($i = 0, $iMax = count($onlinerow_reg); $i < $iMax; $i++) { if (!in_array($onlinerow_reg[$i]['user_id'], $reg_userid_ary)) { $reg_userid_ary[] = $onlinerow_reg[$i]['user_id']; @@ -226,7 +226,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { if (count($onlinerow_guest)) { $guest_users = 0; - for ($i = 0; $i < count($onlinerow_guest); $i++) { + for ($i = 0, $iMax = count($onlinerow_guest); $i < $iMax; $i++) { $guest_userip_ary[] = $onlinerow_guest[$i]['session_ip']; $guest_users++; @@ -263,7 +263,7 @@ print_page('index.tpl', 'admin'); // Functions function inarray($needle, $haystack) { - for ($i = 0; $i < count($haystack); $i++) { + for ($i = 0, $iMax = count($haystack); $i < $iMax; $i++) { if ($haystack[$i] == $needle) { return true; } diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index cb9288af5..1ebc808ce 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -103,7 +103,7 @@ function auth_pack($auth_array) $one_char = $two_char = false; $auth_cache = ''; - for ($i = 0; $i < count($auth_array); $i++) { + for ($i = 0, $iMax = count($auth_array); $i < $iMax; $i++) { $val = base64_pack((int)$auth_array[$i]); if (strlen($val) == 1 && !$one_char) { $auth_cache .= $one_char_encoding; diff --git a/library/attach_mod/includes/functions_delete.php b/library/attach_mod/includes/functions_delete.php index 3e0badfa4..d13a2d55b 100644 --- a/library/attach_mod/includes/functions_delete.php +++ b/library/attach_mod/includes/functions_delete.php @@ -187,7 +187,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } //bt end - for ($i = 0; $i < count($attach_id_array); $i++) { + for ($i = 0, $iMax = count($attach_id_array); $i < $iMax; $i++) { $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 286448ab9..9f7c636dc 100644 --- a/library/attach_mod/includes/functions_selects.php +++ b/library/attach_mod/includes/functions_selects.php @@ -50,7 +50,7 @@ function group_select($select_name, $default_group = 0) $group_name[$num_rows]['group_id'] = 0; $group_name[$num_rows]['group_name'] = $lang['NOT_ASSIGNED']; - for ($i = 0; $i < count($group_name); $i++) { + for ($i = 0, $iMax = count($group_name); $i < $iMax; $i++) { if (!$default_group) { $selected = ($i == 0) ? ' selected="selected"' : ''; } else { @@ -93,7 +93,7 @@ function download_select($select_name, $group_id = 0) $group_select = ''; - for ($i = 0; $i < count($types); $i++) { + for ($i = 0, $iMax = count($types); $i < $iMax; $i++) { if (!$group_id) { $selected = ($types[$i] == NONE_CAT) ? ' selected="selected"' : ''; } else { @@ -172,7 +172,7 @@ function size_select($select_name, $size_compare) $select_field = ' mode $select_sort_mode = '