@@ -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)) |
@@ -435,8 +467,9 @@ discard block |
||
435 | 467 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
436 | 468 | |
437 | 469 | // Initialize $db_cache if not already initialized. |
438 | - if (!isset($db_cache)) |
|
439 | - $db_cache = array(); |
|
470 | + if (!isset($db_cache)) { |
|
471 | + $db_cache = array(); |
|
472 | + } |
|
440 | 473 | |
441 | 474 | if (!empty($_SESSION['debug_redirect'])) |
442 | 475 | { |
@@ -464,17 +497,18 @@ discard block |
||
464 | 497 | while (true) |
465 | 498 | { |
466 | 499 | $pos = strpos($db_string_1, '\'', $pos + 1); |
467 | - if ($pos === false) |
|
468 | - break; |
|
500 | + if ($pos === false) { |
|
501 | + break; |
|
502 | + } |
|
469 | 503 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
470 | 504 | |
471 | 505 | while (true) |
472 | 506 | { |
473 | 507 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
474 | 508 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
475 | - if ($pos1 === false) |
|
476 | - break; |
|
477 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
509 | + if ($pos1 === false) { |
|
510 | + break; |
|
511 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
478 | 512 | { |
479 | 513 | $pos = $pos1; |
480 | 514 | break; |
@@ -490,29 +524,35 @@ discard block |
||
490 | 524 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
491 | 525 | |
492 | 526 | // Comments? We don't use comments in our queries, we leave 'em outside! |
493 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
494 | - $fail = true; |
|
527 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
528 | + $fail = true; |
|
529 | + } |
|
495 | 530 | // Trying to change passwords, slow us down, or something? |
496 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
497 | - $fail = true; |
|
498 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
499 | - $fail = true; |
|
531 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
532 | + $fail = true; |
|
533 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
534 | + $fail = true; |
|
535 | + } |
|
500 | 536 | |
501 | - if (!empty($fail) && function_exists('log_error')) |
|
502 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
537 | + if (!empty($fail) && function_exists('log_error')) { |
|
538 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
539 | + } |
|
503 | 540 | } |
504 | 541 | |
505 | - if (empty($db_unbuffered)) |
|
506 | - $ret = @mysqli_query($connection, $db_string); |
|
507 | - else |
|
508 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
542 | + if (empty($db_unbuffered)) { |
|
543 | + $ret = @mysqli_query($connection, $db_string); |
|
544 | + } else { |
|
545 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
546 | + } |
|
509 | 547 | |
510 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
511 | - $ret = smf_db_error($db_string, $connection); |
|
548 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
549 | + $ret = smf_db_error($db_string, $connection); |
|
550 | + } |
|
512 | 551 | |
513 | 552 | // Debugging. |
514 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
515 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
553 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
554 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
555 | + } |
|
516 | 556 | |
517 | 557 | return $ret; |
518 | 558 | } |
@@ -559,12 +599,13 @@ discard block |
||
559 | 599 | // Decide which connection to use |
560 | 600 | $connection = $connection === null ? $db_connection : $connection; |
561 | 601 | |
562 | - if ($type == 'begin') |
|
563 | - return @mysqli_query($connection, 'BEGIN'); |
|
564 | - elseif ($type == 'rollback') |
|
565 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
566 | - elseif ($type == 'commit') |
|
567 | - return @mysqli_query($connection, 'COMMIT'); |
|
602 | + if ($type == 'begin') { |
|
603 | + return @mysqli_query($connection, 'BEGIN'); |
|
604 | + } elseif ($type == 'rollback') { |
|
605 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
606 | + } elseif ($type == 'commit') { |
|
607 | + return @mysqli_query($connection, 'COMMIT'); |
|
608 | + } |
|
568 | 609 | |
569 | 610 | return false; |
570 | 611 | } |
@@ -604,8 +645,9 @@ discard block |
||
604 | 645 | // 2013: Lost connection to server during query. |
605 | 646 | |
606 | 647 | // Log the error. |
607 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
608 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
648 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
649 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
650 | + } |
|
609 | 651 | |
610 | 652 | // Database error auto fixing ;). |
611 | 653 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -614,8 +656,9 @@ discard block |
||
614 | 656 | $old_cache = @$modSettings['cache_enable']; |
615 | 657 | $modSettings['cache_enable'] = '1'; |
616 | 658 | |
617 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
618 | - $db_last_error = max(@$db_last_error, $temp); |
|
659 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
660 | + $db_last_error = max(@$db_last_error, $temp); |
|
661 | + } |
|
619 | 662 | |
620 | 663 | if (@$db_last_error < time() - 3600 * 24 * 3) |
621 | 664 | { |
@@ -631,8 +674,9 @@ discard block |
||
631 | 674 | foreach ($tables as $table) |
632 | 675 | { |
633 | 676 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
634 | - if (trim($table) != '') |
|
635 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
677 | + if (trim($table) != '') { |
|
678 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
679 | + } |
|
636 | 680 | } |
637 | 681 | } |
638 | 682 | |
@@ -641,8 +685,9 @@ discard block |
||
641 | 685 | // Table crashed. Let's try to fix it. |
642 | 686 | elseif ($query_errno == 1016) |
643 | 687 | { |
644 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
645 | - $fix_tables = array('`' . $match[1] . '`'); |
|
688 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
689 | + $fix_tables = array('`' . $match[1] . '`'); |
|
690 | + } |
|
646 | 691 | } |
647 | 692 | // Indexes crashed. Should be easy to fix! |
648 | 693 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -661,13 +706,15 @@ discard block |
||
661 | 706 | |
662 | 707 | // Make a note of the REPAIR... |
663 | 708 | cache_put_data('db_last_error', time(), 600); |
664 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
665 | - updateSettingsFile(array('db_last_error' => time())); |
|
709 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
710 | + updateSettingsFile(array('db_last_error' => time())); |
|
711 | + } |
|
666 | 712 | |
667 | 713 | // Attempt to find and repair the broken table. |
668 | - foreach ($fix_tables as $table) |
|
669 | - $smcFunc['db_query']('', " |
|
714 | + foreach ($fix_tables as $table) { |
|
715 | + $smcFunc['db_query']('', " |
|
670 | 716 | REPAIR TABLE $table", false, false); |
717 | + } |
|
671 | 718 | |
672 | 719 | // And send off an email! |
673 | 720 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -676,11 +723,12 @@ discard block |
||
676 | 723 | |
677 | 724 | // Try the query again...? |
678 | 725 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
679 | - if ($ret !== false) |
|
680 | - return $ret; |
|
726 | + if ($ret !== false) { |
|
727 | + return $ret; |
|
728 | + } |
|
729 | + } else { |
|
730 | + $modSettings['cache_enable'] = $old_cache; |
|
681 | 731 | } |
682 | - else |
|
683 | - $modSettings['cache_enable'] = $old_cache; |
|
684 | 732 | |
685 | 733 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
686 | 734 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -690,22 +738,25 @@ discard block |
||
690 | 738 | // Are we in SSI mode? If so try that username and password first |
691 | 739 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
692 | 740 | { |
693 | - if (empty($db_persist)) |
|
694 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
695 | - else |
|
696 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
741 | + if (empty($db_persist)) { |
|
742 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
743 | + } else { |
|
744 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
745 | + } |
|
697 | 746 | } |
698 | 747 | // Fall back to the regular username and password if need be |
699 | 748 | if (!$db_connection) |
700 | 749 | { |
701 | - if (empty($db_persist)) |
|
702 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
703 | - else |
|
704 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
750 | + if (empty($db_persist)) { |
|
751 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
752 | + } else { |
|
753 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
754 | + } |
|
705 | 755 | } |
706 | 756 | |
707 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
708 | - $db_connection = false; |
|
757 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
758 | + $db_connection = false; |
|
759 | + } |
|
709 | 760 | } |
710 | 761 | |
711 | 762 | if ($db_connection) |
@@ -716,24 +767,27 @@ discard block |
||
716 | 767 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
717 | 768 | |
718 | 769 | $new_errno = mysqli_errno($db_connection); |
719 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
720 | - break; |
|
770 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
771 | + break; |
|
772 | + } |
|
721 | 773 | } |
722 | 774 | |
723 | 775 | // If it failed again, shucks to be you... we're not trying it over and over. |
724 | - if ($ret !== false) |
|
725 | - return $ret; |
|
776 | + if ($ret !== false) { |
|
777 | + return $ret; |
|
778 | + } |
|
726 | 779 | } |
727 | 780 | } |
728 | 781 | // Are they out of space, perhaps? |
729 | 782 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
730 | 783 | { |
731 | - if (!isset($txt)) |
|
732 | - $query_error .= ' - check database storage space.'; |
|
733 | - else |
|
784 | + if (!isset($txt)) { |
|
785 | + $query_error .= ' - check database storage space.'; |
|
786 | + } else |
|
734 | 787 | { |
735 | - if (!isset($txt['mysql_error_space'])) |
|
736 | - loadLanguage('Errors'); |
|
788 | + if (!isset($txt['mysql_error_space'])) { |
|
789 | + loadLanguage('Errors'); |
|
790 | + } |
|
737 | 791 | |
738 | 792 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
739 | 793 | } |
@@ -741,15 +795,17 @@ discard block |
||
741 | 795 | } |
742 | 796 | |
743 | 797 | // Nothing's defined yet... just die with it. |
744 | - if (empty($context) || empty($txt)) |
|
745 | - die($query_error); |
|
798 | + if (empty($context) || empty($txt)) { |
|
799 | + die($query_error); |
|
800 | + } |
|
746 | 801 | |
747 | 802 | // Show an error message, if possible. |
748 | 803 | $context['error_title'] = $txt['database_error']; |
749 | - if (allowedTo('admin_forum')) |
|
750 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
751 | - else |
|
752 | - $context['error_message'] = $txt['try_again']; |
|
804 | + if (allowedTo('admin_forum')) { |
|
805 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
806 | + } else { |
|
807 | + $context['error_message'] = $txt['try_again']; |
|
808 | + } |
|
753 | 809 | |
754 | 810 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
755 | 811 | { |
@@ -781,8 +837,9 @@ discard block |
||
781 | 837 | $return_var = null; |
782 | 838 | |
783 | 839 | // With nothing to insert, simply return. |
784 | - if (empty($data)) |
|
785 | - return; |
|
840 | + if (empty($data)) { |
|
841 | + return; |
|
842 | + } |
|
786 | 843 | |
787 | 844 | // Replace the prefix holder with the actual prefix. |
788 | 845 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -792,23 +849,26 @@ discard block |
||
792 | 849 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
793 | 850 | { |
794 | 851 | $with_returning = true; |
795 | - if ($returnmode == 2) |
|
796 | - $return_var = array(); |
|
852 | + if ($returnmode == 2) { |
|
853 | + $return_var = array(); |
|
854 | + } |
|
797 | 855 | } |
798 | 856 | |
799 | 857 | // Inserting data as a single row can be done as a single array. |
800 | - if (!is_array($data[array_rand($data)])) |
|
801 | - $data = array($data); |
|
858 | + if (!is_array($data[array_rand($data)])) { |
|
859 | + $data = array($data); |
|
860 | + } |
|
802 | 861 | |
803 | 862 | // Create the mold for a single row insert. |
804 | 863 | $insertData = '('; |
805 | 864 | foreach ($columns as $columnName => $type) |
806 | 865 | { |
807 | 866 | // Are we restricting the length? |
808 | - if (strpos($type, 'string-') !== false) |
|
809 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
810 | - else |
|
811 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
867 | + if (strpos($type, 'string-') !== false) { |
|
868 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
869 | + } else { |
|
870 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
871 | + } |
|
812 | 872 | } |
813 | 873 | $insertData = substr($insertData, 0, -2) . ')'; |
814 | 874 | |
@@ -817,8 +877,9 @@ discard block |
||
817 | 877 | |
818 | 878 | // Here's where the variables are injected to the query. |
819 | 879 | $insertRows = array(); |
820 | - foreach ($data as $dataRow) |
|
821 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
880 | + foreach ($data as $dataRow) { |
|
881 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
882 | + } |
|
822 | 883 | |
823 | 884 | // Determine the method of insertion. |
824 | 885 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -837,8 +898,7 @@ discard block |
||
837 | 898 | ), |
838 | 899 | $connection |
839 | 900 | ); |
840 | - } |
|
841 | - else //special way for ignore method with returning |
|
901 | + } else //special way for ignore method with returning |
|
842 | 902 | { |
843 | 903 | $count = count($insertRows); |
844 | 904 | $ai = 0; |
@@ -858,19 +918,21 @@ discard block |
||
858 | 918 | ); |
859 | 919 | $new_id = $smcFunc['db_insert_id'](); |
860 | 920 | |
861 | - if ($last_id != $new_id) //the inserted value was new |
|
921 | + if ($last_id != $new_id) { |
|
922 | + //the inserted value was new |
|
862 | 923 | { |
863 | 924 | $ai = $new_id; |
864 | 925 | } |
865 | - else // the inserted value already exists we need to find the pk |
|
926 | + } else // the inserted value already exists we need to find the pk |
|
866 | 927 | { |
867 | 928 | $where_string = ''; |
868 | 929 | $count2 = count($indexed_columns); |
869 | 930 | for ($x = 0; $x < $count2; $x++) |
870 | 931 | { |
871 | 932 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
872 | - if (($x + 1) < $count2) |
|
873 | - $where_string += ' AND '; |
|
933 | + if (($x + 1) < $count2) { |
|
934 | + $where_string += ' AND '; |
|
935 | + } |
|
874 | 936 | } |
875 | 937 | |
876 | 938 | $request = $smcFunc['db_query']('',' |
@@ -886,25 +948,27 @@ discard block |
||
886 | 948 | } |
887 | 949 | } |
888 | 950 | |
889 | - if ($returnmode == 1) |
|
890 | - $return_var = $ai; |
|
891 | - else if ($returnmode == 2) |
|
892 | - $return_var[] = $ai; |
|
951 | + if ($returnmode == 1) { |
|
952 | + $return_var = $ai; |
|
953 | + } else if ($returnmode == 2) { |
|
954 | + $return_var[] = $ai; |
|
955 | + } |
|
893 | 956 | } |
894 | 957 | } |
895 | 958 | |
896 | 959 | |
897 | 960 | if ($with_returning) |
898 | 961 | { |
899 | - if ($returnmode == 1 && empty($return_var)) |
|
900 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
901 | - else if ($returnmode == 2 && empty($return_var)) |
|
962 | + if ($returnmode == 1 && empty($return_var)) { |
|
963 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
964 | + } else if ($returnmode == 2 && empty($return_var)) |
|
902 | 965 | { |
903 | 966 | $return_var = array(); |
904 | 967 | $count = count($insertRows); |
905 | 968 | $start = smf_db_insert_id($table, $keys[0]); |
906 | - for ($i = 0; $i < $count; $i++ ) |
|
907 | - $return_var[] = $start + $i; |
|
969 | + for ($i = 0; $i < $count; $i++ ) { |
|
970 | + $return_var[] = $start + $i; |
|
971 | + } |
|
908 | 972 | } |
909 | 973 | return $return_var; |
910 | 974 | } |
@@ -922,8 +986,9 @@ discard block |
||
922 | 986 | */ |
923 | 987 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
924 | 988 | { |
925 | - if (empty($log_message)) |
|
926 | - $log_message = $error_message; |
|
989 | + if (empty($log_message)) { |
|
990 | + $log_message = $error_message; |
|
991 | + } |
|
927 | 992 | |
928 | 993 | foreach (debug_backtrace() as $step) |
929 | 994 | { |
@@ -942,12 +1007,14 @@ discard block |
||
942 | 1007 | } |
943 | 1008 | |
944 | 1009 | // A special case - we want the file and line numbers for debugging. |
945 | - if ($error_type == 'return') |
|
946 | - return array($file, $line); |
|
1010 | + if ($error_type == 'return') { |
|
1011 | + return array($file, $line); |
|
1012 | + } |
|
947 | 1013 | |
948 | 1014 | // Is always a critical error. |
949 | - if (function_exists('log_error')) |
|
950 | - log_error($log_message, 'critical', $file, $line); |
|
1015 | + if (function_exists('log_error')) { |
|
1016 | + log_error($log_message, 'critical', $file, $line); |
|
1017 | + } |
|
951 | 1018 | |
952 | 1019 | if (function_exists('fatal_error')) |
953 | 1020 | { |
@@ -955,12 +1022,12 @@ discard block |
||
955 | 1022 | |
956 | 1023 | // Cannot continue... |
957 | 1024 | exit; |
1025 | + } elseif ($error_type) { |
|
1026 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
1027 | + } else { |
|
1028 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
1029 | + } |
|
958 | 1030 | } |
959 | - elseif ($error_type) |
|
960 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
961 | - else |
|
962 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
963 | -} |
|
964 | 1031 | |
965 | 1032 | /** |
966 | 1033 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -977,10 +1044,11 @@ discard block |
||
977 | 1044 | '\\' => '\\\\', |
978 | 1045 | ); |
979 | 1046 | |
980 | - if ($translate_human_wildcards) |
|
981 | - $replacements += array( |
|
1047 | + if ($translate_human_wildcards) { |
|
1048 | + $replacements += array( |
|
982 | 1049 | '*' => '%', |
983 | 1050 | ); |
1051 | + } |
|
984 | 1052 | |
985 | 1053 | return strtr($string, $replacements); |
986 | 1054 | } |
@@ -994,8 +1062,9 @@ discard block |
||
994 | 1062 | */ |
995 | 1063 | function smf_is_resource($result) |
996 | 1064 | { |
997 | - if ($result instanceof mysqli_result) |
|
998 | - return true; |
|
1065 | + if ($result instanceof mysqli_result) { |
|
1066 | + return true; |
|
1067 | + } |
|
999 | 1068 | |
1000 | 1069 | return false; |
1001 | 1070 | } |
@@ -1023,16 +1092,18 @@ discard block |
||
1023 | 1092 | global $db_prefix, $db_connection; |
1024 | 1093 | static $mysql_error_data_prep; |
1025 | 1094 | |
1026 | - if (empty($mysql_error_data_prep)) |
|
1027 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1095 | + if (empty($mysql_error_data_prep)) { |
|
1096 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1028 | 1097 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
1029 | 1098 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?)' |
1030 | 1099 | ); |
1100 | + } |
|
1031 | 1101 | |
1032 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
1033 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1034 | - else |
|
1035 | - $error_array[2] = null; |
|
1102 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
1103 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1104 | + } else { |
|
1105 | + $error_array[2] = null; |
|
1106 | + } |
|
1036 | 1107 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
1037 | 1108 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1038 | 1109 | $error_array[7], $error_array[8]); |
@@ -1054,8 +1125,9 @@ discard block |
||
1054 | 1125 | $count = count($array_values); |
1055 | 1126 | $then = ($desc ? ' THEN -' : ' THEN '); |
1056 | 1127 | |
1057 | - for ($i = 0; $i < $count; $i++) |
|
1058 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1128 | + for ($i = 0; $i < $count; $i++) { |
|
1129 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1130 | + } |
|
1059 | 1131 | |
1060 | 1132 | $return .= 'END'; |
1061 | 1133 | return $return; |
@@ -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 | * Check if the user is who he/she says he is |
@@ -42,12 +43,14 @@ discard block |
||
42 | 43 | $refreshTime = isset($_GET['xml']) ? 4200 : 3600; |
43 | 44 | |
44 | 45 | // Is the security option off? |
45 | - if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) |
|
46 | - return; |
|
46 | + if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) { |
|
47 | + return; |
|
48 | + } |
|
47 | 49 | |
48 | 50 | // Or are they already logged in?, Moderator or admin session is need for this area |
49 | - if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) |
|
50 | - return; |
|
51 | + if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) { |
|
52 | + return; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | require_once($sourcedir . '/Subs-Auth.php'); |
53 | 56 | |
@@ -55,8 +58,9 @@ discard block |
||
55 | 58 | if (isset($_POST[$type . '_pass'])) |
56 | 59 | { |
57 | 60 | // Check to ensure we're forcing SSL for authentication |
58 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
59 | - fatal_lang_error('login_ssl_required'); |
|
61 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
62 | + fatal_lang_error('login_ssl_required'); |
|
63 | + } |
|
60 | 64 | |
61 | 65 | checkSession(); |
62 | 66 | |
@@ -72,17 +76,19 @@ discard block |
||
72 | 76 | } |
73 | 77 | |
74 | 78 | // Better be sure to remember the real referer |
75 | - if (empty($_SESSION['request_referer'])) |
|
76 | - $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
77 | - elseif (empty($_POST)) |
|
78 | - unset($_SESSION['request_referer']); |
|
79 | + if (empty($_SESSION['request_referer'])) { |
|
80 | + $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
81 | + } elseif (empty($_POST)) { |
|
82 | + unset($_SESSION['request_referer']); |
|
83 | + } |
|
79 | 84 | |
80 | 85 | // Need to type in a password for that, man. |
81 | - if (!isset($_GET['xml'])) |
|
82 | - adminLogin($type); |
|
83 | - else |
|
84 | - return 'session_verify_fail'; |
|
85 | -} |
|
86 | + if (!isset($_GET['xml'])) { |
|
87 | + adminLogin($type); |
|
88 | + } else { |
|
89 | + return 'session_verify_fail'; |
|
90 | + } |
|
91 | + } |
|
86 | 92 | |
87 | 93 | /** |
88 | 94 | * Require a user who is logged in. (not a guest.) |
@@ -96,25 +102,30 @@ discard block |
||
96 | 102 | global $user_info, $txt, $context, $scripturl, $modSettings; |
97 | 103 | |
98 | 104 | // Luckily, this person isn't a guest. |
99 | - if (!$user_info['is_guest']) |
|
100 | - return; |
|
105 | + if (!$user_info['is_guest']) { |
|
106 | + return; |
|
107 | + } |
|
101 | 108 | |
102 | 109 | // Log what they were trying to do didn't work) |
103 | - if (!empty($modSettings['who_enabled'])) |
|
104 | - $_GET['error'] = 'guest_login'; |
|
110 | + if (!empty($modSettings['who_enabled'])) { |
|
111 | + $_GET['error'] = 'guest_login'; |
|
112 | + } |
|
105 | 113 | writeLog(true); |
106 | 114 | |
107 | 115 | // Just die. |
108 | - if (isset($_REQUEST['xml'])) |
|
109 | - obExit(false); |
|
116 | + if (isset($_REQUEST['xml'])) { |
|
117 | + obExit(false); |
|
118 | + } |
|
110 | 119 | |
111 | 120 | // Attempt to detect if they came from dlattach. |
112 | - if (SMF != 'SSI' && empty($context['theme_loaded'])) |
|
113 | - loadTheme(); |
|
121 | + if (SMF != 'SSI' && empty($context['theme_loaded'])) { |
|
122 | + loadTheme(); |
|
123 | + } |
|
114 | 124 | |
115 | 125 | // Never redirect to an attachment |
116 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
117 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
126 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
127 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
128 | + } |
|
118 | 129 | |
119 | 130 | // Load the Login template and language file. |
120 | 131 | loadLanguage('Login'); |
@@ -124,8 +135,7 @@ discard block |
||
124 | 135 | { |
125 | 136 | $_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING']; |
126 | 137 | redirectexit('action=login'); |
127 | - } |
|
128 | - else |
|
138 | + } else |
|
129 | 139 | { |
130 | 140 | loadTemplate('Login'); |
131 | 141 | $context['sub_template'] = 'kick_guest'; |
@@ -155,8 +165,9 @@ discard block |
||
155 | 165 | global $sourcedir, $cookiename, $user_settings, $smcFunc; |
156 | 166 | |
157 | 167 | // You cannot be banned if you are an admin - doesn't help if you log out. |
158 | - if ($user_info['is_admin']) |
|
159 | - return; |
|
168 | + if ($user_info['is_admin']) { |
|
169 | + return; |
|
170 | + } |
|
160 | 171 | |
161 | 172 | // Only check the ban every so often. (to reduce load.) |
162 | 173 | if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email'])) |
@@ -177,8 +188,9 @@ discard block |
||
177 | 188 | // Check both IP addresses. |
178 | 189 | foreach (array('ip', 'ip2') as $ip_number) |
179 | 190 | { |
180 | - if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) |
|
181 | - continue; |
|
191 | + if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) { |
|
192 | + continue; |
|
193 | + } |
|
182 | 194 | $ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high'; |
183 | 195 | $ban_query_vars[$ip_number] = $user_info[$ip_number]; |
184 | 196 | // IP was valid, maybe there's also a hostname... |
@@ -228,24 +240,28 @@ discard block |
||
228 | 240 | // Store every type of ban that applies to you in your session. |
229 | 241 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
230 | 242 | { |
231 | - foreach ($restrictions as $restriction) |
|
232 | - if (!empty($row[$restriction])) |
|
243 | + foreach ($restrictions as $restriction) { |
|
244 | + if (!empty($row[$restriction])) |
|
233 | 245 | { |
234 | 246 | $_SESSION['ban'][$restriction]['reason'] = $row['reason']; |
247 | + } |
|
235 | 248 | $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban']; |
236 | - if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) |
|
237 | - $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
249 | + if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) { |
|
250 | + $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
251 | + } |
|
238 | 252 | |
239 | - if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) |
|
240 | - $flag_is_activated = true; |
|
253 | + if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) { |
|
254 | + $flag_is_activated = true; |
|
255 | + } |
|
241 | 256 | } |
242 | 257 | } |
243 | 258 | $smcFunc['db_free_result']($request); |
244 | 259 | } |
245 | 260 | |
246 | 261 | // Mark the cannot_access and cannot_post bans as being 'hit'. |
247 | - if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) |
|
248 | - log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
262 | + if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) { |
|
263 | + log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
264 | + } |
|
249 | 265 | |
250 | 266 | // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up. |
251 | 267 | if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated) |
@@ -260,8 +276,9 @@ discard block |
||
260 | 276 | if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) |
261 | 277 | { |
262 | 278 | $bans = explode(',', $_COOKIE[$cookiename . '_']); |
263 | - foreach ($bans as $key => $value) |
|
264 | - $bans[$key] = (int) $value; |
|
279 | + foreach ($bans as $key => $value) { |
|
280 | + $bans[$key] = (int) $value; |
|
281 | + } |
|
265 | 282 | $request = $smcFunc['db_query']('', ' |
266 | 283 | SELECT bi.id_ban, bg.reason |
267 | 284 | FROM {db_prefix}ban_items AS bi |
@@ -297,14 +314,15 @@ discard block |
||
297 | 314 | if (isset($_SESSION['ban']['cannot_access'])) |
298 | 315 | { |
299 | 316 | // We don't wanna see you! |
300 | - if (!$user_info['is_guest']) |
|
301 | - $smcFunc['db_query']('', ' |
|
317 | + if (!$user_info['is_guest']) { |
|
318 | + $smcFunc['db_query']('', ' |
|
302 | 319 | DELETE FROM {db_prefix}log_online |
303 | 320 | WHERE id_member = {int:current_member}', |
304 | 321 | array( |
305 | 322 | 'current_member' => $user_info['id'], |
306 | 323 | ) |
307 | 324 | ); |
325 | + } |
|
308 | 326 | |
309 | 327 | // 'Log' the user out. Can't have any funny business... (save the name!) |
310 | 328 | $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title']; |
@@ -390,9 +408,10 @@ discard block |
||
390 | 408 | } |
391 | 409 | |
392 | 410 | // Fix up the banning permissions. |
393 | - if (isset($user_info['permissions'])) |
|
394 | - banPermissions(); |
|
395 | -} |
|
411 | + if (isset($user_info['permissions'])) { |
|
412 | + banPermissions(); |
|
413 | + } |
|
414 | + } |
|
396 | 415 | |
397 | 416 | /** |
398 | 417 | * Fix permissions according to ban status. |
@@ -403,8 +422,9 @@ discard block |
||
403 | 422 | global $user_info, $sourcedir, $modSettings, $context; |
404 | 423 | |
405 | 424 | // Somehow they got here, at least take away all permissions... |
406 | - if (isset($_SESSION['ban']['cannot_access'])) |
|
407 | - $user_info['permissions'] = array(); |
|
425 | + if (isset($_SESSION['ban']['cannot_access'])) { |
|
426 | + $user_info['permissions'] = array(); |
|
427 | + } |
|
408 | 428 | // Okay, well, you can watch, but don't touch a thing. |
409 | 429 | elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning'])) |
410 | 430 | { |
@@ -446,19 +466,20 @@ discard block |
||
446 | 466 | call_integration_hook('integrate_warn_permissions', array(&$permission_change)); |
447 | 467 | foreach ($permission_change as $old => $new) |
448 | 468 | { |
449 | - if (!in_array($old, $user_info['permissions'])) |
|
450 | - unset($permission_change[$old]); |
|
451 | - else |
|
452 | - $user_info['permissions'][] = $new; |
|
469 | + if (!in_array($old, $user_info['permissions'])) { |
|
470 | + unset($permission_change[$old]); |
|
471 | + } else { |
|
472 | + $user_info['permissions'][] = $new; |
|
473 | + } |
|
453 | 474 | } |
454 | 475 | $user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change)); |
455 | 476 | } |
456 | 477 | |
457 | 478 | // @todo Find a better place to call this? Needs to be after permissions loaded! |
458 | 479 | // Finally, some bits we cache in the session because it saves queries. |
459 | - if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) |
|
460 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
461 | - else |
|
480 | + if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) { |
|
481 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
482 | + } else |
|
462 | 483 | { |
463 | 484 | require_once($sourcedir . '/Subs-Auth.php'); |
464 | 485 | rebuildModCache(); |
@@ -469,14 +490,12 @@ discard block |
||
469 | 490 | { |
470 | 491 | $context['open_mod_reports'] = $_SESSION['rc']['reports']; |
471 | 492 | $context['open_member_reports'] = $_SESSION['rc']['member_reports']; |
472 | - } |
|
473 | - elseif ($_SESSION['mc']['bq'] != '0=1') |
|
493 | + } elseif ($_SESSION['mc']['bq'] != '0=1') |
|
474 | 494 | { |
475 | 495 | require_once($sourcedir . '/Subs-ReportedContent.php'); |
476 | 496 | $context['open_mod_reports'] = recountOpenReports('posts'); |
477 | 497 | $context['open_member_reports'] = recountOpenReports('members'); |
478 | - } |
|
479 | - else |
|
498 | + } else |
|
480 | 499 | { |
481 | 500 | $context['open_mod_reports'] = 0; |
482 | 501 | $context['open_member_reports'] = 0; |
@@ -496,8 +515,9 @@ discard block |
||
496 | 515 | global $user_info, $smcFunc; |
497 | 516 | |
498 | 517 | // Don't log web accelerators, it's very confusing... |
499 | - if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
|
500 | - return; |
|
518 | + if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') { |
|
519 | + return; |
|
520 | + } |
|
501 | 521 | |
502 | 522 | $smcFunc['db_insert']('', |
503 | 523 | '{db_prefix}log_banned', |
@@ -507,8 +527,8 @@ discard block |
||
507 | 527 | ); |
508 | 528 | |
509 | 529 | // One extra point for these bans. |
510 | - if (!empty($ban_ids)) |
|
511 | - $smcFunc['db_query']('', ' |
|
530 | + if (!empty($ban_ids)) { |
|
531 | + $smcFunc['db_query']('', ' |
|
512 | 532 | UPDATE {db_prefix}ban_items |
513 | 533 | SET hits = hits + 1 |
514 | 534 | WHERE id_ban IN ({array_int:ban_ids})', |
@@ -516,7 +536,8 @@ discard block |
||
516 | 536 | 'ban_ids' => $ban_ids, |
517 | 537 | ) |
518 | 538 | ); |
519 | -} |
|
539 | + } |
|
540 | + } |
|
520 | 541 | |
521 | 542 | /** |
522 | 543 | * Checks if a given email address might be banned. |
@@ -532,8 +553,9 @@ discard block |
||
532 | 553 | global $txt, $smcFunc; |
533 | 554 | |
534 | 555 | // Can't ban an empty email |
535 | - if (empty($email) || trim($email) == '') |
|
536 | - return; |
|
556 | + if (empty($email) || trim($email) == '') { |
|
557 | + return; |
|
558 | + } |
|
537 | 559 | |
538 | 560 | // Let's start with the bans based on your IP/hostname/memberID... |
539 | 561 | $ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array(); |
@@ -606,16 +628,18 @@ discard block |
||
606 | 628 | if ($type == 'post') |
607 | 629 | { |
608 | 630 | $check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null); |
609 | - if ($check !== $sc) |
|
610 | - $error = 'session_timeout'; |
|
631 | + if ($check !== $sc) { |
|
632 | + $error = 'session_timeout'; |
|
633 | + } |
|
611 | 634 | } |
612 | 635 | |
613 | 636 | // How about $_GET['sesc']? |
614 | 637 | elseif ($type == 'get') |
615 | 638 | { |
616 | 639 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null); |
617 | - if ($check !== $sc) |
|
618 | - $error = 'session_verify_fail'; |
|
640 | + if ($check !== $sc) { |
|
641 | + $error = 'session_verify_fail'; |
|
642 | + } |
|
619 | 643 | } |
620 | 644 | |
621 | 645 | // Or can it be in either? |
@@ -623,13 +647,15 @@ discard block |
||
623 | 647 | { |
624 | 648 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null))); |
625 | 649 | |
626 | - if ($check !== $sc) |
|
627 | - $error = 'session_verify_fail'; |
|
650 | + if ($check !== $sc) { |
|
651 | + $error = 'session_verify_fail'; |
|
652 | + } |
|
628 | 653 | } |
629 | 654 | |
630 | 655 | // Verify that they aren't changing user agents on us - that could be bad. |
631 | - if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) |
|
632 | - $error = 'session_verify_fail'; |
|
656 | + if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) { |
|
657 | + $error = 'session_verify_fail'; |
|
658 | + } |
|
633 | 659 | |
634 | 660 | // Make sure a page with session check requirement is not being prefetched. |
635 | 661 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -640,30 +666,35 @@ discard block |
||
640 | 666 | } |
641 | 667 | |
642 | 668 | // Check the referring site - it should be the same server at least! |
643 | - if (isset($_SESSION['request_referer'])) |
|
644 | - $referrer = $_SESSION['request_referer']; |
|
645 | - else |
|
646 | - $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
669 | + if (isset($_SESSION['request_referer'])) { |
|
670 | + $referrer = $_SESSION['request_referer']; |
|
671 | + } else { |
|
672 | + $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
673 | + } |
|
647 | 674 | if (!empty($referrer['host'])) |
648 | 675 | { |
649 | - if (strpos($_SERVER['HTTP_HOST'], ':') !== false) |
|
650 | - $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
651 | - else |
|
652 | - $real_host = $_SERVER['HTTP_HOST']; |
|
676 | + if (strpos($_SERVER['HTTP_HOST'], ':') !== false) { |
|
677 | + $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
678 | + } else { |
|
679 | + $real_host = $_SERVER['HTTP_HOST']; |
|
680 | + } |
|
653 | 681 | |
654 | 682 | $parsed_url = parse_url($boardurl); |
655 | 683 | |
656 | 684 | // Are global cookies on? If so, let's check them ;). |
657 | 685 | if (!empty($modSettings['globalCookies'])) |
658 | 686 | { |
659 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
660 | - $parsed_url['host'] = $parts[1]; |
|
687 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
688 | + $parsed_url['host'] = $parts[1]; |
|
689 | + } |
|
661 | 690 | |
662 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) |
|
663 | - $referrer['host'] = $parts[1]; |
|
691 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) { |
|
692 | + $referrer['host'] = $parts[1]; |
|
693 | + } |
|
664 | 694 | |
665 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) |
|
666 | - $real_host = $parts[1]; |
|
695 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) { |
|
696 | + $real_host = $parts[1]; |
|
697 | + } |
|
667 | 698 | } |
668 | 699 | |
669 | 700 | // Okay: referrer must either match parsed_url or real_host. |
@@ -681,12 +712,14 @@ discard block |
||
681 | 712 | $log_error = true; |
682 | 713 | } |
683 | 714 | |
684 | - if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') |
|
685 | - fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
715 | + if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') { |
|
716 | + fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
717 | + } |
|
686 | 718 | |
687 | 719 | // Everything is ok, return an empty string. |
688 | - if (!isset($error)) |
|
689 | - return ''; |
|
720 | + if (!isset($error)) { |
|
721 | + return ''; |
|
722 | + } |
|
690 | 723 | // A session error occurred, show the error. |
691 | 724 | elseif ($is_fatal) |
692 | 725 | { |
@@ -695,13 +728,14 @@ discard block |
||
695 | 728 | ob_end_clean(); |
696 | 729 | header('HTTP/1.1 403 Forbidden - Session timeout'); |
697 | 730 | die; |
731 | + } else { |
|
732 | + fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
698 | 733 | } |
699 | - else |
|
700 | - fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
701 | 734 | } |
702 | 735 | // A session error occurred, return the error to the calling function. |
703 | - else |
|
704 | - return $error; |
|
736 | + else { |
|
737 | + return $error; |
|
738 | + } |
|
705 | 739 | |
706 | 740 | // We really should never fall through here, for very important reasons. Let's make sure. |
707 | 741 | trigger_error('Hacking attempt...', E_USER_ERROR); |
@@ -717,10 +751,9 @@ discard block |
||
717 | 751 | { |
718 | 752 | global $modSettings; |
719 | 753 | |
720 | - if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) |
|
721 | - return true; |
|
722 | - |
|
723 | - else |
|
754 | + if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) { |
|
755 | + return true; |
|
756 | + } else |
|
724 | 757 | { |
725 | 758 | $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']); |
726 | 759 | $_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']); |
@@ -771,9 +804,9 @@ discard block |
||
771 | 804 | $return = $_SESSION['token'][$type . '-' . $action][3]; |
772 | 805 | unset($_SESSION['token'][$type . '-' . $action]); |
773 | 806 | return $return; |
807 | + } else { |
|
808 | + return ''; |
|
774 | 809 | } |
775 | - else |
|
776 | - return ''; |
|
777 | 810 | } |
778 | 811 | |
779 | 812 | // This nasty piece of code validates a token. |
@@ -804,12 +837,14 @@ discard block |
||
804 | 837 | fatal_lang_error('token_verify_fail', false); |
805 | 838 | } |
806 | 839 | // Remove this token as its useless |
807 | - else |
|
808 | - unset($_SESSION['token'][$type . '-' . $action]); |
|
840 | + else { |
|
841 | + unset($_SESSION['token'][$type . '-' . $action]); |
|
842 | + } |
|
809 | 843 | |
810 | 844 | // Randomly check if we should remove some older tokens. |
811 | - if (mt_rand(0, 138) == 23) |
|
812 | - cleanTokens(); |
|
845 | + if (mt_rand(0, 138) == 23) { |
|
846 | + cleanTokens(); |
|
847 | + } |
|
813 | 848 | |
814 | 849 | return false; |
815 | 850 | } |
@@ -824,14 +859,16 @@ discard block |
||
824 | 859 | function cleanTokens($complete = false) |
825 | 860 | { |
826 | 861 | // We appreciate cleaning up after yourselves. |
827 | - if (!isset($_SESSION['token'])) |
|
828 | - return; |
|
862 | + if (!isset($_SESSION['token'])) { |
|
863 | + return; |
|
864 | + } |
|
829 | 865 | |
830 | 866 | // Clean up tokens, trying to give enough time still. |
831 | - foreach ($_SESSION['token'] as $key => $data) |
|
832 | - if ($data[2] + 10800 < time() || $complete) |
|
867 | + foreach ($_SESSION['token'] as $key => $data) { |
|
868 | + if ($data[2] + 10800 < time() || $complete) |
|
833 | 869 | unset($_SESSION['token'][$key]); |
834 | -} |
|
870 | + } |
|
871 | + } |
|
835 | 872 | |
836 | 873 | /** |
837 | 874 | * Check whether a form has been submitted twice. |
@@ -849,37 +886,40 @@ discard block |
||
849 | 886 | { |
850 | 887 | global $context; |
851 | 888 | |
852 | - if (!isset($_SESSION['forms'])) |
|
853 | - $_SESSION['forms'] = array(); |
|
889 | + if (!isset($_SESSION['forms'])) { |
|
890 | + $_SESSION['forms'] = array(); |
|
891 | + } |
|
854 | 892 | |
855 | 893 | // Register a form number and store it in the session stack. (use this on the page that has the form.) |
856 | 894 | if ($action == 'register') |
857 | 895 | { |
858 | 896 | $context['form_sequence_number'] = 0; |
859 | - while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) |
|
860 | - $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
897 | + while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) { |
|
898 | + $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
899 | + } |
|
861 | 900 | } |
862 | 901 | // Check whether the submitted number can be found in the session. |
863 | 902 | elseif ($action == 'check') |
864 | 903 | { |
865 | - if (!isset($_REQUEST['seqnum'])) |
|
866 | - return true; |
|
867 | - elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
904 | + if (!isset($_REQUEST['seqnum'])) { |
|
905 | + return true; |
|
906 | + } elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
868 | 907 | { |
869 | 908 | $_SESSION['forms'][] = (int) $_REQUEST['seqnum']; |
870 | 909 | return true; |
910 | + } elseif ($is_fatal) { |
|
911 | + fatal_lang_error('error_form_already_submitted', false); |
|
912 | + } else { |
|
913 | + return false; |
|
871 | 914 | } |
872 | - elseif ($is_fatal) |
|
873 | - fatal_lang_error('error_form_already_submitted', false); |
|
874 | - else |
|
875 | - return false; |
|
876 | 915 | } |
877 | 916 | // Don't check, just free the stack number. |
878 | - elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
879 | - $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
880 | - elseif ($action != 'free') |
|
881 | - trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
882 | -} |
|
917 | + elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { |
|
918 | + $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
919 | + } elseif ($action != 'free') { |
|
920 | + trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
921 | + } |
|
922 | + } |
|
883 | 923 | |
884 | 924 | /** |
885 | 925 | * Check the user's permissions. |
@@ -896,16 +936,19 @@ discard block |
||
896 | 936 | global $user_info, $smcFunc; |
897 | 937 | |
898 | 938 | // You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!) |
899 | - if (empty($permission)) |
|
900 | - return true; |
|
939 | + if (empty($permission)) { |
|
940 | + return true; |
|
941 | + } |
|
901 | 942 | |
902 | 943 | // You're never allowed to do something if your data hasn't been loaded yet! |
903 | - if (empty($user_info)) |
|
904 | - return false; |
|
944 | + if (empty($user_info)) { |
|
945 | + return false; |
|
946 | + } |
|
905 | 947 | |
906 | 948 | // Administrators are supermen :P. |
907 | - if ($user_info['is_admin']) |
|
908 | - return true; |
|
949 | + if ($user_info['is_admin']) { |
|
950 | + return true; |
|
951 | + } |
|
909 | 952 | |
910 | 953 | // Let's ensure this is an array. |
911 | 954 | $permission = (array) $permission; |
@@ -913,14 +956,16 @@ discard block |
||
913 | 956 | // Are we checking the _current_ board, or some other boards? |
914 | 957 | if ($boards === null) |
915 | 958 | { |
916 | - if (count(array_intersect($permission, $user_info['permissions'])) != 0) |
|
917 | - return true; |
|
959 | + if (count(array_intersect($permission, $user_info['permissions'])) != 0) { |
|
960 | + return true; |
|
961 | + } |
|
918 | 962 | // You aren't allowed, by default. |
919 | - else |
|
920 | - return false; |
|
963 | + else { |
|
964 | + return false; |
|
965 | + } |
|
966 | + } elseif (!is_array($boards)) { |
|
967 | + $boards = array($boards); |
|
921 | 968 | } |
922 | - elseif (!is_array($boards)) |
|
923 | - $boards = array($boards); |
|
924 | 969 | |
925 | 970 | $request = $smcFunc['db_query']('', ' |
926 | 971 | SELECT MIN(bp.add_deny) AS add_deny |
@@ -943,12 +988,14 @@ discard block |
||
943 | 988 | ); |
944 | 989 | |
945 | 990 | // Make sure they can do it on all of the boards. |
946 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
947 | - return false; |
|
991 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
992 | + return false; |
|
993 | + } |
|
948 | 994 | |
949 | 995 | $result = true; |
950 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
951 | - $result &= !empty($row['add_deny']); |
|
996 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
997 | + $result &= !empty($row['add_deny']); |
|
998 | + } |
|
952 | 999 | $smcFunc['db_free_result']($request); |
953 | 1000 | |
954 | 1001 | // If the query returned 1, they can do it... otherwise, they can't. |
@@ -1013,9 +1060,10 @@ discard block |
||
1013 | 1060 | |
1014 | 1061 | // If you're doing something on behalf of some "heavy" permissions, validate your session. |
1015 | 1062 | // (take out the heavy permissions, and if you can't do anything but those, you need a validated session.) |
1016 | - if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) |
|
1017 | - validateSession(); |
|
1018 | -} |
|
1063 | + if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) { |
|
1064 | + validateSession(); |
|
1065 | + } |
|
1066 | + } |
|
1019 | 1067 | |
1020 | 1068 | /** |
1021 | 1069 | * Return the boards a user has a certain (board) permission on. (array(0) if all.) |
@@ -1034,8 +1082,9 @@ discard block |
||
1034 | 1082 | global $user_info, $smcFunc; |
1035 | 1083 | |
1036 | 1084 | // Arrays are nice, most of the time. |
1037 | - if (!is_array($permissions)) |
|
1038 | - $permissions = array($permissions); |
|
1085 | + if (!is_array($permissions)) { |
|
1086 | + $permissions = array($permissions); |
|
1087 | + } |
|
1039 | 1088 | |
1040 | 1089 | /* |
1041 | 1090 | * Set $simple to true to use this function as it were in SMF 2.0.x. |
@@ -1047,13 +1096,14 @@ discard block |
||
1047 | 1096 | // Administrators are all powerful, sorry. |
1048 | 1097 | if ($user_info['is_admin']) |
1049 | 1098 | { |
1050 | - if ($simple) |
|
1051 | - return array(0); |
|
1052 | - else |
|
1099 | + if ($simple) { |
|
1100 | + return array(0); |
|
1101 | + } else |
|
1053 | 1102 | { |
1054 | 1103 | $boards = array(); |
1055 | - foreach ($permissions as $permission) |
|
1056 | - $boards[$permission] = array(0); |
|
1104 | + foreach ($permissions as $permission) { |
|
1105 | + $boards[$permission] = array(0); |
|
1106 | + } |
|
1057 | 1107 | |
1058 | 1108 | return $boards; |
1059 | 1109 | } |
@@ -1085,31 +1135,32 @@ discard block |
||
1085 | 1135 | { |
1086 | 1136 | if ($simple) |
1087 | 1137 | { |
1088 | - if (empty($row['add_deny'])) |
|
1089 | - $deny_boards[] = $row['id_board']; |
|
1090 | - else |
|
1091 | - $boards[] = $row['id_board']; |
|
1092 | - } |
|
1093 | - else |
|
1138 | + if (empty($row['add_deny'])) { |
|
1139 | + $deny_boards[] = $row['id_board']; |
|
1140 | + } else { |
|
1141 | + $boards[] = $row['id_board']; |
|
1142 | + } |
|
1143 | + } else |
|
1094 | 1144 | { |
1095 | - if (empty($row['add_deny'])) |
|
1096 | - $deny_boards[$row['permission']][] = $row['id_board']; |
|
1097 | - else |
|
1098 | - $boards[$row['permission']][] = $row['id_board']; |
|
1145 | + if (empty($row['add_deny'])) { |
|
1146 | + $deny_boards[$row['permission']][] = $row['id_board']; |
|
1147 | + } else { |
|
1148 | + $boards[$row['permission']][] = $row['id_board']; |
|
1149 | + } |
|
1099 | 1150 | } |
1100 | 1151 | } |
1101 | 1152 | $smcFunc['db_free_result']($request); |
1102 | 1153 | |
1103 | - if ($simple) |
|
1104 | - $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
1105 | - else |
|
1154 | + if ($simple) { |
|
1155 | + $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
1156 | + } else |
|
1106 | 1157 | { |
1107 | 1158 | foreach ($permissions as $permission) |
1108 | 1159 | { |
1109 | 1160 | // never had it to start with |
1110 | - if (empty($boards[$permission])) |
|
1111 | - $boards[$permission] = array(); |
|
1112 | - else |
|
1161 | + if (empty($boards[$permission])) { |
|
1162 | + $boards[$permission] = array(); |
|
1163 | + } else |
|
1113 | 1164 | { |
1114 | 1165 | // Or it may have been removed |
1115 | 1166 | $deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array(); |
@@ -1145,10 +1196,11 @@ discard block |
||
1145 | 1196 | |
1146 | 1197 | |
1147 | 1198 | // Moderators are free... |
1148 | - if (!allowedTo('moderate_board')) |
|
1149 | - $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
1150 | - else |
|
1151 | - $timeLimit = 2; |
|
1199 | + if (!allowedTo('moderate_board')) { |
|
1200 | + $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
1201 | + } else { |
|
1202 | + $timeLimit = 2; |
|
1203 | + } |
|
1152 | 1204 | |
1153 | 1205 | call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit)); |
1154 | 1206 | |
@@ -1175,8 +1227,9 @@ discard block |
||
1175 | 1227 | if ($smcFunc['db_affected_rows']() != 1) |
1176 | 1228 | { |
1177 | 1229 | // Spammer! You only have to wait a *few* seconds! |
1178 | - if (!$only_return_result) |
|
1179 | - fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
1230 | + if (!$only_return_result) { |
|
1231 | + fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
1232 | + } |
|
1180 | 1233 | |
1181 | 1234 | return true; |
1182 | 1235 | } |
@@ -1194,11 +1247,13 @@ discard block |
||
1194 | 1247 | */ |
1195 | 1248 | function secureDirectory($path, $attachments = false) |
1196 | 1249 | { |
1197 | - if (empty($path)) |
|
1198 | - return 'empty_path'; |
|
1250 | + if (empty($path)) { |
|
1251 | + return 'empty_path'; |
|
1252 | + } |
|
1199 | 1253 | |
1200 | - if (!is_writable($path)) |
|
1201 | - return 'path_not_writable'; |
|
1254 | + if (!is_writable($path)) { |
|
1255 | + return 'path_not_writable'; |
|
1256 | + } |
|
1202 | 1257 | |
1203 | 1258 | $directoryname = basename($path); |
1204 | 1259 | |
@@ -1210,9 +1265,9 @@ discard block |
||
1210 | 1265 | |
1211 | 1266 | RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml'; |
1212 | 1267 | |
1213 | - if (file_exists($path . '/.htaccess')) |
|
1214 | - $errors[] = 'htaccess_exists'; |
|
1215 | - else |
|
1268 | + if (file_exists($path . '/.htaccess')) { |
|
1269 | + $errors[] = 'htaccess_exists'; |
|
1270 | + } else |
|
1216 | 1271 | { |
1217 | 1272 | $fh = @fopen($path . '/.htaccess', 'w'); |
1218 | 1273 | if ($fh) { |
@@ -1224,9 +1279,9 @@ discard block |
||
1224 | 1279 | $errors[] = 'htaccess_cannot_create_file'; |
1225 | 1280 | } |
1226 | 1281 | |
1227 | - if (file_exists($path . '/index.php')) |
|
1228 | - $errors[] = 'index-php_exists'; |
|
1229 | - else |
|
1282 | + if (file_exists($path . '/index.php')) { |
|
1283 | + $errors[] = 'index-php_exists'; |
|
1284 | + } else |
|
1230 | 1285 | { |
1231 | 1286 | $fh = @fopen($path . '/index.php', 'w'); |
1232 | 1287 | if ($fh) { |
@@ -1253,11 +1308,12 @@ discard block |
||
1253 | 1308 | $errors[] = 'index-php_cannot_create_file'; |
1254 | 1309 | } |
1255 | 1310 | |
1256 | - if (!empty($errors)) |
|
1257 | - return $errors; |
|
1258 | - else |
|
1259 | - return true; |
|
1260 | -} |
|
1311 | + if (!empty($errors)) { |
|
1312 | + return $errors; |
|
1313 | + } else { |
|
1314 | + return true; |
|
1315 | + } |
|
1316 | + } |
|
1261 | 1317 | |
1262 | 1318 | /** |
1263 | 1319 | * This sets the X-Frame-Options header. |
@@ -1270,14 +1326,16 @@ discard block |
||
1270 | 1326 | global $modSettings; |
1271 | 1327 | |
1272 | 1328 | $option = 'SAMEORIGIN'; |
1273 | - if (is_null($override) && !empty($modSettings['frame_security'])) |
|
1274 | - $option = $modSettings['frame_security']; |
|
1275 | - elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) |
|
1276 | - $option = $override; |
|
1329 | + if (is_null($override) && !empty($modSettings['frame_security'])) { |
|
1330 | + $option = $modSettings['frame_security']; |
|
1331 | + } elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) { |
|
1332 | + $option = $override; |
|
1333 | + } |
|
1277 | 1334 | |
1278 | 1335 | // Don't bother setting the header if we have disabled it. |
1279 | - if ($option == 'DISABLE') |
|
1280 | - return; |
|
1336 | + if ($option == 'DISABLE') { |
|
1337 | + return; |
|
1338 | + } |
|
1281 | 1339 | |
1282 | 1340 | // Finally set it. |
1283 | 1341 | header('X-Frame-Options: ' . $option); |
@@ -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'); |
@@ -102,19 +106,20 @@ discard block |
||
102 | 106 | list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
103 | 107 | |
104 | 108 | // That didn't work... Maybe it's using serialize? |
105 | - if (is_null($timeout)) |
|
106 | - list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
107 | - } |
|
108 | - elseif (isset($_SESSION['login_' . $cookiename])) |
|
109 | + if (is_null($timeout)) { |
|
110 | + list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
111 | + } |
|
112 | + } elseif (isset($_SESSION['login_' . $cookiename])) |
|
109 | 113 | { |
110 | 114 | list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
111 | 115 | |
112 | 116 | // Try for old format |
113 | - if (is_null($timeout)) |
|
114 | - list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
117 | + if (is_null($timeout)) { |
|
118 | + list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
119 | + } |
|
120 | + } else { |
|
121 | + trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
115 | 122 | } |
116 | - else |
|
117 | - trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
118 | 123 | |
119 | 124 | $user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4); |
120 | 125 | updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt'])); |
@@ -127,10 +132,11 @@ discard block |
||
127 | 132 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
128 | 133 | |
129 | 134 | // If we're preserving the cookie, reset it with updated salt |
130 | - if (isset($tfamember, $tfasecret, $exp, $state, $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, ''); |
|
135 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
136 | + setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
137 | + } else { |
|
138 | + setTFACookie(-3600, 0, ''); |
|
139 | + } |
|
134 | 140 | } |
135 | 141 | |
136 | 142 | setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
@@ -141,20 +147,20 @@ discard block |
||
141 | 147 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
142 | 148 | { |
143 | 149 | // Strike! You're outta there! |
144 | - if ($_GET['member'] != $user_info['id']) |
|
145 | - fatal_lang_error('login_cookie_error', false); |
|
150 | + if ($_GET['member'] != $user_info['id']) { |
|
151 | + fatal_lang_error('login_cookie_error', false); |
|
152 | + } |
|
146 | 153 | |
147 | 154 | $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 | 155 | |
149 | 156 | // 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)) |
|
157 | + if (empty($_SESSION['login_url'])) { |
|
158 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
159 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
153 | 160 | { |
154 | 161 | unset ($_SESSION['login_url']); |
155 | 162 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
156 | - } |
|
157 | - else |
|
163 | + } else |
|
158 | 164 | { |
159 | 165 | // Best not to clutter the session data too much... |
160 | 166 | $temp = $_SESSION['login_url']; |
@@ -165,8 +171,9 @@ discard block |
||
165 | 171 | } |
166 | 172 | |
167 | 173 | // Beyond this point you are assumed to be a guest trying to login. |
168 | - if (!$user_info['is_guest']) |
|
169 | - redirectexit(); |
|
174 | + if (!$user_info['is_guest']) { |
|
175 | + redirectexit(); |
|
176 | + } |
|
170 | 177 | |
171 | 178 | // Are you guessing with a script? |
172 | 179 | checkSession(); |
@@ -174,18 +181,21 @@ discard block |
||
174 | 181 | spamProtection('login'); |
175 | 182 | |
176 | 183 | // 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']; |
|
184 | + 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)) { |
|
185 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
186 | + } |
|
179 | 187 | |
180 | 188 | // 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'); |
|
189 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
190 | + fatal_lang_error('login_threshold_fail', 'login'); |
|
191 | + } |
|
183 | 192 | |
184 | 193 | // 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']; |
|
194 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
195 | + $modSettings['cookieTime'] = 3153600; |
|
196 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
197 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
198 | + } |
|
189 | 199 | |
190 | 200 | loadLanguage('Login'); |
191 | 201 | // Load the template stuff. |
@@ -305,8 +315,9 @@ discard block |
||
305 | 315 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
306 | 316 | |
307 | 317 | // 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'])); |
|
318 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
319 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
320 | + } |
|
310 | 321 | |
311 | 322 | // phpBB3 users new hashing. We now support it as well ;). |
312 | 323 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -326,27 +337,29 @@ discard block |
||
326 | 337 | // Some common md5 ones. |
327 | 338 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
328 | 339 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
329 | - } |
|
330 | - elseif (strlen($user_settings['passwd']) == 40) |
|
340 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
331 | 341 | { |
332 | 342 | // Maybe they are using a hash from before the password fix. |
333 | 343 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
334 | 344 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
335 | 345 | |
336 | 346 | // 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']))); |
|
347 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
348 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
349 | + } |
|
339 | 350 | |
340 | 351 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
341 | 352 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
342 | 353 | { |
343 | 354 | // 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']))); |
|
355 | + if (function_exists('iconv')) { |
|
356 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
357 | + } |
|
346 | 358 | |
347 | 359 | // 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']))); |
|
360 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
361 | + $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 | + } |
|
350 | 363 | } |
351 | 364 | } |
352 | 365 | |
@@ -376,8 +389,9 @@ discard block |
||
376 | 389 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
377 | 390 | |
378 | 391 | // 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'); |
|
392 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
393 | + redirectexit('action=reminder'); |
|
394 | + } |
|
381 | 395 | // We'll give you another chance... |
382 | 396 | else |
383 | 397 | { |
@@ -388,8 +402,7 @@ discard block |
||
388 | 402 | return; |
389 | 403 | } |
390 | 404 | } |
391 | - } |
|
392 | - elseif (!empty($user_settings['passwd_flood'])) |
|
405 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
393 | 406 | { |
394 | 407 | // Let's be sure they weren't a little hacker. |
395 | 408 | validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true); |
@@ -406,8 +419,9 @@ discard block |
||
406 | 419 | } |
407 | 420 | |
408 | 421 | // Check their activation status. |
409 | - if (!checkActivation()) |
|
410 | - return; |
|
422 | + if (!checkActivation()) { |
|
423 | + return; |
|
424 | + } |
|
411 | 425 | |
412 | 426 | DoLogin(); |
413 | 427 | } |
@@ -419,8 +433,9 @@ discard block |
||
419 | 433 | { |
420 | 434 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
421 | 435 | |
422 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
423 | - fatal_lang_error('no_access', false); |
|
436 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
437 | + fatal_lang_error('no_access', false); |
|
438 | + } |
|
424 | 439 | |
425 | 440 | loadLanguage('Profile'); |
426 | 441 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -428,8 +443,9 @@ discard block |
||
428 | 443 | $member = $context['tfa_member']; |
429 | 444 | |
430 | 445 | // 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); |
|
446 | + if (time() - $member['last_login'] < 120) { |
|
447 | + fatal_lang_error('tfa_wait', false); |
|
448 | + } |
|
433 | 449 | |
434 | 450 | $totp = new \TOTP\Auth($member['tfa_secret']); |
435 | 451 | $totp->setRange(1); |
@@ -443,8 +459,9 @@ discard block |
||
443 | 459 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
444 | 460 | { |
445 | 461 | // 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'); |
|
462 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
463 | + fatal_lang_error('login_ssl_required'); |
|
464 | + } |
|
448 | 465 | |
449 | 466 | $code = $_POST['tfa_code']; |
450 | 467 | |
@@ -454,20 +471,19 @@ discard block |
||
454 | 471 | |
455 | 472 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve'])); |
456 | 473 | redirectexit(); |
457 | - } |
|
458 | - else |
|
474 | + } else |
|
459 | 475 | { |
460 | 476 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
461 | 477 | |
462 | 478 | $context['tfa_error'] = true; |
463 | 479 | $context['tfa_value'] = $_POST['tfa_code']; |
464 | 480 | } |
465 | - } |
|
466 | - elseif (!empty($_POST['tfa_backup'])) |
|
481 | + } elseif (!empty($_POST['tfa_backup'])) |
|
467 | 482 | { |
468 | 483 | // 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'); |
|
484 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
485 | + fatal_lang_error('login_ssl_required'); |
|
486 | + } |
|
471 | 487 | |
472 | 488 | $backup = $_POST['tfa_backup']; |
473 | 489 | |
@@ -481,8 +497,7 @@ discard block |
||
481 | 497 | )); |
482 | 498 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
483 | 499 | redirectexit('action=profile;area=tfasetup;backup'); |
484 | - } |
|
485 | - else |
|
500 | + } else |
|
486 | 501 | { |
487 | 502 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
488 | 503 | |
@@ -505,8 +520,9 @@ discard block |
||
505 | 520 | { |
506 | 521 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
507 | 522 | |
508 | - if (!isset($context['login_errors'])) |
|
509 | - $context['login_errors'] = array(); |
|
523 | + if (!isset($context['login_errors'])) { |
|
524 | + $context['login_errors'] = array(); |
|
525 | + } |
|
510 | 526 | |
511 | 527 | // What is the true activation status of this account? |
512 | 528 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -518,8 +534,9 @@ discard block |
||
518 | 534 | return false; |
519 | 535 | } |
520 | 536 | // Awaiting approval still? |
521 | - elseif ($activation_status == 3) |
|
522 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
537 | + elseif ($activation_status == 3) { |
|
538 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
539 | + } |
|
523 | 540 | // Awaiting deletion, changed their mind? |
524 | 541 | elseif ($activation_status == 4) |
525 | 542 | { |
@@ -527,8 +544,7 @@ discard block |
||
527 | 544 | { |
528 | 545 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
529 | 546 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
530 | - } |
|
531 | - else |
|
547 | + } else |
|
532 | 548 | { |
533 | 549 | $context['disable_login_hashing'] = true; |
534 | 550 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -568,8 +584,9 @@ discard block |
||
568 | 584 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
569 | 585 | |
570 | 586 | // Reset the login threshold. |
571 | - if (isset($_SESSION['failed_login'])) |
|
572 | - unset($_SESSION['failed_login']); |
|
587 | + if (isset($_SESSION['failed_login'])) { |
|
588 | + unset($_SESSION['failed_login']); |
|
589 | + } |
|
573 | 590 | |
574 | 591 | $user_info['is_guest'] = false; |
575 | 592 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -591,16 +608,18 @@ discard block |
||
591 | 608 | 'id_member' => $user_info['id'], |
592 | 609 | ) |
593 | 610 | ); |
594 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
595 | - $_SESSION['first_login'] = true; |
|
596 | - else |
|
597 | - unset($_SESSION['first_login']); |
|
611 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
612 | + $_SESSION['first_login'] = true; |
|
613 | + } else { |
|
614 | + unset($_SESSION['first_login']); |
|
615 | + } |
|
598 | 616 | $smcFunc['db_free_result']($request); |
599 | 617 | |
600 | 618 | // You've logged in, haven't you? |
601 | 619 | $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(); |
|
620 | + if (empty($user_settings['tfa_secret'])) { |
|
621 | + $update['last_login'] = time(); |
|
622 | + } |
|
604 | 623 | updateMemberData($user_info['id'], $update); |
605 | 624 | |
606 | 625 | // Get rid of the online entry for that old guest.... |
@@ -614,8 +633,8 @@ discard block |
||
614 | 633 | $_SESSION['log_time'] = 0; |
615 | 634 | |
616 | 635 | // Log this entry, only if we have it enabled. |
617 | - if (!empty($modSettings['loginHistoryDays'])) |
|
618 | - $smcFunc['db_insert']('insert', |
|
636 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
637 | + $smcFunc['db_insert']('insert', |
|
619 | 638 | '{db_prefix}member_logins', |
620 | 639 | array( |
621 | 640 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -627,13 +646,15 @@ discard block |
||
627 | 646 | 'id_member', 'time' |
628 | 647 | ) |
629 | 648 | ); |
649 | + } |
|
630 | 650 | |
631 | 651 | // 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 | -} |
|
652 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
653 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
654 | + } else { |
|
655 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
656 | + } |
|
657 | + } |
|
637 | 658 | |
638 | 659 | /** |
639 | 660 | * Logs the current user out of their account. |
@@ -649,13 +670,15 @@ discard block |
||
649 | 670 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
650 | 671 | |
651 | 672 | // Make sure they aren't being auto-logged out. |
652 | - if (!$internal) |
|
653 | - checkSession('get'); |
|
673 | + if (!$internal) { |
|
674 | + checkSession('get'); |
|
675 | + } |
|
654 | 676 | |
655 | 677 | require_once($sourcedir . '/Subs-Auth.php'); |
656 | 678 | |
657 | - if (isset($_SESSION['pack_ftp'])) |
|
658 | - $_SESSION['pack_ftp'] = null; |
|
679 | + if (isset($_SESSION['pack_ftp'])) { |
|
680 | + $_SESSION['pack_ftp'] = null; |
|
681 | + } |
|
659 | 682 | |
660 | 683 | // It won't be first login anymore. |
661 | 684 | unset($_SESSION['first_login']); |
@@ -683,8 +706,9 @@ discard block |
||
683 | 706 | |
684 | 707 | // And some other housekeeping while we're at it. |
685 | 708 | $salt = substr(md5(mt_rand()), 0, 4); |
686 | - if (!empty($user_info['id'])) |
|
687 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
709 | + if (!empty($user_info['id'])) { |
|
710 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
711 | + } |
|
688 | 712 | |
689 | 713 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
690 | 714 | { |
@@ -693,10 +717,11 @@ discard block |
||
693 | 717 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
694 | 718 | |
695 | 719 | // If we're preserving the cookie, reset it with updated salt |
696 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
697 | - setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
698 | - else |
|
699 | - setTFACookie(-3600, 0, ''); |
|
720 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
721 | + setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
722 | + } else { |
|
723 | + setTFACookie(-3600, 0, ''); |
|
724 | + } |
|
700 | 725 | } |
701 | 726 | |
702 | 727 | session_destroy(); |
@@ -704,14 +729,13 @@ discard block |
||
704 | 729 | // Off to the merry board index we go! |
705 | 730 | if ($redirect) |
706 | 731 | { |
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)) |
|
732 | + if (empty($_SESSION['logout_url'])) { |
|
733 | + redirectexit('', $context['server']['needs_login_fix']); |
|
734 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
710 | 735 | { |
711 | 736 | unset ($_SESSION['logout_url']); |
712 | 737 | redirectexit(); |
713 | - } |
|
714 | - else |
|
738 | + } else |
|
715 | 739 | { |
716 | 740 | $temp = $_SESSION['logout_url']; |
717 | 741 | unset($_SESSION['logout_url']); |
@@ -744,8 +768,9 @@ discard block |
||
744 | 768 | function phpBB3_password_check($passwd, $passwd_hash) |
745 | 769 | { |
746 | 770 | // Too long or too short? |
747 | - if (strlen($passwd_hash) != 34) |
|
748 | - return; |
|
771 | + if (strlen($passwd_hash) != 34) { |
|
772 | + return; |
|
773 | + } |
|
749 | 774 | |
750 | 775 | // Range of characters allowed. |
751 | 776 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -756,8 +781,9 @@ discard block |
||
756 | 781 | $salt = substr($passwd_hash, 4, 8); |
757 | 782 | |
758 | 783 | $hash = md5($salt . $passwd, true); |
759 | - for (; $count != 0; --$count) |
|
760 | - $hash = md5($hash . $passwd, true); |
|
784 | + for (; $count != 0; --$count) { |
|
785 | + $hash = md5($hash . $passwd, true); |
|
786 | + } |
|
761 | 787 | |
762 | 788 | $output = substr($passwd_hash, 0, 12); |
763 | 789 | $i = 0; |
@@ -766,21 +792,25 @@ discard block |
||
766 | 792 | $value = ord($hash[$i++]); |
767 | 793 | $output .= $range[$value & 0x3f]; |
768 | 794 | |
769 | - if ($i < 16) |
|
770 | - $value |= ord($hash[$i]) << 8; |
|
795 | + if ($i < 16) { |
|
796 | + $value |= ord($hash[$i]) << 8; |
|
797 | + } |
|
771 | 798 | |
772 | 799 | $output .= $range[($value >> 6) & 0x3f]; |
773 | 800 | |
774 | - if ($i++ >= 16) |
|
775 | - break; |
|
801 | + if ($i++ >= 16) { |
|
802 | + break; |
|
803 | + } |
|
776 | 804 | |
777 | - if ($i < 16) |
|
778 | - $value |= ord($hash[$i]) << 16; |
|
805 | + if ($i < 16) { |
|
806 | + $value |= ord($hash[$i]) << 16; |
|
807 | + } |
|
779 | 808 | |
780 | 809 | $output .= $range[($value >> 12) & 0x3f]; |
781 | 810 | |
782 | - if ($i++ >= 16) |
|
783 | - break; |
|
811 | + if ($i++ >= 16) { |
|
812 | + break; |
|
813 | + } |
|
784 | 814 | |
785 | 815 | $output .= $range[($value >> 18) & 0x3f]; |
786 | 816 | } |
@@ -812,8 +842,9 @@ discard block |
||
812 | 842 | require_once($sourcedir . '/Subs-Auth.php'); |
813 | 843 | setLoginCookie(-3600, 0); |
814 | 844 | |
815 | - if (isset($_SESSION['login_' . $cookiename])) |
|
816 | - unset($_SESSION['login_' . $cookiename]); |
|
845 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
846 | + unset($_SESSION['login_' . $cookiename]); |
|
847 | + } |
|
817 | 848 | } |
818 | 849 | |
819 | 850 | // We need a member! |
@@ -827,8 +858,9 @@ discard block |
||
827 | 858 | } |
828 | 859 | |
829 | 860 | // Right, have we got a flood value? |
830 | - if ($password_flood_value !== false) |
|
831 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
861 | + if ($password_flood_value !== false) { |
|
862 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
863 | + } |
|
832 | 864 | |
833 | 865 | // Timestamp or number of tries invalid? |
834 | 866 | if (empty($number_tries) || empty($time_stamp)) |
@@ -844,15 +876,17 @@ discard block |
||
844 | 876 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
845 | 877 | |
846 | 878 | // They are trying too fast, make them wait longer |
847 | - if ($time_stamp < time() - 10) |
|
848 | - $time_stamp = time(); |
|
879 | + if ($time_stamp < time() - 10) { |
|
880 | + $time_stamp = time(); |
|
881 | + } |
|
849 | 882 | } |
850 | 883 | |
851 | 884 | $number_tries++; |
852 | 885 | |
853 | 886 | // Broken the law? |
854 | - if ($number_tries > 5) |
|
855 | - fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
887 | + if ($number_tries > 5) { |
|
888 | + fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
889 | + } |
|
856 | 890 | |
857 | 891 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
858 | 892 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
30 | 31 | |
31 | 32 | // Is this an incoming AJAX check? |
32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
33 | - return RegisterCheckUsername(); |
|
33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
34 | + return RegisterCheckUsername(); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | // Check if the administrator has it disabled. |
36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
37 | - fatal_lang_error('registration_disabled', false); |
|
38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
39 | + fatal_lang_error('registration_disabled', false); |
|
40 | + } |
|
38 | 41 | |
39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
45 | + } |
|
42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
43 | - elseif (empty($user_info['is_guest'])) |
|
44 | - redirectexit(); |
|
47 | + elseif (empty($user_info['is_guest'])) { |
|
48 | + redirectexit(); |
|
49 | + } |
|
45 | 50 | |
46 | 51 | loadLanguage('Login'); |
47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
82 | 87 | } |
83 | 88 | } |
84 | 89 | // Make sure they don't squeeze through without agreeing. |
85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
86 | - $current_step = 1; |
|
90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
91 | + $current_step = 1; |
|
92 | + } |
|
87 | 93 | |
88 | 94 | // Show the user the right form. |
89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
91 | 97 | |
92 | 98 | // Kinda need this. |
93 | - if ($context['sub_template'] == 'registration_form') |
|
94 | - loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
99 | + if ($context['sub_template'] == 'registration_form') { |
|
100 | + loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
101 | + } |
|
95 | 102 | |
96 | 103 | // Add the register chain to the link tree. |
97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
100 | 107 | ); |
101 | 108 | |
102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
103 | - if (!isset($_SESSION['register'])) |
|
104 | - $_SESSION['register'] = array( |
|
110 | + if (!isset($_SESSION['register'])) { |
|
111 | + $_SESSION['register'] = array( |
|
105 | 112 | 'timenow' => time(), |
106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
107 | 114 | ); |
108 | - else |
|
109 | - $_SESSION['register']['timenow'] = time(); |
|
115 | + } else { |
|
116 | + $_SESSION['register']['timenow'] = time(); |
|
117 | + } |
|
110 | 118 | |
111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
112 | 120 | if ($context['require_agreement']) |
113 | 121 | { |
114 | 122 | // Have we got a localized one? |
115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
119 | - else |
|
120 | - $context['agreement'] = ''; |
|
123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
127 | + } else { |
|
128 | + $context['agreement'] = ''; |
|
129 | + } |
|
121 | 130 | |
122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
134 | 143 | |
135 | 144 | // Do we have any languages? |
136 | - if (empty($context['languages'])) |
|
137 | - getLanguages(); |
|
145 | + if (empty($context['languages'])) { |
|
146 | + getLanguages(); |
|
147 | + } |
|
138 | 148 | |
139 | 149 | // Try to find our selected language. |
140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
143 | 153 | |
144 | 154 | // Found it! |
145 | - if ($selectedLanguage == $lang['filename']) |
|
146 | - $context['languages'][$key]['selected'] = true; |
|
155 | + if ($selectedLanguage == $lang['filename']) { |
|
156 | + $context['languages'][$key]['selected'] = true; |
|
157 | + } |
|
147 | 158 | } |
148 | 159 | } |
149 | 160 | |
@@ -167,9 +178,10 @@ discard block |
||
167 | 178 | $reg_fields = explode(',', $modSettings['registration_fields']); |
168 | 179 | |
169 | 180 | // We might have had some submissions on this front - go check. |
170 | - foreach ($reg_fields as $field) |
|
171 | - if (isset($_POST[$field])) |
|
181 | + foreach ($reg_fields as $field) { |
|
182 | + if (isset($_POST[$field])) |
|
172 | 183 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
184 | + } |
|
173 | 185 | |
174 | 186 | // Load all the fields in question. |
175 | 187 | setupProfileContext($reg_fields); |
@@ -186,8 +198,9 @@ discard block |
||
186 | 198 | $context['visual_verification_id'] = $verificationOptions['id']; |
187 | 199 | } |
188 | 200 | // Otherwise we have nothing to show. |
189 | - else |
|
190 | - $context['visual_verification'] = false; |
|
201 | + else { |
|
202 | + $context['visual_verification'] = false; |
|
203 | + } |
|
191 | 204 | |
192 | 205 | |
193 | 206 | $context += array( |
@@ -198,8 +211,9 @@ discard block |
||
198 | 211 | |
199 | 212 | // Were there any errors? |
200 | 213 | $context['registration_errors'] = array(); |
201 | - if (!empty($reg_errors)) |
|
202 | - $context['registration_errors'] = $reg_errors; |
|
214 | + if (!empty($reg_errors)) { |
|
215 | + $context['registration_errors'] = $reg_errors; |
|
216 | + } |
|
203 | 217 | |
204 | 218 | createToken('register'); |
205 | 219 | } |
@@ -216,27 +230,32 @@ discard block |
||
216 | 230 | validateToken('register'); |
217 | 231 | |
218 | 232 | // Check to ensure we're forcing SSL for authentication |
219 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
220 | - fatal_lang_error('register_ssl_required'); |
|
233 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
234 | + fatal_lang_error('register_ssl_required'); |
|
235 | + } |
|
221 | 236 | |
222 | 237 | // Start collecting together any errors. |
223 | 238 | $reg_errors = array(); |
224 | 239 | |
225 | 240 | // You can't register if it's disabled. |
226 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
227 | - fatal_lang_error('registration_disabled', false); |
|
241 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
242 | + fatal_lang_error('registration_disabled', false); |
|
243 | + } |
|
228 | 244 | |
229 | 245 | // Well, if you don't agree, you can't register. |
230 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
231 | - redirectexit(); |
|
246 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
247 | + redirectexit(); |
|
248 | + } |
|
232 | 249 | |
233 | 250 | // Make sure they came from *somewhere*, have a session. |
234 | - if (!isset($_SESSION['old_url'])) |
|
235 | - redirectexit('action=signup'); |
|
251 | + if (!isset($_SESSION['old_url'])) { |
|
252 | + redirectexit('action=signup'); |
|
253 | + } |
|
236 | 254 | |
237 | 255 | // If we don't require an agreement, we need a extra check for coppa. |
238 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
239 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
256 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
257 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
258 | + } |
|
240 | 259 | // Are they under age, and under age users are banned? |
241 | 260 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
242 | 261 | { |
@@ -245,8 +264,9 @@ discard block |
||
245 | 264 | } |
246 | 265 | |
247 | 266 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
248 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
249 | - redirectexit('action=signup'); |
|
267 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
268 | + redirectexit('action=signup'); |
|
269 | + } |
|
250 | 270 | // Failing that, check the time on it. |
251 | 271 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
252 | 272 | { |
@@ -266,15 +286,17 @@ discard block |
||
266 | 286 | if (is_array($context['visual_verification'])) |
267 | 287 | { |
268 | 288 | loadLanguage('Errors'); |
269 | - foreach ($context['visual_verification'] as $error) |
|
270 | - $reg_errors[] = $txt['error_' . $error]; |
|
289 | + foreach ($context['visual_verification'] as $error) { |
|
290 | + $reg_errors[] = $txt['error_' . $error]; |
|
291 | + } |
|
271 | 292 | } |
272 | 293 | } |
273 | 294 | |
274 | 295 | foreach ($_POST as $key => $value) |
275 | 296 | { |
276 | - if (!is_array($_POST[$key])) |
|
277 | - $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
297 | + if (!is_array($_POST[$key])) { |
|
298 | + $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
299 | + } |
|
278 | 300 | } |
279 | 301 | |
280 | 302 | // Collect all extra registration fields someone might have filled in. |
@@ -304,12 +326,14 @@ discard block |
||
304 | 326 | $reg_fields = explode(',', $modSettings['registration_fields']); |
305 | 327 | |
306 | 328 | // Website is a little different |
307 | - if (in_array('website', $reg_fields)) |
|
308 | - $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
329 | + if (in_array('website', $reg_fields)) { |
|
330 | + $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
331 | + } |
|
309 | 332 | } |
310 | 333 | |
311 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
312 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
334 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
335 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
336 | + } |
|
313 | 337 | |
314 | 338 | // Needed for isReservedName() and registerMember(). |
315 | 339 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -318,8 +342,9 @@ discard block |
||
318 | 342 | if (isset($_POST['real_name'])) |
319 | 343 | { |
320 | 344 | // Are you already allowed to edit the displayed name? |
321 | - if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) |
|
322 | - $canEditDisplayName = true; |
|
345 | + if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) { |
|
346 | + $canEditDisplayName = true; |
|
347 | + } |
|
323 | 348 | |
324 | 349 | // If you are a guest, will you be allowed to once you register? |
325 | 350 | else |
@@ -343,33 +368,38 @@ discard block |
||
343 | 368 | $_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name'])); |
344 | 369 | |
345 | 370 | // Only set it if we are sure it is good |
346 | - if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
347 | - $possible_strings[] = 'real_name'; |
|
371 | + if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
372 | + $possible_strings[] = 'real_name'; |
|
373 | + } |
|
348 | 374 | } |
349 | 375 | } |
350 | 376 | |
351 | 377 | // Handle a string as a birthdate... |
352 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
353 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
378 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
379 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
380 | + } |
|
354 | 381 | // Or birthdate parts... |
355 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
356 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
382 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
383 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
384 | + } |
|
357 | 385 | |
358 | 386 | // Validate the passed language file. |
359 | 387 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
360 | 388 | { |
361 | 389 | // Do we have any languages? |
362 | - if (empty($context['languages'])) |
|
363 | - getLanguages(); |
|
390 | + if (empty($context['languages'])) { |
|
391 | + getLanguages(); |
|
392 | + } |
|
364 | 393 | |
365 | 394 | // Did we find it? |
366 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
367 | - $_SESSION['language'] = $_POST['lngfile']; |
|
368 | - else |
|
395 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
396 | + $_SESSION['language'] = $_POST['lngfile']; |
|
397 | + } else { |
|
398 | + unset($_POST['lngfile']); |
|
399 | + } |
|
400 | + } else { |
|
369 | 401 | unset($_POST['lngfile']); |
370 | 402 | } |
371 | - else |
|
372 | - unset($_POST['lngfile']); |
|
373 | 403 | |
374 | 404 | // Set the options needed for registration. |
375 | 405 | $regOptions = array( |
@@ -389,22 +419,27 @@ discard block |
||
389 | 419 | ); |
390 | 420 | |
391 | 421 | // Include the additional options that might have been filled in. |
392 | - foreach ($possible_strings as $var) |
|
393 | - if (isset($_POST[$var])) |
|
422 | + foreach ($possible_strings as $var) { |
|
423 | + if (isset($_POST[$var])) |
|
394 | 424 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
395 | - foreach ($possible_ints as $var) |
|
396 | - if (isset($_POST[$var])) |
|
425 | + } |
|
426 | + foreach ($possible_ints as $var) { |
|
427 | + if (isset($_POST[$var])) |
|
397 | 428 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
398 | - foreach ($possible_floats as $var) |
|
399 | - if (isset($_POST[$var])) |
|
429 | + } |
|
430 | + foreach ($possible_floats as $var) { |
|
431 | + if (isset($_POST[$var])) |
|
400 | 432 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
401 | - foreach ($possible_bools as $var) |
|
402 | - if (isset($_POST[$var])) |
|
433 | + } |
|
434 | + foreach ($possible_bools as $var) { |
|
435 | + if (isset($_POST[$var])) |
|
403 | 436 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
437 | + } |
|
404 | 438 | |
405 | 439 | // Registration options are always default options... |
406 | - if (isset($_POST['default_options'])) |
|
407 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
440 | + if (isset($_POST['default_options'])) { |
|
441 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
442 | + } |
|
408 | 443 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
409 | 444 | |
410 | 445 | // Make sure they are clean, dammit! |
@@ -424,12 +459,14 @@ discard block |
||
424 | 459 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
425 | 460 | { |
426 | 461 | // Don't allow overriding of the theme variables. |
427 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
428 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
462 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
463 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
464 | + } |
|
429 | 465 | |
430 | 466 | // Not actually showing it then? |
431 | - if (!$row['show_reg']) |
|
432 | - continue; |
|
467 | + if (!$row['show_reg']) { |
|
468 | + continue; |
|
469 | + } |
|
433 | 470 | |
434 | 471 | // Prepare the value! |
435 | 472 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -438,24 +475,27 @@ discard block |
||
438 | 475 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
439 | 476 | { |
440 | 477 | // Is it too long? |
441 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
442 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
478 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
479 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
480 | + } |
|
443 | 481 | |
444 | 482 | // Any masks to apply? |
445 | 483 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
446 | 484 | { |
447 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
448 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
449 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
450 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
451 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
452 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
485 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
486 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
487 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
488 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
489 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
490 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
491 | + } |
|
453 | 492 | } |
454 | 493 | } |
455 | 494 | |
456 | 495 | // Is this required but not there? |
457 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
458 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
496 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
497 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
498 | + } |
|
459 | 499 | } |
460 | 500 | $smcFunc['db_free_result']($request); |
461 | 501 | |
@@ -463,8 +503,9 @@ discard block |
||
463 | 503 | if (!empty($custom_field_errors)) |
464 | 504 | { |
465 | 505 | loadLanguage('Errors'); |
466 | - foreach ($custom_field_errors as $error) |
|
467 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
506 | + foreach ($custom_field_errors as $error) { |
|
507 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
508 | + } |
|
468 | 509 | } |
469 | 510 | |
470 | 511 | // Lets check for other errors before trying to register the member. |
@@ -509,8 +550,9 @@ discard block |
||
509 | 550 | } |
510 | 551 | |
511 | 552 | // If COPPA has been selected then things get complicated, setup the template. |
512 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
513 | - redirectexit('action=coppa;member=' . $memberID); |
|
553 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
554 | + redirectexit('action=coppa;member=' . $memberID); |
|
555 | + } |
|
514 | 556 | // Basic template variable setup. |
515 | 557 | elseif (!empty($modSettings['registration_method'])) |
516 | 558 | { |
@@ -522,8 +564,7 @@ discard block |
||
522 | 564 | 'sub_template' => 'after', |
523 | 565 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
524 | 566 | ); |
525 | - } |
|
526 | - else |
|
567 | + } else |
|
527 | 568 | { |
528 | 569 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
529 | 570 | |
@@ -543,16 +584,18 @@ discard block |
||
543 | 584 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
544 | 585 | |
545 | 586 | // Logged in users should not bother to activate their accounts |
546 | - if (!empty($user_info['id'])) |
|
547 | - redirectexit(); |
|
587 | + if (!empty($user_info['id'])) { |
|
588 | + redirectexit(); |
|
589 | + } |
|
548 | 590 | |
549 | 591 | loadLanguage('Login'); |
550 | 592 | loadTemplate('Login'); |
551 | 593 | |
552 | 594 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
553 | 595 | { |
554 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
555 | - fatal_lang_error('no_access', false); |
|
596 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
597 | + fatal_lang_error('no_access', false); |
|
598 | + } |
|
556 | 599 | |
557 | 600 | $context['member_id'] = 0; |
558 | 601 | $context['sub_template'] = 'resend'; |
@@ -592,11 +635,13 @@ discard block |
||
592 | 635 | // Change their email address? (they probably tried a fake one first :P.) |
593 | 636 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
594 | 637 | { |
595 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
596 | - fatal_lang_error('no_access', false); |
|
638 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
639 | + fatal_lang_error('no_access', false); |
|
640 | + } |
|
597 | 641 | |
598 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
599 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
642 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
643 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
644 | + } |
|
600 | 645 | |
601 | 646 | // Make sure their email isn't banned. |
602 | 647 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -612,8 +657,9 @@ discard block |
||
612 | 657 | ) |
613 | 658 | ); |
614 | 659 | |
615 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
616 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
660 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
661 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
662 | + } |
|
617 | 663 | $smcFunc['db_free_result']($request); |
618 | 664 | |
619 | 665 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -651,9 +697,9 @@ discard block |
||
651 | 697 | // Quit if this code is not right. |
652 | 698 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
653 | 699 | { |
654 | - if (!empty($row['is_activated'])) |
|
655 | - fatal_lang_error('already_activated', false); |
|
656 | - elseif ($row['validation_code'] == '') |
|
700 | + if (!empty($row['is_activated'])) { |
|
701 | + fatal_lang_error('already_activated', false); |
|
702 | + } elseif ($row['validation_code'] == '') |
|
657 | 703 | { |
658 | 704 | loadLanguage('Profile'); |
659 | 705 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -703,8 +749,9 @@ discard block |
||
703 | 749 | loadTemplate('Register'); |
704 | 750 | |
705 | 751 | // No User ID?? |
706 | - if (!isset($_GET['member'])) |
|
707 | - fatal_lang_error('no_access', false); |
|
752 | + if (!isset($_GET['member'])) { |
|
753 | + fatal_lang_error('no_access', false); |
|
754 | + } |
|
708 | 755 | |
709 | 756 | // Get the user details... |
710 | 757 | $request = $smcFunc['db_query']('', ' |
@@ -717,8 +764,9 @@ discard block |
||
717 | 764 | 'is_coppa' => 5, |
718 | 765 | ) |
719 | 766 | ); |
720 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
721 | - fatal_lang_error('no_access', false); |
|
767 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
768 | + fatal_lang_error('no_access', false); |
|
769 | + } |
|
722 | 770 | list ($username) = $smcFunc['db_fetch_row']($request); |
723 | 771 | $smcFunc['db_free_result']($request); |
724 | 772 | |
@@ -756,8 +804,7 @@ discard block |
||
756 | 804 | echo $data; |
757 | 805 | obExit(false); |
758 | 806 | } |
759 | - } |
|
760 | - else |
|
807 | + } else |
|
761 | 808 | { |
762 | 809 | $context += array( |
763 | 810 | 'page_title' => $txt['coppa_title'], |
@@ -810,8 +857,9 @@ discard block |
||
810 | 857 | { |
811 | 858 | require_once($sourcedir . '/Subs-Graphics.php'); |
812 | 859 | |
813 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
814 | - header('HTTP/1.1 400 Bad Request'); |
|
860 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
861 | + header('HTTP/1.1 400 Bad Request'); |
|
862 | + } |
|
815 | 863 | |
816 | 864 | // Otherwise just show a pre-defined letter. |
817 | 865 | elseif (isset($_REQUEST['letter'])) |
@@ -829,14 +877,13 @@ discard block |
||
829 | 877 | header('Content-Type: image/gif'); |
830 | 878 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
831 | 879 | } |
832 | - } |
|
833 | - |
|
834 | - elseif ($_REQUEST['format'] === '.wav') |
|
880 | + } elseif ($_REQUEST['format'] === '.wav') |
|
835 | 881 | { |
836 | 882 | require_once($sourcedir . '/Subs-Sound.php'); |
837 | 883 | |
838 | - if (!createWaveFile($code)) |
|
839 | - header('HTTP/1.1 400 Bad Request'); |
|
884 | + if (!createWaveFile($code)) { |
|
885 | + header('HTTP/1.1 400 Bad Request'); |
|
886 | + } |
|
840 | 887 | } |
841 | 888 | |
842 | 889 | // We all die one day... |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * The main designating function for modifying profiles. Loads up info, determins what to do, etc. |
@@ -29,18 +30,21 @@ discard block |
||
29 | 30 | global $modSettings, $memberContext, $profile_vars, $post_errors, $smcFunc; |
30 | 31 | |
31 | 32 | // Don't reload this as we may have processed error strings. |
32 | - if (empty($post_errors)) |
|
33 | - loadLanguage('Profile+Drafts'); |
|
33 | + if (empty($post_errors)) { |
|
34 | + loadLanguage('Profile+Drafts'); |
|
35 | + } |
|
34 | 36 | loadTemplate('Profile'); |
35 | 37 | |
36 | 38 | require_once($sourcedir . '/Subs-Menu.php'); |
37 | 39 | |
38 | 40 | // Did we get the user by name... |
39 | - if (isset($_REQUEST['user'])) |
|
40 | - $memberResult = loadMemberData($_REQUEST['user'], true, 'profile'); |
|
41 | + if (isset($_REQUEST['user'])) { |
|
42 | + $memberResult = loadMemberData($_REQUEST['user'], true, 'profile'); |
|
43 | + } |
|
41 | 44 | // ... or by id_member? |
42 | - elseif (!empty($_REQUEST['u'])) |
|
43 | - $memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile'); |
|
45 | + elseif (!empty($_REQUEST['u'])) { |
|
46 | + $memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile'); |
|
47 | + } |
|
44 | 48 | // If it was just ?action=profile, edit your own profile, but only if you're not a guest. |
45 | 49 | else |
46 | 50 | { |
@@ -50,8 +54,9 @@ discard block |
||
50 | 54 | } |
51 | 55 | |
52 | 56 | // Check if loadMemberData() has returned a valid result. |
53 | - if (!$memberResult) |
|
54 | - fatal_lang_error('not_a_user', false, 404); |
|
57 | + if (!$memberResult) { |
|
58 | + fatal_lang_error('not_a_user', false, 404); |
|
59 | + } |
|
55 | 60 | |
56 | 61 | // If all went well, we have a valid member ID! |
57 | 62 | list ($memID) = $memberResult; |
@@ -67,8 +72,9 @@ discard block |
||
67 | 72 | |
68 | 73 | // Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission. |
69 | 74 | // And we care about what the current user can do, not what the user whose profile it is. |
70 | - if ($user_info['mod_cache']['gq'] != '0=1') |
|
71 | - $user_info['permissions'][] = 'approve_group_requests'; |
|
75 | + if ($user_info['mod_cache']['gq'] != '0=1') { |
|
76 | + $user_info['permissions'][] = 'approve_group_requests'; |
|
77 | + } |
|
72 | 78 | |
73 | 79 | // If paid subscriptions are enabled, make sure we actually have at least one subscription available... |
74 | 80 | $context['subs_available'] = false; |
@@ -436,21 +442,25 @@ discard block |
||
436 | 442 | foreach ($section['areas'] as $area_id => $area) |
437 | 443 | { |
438 | 444 | // If it said no permissions that meant it wasn't valid! |
439 | - if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) |
|
440 | - $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false; |
|
445 | + if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) { |
|
446 | + $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false; |
|
447 | + } |
|
441 | 448 | // Otherwise pick the right set. |
442 | - else |
|
443 | - $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any']; |
|
449 | + else { |
|
450 | + $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any']; |
|
451 | + } |
|
444 | 452 | |
445 | 453 | // Password required in most cases |
446 | - if (!empty($area['password'])) |
|
447 | - $context['password_areas'][] = $area_id; |
|
454 | + if (!empty($area['password'])) { |
|
455 | + $context['password_areas'][] = $area_id; |
|
456 | + } |
|
448 | 457 | } |
449 | 458 | } |
450 | 459 | |
451 | 460 | // Is there an updated message to show? |
452 | - if (isset($_GET['updated'])) |
|
453 | - $context['profile_updated'] = $txt['profile_updated_own']; |
|
461 | + if (isset($_GET['updated'])) { |
|
462 | + $context['profile_updated'] = $txt['profile_updated_own']; |
|
463 | + } |
|
454 | 464 | |
455 | 465 | // Set a few options for the menu. |
456 | 466 | $menuOptions = array( |
@@ -465,8 +475,9 @@ discard block |
||
465 | 475 | $profile_include_data = createMenu($profile_areas, $menuOptions); |
466 | 476 | |
467 | 477 | // No menu means no access. |
468 | - if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) |
|
469 | - fatal_lang_error('no_access', false); |
|
478 | + if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) { |
|
479 | + fatal_lang_error('no_access', false); |
|
480 | + } |
|
470 | 481 | |
471 | 482 | // Make a note of the Unique ID for this menu. |
472 | 483 | $context['profile_menu_id'] = $context['max_menu_id']; |
@@ -492,8 +503,9 @@ discard block |
||
492 | 503 | if ($current_area == $area_id) |
493 | 504 | { |
494 | 505 | // This can't happen - but is a security check. |
495 | - if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) |
|
496 | - fatal_lang_error('no_access', false); |
|
506 | + if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) { |
|
507 | + fatal_lang_error('no_access', false); |
|
508 | + } |
|
497 | 509 | |
498 | 510 | // Are we saving data in a valid area? |
499 | 511 | if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview'])) |
@@ -512,12 +524,14 @@ discard block |
||
512 | 524 | } |
513 | 525 | |
514 | 526 | // Does this require session validating? |
515 | - if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) |
|
516 | - $security_checks['validate'] = true; |
|
527 | + if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) { |
|
528 | + $security_checks['validate'] = true; |
|
529 | + } |
|
517 | 530 | |
518 | 531 | // Permissions for good measure. |
519 | - if (!empty($profile_include_data['permission'])) |
|
520 | - $security_checks['permission'] = $profile_include_data['permission']; |
|
532 | + if (!empty($profile_include_data['permission'])) { |
|
533 | + $security_checks['permission'] = $profile_include_data['permission']; |
|
534 | + } |
|
521 | 535 | |
522 | 536 | // Either way got something. |
523 | 537 | $found_area = true; |
@@ -526,21 +540,26 @@ discard block |
||
526 | 540 | } |
527 | 541 | |
528 | 542 | // Oh dear, some serious security lapse is going on here... we'll put a stop to that! |
529 | - if (!$found_area) |
|
530 | - fatal_lang_error('no_access', false); |
|
543 | + if (!$found_area) { |
|
544 | + fatal_lang_error('no_access', false); |
|
545 | + } |
|
531 | 546 | |
532 | 547 | // Release this now. |
533 | 548 | unset($profile_areas); |
534 | 549 | |
535 | 550 | // Now the context is setup have we got any security checks to carry out additional to that above? |
536 | - if (isset($security_checks['session'])) |
|
537 | - checkSession($security_checks['session']); |
|
538 | - if (isset($security_checks['validate'])) |
|
539 | - validateSession(); |
|
540 | - if (isset($security_checks['validateToken'])) |
|
541 | - validateToken($token_name, $token_type); |
|
542 | - if (isset($security_checks['permission'])) |
|
543 | - isAllowedTo($security_checks['permission']); |
|
551 | + if (isset($security_checks['session'])) { |
|
552 | + checkSession($security_checks['session']); |
|
553 | + } |
|
554 | + if (isset($security_checks['validate'])) { |
|
555 | + validateSession(); |
|
556 | + } |
|
557 | + if (isset($security_checks['validateToken'])) { |
|
558 | + validateToken($token_name, $token_type); |
|
559 | + } |
|
560 | + if (isset($security_checks['permission'])) { |
|
561 | + isAllowedTo($security_checks['permission']); |
|
562 | + } |
|
544 | 563 | |
545 | 564 | // Create a token if needed. |
546 | 565 | if (isset($security_checks['needsToken']) || isset($security_checks['validateToken'])) |
@@ -550,8 +569,9 @@ discard block |
||
550 | 569 | } |
551 | 570 | |
552 | 571 | // File to include? |
553 | - if (isset($profile_include_data['file'])) |
|
554 | - require_once($sourcedir . '/' . $profile_include_data['file']); |
|
572 | + if (isset($profile_include_data['file'])) { |
|
573 | + require_once($sourcedir . '/' . $profile_include_data['file']); |
|
574 | + } |
|
555 | 575 | |
556 | 576 | // Build the link tree. |
557 | 577 | $context['linktree'][] = array( |
@@ -559,17 +579,19 @@ discard block |
||
559 | 579 | 'name' => sprintf($txt['profile_of_username'], $context['member']['name']), |
560 | 580 | ); |
561 | 581 | |
562 | - if (!empty($profile_include_data['label'])) |
|
563 | - $context['linktree'][] = array( |
|
582 | + if (!empty($profile_include_data['label'])) { |
|
583 | + $context['linktree'][] = array( |
|
564 | 584 | 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'], |
565 | 585 | 'name' => $profile_include_data['label'], |
566 | 586 | ); |
587 | + } |
|
567 | 588 | |
568 | - if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) |
|
569 | - $context['linktree'][] = array( |
|
589 | + if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) { |
|
590 | + $context['linktree'][] = array( |
|
570 | 591 | 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'], |
571 | 592 | 'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0], |
572 | 593 | ); |
594 | + } |
|
573 | 595 | |
574 | 596 | // Set the template for this area and add the profile layer. |
575 | 597 | $context['sub_template'] = $profile_include_data['function']; |
@@ -595,12 +617,14 @@ discard block |
||
595 | 617 | if ($check_password) |
596 | 618 | { |
597 | 619 | // Check to ensure we're forcing SSL for authentication |
598 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
599 | - fatal_lang_error('login_ssl_required'); |
|
620 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
621 | + fatal_lang_error('login_ssl_required'); |
|
622 | + } |
|
600 | 623 | |
601 | 624 | // You didn't even enter a password! |
602 | - if (trim($_POST['oldpasswrd']) == '') |
|
603 | - $post_errors[] = 'no_password'; |
|
625 | + if (trim($_POST['oldpasswrd']) == '') { |
|
626 | + $post_errors[] = 'no_password'; |
|
627 | + } |
|
604 | 628 | |
605 | 629 | // Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password |
606 | 630 | $_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']); |
@@ -609,42 +633,43 @@ discard block |
||
609 | 633 | $good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true); |
610 | 634 | |
611 | 635 | // Bad password!!! |
612 | - if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) |
|
613 | - $post_errors[] = 'bad_password'; |
|
636 | + if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) { |
|
637 | + $post_errors[] = 'bad_password'; |
|
638 | + } |
|
614 | 639 | |
615 | 640 | // Warn other elements not to jump the gun and do custom changes! |
616 | - if (in_array('bad_password', $post_errors)) |
|
617 | - $context['password_auth_failed'] = true; |
|
641 | + if (in_array('bad_password', $post_errors)) { |
|
642 | + $context['password_auth_failed'] = true; |
|
643 | + } |
|
618 | 644 | } |
619 | 645 | |
620 | 646 | // Change the IP address in the database. |
621 | - if ($context['user']['is_owner']) |
|
622 | - $profile_vars['member_ip'] = $user_info['ip']; |
|
647 | + if ($context['user']['is_owner']) { |
|
648 | + $profile_vars['member_ip'] = $user_info['ip']; |
|
649 | + } |
|
623 | 650 | |
624 | 651 | // Now call the sub-action function... |
625 | 652 | if ($current_area == 'activateaccount') |
626 | 653 | { |
627 | - if (empty($post_errors)) |
|
628 | - activateAccount($memID); |
|
629 | - } |
|
630 | - elseif ($current_area == 'deleteaccount') |
|
654 | + if (empty($post_errors)) { |
|
655 | + activateAccount($memID); |
|
656 | + } |
|
657 | + } elseif ($current_area == 'deleteaccount') |
|
631 | 658 | { |
632 | 659 | if (empty($post_errors)) |
633 | 660 | { |
634 | 661 | deleteAccount2($memID); |
635 | 662 | redirectexit(); |
636 | 663 | } |
637 | - } |
|
638 | - elseif ($current_area == 'groupmembership' && empty($post_errors)) |
|
664 | + } elseif ($current_area == 'groupmembership' && empty($post_errors)) |
|
639 | 665 | { |
640 | 666 | $msg = groupMembership2($profile_vars, $post_errors, $memID); |
641 | 667 | |
642 | 668 | // Whatever we've done, we have nothing else to do here... |
643 | 669 | redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : '')); |
644 | - } |
|
645 | - elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) |
|
646 | - saveProfileFields(); |
|
647 | - else |
|
670 | + } elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) { |
|
671 | + saveProfileFields(); |
|
672 | + } else |
|
648 | 673 | { |
649 | 674 | $force_redirect = true; |
650 | 675 | // Ensure we include this. |
@@ -660,34 +685,36 @@ discard block |
||
660 | 685 | // Load the language file so we can give a nice explanation of the errors. |
661 | 686 | loadLanguage('Errors'); |
662 | 687 | $context['post_errors'] = $post_errors; |
663 | - } |
|
664 | - elseif (!empty($profile_vars)) |
|
688 | + } elseif (!empty($profile_vars)) |
|
665 | 689 | { |
666 | 690 | // If we've changed the password, notify any integration that may be listening in. |
667 | - if (isset($profile_vars['passwd'])) |
|
668 | - call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2'])); |
|
691 | + if (isset($profile_vars['passwd'])) { |
|
692 | + call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2'])); |
|
693 | + } |
|
669 | 694 | |
670 | 695 | updateMemberData($memID, $profile_vars); |
671 | 696 | |
672 | 697 | // What if this is the newest member? |
673 | - if ($modSettings['latestMember'] == $memID) |
|
674 | - updateStats('member'); |
|
675 | - elseif (isset($profile_vars['real_name'])) |
|
676 | - updateSettings(array('memberlist_updated' => time())); |
|
698 | + if ($modSettings['latestMember'] == $memID) { |
|
699 | + updateStats('member'); |
|
700 | + } elseif (isset($profile_vars['real_name'])) { |
|
701 | + updateSettings(array('memberlist_updated' => time())); |
|
702 | + } |
|
677 | 703 | |
678 | 704 | // If the member changed his/her birthdate, update calendar statistics. |
679 | - if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) |
|
680 | - updateSettings(array( |
|
705 | + if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) { |
|
706 | + updateSettings(array( |
|
681 | 707 | 'calendar_updated' => time(), |
682 | 708 | )); |
709 | + } |
|
683 | 710 | |
684 | 711 | // Anything worth logging? |
685 | 712 | if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled'])) |
686 | 713 | { |
687 | 714 | $log_changes = array(); |
688 | 715 | require_once($sourcedir . '/Logging.php'); |
689 | - foreach ($context['log_changes'] as $k => $v) |
|
690 | - $log_changes[] = array( |
|
716 | + foreach ($context['log_changes'] as $k => $v) { |
|
717 | + $log_changes[] = array( |
|
691 | 718 | 'action' => $k, |
692 | 719 | 'log_type' => 'user', |
693 | 720 | 'extra' => array_merge($v, array( |
@@ -695,14 +722,16 @@ discard block |
||
695 | 722 | 'member_affected' => $memID, |
696 | 723 | )), |
697 | 724 | ); |
725 | + } |
|
698 | 726 | |
699 | 727 | logActions($log_changes); |
700 | 728 | } |
701 | 729 | |
702 | 730 | // Have we got any post save functions to execute? |
703 | - if (!empty($context['profile_execute_on_save'])) |
|
704 | - foreach ($context['profile_execute_on_save'] as $saveFunc) |
|
731 | + if (!empty($context['profile_execute_on_save'])) { |
|
732 | + foreach ($context['profile_execute_on_save'] as $saveFunc) |
|
705 | 733 | $saveFunc(); |
734 | + } |
|
706 | 735 | |
707 | 736 | // Let them know it worked! |
708 | 737 | $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']); |
@@ -716,27 +745,31 @@ discard block |
||
716 | 745 | if (!empty($post_errors)) |
717 | 746 | { |
718 | 747 | // Set all the errors so the template knows what went wrong. |
719 | - foreach ($post_errors as $error_type) |
|
720 | - $context['modify_error'][$error_type] = true; |
|
748 | + foreach ($post_errors as $error_type) { |
|
749 | + $context['modify_error'][$error_type] = true; |
|
750 | + } |
|
721 | 751 | } |
722 | 752 | // If it's you then we should redirect upon save. |
723 | - elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) |
|
724 | - redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated'); |
|
725 | - elseif (!empty($force_redirect)) |
|
726 | - redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area); |
|
753 | + elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) { |
|
754 | + redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated'); |
|
755 | + } elseif (!empty($force_redirect)) { |
|
756 | + redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area); |
|
757 | + } |
|
727 | 758 | |
728 | 759 | |
729 | 760 | // Get the right callable. |
730 | 761 | $call = call_helper($profile_include_data['function'], true); |
731 | 762 | |
732 | 763 | // Is it valid? |
733 | - if (!empty($call)) |
|
734 | - call_user_func($call, $memID); |
|
764 | + if (!empty($call)) { |
|
765 | + call_user_func($call, $memID); |
|
766 | + } |
|
735 | 767 | |
736 | 768 | // Set the page title if it's not already set... |
737 | - if (!isset($context['page_title'])) |
|
738 | - $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : ''); |
|
739 | -} |
|
769 | + if (!isset($context['page_title'])) { |
|
770 | + $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : ''); |
|
771 | + } |
|
772 | + } |
|
740 | 773 | |
741 | 774 | /** |
742 | 775 | * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user. |
@@ -859,16 +892,18 @@ discard block |
||
859 | 892 | if (!allowedTo('admin_forum') && $area != 'register') |
860 | 893 | { |
861 | 894 | // If it's the owner they can see two types of private fields, regardless. |
862 | - if ($memID == $user_info['id']) |
|
863 | - $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)'; |
|
864 | - else |
|
865 | - $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0'; |
|
895 | + if ($memID == $user_info['id']) { |
|
896 | + $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)'; |
|
897 | + } else { |
|
898 | + $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0'; |
|
899 | + } |
|
866 | 900 | } |
867 | 901 | |
868 | - if ($area == 'register') |
|
869 | - $where .= ' AND show_reg != 0'; |
|
870 | - elseif ($area != 'summary') |
|
871 | - $where .= ' AND show_profile = {string:area}'; |
|
902 | + if ($area == 'register') { |
|
903 | + $where .= ' AND show_reg != 0'; |
|
904 | + } elseif ($area != 'summary') { |
|
905 | + $where .= ' AND show_profile = {string:area}'; |
|
906 | + } |
|
872 | 907 | |
873 | 908 | // Load all the relevant fields - and data. |
874 | 909 | $request = $smcFunc['db_query']('', ' |
@@ -894,13 +929,15 @@ discard block |
||
894 | 929 | if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']])) |
895 | 930 | { |
896 | 931 | $value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]); |
897 | - if (in_array($row['field_type'], array('select', 'radio'))) |
|
898 | - $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : ''; |
|
932 | + if (in_array($row['field_type'], array('select', 'radio'))) { |
|
933 | + $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : ''; |
|
934 | + } |
|
899 | 935 | } |
900 | 936 | |
901 | 937 | // Don't show the "disabled" option for the "gender" field if we are on the "summary" area. |
902 | - if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'None') |
|
903 | - continue; |
|
938 | + if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'None') { |
|
939 | + continue; |
|
940 | + } |
|
904 | 941 | |
905 | 942 | // HTML for the input form. |
906 | 943 | $output_html = $value; |
@@ -909,8 +946,7 @@ discard block |
||
909 | 946 | $true = (!$exists && $row['default_value']) || $value; |
910 | 947 | $input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . '>'; |
911 | 948 | $output_html = $true ? $txt['yes'] : $txt['no']; |
912 | - } |
|
913 | - elseif ($row['field_type'] == 'select') |
|
949 | + } elseif ($row['field_type'] == 'select') |
|
914 | 950 | { |
915 | 951 | $input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>'; |
916 | 952 | $options = explode(',', $row['field_options']); |
@@ -918,13 +954,13 @@ discard block |
||
918 | 954 | { |
919 | 955 | $true = (!$exists && $row['default_value'] == $v) || $value == $v; |
920 | 956 | $input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>'; |
921 | - if ($true) |
|
922 | - $output_html = $v; |
|
957 | + if ($true) { |
|
958 | + $output_html = $v; |
|
959 | + } |
|
923 | 960 | } |
924 | 961 | |
925 | 962 | $input_html .= '</select>'; |
926 | - } |
|
927 | - elseif ($row['field_type'] == 'radio') |
|
963 | + } elseif ($row['field_type'] == 'radio') |
|
928 | 964 | { |
929 | 965 | $input_html = '<fieldset>'; |
930 | 966 | $options = explode(',', $row['field_options']); |
@@ -932,36 +968,37 @@ discard block |
||
932 | 968 | { |
933 | 969 | $true = (!$exists && $row['default_value'] == $v) || $value == $v; |
934 | 970 | $input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>'; |
935 | - if ($true) |
|
936 | - $output_html = $v; |
|
971 | + if ($true) { |
|
972 | + $output_html = $v; |
|
973 | + } |
|
937 | 974 | } |
938 | 975 | $input_html .= '</fieldset>'; |
939 | - } |
|
940 | - elseif ($row['field_type'] == 'text') |
|
976 | + } elseif ($row['field_type'] == 'text') |
|
941 | 977 | { |
942 | 978 | $input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '"' . ($row['show_reg'] == 2 ? ' required' : '') . '>'; |
943 | - } |
|
944 | - else |
|
979 | + } else |
|
945 | 980 | { |
946 | 981 | @list ($rows, $cols) = @explode(',', $row['default_value']); |
947 | 982 | $input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>'; |
948 | 983 | } |
949 | 984 | |
950 | 985 | // Parse BBCode |
951 | - if ($row['bbc']) |
|
952 | - $output_html = parse_bbc($output_html); |
|
953 | - elseif ($row['field_type'] == 'textarea') |
|
954 | - // Allow for newlines at least |
|
986 | + if ($row['bbc']) { |
|
987 | + $output_html = parse_bbc($output_html); |
|
988 | + } elseif ($row['field_type'] == 'textarea') { |
|
989 | + // Allow for newlines at least |
|
955 | 990 | $output_html = strtr($output_html, array("\n" => '<br>')); |
991 | + } |
|
956 | 992 | |
957 | 993 | // Enclosing the user input within some other text? |
958 | - if (!empty($row['enclose']) && !empty($output_html)) |
|
959 | - $output_html = strtr($row['enclose'], array( |
|
994 | + if (!empty($row['enclose']) && !empty($output_html)) { |
|
995 | + $output_html = strtr($row['enclose'], array( |
|
960 | 996 | '{SCRIPTURL}' => $scripturl, |
961 | 997 | '{IMAGES_URL}' => $settings['images_url'], |
962 | 998 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
963 | 999 | '{INPUT}' => un_htmlspecialchars($output_html), |
964 | 1000 | )); |
1001 | + } |
|
965 | 1002 | |
966 | 1003 | $context['custom_fields'][] = array( |
967 | 1004 | 'name' => $row['field_name'], |
@@ -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 |