@@ -12,7 +12,8 @@ |
||
12 | 12 | header('location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |
@@ -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, null, $db_options['port'], null, $flags); |
|
79 | - else |
|
80 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
80 | + if (!empty($db_options['port'])) { |
|
81 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
82 | + } else { |
|
83 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 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 | mysqli_query($connection, '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 | |
@@ -164,34 +170,42 @@ discard block |
||
164 | 170 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
165 | 171 | |
166 | 172 | list ($values, $connection) = $db_callback; |
167 | - if (!is_object($connection)) |
|
168 | - display_db_error(); |
|
173 | + if (!is_object($connection)) { |
|
174 | + display_db_error(); |
|
175 | + } |
|
169 | 176 | |
170 | - if ($matches[1] === 'db_prefix') |
|
171 | - return $db_prefix; |
|
177 | + if ($matches[1] === 'db_prefix') { |
|
178 | + return $db_prefix; |
|
179 | + } |
|
172 | 180 | |
173 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
174 | - return $user_info[$matches[1]]; |
|
181 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
182 | + return $user_info[$matches[1]]; |
|
183 | + } |
|
175 | 184 | |
176 | - if ($matches[1] === 'empty') |
|
177 | - return '\'\''; |
|
185 | + if ($matches[1] === 'empty') { |
|
186 | + return '\'\''; |
|
187 | + } |
|
178 | 188 | |
179 | - if (!isset($matches[2])) |
|
180 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
189 | + if (!isset($matches[2])) { |
|
190 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
191 | + } |
|
181 | 192 | |
182 | - if ($matches[1] === 'literal') |
|
183 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
193 | + if ($matches[1] === 'literal') { |
|
194 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
195 | + } |
|
184 | 196 | |
185 | - if (!isset($values[$matches[2]])) |
|
186 | - 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__); |
|
197 | + if (!isset($values[$matches[2]])) { |
|
198 | + 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__); |
|
199 | + } |
|
187 | 200 | |
188 | 201 | $replacement = $values[$matches[2]]; |
189 | 202 | |
190 | 203 | switch ($matches[1]) |
191 | 204 | { |
192 | 205 | case 'int': |
193 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
194 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
206 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
207 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
208 | + } |
|
195 | 209 | return (string) (int) $replacement; |
196 | 210 | break; |
197 | 211 | |
@@ -203,65 +217,73 @@ discard block |
||
203 | 217 | case 'array_int': |
204 | 218 | if (is_array($replacement)) |
205 | 219 | { |
206 | - if (empty($replacement)) |
|
207 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
220 | + if (empty($replacement)) { |
|
221 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
222 | + } |
|
208 | 223 | |
209 | 224 | foreach ($replacement as $key => $value) |
210 | 225 | { |
211 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
212 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
226 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
227 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
228 | + } |
|
213 | 229 | |
214 | 230 | $replacement[$key] = (string) (int) $value; |
215 | 231 | } |
216 | 232 | |
217 | 233 | return implode(', ', $replacement); |
234 | + } else { |
|
235 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
218 | 236 | } |
219 | - else |
|
220 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
221 | 237 | |
222 | 238 | break; |
223 | 239 | |
224 | 240 | case 'array_string': |
225 | 241 | if (is_array($replacement)) |
226 | 242 | { |
227 | - if (empty($replacement)) |
|
228 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
243 | + if (empty($replacement)) { |
|
244 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
245 | + } |
|
229 | 246 | |
230 | - foreach ($replacement as $key => $value) |
|
231 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
247 | + foreach ($replacement as $key => $value) { |
|
248 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
249 | + } |
|
232 | 250 | |
233 | 251 | return implode(', ', $replacement); |
252 | + } else { |
|
253 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
234 | 254 | } |
235 | - else |
|
236 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | 255 | break; |
238 | 256 | |
239 | 257 | case 'date': |
240 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
241 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
242 | - else |
|
243 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
258 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
259 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
260 | + } else { |
|
261 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
262 | + } |
|
244 | 263 | break; |
245 | 264 | |
246 | 265 | case 'time': |
247 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
248 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
249 | - else |
|
250 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
266 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
267 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
268 | + } else { |
|
269 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
270 | + } |
|
251 | 271 | break; |
252 | 272 | |
253 | 273 | case 'datetime': |
254 | - 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) |
|
255 | - return 'str_to_date('. |
|
274 | + 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) { |
|
275 | + return 'str_to_date('. |
|
256 | 276 | 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]). |
257 | 277 | ',\'%Y-%m-%d %h:%i:%s\')'; |
258 | - else |
|
259 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
278 | + } else { |
|
279 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
280 | + } |
|
260 | 281 | break; |
261 | 282 | |
262 | 283 | case 'float': |
263 | - if (!is_numeric($replacement)) |
|
264 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
284 | + if (!is_numeric($replacement)) { |
|
285 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
286 | + } |
|
265 | 287 | return (string) (float) $replacement; |
266 | 288 | break; |
267 | 289 | |
@@ -275,32 +297,37 @@ discard block |
||
275 | 297 | break; |
276 | 298 | |
277 | 299 | case 'inet': |
278 | - if ($replacement == 'null' || $replacement == '') |
|
279 | - return 'null'; |
|
280 | - if (!isValidIP($replacement)) |
|
281 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
300 | + if ($replacement == 'null' || $replacement == '') { |
|
301 | + return 'null'; |
|
302 | + } |
|
303 | + if (!isValidIP($replacement)) { |
|
304 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
305 | + } |
|
282 | 306 | //we don't use the native support of mysql > 5.6.2 |
283 | 307 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
284 | 308 | |
285 | 309 | case 'array_inet': |
286 | 310 | if (is_array($replacement)) |
287 | 311 | { |
288 | - if (empty($replacement)) |
|
289 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
312 | + if (empty($replacement)) { |
|
313 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
314 | + } |
|
290 | 315 | |
291 | 316 | foreach ($replacement as $key => $value) |
292 | 317 | { |
293 | - if ($replacement == 'null' || $replacement == '') |
|
294 | - $replacement[$key] = 'null'; |
|
295 | - if (!isValidIP($value)) |
|
296 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
318 | + if ($replacement == 'null' || $replacement == '') { |
|
319 | + $replacement[$key] = 'null'; |
|
320 | + } |
|
321 | + if (!isValidIP($value)) { |
|
322 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
323 | + } |
|
297 | 324 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
298 | 325 | } |
299 | 326 | |
300 | 327 | return implode(', ', $replacement); |
328 | + } else { |
|
329 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
301 | 330 | } |
302 | - else |
|
303 | - 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 | 331 | break; |
305 | 332 | |
306 | 333 | default: |
@@ -371,18 +398,20 @@ discard block |
||
371 | 398 | // One more query.... |
372 | 399 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
373 | 400 | |
374 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
375 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
401 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
402 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
403 | + } |
|
376 | 404 | |
377 | 405 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
378 | 406 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
379 | 407 | { |
380 | 408 | // Add before LIMIT |
381 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
382 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
383 | - else |
|
384 | - // Append it. |
|
409 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
410 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
411 | + } else { |
|
412 | + // Append it. |
|
385 | 413 | $db_string .= "\n\t\t\tORDER BY null"; |
414 | + } |
|
386 | 415 | } |
387 | 416 | |
388 | 417 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -408,17 +437,18 @@ discard block |
||
408 | 437 | while (true) |
409 | 438 | { |
410 | 439 | $pos = strpos($db_string_1, '\'', $pos + 1); |
411 | - if ($pos === false) |
|
412 | - break; |
|
440 | + if ($pos === false) { |
|
441 | + break; |
|
442 | + } |
|
413 | 443 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
414 | 444 | |
415 | 445 | while (true) |
416 | 446 | { |
417 | 447 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
418 | 448 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
419 | - if ($pos1 === false) |
|
420 | - break; |
|
421 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
449 | + if ($pos1 === false) { |
|
450 | + break; |
|
451 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
422 | 452 | { |
423 | 453 | $pos = $pos1; |
424 | 454 | break; |
@@ -434,16 +464,19 @@ discard block |
||
434 | 464 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
435 | 465 | |
436 | 466 | // Comments? We don't use comments in our queries, we leave 'em outside! |
437 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
438 | - $fail = true; |
|
467 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
468 | + $fail = true; |
|
469 | + } |
|
439 | 470 | // Trying to change passwords, slow us down, or something? |
440 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
441 | - $fail = true; |
|
442 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
443 | - $fail = true; |
|
471 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
472 | + $fail = true; |
|
473 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
474 | + $fail = true; |
|
475 | + } |
|
444 | 476 | |
445 | - if (!empty($fail) && function_exists('log_error')) |
|
446 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
477 | + if (!empty($fail) && function_exists('log_error')) { |
|
478 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
479 | + } |
|
447 | 480 | } |
448 | 481 | |
449 | 482 | // Debugging. |
@@ -453,8 +486,9 @@ discard block |
||
453 | 486 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
454 | 487 | |
455 | 488 | // Initialize $db_cache if not already initialized. |
456 | - if (!isset($db_cache)) |
|
457 | - $db_cache = array(); |
|
489 | + if (!isset($db_cache)) { |
|
490 | + $db_cache = array(); |
|
491 | + } |
|
458 | 492 | |
459 | 493 | if (!empty($_SESSION['debug_redirect'])) |
460 | 494 | { |
@@ -470,17 +504,20 @@ discard block |
||
470 | 504 | $db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start; |
471 | 505 | } |
472 | 506 | |
473 | - if (empty($db_unbuffered)) |
|
474 | - $ret = @mysqli_query($connection, $db_string); |
|
475 | - else |
|
476 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
507 | + if (empty($db_unbuffered)) { |
|
508 | + $ret = @mysqli_query($connection, $db_string); |
|
509 | + } else { |
|
510 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
511 | + } |
|
477 | 512 | |
478 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
479 | - $ret = smf_db_error($db_string, $connection); |
|
513 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
514 | + $ret = smf_db_error($db_string, $connection); |
|
515 | + } |
|
480 | 516 | |
481 | 517 | // Debugging. |
482 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
483 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
518 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
519 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
520 | + } |
|
484 | 521 | |
485 | 522 | return $ret; |
486 | 523 | } |
@@ -527,12 +564,13 @@ discard block |
||
527 | 564 | // Decide which connection to use |
528 | 565 | $connection = $connection === null ? $db_connection : $connection; |
529 | 566 | |
530 | - if ($type == 'begin') |
|
531 | - return @mysqli_query($connection, 'BEGIN'); |
|
532 | - elseif ($type == 'rollback') |
|
533 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
534 | - elseif ($type == 'commit') |
|
535 | - return @mysqli_query($connection, 'COMMIT'); |
|
567 | + if ($type == 'begin') { |
|
568 | + return @mysqli_query($connection, 'BEGIN'); |
|
569 | + } elseif ($type == 'rollback') { |
|
570 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
571 | + } elseif ($type == 'commit') { |
|
572 | + return @mysqli_query($connection, 'COMMIT'); |
|
573 | + } |
|
536 | 574 | |
537 | 575 | return false; |
538 | 576 | } |
@@ -570,8 +608,9 @@ discard block |
||
570 | 608 | // 1213: Deadlock found. |
571 | 609 | |
572 | 610 | // Log the error. |
573 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
574 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
611 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
612 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
613 | + } |
|
575 | 614 | |
576 | 615 | // Database error auto fixing ;). |
577 | 616 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -580,8 +619,9 @@ discard block |
||
580 | 619 | $old_cache = @$modSettings['cache_enable']; |
581 | 620 | $modSettings['cache_enable'] = '1'; |
582 | 621 | |
583 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
584 | - $db_last_error = max(@$db_last_error, $temp); |
|
622 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
623 | + $db_last_error = max(@$db_last_error, $temp); |
|
624 | + } |
|
585 | 625 | |
586 | 626 | if (@$db_last_error < time() - 3600 * 24 * 3) |
587 | 627 | { |
@@ -597,8 +637,9 @@ discard block |
||
597 | 637 | foreach ($tables as $table) |
598 | 638 | { |
599 | 639 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
600 | - if (trim($table) != '') |
|
601 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
640 | + if (trim($table) != '') { |
|
641 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
642 | + } |
|
602 | 643 | } |
603 | 644 | } |
604 | 645 | |
@@ -607,8 +648,9 @@ discard block |
||
607 | 648 | // Table crashed. Let's try to fix it. |
608 | 649 | elseif ($query_errno == 1016) |
609 | 650 | { |
610 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
611 | - $fix_tables = array('`' . $match[1] . '`'); |
|
651 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
652 | + $fix_tables = array('`' . $match[1] . '`'); |
|
653 | + } |
|
612 | 654 | } |
613 | 655 | // Indexes crashed. Should be easy to fix! |
614 | 656 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -627,13 +669,15 @@ discard block |
||
627 | 669 | |
628 | 670 | // Make a note of the REPAIR... |
629 | 671 | cache_put_data('db_last_error', time(), 600); |
630 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
631 | - updateSettingsFile(array('db_last_error' => time())); |
|
672 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
673 | + updateSettingsFile(array('db_last_error' => time())); |
|
674 | + } |
|
632 | 675 | |
633 | 676 | // Attempt to find and repair the broken table. |
634 | - foreach ($fix_tables as $table) |
|
635 | - $smcFunc['db_query']('', " |
|
677 | + foreach ($fix_tables as $table) { |
|
678 | + $smcFunc['db_query']('', " |
|
636 | 679 | REPAIR TABLE $table", false, false); |
680 | + } |
|
637 | 681 | |
638 | 682 | // And send off an email! |
639 | 683 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -642,11 +686,12 @@ discard block |
||
642 | 686 | |
643 | 687 | // Try the query again...? |
644 | 688 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
645 | - if ($ret !== false) |
|
646 | - return $ret; |
|
689 | + if ($ret !== false) { |
|
690 | + return $ret; |
|
691 | + } |
|
692 | + } else { |
|
693 | + $modSettings['cache_enable'] = $old_cache; |
|
647 | 694 | } |
648 | - else |
|
649 | - $modSettings['cache_enable'] = $old_cache; |
|
650 | 695 | |
651 | 696 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
652 | 697 | if (in_array($query_errno, array(1205, 1213))) |
@@ -659,24 +704,27 @@ discard block |
||
659 | 704 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
660 | 705 | |
661 | 706 | $new_errno = mysqli_errno($db_connection); |
662 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
663 | - break; |
|
707 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
708 | + break; |
|
709 | + } |
|
664 | 710 | } |
665 | 711 | |
666 | 712 | // If it failed again, shucks to be you... we're not trying it over and over. |
667 | - if ($ret !== false) |
|
668 | - return $ret; |
|
713 | + if ($ret !== false) { |
|
714 | + return $ret; |
|
715 | + } |
|
669 | 716 | } |
670 | 717 | } |
671 | 718 | // Are they out of space, perhaps? |
672 | 719 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
673 | 720 | { |
674 | - if (!isset($txt)) |
|
675 | - $query_error .= ' - check database storage space.'; |
|
676 | - else |
|
721 | + if (!isset($txt)) { |
|
722 | + $query_error .= ' - check database storage space.'; |
|
723 | + } else |
|
677 | 724 | { |
678 | - if (!isset($txt['mysql_error_space'])) |
|
679 | - loadLanguage('Errors'); |
|
725 | + if (!isset($txt['mysql_error_space'])) { |
|
726 | + loadLanguage('Errors'); |
|
727 | + } |
|
680 | 728 | |
681 | 729 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
682 | 730 | } |
@@ -684,15 +732,17 @@ discard block |
||
684 | 732 | } |
685 | 733 | |
686 | 734 | // Nothing's defined yet... just die with it. |
687 | - if (empty($context) || empty($txt)) |
|
688 | - die($query_error); |
|
735 | + if (empty($context) || empty($txt)) { |
|
736 | + die($query_error); |
|
737 | + } |
|
689 | 738 | |
690 | 739 | // Show an error message, if possible. |
691 | 740 | $context['error_title'] = $txt['database_error']; |
692 | - if (allowedTo('admin_forum')) |
|
693 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
694 | - else |
|
695 | - $context['error_message'] = $txt['try_again']; |
|
741 | + if (allowedTo('admin_forum')) { |
|
742 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
743 | + } else { |
|
744 | + $context['error_message'] = $txt['try_again']; |
|
745 | + } |
|
696 | 746 | |
697 | 747 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
698 | 748 | { |
@@ -724,8 +774,9 @@ discard block |
||
724 | 774 | $return_var = null; |
725 | 775 | |
726 | 776 | // With nothing to insert, simply return. |
727 | - if (empty($data)) |
|
728 | - return; |
|
777 | + if (empty($data)) { |
|
778 | + return; |
|
779 | + } |
|
729 | 780 | |
730 | 781 | // Replace the prefix holder with the actual prefix. |
731 | 782 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -735,23 +786,26 @@ discard block |
||
735 | 786 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
736 | 787 | { |
737 | 788 | $with_returning = true; |
738 | - if ($returnmode == 2) |
|
739 | - $return_var = array(); |
|
789 | + if ($returnmode == 2) { |
|
790 | + $return_var = array(); |
|
791 | + } |
|
740 | 792 | } |
741 | 793 | |
742 | 794 | // Inserting data as a single row can be done as a single array. |
743 | - if (!is_array($data[array_rand($data)])) |
|
744 | - $data = array($data); |
|
795 | + if (!is_array($data[array_rand($data)])) { |
|
796 | + $data = array($data); |
|
797 | + } |
|
745 | 798 | |
746 | 799 | // Create the mold for a single row insert. |
747 | 800 | $insertData = '('; |
748 | 801 | foreach ($columns as $columnName => $type) |
749 | 802 | { |
750 | 803 | // Are we restricting the length? |
751 | - if (strpos($type, 'string-') !== false) |
|
752 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
753 | - else |
|
754 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
804 | + if (strpos($type, 'string-') !== false) { |
|
805 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
806 | + } else { |
|
807 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
808 | + } |
|
755 | 809 | } |
756 | 810 | $insertData = substr($insertData, 0, -2) . ')'; |
757 | 811 | |
@@ -760,8 +814,9 @@ discard block |
||
760 | 814 | |
761 | 815 | // Here's where the variables are injected to the query. |
762 | 816 | $insertRows = array(); |
763 | - foreach ($data as $dataRow) |
|
764 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
817 | + foreach ($data as $dataRow) { |
|
818 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
819 | + } |
|
765 | 820 | |
766 | 821 | // Determine the method of insertion. |
767 | 822 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -780,8 +835,7 @@ discard block |
||
780 | 835 | ), |
781 | 836 | $connection |
782 | 837 | ); |
783 | - } |
|
784 | - else //special way for ignore method with returning |
|
838 | + } else //special way for ignore method with returning |
|
785 | 839 | { |
786 | 840 | $count = count($insertRows); |
787 | 841 | $ai = 0; |
@@ -801,19 +855,21 @@ discard block |
||
801 | 855 | ); |
802 | 856 | $new_id = $smcFunc['db_insert_id'](); |
803 | 857 | |
804 | - if ($last_id != $new_id) //the inserted value was new |
|
858 | + if ($last_id != $new_id) { |
|
859 | + //the inserted value was new |
|
805 | 860 | { |
806 | 861 | $ai = $new_id; |
807 | 862 | } |
808 | - else // the inserted value already exists we need to find the pk |
|
863 | + } else // the inserted value already exists we need to find the pk |
|
809 | 864 | { |
810 | 865 | $where_string = ''; |
811 | 866 | $count2 = count($indexed_columns); |
812 | 867 | for ($x = 0; $x < $count2; $x++) |
813 | 868 | { |
814 | 869 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
815 | - if (($x + 1) < $count2) |
|
816 | - $where_string += ' AND '; |
|
870 | + if (($x + 1) < $count2) { |
|
871 | + $where_string += ' AND '; |
|
872 | + } |
|
817 | 873 | } |
818 | 874 | |
819 | 875 | $request = $smcFunc['db_query']('',' |
@@ -829,25 +885,27 @@ discard block |
||
829 | 885 | } |
830 | 886 | } |
831 | 887 | |
832 | - if ($returnmode == 1) |
|
833 | - $return_var = $ai; |
|
834 | - else if ($returnmode == 2) |
|
835 | - $return_var[] = $ai; |
|
888 | + if ($returnmode == 1) { |
|
889 | + $return_var = $ai; |
|
890 | + } else if ($returnmode == 2) { |
|
891 | + $return_var[] = $ai; |
|
892 | + } |
|
836 | 893 | } |
837 | 894 | } |
838 | 895 | |
839 | 896 | |
840 | 897 | if ($with_returning) |
841 | 898 | { |
842 | - if ($returnmode == 1 && empty($return_var)) |
|
843 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
844 | - else if ($returnmode == 2 && empty($return_var)) |
|
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)) |
|
845 | 902 | { |
846 | 903 | $return_var = array(); |
847 | 904 | $count = count($insertRows); |
848 | 905 | $start = smf_db_insert_id($table, $keys[0]); |
849 | - for ($i = 0; $i < $count; $i++ ) |
|
850 | - $return_var[] = $start + $i; |
|
906 | + for ($i = 0; $i < $count; $i++ ) { |
|
907 | + $return_var[] = $start + $i; |
|
908 | + } |
|
851 | 909 | } |
852 | 910 | return $return_var; |
853 | 911 | } |
@@ -865,8 +923,9 @@ discard block |
||
865 | 923 | */ |
866 | 924 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
867 | 925 | { |
868 | - if (empty($log_message)) |
|
869 | - $log_message = $error_message; |
|
926 | + if (empty($log_message)) { |
|
927 | + $log_message = $error_message; |
|
928 | + } |
|
870 | 929 | |
871 | 930 | foreach (debug_backtrace() as $step) |
872 | 931 | { |
@@ -885,12 +944,14 @@ discard block |
||
885 | 944 | } |
886 | 945 | |
887 | 946 | // A special case - we want the file and line numbers for debugging. |
888 | - if ($error_type == 'return') |
|
889 | - return array($file, $line); |
|
947 | + if ($error_type == 'return') { |
|
948 | + return array($file, $line); |
|
949 | + } |
|
890 | 950 | |
891 | 951 | // Is always a critical error. |
892 | - if (function_exists('log_error')) |
|
893 | - log_error($log_message, 'critical', $file, $line); |
|
952 | + if (function_exists('log_error')) { |
|
953 | + log_error($log_message, 'critical', $file, $line); |
|
954 | + } |
|
894 | 955 | |
895 | 956 | if (function_exists('fatal_error')) |
896 | 957 | { |
@@ -898,12 +959,12 @@ discard block |
||
898 | 959 | |
899 | 960 | // Cannot continue... |
900 | 961 | exit; |
962 | + } elseif ($error_type) { |
|
963 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
964 | + } else { |
|
965 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
966 | + } |
|
901 | 967 | } |
902 | - elseif ($error_type) |
|
903 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
904 | - else |
|
905 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
906 | -} |
|
907 | 968 | |
908 | 969 | /** |
909 | 970 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -920,10 +981,11 @@ discard block |
||
920 | 981 | '\\' => '\\\\', |
921 | 982 | ); |
922 | 983 | |
923 | - if ($translate_human_wildcards) |
|
924 | - $replacements += array( |
|
984 | + if ($translate_human_wildcards) { |
|
985 | + $replacements += array( |
|
925 | 986 | '*' => '%', |
926 | 987 | ); |
988 | + } |
|
927 | 989 | |
928 | 990 | return strtr($string, $replacements); |
929 | 991 | } |
@@ -937,8 +999,9 @@ discard block |
||
937 | 999 | */ |
938 | 1000 | function smf_is_resource($result) |
939 | 1001 | { |
940 | - if ($result instanceof mysqli_result) |
|
941 | - return true; |
|
1002 | + if ($result instanceof mysqli_result) { |
|
1003 | + return true; |
|
1004 | + } |
|
942 | 1005 | |
943 | 1006 | return false; |
944 | 1007 | } |
@@ -967,19 +1030,22 @@ discard block |
||
967 | 1030 | static $mysql_error_data_prep; |
968 | 1031 | |
969 | 1032 | // without database we can't do anything |
970 | - if (empty($db_connection)) |
|
971 | - return; |
|
1033 | + if (empty($db_connection)) { |
|
1034 | + return; |
|
1035 | + } |
|
972 | 1036 | |
973 | - if (empty($mysql_error_data_prep)) |
|
974 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1037 | + if (empty($mysql_error_data_prep)) { |
|
1038 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
975 | 1039 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
976 | 1040 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?)' |
977 | 1041 | ); |
1042 | + } |
|
978 | 1043 | |
979 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
980 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
981 | - else |
|
982 | - $error_array[2] = null; |
|
1044 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
1045 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1046 | + } else { |
|
1047 | + $error_array[2] = null; |
|
1048 | + } |
|
983 | 1049 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
984 | 1050 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
985 | 1051 | $error_array[7], $error_array[8]); |
@@ -1001,8 +1067,9 @@ discard block |
||
1001 | 1067 | $count = count($array_values); |
1002 | 1068 | $then = ($desc ? ' THEN -' : ' THEN '); |
1003 | 1069 | |
1004 | - for ($i = 0; $i < $count; $i++) |
|
1005 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1070 | + for ($i = 0; $i < $count; $i++) { |
|
1071 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1072 | + } |
|
1006 | 1073 | |
1007 | 1074 | $return .= 'END'; |
1008 | 1075 | return $return; |
@@ -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 | * Log an error, if the error logging is enabled. |
@@ -41,17 +42,19 @@ discard block |
||
41 | 42 | // are we in a loop? |
42 | 43 | if($error_call > 2) |
43 | 44 | { |
44 | - if (!isset($db_show_debug) || $db_show_debug === false) |
|
45 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
46 | - else |
|
47 | - $backtrace = debug_backtrace(); |
|
45 | + if (!isset($db_show_debug) || $db_show_debug === false) { |
|
46 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
47 | + } else { |
|
48 | + $backtrace = debug_backtrace(); |
|
49 | + } |
|
48 | 50 | var_dump($backtrace); |
49 | 51 | die('Error loop.'); |
50 | 52 | } |
51 | 53 | |
52 | 54 | // Check if error logging is actually on. |
53 | - if (empty($modSettings['enableErrorLogging'])) |
|
54 | - return $error_message; |
|
55 | + if (empty($modSettings['enableErrorLogging'])) { |
|
56 | + return $error_message; |
|
57 | + } |
|
55 | 58 | |
56 | 59 | // Basically, htmlspecialchars it minus &. (for entities!) |
57 | 60 | $error_message = strtr($error_message, array('<' => '<', '>' => '>', '"' => '"')); |
@@ -59,33 +62,39 @@ discard block |
||
59 | 62 | |
60 | 63 | // Add a file and line to the error message? |
61 | 64 | // Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line |
62 | - if ($file == null) |
|
63 | - $file = ''; |
|
64 | - else |
|
65 | - // Window style slashes don't play well, lets convert them to the unix style. |
|
65 | + if ($file == null) { |
|
66 | + $file = ''; |
|
67 | + } else { |
|
68 | + // Window style slashes don't play well, lets convert them to the unix style. |
|
66 | 69 | $file = str_replace('\\', '/', $file); |
70 | + } |
|
67 | 71 | |
68 | - if ($line == null) |
|
69 | - $line = 0; |
|
70 | - else |
|
71 | - $line = (int) $line; |
|
72 | + if ($line == null) { |
|
73 | + $line = 0; |
|
74 | + } else { |
|
75 | + $line = (int) $line; |
|
76 | + } |
|
72 | 77 | |
73 | 78 | // Just in case there's no id_member or IP set yet. |
74 | - if (empty($user_info['id'])) |
|
75 | - $user_info['id'] = 0; |
|
76 | - if (empty($user_info['ip'])) |
|
77 | - $user_info['ip'] = ''; |
|
79 | + if (empty($user_info['id'])) { |
|
80 | + $user_info['id'] = 0; |
|
81 | + } |
|
82 | + if (empty($user_info['ip'])) { |
|
83 | + $user_info['ip'] = ''; |
|
84 | + } |
|
78 | 85 | |
79 | 86 | // Find the best query string we can... |
80 | 87 | $query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING']; |
81 | 88 | |
82 | 89 | // Don't log the session hash in the url twice, it's a waste. |
83 | - if (!empty($smcFunc['htmlspecialchars'])) |
|
84 | - $query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); |
|
90 | + if (!empty($smcFunc['htmlspecialchars'])) { |
|
91 | + $query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); |
|
92 | + } |
|
85 | 93 | |
86 | 94 | // Just so we know what board error messages are from. |
87 | - if (isset($_POST['board']) && !isset($_GET['board'])) |
|
88 | - $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
95 | + if (isset($_POST['board']) && !isset($_GET['board'])) { |
|
96 | + $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
97 | + } |
|
89 | 98 | |
90 | 99 | // What types of categories do we have? |
91 | 100 | $known_error_types = array( |
@@ -134,9 +143,9 @@ discard block |
||
134 | 143 | |
135 | 144 | list($context['num_errors']) = $smcFunc['db_fetch_row']($query); |
136 | 145 | $smcFunc['db_free_result']($query); |
146 | + } else { |
|
147 | + $context['num_errors']++; |
|
137 | 148 | } |
138 | - else |
|
139 | - $context['num_errors']++; |
|
140 | 149 | } |
141 | 150 | |
142 | 151 | // reset error call |
@@ -158,12 +167,14 @@ discard block |
||
158 | 167 | global $txt; |
159 | 168 | |
160 | 169 | // Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all |
161 | - if (!empty($status)) |
|
162 | - send_http_status($status); |
|
170 | + if (!empty($status)) { |
|
171 | + send_http_status($status); |
|
172 | + } |
|
163 | 173 | |
164 | 174 | // We don't have $txt yet, but that's okay... |
165 | - if (empty($txt)) |
|
166 | - die($error); |
|
175 | + if (empty($txt)) { |
|
176 | + die($error); |
|
177 | + } |
|
167 | 178 | |
168 | 179 | log_error_online($error, false); |
169 | 180 | setup_fatal_error_context($log ? log_error($error, $log) : $error); |
@@ -190,8 +201,9 @@ discard block |
||
190 | 201 | static $fatal_error_called = false; |
191 | 202 | |
192 | 203 | // Send the status header - set this to 0 or false if you don't want to send one at all |
193 | - if (!empty($status)) |
|
194 | - send_http_status($status); |
|
204 | + if (!empty($status)) { |
|
205 | + send_http_status($status); |
|
206 | + } |
|
195 | 207 | |
196 | 208 | // Try to load a theme if we don't have one. |
197 | 209 | if (empty($context['theme_loaded']) && empty($fatal_error_called)) |
@@ -201,8 +213,9 @@ discard block |
||
201 | 213 | } |
202 | 214 | |
203 | 215 | // If we have no theme stuff we can't have the language file... |
204 | - if (empty($context['theme_loaded'])) |
|
205 | - die($error); |
|
216 | + if (empty($context['theme_loaded'])) { |
|
217 | + die($error); |
|
218 | + } |
|
206 | 219 | |
207 | 220 | $reload_lang_file = true; |
208 | 221 | // Log the error in the forum's language, but don't waste the time if we aren't logging |
@@ -238,8 +251,9 @@ discard block |
||
238 | 251 | global $settings, $modSettings, $db_show_debug; |
239 | 252 | |
240 | 253 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5 |
241 | - if (error_reporting() == 0) |
|
242 | - return; |
|
254 | + if (error_reporting() == 0) { |
|
255 | + return; |
|
256 | + } |
|
243 | 257 | |
244 | 258 | if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename'])) |
245 | 259 | { |
@@ -247,19 +261,22 @@ discard block |
||
247 | 261 | $count = count($array); |
248 | 262 | for ($i = 0; $i < $count; $i++) |
249 | 263 | { |
250 | - if ($array[$i]['function'] != 'loadSubTemplate') |
|
251 | - continue; |
|
264 | + if ($array[$i]['function'] != 'loadSubTemplate') { |
|
265 | + continue; |
|
266 | + } |
|
252 | 267 | |
253 | 268 | // This is a bug in PHP, with eval, it seems! |
254 | - if (empty($array[$i]['args'])) |
|
255 | - $i++; |
|
269 | + if (empty($array[$i]['args'])) { |
|
270 | + $i++; |
|
271 | + } |
|
256 | 272 | break; |
257 | 273 | } |
258 | 274 | |
259 | - if (isset($array[$i]) && !empty($array[$i]['args'])) |
|
260 | - $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
261 | - else |
|
262 | - $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
275 | + if (isset($array[$i]) && !empty($array[$i]['args'])) { |
|
276 | + $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
277 | + } else { |
|
278 | + $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
279 | + } |
|
263 | 280 | } |
264 | 281 | |
265 | 282 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -268,8 +285,9 @@ discard block |
||
268 | 285 | if ($error_level % 255 != E_ERROR) |
269 | 286 | { |
270 | 287 | $temporary = ob_get_contents(); |
271 | - if (substr($temporary, -2) == '="') |
|
272 | - echo '"'; |
|
288 | + if (substr($temporary, -2) == '="') { |
|
289 | + echo '"'; |
|
290 | + } |
|
273 | 291 | } |
274 | 292 | |
275 | 293 | // Debugging! This should look like a PHP error message. |
@@ -285,23 +303,27 @@ discard block |
||
285 | 303 | call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line)); |
286 | 304 | |
287 | 305 | // Dying on these errors only causes MORE problems (blank pages!) |
288 | - if ($file == 'Unknown') |
|
289 | - return; |
|
306 | + if ($file == 'Unknown') { |
|
307 | + return; |
|
308 | + } |
|
290 | 309 | |
291 | 310 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. |
292 | - if ($error_level % 255 == E_ERROR) |
|
293 | - obExit(false); |
|
294 | - else |
|
295 | - return; |
|
311 | + if ($error_level % 255 == E_ERROR) { |
|
312 | + obExit(false); |
|
313 | + } else { |
|
314 | + return; |
|
315 | + } |
|
296 | 316 | |
297 | 317 | // If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die. Violently so. |
298 | - if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) |
|
299 | - fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
318 | + if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) { |
|
319 | + fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
320 | + } |
|
300 | 321 | |
301 | 322 | // We should NEVER get to this point. Any fatal error MUST quit, or very bad things can happen. |
302 | - if ($error_level % 255 == E_ERROR) |
|
303 | - die('No direct access...'); |
|
304 | -} |
|
323 | + if ($error_level % 255 == E_ERROR) { |
|
324 | + die('No direct access...'); |
|
325 | + } |
|
326 | + } |
|
305 | 327 | |
306 | 328 | /** |
307 | 329 | * It is called by {@link fatal_error()} and {@link fatal_lang_error()}. |
@@ -317,24 +339,28 @@ discard block |
||
317 | 339 | |
318 | 340 | // Attempt to prevent a recursive loop. |
319 | 341 | ++$level; |
320 | - if ($level > 1) |
|
321 | - return false; |
|
342 | + if ($level > 1) { |
|
343 | + return false; |
|
344 | + } |
|
322 | 345 | |
323 | 346 | // Maybe they came from dlattach or similar? |
324 | - if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) |
|
325 | - loadTheme(); |
|
347 | + if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) { |
|
348 | + loadTheme(); |
|
349 | + } |
|
326 | 350 | |
327 | 351 | // Don't bother indexing errors mate... |
328 | 352 | $context['robot_no_index'] = true; |
329 | 353 | |
330 | - if (!isset($context['error_title'])) |
|
331 | - $context['error_title'] = $txt['error_occured']; |
|
354 | + if (!isset($context['error_title'])) { |
|
355 | + $context['error_title'] = $txt['error_occured']; |
|
356 | + } |
|
332 | 357 | $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message; |
333 | 358 | |
334 | 359 | $context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : ''; |
335 | 360 | |
336 | - if (empty($context['page_title'])) |
|
337 | - $context['page_title'] = $context['error_title']; |
|
361 | + if (empty($context['page_title'])) { |
|
362 | + $context['page_title'] = $context['error_title']; |
|
363 | + } |
|
338 | 364 | |
339 | 365 | loadTemplate('Errors'); |
340 | 366 | $context['sub_template'] = 'fatal_error'; |
@@ -342,23 +368,26 @@ discard block |
||
342 | 368 | // If this is SSI, what do they want us to do? |
343 | 369 | if (SMF == 'SSI') |
344 | 370 | { |
345 | - if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) |
|
346 | - $ssi_on_error_method(); |
|
347 | - elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
348 | - loadSubTemplate('fatal_error'); |
|
371 | + if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) { |
|
372 | + $ssi_on_error_method(); |
|
373 | + } elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
374 | + loadSubTemplate('fatal_error'); |
|
375 | + } |
|
349 | 376 | |
350 | 377 | // No layers? |
351 | - if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
352 | - exit; |
|
378 | + if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
379 | + exit; |
|
380 | + } |
|
353 | 381 | } |
354 | 382 | // Alternatively from the cron call? |
355 | 383 | elseif (SMF == 'BACKGROUND') |
356 | 384 | { |
357 | 385 | // We can't rely on even having language files available. |
358 | - if (defined('FROM_CLI') && FROM_CLI) |
|
359 | - echo 'cron error: ', $context['error_message']; |
|
360 | - else |
|
361 | - echo 'An error occurred. More information may be available in your logs.'; |
|
386 | + if (defined('FROM_CLI') && FROM_CLI) { |
|
387 | + echo 'cron error: ', $context['error_message']; |
|
388 | + } else { |
|
389 | + echo 'An error occurred. More information may be available in your logs.'; |
|
390 | + } |
|
362 | 391 | exit; |
363 | 392 | } |
364 | 393 | |
@@ -386,8 +415,8 @@ discard block |
||
386 | 415 | |
387 | 416 | set_fatal_error_headers(); |
388 | 417 | |
389 | - if (!empty($maintenance)) |
|
390 | - echo '<!DOCTYPE html> |
|
418 | + if (!empty($maintenance)) { |
|
419 | + echo '<!DOCTYPE html> |
|
391 | 420 | <html> |
392 | 421 | <head> |
393 | 422 | <meta name="robots" content="noindex"> |
@@ -398,6 +427,7 @@ discard block |
||
398 | 427 | ', $mmessage, ' |
399 | 428 | </body> |
400 | 429 | </html>'; |
430 | + } |
|
401 | 431 | |
402 | 432 | die(); |
403 | 433 | } |
@@ -419,15 +449,17 @@ discard block |
||
419 | 449 | // For our purposes, we're gonna want this on if at all possible. |
420 | 450 | $modSettings['cache_enable'] = '1'; |
421 | 451 | |
422 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
423 | - $db_last_error = max($db_last_error, $temp); |
|
452 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
453 | + $db_last_error = max($db_last_error, $temp); |
|
454 | + } |
|
424 | 455 | |
425 | 456 | if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send)) |
426 | 457 | { |
427 | 458 | // Avoid writing to the Settings.php file if at all possible; use shared memory instead. |
428 | 459 | cache_put_data('db_last_error', time(), 600); |
429 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
430 | - logLastDatabaseError(); |
|
460 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
461 | + logLastDatabaseError(); |
|
462 | + } |
|
431 | 463 | |
432 | 464 | // Language files aren't loaded yet :(. |
433 | 465 | $db_error = @$smcFunc['db_error']($db_connection); |
@@ -484,8 +516,9 @@ discard block |
||
484 | 516 | */ |
485 | 517 | function set_fatal_error_headers() |
486 | 518 | { |
487 | - if (headers_sent()) |
|
488 | - return; |
|
519 | + if (headers_sent()) { |
|
520 | + return; |
|
521 | + } |
|
489 | 522 | |
490 | 523 | // Don't cache this page! |
491 | 524 | header('expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -511,12 +544,14 @@ discard block |
||
511 | 544 | global $smcFunc, $user_info, $modSettings; |
512 | 545 | |
513 | 546 | // Don't bother if Who's Online is disabled. |
514 | - if (empty($modSettings['who_enabled'])) |
|
515 | - return; |
|
547 | + if (empty($modSettings['who_enabled'])) { |
|
548 | + return; |
|
549 | + } |
|
516 | 550 | |
517 | 551 | // Maybe they came from SSI or similar where sessions are not recorded? |
518 | - if (SMF == 'SSI' || SMF == 'BACKGROUND') |
|
519 | - return; |
|
552 | + if (SMF == 'SSI' || SMF == 'BACKGROUND') { |
|
553 | + return; |
|
554 | + } |
|
520 | 555 | |
521 | 556 | $session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id(); |
522 | 557 | |
@@ -542,8 +577,9 @@ discard block |
||
542 | 577 | $url = $smcFunc['json_decode']($url, true); |
543 | 578 | $url['error'] = $error; |
544 | 579 | |
545 | - if (!empty($sprintf)) |
|
546 | - $url['error_params'] = $sprintf; |
|
580 | + if (!empty($sprintf)) { |
|
581 | + $url['error_params'] = $sprintf; |
|
582 | + } |
|
547 | 583 | |
548 | 584 | $smcFunc['db_query']('', ' |
549 | 585 | UPDATE {db_prefix}log_online |
@@ -574,10 +610,11 @@ discard block |
||
574 | 610 | |
575 | 611 | $protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; |
576 | 612 | |
577 | - if (!isset($statuses[$code])) |
|
578 | - header($protocol . ' 500 Internal Server Error'); |
|
579 | - else |
|
580 | - header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
581 | -} |
|
613 | + if (!isset($statuses[$code])) { |
|
614 | + header($protocol . ' 500 Internal Server Error'); |
|
615 | + } else { |
|
616 | + header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
617 | + } |
|
618 | + } |
|
582 | 619 | |
583 | 620 | ?> |
584 | 621 | \ No newline at end of file |