From 3d817078a6f6ac4593f3c3c6a80b6bc703cf83b1 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Sun, 26 Feb 2017 01:44:28 +0300 Subject: [PATCH] Deprecated each() function in php 7.2 --- admin/admin_forumauth.php | 6 ++-- admin/admin_forumauth_list.php | 4 +-- admin/admin_forums.php | 2 +- admin/admin_smilies.php | 3 +- admin/index.php | 4 +-- .../attach_mod/includes/functions_attach.php | 2 +- library/includes/bbcode.php | 2 +- library/includes/functions.php | 4 +-- library/includes/functions_selects.php | 2 +- library/includes/smtp.php | 35 ++++++++++--------- memberlist.php | 2 +- modcp.php | 2 +- privmsg.php | 20 +++++------ search.php | 2 +- viewtopic.php | 4 +-- 15 files changed, 49 insertions(+), 45 deletions(-) diff --git a/admin/admin_forumauth.php b/admin/admin_forumauth.php index 876ea6dfc..377b9f3a5 100644 --- a/admin/admin_forumauth.php +++ b/admin/admin_forumauth.php @@ -158,10 +158,10 @@ if (empty($forum_id)) { )); } else { // 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); - while (list($key, $auth_levels) = each($simple_auth_ary)) { + reset($simple_auth_ary); + foreach ($simple_auth_ary as $key => $auth_levels) { $matched = 1; for ($k = 0, $kMax = count($auth_levels); $k < $iMax; $k++) { $matched_type = $key; diff --git a/admin/admin_forumauth_list.php b/admin/admin_forumauth_list.php index b619456cc..a00048d12 100644 --- a/admin/admin_forumauth_list.php +++ b/admin/admin_forumauth_list.php @@ -275,8 +275,8 @@ if (empty($forum_id) && empty($cat_id)) { $category_rows = DB()->sql_fetchrowset($result); - $cat_id = $category_rows[0]['cat_id']; - $cat_name = $category_rows[0]['cat_title']; + $cat_id = reset($category_rows)['cat_id']; + $cat_name = reset($category_rows)['cat_title']; $template->assign_block_vars('cat_row', array( 'CAT_NAME' => htmlCHR($cat_name), diff --git a/admin/admin_forums.php b/admin/admin_forums.php index 8c710c553..05ebdcb96 100644 --- a/admin/admin_forums.php +++ b/admin/admin_forums.php @@ -64,7 +64,7 @@ if (isset($_REQUEST['addforum']) || isset($_REQUEST['addcategory'])) { if ($mode == 'addforum' && isset($_POST['addforum']) && isset($_POST['forumname']) && is_array($_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]); } } diff --git a/admin/admin_smilies.php b/admin/admin_smilies.php index c84c83860..66b3b1d36 100644 --- a/admin/admin_smilies.php +++ b/admin/admin_smilies.php @@ -39,6 +39,7 @@ if (isset($_POST['mode']) || isset($_GET['mode'])) { } $delimeter = '=+:'; +$smiley_paks = []; // Read a listing of uploaded smilies for use in the add or edit smliey code $dir = @opendir(BB_ROOT . $bb_cfg['smilies_path']); @@ -127,7 +128,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) { } else { // Display the script to get the smile_pak cfg file $smile_paks_select = ''; - while (list($offset, $zone) = @each($lang['TZ'])) { + foreach ($lang['TZ'] as $offset => $zone) { $selected = ($offset == $default) ? ' selected="selected"' : ''; $tz_select .= ''; } diff --git a/library/includes/smtp.php b/library/includes/smtp.php index c138bca1e..16d1c009d 100644 --- a/library/includes/smtp.php +++ b/library/includes/smtp.php @@ -71,7 +71,7 @@ function smtpmail($mail_to, $subject, $message, $headers = '') @reset($header_array); $headers = $cc = $bcc = ''; - while (list(, $header) = each($header_array)) { + foreach ($header_array as $header) { if (preg_match('#^cc:#si', $header)) { $cc = preg_replace('#^cc:(.*)#si', '\1', $header); } elseif (preg_match('#^bcc:#si', $header)) { @@ -134,24 +134,27 @@ function smtpmail($mail_to, $subject, $message, $headers = '') server_parse($socket, "250", __LINE__); } - // Ok now do the CC and BCC fields... - @reset($bcc); - while (list(, $bcc_address) = each($bcc)) { - // Add an additional bit of error checking to bcc header... - $bcc_address = trim($bcc_address); - if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address)) { - fwrite($socket, "RCPT TO: <$bcc_address>\r\n"); - server_parse($socket, "250", __LINE__); + if (!empty($bcc)) { + reset($bcc); + foreach ($bcc as $bcc_address) { + // Add an additional bit of error checking to bcc header... + $bcc_address = trim($bcc_address); + if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address)) { + fwrite($socket, "RCPT TO: <$bcc_address>\r\n"); + server_parse($socket, "250", __LINE__); + } } } - @reset($cc); - while (list(, $cc_address) = each($cc)) { - // Add an additional bit of error checking to cc header - $cc_address = trim($cc_address); - if (preg_match('#[^ ]+\@[^ ]+#', $cc_address)) { - fwrite($socket, "RCPT TO: <$cc_address>\r\n"); - server_parse($socket, "250", __LINE__); + if (!empty($cc)) { + reset($cc); + foreach ($cc as $cc_address) { + // Add an additional bit of error checking to cc header + $cc_address = trim($cc_address); + if (preg_match('#[^ ]+\@[^ ]+#', $cc_address)) { + fwrite($socket, "RCPT TO: <$cc_address>\r\n"); + server_parse($socket, "250", __LINE__); + } } } diff --git a/memberlist.php b/memberlist.php index 794ccf1de..f1f17f4a4 100644 --- a/memberlist.php +++ b/memberlist.php @@ -135,7 +135,7 @@ if ($by_letter_req) { } elseif ($by_letter_req === 'others') { $by_letter = 'others'; $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); $letter_sql = "LOWER(username) LIKE '$by_letter%'"; } diff --git a/modcp.php b/modcp.php index 3dc445ffe..f37468b8f 100644 --- a/modcp.php +++ b/modcp.php @@ -39,7 +39,7 @@ function return_msg_mcp($status_msg) global $topic_id, $req_topics, $forum_id, $lang, $mode; if (count($req_topics) == 1) { - $topic_id = $req_topics[0]; + $topic_id = reset($req_topics); } $message = $status_msg; diff --git a/privmsg.php b/privmsg.php index 9af6369d6..92f05ab74 100644 --- a/privmsg.php +++ b/privmsg.php @@ -545,14 +545,14 @@ if ($mode == 'read') { } while ($row = DB()->sql_fetchrow($result)); if (count($update_users)) { - while (list($type, $users) = each($update_users)) { - while (list($user_id, $dec) = each($users)) { + foreach ($update_users as $type => $users) { + foreach ($users as $user_id => $dec) { $update_list[$type][$dec][] = $user_id; } } unset($update_users); - while (list($type, $dec_ary) = each($update_list)) { + foreach ($update_list as $type => $dec_ary) { switch ($type) { case 'new': $type = "user_new_privmsg"; @@ -563,7 +563,7 @@ if ($mode == 'read') { break; } - while (list($dec, $user_ary) = each($dec_ary)) { + foreach ($dec_ary as $dec => $user_ary) { $user_ids = implode(', ', $user_ary); $sql = "UPDATE " . BB_USERS . " @@ -698,24 +698,24 @@ if ($mode == 'read') { do { switch ($row['privmsgs_type']) { case PRIVMSGS_NEW_MAIL: - @$update_users['new'][$row['privmsgs_to_userid']]++; + $update_users['new'][$row['privmsgs_to_userid']]++; break; case PRIVMSGS_UNREAD_MAIL: - @$update_users['unread'][$row['privmsgs_to_userid']]++; + $update_users['unread'][$row['privmsgs_to_userid']]++; break; } } while ($row = DB()->sql_fetchrow($result)); if (count($update_users)) { - while (list($type, $users) = each($update_users)) { - while (list($user_id, $dec) = each($users)) { + foreach ($update_users as $type => $users) { + foreach ($users as $user_id => $dec) { $update_list[$type][$dec][] = $user_id; } } unset($update_users); - while (list($type, $dec_ary) = each($update_list)) { + foreach ($update_list as $type => $dec_ary) { switch ($type) { case 'new': $type = "user_new_privmsg"; @@ -726,7 +726,7 @@ if ($mode == 'read') { break; } - while (list($dec, $user_ary) = each($dec_ary)) { + foreach ($dec_ary as $dec => $user_ary) { $user_ids = implode(', ', $user_ary); $sql = "UPDATE " . BB_USERS . " SET $type = $type - $dec WHERE user_id IN ($user_ids)"; diff --git a/search.php b/search.php index 389e5e081..b51436311 100644 --- a/search.php +++ b/search.php @@ -592,7 +592,7 @@ if ($post_mode) { foreach ($sorted_rows as $topic_id => $topic_posts) { // Topic title block - $first_post = $topic_posts[0]; + $first_post = reset($topic_posts); $topic_id = (int)$topic_id; $forum_id = (int)$first_post['forum_id']; $is_unread_t = is_unread($first_post['topic_last_post_time'], $topic_id, $forum_id); diff --git a/viewtopic.php b/viewtopic.php index 9cfc60f2a..dbcd9f1db 100644 --- a/viewtopic.php +++ b/viewtopic.php @@ -661,7 +661,7 @@ for ($i = 0; $i < $total_posts; $i++) { '\"', '"', substr( 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 ) ); @@ -671,7 +671,7 @@ for ($i = 0; $i < $total_posts; $i++) { '\"', '"', substr( 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 ) );