Merge pull request #211 from Exile37/feature/deprecated_each

Deprecated each() function in php 7.2
This commit is contained in:
Yuriy Pikhtarev 2017-05-09 20:28:15 +03:00 committed by GitHub
commit 74ab0dca58
15 changed files with 49 additions and 45 deletions

View file

@ -158,10 +158,10 @@ if (empty($forum_id)) {
)); ));
} else { } else {
// Output the authorisation details if an id was specified // Output the authorisation details if an id was specified
$forum_name = $forum_rows[0]['forum_name']; $forum_name = reset($forum_rows)['forum_name'];
@reset($simple_auth_ary); reset($simple_auth_ary);
while (list($key, $auth_levels) = each($simple_auth_ary)) { foreach ($simple_auth_ary as $key => $auth_levels) {
$matched = 1; $matched = 1;
for ($k = 0, $kMax = count($auth_levels); $k < $iMax; $k++) { for ($k = 0, $kMax = count($auth_levels); $k < $iMax; $k++) {
$matched_type = $key; $matched_type = $key;

View file

@ -275,8 +275,8 @@ if (empty($forum_id) && empty($cat_id)) {
$category_rows = DB()->sql_fetchrowset($result); $category_rows = DB()->sql_fetchrowset($result);
$cat_id = $category_rows[0]['cat_id']; $cat_id = reset($category_rows)['cat_id'];
$cat_name = $category_rows[0]['cat_title']; $cat_name = reset($category_rows)['cat_title'];
$template->assign_block_vars('cat_row', array( $template->assign_block_vars('cat_row', array(
'CAT_NAME' => htmlCHR($cat_name), 'CAT_NAME' => htmlCHR($cat_name),

View file

@ -64,7 +64,7 @@ if (isset($_REQUEST['addforum']) || isset($_REQUEST['addcategory'])) {
if ($mode == 'addforum' && isset($_POST['addforum']) && isset($_POST['forumname']) && is_array($_POST['addforum'])) { if ($mode == 'addforum' && isset($_POST['addforum']) && isset($_POST['forumname']) && is_array($_POST['addforum'])) {
$req_cat_id = array_keys($_POST['addforum']); $req_cat_id = array_keys($_POST['addforum']);
$cat_id = $req_cat_id[0]; $cat_id = reset($req_cat_id);
$forumname = stripslashes($_POST['forumname'][$cat_id]); $forumname = stripslashes($_POST['forumname'][$cat_id]);
} }
} }

View file

@ -39,6 +39,7 @@ if (isset($_POST['mode']) || isset($_GET['mode'])) {
} }
$delimeter = '=+:'; $delimeter = '=+:';
$smiley_paks = [];
// Read a listing of uploaded smilies for use in the add or edit smliey code // Read a listing of uploaded smilies for use in the add or edit smliey code
$dir = @opendir(BB_ROOT . $bb_cfg['smilies_path']); $dir = @opendir(BB_ROOT . $bb_cfg['smilies_path']);
@ -127,7 +128,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) {
} else { } else {
// Display the script to get the smile_pak cfg file // Display the script to get the smile_pak cfg file
$smile_paks_select = '<select name="smile_pak"><option value="">' . $lang['SELECT_PAK'] . '</option>'; $smile_paks_select = '<select name="smile_pak"><option value="">' . $lang['SELECT_PAK'] . '</option>';
while (list($key, $value) = @each($smiley_paks)) { foreach ($smiley_paks as $key => $value) {
if (!empty($value)) { if (!empty($value)) {
$smile_paks_select .= '<option>' . $value . '</option>'; $smile_paks_select .= '<option>' . $value . '</option>';
} }

View file

@ -48,7 +48,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
ksort($module); ksort($module);
while (list($cat, $action_array) = each($module)) { foreach ($module as $cat => $action_array) {
$cat = (!empty($lang[$cat])) ? $lang[$cat] : preg_replace('/_/', ' ', $cat); $cat = (!empty($lang[$cat])) ? $lang[$cat] : preg_replace('/_/', ' ', $cat);
$template->assign_block_vars('catrow', array( $template->assign_block_vars('catrow', array(
@ -58,7 +58,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
ksort($action_array); ksort($action_array);
$row_count = 0; $row_count = 0;
while (list($action, $file) = each($action_array)) { foreach ($action_array as $action => $file) {
$row_class = !($row_count % 2) ? 'row1' : 'row2'; $row_class = !($row_count % 2) ? 'row1' : 'row2';
$action = (!empty($lang[$action])) ? $lang[$action] : preg_replace('/_/', ' ', $action); $action = (!empty($lang[$action])) ? $lang[$action] : preg_replace('/_/', ' ', $action);

View file

@ -513,7 +513,7 @@ function get_var($var_name, $default, $multibyte = false)
$type = gettype($default); $type = gettype($default);
$key_type = null; $key_type = null;
} else { } else {
list($key_type, $type) = each($default); list($key_type, $type) = $default;
$type = gettype($type); $type = gettype($type);
$key_type = gettype($key_type); $key_type = gettype($key_type);
} }

View file

@ -152,7 +152,7 @@ function generate_smilies($mode)
$row = 0; $row = 0;
$col = 0; $col = 0;
while (list($smile_url, $data) = @each($rowset)) { foreach ($rowset as $smile_url => $data) {
if (!$col) { if (!$col) {
$template->assign_block_vars('smilies_row', array()); $template->assign_block_vars('smilies_row', array());
} }

View file

@ -1028,13 +1028,13 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false)
if (!is_array($default)) { if (!is_array($default)) {
$type = gettype($default); $type = gettype($default);
} else { } else {
list($key_type, $type) = each($default); list($key_type, $type) = $default;
$type = gettype($type); $type = gettype($type);
$key_type = gettype($key_type); $key_type = gettype($key_type);
if ($type == 'array') { if ($type == 'array') {
reset($default); reset($default);
$default = current($default); $default = current($default);
list($sub_key_type, $sub_type) = each($default); list($sub_key_type, $sub_type) = $default;
$sub_type = gettype($sub_type); $sub_type = gettype($sub_type);
$sub_type = ($sub_type == 'array') ? 'NULL' : $sub_type; $sub_type = ($sub_type == 'array') ? 'NULL' : $sub_type;
$sub_key_type = gettype($sub_key_type); $sub_key_type = gettype($sub_key_type);

View file

@ -61,7 +61,7 @@ function tz_select($default, $select_name = 'timezone')
} }
$tz_select = '<select name="' . $select_name . '">'; $tz_select = '<select name="' . $select_name . '">';
while (list($offset, $zone) = @each($lang['TZ'])) { foreach ($lang['TZ'] as $offset => $zone) {
$selected = ($offset == $default) ? ' selected="selected"' : ''; $selected = ($offset == $default) ? ' selected="selected"' : '';
$tz_select .= '<option value="' . $offset . '"' . $selected . '>' . $zone . '</option>'; $tz_select .= '<option value="' . $offset . '"' . $selected . '>' . $zone . '</option>';
} }

View file

@ -71,7 +71,7 @@ function smtpmail($mail_to, $subject, $message, $headers = '')
@reset($header_array); @reset($header_array);
$headers = $cc = $bcc = ''; $headers = $cc = $bcc = '';
while (list(, $header) = each($header_array)) { foreach ($header_array as $header) {
if (preg_match('#^cc:#si', $header)) { if (preg_match('#^cc:#si', $header)) {
$cc = preg_replace('#^cc:(.*)#si', '\1', $header); $cc = preg_replace('#^cc:(.*)#si', '\1', $header);
} elseif (preg_match('#^bcc:#si', $header)) { } elseif (preg_match('#^bcc:#si', $header)) {
@ -134,24 +134,27 @@ function smtpmail($mail_to, $subject, $message, $headers = '')
server_parse($socket, "250", __LINE__); server_parse($socket, "250", __LINE__);
} }
// Ok now do the CC and BCC fields... if (!empty($bcc)) {
@reset($bcc); reset($bcc);
while (list(, $bcc_address) = each($bcc)) { foreach ($bcc as $bcc_address) {
// Add an additional bit of error checking to bcc header... // Add an additional bit of error checking to bcc header...
$bcc_address = trim($bcc_address); $bcc_address = trim($bcc_address);
if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address)) { if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address)) {
fwrite($socket, "RCPT TO: <$bcc_address>\r\n"); fwrite($socket, "RCPT TO: <$bcc_address>\r\n");
server_parse($socket, "250", __LINE__); server_parse($socket, "250", __LINE__);
}
} }
} }
@reset($cc); if (!empty($cc)) {
while (list(, $cc_address) = each($cc)) { reset($cc);
// Add an additional bit of error checking to cc header foreach ($cc as $cc_address) {
$cc_address = trim($cc_address); // Add an additional bit of error checking to cc header
if (preg_match('#[^ ]+\@[^ ]+#', $cc_address)) { $cc_address = trim($cc_address);
fwrite($socket, "RCPT TO: <$cc_address>\r\n"); if (preg_match('#[^ ]+\@[^ ]+#', $cc_address)) {
server_parse($socket, "250", __LINE__); fwrite($socket, "RCPT TO: <$cc_address>\r\n");
server_parse($socket, "250", __LINE__);
}
} }
} }

View file

@ -135,7 +135,7 @@ if ($by_letter_req) {
} elseif ($by_letter_req === 'others') { } elseif ($by_letter_req === 'others') {
$by_letter = 'others'; $by_letter = 'others';
$letter_sql = "username REGEXP '^[!-@\\[-`].*$'"; $letter_sql = "username REGEXP '^[!-@\\[-`].*$'";
} elseif ($letter_req = preg_replace("#[^$letters_range]#ui", '', iconv('windows-1251', 'UTF-8', $by_letter_req[0]))) { } elseif ($letter_req = preg_replace("#[^$letters_range]#ui", '', iconv('windows-1251', 'UTF-8', reset($by_letter_req)))) {
$by_letter = DB()->escape($letter_req); $by_letter = DB()->escape($letter_req);
$letter_sql = "LOWER(username) LIKE '$by_letter%'"; $letter_sql = "LOWER(username) LIKE '$by_letter%'";
} }

View file

@ -39,7 +39,7 @@ function return_msg_mcp($status_msg)
global $topic_id, $req_topics, $forum_id, $lang, $mode; global $topic_id, $req_topics, $forum_id, $lang, $mode;
if (count($req_topics) == 1) { if (count($req_topics) == 1) {
$topic_id = $req_topics[0]; $topic_id = reset($req_topics);
} }
$message = $status_msg; $message = $status_msg;

View file

@ -545,14 +545,14 @@ if ($mode == 'read') {
} while ($row = DB()->sql_fetchrow($result)); } while ($row = DB()->sql_fetchrow($result));
if (count($update_users)) { if (count($update_users)) {
while (list($type, $users) = each($update_users)) { foreach ($update_users as $type => $users) {
while (list($user_id, $dec) = each($users)) { foreach ($users as $user_id => $dec) {
$update_list[$type][$dec][] = $user_id; $update_list[$type][$dec][] = $user_id;
} }
} }
unset($update_users); unset($update_users);
while (list($type, $dec_ary) = each($update_list)) { foreach ($update_list as $type => $dec_ary) {
switch ($type) { switch ($type) {
case 'new': case 'new':
$type = "user_new_privmsg"; $type = "user_new_privmsg";
@ -563,7 +563,7 @@ if ($mode == 'read') {
break; break;
} }
while (list($dec, $user_ary) = each($dec_ary)) { foreach ($dec_ary as $dec => $user_ary) {
$user_ids = implode(', ', $user_ary); $user_ids = implode(', ', $user_ary);
$sql = "UPDATE " . BB_USERS . " $sql = "UPDATE " . BB_USERS . "
@ -698,24 +698,24 @@ if ($mode == 'read') {
do { do {
switch ($row['privmsgs_type']) { switch ($row['privmsgs_type']) {
case PRIVMSGS_NEW_MAIL: case PRIVMSGS_NEW_MAIL:
@$update_users['new'][$row['privmsgs_to_userid']]++; $update_users['new'][$row['privmsgs_to_userid']]++;
break; break;
case PRIVMSGS_UNREAD_MAIL: case PRIVMSGS_UNREAD_MAIL:
@$update_users['unread'][$row['privmsgs_to_userid']]++; $update_users['unread'][$row['privmsgs_to_userid']]++;
break; break;
} }
} while ($row = DB()->sql_fetchrow($result)); } while ($row = DB()->sql_fetchrow($result));
if (count($update_users)) { if (count($update_users)) {
while (list($type, $users) = each($update_users)) { foreach ($update_users as $type => $users) {
while (list($user_id, $dec) = each($users)) { foreach ($users as $user_id => $dec) {
$update_list[$type][$dec][] = $user_id; $update_list[$type][$dec][] = $user_id;
} }
} }
unset($update_users); unset($update_users);
while (list($type, $dec_ary) = each($update_list)) { foreach ($update_list as $type => $dec_ary) {
switch ($type) { switch ($type) {
case 'new': case 'new':
$type = "user_new_privmsg"; $type = "user_new_privmsg";
@ -726,7 +726,7 @@ if ($mode == 'read') {
break; break;
} }
while (list($dec, $user_ary) = each($dec_ary)) { foreach ($dec_ary as $dec => $user_ary) {
$user_ids = implode(', ', $user_ary); $user_ids = implode(', ', $user_ary);
$sql = "UPDATE " . BB_USERS . " SET $type = $type - $dec WHERE user_id IN ($user_ids)"; $sql = "UPDATE " . BB_USERS . " SET $type = $type - $dec WHERE user_id IN ($user_ids)";

View file

@ -592,7 +592,7 @@ if ($post_mode) {
foreach ($sorted_rows as $topic_id => $topic_posts) { foreach ($sorted_rows as $topic_id => $topic_posts) {
// Topic title block // Topic title block
$first_post = $topic_posts[0]; $first_post = reset($topic_posts);
$topic_id = (int)$topic_id; $topic_id = (int)$topic_id;
$forum_id = (int)$first_post['forum_id']; $forum_id = (int)$first_post['forum_id'];
$is_unread_t = is_unread($first_post['topic_last_post_time'], $topic_id, $forum_id); $is_unread_t = is_unread($first_post['topic_last_post_time'], $topic_id, $forum_id);

View file

@ -661,7 +661,7 @@ for ($i = 0; $i < $total_posts; $i++) {
'\"', '"', '\"', '"',
substr( substr(
preg_replace_callback('#(\>(((?>([^><]+|(?R)))*)\<))#s', function ($matches) use ($orig_word, $replacement_word) { preg_replace_callback('#(\>(((?>([^><]+|(?R)))*)\<))#s', function ($matches) use ($orig_word, $replacement_word) {
return preg_replace($orig_word, $replacement_word, $matches[0]); return preg_replace($orig_word, $replacement_word, reset($matches));
}, '>' . $user_sig . '<'), 1, -1 }, '>' . $user_sig . '<'), 1, -1
) )
); );
@ -671,7 +671,7 @@ for ($i = 0; $i < $total_posts; $i++) {
'\"', '"', '\"', '"',
substr( substr(
preg_replace_callback('#(\>(((?>([^><]+|(?R)))*)\<))#s', function ($matches) use ($orig_word, $replacement_word) { preg_replace_callback('#(\>(((?>([^><]+|(?R)))*)\<))#s', function ($matches) use ($orig_word, $replacement_word) {
return preg_replace($orig_word, $replacement_word, $matches[0]); return preg_replace($orig_word, $replacement_word, reset($matches));
}, '>' . $message . '<'), 1, -1 }, '>' . $message . '<'), 1, -1
) )
); );