@@ -27,9 +27,10 @@ discard block |
||
27 | 27 | <h3 class="catbg"> |
28 | 28 | <span class="floatleft">', $txt['members_list'], '</span>'; |
29 | 29 | |
30 | - if (!isset($context['old_search'])) |
|
31 | - echo ' |
|
30 | + if (!isset($context['old_search'])) { |
|
31 | + echo ' |
|
32 | 32 | <span class="floatright">', $context['letter_links'], '</span>'; |
33 | + } |
|
33 | 34 | echo ' |
34 | 35 | </h3> |
35 | 36 | </div>'; |
@@ -44,20 +45,23 @@ discard block |
||
44 | 45 | foreach ($context['columns'] as $key => $column) |
45 | 46 | { |
46 | 47 | // @TODO maybe find something nicer? |
47 | - if ($key == 'email_address' && !$context['can_send_email']) |
|
48 | - continue; |
|
48 | + if ($key == 'email_address' && !$context['can_send_email']) { |
|
49 | + continue; |
|
50 | + } |
|
49 | 51 | |
50 | 52 | // This is a selected column, so underline it or some such. |
51 | - if ($column['selected']) |
|
52 | - echo ' |
|
53 | + if ($column['selected']) { |
|
54 | + echo ' |
|
53 | 55 | <th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', ' selected" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . '> |
54 | 56 | <a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></th>'; |
57 | + } |
|
55 | 58 | |
56 | 59 | // This is just some column... show the link and be done with it. |
57 | - else |
|
58 | - echo ' |
|
60 | + else { |
|
61 | + echo ' |
|
59 | 62 | <th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' style="width: ' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '> |
60 | 63 | ', $column['link'], '</th>'; |
64 | + } |
|
61 | 65 | } |
62 | 66 | |
63 | 67 | echo ' |
@@ -77,9 +81,10 @@ discard block |
||
77 | 81 | </td> |
78 | 82 | <td class="lefttext">', $member['link'], '</td>'; |
79 | 83 | |
80 | - if (!isset($context['disabled_fields']['website'])) |
|
81 | - echo ' |
|
84 | + if (!isset($context['disabled_fields']['website'])) { |
|
85 | + echo ' |
|
82 | 86 | <td class="centertext website_url">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" rel="noopener"><span class="generic_icons www" title="' . $member['website']['title'] . '"></span></a>' : '', '</td>'; |
87 | + } |
|
83 | 88 | |
84 | 89 | // Group and date. |
85 | 90 | echo ' |
@@ -92,32 +97,35 @@ discard block |
||
92 | 97 | <td class="centertext" style="white-space: nowrap; width: 15px">', $member['posts'], '</td> |
93 | 98 | <td class="centertext statsbar" style="width: 120px">'; |
94 | 99 | |
95 | - if (!empty($member['post_percent'])) |
|
96 | - echo ' |
|
100 | + if (!empty($member['post_percent'])) { |
|
101 | + echo ' |
|
97 | 102 | <div class="bar" style="width: ', $member['post_percent'] + 4, 'px;"> |
98 | 103 | <div style="width: ', $member['post_percent'], 'px;"></div> |
99 | 104 | </div>'; |
105 | + } |
|
100 | 106 | |
101 | 107 | echo ' |
102 | 108 | </td>'; |
103 | 109 | } |
104 | 110 | |
105 | 111 | // Show custom fields marked to be shown here |
106 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
107 | - foreach ($context['custom_profile_fields']['columns'] as $key => $column) |
|
112 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
113 | + foreach ($context['custom_profile_fields']['columns'] as $key => $column) |
|
108 | 114 | echo ' |
109 | 115 | <td class="righttext">', $member['options'][$key], '</td>'; |
116 | + } |
|
110 | 117 | |
111 | 118 | echo ' |
112 | 119 | </tr>'; |
113 | 120 | } |
114 | 121 | } |
115 | 122 | // No members? |
116 | - else |
|
117 | - echo ' |
|
123 | + else { |
|
124 | + echo ' |
|
118 | 125 | <tr> |
119 | 126 | <td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td> |
120 | 127 | </tr>'; |
128 | + } |
|
121 | 129 | |
122 | 130 | echo ' |
123 | 131 | </tbody> |
@@ -130,11 +138,12 @@ discard block |
||
130 | 138 | <div class="pagelinks floatleft">', $context['page_index'], '</div>'; |
131 | 139 | |
132 | 140 | // If it is displaying the result of a search show a "search again" link to edit their criteria. |
133 | - if (isset($context['old_search'])) |
|
134 | - echo ' |
|
141 | + if (isset($context['old_search'])) { |
|
142 | + echo ' |
|
135 | 143 | <div class="buttonlist floatright"> |
136 | 144 | <a class="button" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a> |
137 | 145 | </div>'; |
146 | + } |
|
138 | 147 | echo ' |
139 | 148 | </div> |
140 | 149 | </div><!-- #memberlist -->'; |
@@ -174,12 +183,13 @@ discard block |
||
174 | 183 | <dd> |
175 | 184 | <ul>'; |
176 | 185 | |
177 | - foreach ($context['search_fields'] as $id => $title) |
|
178 | - echo ' |
|
186 | + foreach ($context['search_fields'] as $id => $title) { |
|
187 | + echo ' |
|
179 | 188 | <li> |
180 | 189 | <input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '"', in_array($id, $context['search_defaults']) ? ' checked' : '', '> |
181 | 190 | <label for="fields-', $id, '">', $title, '</label> |
182 | 191 | </li>'; |
192 | + } |
|
183 | 193 | |
184 | 194 | echo ' |
185 | 195 | </ul> |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Ask them for their login information. (shows a page for the user to type |
@@ -29,8 +30,9 @@ discard block |
||
29 | 30 | global $txt, $context, $scripturl, $user_info; |
30 | 31 | |
31 | 32 | // You are already logged in, go take a tour of the boards |
32 | - if (!empty($user_info['id'])) |
|
33 | - redirectexit(); |
|
33 | + if (!empty($user_info['id'])) { |
|
34 | + redirectexit(); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | // We need to load the Login template/language file. |
36 | 38 | loadLanguage('Login'); |
@@ -57,10 +59,11 @@ discard block |
||
57 | 59 | ); |
58 | 60 | |
59 | 61 | // Set the login URL - will be used when the login process is done (but careful not to send us to an attachment). |
60 | - if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) |
|
61 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
62 | - elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) |
|
63 | - unset($_SESSION['login_url']); |
|
62 | + if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) { |
|
63 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
64 | + } elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) { |
|
65 | + unset($_SESSION['login_url']); |
|
66 | + } |
|
64 | 67 | |
65 | 68 | // Create a one time token. |
66 | 69 | createToken('login'); |
@@ -83,8 +86,9 @@ discard block |
||
83 | 86 | global $cookiename, $modSettings, $context, $sourcedir, $maintenance; |
84 | 87 | |
85 | 88 | // Check to ensure we're forcing SSL for authentication |
86 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
87 | - fatal_lang_error('login_ssl_required'); |
|
89 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
90 | + fatal_lang_error('login_ssl_required'); |
|
91 | + } |
|
88 | 92 | |
89 | 93 | // Load cookie authentication stuff. |
90 | 94 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -98,23 +102,26 @@ discard block |
||
98 | 102 | if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest']) |
99 | 103 | { |
100 | 104 | // First check for 2.1 json-format cookie in $_COOKIE |
101 | - if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) |
|
102 | - list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
|
105 | + if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) { |
|
106 | + list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
|
107 | + } |
|
103 | 108 | |
104 | 109 | // Try checking for 2.1 json-format cookie in $_SESSION |
105 | - elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) |
|
106 | - list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
|
110 | + elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) { |
|
111 | + list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
|
112 | + } |
|
107 | 113 | |
108 | 114 | // Next, try checking for 2.0 serialized string cookie in $_COOKIE |
109 | - elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) |
|
110 | - list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
115 | + elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) { |
|
116 | + list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
117 | + } |
|
111 | 118 | |
112 | 119 | // Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION |
113 | - elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) |
|
114 | - list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
115 | - |
|
116 | - else |
|
117 | - trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
120 | + elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) { |
|
121 | + list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
122 | + } else { |
|
123 | + trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
124 | + } |
|
118 | 125 | |
119 | 126 | $user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4); |
120 | 127 | updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt'])); |
@@ -127,10 +134,11 @@ discard block |
||
127 | 134 | list ($tfamember, $tfasecret, $exp, $domain, $path, $preserve) = $tfadata; |
128 | 135 | |
129 | 136 | // If we're preserving the cookie, reset it with updated salt |
130 | - if (isset($tfamember, $tfasecret, $exp, $domain, $path, $preserve) && $preserve && time() < $exp) |
|
131 | - setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
132 | - else |
|
133 | - setTFACookie(-3600, 0, ''); |
|
137 | + if (isset($tfamember, $tfasecret, $exp, $domain, $path, $preserve) && $preserve && time() < $exp) { |
|
138 | + setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
139 | + } else { |
|
140 | + setTFACookie(-3600, 0, ''); |
|
141 | + } |
|
134 | 142 | } |
135 | 143 | |
136 | 144 | setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
@@ -141,20 +149,20 @@ discard block |
||
141 | 149 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
142 | 150 | { |
143 | 151 | // Strike! You're outta there! |
144 | - if ($_GET['member'] != $user_info['id']) |
|
145 | - fatal_lang_error('login_cookie_error', false); |
|
152 | + if ($_GET['member'] != $user_info['id']) { |
|
153 | + fatal_lang_error('login_cookie_error', false); |
|
154 | + } |
|
146 | 155 | |
147 | 156 | $user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])))); |
148 | 157 | |
149 | 158 | // Some whitelisting for login_url... |
150 | - if (empty($_SESSION['login_url'])) |
|
151 | - redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
152 | - elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
159 | + if (empty($_SESSION['login_url'])) { |
|
160 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
161 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
153 | 162 | { |
154 | 163 | unset ($_SESSION['login_url']); |
155 | 164 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
156 | - } |
|
157 | - else |
|
165 | + } else |
|
158 | 166 | { |
159 | 167 | // Best not to clutter the session data too much... |
160 | 168 | $temp = $_SESSION['login_url']; |
@@ -165,8 +173,9 @@ discard block |
||
165 | 173 | } |
166 | 174 | |
167 | 175 | // Beyond this point you are assumed to be a guest trying to login. |
168 | - if (!$user_info['is_guest']) |
|
169 | - redirectexit(); |
|
176 | + if (!$user_info['is_guest']) { |
|
177 | + redirectexit(); |
|
178 | + } |
|
170 | 179 | |
171 | 180 | // Are you guessing with a script? |
172 | 181 | checkSession(); |
@@ -174,18 +183,21 @@ discard block |
||
174 | 183 | spamProtection('login'); |
175 | 184 | |
176 | 185 | // Set the login_url if it's not already set (but careful not to send us to an attachment). |
177 | - if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) |
|
178 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
186 | + if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) { |
|
187 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
188 | + } |
|
179 | 189 | |
180 | 190 | // Been guessing a lot, haven't we? |
181 | - if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) |
|
182 | - fatal_lang_error('login_threshold_fail', 'login'); |
|
191 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
192 | + fatal_lang_error('login_threshold_fail', 'login'); |
|
193 | + } |
|
183 | 194 | |
184 | 195 | // Set up the cookie length. (if it's invalid, just fall through and use the default.) |
185 | - if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) |
|
186 | - $modSettings['cookieTime'] = 3153600; |
|
187 | - elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) |
|
188 | - $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
196 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
197 | + $modSettings['cookieTime'] = 3153600; |
|
198 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
199 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
200 | + } |
|
189 | 201 | |
190 | 202 | loadLanguage('Login'); |
191 | 203 | // Load the template stuff. |
@@ -305,8 +317,9 @@ discard block |
||
305 | 317 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
306 | 318 | |
307 | 319 | // Snitz style - SHA-256. Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway. |
308 | - if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) |
|
309 | - $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
320 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
321 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
322 | + } |
|
310 | 323 | |
311 | 324 | // phpBB3 users new hashing. We now support it as well ;). |
312 | 325 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -326,27 +339,29 @@ discard block |
||
326 | 339 | // Some common md5 ones. |
327 | 340 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
328 | 341 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
329 | - } |
|
330 | - elseif (strlen($user_settings['passwd']) == 40) |
|
342 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
331 | 343 | { |
332 | 344 | // Maybe they are using a hash from before the password fix. |
333 | 345 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
334 | 346 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
335 | 347 | |
336 | 348 | // BurningBoard3 style of hashing. |
337 | - if (!empty($modSettings['enable_password_conversion'])) |
|
338 | - $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
349 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
350 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
351 | + } |
|
339 | 352 | |
340 | 353 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
341 | 354 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
342 | 355 | { |
343 | 356 | // Try iconv first, for no particular reason. |
344 | - if (function_exists('iconv')) |
|
345 | - $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
357 | + if (function_exists('iconv')) { |
|
358 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
359 | + } |
|
346 | 360 | |
347 | 361 | // Say it aint so, iconv failed! |
348 | - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) |
|
349 | - $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
362 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
363 | + $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
364 | + } |
|
350 | 365 | } |
351 | 366 | } |
352 | 367 | |
@@ -376,8 +391,9 @@ discard block |
||
376 | 391 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
377 | 392 | |
378 | 393 | // Hmm... don't remember it, do you? Here, try the password reminder ;). |
379 | - if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) |
|
380 | - redirectexit('action=reminder'); |
|
394 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
395 | + redirectexit('action=reminder'); |
|
396 | + } |
|
381 | 397 | // We'll give you another chance... |
382 | 398 | else |
383 | 399 | { |
@@ -388,8 +404,7 @@ discard block |
||
388 | 404 | return; |
389 | 405 | } |
390 | 406 | } |
391 | - } |
|
392 | - elseif (!empty($user_settings['passwd_flood'])) |
|
407 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
393 | 408 | { |
394 | 409 | // Let's be sure they weren't a little hacker. |
395 | 410 | validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true); |
@@ -406,8 +421,9 @@ discard block |
||
406 | 421 | } |
407 | 422 | |
408 | 423 | // Check their activation status. |
409 | - if (!checkActivation()) |
|
410 | - return; |
|
424 | + if (!checkActivation()) { |
|
425 | + return; |
|
426 | + } |
|
411 | 427 | |
412 | 428 | DoLogin(); |
413 | 429 | } |
@@ -419,8 +435,9 @@ discard block |
||
419 | 435 | { |
420 | 436 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
421 | 437 | |
422 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
423 | - fatal_lang_error('no_access', false); |
|
438 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
439 | + fatal_lang_error('no_access', false); |
|
440 | + } |
|
424 | 441 | |
425 | 442 | loadLanguage('Profile'); |
426 | 443 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -428,8 +445,9 @@ discard block |
||
428 | 445 | $member = $context['tfa_member']; |
429 | 446 | |
430 | 447 | // Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA |
431 | - if (time() - $member['last_login'] < 120) |
|
432 | - fatal_lang_error('tfa_wait', false); |
|
448 | + if (time() - $member['last_login'] < 120) { |
|
449 | + fatal_lang_error('tfa_wait', false); |
|
450 | + } |
|
433 | 451 | |
434 | 452 | $totp = new \TOTP\Auth($member['tfa_secret']); |
435 | 453 | $totp->setRange(1); |
@@ -443,8 +461,9 @@ discard block |
||
443 | 461 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
444 | 462 | { |
445 | 463 | // Check to ensure we're forcing SSL for authentication |
446 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
447 | - fatal_lang_error('login_ssl_required'); |
|
464 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
465 | + fatal_lang_error('login_ssl_required'); |
|
466 | + } |
|
448 | 467 | |
449 | 468 | $code = $_POST['tfa_code']; |
450 | 469 | |
@@ -454,20 +473,19 @@ discard block |
||
454 | 473 | |
455 | 474 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve'])); |
456 | 475 | redirectexit(); |
457 | - } |
|
458 | - else |
|
476 | + } else |
|
459 | 477 | { |
460 | 478 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
461 | 479 | |
462 | 480 | $context['tfa_error'] = true; |
463 | 481 | $context['tfa_value'] = $_POST['tfa_code']; |
464 | 482 | } |
465 | - } |
|
466 | - elseif (!empty($_POST['tfa_backup'])) |
|
483 | + } elseif (!empty($_POST['tfa_backup'])) |
|
467 | 484 | { |
468 | 485 | // Check to ensure we're forcing SSL for authentication |
469 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
470 | - fatal_lang_error('login_ssl_required'); |
|
486 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
487 | + fatal_lang_error('login_ssl_required'); |
|
488 | + } |
|
471 | 489 | |
472 | 490 | $backup = $_POST['tfa_backup']; |
473 | 491 | |
@@ -481,8 +499,7 @@ discard block |
||
481 | 499 | )); |
482 | 500 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
483 | 501 | redirectexit('action=profile;area=tfasetup;backup'); |
484 | - } |
|
485 | - else |
|
502 | + } else |
|
486 | 503 | { |
487 | 504 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
488 | 505 | |
@@ -505,8 +522,9 @@ discard block |
||
505 | 522 | { |
506 | 523 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
507 | 524 | |
508 | - if (!isset($context['login_errors'])) |
|
509 | - $context['login_errors'] = array(); |
|
525 | + if (!isset($context['login_errors'])) { |
|
526 | + $context['login_errors'] = array(); |
|
527 | + } |
|
510 | 528 | |
511 | 529 | // What is the true activation status of this account? |
512 | 530 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -518,8 +536,9 @@ discard block |
||
518 | 536 | return false; |
519 | 537 | } |
520 | 538 | // Awaiting approval still? |
521 | - elseif ($activation_status == 3) |
|
522 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
539 | + elseif ($activation_status == 3) { |
|
540 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
541 | + } |
|
523 | 542 | // Awaiting deletion, changed their mind? |
524 | 543 | elseif ($activation_status == 4) |
525 | 544 | { |
@@ -527,8 +546,7 @@ discard block |
||
527 | 546 | { |
528 | 547 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
529 | 548 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
530 | - } |
|
531 | - else |
|
549 | + } else |
|
532 | 550 | { |
533 | 551 | $context['disable_login_hashing'] = true; |
534 | 552 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -568,8 +586,9 @@ discard block |
||
568 | 586 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
569 | 587 | |
570 | 588 | // Reset the login threshold. |
571 | - if (isset($_SESSION['failed_login'])) |
|
572 | - unset($_SESSION['failed_login']); |
|
589 | + if (isset($_SESSION['failed_login'])) { |
|
590 | + unset($_SESSION['failed_login']); |
|
591 | + } |
|
573 | 592 | |
574 | 593 | $user_info['is_guest'] = false; |
575 | 594 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -591,16 +610,18 @@ discard block |
||
591 | 610 | 'id_member' => $user_info['id'], |
592 | 611 | ) |
593 | 612 | ); |
594 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
595 | - $_SESSION['first_login'] = true; |
|
596 | - else |
|
597 | - unset($_SESSION['first_login']); |
|
613 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
614 | + $_SESSION['first_login'] = true; |
|
615 | + } else { |
|
616 | + unset($_SESSION['first_login']); |
|
617 | + } |
|
598 | 618 | $smcFunc['db_free_result']($request); |
599 | 619 | |
600 | 620 | // You've logged in, haven't you? |
601 | 621 | $update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']); |
602 | - if (empty($user_settings['tfa_secret'])) |
|
603 | - $update['last_login'] = time(); |
|
622 | + if (empty($user_settings['tfa_secret'])) { |
|
623 | + $update['last_login'] = time(); |
|
624 | + } |
|
604 | 625 | updateMemberData($user_info['id'], $update); |
605 | 626 | |
606 | 627 | // Get rid of the online entry for that old guest.... |
@@ -614,8 +635,8 @@ discard block |
||
614 | 635 | $_SESSION['log_time'] = 0; |
615 | 636 | |
616 | 637 | // Log this entry, only if we have it enabled. |
617 | - if (!empty($modSettings['loginHistoryDays'])) |
|
618 | - $smcFunc['db_insert']('insert', |
|
638 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
639 | + $smcFunc['db_insert']('insert', |
|
619 | 640 | '{db_prefix}member_logins', |
620 | 641 | array( |
621 | 642 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -627,13 +648,15 @@ discard block |
||
627 | 648 | 'id_member', 'time' |
628 | 649 | ) |
629 | 650 | ); |
651 | + } |
|
630 | 652 | |
631 | 653 | // Just log you back out if it's in maintenance mode and you AREN'T an admin. |
632 | - if (empty($maintenance) || allowedTo('admin_forum')) |
|
633 | - redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
634 | - else |
|
635 | - redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
636 | -} |
|
654 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
655 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
656 | + } else { |
|
657 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
658 | + } |
|
659 | + } |
|
637 | 660 | |
638 | 661 | /** |
639 | 662 | * Logs the current user out of their account. |
@@ -649,13 +672,15 @@ discard block |
||
649 | 672 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
650 | 673 | |
651 | 674 | // Make sure they aren't being auto-logged out. |
652 | - if (!$internal) |
|
653 | - checkSession('get'); |
|
675 | + if (!$internal) { |
|
676 | + checkSession('get'); |
|
677 | + } |
|
654 | 678 | |
655 | 679 | require_once($sourcedir . '/Subs-Auth.php'); |
656 | 680 | |
657 | - if (isset($_SESSION['pack_ftp'])) |
|
658 | - $_SESSION['pack_ftp'] = null; |
|
681 | + if (isset($_SESSION['pack_ftp'])) { |
|
682 | + $_SESSION['pack_ftp'] = null; |
|
683 | + } |
|
659 | 684 | |
660 | 685 | // It won't be first login anymore. |
661 | 686 | unset($_SESSION['first_login']); |
@@ -683,8 +708,9 @@ discard block |
||
683 | 708 | |
684 | 709 | // And some other housekeeping while we're at it. |
685 | 710 | $salt = substr(md5(mt_rand()), 0, 4); |
686 | - if (!empty($user_info['id'])) |
|
687 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
711 | + if (!empty($user_info['id'])) { |
|
712 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
713 | + } |
|
688 | 714 | |
689 | 715 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
690 | 716 | { |
@@ -693,10 +719,11 @@ discard block |
||
693 | 719 | list ($tfamember, $tfasecret, $exp, $domain, $path, $preserve) = $tfadata; |
694 | 720 | |
695 | 721 | // If we're preserving the cookie, reset it with updated salt |
696 | - if (isset($tfamember, $tfasecret, $exp, $domain, $path, $preserve) && $preserve && time() < $exp) |
|
697 | - setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
698 | - else |
|
699 | - setTFACookie(-3600, 0, ''); |
|
722 | + if (isset($tfamember, $tfasecret, $exp, $domain, $path, $preserve) && $preserve && time() < $exp) { |
|
723 | + setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
724 | + } else { |
|
725 | + setTFACookie(-3600, 0, ''); |
|
726 | + } |
|
700 | 727 | } |
701 | 728 | |
702 | 729 | session_destroy(); |
@@ -704,14 +731,13 @@ discard block |
||
704 | 731 | // Off to the merry board index we go! |
705 | 732 | if ($redirect) |
706 | 733 | { |
707 | - if (empty($_SESSION['logout_url'])) |
|
708 | - redirectexit('', $context['server']['needs_login_fix']); |
|
709 | - elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
734 | + if (empty($_SESSION['logout_url'])) { |
|
735 | + redirectexit('', $context['server']['needs_login_fix']); |
|
736 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
710 | 737 | { |
711 | 738 | unset ($_SESSION['logout_url']); |
712 | 739 | redirectexit(); |
713 | - } |
|
714 | - else |
|
740 | + } else |
|
715 | 741 | { |
716 | 742 | $temp = $_SESSION['logout_url']; |
717 | 743 | unset($_SESSION['logout_url']); |
@@ -744,8 +770,9 @@ discard block |
||
744 | 770 | function phpBB3_password_check($passwd, $passwd_hash) |
745 | 771 | { |
746 | 772 | // Too long or too short? |
747 | - if (strlen($passwd_hash) != 34) |
|
748 | - return; |
|
773 | + if (strlen($passwd_hash) != 34) { |
|
774 | + return; |
|
775 | + } |
|
749 | 776 | |
750 | 777 | // Range of characters allowed. |
751 | 778 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -756,8 +783,9 @@ discard block |
||
756 | 783 | $salt = substr($passwd_hash, 4, 8); |
757 | 784 | |
758 | 785 | $hash = md5($salt . $passwd, true); |
759 | - for (; $count != 0; --$count) |
|
760 | - $hash = md5($hash . $passwd, true); |
|
786 | + for (; $count != 0; --$count) { |
|
787 | + $hash = md5($hash . $passwd, true); |
|
788 | + } |
|
761 | 789 | |
762 | 790 | $output = substr($passwd_hash, 0, 12); |
763 | 791 | $i = 0; |
@@ -766,21 +794,25 @@ discard block |
||
766 | 794 | $value = ord($hash[$i++]); |
767 | 795 | $output .= $range[$value & 0x3f]; |
768 | 796 | |
769 | - if ($i < 16) |
|
770 | - $value |= ord($hash[$i]) << 8; |
|
797 | + if ($i < 16) { |
|
798 | + $value |= ord($hash[$i]) << 8; |
|
799 | + } |
|
771 | 800 | |
772 | 801 | $output .= $range[($value >> 6) & 0x3f]; |
773 | 802 | |
774 | - if ($i++ >= 16) |
|
775 | - break; |
|
803 | + if ($i++ >= 16) { |
|
804 | + break; |
|
805 | + } |
|
776 | 806 | |
777 | - if ($i < 16) |
|
778 | - $value |= ord($hash[$i]) << 16; |
|
807 | + if ($i < 16) { |
|
808 | + $value |= ord($hash[$i]) << 16; |
|
809 | + } |
|
779 | 810 | |
780 | 811 | $output .= $range[($value >> 12) & 0x3f]; |
781 | 812 | |
782 | - if ($i++ >= 16) |
|
783 | - break; |
|
813 | + if ($i++ >= 16) { |
|
814 | + break; |
|
815 | + } |
|
784 | 816 | |
785 | 817 | $output .= $range[($value >> 18) & 0x3f]; |
786 | 818 | } |
@@ -812,8 +844,9 @@ discard block |
||
812 | 844 | require_once($sourcedir . '/Subs-Auth.php'); |
813 | 845 | setLoginCookie(-3600, 0); |
814 | 846 | |
815 | - if (isset($_SESSION['login_' . $cookiename])) |
|
816 | - unset($_SESSION['login_' . $cookiename]); |
|
847 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
848 | + unset($_SESSION['login_' . $cookiename]); |
|
849 | + } |
|
817 | 850 | } |
818 | 851 | |
819 | 852 | // We need a member! |
@@ -827,8 +860,9 @@ discard block |
||
827 | 860 | } |
828 | 861 | |
829 | 862 | // Right, have we got a flood value? |
830 | - if ($password_flood_value !== false) |
|
831 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
863 | + if ($password_flood_value !== false) { |
|
864 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
865 | + } |
|
832 | 866 | |
833 | 867 | // Timestamp or number of tries invalid? |
834 | 868 | if (empty($number_tries) || empty($time_stamp)) |
@@ -844,15 +878,17 @@ discard block |
||
844 | 878 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
845 | 879 | |
846 | 880 | // They are trying too fast, make them wait longer |
847 | - if ($time_stamp < time() - 10) |
|
848 | - $time_stamp = time(); |
|
881 | + if ($time_stamp < time() - 10) { |
|
882 | + $time_stamp = time(); |
|
883 | + } |
|
849 | 884 | } |
850 | 885 | |
851 | 886 | $number_tries++; |
852 | 887 | |
853 | 888 | // Broken the law? |
854 | - if ($number_tries > 5) |
|
855 | - fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
889 | + if ($number_tries > 5) { |
|
890 | + fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
891 | + } |
|
856 | 892 | |
857 | 893 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
858 | 894 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Sets the SMF-style login cookie and session based on the id_member and password passed. |
@@ -45,8 +46,9 @@ discard block |
||
45 | 46 | if (isset($_COOKIE[$cookiename])) |
46 | 47 | { |
47 | 48 | // First check for 2.1 json-format cookie |
48 | - if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) |
|
49 | - list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
|
49 | + if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) { |
|
50 | + list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
|
51 | + } |
|
50 | 52 | |
51 | 53 | // Legacy format (for recent 2.0 --> 2.1 upgrades) |
52 | 54 | elseif (preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;(i:3;i:\d;)?~', $_COOKIE[$cookiename]) === 1) |
@@ -56,15 +58,17 @@ discard block |
||
56 | 58 | $cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2); |
57 | 59 | |
58 | 60 | // Maybe we need to temporarily pretend to be using local cookies |
59 | - if ($cookie_state == 0 && $old_state == 1) |
|
60 | - list($old_domain, $old_path) = url_parts(true, false); |
|
61 | - else |
|
62 | - list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0); |
|
61 | + if ($cookie_state == 0 && $old_state == 1) { |
|
62 | + list($old_domain, $old_path) = url_parts(true, false); |
|
63 | + } else { |
|
64 | + list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0); |
|
65 | + } |
|
63 | 66 | } |
64 | 67 | |
65 | 68 | // Out with the old, in with the new! |
66 | - if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) |
|
67 | - smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain); |
|
69 | + if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) { |
|
70 | + smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain); |
|
71 | + } |
|
68 | 72 | } |
69 | 73 | |
70 | 74 | // Get the data and path to set it on. |
@@ -80,8 +84,9 @@ discard block |
||
80 | 84 | smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], $cookie_url[0]); |
81 | 85 | |
82 | 86 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
83 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
84 | - smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], ''); |
|
87 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
88 | + smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], ''); |
|
89 | + } |
|
85 | 90 | |
86 | 91 | // Any alias URLs? This is mainly for use with frames, etc. |
87 | 92 | if (!empty($modSettings['forum_alias_urls'])) |
@@ -97,8 +102,9 @@ discard block |
||
97 | 102 | |
98 | 103 | $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); |
99 | 104 | |
100 | - if ($cookie_url[0] == '') |
|
101 | - $cookie_url[0] = strtok($alias, '/'); |
|
105 | + if ($cookie_url[0] == '') { |
|
106 | + $cookie_url[0] = strtok($alias, '/'); |
|
107 | + } |
|
102 | 108 | |
103 | 109 | $alias_data = $smcFunc['json_decode']($data); |
104 | 110 | $alias_data[3] = $cookie_url[0]; |
@@ -149,8 +155,9 @@ discard block |
||
149 | 155 | $identifier = $cookiename . '_tfa'; |
150 | 156 | $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); |
151 | 157 | |
152 | - if ($preserve) |
|
153 | - $cookie_length = 81600 * 30; |
|
158 | + if ($preserve) { |
|
159 | + $cookie_length = 81600 * 30; |
|
160 | + } |
|
154 | 161 | |
155 | 162 | // Get the data and path to set it on. |
156 | 163 | $data = $smcFunc['json_encode'](empty($id) ? array(0, '', 0, $cookie_url[0], $cookie_url[1], false) : array($id, $secret, time() + $cookie_length, $cookie_url[0], $cookie_url[1], $preserve), JSON_FORCE_OBJECT); |
@@ -159,8 +166,9 @@ discard block |
||
159 | 166 | smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
160 | 167 | |
161 | 168 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
162 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
163 | - smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
169 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
170 | + smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
171 | + } |
|
164 | 172 | |
165 | 173 | $_COOKIE[$identifier] = $data; |
166 | 174 | } |
@@ -182,23 +190,28 @@ discard block |
||
182 | 190 | $parsed_url = parse_url($boardurl); |
183 | 191 | |
184 | 192 | // Is local cookies off? |
185 | - if (empty($parsed_url['path']) || !$local) |
|
186 | - $parsed_url['path'] = ''; |
|
193 | + if (empty($parsed_url['path']) || !$local) { |
|
194 | + $parsed_url['path'] = ''; |
|
195 | + } |
|
187 | 196 | |
188 | - if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) |
|
189 | - $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
197 | + if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) { |
|
198 | + $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
199 | + } |
|
190 | 200 | |
191 | 201 | // Globalize cookies across domains (filter out IP-addresses)? |
192 | - elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
193 | - $parsed_url['host'] = '.' . $parts[1]; |
|
202 | + elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
203 | + $parsed_url['host'] = '.' . $parts[1]; |
|
204 | + } |
|
194 | 205 | |
195 | 206 | // We shouldn't use a host at all if both options are off. |
196 | - elseif (!$local && !$global) |
|
197 | - $parsed_url['host'] = ''; |
|
207 | + elseif (!$local && !$global) { |
|
208 | + $parsed_url['host'] = ''; |
|
209 | + } |
|
198 | 210 | |
199 | 211 | // The host also shouldn't be set if there aren't any dots in it. |
200 | - elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) |
|
201 | - $parsed_url['host'] = ''; |
|
212 | + elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) { |
|
213 | + $parsed_url['host'] = ''; |
|
214 | + } |
|
202 | 215 | |
203 | 216 | return array($parsed_url['host'], $parsed_url['path'] . '/'); |
204 | 217 | } |
@@ -217,8 +230,9 @@ discard block |
||
217 | 230 | createToken('login'); |
218 | 231 | |
219 | 232 | // Never redirect to an attachment |
220 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
221 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
233 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
234 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
235 | + } |
|
222 | 236 | |
223 | 237 | $context['sub_template'] = 'kick_guest'; |
224 | 238 | $context['page_title'] = $txt['login']; |
@@ -273,10 +287,12 @@ discard block |
||
273 | 287 | $txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']); |
274 | 288 | log_error($txt['security_wrong'], 'critical'); |
275 | 289 | |
276 | - if (isset($_POST[$type . '_hash_pass'])) |
|
277 | - unset($_POST[$type . '_hash_pass']); |
|
278 | - if (isset($_POST[$type . '_pass'])) |
|
279 | - unset($_POST[$type . '_pass']); |
|
290 | + if (isset($_POST[$type . '_hash_pass'])) { |
|
291 | + unset($_POST[$type . '_hash_pass']); |
|
292 | + } |
|
293 | + if (isset($_POST[$type . '_pass'])) { |
|
294 | + unset($_POST[$type . '_pass']); |
|
295 | + } |
|
280 | 296 | |
281 | 297 | $context['incorrect_password'] = true; |
282 | 298 | } |
@@ -289,15 +305,17 @@ discard block |
||
289 | 305 | |
290 | 306 | // Now go through $_POST. Make sure the session hash is sent. |
291 | 307 | $_POST[$context['session_var']] = $context['session_id']; |
292 | - foreach ($_POST as $k => $v) |
|
293 | - $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
308 | + foreach ($_POST as $k => $v) { |
|
309 | + $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
310 | + } |
|
294 | 311 | |
295 | 312 | // Now we'll use the admin_login sub template of the Login template. |
296 | 313 | $context['sub_template'] = 'admin_login'; |
297 | 314 | |
298 | 315 | // And title the page something like "Login". |
299 | - if (!isset($context['page_title'])) |
|
300 | - $context['page_title'] = $txt['login']; |
|
316 | + if (!isset($context['page_title'])) { |
|
317 | + $context['page_title'] = $txt['login']; |
|
318 | + } |
|
301 | 319 | |
302 | 320 | // The type of action. |
303 | 321 | $context['sessionCheckType'] = $type; |
@@ -320,14 +338,15 @@ discard block |
||
320 | 338 | { |
321 | 339 | global $smcFunc; |
322 | 340 | |
323 | - if (!is_array($v)) |
|
324 | - return ' |
|
341 | + if (!is_array($v)) { |
|
342 | + return ' |
|
325 | 343 | <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '"', '<' => '<', '>' => '>')) . '">'; |
326 | - else |
|
344 | + } else |
|
327 | 345 | { |
328 | 346 | $ret = ''; |
329 | - foreach ($v as $k2 => $v2) |
|
330 | - $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
347 | + foreach ($v as $k2 => $v2) { |
|
348 | + $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
349 | + } |
|
331 | 350 | |
332 | 351 | return $ret; |
333 | 352 | } |
@@ -354,18 +373,20 @@ discard block |
||
354 | 373 | foreach ($get as $k => $v) |
355 | 374 | { |
356 | 375 | // Only if it's not already in the $scripturl! |
357 | - if (!isset($temp[$k])) |
|
358 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
376 | + if (!isset($temp[$k])) { |
|
377 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
378 | + } |
|
359 | 379 | // If it changed, put it out there, but with an ampersand. |
360 | - elseif ($temp[$k] != $get[$k]) |
|
361 | - $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
380 | + elseif ($temp[$k] != $get[$k]) { |
|
381 | + $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
382 | + } |
|
362 | 383 | } |
363 | - } |
|
364 | - else |
|
384 | + } else |
|
365 | 385 | { |
366 | 386 | // Add up all the data from $_GET into get_data. |
367 | - foreach ($get as $k => $v) |
|
368 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
387 | + foreach ($get as $k => $v) { |
|
388 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
389 | + } |
|
369 | 390 | } |
370 | 391 | |
371 | 392 | $query_string = substr($query_string, 0, -1); |
@@ -388,8 +409,9 @@ discard block |
||
388 | 409 | global $scripturl, $user_info, $smcFunc; |
389 | 410 | |
390 | 411 | // If it's not already an array, make it one. |
391 | - if (!is_array($names)) |
|
392 | - $names = explode(',', $names); |
|
412 | + if (!is_array($names)) { |
|
413 | + $names = explode(',', $names); |
|
414 | + } |
|
393 | 415 | |
394 | 416 | $maybe_email = false; |
395 | 417 | foreach ($names as $i => $name) |
@@ -400,10 +422,11 @@ discard block |
||
400 | 422 | $maybe_email |= strpos($name, '@') !== false; |
401 | 423 | |
402 | 424 | // Make it so standard wildcards will work. (* and ?) |
403 | - if ($use_wildcards) |
|
404 | - $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
405 | - else |
|
406 | - $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
425 | + if ($use_wildcards) { |
|
426 | + $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
427 | + } else { |
|
428 | + $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
429 | + } |
|
407 | 430 | } |
408 | 431 | |
409 | 432 | // What are we using to compare? |
@@ -413,11 +436,12 @@ discard block |
||
413 | 436 | $results = array(); |
414 | 437 | |
415 | 438 | // This ensures you can't search someones email address if you can't see it. |
416 | - if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) |
|
417 | - $email_condition = ' |
|
439 | + if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) { |
|
440 | + $email_condition = ' |
|
418 | 441 | OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')'; |
419 | - else |
|
420 | - $email_condition = ''; |
|
442 | + } else { |
|
443 | + $email_condition = ''; |
|
444 | + } |
|
421 | 445 | |
422 | 446 | // Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise. |
423 | 447 | $member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name'; |
@@ -475,10 +499,11 @@ discard block |
||
475 | 499 | $context['template_layers'] = array(); |
476 | 500 | $context['sub_template'] = 'find_members'; |
477 | 501 | |
478 | - if (isset($_REQUEST['search'])) |
|
479 | - $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
480 | - else |
|
481 | - $_REQUEST['start'] = 0; |
|
502 | + if (isset($_REQUEST['search'])) { |
|
503 | + $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
504 | + } else { |
|
505 | + $_REQUEST['start'] = 0; |
|
506 | + } |
|
482 | 507 | |
483 | 508 | // Allow the user to pass the input to be added to to the box. |
484 | 509 | $context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to'; |
@@ -519,10 +544,10 @@ discard block |
||
519 | 544 | ); |
520 | 545 | |
521 | 546 | $context['results'] = array_slice($context['results'], $_REQUEST['start'], 7); |
547 | + } else { |
|
548 | + $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
549 | + } |
|
522 | 550 | } |
523 | - else |
|
524 | - $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
525 | -} |
|
526 | 551 | |
527 | 552 | /** |
528 | 553 | * Outputs each member name on its own line. |
@@ -538,8 +563,9 @@ discard block |
||
538 | 563 | $_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])); |
539 | 564 | $_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&' => '&')); |
540 | 565 | |
541 | - if (function_exists('iconv')) |
|
542 | - header('Content-Type: text/plain; charset=UTF-8'); |
|
566 | + if (function_exists('iconv')) { |
|
567 | + header('Content-Type: text/plain; charset=UTF-8'); |
|
568 | + } |
|
543 | 569 | |
544 | 570 | $request = $smcFunc['db_query']('', ' |
545 | 571 | SELECT real_name |
@@ -559,14 +585,16 @@ discard block |
||
559 | 585 | if (function_exists('iconv')) |
560 | 586 | { |
561 | 587 | $utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']); |
562 | - if ($utf8) |
|
563 | - $row['real_name'] = $utf8; |
|
588 | + if ($utf8) { |
|
589 | + $row['real_name'] = $utf8; |
|
590 | + } |
|
564 | 591 | } |
565 | 592 | |
566 | 593 | $row['real_name'] = strtr($row['real_name'], array('&' => '&', '<' => '<', '>' => '>', '"' => '"')); |
567 | 594 | |
568 | - if (preg_match('~&#\d+;~', $row['real_name']) != 0) |
|
569 | - $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
595 | + if (preg_match('~&#\d+;~', $row['real_name']) != 0) { |
|
596 | + $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
597 | + } |
|
570 | 598 | |
571 | 599 | echo $row['real_name'], "\n"; |
572 | 600 | } |
@@ -623,9 +651,9 @@ discard block |
||
623 | 651 | |
624 | 652 | // Update the database... |
625 | 653 | updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1)); |
654 | + } else { |
|
655 | + updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
626 | 656 | } |
627 | - else |
|
628 | - updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
629 | 657 | |
630 | 658 | call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword)); |
631 | 659 | |
@@ -656,31 +684,37 @@ discard block |
||
656 | 684 | $errors = array(); |
657 | 685 | |
658 | 686 | // Don't use too long a name. |
659 | - if ($smcFunc['strlen']($username) > 25) |
|
660 | - $errors[] = array('lang', 'error_long_name'); |
|
687 | + if ($smcFunc['strlen']($username) > 25) { |
|
688 | + $errors[] = array('lang', 'error_long_name'); |
|
689 | + } |
|
661 | 690 | |
662 | 691 | // No name?! How can you register with no name? |
663 | - if ($username == '') |
|
664 | - $errors[] = array('lang', 'need_username'); |
|
692 | + if ($username == '') { |
|
693 | + $errors[] = array('lang', 'need_username'); |
|
694 | + } |
|
665 | 695 | |
666 | 696 | // Only these characters are permitted. |
667 | - if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) |
|
668 | - $errors[] = array('lang', 'error_invalid_characters_username'); |
|
697 | + if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) { |
|
698 | + $errors[] = array('lang', 'error_invalid_characters_username'); |
|
699 | + } |
|
669 | 700 | |
670 | - if (stristr($username, $txt['guest_title']) !== false) |
|
671 | - $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
701 | + if (stristr($username, $txt['guest_title']) !== false) { |
|
702 | + $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
703 | + } |
|
672 | 704 | |
673 | 705 | if ($check_reserved_name) |
674 | 706 | { |
675 | 707 | require_once($sourcedir . '/Subs-Members.php'); |
676 | - if (isReservedName($username, $memID, false)) |
|
677 | - $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
708 | + if (isReservedName($username, $memID, false)) { |
|
709 | + $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
710 | + } |
|
678 | 711 | } |
679 | 712 | |
680 | - if ($return_error) |
|
681 | - return $errors; |
|
682 | - elseif (empty($errors)) |
|
683 | - return null; |
|
713 | + if ($return_error) { |
|
714 | + return $errors; |
|
715 | + } elseif (empty($errors)) { |
|
716 | + return null; |
|
717 | + } |
|
684 | 718 | |
685 | 719 | loadLanguage('Errors'); |
686 | 720 | $error = $errors[0]; |
@@ -706,22 +740,26 @@ discard block |
||
706 | 740 | global $modSettings, $smcFunc; |
707 | 741 | |
708 | 742 | // Perform basic requirements first. |
709 | - if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) |
|
710 | - return 'short'; |
|
743 | + if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) { |
|
744 | + return 'short'; |
|
745 | + } |
|
711 | 746 | |
712 | 747 | // Is this enough? |
713 | - if (empty($modSettings['password_strength'])) |
|
714 | - return null; |
|
748 | + if (empty($modSettings['password_strength'])) { |
|
749 | + return null; |
|
750 | + } |
|
715 | 751 | |
716 | 752 | // Otherwise, perform the medium strength test - checking if password appears in the restricted string. |
717 | - if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) |
|
718 | - return 'restricted_words'; |
|
719 | - elseif ($smcFunc['strpos']($password, $username) !== false) |
|
720 | - return 'restricted_words'; |
|
753 | + if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) { |
|
754 | + return 'restricted_words'; |
|
755 | + } elseif ($smcFunc['strpos']($password, $username) !== false) { |
|
756 | + return 'restricted_words'; |
|
757 | + } |
|
721 | 758 | |
722 | 759 | // If just medium, we're done. |
723 | - if ($modSettings['password_strength'] == 1) |
|
724 | - return null; |
|
760 | + if ($modSettings['password_strength'] == 1) { |
|
761 | + return null; |
|
762 | + } |
|
725 | 763 | |
726 | 764 | // Otherwise, hard test next, check for numbers and letters, uppercase too. |
727 | 765 | $good = preg_match('~(\D\d|\d\D)~', $password) != 0; |
@@ -753,14 +791,16 @@ discard block |
||
753 | 791 | ) |
754 | 792 | ); |
755 | 793 | $groups = array(); |
756 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
757 | - $groups[] = $row['id_group']; |
|
794 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
795 | + $groups[] = $row['id_group']; |
|
796 | + } |
|
758 | 797 | $smcFunc['db_free_result']($request); |
759 | 798 | |
760 | - if (empty($groups)) |
|
761 | - $group_query = '0=1'; |
|
762 | - else |
|
763 | - $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
799 | + if (empty($groups)) { |
|
800 | + $group_query = '0=1'; |
|
801 | + } else { |
|
802 | + $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
803 | + } |
|
764 | 804 | } |
765 | 805 | |
766 | 806 | // Then, same again, just the boards this time! |
@@ -770,10 +810,11 @@ discard block |
||
770 | 810 | { |
771 | 811 | $boards = boardsAllowedTo('moderate_board', true); |
772 | 812 | |
773 | - if (empty($boards)) |
|
774 | - $board_query = '0=1'; |
|
775 | - else |
|
776 | - $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
813 | + if (empty($boards)) { |
|
814 | + $board_query = '0=1'; |
|
815 | + } else { |
|
816 | + $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
817 | + } |
|
777 | 818 | } |
778 | 819 | |
779 | 820 | // What boards are they the moderator of? |
@@ -788,8 +829,9 @@ discard block |
||
788 | 829 | 'current_member' => $user_info['id'], |
789 | 830 | ) |
790 | 831 | ); |
791 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
792 | - $boards_mod[] = $row['id_board']; |
|
832 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
833 | + $boards_mod[] = $row['id_board']; |
|
834 | + } |
|
793 | 835 | $smcFunc['db_free_result']($request); |
794 | 836 | |
795 | 837 | // Can any of the groups they're in moderate any of the boards? |
@@ -801,8 +843,9 @@ discard block |
||
801 | 843 | 'groups' => $user_info['groups'], |
802 | 844 | ) |
803 | 845 | ); |
804 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
805 | - $boards_mod[] = $row['id_board']; |
|
846 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
847 | + $boards_mod[] = $row['id_board']; |
|
848 | + } |
|
806 | 849 | $smcFunc['db_free_result']($request); |
807 | 850 | |
808 | 851 | // Just in case we've got duplicates here... |
@@ -847,10 +890,12 @@ discard block |
||
847 | 890 | global $modSettings; |
848 | 891 | |
849 | 892 | // In case a customization wants to override the default settings |
850 | - if ($httponly === null) |
|
851 | - $httponly = !empty($modSettings['httponlyCookies']); |
|
852 | - if ($secure === null) |
|
853 | - $secure = !empty($modSettings['secureCookies']); |
|
893 | + if ($httponly === null) { |
|
894 | + $httponly = !empty($modSettings['httponlyCookies']); |
|
895 | + } |
|
896 | + if ($secure === null) { |
|
897 | + $secure = !empty($modSettings['secureCookies']); |
|
898 | + } |
|
854 | 899 | |
855 | 900 | // Intercept cookie? |
856 | 901 | call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly)); |
@@ -870,8 +915,9 @@ discard block |
||
870 | 915 | function hash_password($username, $password, $cost = null) |
871 | 916 | { |
872 | 917 | global $sourcedir, $smcFunc, $modSettings; |
873 | - if (!function_exists('password_hash')) |
|
874 | - require_once($sourcedir . '/Subs-Password.php'); |
|
918 | + if (!function_exists('password_hash')) { |
|
919 | + require_once($sourcedir . '/Subs-Password.php'); |
|
920 | + } |
|
875 | 921 | |
876 | 922 | $cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost; |
877 | 923 | |
@@ -903,8 +949,9 @@ discard block |
||
903 | 949 | function hash_verify_password($username, $password, $hash) |
904 | 950 | { |
905 | 951 | global $sourcedir, $smcFunc; |
906 | - if (!function_exists('password_verify')) |
|
907 | - require_once($sourcedir . '/Subs-Password.php'); |
|
952 | + if (!function_exists('password_verify')) { |
|
953 | + require_once($sourcedir . '/Subs-Password.php'); |
|
954 | + } |
|
908 | 955 | |
909 | 956 | return password_verify($smcFunc['strtolower']($username) . $password, $hash); |
910 | 957 | } |
@@ -1697,8 +1697,7 @@ discard block |
||
1697 | 1697 | updateStats('topic'); |
1698 | 1698 | |
1699 | 1699 | // This function is needed to do the updateStats('subject') call. |
1700 | - $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
|
1701 | - function($string){ |
|
1700 | + $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
|
1702 | 1701 | global $sourcedir; |
1703 | 1702 | if (function_exists('mb_strtolower')) |
1704 | 1703 | return mb_strtolower($string, 'UTF-8'); |
@@ -1767,7 +1766,7 @@ discard block |
||
1767 | 1766 | if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}') |
1768 | 1767 | { |
1769 | 1768 | // Set the ten lines to nothing. |
1770 | - for ($j=0; $j < 10; $j++) |
|
1769 | + for ($j = 0; $j < 10; $j++) |
|
1771 | 1770 | $settingsArray[$i++] = ''; |
1772 | 1771 | |
1773 | 1772 | continue; |
@@ -20,8 +20,9 @@ discard block |
||
20 | 20 | // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;"> |
21 | 21 | |
22 | 22 | // Let's pull in useful classes |
23 | -if (!defined('SMF')) |
|
23 | +if (!defined('SMF')) { |
|
24 | 24 | define('SMF', 1); |
25 | +} |
|
25 | 26 | |
26 | 27 | require_once('Sources/Class-Package.php'); |
27 | 28 | |
@@ -63,10 +64,11 @@ discard block |
||
63 | 64 | |
64 | 65 | list ($charcode) = pg_fetch_row($request); |
65 | 66 | |
66 | - if ($charcode == 'UTF8') |
|
67 | - return true; |
|
68 | - else |
|
69 | - return false; |
|
67 | + if ($charcode == 'UTF8') { |
|
68 | + return true; |
|
69 | + } else { |
|
70 | + return false; |
|
71 | + } |
|
70 | 72 | }, |
71 | 73 | 'utf8_version' => '8.0', |
72 | 74 | 'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;', |
@@ -76,12 +78,14 @@ discard block |
||
76 | 78 | $value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value); |
77 | 79 | |
78 | 80 | // Is it reserved? |
79 | - if ($value == 'pg_') |
|
80 | - return $txt['error_db_prefix_reserved']; |
|
81 | + if ($value == 'pg_') { |
|
82 | + return $txt['error_db_prefix_reserved']; |
|
83 | + } |
|
81 | 84 | |
82 | 85 | // Is the prefix numeric? |
83 | - if (preg_match('~^\d~', $value)) |
|
84 | - return $txt['error_db_prefix_numeric']; |
|
86 | + if (preg_match('~^\d~', $value)) { |
|
87 | + return $txt['error_db_prefix_numeric']; |
|
88 | + } |
|
85 | 89 | |
86 | 90 | return true; |
87 | 91 | }, |
@@ -128,10 +132,11 @@ discard block |
||
128 | 132 | $incontext['skip'] = false; |
129 | 133 | |
130 | 134 | // Call the step and if it returns false that means pause! |
131 | - if (function_exists($step[2]) && $step[2]() === false) |
|
132 | - break; |
|
133 | - elseif (function_exists($step[2])) |
|
134 | - $incontext['current_step']++; |
|
135 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
136 | + break; |
|
137 | + } elseif (function_exists($step[2])) { |
|
138 | + $incontext['current_step']++; |
|
139 | + } |
|
135 | 140 | |
136 | 141 | // No warnings pass on. |
137 | 142 | $incontext['warning'] = ''; |
@@ -147,8 +152,9 @@ discard block |
||
147 | 152 | global $databases; |
148 | 153 | |
149 | 154 | // Just so people using older versions of PHP aren't left in the cold. |
150 | - if (!isset($_SERVER['PHP_SELF'])) |
|
151 | - $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
155 | + if (!isset($_SERVER['PHP_SELF'])) { |
|
156 | + $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
157 | + } |
|
152 | 158 | |
153 | 159 | // Enable error reporting for fatal errors. |
154 | 160 | error_reporting(E_ERROR | E_PARSE); |
@@ -164,21 +170,23 @@ discard block |
||
164 | 170 | { |
165 | 171 | ob_start(); |
166 | 172 | |
167 | - if (ini_get('session.save_handler') == 'user') |
|
168 | - @ini_set('session.save_handler', 'files'); |
|
169 | - if (function_exists('session_start')) |
|
170 | - @session_start(); |
|
171 | - } |
|
172 | - else |
|
173 | + if (ini_get('session.save_handler') == 'user') { |
|
174 | + @ini_set('session.save_handler', 'files'); |
|
175 | + } |
|
176 | + if (function_exists('session_start')) { |
|
177 | + @session_start(); |
|
178 | + } |
|
179 | + } else |
|
173 | 180 | { |
174 | 181 | ob_start('ob_gzhandler'); |
175 | 182 | |
176 | - if (ini_get('session.save_handler') == 'user') |
|
177 | - @ini_set('session.save_handler', 'files'); |
|
183 | + if (ini_get('session.save_handler') == 'user') { |
|
184 | + @ini_set('session.save_handler', 'files'); |
|
185 | + } |
|
178 | 186 | session_start(); |
179 | 187 | |
180 | - if (!headers_sent()) |
|
181 | - echo '<!DOCTYPE html> |
|
188 | + if (!headers_sent()) { |
|
189 | + echo '<!DOCTYPE html> |
|
182 | 190 | <html> |
183 | 191 | <head> |
184 | 192 | <title>', htmlspecialchars($_GET['pass_string']), '</title> |
@@ -187,14 +195,16 @@ discard block |
||
187 | 195 | <strong>', htmlspecialchars($_GET['pass_string']), '</strong> |
188 | 196 | </body> |
189 | 197 | </html>'; |
198 | + } |
|
190 | 199 | exit; |
191 | 200 | } |
192 | 201 | |
193 | 202 | // Add slashes, as long as they aren't already being added. |
194 | - if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) |
|
195 | - foreach ($_POST as $k => $v) |
|
203 | + if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) { |
|
204 | + foreach ($_POST as $k => $v) |
|
196 | 205 | if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false) |
197 | 206 | $_POST[$k] = addslashes($v); |
207 | + } |
|
198 | 208 | |
199 | 209 | // This is really quite simple; if ?delete is on the URL, delete the installer... |
200 | 210 | if (isset($_GET['delete'])) |
@@ -215,8 +225,7 @@ discard block |
||
215 | 225 | $ftp->close(); |
216 | 226 | |
217 | 227 | unset($_SESSION['installer_temp_ftp']); |
218 | - } |
|
219 | - else |
|
228 | + } else |
|
220 | 229 | { |
221 | 230 | @unlink(__FILE__); |
222 | 231 | |
@@ -230,10 +239,11 @@ discard block |
||
230 | 239 | // Now just redirect to a blank.png... |
231 | 240 | $secure = false; |
232 | 241 | |
233 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
234 | - $secure = true; |
|
235 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
236 | - $secure = true; |
|
242 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
243 | + $secure = true; |
|
244 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
245 | + $secure = true; |
|
246 | + } |
|
237 | 247 | |
238 | 248 | header('Location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png'); |
239 | 249 | exit; |
@@ -244,10 +254,11 @@ discard block |
||
244 | 254 | { |
245 | 255 | // Get PHP's default timezone, if set |
246 | 256 | $ini_tz = ini_get('date.timezone'); |
247 | - if (!empty($ini_tz)) |
|
248 | - $timezone_id = $ini_tz; |
|
249 | - else |
|
250 | - $timezone_id = ''; |
|
257 | + if (!empty($ini_tz)) { |
|
258 | + $timezone_id = $ini_tz; |
|
259 | + } else { |
|
260 | + $timezone_id = ''; |
|
261 | + } |
|
251 | 262 | |
252 | 263 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
253 | 264 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -277,8 +288,9 @@ discard block |
||
277 | 288 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
278 | 289 | while ($entry = $dir->read()) |
279 | 290 | { |
280 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
281 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
291 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
292 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
293 | + } |
|
282 | 294 | } |
283 | 295 | $dir->close(); |
284 | 296 | } |
@@ -313,10 +325,11 @@ discard block |
||
313 | 325 | } |
314 | 326 | |
315 | 327 | // Override the language file? |
316 | - if (isset($_GET['lang_file'])) |
|
317 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
318 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
319 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
328 | + if (isset($_GET['lang_file'])) { |
|
329 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
330 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
331 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
332 | + } |
|
320 | 333 | |
321 | 334 | // Make sure it exists, if it doesn't reset it. |
322 | 335 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -325,8 +338,9 @@ discard block |
||
325 | 338 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
326 | 339 | |
327 | 340 | // If we have english and some other language, use the other language. We Americans hate english :P. |
328 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
329 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
341 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
342 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
343 | + } |
|
330 | 344 | } |
331 | 345 | |
332 | 346 | // And now include the actual language file itself. |
@@ -343,15 +357,18 @@ discard block |
||
343 | 357 | global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings; |
344 | 358 | global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist; |
345 | 359 | |
346 | - if (empty($sourcedir)) |
|
347 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
360 | + if (empty($sourcedir)) { |
|
361 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
362 | + } |
|
348 | 363 | |
349 | 364 | // Need this to check whether we need the database password. |
350 | 365 | require(dirname(__FILE__) . '/Settings.php'); |
351 | - if (!defined('SMF')) |
|
352 | - define('SMF', 1); |
|
353 | - if (empty($smcFunc)) |
|
354 | - $smcFunc = array(); |
|
366 | + if (!defined('SMF')) { |
|
367 | + define('SMF', 1); |
|
368 | + } |
|
369 | + if (empty($smcFunc)) { |
|
370 | + $smcFunc = array(); |
|
371 | + } |
|
355 | 372 | |
356 | 373 | $modSettings['disableQueryCheck'] = true; |
357 | 374 | |
@@ -359,8 +376,9 @@ discard block |
||
359 | 376 | if (!$db_connection) |
360 | 377 | { |
361 | 378 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
362 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
363 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
379 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
380 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
381 | + } |
|
364 | 382 | |
365 | 383 | $db_options = array('persist' => $db_persist); |
366 | 384 | $port = ''; |
@@ -371,19 +389,20 @@ discard block |
||
371 | 389 | if ($db_type == 'mysql') |
372 | 390 | { |
373 | 391 | $port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port']; |
374 | - } |
|
375 | - elseif ($db_type == 'postgresql') |
|
392 | + } elseif ($db_type == 'postgresql') |
|
376 | 393 | { |
377 | 394 | // PostgreSQL doesn't have a default port setting in php.ini, so just check against the default |
378 | 395 | $port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port']; |
379 | 396 | } |
380 | 397 | } |
381 | 398 | |
382 | - if (!empty($port)) |
|
383 | - $db_options['port'] = $port; |
|
399 | + if (!empty($port)) { |
|
400 | + $db_options['port'] = $port; |
|
401 | + } |
|
384 | 402 | |
385 | - if (!$db_connection) |
|
386 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
403 | + if (!$db_connection) { |
|
404 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
405 | + } |
|
387 | 406 | } |
388 | 407 | } |
389 | 408 | |
@@ -411,8 +430,9 @@ discard block |
||
411 | 430 | // @todo REMOVE THIS!! |
412 | 431 | else |
413 | 432 | { |
414 | - if (function_exists('doStep' . $_GET['step'])) |
|
415 | - call_user_func('doStep' . $_GET['step']); |
|
433 | + if (function_exists('doStep' . $_GET['step'])) { |
|
434 | + call_user_func('doStep' . $_GET['step']); |
|
435 | + } |
|
416 | 436 | } |
417 | 437 | // Show the footer. |
418 | 438 | template_install_below(); |
@@ -430,8 +450,9 @@ discard block |
||
430 | 450 | $incontext['sub_template'] = 'welcome_message'; |
431 | 451 | |
432 | 452 | // Done the submission? |
433 | - if (isset($_POST['contbutt'])) |
|
434 | - return true; |
|
453 | + if (isset($_POST['contbutt'])) { |
|
454 | + return true; |
|
455 | + } |
|
435 | 456 | |
436 | 457 | // See if we think they have already installed it? |
437 | 458 | if (is_readable(dirname(__FILE__) . '/Settings.php')) |
@@ -439,14 +460,17 @@ discard block |
||
439 | 460 | $probably_installed = 0; |
440 | 461 | foreach (file(dirname(__FILE__) . '/Settings.php') as $line) |
441 | 462 | { |
442 | - if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) |
|
443 | - $probably_installed++; |
|
444 | - if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) |
|
445 | - $probably_installed++; |
|
463 | + if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) { |
|
464 | + $probably_installed++; |
|
465 | + } |
|
466 | + if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) { |
|
467 | + $probably_installed++; |
|
468 | + } |
|
446 | 469 | } |
447 | 470 | |
448 | - if ($probably_installed == 2) |
|
449 | - $incontext['warning'] = $txt['error_already_installed']; |
|
471 | + if ($probably_installed == 2) { |
|
472 | + $incontext['warning'] = $txt['error_already_installed']; |
|
473 | + } |
|
450 | 474 | } |
451 | 475 | |
452 | 476 | // Is some database support even compiled in? |
@@ -461,45 +485,54 @@ discard block |
||
461 | 485 | $databases[$key]['supported'] = false; |
462 | 486 | $notFoundSQLFile = true; |
463 | 487 | $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql'); |
488 | + } else { |
|
489 | + $incontext['supported_databases'][] = $db; |
|
464 | 490 | } |
465 | - else |
|
466 | - $incontext['supported_databases'][] = $db; |
|
467 | 491 | } |
468 | 492 | } |
469 | 493 | |
470 | 494 | // Check the PHP version. |
471 | - if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) |
|
472 | - $error = 'error_php_too_low'; |
|
495 | + if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) { |
|
496 | + $error = 'error_php_too_low'; |
|
497 | + } |
|
473 | 498 | // Make sure we have a supported database |
474 | - elseif (empty($incontext['supported_databases'])) |
|
475 | - $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
499 | + elseif (empty($incontext['supported_databases'])) { |
|
500 | + $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
501 | + } |
|
476 | 502 | // How about session support? Some crazy sysadmin remove it? |
477 | - elseif (!function_exists('session_start')) |
|
478 | - $error = 'error_session_missing'; |
|
503 | + elseif (!function_exists('session_start')) { |
|
504 | + $error = 'error_session_missing'; |
|
505 | + } |
|
479 | 506 | // Make sure they uploaded all the files. |
480 | - elseif (!file_exists(dirname(__FILE__) . '/index.php')) |
|
481 | - $error = 'error_missing_files'; |
|
507 | + elseif (!file_exists(dirname(__FILE__) . '/index.php')) { |
|
508 | + $error = 'error_missing_files'; |
|
509 | + } |
|
482 | 510 | // Very simple check on the session.save_path for Windows. |
483 | 511 | // @todo Move this down later if they don't use database-driven sessions? |
484 | - elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') |
|
485 | - $error = 'error_session_save_path'; |
|
512 | + elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') { |
|
513 | + $error = 'error_session_save_path'; |
|
514 | + } |
|
486 | 515 | |
487 | 516 | // Since each of the three messages would look the same, anyway... |
488 | - if (isset($error)) |
|
489 | - $incontext['error'] = $txt[$error]; |
|
517 | + if (isset($error)) { |
|
518 | + $incontext['error'] = $txt[$error]; |
|
519 | + } |
|
490 | 520 | |
491 | 521 | // Mod_security blocks everything that smells funny. Let SMF handle security. |
492 | - if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) |
|
493 | - $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
522 | + if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) { |
|
523 | + $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
524 | + } |
|
494 | 525 | |
495 | 526 | // Confirm mbstring is loaded... |
496 | - if (!extension_loaded('mbstring')) |
|
497 | - $incontext['error'] = $txt['install_no_mbstring']; |
|
527 | + if (!extension_loaded('mbstring')) { |
|
528 | + $incontext['error'] = $txt['install_no_mbstring']; |
|
529 | + } |
|
498 | 530 | |
499 | 531 | // Check for https stream support. |
500 | 532 | $supported_streams = stream_get_wrappers(); |
501 | - if (!in_array('https', $supported_streams)) |
|
502 | - $incontext['warning'] = $txt['install_no_https']; |
|
533 | + if (!in_array('https', $supported_streams)) { |
|
534 | + $incontext['warning'] = $txt['install_no_https']; |
|
535 | + } |
|
503 | 536 | |
504 | 537 | return false; |
505 | 538 | } |
@@ -525,12 +558,14 @@ discard block |
||
525 | 558 | 'db_last_error.php', |
526 | 559 | ); |
527 | 560 | |
528 | - foreach ($incontext['detected_languages'] as $lang => $temp) |
|
529 | - $extra_files[] = 'Themes/default/languages/' . $lang; |
|
561 | + foreach ($incontext['detected_languages'] as $lang => $temp) { |
|
562 | + $extra_files[] = 'Themes/default/languages/' . $lang; |
|
563 | + } |
|
530 | 564 | |
531 | 565 | // With mod_security installed, we could attempt to fix it with .htaccess. |
532 | - if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) |
|
533 | - $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
566 | + if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) { |
|
567 | + $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
568 | + } |
|
534 | 569 | |
535 | 570 | $failed_files = array(); |
536 | 571 | |
@@ -542,20 +577,23 @@ discard block |
||
542 | 577 | foreach ($writable_files as $file) |
543 | 578 | { |
544 | 579 | // Some files won't exist, try to address up front |
545 | - if (!file_exists(dirname(__FILE__) . '/' . $file)) |
|
546 | - @touch(dirname(__FILE__) . '/' . $file); |
|
580 | + if (!file_exists(dirname(__FILE__) . '/' . $file)) { |
|
581 | + @touch(dirname(__FILE__) . '/' . $file); |
|
582 | + } |
|
547 | 583 | // NOW do the writable check... |
548 | 584 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
549 | 585 | { |
550 | 586 | @chmod(dirname(__FILE__) . '/' . $file, 0755); |
551 | 587 | |
552 | 588 | // Well, 755 hopefully worked... if not, try 777. |
553 | - if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) |
|
554 | - $failed_files[] = $file; |
|
589 | + if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) { |
|
590 | + $failed_files[] = $file; |
|
591 | + } |
|
555 | 592 | } |
556 | 593 | } |
557 | - foreach ($extra_files as $file) |
|
558 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
594 | + foreach ($extra_files as $file) { |
|
595 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
596 | + } |
|
559 | 597 | } |
560 | 598 | // Windows is trickier. Let's try opening for r+... |
561 | 599 | else |
@@ -565,30 +603,35 @@ discard block |
||
565 | 603 | foreach ($writable_files as $file) |
566 | 604 | { |
567 | 605 | // Folders can't be opened for write... but the index.php in them can ;) |
568 | - if (is_dir(dirname(__FILE__) . '/' . $file)) |
|
569 | - $file .= '/index.php'; |
|
606 | + if (is_dir(dirname(__FILE__) . '/' . $file)) { |
|
607 | + $file .= '/index.php'; |
|
608 | + } |
|
570 | 609 | |
571 | 610 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
572 | 611 | @chmod(dirname(__FILE__) . '/' . $file, 0777); |
573 | 612 | $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+'); |
574 | 613 | |
575 | 614 | // Hmm, okay, try just for write in that case... |
576 | - if (!is_resource($fp)) |
|
577 | - $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
615 | + if (!is_resource($fp)) { |
|
616 | + $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
617 | + } |
|
578 | 618 | |
579 | - if (!is_resource($fp)) |
|
580 | - $failed_files[] = $file; |
|
619 | + if (!is_resource($fp)) { |
|
620 | + $failed_files[] = $file; |
|
621 | + } |
|
581 | 622 | |
582 | 623 | @fclose($fp); |
583 | 624 | } |
584 | - foreach ($extra_files as $file) |
|
585 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
625 | + foreach ($extra_files as $file) { |
|
626 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
627 | + } |
|
586 | 628 | } |
587 | 629 | |
588 | 630 | $failure = count($failed_files) >= 1; |
589 | 631 | |
590 | - if (!isset($_SERVER)) |
|
591 | - return !$failure; |
|
632 | + if (!isset($_SERVER)) { |
|
633 | + return !$failure; |
|
634 | + } |
|
592 | 635 | |
593 | 636 | // Put the list into context. |
594 | 637 | $incontext['failed_files'] = $failed_files; |
@@ -636,19 +679,23 @@ discard block |
||
636 | 679 | |
637 | 680 | if (!isset($ftp) || $ftp->error !== false) |
638 | 681 | { |
639 | - if (!isset($ftp)) |
|
640 | - $ftp = new ftp_connection(null); |
|
682 | + if (!isset($ftp)) { |
|
683 | + $ftp = new ftp_connection(null); |
|
684 | + } |
|
641 | 685 | // Save the error so we can mess with listing... |
642 | - elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) |
|
643 | - $incontext['ftp_errors'][] = $ftp->last_message; |
|
686 | + elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) { |
|
687 | + $incontext['ftp_errors'][] = $ftp->last_message; |
|
688 | + } |
|
644 | 689 | |
645 | 690 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
646 | 691 | |
647 | - if (empty($_POST['ftp_path']) && $found_path) |
|
648 | - $_POST['ftp_path'] = $detect_path; |
|
692 | + if (empty($_POST['ftp_path']) && $found_path) { |
|
693 | + $_POST['ftp_path'] = $detect_path; |
|
694 | + } |
|
649 | 695 | |
650 | - if (!isset($_POST['ftp_username'])) |
|
651 | - $_POST['ftp_username'] = $username; |
|
696 | + if (!isset($_POST['ftp_username'])) { |
|
697 | + $_POST['ftp_username'] = $username; |
|
698 | + } |
|
652 | 699 | |
653 | 700 | // Set the username etc, into context. |
654 | 701 | $incontext['ftp'] = array( |
@@ -660,8 +707,7 @@ discard block |
||
660 | 707 | ); |
661 | 708 | |
662 | 709 | return false; |
663 | - } |
|
664 | - else |
|
710 | + } else |
|
665 | 711 | { |
666 | 712 | $_SESSION['installer_temp_ftp'] = array( |
667 | 713 | 'server' => $_POST['ftp_server'], |
@@ -675,10 +721,12 @@ discard block |
||
675 | 721 | |
676 | 722 | foreach ($failed_files as $file) |
677 | 723 | { |
678 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
679 | - $ftp->chmod($file, 0755); |
|
680 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
681 | - $ftp->chmod($file, 0777); |
|
724 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
725 | + $ftp->chmod($file, 0755); |
|
726 | + } |
|
727 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
728 | + $ftp->chmod($file, 0777); |
|
729 | + } |
|
682 | 730 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
683 | 731 | { |
684 | 732 | $failed_files_updated[] = $file; |
@@ -734,15 +782,17 @@ discard block |
||
734 | 782 | |
735 | 783 | if (!$foundOne) |
736 | 784 | { |
737 | - if (isset($db['default_host'])) |
|
738 | - $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
785 | + if (isset($db['default_host'])) { |
|
786 | + $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
787 | + } |
|
739 | 788 | if (isset($db['default_user'])) |
740 | 789 | { |
741 | 790 | $incontext['db']['user'] = ini_get($db['default_user']); |
742 | 791 | $incontext['db']['name'] = ini_get($db['default_user']); |
743 | 792 | } |
744 | - if (isset($db['default_password'])) |
|
745 | - $incontext['db']['pass'] = ini_get($db['default_password']); |
|
793 | + if (isset($db['default_password'])) { |
|
794 | + $incontext['db']['pass'] = ini_get($db['default_password']); |
|
795 | + } |
|
746 | 796 | |
747 | 797 | // For simplicity and less confusion, leave the port blank by default |
748 | 798 | $incontext['db']['port'] = ''; |
@@ -761,10 +811,10 @@ discard block |
||
761 | 811 | $incontext['db']['server'] = $_POST['db_server']; |
762 | 812 | $incontext['db']['prefix'] = $_POST['db_prefix']; |
763 | 813 | |
764 | - if (!empty($_POST['db_port'])) |
|
765 | - $incontext['db']['port'] = $_POST['db_port']; |
|
766 | - } |
|
767 | - else |
|
814 | + if (!empty($_POST['db_port'])) { |
|
815 | + $incontext['db']['port'] = $_POST['db_port']; |
|
816 | + } |
|
817 | + } else |
|
768 | 818 | { |
769 | 819 | $incontext['db']['prefix'] = 'smf_'; |
770 | 820 | } |
@@ -800,10 +850,11 @@ discard block |
||
800 | 850 | if (!empty($_POST['db_port'])) |
801 | 851 | { |
802 | 852 | // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though. |
803 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) |
|
804 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
805 | - elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) |
|
806 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
853 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) { |
|
854 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
855 | + } elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) { |
|
856 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
857 | + } |
|
807 | 858 | } |
808 | 859 | |
809 | 860 | // God I hope it saved! |
@@ -816,8 +867,9 @@ discard block |
||
816 | 867 | // Make sure it works. |
817 | 868 | require(dirname(__FILE__) . '/Settings.php'); |
818 | 869 | |
819 | - if (empty($sourcedir)) |
|
820 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
870 | + if (empty($sourcedir)) { |
|
871 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
872 | + } |
|
821 | 873 | |
822 | 874 | // Better find the database file! |
823 | 875 | if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
@@ -827,18 +879,21 @@ discard block |
||
827 | 879 | } |
828 | 880 | |
829 | 881 | // Now include it for database functions! |
830 | - if (!defined('SMF')) |
|
831 | - define('SMF', 1); |
|
882 | + if (!defined('SMF')) { |
|
883 | + define('SMF', 1); |
|
884 | + } |
|
832 | 885 | |
833 | 886 | $modSettings['disableQueryCheck'] = true; |
834 | - if (empty($smcFunc)) |
|
835 | - $smcFunc = array(); |
|
887 | + if (empty($smcFunc)) { |
|
888 | + $smcFunc = array(); |
|
889 | + } |
|
836 | 890 | |
837 | 891 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
838 | 892 | |
839 | 893 | // What - running PHP4? The shame! |
840 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
841 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
894 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
895 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
896 | + } |
|
842 | 897 | |
843 | 898 | // Attempt a connection. |
844 | 899 | $needsDB = !empty($databases[$db_type]['always_has_db']); |
@@ -926,12 +981,14 @@ discard block |
||
926 | 981 | $incontext['page_title'] = $txt['install_settings']; |
927 | 982 | |
928 | 983 | // Let's see if we got the database type correct. |
929 | - if (isset($_POST['db_type'], $databases[$_POST['db_type']])) |
|
930 | - $db_type = $_POST['db_type']; |
|
984 | + if (isset($_POST['db_type'], $databases[$_POST['db_type']])) { |
|
985 | + $db_type = $_POST['db_type']; |
|
986 | + } |
|
931 | 987 | |
932 | 988 | // Else we'd better be able to get the connection. |
933 | - else |
|
934 | - load_database(); |
|
989 | + else { |
|
990 | + load_database(); |
|
991 | + } |
|
935 | 992 | |
936 | 993 | $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type; |
937 | 994 | |
@@ -940,10 +997,11 @@ discard block |
||
940 | 997 | |
941 | 998 | $secure = false; |
942 | 999 | |
943 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
944 | - $secure = true; |
|
945 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
946 | - $secure = true; |
|
1000 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
1001 | + $secure = true; |
|
1002 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
1003 | + $secure = true; |
|
1004 | + } |
|
947 | 1005 | |
948 | 1006 | // Now, to put what we've learned together... and add a path. |
949 | 1007 | $incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); |
@@ -975,18 +1033,21 @@ discard block |
||
975 | 1033 | // Submitting? |
976 | 1034 | if (isset($_POST['boardurl'])) |
977 | 1035 | { |
978 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
979 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
980 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
981 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
982 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
983 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1036 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
1037 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1038 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
1039 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1040 | + } |
|
1041 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
1042 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1043 | + } |
|
984 | 1044 | |
985 | 1045 | //Make sure boardurl is aligned with ssl setting |
986 | - if (empty($_POST['force_ssl'])) |
|
987 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
988 | - else |
|
989 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
1046 | + if (empty($_POST['force_ssl'])) { |
|
1047 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
1048 | + } else { |
|
1049 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
1050 | + } |
|
990 | 1051 | |
991 | 1052 | // Save these variables. |
992 | 1053 | $vars = array( |
@@ -1025,10 +1086,10 @@ discard block |
||
1025 | 1086 | { |
1026 | 1087 | $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); |
1027 | 1088 | return false; |
1028 | - } |
|
1029 | - else |
|
1030 | - // Set the character set here. |
|
1089 | + } else { |
|
1090 | + // Set the character set here. |
|
1031 | 1091 | updateSettingsFile(array('db_character_set' => 'utf8')); |
1092 | + } |
|
1032 | 1093 | } |
1033 | 1094 | |
1034 | 1095 | // Good, skip on. |
@@ -1048,8 +1109,9 @@ discard block |
||
1048 | 1109 | $incontext['continue'] = 1; |
1049 | 1110 | |
1050 | 1111 | // Already done? |
1051 | - if (isset($_POST['pop_done'])) |
|
1052 | - return true; |
|
1112 | + if (isset($_POST['pop_done'])) { |
|
1113 | + return true; |
|
1114 | + } |
|
1053 | 1115 | |
1054 | 1116 | // Reload settings. |
1055 | 1117 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1067,8 +1129,9 @@ discard block |
||
1067 | 1129 | $modSettings = array(); |
1068 | 1130 | if ($result !== false) |
1069 | 1131 | { |
1070 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1071 | - $modSettings[$row['variable']] = $row['value']; |
|
1132 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
1133 | + $modSettings[$row['variable']] = $row['value']; |
|
1134 | + } |
|
1072 | 1135 | $smcFunc['db_free_result']($result); |
1073 | 1136 | |
1074 | 1137 | // Do they match? If so, this is just a refresh so charge on! |
@@ -1081,20 +1144,22 @@ discard block |
||
1081 | 1144 | $modSettings['disableQueryCheck'] = true; |
1082 | 1145 | |
1083 | 1146 | // If doing UTF8, select it. PostgreSQL requires passing it as a string... |
1084 | - if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) |
|
1085 | - $smcFunc['db_query']('', ' |
|
1147 | + if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) { |
|
1148 | + $smcFunc['db_query']('', ' |
|
1086 | 1149 | SET NAMES {string:utf8}', |
1087 | 1150 | array( |
1088 | 1151 | 'db_error_skip' => true, |
1089 | 1152 | 'utf8' => 'utf8', |
1090 | 1153 | ) |
1091 | 1154 | ); |
1155 | + } |
|
1092 | 1156 | |
1093 | 1157 | // Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments... |
1094 | - if (substr(__DIR__, -1) == '\\') |
|
1095 | - $attachdir = __DIR__ . 'attachments'; |
|
1096 | - else |
|
1097 | - $attachdir = __DIR__ . '/attachments'; |
|
1158 | + if (substr(__DIR__, -1) == '\\') { |
|
1159 | + $attachdir = __DIR__ . 'attachments'; |
|
1160 | + } else { |
|
1161 | + $attachdir = __DIR__ . '/attachments'; |
|
1162 | + } |
|
1098 | 1163 | |
1099 | 1164 | $replaces = array( |
1100 | 1165 | '{$db_prefix}' => $db_prefix, |
@@ -1111,8 +1176,9 @@ discard block |
||
1111 | 1176 | |
1112 | 1177 | foreach ($txt as $key => $value) |
1113 | 1178 | { |
1114 | - if (substr($key, 0, 8) == 'default_') |
|
1115 | - $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
1179 | + if (substr($key, 0, 8) == 'default_') { |
|
1180 | + $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
1181 | + } |
|
1116 | 1182 | } |
1117 | 1183 | $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n')); |
1118 | 1184 | |
@@ -1127,8 +1193,9 @@ discard block |
||
1127 | 1193 | |
1128 | 1194 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
1129 | 1195 | { |
1130 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
1131 | - $engines[] = $row['Engine']; |
|
1196 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
1197 | + $engines[] = $row['Engine']; |
|
1198 | + } |
|
1132 | 1199 | } |
1133 | 1200 | |
1134 | 1201 | // Done with this now |
@@ -1152,8 +1219,7 @@ discard block |
||
1152 | 1219 | $replaces['START TRANSACTION;'] = ''; |
1153 | 1220 | $replaces['COMMIT;'] = ''; |
1154 | 1221 | } |
1155 | - } |
|
1156 | - else |
|
1222 | + } else |
|
1157 | 1223 | { |
1158 | 1224 | $has_innodb = false; |
1159 | 1225 | } |
@@ -1175,21 +1241,24 @@ discard block |
||
1175 | 1241 | foreach ($sql_lines as $count => $line) |
1176 | 1242 | { |
1177 | 1243 | // No comments allowed! |
1178 | - if (substr(trim($line), 0, 1) != '#') |
|
1179 | - $current_statement .= "\n" . rtrim($line); |
|
1244 | + if (substr(trim($line), 0, 1) != '#') { |
|
1245 | + $current_statement .= "\n" . rtrim($line); |
|
1246 | + } |
|
1180 | 1247 | |
1181 | 1248 | // Is this the end of the query string? |
1182 | - if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) |
|
1183 | - continue; |
|
1249 | + if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) { |
|
1250 | + continue; |
|
1251 | + } |
|
1184 | 1252 | |
1185 | 1253 | // Does this table already exist? If so, don't insert more data into it! |
1186 | 1254 | if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists)) |
1187 | 1255 | { |
1188 | 1256 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
1189 | - if (!empty($matches[0])) |
|
1190 | - $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
1191 | - else |
|
1192 | - $incontext['sql_results']['insert_dups']++; |
|
1257 | + if (!empty($matches[0])) { |
|
1258 | + $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
1259 | + } else { |
|
1260 | + $incontext['sql_results']['insert_dups']++; |
|
1261 | + } |
|
1193 | 1262 | |
1194 | 1263 | $current_statement = ''; |
1195 | 1264 | continue; |
@@ -1198,8 +1267,9 @@ discard block |
||
1198 | 1267 | if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false) |
1199 | 1268 | { |
1200 | 1269 | // Use the appropriate function based on the DB type |
1201 | - if ($db_type == 'mysql' || $db_type == 'mysqli') |
|
1202 | - $db_errorno = $db_type . '_errno'; |
|
1270 | + if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
1271 | + $db_errorno = $db_type . '_errno'; |
|
1272 | + } |
|
1203 | 1273 | |
1204 | 1274 | // Error 1050: Table already exists! |
1205 | 1275 | // @todo Needs to be made better! |
@@ -1214,18 +1284,18 @@ discard block |
||
1214 | 1284 | // MySQLi requires a connection object. It's optional with MySQL and Postgres |
1215 | 1285 | $incontext['failures'][$count] = $smcFunc['db_error']($db_connection); |
1216 | 1286 | } |
1217 | - } |
|
1218 | - else |
|
1287 | + } else |
|
1219 | 1288 | { |
1220 | - if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1221 | - $incontext['sql_results']['tables']++; |
|
1222 | - elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1289 | + if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) { |
|
1290 | + $incontext['sql_results']['tables']++; |
|
1291 | + } elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1223 | 1292 | { |
1224 | 1293 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
1225 | - if (!empty($matches[0])) |
|
1226 | - $incontext['sql_results']['inserts'] += count($matches[0]); |
|
1227 | - else |
|
1228 | - $incontext['sql_results']['inserts']++; |
|
1294 | + if (!empty($matches[0])) { |
|
1295 | + $incontext['sql_results']['inserts'] += count($matches[0]); |
|
1296 | + } else { |
|
1297 | + $incontext['sql_results']['inserts']++; |
|
1298 | + } |
|
1229 | 1299 | } |
1230 | 1300 | } |
1231 | 1301 | |
@@ -1238,15 +1308,17 @@ discard block |
||
1238 | 1308 | // Sort out the context for the SQL. |
1239 | 1309 | foreach ($incontext['sql_results'] as $key => $number) |
1240 | 1310 | { |
1241 | - if ($number == 0) |
|
1242 | - unset($incontext['sql_results'][$key]); |
|
1243 | - else |
|
1244 | - $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
1311 | + if ($number == 0) { |
|
1312 | + unset($incontext['sql_results'][$key]); |
|
1313 | + } else { |
|
1314 | + $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
1315 | + } |
|
1245 | 1316 | } |
1246 | 1317 | |
1247 | 1318 | // Make sure UTF will be used globally. |
1248 | - if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) |
|
1249 | - $newSettings[] = array('global_character_set', 'UTF-8'); |
|
1319 | + if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) { |
|
1320 | + $newSettings[] = array('global_character_set', 'UTF-8'); |
|
1321 | + } |
|
1250 | 1322 | |
1251 | 1323 | // Auto-detect local & global cookie settings |
1252 | 1324 | $url_parts = parse_url($boardurl); |
@@ -1275,15 +1347,19 @@ discard block |
||
1275 | 1347 | |
1276 | 1348 | // Look for subfolder, if found, set localCookie |
1277 | 1349 | // Checking for len > 1 ensures you don't have just a slash... |
1278 | - if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) |
|
1279 | - $localCookies = '1'; |
|
1350 | + if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) { |
|
1351 | + $localCookies = '1'; |
|
1352 | + } |
|
1280 | 1353 | |
1281 | - if (isset($globalCookies)) |
|
1282 | - $newSettings[] = array('globalCookies', $globalCookies); |
|
1283 | - if (isset($globalCookiesDomain)) |
|
1284 | - $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
1285 | - if (isset($localCookies)) |
|
1286 | - $newSettings[] = array('localCookies', $localCookies); |
|
1354 | + if (isset($globalCookies)) { |
|
1355 | + $newSettings[] = array('globalCookies', $globalCookies); |
|
1356 | + } |
|
1357 | + if (isset($globalCookiesDomain)) { |
|
1358 | + $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
1359 | + } |
|
1360 | + if (isset($localCookies)) { |
|
1361 | + $newSettings[] = array('localCookies', $localCookies); |
|
1362 | + } |
|
1287 | 1363 | } |
1288 | 1364 | |
1289 | 1365 | // Are we allowing stat collection? |
@@ -1301,16 +1377,17 @@ discard block |
||
1301 | 1377 | fwrite($fp, $out); |
1302 | 1378 | |
1303 | 1379 | $return_data = ''; |
1304 | - while (!feof($fp)) |
|
1305 | - $return_data .= fgets($fp, 128); |
|
1380 | + while (!feof($fp)) { |
|
1381 | + $return_data .= fgets($fp, 128); |
|
1382 | + } |
|
1306 | 1383 | |
1307 | 1384 | fclose($fp); |
1308 | 1385 | |
1309 | 1386 | // Get the unique site ID. |
1310 | 1387 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
1311 | 1388 | |
1312 | - if (!empty($ID[1])) |
|
1313 | - $smcFunc['db_insert']('replace', |
|
1389 | + if (!empty($ID[1])) { |
|
1390 | + $smcFunc['db_insert']('replace', |
|
1314 | 1391 | $db_prefix . 'settings', |
1315 | 1392 | array('variable' => 'string', 'value' => 'string'), |
1316 | 1393 | array( |
@@ -1319,11 +1396,12 @@ discard block |
||
1319 | 1396 | ), |
1320 | 1397 | array('variable') |
1321 | 1398 | ); |
1399 | + } |
|
1322 | 1400 | } |
1323 | 1401 | } |
1324 | 1402 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
1325 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
1326 | - $smcFunc['db_query']('', ' |
|
1403 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
1404 | + $smcFunc['db_query']('', ' |
|
1327 | 1405 | DELETE FROM {db_prefix}settings |
1328 | 1406 | WHERE variable = {string:enable_sm_stats}', |
1329 | 1407 | array( |
@@ -1331,20 +1409,23 @@ discard block |
||
1331 | 1409 | 'db_error_skip' => true, |
1332 | 1410 | ) |
1333 | 1411 | ); |
1412 | + } |
|
1334 | 1413 | |
1335 | 1414 | // Are we enabling SSL? |
1336 | - if (!empty($_POST['force_ssl'])) |
|
1337 | - $newSettings[] = array('force_ssl', 2); |
|
1415 | + if (!empty($_POST['force_ssl'])) { |
|
1416 | + $newSettings[] = array('force_ssl', 2); |
|
1417 | + } |
|
1338 | 1418 | |
1339 | 1419 | // Setting a timezone is required. |
1340 | 1420 | if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) |
1341 | 1421 | { |
1342 | 1422 | // Get PHP's default timezone, if set |
1343 | 1423 | $ini_tz = ini_get('date.timezone'); |
1344 | - if (!empty($ini_tz)) |
|
1345 | - $timezone_id = $ini_tz; |
|
1346 | - else |
|
1347 | - $timezone_id = ''; |
|
1424 | + if (!empty($ini_tz)) { |
|
1425 | + $timezone_id = $ini_tz; |
|
1426 | + } else { |
|
1427 | + $timezone_id = ''; |
|
1428 | + } |
|
1348 | 1429 | |
1349 | 1430 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
1350 | 1431 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -1353,8 +1434,9 @@ discard block |
||
1353 | 1434 | $timezone_id = timezone_name_from_abbr('', $server_offset, 0); |
1354 | 1435 | } |
1355 | 1436 | |
1356 | - if (date_default_timezone_set($timezone_id)) |
|
1357 | - $newSettings[] = array('default_timezone', $timezone_id); |
|
1437 | + if (date_default_timezone_set($timezone_id)) { |
|
1438 | + $newSettings[] = array('default_timezone', $timezone_id); |
|
1439 | + } |
|
1358 | 1440 | } |
1359 | 1441 | |
1360 | 1442 | if (!empty($newSettings)) |
@@ -1385,16 +1467,18 @@ discard block |
||
1385 | 1467 | } |
1386 | 1468 | |
1387 | 1469 | // MySQL specific stuff |
1388 | - if (substr($db_type, 0, 5) != 'mysql') |
|
1389 | - return false; |
|
1470 | + if (substr($db_type, 0, 5) != 'mysql') { |
|
1471 | + return false; |
|
1472 | + } |
|
1390 | 1473 | |
1391 | 1474 | // Find database user privileges. |
1392 | 1475 | $privs = array(); |
1393 | 1476 | $get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array()); |
1394 | 1477 | while ($row = $smcFunc['db_fetch_assoc']($get_privs)) |
1395 | 1478 | { |
1396 | - if ($row['Privilege'] == 'Alter') |
|
1397 | - $privs[] = $row['Privilege']; |
|
1479 | + if ($row['Privilege'] == 'Alter') { |
|
1480 | + $privs[] = $row['Privilege']; |
|
1481 | + } |
|
1398 | 1482 | } |
1399 | 1483 | $smcFunc['db_free_result']($get_privs); |
1400 | 1484 | |
@@ -1424,8 +1508,9 @@ discard block |
||
1424 | 1508 | $incontext['continue'] = 1; |
1425 | 1509 | |
1426 | 1510 | // Skipping? |
1427 | - if (!empty($_POST['skip'])) |
|
1428 | - return true; |
|
1511 | + if (!empty($_POST['skip'])) { |
|
1512 | + return true; |
|
1513 | + } |
|
1429 | 1514 | |
1430 | 1515 | // Need this to check whether we need the database password. |
1431 | 1516 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1442,18 +1527,22 @@ discard block |
||
1442 | 1527 | // We need this to properly hash the password for Admin |
1443 | 1528 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
1444 | 1529 | global $sourcedir; |
1445 | - if (function_exists('mb_strtolower')) |
|
1446 | - return mb_strtolower($string, 'UTF-8'); |
|
1530 | + if (function_exists('mb_strtolower')) { |
|
1531 | + return mb_strtolower($string, 'UTF-8'); |
|
1532 | + } |
|
1447 | 1533 | require_once($sourcedir . '/Subs-Charset.php'); |
1448 | 1534 | return utf8_strtolower($string); |
1449 | 1535 | }; |
1450 | 1536 | |
1451 | - if (!isset($_POST['username'])) |
|
1452 | - $_POST['username'] = ''; |
|
1453 | - if (!isset($_POST['email'])) |
|
1454 | - $_POST['email'] = ''; |
|
1455 | - if (!isset($_POST['server_email'])) |
|
1456 | - $_POST['server_email'] = ''; |
|
1537 | + if (!isset($_POST['username'])) { |
|
1538 | + $_POST['username'] = ''; |
|
1539 | + } |
|
1540 | + if (!isset($_POST['email'])) { |
|
1541 | + $_POST['email'] = ''; |
|
1542 | + } |
|
1543 | + if (!isset($_POST['server_email'])) { |
|
1544 | + $_POST['server_email'] = ''; |
|
1545 | + } |
|
1457 | 1546 | |
1458 | 1547 | $incontext['username'] = htmlspecialchars(stripslashes($_POST['username'])); |
1459 | 1548 | $incontext['email'] = htmlspecialchars(stripslashes($_POST['email'])); |
@@ -1472,8 +1561,9 @@ discard block |
||
1472 | 1561 | 'admin_group' => 1, |
1473 | 1562 | ) |
1474 | 1563 | ); |
1475 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
1476 | - $incontext['skip'] = 1; |
|
1564 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
1565 | + $incontext['skip'] = 1; |
|
1566 | + } |
|
1477 | 1567 | $smcFunc['db_free_result']($request); |
1478 | 1568 | |
1479 | 1569 | // Trying to create an account? |
@@ -1504,8 +1594,9 @@ discard block |
||
1504 | 1594 | } |
1505 | 1595 | |
1506 | 1596 | // Update the webmaster's email? |
1507 | - if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) |
|
1508 | - updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
1597 | + if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) { |
|
1598 | + updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
1599 | + } |
|
1509 | 1600 | |
1510 | 1601 | // Work out whether we're going to have dodgy characters and remove them. |
1511 | 1602 | $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0; |
@@ -1528,32 +1619,27 @@ discard block |
||
1528 | 1619 | $smcFunc['db_free_result']($result); |
1529 | 1620 | |
1530 | 1621 | $incontext['account_existed'] = $txt['error_user_settings_taken']; |
1531 | - } |
|
1532 | - elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
1622 | + } elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
1533 | 1623 | { |
1534 | 1624 | // Try the previous step again. |
1535 | 1625 | $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long']; |
1536 | 1626 | return false; |
1537 | - } |
|
1538 | - elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
1627 | + } elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
1539 | 1628 | { |
1540 | 1629 | // Try the previous step again. |
1541 | 1630 | $incontext['error'] = $txt['error_invalid_characters_username']; |
1542 | 1631 | return false; |
1543 | - } |
|
1544 | - elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
1632 | + } elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
1545 | 1633 | { |
1546 | 1634 | // One step back, this time fill out a proper admin email address. |
1547 | 1635 | $incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']); |
1548 | 1636 | return false; |
1549 | - } |
|
1550 | - elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
1637 | + } elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
1551 | 1638 | { |
1552 | 1639 | // One step back, this time fill out a proper admin email address. |
1553 | 1640 | $incontext['error'] = $txt['error_valid_server_email_needed']; |
1554 | 1641 | return false; |
1555 | - } |
|
1556 | - elseif ($_POST['username'] != '') |
|
1642 | + } elseif ($_POST['username'] != '') |
|
1557 | 1643 | { |
1558 | 1644 | $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4); |
1559 | 1645 | |
@@ -1621,17 +1707,19 @@ discard block |
||
1621 | 1707 | reloadSettings(); |
1622 | 1708 | |
1623 | 1709 | // Bring a warning over. |
1624 | - if (!empty($incontext['account_existed'])) |
|
1625 | - $incontext['warning'] = $incontext['account_existed']; |
|
1710 | + if (!empty($incontext['account_existed'])) { |
|
1711 | + $incontext['warning'] = $incontext['account_existed']; |
|
1712 | + } |
|
1626 | 1713 | |
1627 | - if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) |
|
1628 | - $smcFunc['db_query']('', ' |
|
1714 | + if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) { |
|
1715 | + $smcFunc['db_query']('', ' |
|
1629 | 1716 | SET NAMES {string:db_character_set}', |
1630 | 1717 | array( |
1631 | 1718 | 'db_character_set' => $db_character_set, |
1632 | 1719 | 'db_error_skip' => true, |
1633 | 1720 | ) |
1634 | 1721 | ); |
1722 | + } |
|
1635 | 1723 | |
1636 | 1724 | // As track stats is by default enabled let's add some activity. |
1637 | 1725 | $smcFunc['db_insert']('ignore', |
@@ -1652,14 +1740,16 @@ discard block |
||
1652 | 1740 | // Only proceed if we can load the data. |
1653 | 1741 | if ($request) |
1654 | 1742 | { |
1655 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
1656 | - $modSettings[$row[0]] = $row[1]; |
|
1743 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
1744 | + $modSettings[$row[0]] = $row[1]; |
|
1745 | + } |
|
1657 | 1746 | $smcFunc['db_free_result']($request); |
1658 | 1747 | } |
1659 | 1748 | |
1660 | 1749 | // Automatically log them in ;) |
1661 | - if (isset($incontext['member_id']) && isset($incontext['member_salt'])) |
|
1662 | - setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
1750 | + if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { |
|
1751 | + setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
1752 | + } |
|
1663 | 1753 | |
1664 | 1754 | $result = $smcFunc['db_query']('', ' |
1665 | 1755 | SELECT value |
@@ -1670,13 +1760,14 @@ discard block |
||
1670 | 1760 | 'db_error_skip' => true, |
1671 | 1761 | ) |
1672 | 1762 | ); |
1673 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1674 | - list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
1763 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1764 | + list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
1765 | + } |
|
1675 | 1766 | $smcFunc['db_free_result']($result); |
1676 | 1767 | |
1677 | - if (empty($db_sessions)) |
|
1678 | - $_SESSION['admin_time'] = time(); |
|
1679 | - else |
|
1768 | + if (empty($db_sessions)) { |
|
1769 | + $_SESSION['admin_time'] = time(); |
|
1770 | + } else |
|
1680 | 1771 | { |
1681 | 1772 | $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); |
1682 | 1773 | |
@@ -1700,8 +1791,9 @@ discard block |
||
1700 | 1791 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
1701 | 1792 | function($string){ |
1702 | 1793 | global $sourcedir; |
1703 | - if (function_exists('mb_strtolower')) |
|
1704 | - return mb_strtolower($string, 'UTF-8'); |
|
1794 | + if (function_exists('mb_strtolower')) { |
|
1795 | + return mb_strtolower($string, 'UTF-8'); |
|
1796 | + } |
|
1705 | 1797 | require_once($sourcedir . '/Subs-Charset.php'); |
1706 | 1798 | return utf8_strtolower($string); |
1707 | 1799 | }; |
@@ -1717,8 +1809,9 @@ discard block |
||
1717 | 1809 | ) |
1718 | 1810 | ); |
1719 | 1811 | $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8'; |
1720 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
1721 | - updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
1812 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
1813 | + updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
1814 | + } |
|
1722 | 1815 | $smcFunc['db_free_result']($request); |
1723 | 1816 | |
1724 | 1817 | // Now is the perfect time to fetch the SM files. |
@@ -1737,8 +1830,9 @@ discard block |
||
1737 | 1830 | |
1738 | 1831 | // Check if we need some stupid MySQL fix. |
1739 | 1832 | $server_version = $smcFunc['db_server_info'](); |
1740 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
1741 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1833 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
1834 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1835 | + } |
|
1742 | 1836 | |
1743 | 1837 | // Some final context for the template. |
1744 | 1838 | $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; |
@@ -1758,8 +1852,9 @@ discard block |
||
1758 | 1852 | $settingsArray = file(dirname(__FILE__) . '/Settings.php'); |
1759 | 1853 | |
1760 | 1854 | // @todo Do we just want to read the file in clean, and split it this way always? |
1761 | - if (count($settingsArray) == 1) |
|
1762 | - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
1855 | + if (count($settingsArray) == 1) { |
|
1856 | + $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
1857 | + } |
|
1763 | 1858 | |
1764 | 1859 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
1765 | 1860 | { |
@@ -1767,25 +1862,29 @@ discard block |
||
1767 | 1862 | if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}') |
1768 | 1863 | { |
1769 | 1864 | // Set the ten lines to nothing. |
1770 | - for ($j=0; $j < 10; $j++) |
|
1771 | - $settingsArray[$i++] = ''; |
|
1865 | + for ($j=0; $j < 10; $j++) { |
|
1866 | + $settingsArray[$i++] = ''; |
|
1867 | + } |
|
1772 | 1868 | |
1773 | 1869 | continue; |
1774 | 1870 | } |
1775 | 1871 | |
1776 | - if (trim($settingsArray[$i]) == '?' . '>') |
|
1777 | - $settingsArray[$i] = ''; |
|
1872 | + if (trim($settingsArray[$i]) == '?' . '>') { |
|
1873 | + $settingsArray[$i] = ''; |
|
1874 | + } |
|
1778 | 1875 | |
1779 | 1876 | // Don't trim or bother with it if it's not a variable. |
1780 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
1781 | - continue; |
|
1877 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
1878 | + continue; |
|
1879 | + } |
|
1782 | 1880 | |
1783 | 1881 | $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n"; |
1784 | 1882 | |
1785 | - foreach ($vars as $var => $val) |
|
1786 | - if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
1883 | + foreach ($vars as $var => $val) { |
|
1884 | + if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
1787 | 1885 | { |
1788 | 1886 | $comment = strstr($settingsArray[$i], '#'); |
1887 | + } |
|
1789 | 1888 | $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n"); |
1790 | 1889 | unset($vars[$var]); |
1791 | 1890 | } |
@@ -1795,36 +1894,41 @@ discard block |
||
1795 | 1894 | if (!empty($vars)) |
1796 | 1895 | { |
1797 | 1896 | $settingsArray[$i++] = ''; |
1798 | - foreach ($vars as $var => $val) |
|
1799 | - $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
1897 | + foreach ($vars as $var => $val) { |
|
1898 | + $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
1899 | + } |
|
1800 | 1900 | } |
1801 | 1901 | |
1802 | 1902 | // Blank out the file - done to fix a oddity with some servers. |
1803 | 1903 | $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w'); |
1804 | - if (!$fp) |
|
1805 | - return false; |
|
1904 | + if (!$fp) { |
|
1905 | + return false; |
|
1906 | + } |
|
1806 | 1907 | fclose($fp); |
1807 | 1908 | |
1808 | 1909 | $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+'); |
1809 | 1910 | |
1810 | 1911 | // Gotta have one of these ;) |
1811 | - if (trim($settingsArray[0]) != '<?php') |
|
1812 | - fwrite($fp, "<?php\n"); |
|
1912 | + if (trim($settingsArray[0]) != '<?php') { |
|
1913 | + fwrite($fp, "<?php\n"); |
|
1914 | + } |
|
1813 | 1915 | |
1814 | 1916 | $lines = count($settingsArray); |
1815 | 1917 | for ($i = 0; $i < $lines - 1; $i++) |
1816 | 1918 | { |
1817 | 1919 | // Don't just write a bunch of blank lines. |
1818 | - if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') |
|
1819 | - fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
1920 | + if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') { |
|
1921 | + fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
1922 | + } |
|
1820 | 1923 | } |
1821 | 1924 | fwrite($fp, $settingsArray[$i] . '?' . '>'); |
1822 | 1925 | fclose($fp); |
1823 | 1926 | |
1824 | 1927 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
1825 | 1928 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
1826 | - if (function_exists('opcache_invalidate')) |
|
1827 | - opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
1929 | + if (function_exists('opcache_invalidate')) { |
|
1930 | + opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
1931 | + } |
|
1828 | 1932 | |
1829 | 1933 | return true; |
1830 | 1934 | } |
@@ -1849,9 +1953,9 @@ discard block |
||
1849 | 1953 | SecFilterScanPOST Off |
1850 | 1954 | </IfModule>'; |
1851 | 1955 | |
1852 | - if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) |
|
1853 | - return true; |
|
1854 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
1956 | + if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) { |
|
1957 | + return true; |
|
1958 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
1855 | 1959 | { |
1856 | 1960 | $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess')); |
1857 | 1961 | |
@@ -1863,29 +1967,28 @@ discard block |
||
1863 | 1967 | fwrite($ht_handle, $htaccess_addition); |
1864 | 1968 | fclose($ht_handle); |
1865 | 1969 | return true; |
1970 | + } else { |
|
1971 | + return false; |
|
1866 | 1972 | } |
1867 | - else |
|
1868 | - return false; |
|
1973 | + } else { |
|
1974 | + return true; |
|
1869 | 1975 | } |
1870 | - else |
|
1871 | - return true; |
|
1872 | - } |
|
1873 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess')) |
|
1874 | - return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
1875 | - elseif (is_writable(dirname(__FILE__))) |
|
1976 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess')) { |
|
1977 | + return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
1978 | + } elseif (is_writable(dirname(__FILE__))) |
|
1876 | 1979 | { |
1877 | 1980 | if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w')) |
1878 | 1981 | { |
1879 | 1982 | fwrite($ht_handle, $htaccess_addition); |
1880 | 1983 | fclose($ht_handle); |
1881 | 1984 | return true; |
1985 | + } else { |
|
1986 | + return false; |
|
1882 | 1987 | } |
1883 | - else |
|
1988 | + } else { |
|
1884 | 1989 | return false; |
1885 | 1990 | } |
1886 | - else |
|
1887 | - return false; |
|
1888 | -} |
|
1991 | + } |
|
1889 | 1992 | |
1890 | 1993 | function template_install_above() |
1891 | 1994 | { |
@@ -1923,9 +2026,10 @@ discard block |
||
1923 | 2026 | <label for="installer_language">', $txt['installer_language'], ':</label> |
1924 | 2027 | <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">'; |
1925 | 2028 | |
1926 | - foreach ($incontext['detected_languages'] as $lang => $name) |
|
1927 | - echo ' |
|
2029 | + foreach ($incontext['detected_languages'] as $lang => $name) { |
|
2030 | + echo ' |
|
1928 | 2031 | <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>'; |
2032 | + } |
|
1929 | 2033 | |
1930 | 2034 | echo ' |
1931 | 2035 | </select> |
@@ -1945,9 +2049,10 @@ discard block |
||
1945 | 2049 | <h2>', $txt['upgrade_progress'], '</h2> |
1946 | 2050 | <ul>'; |
1947 | 2051 | |
1948 | - foreach ($incontext['steps'] as $num => $step) |
|
1949 | - echo ' |
|
2052 | + foreach ($incontext['steps'] as $num => $step) { |
|
2053 | + echo ' |
|
1950 | 2054 | <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
2055 | + } |
|
1951 | 2056 | |
1952 | 2057 | echo ' |
1953 | 2058 | </ul> |
@@ -1972,20 +2077,23 @@ discard block |
||
1972 | 2077 | echo ' |
1973 | 2078 | <div class="floatright">'; |
1974 | 2079 | |
1975 | - if (!empty($incontext['continue'])) |
|
1976 | - echo ' |
|
2080 | + if (!empty($incontext['continue'])) { |
|
2081 | + echo ' |
|
1977 | 2082 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button" />'; |
1978 | - if (!empty($incontext['skip'])) |
|
1979 | - echo ' |
|
2083 | + } |
|
2084 | + if (!empty($incontext['skip'])) { |
|
2085 | + echo ' |
|
1980 | 2086 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button" />'; |
2087 | + } |
|
1981 | 2088 | echo ' |
1982 | 2089 | </div>'; |
1983 | 2090 | } |
1984 | 2091 | |
1985 | 2092 | // Show the closing form tag and other data only if not in the last step |
1986 | - if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) |
|
1987 | - echo ' |
|
2093 | + if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) { |
|
2094 | + echo ' |
|
1988 | 2095 | </form>'; |
2096 | + } |
|
1989 | 2097 | |
1990 | 2098 | echo ' |
1991 | 2099 | </div> |
@@ -2020,13 +2128,15 @@ discard block |
||
2020 | 2128 | </div>'; |
2021 | 2129 | |
2022 | 2130 | // Show the warnings, or not. |
2023 | - if (template_warning_divs()) |
|
2024 | - echo ' |
|
2131 | + if (template_warning_divs()) { |
|
2132 | + echo ' |
|
2025 | 2133 | <h3>', $txt['install_all_lovely'], '</h3>'; |
2134 | + } |
|
2026 | 2135 | |
2027 | 2136 | // Say we want the continue button! |
2028 | - if (empty($incontext['error'])) |
|
2029 | - $incontext['continue'] = 1; |
|
2137 | + if (empty($incontext['error'])) { |
|
2138 | + $incontext['continue'] = 1; |
|
2139 | + } |
|
2030 | 2140 | |
2031 | 2141 | // For the latest version stuff. |
2032 | 2142 | echo ' |
@@ -2060,8 +2170,8 @@ discard block |
||
2060 | 2170 | global $txt, $incontext; |
2061 | 2171 | |
2062 | 2172 | // Errors are very serious.. |
2063 | - if (!empty($incontext['error'])) |
|
2064 | - echo ' |
|
2173 | + if (!empty($incontext['error'])) { |
|
2174 | + echo ' |
|
2065 | 2175 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
2066 | 2176 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
2067 | 2177 | <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br> |
@@ -2069,9 +2179,10 @@ discard block |
||
2069 | 2179 | ', $incontext['error'], ' |
2070 | 2180 | </div> |
2071 | 2181 | </div>'; |
2182 | + } |
|
2072 | 2183 | // A warning message? |
2073 | - elseif (!empty($incontext['warning'])) |
|
2074 | - echo ' |
|
2184 | + elseif (!empty($incontext['warning'])) { |
|
2185 | + echo ' |
|
2075 | 2186 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
2076 | 2187 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
2077 | 2188 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -2079,6 +2190,7 @@ discard block |
||
2079 | 2190 | ', $incontext['warning'], ' |
2080 | 2191 | </div> |
2081 | 2192 | </div>'; |
2193 | + } |
|
2082 | 2194 | |
2083 | 2195 | return empty($incontext['error']) && empty($incontext['warning']); |
2084 | 2196 | } |
@@ -2094,27 +2206,30 @@ discard block |
||
2094 | 2206 | <li>', $incontext['failed_files']), '</li> |
2095 | 2207 | </ul>'; |
2096 | 2208 | |
2097 | - if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') |
|
2098 | - echo ' |
|
2209 | + if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') { |
|
2210 | + echo ' |
|
2099 | 2211 | <hr> |
2100 | 2212 | <p>', $txt['chmod_linux_info'], '</p> |
2101 | 2213 | <tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>'; |
2214 | + } |
|
2102 | 2215 | |
2103 | 2216 | // This is serious! |
2104 | - if (!template_warning_divs()) |
|
2105 | - return; |
|
2217 | + if (!template_warning_divs()) { |
|
2218 | + return; |
|
2219 | + } |
|
2106 | 2220 | |
2107 | 2221 | echo ' |
2108 | 2222 | <hr> |
2109 | 2223 | <p>', $txt['ftp_setup_info'], '</p>'; |
2110 | 2224 | |
2111 | - if (!empty($incontext['ftp_errors'])) |
|
2112 | - echo ' |
|
2225 | + if (!empty($incontext['ftp_errors'])) { |
|
2226 | + echo ' |
|
2113 | 2227 | <div class="error_message"> |
2114 | 2228 | ', $txt['error_ftp_no_connect'], '<br><br> |
2115 | 2229 | <code>', implode('<br>', $incontext['ftp_errors']), '</code> |
2116 | 2230 | </div> |
2117 | 2231 | <br>'; |
2232 | + } |
|
2118 | 2233 | |
2119 | 2234 | echo ' |
2120 | 2235 | <form action="', $incontext['form_url'], '" method="post"> |
@@ -2174,17 +2289,17 @@ discard block |
||
2174 | 2289 | <td> |
2175 | 2290 | <select name="db_type" id="db_type_input" onchange="toggleDBInput();">'; |
2176 | 2291 | |
2177 | - foreach ($incontext['supported_databases'] as $key => $db) |
|
2178 | - echo ' |
|
2292 | + foreach ($incontext['supported_databases'] as $key => $db) { |
|
2293 | + echo ' |
|
2179 | 2294 | <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>'; |
2295 | + } |
|
2180 | 2296 | |
2181 | 2297 | echo ' |
2182 | 2298 | </select> |
2183 | 2299 | <div class="smalltext block">', $txt['db_settings_type_info'], '</div> |
2184 | 2300 | </td> |
2185 | 2301 | </tr>'; |
2186 | - } |
|
2187 | - else |
|
2302 | + } else |
|
2188 | 2303 | { |
2189 | 2304 | echo ' |
2190 | 2305 | <tr style="display: none;"> |
@@ -2377,9 +2492,10 @@ discard block |
||
2377 | 2492 | <div style="color: red;">', $txt['error_db_queries'], '</div> |
2378 | 2493 | <ul>'; |
2379 | 2494 | |
2380 | - foreach ($incontext['failures'] as $line => $fail) |
|
2381 | - echo ' |
|
2495 | + foreach ($incontext['failures'] as $line => $fail) { |
|
2496 | + echo ' |
|
2382 | 2497 | <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>'; |
2498 | + } |
|
2383 | 2499 | |
2384 | 2500 | echo ' |
2385 | 2501 | </ul>'; |
@@ -2440,15 +2556,16 @@ discard block |
||
2440 | 2556 | </tr> |
2441 | 2557 | </table>'; |
2442 | 2558 | |
2443 | - if ($incontext['require_db_confirm']) |
|
2444 | - echo ' |
|
2559 | + if ($incontext['require_db_confirm']) { |
|
2560 | + echo ' |
|
2445 | 2561 | <h2>', $txt['user_settings_database'], '</h2> |
2446 | 2562 | <p>', $txt['user_settings_database_info'], '</p> |
2447 | 2563 | |
2448 | 2564 | <div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;"> |
2449 | 2565 | <input type="password" name="password3" size="30" /> |
2450 | 2566 | </div>'; |
2451 | -} |
|
2567 | + } |
|
2568 | + } |
|
2452 | 2569 | |
2453 | 2570 | // Tell them it's done, and to delete. |
2454 | 2571 | function template_delete_install() |
@@ -2461,14 +2578,15 @@ discard block |
||
2461 | 2578 | template_warning_divs(); |
2462 | 2579 | |
2463 | 2580 | // Install directory still writable? |
2464 | - if ($incontext['dir_still_writable']) |
|
2465 | - echo ' |
|
2581 | + if ($incontext['dir_still_writable']) { |
|
2582 | + echo ' |
|
2466 | 2583 | <em>', $txt['still_writable'], '</em><br> |
2467 | 2584 | <br>'; |
2585 | + } |
|
2468 | 2586 | |
2469 | 2587 | // Don't show the box if it's like 99% sure it won't work :P. |
2470 | - if ($incontext['probably_delete_install']) |
|
2471 | - echo ' |
|
2588 | + if ($incontext['probably_delete_install']) { |
|
2589 | + echo ' |
|
2472 | 2590 | <div style="margin: 1ex; font-weight: bold;"> |
2473 | 2591 | <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label> |
2474 | 2592 | </div> |
@@ -2484,6 +2602,7 @@ discard block |
||
2484 | 2602 | } |
2485 | 2603 | </script> |
2486 | 2604 | <br>'; |
2605 | + } |
|
2487 | 2606 | |
2488 | 2607 | echo ' |
2489 | 2608 | ', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br> |
@@ -186,8 +186,9 @@ discard block |
||
186 | 186 | |
187 | 187 | ########## Error-Catching ########## |
188 | 188 | # Note: You shouldn't touch these settings. |
189 | -if (file_exists(dirname(__FILE__) . '/db_last_error.php')) |
|
189 | +if (file_exists(dirname(__FILE__) . '/db_last_error.php')) { |
|
190 | 190 | include(dirname(__FILE__) . '/db_last_error.php'); |
191 | +} |
|
191 | 192 | |
192 | 193 | if (!isset($db_last_error)) |
193 | 194 | { |
@@ -199,20 +200,24 @@ discard block |
||
199 | 200 | if (file_exists(dirname(__FILE__) . '/install.php')) |
200 | 201 | { |
201 | 202 | $secure = false; |
202 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
203 | - $secure = true; |
|
204 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
205 | - $secure = true; |
|
203 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
204 | + $secure = true; |
|
205 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
206 | + $secure = true; |
|
207 | + } |
|
206 | 208 | |
207 | 209 | header('Location: http' . ($secure ? 's' : '') . '://' . (empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']) . (strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')) . '/install.php'); exit; |
208 | 210 | } |
209 | 211 | |
210 | 212 | # Make sure the paths are correct... at least try to fix them. |
211 | -if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) |
|
213 | +if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) { |
|
212 | 214 | $boarddir = dirname(__FILE__); |
213 | -if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) |
|
215 | +} |
|
216 | +if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) { |
|
214 | 217 | $sourcedir = $boarddir . '/Sources'; |
215 | -if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) |
|
218 | +} |
|
219 | +if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) { |
|
216 | 220 | $cachedir = $boarddir . '/cache'; |
221 | +} |
|
217 | 222 | |
218 | 223 | ?> |
219 | 224 | \ No newline at end of file |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | |
256 | 256 | case 'datetime': |
257 | 257 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
258 | - return 'str_to_date('. |
|
259 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
258 | + return 'str_to_date(' . |
|
259 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
260 | 260 | ',\'%Y-%m-%d %h:%i:%s\')'; |
261 | 261 | else |
262 | 262 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | $old_pos = 0; |
461 | 461 | $pos = -1; |
462 | 462 | // Remove the string escape for better runtime |
463 | - $db_string_1 = str_replace('\\\'','',$db_string); |
|
463 | + $db_string_1 = str_replace('\\\'', '', $db_string); |
|
464 | 464 | while (true) |
465 | 465 | { |
466 | 466 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | { |
843 | 843 | $count = count($insertRows); |
844 | 844 | $ai = 0; |
845 | - for($i = 0; $i < $count; $i++) |
|
845 | + for ($i = 0; $i < $count; $i++) |
|
846 | 846 | { |
847 | 847 | $old_id = $smcFunc['db_insert_id'](); |
848 | 848 | |
@@ -868,13 +868,13 @@ discard block |
||
868 | 868 | $count2 = count($indexed_columns); |
869 | 869 | for ($x = 0; $x < $count2; $x++) |
870 | 870 | { |
871 | - $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
|
871 | + $where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x]; |
|
872 | 872 | if (($x + 1) < $count2) |
873 | 873 | $where_string += ' AND '; |
874 | 874 | } |
875 | 875 | |
876 | - $request = $smcFunc['db_query']('',' |
|
877 | - SELECT `'. $keys[0] . '` FROM ' . $table .' |
|
876 | + $request = $smcFunc['db_query']('', ' |
|
877 | + SELECT `'. $keys[0] . '` FROM ' . $table . ' |
|
878 | 878 | WHERE ' . $where_string . ' LIMIT 1', |
879 | 879 | array() |
880 | 880 | ); |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | $return_var = array(); |
904 | 904 | $count = count($insertRows); |
905 | 905 | $start = smf_db_insert_id($table, $keys[0]); |
906 | - for ($i = 0; $i < $count; $i++ ) |
|
906 | + for ($i = 0; $i < $count; $i++) |
|
907 | 907 | $return_var[] = $start + $i; |
908 | 908 | } |
909 | 909 | return $return_var; |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
1037 | 1037 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1038 | 1038 | $error_array[7], $error_array[8]); |
1039 | - mysqli_stmt_execute ($mysql_error_data_prep); |
|
1039 | + mysqli_stmt_execute($mysql_error_data_prep); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | /** |
@@ -1050,7 +1050,7 @@ discard block |
||
1050 | 1050 | */ |
1051 | 1051 | function smf_db_custom_order($field, $array_values, $desc = false) |
1052 | 1052 | { |
1053 | - $return = 'CASE '. $field . ' '; |
|
1053 | + $return = 'CASE ' . $field . ' '; |
|
1054 | 1054 | $count = count($array_values); |
1055 | 1055 | $then = ($desc ? ' THEN -' : ' THEN '); |
1056 | 1056 |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
33 | 34 | global $smcFunc; |
34 | 35 | |
35 | 36 | // Map some database specific functions, only do this once. |
36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
37 | - $smcFunc += array( |
|
37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
38 | + $smcFunc += array( |
|
38 | 39 | 'db_query' => 'smf_db_query', |
39 | 40 | 'db_quote' => 'smf_db_quote', |
40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -63,9 +64,11 @@ discard block |
||
63 | 64 | 'db_error_insert' => 'smf_db_error_insert', |
64 | 65 | 'db_custom_order' => 'smf_db_custom_order', |
65 | 66 | ); |
67 | + } |
|
66 | 68 | |
67 | - if (!empty($db_options['persist'])) |
|
68 | - $db_server = 'p:' . $db_server; |
|
69 | + if (!empty($db_options['persist'])) { |
|
70 | + $db_server = 'p:' . $db_server; |
|
71 | + } |
|
69 | 72 | |
70 | 73 | $connection = mysqli_init(); |
71 | 74 | |
@@ -74,24 +77,27 @@ discard block |
||
74 | 77 | $success = false; |
75 | 78 | |
76 | 79 | if ($connection) { |
77 | - if (!empty($db_options['port'])) |
|
78 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
79 | - else |
|
80 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
80 | + if (!empty($db_options['port'])) { |
|
81 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
82 | + } else { |
|
83 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
84 | + } |
|
81 | 85 | } |
82 | 86 | |
83 | 87 | // Something's wrong, show an error if its fatal (which we assume it is) |
84 | 88 | if ($success === false) |
85 | 89 | { |
86 | - if (!empty($db_options['non_fatal'])) |
|
87 | - return null; |
|
88 | - else |
|
89 | - display_db_error(); |
|
90 | + if (!empty($db_options['non_fatal'])) { |
|
91 | + return null; |
|
92 | + } else { |
|
93 | + display_db_error(); |
|
94 | + } |
|
90 | 95 | } |
91 | 96 | |
92 | 97 | // Select the database, unless told not to |
93 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
94 | - display_db_error(); |
|
98 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
99 | + display_db_error(); |
|
100 | + } |
|
95 | 101 | |
96 | 102 | $smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'', |
97 | 103 | array(), |
@@ -167,34 +173,42 @@ discard block |
||
167 | 173 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
168 | 174 | |
169 | 175 | list ($values, $connection) = $db_callback; |
170 | - if (!is_object($connection)) |
|
171 | - display_db_error(); |
|
176 | + if (!is_object($connection)) { |
|
177 | + display_db_error(); |
|
178 | + } |
|
172 | 179 | |
173 | - if ($matches[1] === 'db_prefix') |
|
174 | - return $db_prefix; |
|
180 | + if ($matches[1] === 'db_prefix') { |
|
181 | + return $db_prefix; |
|
182 | + } |
|
175 | 183 | |
176 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
177 | - return $user_info[$matches[1]]; |
|
184 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
185 | + return $user_info[$matches[1]]; |
|
186 | + } |
|
178 | 187 | |
179 | - if ($matches[1] === 'empty') |
|
180 | - return '\'\''; |
|
188 | + if ($matches[1] === 'empty') { |
|
189 | + return '\'\''; |
|
190 | + } |
|
181 | 191 | |
182 | - if (!isset($matches[2])) |
|
183 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
192 | + if (!isset($matches[2])) { |
|
193 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
194 | + } |
|
184 | 195 | |
185 | - if ($matches[1] === 'literal') |
|
186 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
196 | + if ($matches[1] === 'literal') { |
|
197 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
198 | + } |
|
187 | 199 | |
188 | - if (!isset($values[$matches[2]])) |
|
189 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
200 | + if (!isset($values[$matches[2]])) { |
|
201 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
202 | + } |
|
190 | 203 | |
191 | 204 | $replacement = $values[$matches[2]]; |
192 | 205 | |
193 | 206 | switch ($matches[1]) |
194 | 207 | { |
195 | 208 | case 'int': |
196 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
197 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
209 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
210 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
211 | + } |
|
198 | 212 | return (string) (int) $replacement; |
199 | 213 | break; |
200 | 214 | |
@@ -206,65 +220,73 @@ discard block |
||
206 | 220 | case 'array_int': |
207 | 221 | if (is_array($replacement)) |
208 | 222 | { |
209 | - if (empty($replacement)) |
|
210 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
223 | + if (empty($replacement)) { |
|
224 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
225 | + } |
|
211 | 226 | |
212 | 227 | foreach ($replacement as $key => $value) |
213 | 228 | { |
214 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
215 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
229 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
230 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
231 | + } |
|
216 | 232 | |
217 | 233 | $replacement[$key] = (string) (int) $value; |
218 | 234 | } |
219 | 235 | |
220 | 236 | return implode(', ', $replacement); |
237 | + } else { |
|
238 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
221 | 239 | } |
222 | - else |
|
223 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
224 | 240 | |
225 | 241 | break; |
226 | 242 | |
227 | 243 | case 'array_string': |
228 | 244 | if (is_array($replacement)) |
229 | 245 | { |
230 | - if (empty($replacement)) |
|
231 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
246 | + if (empty($replacement)) { |
|
247 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
248 | + } |
|
232 | 249 | |
233 | - foreach ($replacement as $key => $value) |
|
234 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
250 | + foreach ($replacement as $key => $value) { |
|
251 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
252 | + } |
|
235 | 253 | |
236 | 254 | return implode(', ', $replacement); |
255 | + } else { |
|
256 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | 257 | } |
238 | - else |
|
239 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | 258 | break; |
241 | 259 | |
242 | 260 | case 'date': |
243 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
244 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
245 | - else |
|
246 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
261 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
262 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
263 | + } else { |
|
264 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
265 | + } |
|
247 | 266 | break; |
248 | 267 | |
249 | 268 | case 'time': |
250 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
251 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
252 | - else |
|
253 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
269 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
270 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
271 | + } else { |
|
272 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
273 | + } |
|
254 | 274 | break; |
255 | 275 | |
256 | 276 | case 'datetime': |
257 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
258 | - return 'str_to_date('. |
|
277 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
278 | + return 'str_to_date('. |
|
259 | 279 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
260 | 280 | ',\'%Y-%m-%d %h:%i:%s\')'; |
261 | - else |
|
262 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
281 | + } else { |
|
282 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
283 | + } |
|
263 | 284 | break; |
264 | 285 | |
265 | 286 | case 'float': |
266 | - if (!is_numeric($replacement)) |
|
267 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
287 | + if (!is_numeric($replacement)) { |
|
288 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
289 | + } |
|
268 | 290 | return (string) (float) $replacement; |
269 | 291 | break; |
270 | 292 | |
@@ -278,32 +300,37 @@ discard block |
||
278 | 300 | break; |
279 | 301 | |
280 | 302 | case 'inet': |
281 | - if ($replacement == 'null' || $replacement == '') |
|
282 | - return 'null'; |
|
283 | - if (!isValidIP($replacement)) |
|
284 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
303 | + if ($replacement == 'null' || $replacement == '') { |
|
304 | + return 'null'; |
|
305 | + } |
|
306 | + if (!isValidIP($replacement)) { |
|
307 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
308 | + } |
|
285 | 309 | //we don't use the native support of mysql > 5.6.2 |
286 | 310 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
287 | 311 | |
288 | 312 | case 'array_inet': |
289 | 313 | if (is_array($replacement)) |
290 | 314 | { |
291 | - if (empty($replacement)) |
|
292 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
315 | + if (empty($replacement)) { |
|
316 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
317 | + } |
|
293 | 318 | |
294 | 319 | foreach ($replacement as $key => $value) |
295 | 320 | { |
296 | - if ($replacement == 'null' || $replacement == '') |
|
297 | - $replacement[$key] = 'null'; |
|
298 | - if (!isValidIP($value)) |
|
299 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
321 | + if ($replacement == 'null' || $replacement == '') { |
|
322 | + $replacement[$key] = 'null'; |
|
323 | + } |
|
324 | + if (!isValidIP($value)) { |
|
325 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
326 | + } |
|
300 | 327 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
301 | 328 | } |
302 | 329 | |
303 | 330 | return implode(', ', $replacement); |
331 | + } else { |
|
332 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
304 | 333 | } |
305 | - else |
|
306 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
307 | 334 | break; |
308 | 335 | |
309 | 336 | default: |
@@ -379,22 +406,25 @@ discard block |
||
379 | 406 | // Are we in SSI mode? If so try that username and password first |
380 | 407 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
381 | 408 | { |
382 | - if (empty($db_persist)) |
|
383 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
384 | - else |
|
385 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
409 | + if (empty($db_persist)) { |
|
410 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
411 | + } else { |
|
412 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
413 | + } |
|
386 | 414 | } |
387 | 415 | // Fall back to the regular username and password if need be |
388 | 416 | if (!$db_connection) |
389 | 417 | { |
390 | - if (empty($db_persist)) |
|
391 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
392 | - else |
|
393 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
418 | + if (empty($db_persist)) { |
|
419 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
420 | + } else { |
|
421 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
422 | + } |
|
394 | 423 | } |
395 | 424 | |
396 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
397 | - $db_connection = false; |
|
425 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
426 | + $db_connection = false; |
|
427 | + } |
|
398 | 428 | |
399 | 429 | $connection = $db_connection; |
400 | 430 | } |
@@ -402,18 +432,20 @@ discard block |
||
402 | 432 | // One more query.... |
403 | 433 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
404 | 434 | |
405 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
406 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
435 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
436 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
437 | + } |
|
407 | 438 | |
408 | 439 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
409 | 440 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
410 | 441 | { |
411 | 442 | // Add before LIMIT |
412 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
413 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
414 | - else |
|
415 | - // Append it. |
|
443 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
444 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
445 | + } else { |
|
446 | + // Append it. |
|
416 | 447 | $db_string .= "\n\t\t\tORDER BY null"; |
448 | + } |
|
417 | 449 | } |
418 | 450 | |
419 | 451 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -439,17 +471,18 @@ discard block |
||
439 | 471 | while (true) |
440 | 472 | { |
441 | 473 | $pos = strpos($db_string_1, '\'', $pos + 1); |
442 | - if ($pos === false) |
|
443 | - break; |
|
474 | + if ($pos === false) { |
|
475 | + break; |
|
476 | + } |
|
444 | 477 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
445 | 478 | |
446 | 479 | while (true) |
447 | 480 | { |
448 | 481 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
449 | 482 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
450 | - if ($pos1 === false) |
|
451 | - break; |
|
452 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
483 | + if ($pos1 === false) { |
|
484 | + break; |
|
485 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
453 | 486 | { |
454 | 487 | $pos = $pos1; |
455 | 488 | break; |
@@ -465,16 +498,19 @@ discard block |
||
465 | 498 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
466 | 499 | |
467 | 500 | // Comments? We don't use comments in our queries, we leave 'em outside! |
468 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
469 | - $fail = true; |
|
501 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
502 | + $fail = true; |
|
503 | + } |
|
470 | 504 | // Trying to change passwords, slow us down, or something? |
471 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
472 | - $fail = true; |
|
473 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
474 | - $fail = true; |
|
505 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
506 | + $fail = true; |
|
507 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
508 | + $fail = true; |
|
509 | + } |
|
475 | 510 | |
476 | - if (!empty($fail) && function_exists('log_error')) |
|
477 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
511 | + if (!empty($fail) && function_exists('log_error')) { |
|
512 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
513 | + } |
|
478 | 514 | } |
479 | 515 | |
480 | 516 | // Debugging. |
@@ -484,8 +520,9 @@ discard block |
||
484 | 520 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
485 | 521 | |
486 | 522 | // Initialize $db_cache if not already initialized. |
487 | - if (!isset($db_cache)) |
|
488 | - $db_cache = array(); |
|
523 | + if (!isset($db_cache)) { |
|
524 | + $db_cache = array(); |
|
525 | + } |
|
489 | 526 | |
490 | 527 | if (!empty($_SESSION['debug_redirect'])) |
491 | 528 | { |
@@ -501,17 +538,20 @@ discard block |
||
501 | 538 | $db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start; |
502 | 539 | } |
503 | 540 | |
504 | - if (empty($db_unbuffered)) |
|
505 | - $ret = @mysqli_query($connection, $db_string); |
|
506 | - else |
|
507 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
541 | + if (empty($db_unbuffered)) { |
|
542 | + $ret = @mysqli_query($connection, $db_string); |
|
543 | + } else { |
|
544 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
545 | + } |
|
508 | 546 | |
509 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
510 | - $ret = smf_db_error($db_string, $connection); |
|
547 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
548 | + $ret = smf_db_error($db_string, $connection); |
|
549 | + } |
|
511 | 550 | |
512 | 551 | // Debugging. |
513 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
514 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
552 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
553 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
554 | + } |
|
515 | 555 | |
516 | 556 | return $ret; |
517 | 557 | } |
@@ -558,12 +598,13 @@ discard block |
||
558 | 598 | // Decide which connection to use |
559 | 599 | $connection = $connection === null ? $db_connection : $connection; |
560 | 600 | |
561 | - if ($type == 'begin') |
|
562 | - return @mysqli_query($connection, 'BEGIN'); |
|
563 | - elseif ($type == 'rollback') |
|
564 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
565 | - elseif ($type == 'commit') |
|
566 | - return @mysqli_query($connection, 'COMMIT'); |
|
601 | + if ($type == 'begin') { |
|
602 | + return @mysqli_query($connection, 'BEGIN'); |
|
603 | + } elseif ($type == 'rollback') { |
|
604 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
605 | + } elseif ($type == 'commit') { |
|
606 | + return @mysqli_query($connection, 'COMMIT'); |
|
607 | + } |
|
567 | 608 | |
568 | 609 | return false; |
569 | 610 | } |
@@ -603,8 +644,9 @@ discard block |
||
603 | 644 | // 2013: Lost connection to server during query. |
604 | 645 | |
605 | 646 | // Log the error. |
606 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
607 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
647 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
648 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
649 | + } |
|
608 | 650 | |
609 | 651 | // Database error auto fixing ;). |
610 | 652 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -613,8 +655,9 @@ discard block |
||
613 | 655 | $old_cache = @$modSettings['cache_enable']; |
614 | 656 | $modSettings['cache_enable'] = '1'; |
615 | 657 | |
616 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
617 | - $db_last_error = max(@$db_last_error, $temp); |
|
658 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
659 | + $db_last_error = max(@$db_last_error, $temp); |
|
660 | + } |
|
618 | 661 | |
619 | 662 | if (@$db_last_error < time() - 3600 * 24 * 3) |
620 | 663 | { |
@@ -630,8 +673,9 @@ discard block |
||
630 | 673 | foreach ($tables as $table) |
631 | 674 | { |
632 | 675 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
633 | - if (trim($table) != '') |
|
634 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
676 | + if (trim($table) != '') { |
|
677 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
678 | + } |
|
635 | 679 | } |
636 | 680 | } |
637 | 681 | |
@@ -640,8 +684,9 @@ discard block |
||
640 | 684 | // Table crashed. Let's try to fix it. |
641 | 685 | elseif ($query_errno == 1016) |
642 | 686 | { |
643 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
644 | - $fix_tables = array('`' . $match[1] . '`'); |
|
687 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
688 | + $fix_tables = array('`' . $match[1] . '`'); |
|
689 | + } |
|
645 | 690 | } |
646 | 691 | // Indexes crashed. Should be easy to fix! |
647 | 692 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -660,13 +705,15 @@ discard block |
||
660 | 705 | |
661 | 706 | // Make a note of the REPAIR... |
662 | 707 | cache_put_data('db_last_error', time(), 600); |
663 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
664 | - updateSettingsFile(array('db_last_error' => time())); |
|
708 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
709 | + updateSettingsFile(array('db_last_error' => time())); |
|
710 | + } |
|
665 | 711 | |
666 | 712 | // Attempt to find and repair the broken table. |
667 | - foreach ($fix_tables as $table) |
|
668 | - $smcFunc['db_query']('', " |
|
713 | + foreach ($fix_tables as $table) { |
|
714 | + $smcFunc['db_query']('', " |
|
669 | 715 | REPAIR TABLE $table", false, false); |
716 | + } |
|
670 | 717 | |
671 | 718 | // And send off an email! |
672 | 719 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -675,11 +722,12 @@ discard block |
||
675 | 722 | |
676 | 723 | // Try the query again...? |
677 | 724 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
678 | - if ($ret !== false) |
|
679 | - return $ret; |
|
725 | + if ($ret !== false) { |
|
726 | + return $ret; |
|
727 | + } |
|
728 | + } else { |
|
729 | + $modSettings['cache_enable'] = $old_cache; |
|
680 | 730 | } |
681 | - else |
|
682 | - $modSettings['cache_enable'] = $old_cache; |
|
683 | 731 | |
684 | 732 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
685 | 733 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -689,22 +737,25 @@ discard block |
||
689 | 737 | // Are we in SSI mode? If so try that username and password first |
690 | 738 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
691 | 739 | { |
692 | - if (empty($db_persist)) |
|
693 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
694 | - else |
|
695 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
740 | + if (empty($db_persist)) { |
|
741 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
742 | + } else { |
|
743 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
744 | + } |
|
696 | 745 | } |
697 | 746 | // Fall back to the regular username and password if need be |
698 | 747 | if (!$db_connection) |
699 | 748 | { |
700 | - if (empty($db_persist)) |
|
701 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
702 | - else |
|
703 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
749 | + if (empty($db_persist)) { |
|
750 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
751 | + } else { |
|
752 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
753 | + } |
|
704 | 754 | } |
705 | 755 | |
706 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
707 | - $db_connection = false; |
|
756 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
757 | + $db_connection = false; |
|
758 | + } |
|
708 | 759 | } |
709 | 760 | |
710 | 761 | if ($db_connection) |
@@ -715,24 +766,27 @@ discard block |
||
715 | 766 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
716 | 767 | |
717 | 768 | $new_errno = mysqli_errno($db_connection); |
718 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
719 | - break; |
|
769 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
770 | + break; |
|
771 | + } |
|
720 | 772 | } |
721 | 773 | |
722 | 774 | // If it failed again, shucks to be you... we're not trying it over and over. |
723 | - if ($ret !== false) |
|
724 | - return $ret; |
|
775 | + if ($ret !== false) { |
|
776 | + return $ret; |
|
777 | + } |
|
725 | 778 | } |
726 | 779 | } |
727 | 780 | // Are they out of space, perhaps? |
728 | 781 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
729 | 782 | { |
730 | - if (!isset($txt)) |
|
731 | - $query_error .= ' - check database storage space.'; |
|
732 | - else |
|
783 | + if (!isset($txt)) { |
|
784 | + $query_error .= ' - check database storage space.'; |
|
785 | + } else |
|
733 | 786 | { |
734 | - if (!isset($txt['mysql_error_space'])) |
|
735 | - loadLanguage('Errors'); |
|
787 | + if (!isset($txt['mysql_error_space'])) { |
|
788 | + loadLanguage('Errors'); |
|
789 | + } |
|
736 | 790 | |
737 | 791 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
738 | 792 | } |
@@ -740,15 +794,17 @@ discard block |
||
740 | 794 | } |
741 | 795 | |
742 | 796 | // Nothing's defined yet... just die with it. |
743 | - if (empty($context) || empty($txt)) |
|
744 | - die($query_error); |
|
797 | + if (empty($context) || empty($txt)) { |
|
798 | + die($query_error); |
|
799 | + } |
|
745 | 800 | |
746 | 801 | // Show an error message, if possible. |
747 | 802 | $context['error_title'] = $txt['database_error']; |
748 | - if (allowedTo('admin_forum')) |
|
749 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
750 | - else |
|
751 | - $context['error_message'] = $txt['try_again']; |
|
803 | + if (allowedTo('admin_forum')) { |
|
804 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
805 | + } else { |
|
806 | + $context['error_message'] = $txt['try_again']; |
|
807 | + } |
|
752 | 808 | |
753 | 809 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
754 | 810 | { |
@@ -780,8 +836,9 @@ discard block |
||
780 | 836 | $return_var = null; |
781 | 837 | |
782 | 838 | // With nothing to insert, simply return. |
783 | - if (empty($data)) |
|
784 | - return; |
|
839 | + if (empty($data)) { |
|
840 | + return; |
|
841 | + } |
|
785 | 842 | |
786 | 843 | // Replace the prefix holder with the actual prefix. |
787 | 844 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -791,23 +848,26 @@ discard block |
||
791 | 848 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
792 | 849 | { |
793 | 850 | $with_returning = true; |
794 | - if ($returnmode == 2) |
|
795 | - $return_var = array(); |
|
851 | + if ($returnmode == 2) { |
|
852 | + $return_var = array(); |
|
853 | + } |
|
796 | 854 | } |
797 | 855 | |
798 | 856 | // Inserting data as a single row can be done as a single array. |
799 | - if (!is_array($data[array_rand($data)])) |
|
800 | - $data = array($data); |
|
857 | + if (!is_array($data[array_rand($data)])) { |
|
858 | + $data = array($data); |
|
859 | + } |
|
801 | 860 | |
802 | 861 | // Create the mold for a single row insert. |
803 | 862 | $insertData = '('; |
804 | 863 | foreach ($columns as $columnName => $type) |
805 | 864 | { |
806 | 865 | // Are we restricting the length? |
807 | - if (strpos($type, 'string-') !== false) |
|
808 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
809 | - else |
|
810 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
866 | + if (strpos($type, 'string-') !== false) { |
|
867 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
868 | + } else { |
|
869 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
870 | + } |
|
811 | 871 | } |
812 | 872 | $insertData = substr($insertData, 0, -2) . ')'; |
813 | 873 | |
@@ -816,8 +876,9 @@ discard block |
||
816 | 876 | |
817 | 877 | // Here's where the variables are injected to the query. |
818 | 878 | $insertRows = array(); |
819 | - foreach ($data as $dataRow) |
|
820 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
879 | + foreach ($data as $dataRow) { |
|
880 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
881 | + } |
|
821 | 882 | |
822 | 883 | // Determine the method of insertion. |
823 | 884 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -836,8 +897,7 @@ discard block |
||
836 | 897 | ), |
837 | 898 | $connection |
838 | 899 | ); |
839 | - } |
|
840 | - else //special way for ignore method with returning |
|
900 | + } else //special way for ignore method with returning |
|
841 | 901 | { |
842 | 902 | $count = count($insertRows); |
843 | 903 | $ai = 0; |
@@ -857,19 +917,21 @@ discard block |
||
857 | 917 | ); |
858 | 918 | $new_id = $smcFunc['db_insert_id'](); |
859 | 919 | |
860 | - if ($last_id != $new_id) //the inserted value was new |
|
920 | + if ($last_id != $new_id) { |
|
921 | + //the inserted value was new |
|
861 | 922 | { |
862 | 923 | $ai = $new_id; |
863 | 924 | } |
864 | - else // the inserted value already exists we need to find the pk |
|
925 | + } else // the inserted value already exists we need to find the pk |
|
865 | 926 | { |
866 | 927 | $where_string = ''; |
867 | 928 | $count2 = count($indexed_columns); |
868 | 929 | for ($x = 0; $x < $count2; $x++) |
869 | 930 | { |
870 | 931 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
871 | - if (($x + 1) < $count2) |
|
872 | - $where_string += ' AND '; |
|
932 | + if (($x + 1) < $count2) { |
|
933 | + $where_string += ' AND '; |
|
934 | + } |
|
873 | 935 | } |
874 | 936 | |
875 | 937 | $request = $smcFunc['db_query']('',' |
@@ -885,25 +947,27 @@ discard block |
||
885 | 947 | } |
886 | 948 | } |
887 | 949 | |
888 | - if ($returnmode == 1) |
|
889 | - $return_var = $ai; |
|
890 | - else if ($returnmode == 2) |
|
891 | - $return_var[] = $ai; |
|
950 | + if ($returnmode == 1) { |
|
951 | + $return_var = $ai; |
|
952 | + } else if ($returnmode == 2) { |
|
953 | + $return_var[] = $ai; |
|
954 | + } |
|
892 | 955 | } |
893 | 956 | } |
894 | 957 | |
895 | 958 | |
896 | 959 | if ($with_returning) |
897 | 960 | { |
898 | - if ($returnmode == 1 && empty($return_var)) |
|
899 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
900 | - else if ($returnmode == 2 && empty($return_var)) |
|
961 | + if ($returnmode == 1 && empty($return_var)) { |
|
962 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
963 | + } else if ($returnmode == 2 && empty($return_var)) |
|
901 | 964 | { |
902 | 965 | $return_var = array(); |
903 | 966 | $count = count($insertRows); |
904 | 967 | $start = smf_db_insert_id($table, $keys[0]); |
905 | - for ($i = 0; $i < $count; $i++ ) |
|
906 | - $return_var[] = $start + $i; |
|
968 | + for ($i = 0; $i < $count; $i++ ) { |
|
969 | + $return_var[] = $start + $i; |
|
970 | + } |
|
907 | 971 | } |
908 | 972 | return $return_var; |
909 | 973 | } |
@@ -921,8 +985,9 @@ discard block |
||
921 | 985 | */ |
922 | 986 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
923 | 987 | { |
924 | - if (empty($log_message)) |
|
925 | - $log_message = $error_message; |
|
988 | + if (empty($log_message)) { |
|
989 | + $log_message = $error_message; |
|
990 | + } |
|
926 | 991 | |
927 | 992 | foreach (debug_backtrace() as $step) |
928 | 993 | { |
@@ -941,12 +1006,14 @@ discard block |
||
941 | 1006 | } |
942 | 1007 | |
943 | 1008 | // A special case - we want the file and line numbers for debugging. |
944 | - if ($error_type == 'return') |
|
945 | - return array($file, $line); |
|
1009 | + if ($error_type == 'return') { |
|
1010 | + return array($file, $line); |
|
1011 | + } |
|
946 | 1012 | |
947 | 1013 | // Is always a critical error. |
948 | - if (function_exists('log_error')) |
|
949 | - log_error($log_message, 'critical', $file, $line); |
|
1014 | + if (function_exists('log_error')) { |
|
1015 | + log_error($log_message, 'critical', $file, $line); |
|
1016 | + } |
|
950 | 1017 | |
951 | 1018 | if (function_exists('fatal_error')) |
952 | 1019 | { |
@@ -954,12 +1021,12 @@ discard block |
||
954 | 1021 | |
955 | 1022 | // Cannot continue... |
956 | 1023 | exit; |
1024 | + } elseif ($error_type) { |
|
1025 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
1026 | + } else { |
|
1027 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
1028 | + } |
|
957 | 1029 | } |
958 | - elseif ($error_type) |
|
959 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
960 | - else |
|
961 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
962 | -} |
|
963 | 1030 | |
964 | 1031 | /** |
965 | 1032 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -976,10 +1043,11 @@ discard block |
||
976 | 1043 | '\\' => '\\\\', |
977 | 1044 | ); |
978 | 1045 | |
979 | - if ($translate_human_wildcards) |
|
980 | - $replacements += array( |
|
1046 | + if ($translate_human_wildcards) { |
|
1047 | + $replacements += array( |
|
981 | 1048 | '*' => '%', |
982 | 1049 | ); |
1050 | + } |
|
983 | 1051 | |
984 | 1052 | return strtr($string, $replacements); |
985 | 1053 | } |
@@ -993,8 +1061,9 @@ discard block |
||
993 | 1061 | */ |
994 | 1062 | function smf_is_resource($result) |
995 | 1063 | { |
996 | - if ($result instanceof mysqli_result) |
|
997 | - return true; |
|
1064 | + if ($result instanceof mysqli_result) { |
|
1065 | + return true; |
|
1066 | + } |
|
998 | 1067 | |
999 | 1068 | return false; |
1000 | 1069 | } |
@@ -1022,16 +1091,18 @@ discard block |
||
1022 | 1091 | global $db_prefix, $db_connection; |
1023 | 1092 | static $mysql_error_data_prep; |
1024 | 1093 | |
1025 | - if (empty($mysql_error_data_prep)) |
|
1026 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1094 | + if (empty($mysql_error_data_prep)) { |
|
1095 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1027 | 1096 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
1028 | 1097 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?)' |
1029 | 1098 | ); |
1099 | + } |
|
1030 | 1100 | |
1031 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
1032 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1033 | - else |
|
1034 | - $error_array[2] = null; |
|
1101 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
1102 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1103 | + } else { |
|
1104 | + $error_array[2] = null; |
|
1105 | + } |
|
1035 | 1106 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
1036 | 1107 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1037 | 1108 | $error_array[7], $error_array[8]); |
@@ -1053,8 +1124,9 @@ discard block |
||
1053 | 1124 | $count = count($array_values); |
1054 | 1125 | $then = ($desc ? ' THEN -' : ' THEN '); |
1055 | 1126 | |
1056 | - for ($i = 0; $i < $count; $i++) |
|
1057 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1127 | + for ($i = 0; $i < $count; $i++) { |
|
1128 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1129 | + } |
|
1058 | 1130 | |
1059 | 1131 | $return .= 'END'; |
1060 | 1132 | return $return; |