@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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, $mysql_set_mode; |
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', |
@@ -58,9 +59,11 @@ discard block |
||
58 | 59 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
59 | 60 | 'db_is_resource' => 'smf_is_resource', |
60 | 61 | ); |
62 | + } |
|
61 | 63 | |
62 | - if (!empty($db_options['persist'])) |
|
63 | - $db_server = 'p:' . $db_server; |
|
64 | + if (!empty($db_options['persist'])) { |
|
65 | + $db_server = 'p:' . $db_server; |
|
66 | + } |
|
64 | 67 | |
65 | 68 | $connection = mysqli_init(); |
66 | 69 | |
@@ -69,31 +72,35 @@ discard block |
||
69 | 72 | $success = false; |
70 | 73 | |
71 | 74 | if ($connection) { |
72 | - if (!empty($db_options['port'])) |
|
73 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
74 | - else |
|
75 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
75 | + if (!empty($db_options['port'])) { |
|
76 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
77 | + } else { |
|
78 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
79 | + } |
|
76 | 80 | } |
77 | 81 | |
78 | 82 | // Something's wrong, show an error if its fatal (which we assume it is) |
79 | 83 | if ($success === false) |
80 | 84 | { |
81 | - if (!empty($db_options['non_fatal'])) |
|
82 | - return null; |
|
83 | - else |
|
84 | - display_db_error(); |
|
85 | + if (!empty($db_options['non_fatal'])) { |
|
86 | + return null; |
|
87 | + } else { |
|
88 | + display_db_error(); |
|
89 | + } |
|
85 | 90 | } |
86 | 91 | |
87 | 92 | // Select the database, unless told not to |
88 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
89 | - display_db_error(); |
|
93 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
94 | + display_db_error(); |
|
95 | + } |
|
90 | 96 | |
91 | 97 | // This makes it possible to have SMF automatically change the sql_mode and autocommit if needed. |
92 | - if (isset($mysql_set_mode) && $mysql_set_mode === true) |
|
93 | - $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
98 | + if (isset($mysql_set_mode) && $mysql_set_mode === true) { |
|
99 | + $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
94 | 100 | array(), |
95 | 101 | false |
96 | 102 | ); |
103 | + } |
|
97 | 104 | |
98 | 105 | return $connection; |
99 | 106 | } |
@@ -164,37 +171,46 @@ discard block |
||
164 | 171 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
165 | 172 | |
166 | 173 | list ($values, $connection) = $db_callback; |
167 | - if (!is_object($connection)) |
|
168 | - display_db_error(); |
|
174 | + if (!is_object($connection)) { |
|
175 | + display_db_error(); |
|
176 | + } |
|
169 | 177 | |
170 | - if ($matches[1] === 'db_prefix') |
|
171 | - return $db_prefix; |
|
178 | + if ($matches[1] === 'db_prefix') { |
|
179 | + return $db_prefix; |
|
180 | + } |
|
172 | 181 | |
173 | - if ($matches[1] === 'query_see_board') |
|
174 | - return $user_info['query_see_board']; |
|
182 | + if ($matches[1] === 'query_see_board') { |
|
183 | + return $user_info['query_see_board']; |
|
184 | + } |
|
175 | 185 | |
176 | - if ($matches[1] === 'query_wanna_see_board') |
|
177 | - return $user_info['query_wanna_see_board']; |
|
186 | + if ($matches[1] === 'query_wanna_see_board') { |
|
187 | + return $user_info['query_wanna_see_board']; |
|
188 | + } |
|
178 | 189 | |
179 | - if ($matches[1] === 'empty') |
|
180 | - return '\'\''; |
|
190 | + if ($matches[1] === 'empty') { |
|
191 | + return '\'\''; |
|
192 | + } |
|
181 | 193 | |
182 | - if (!isset($matches[2])) |
|
183 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
194 | + if (!isset($matches[2])) { |
|
195 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
196 | + } |
|
184 | 197 | |
185 | - if ($matches[1] === 'literal') |
|
186 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
198 | + if ($matches[1] === 'literal') { |
|
199 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
200 | + } |
|
187 | 201 | |
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__); |
|
202 | + if (!isset($values[$matches[2]])) { |
|
203 | + 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__); |
|
204 | + } |
|
190 | 205 | |
191 | 206 | $replacement = $values[$matches[2]]; |
192 | 207 | |
193 | 208 | switch ($matches[1]) |
194 | 209 | { |
195 | 210 | 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__); |
|
211 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
212 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
213 | + } |
|
198 | 214 | return (string) (int) $replacement; |
199 | 215 | break; |
200 | 216 | |
@@ -206,56 +222,63 @@ discard block |
||
206 | 222 | case 'array_int': |
207 | 223 | if (is_array($replacement)) |
208 | 224 | { |
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__); |
|
225 | + if (empty($replacement)) { |
|
226 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
227 | + } |
|
211 | 228 | |
212 | 229 | foreach ($replacement as $key => $value) |
213 | 230 | { |
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__); |
|
231 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
232 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
233 | + } |
|
216 | 234 | |
217 | 235 | $replacement[$key] = (string) (int) $value; |
218 | 236 | } |
219 | 237 | |
220 | 238 | return implode(', ', $replacement); |
239 | + } else { |
|
240 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
221 | 241 | } |
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 | 242 | |
225 | 243 | break; |
226 | 244 | |
227 | 245 | case 'array_string': |
228 | 246 | if (is_array($replacement)) |
229 | 247 | { |
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__); |
|
248 | + if (empty($replacement)) { |
|
249 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
250 | + } |
|
232 | 251 | |
233 | - foreach ($replacement as $key => $value) |
|
234 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
252 | + foreach ($replacement as $key => $value) { |
|
253 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
254 | + } |
|
235 | 255 | |
236 | 256 | return implode(', ', $replacement); |
257 | + } else { |
|
258 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | 259 | } |
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 | 260 | break; |
241 | 261 | |
242 | 262 | 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__); |
|
263 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
264 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
265 | + } else { |
|
266 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
267 | + } |
|
247 | 268 | break; |
248 | 269 | |
249 | 270 | 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__); |
|
271 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
272 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
273 | + } else { |
|
274 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
275 | + } |
|
254 | 276 | break; |
255 | 277 | |
256 | 278 | case 'float': |
257 | - if (!is_numeric($replacement)) |
|
258 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
279 | + if (!is_numeric($replacement)) { |
|
280 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
281 | + } |
|
259 | 282 | return (string) (float) $replacement; |
260 | 283 | break; |
261 | 284 | |
@@ -269,32 +292,37 @@ discard block |
||
269 | 292 | break; |
270 | 293 | |
271 | 294 | case 'inet': |
272 | - if ($replacement == 'null' || $replacement == '') |
|
273 | - return 'null'; |
|
274 | - if (!isValidIP($replacement)) |
|
275 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
295 | + if ($replacement == 'null' || $replacement == '') { |
|
296 | + return 'null'; |
|
297 | + } |
|
298 | + if (!isValidIP($replacement)) { |
|
299 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
300 | + } |
|
276 | 301 | //we don't use the native support of mysql > 5.6.2 |
277 | 302 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
278 | 303 | |
279 | 304 | case 'array_inet': |
280 | 305 | if (is_array($replacement)) |
281 | 306 | { |
282 | - if (empty($replacement)) |
|
283 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
307 | + if (empty($replacement)) { |
|
308 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
309 | + } |
|
284 | 310 | |
285 | 311 | foreach ($replacement as $key => $value) |
286 | 312 | { |
287 | - if ($replacement == 'null' || $replacement == '') |
|
288 | - $replacement[$key] = 'null'; |
|
289 | - if (!isValidIP($value)) |
|
290 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
313 | + if ($replacement == 'null' || $replacement == '') { |
|
314 | + $replacement[$key] = 'null'; |
|
315 | + } |
|
316 | + if (!isValidIP($value)) { |
|
317 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
318 | + } |
|
291 | 319 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
292 | 320 | } |
293 | 321 | |
294 | 322 | return implode(', ', $replacement); |
323 | + } else { |
|
324 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
295 | 325 | } |
296 | - else |
|
297 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
298 | 326 | break; |
299 | 327 | |
300 | 328 | default: |
@@ -370,22 +398,25 @@ discard block |
||
370 | 398 | // Are we in SSI mode? If so try that username and password first |
371 | 399 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
372 | 400 | { |
373 | - if (empty($db_persist)) |
|
374 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
375 | - else |
|
376 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
401 | + if (empty($db_persist)) { |
|
402 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
403 | + } else { |
|
404 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
405 | + } |
|
377 | 406 | } |
378 | 407 | // Fall back to the regular username and password if need be |
379 | 408 | if (!$db_connection) |
380 | 409 | { |
381 | - if (empty($db_persist)) |
|
382 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
383 | - else |
|
384 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
410 | + if (empty($db_persist)) { |
|
411 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
412 | + } else { |
|
413 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
414 | + } |
|
385 | 415 | } |
386 | 416 | |
387 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
388 | - $db_connection = false; |
|
417 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
418 | + $db_connection = false; |
|
419 | + } |
|
389 | 420 | |
390 | 421 | $connection = $db_connection; |
391 | 422 | } |
@@ -393,18 +424,20 @@ discard block |
||
393 | 424 | // One more query.... |
394 | 425 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
395 | 426 | |
396 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
397 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
427 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
428 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
429 | + } |
|
398 | 430 | |
399 | 431 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
400 | 432 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
401 | 433 | { |
402 | 434 | // Add before LIMIT |
403 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
404 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
405 | - else |
|
406 | - // Append it. |
|
435 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
436 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
437 | + } else { |
|
438 | + // Append it. |
|
407 | 439 | $db_string .= "\n\t\t\tORDER BY null"; |
440 | + } |
|
408 | 441 | } |
409 | 442 | |
410 | 443 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -426,8 +459,9 @@ discard block |
||
426 | 459 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
427 | 460 | |
428 | 461 | // Initialize $db_cache if not already initialized. |
429 | - if (!isset($db_cache)) |
|
430 | - $db_cache = array(); |
|
462 | + if (!isset($db_cache)) { |
|
463 | + $db_cache = array(); |
|
464 | + } |
|
431 | 465 | |
432 | 466 | if (!empty($_SESSION['debug_redirect'])) |
433 | 467 | { |
@@ -453,17 +487,18 @@ discard block |
||
453 | 487 | while (true) |
454 | 488 | { |
455 | 489 | $pos = strpos($db_string, '\'', $pos + 1); |
456 | - if ($pos === false) |
|
457 | - break; |
|
490 | + if ($pos === false) { |
|
491 | + break; |
|
492 | + } |
|
458 | 493 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
459 | 494 | |
460 | 495 | while (true) |
461 | 496 | { |
462 | 497 | $pos1 = strpos($db_string, '\'', $pos + 1); |
463 | 498 | $pos2 = strpos($db_string, '\\', $pos + 1); |
464 | - if ($pos1 === false) |
|
465 | - break; |
|
466 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
499 | + if ($pos1 === false) { |
|
500 | + break; |
|
501 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
467 | 502 | { |
468 | 503 | $pos = $pos1; |
469 | 504 | break; |
@@ -479,29 +514,35 @@ discard block |
||
479 | 514 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
480 | 515 | |
481 | 516 | // Comments? We don't use comments in our queries, we leave 'em outside! |
482 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
483 | - $fail = true; |
|
517 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
518 | + $fail = true; |
|
519 | + } |
|
484 | 520 | // Trying to change passwords, slow us down, or something? |
485 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
486 | - $fail = true; |
|
487 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
488 | - $fail = true; |
|
521 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
522 | + $fail = true; |
|
523 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
524 | + $fail = true; |
|
525 | + } |
|
489 | 526 | |
490 | - if (!empty($fail) && function_exists('log_error')) |
|
491 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
527 | + if (!empty($fail) && function_exists('log_error')) { |
|
528 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
529 | + } |
|
492 | 530 | } |
493 | 531 | |
494 | - if (empty($db_unbuffered)) |
|
495 | - $ret = @mysqli_query($connection, $db_string); |
|
496 | - else |
|
497 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
532 | + if (empty($db_unbuffered)) { |
|
533 | + $ret = @mysqli_query($connection, $db_string); |
|
534 | + } else { |
|
535 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
536 | + } |
|
498 | 537 | |
499 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
500 | - $ret = smf_db_error($db_string, $connection); |
|
538 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
539 | + $ret = smf_db_error($db_string, $connection); |
|
540 | + } |
|
501 | 541 | |
502 | 542 | // Debugging. |
503 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
504 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
543 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
544 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
545 | + } |
|
505 | 546 | |
506 | 547 | return $ret; |
507 | 548 | } |
@@ -548,12 +589,13 @@ discard block |
||
548 | 589 | // Decide which connection to use |
549 | 590 | $connection = $connection === null ? $db_connection : $connection; |
550 | 591 | |
551 | - if ($type == 'begin') |
|
552 | - return @mysqli_query($connection, 'BEGIN'); |
|
553 | - elseif ($type == 'rollback') |
|
554 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
555 | - elseif ($type == 'commit') |
|
556 | - return @mysqli_query($connection, 'COMMIT'); |
|
592 | + if ($type == 'begin') { |
|
593 | + return @mysqli_query($connection, 'BEGIN'); |
|
594 | + } elseif ($type == 'rollback') { |
|
595 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
596 | + } elseif ($type == 'commit') { |
|
597 | + return @mysqli_query($connection, 'COMMIT'); |
|
598 | + } |
|
557 | 599 | |
558 | 600 | return false; |
559 | 601 | } |
@@ -593,8 +635,9 @@ discard block |
||
593 | 635 | // 2013: Lost connection to server during query. |
594 | 636 | |
595 | 637 | // Log the error. |
596 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
597 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
638 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
639 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
640 | + } |
|
598 | 641 | |
599 | 642 | // Database error auto fixing ;). |
600 | 643 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -603,8 +646,9 @@ discard block |
||
603 | 646 | $old_cache = @$modSettings['cache_enable']; |
604 | 647 | $modSettings['cache_enable'] = '1'; |
605 | 648 | |
606 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
607 | - $db_last_error = max(@$db_last_error, $temp); |
|
649 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
650 | + $db_last_error = max(@$db_last_error, $temp); |
|
651 | + } |
|
608 | 652 | |
609 | 653 | if (@$db_last_error < time() - 3600 * 24 * 3) |
610 | 654 | { |
@@ -620,8 +664,9 @@ discard block |
||
620 | 664 | foreach ($tables as $table) |
621 | 665 | { |
622 | 666 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
623 | - if (trim($table) != '') |
|
624 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
667 | + if (trim($table) != '') { |
|
668 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
669 | + } |
|
625 | 670 | } |
626 | 671 | } |
627 | 672 | |
@@ -630,8 +675,9 @@ discard block |
||
630 | 675 | // Table crashed. Let's try to fix it. |
631 | 676 | elseif ($query_errno == 1016) |
632 | 677 | { |
633 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
634 | - $fix_tables = array('`' . $match[1] . '`'); |
|
678 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
679 | + $fix_tables = array('`' . $match[1] . '`'); |
|
680 | + } |
|
635 | 681 | } |
636 | 682 | // Indexes crashed. Should be easy to fix! |
637 | 683 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -650,13 +696,15 @@ discard block |
||
650 | 696 | |
651 | 697 | // Make a note of the REPAIR... |
652 | 698 | cache_put_data('db_last_error', time(), 600); |
653 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
654 | - updateSettingsFile(array('db_last_error' => time())); |
|
699 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
700 | + updateSettingsFile(array('db_last_error' => time())); |
|
701 | + } |
|
655 | 702 | |
656 | 703 | // Attempt to find and repair the broken table. |
657 | - foreach ($fix_tables as $table) |
|
658 | - $smcFunc['db_query']('', " |
|
704 | + foreach ($fix_tables as $table) { |
|
705 | + $smcFunc['db_query']('', " |
|
659 | 706 | REPAIR TABLE $table", false, false); |
707 | + } |
|
660 | 708 | |
661 | 709 | // And send off an email! |
662 | 710 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -665,11 +713,12 @@ discard block |
||
665 | 713 | |
666 | 714 | // Try the query again...? |
667 | 715 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
668 | - if ($ret !== false) |
|
669 | - return $ret; |
|
716 | + if ($ret !== false) { |
|
717 | + return $ret; |
|
718 | + } |
|
719 | + } else { |
|
720 | + $modSettings['cache_enable'] = $old_cache; |
|
670 | 721 | } |
671 | - else |
|
672 | - $modSettings['cache_enable'] = $old_cache; |
|
673 | 722 | |
674 | 723 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
675 | 724 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -679,22 +728,25 @@ discard block |
||
679 | 728 | // Are we in SSI mode? If so try that username and password first |
680 | 729 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
681 | 730 | { |
682 | - if (empty($db_persist)) |
|
683 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
684 | - else |
|
685 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
731 | + if (empty($db_persist)) { |
|
732 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
733 | + } else { |
|
734 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
735 | + } |
|
686 | 736 | } |
687 | 737 | // Fall back to the regular username and password if need be |
688 | 738 | if (!$db_connection) |
689 | 739 | { |
690 | - if (empty($db_persist)) |
|
691 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
692 | - else |
|
693 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
740 | + if (empty($db_persist)) { |
|
741 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
742 | + } else { |
|
743 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
744 | + } |
|
694 | 745 | } |
695 | 746 | |
696 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
697 | - $db_connection = false; |
|
747 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
748 | + $db_connection = false; |
|
749 | + } |
|
698 | 750 | } |
699 | 751 | |
700 | 752 | if ($db_connection) |
@@ -705,24 +757,27 @@ discard block |
||
705 | 757 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
706 | 758 | |
707 | 759 | $new_errno = mysqli_errno($db_connection); |
708 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
709 | - break; |
|
760 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
761 | + break; |
|
762 | + } |
|
710 | 763 | } |
711 | 764 | |
712 | 765 | // If it failed again, shucks to be you... we're not trying it over and over. |
713 | - if ($ret !== false) |
|
714 | - return $ret; |
|
766 | + if ($ret !== false) { |
|
767 | + return $ret; |
|
768 | + } |
|
715 | 769 | } |
716 | 770 | } |
717 | 771 | // Are they out of space, perhaps? |
718 | 772 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
719 | 773 | { |
720 | - if (!isset($txt)) |
|
721 | - $query_error .= ' - check database storage space.'; |
|
722 | - else |
|
774 | + if (!isset($txt)) { |
|
775 | + $query_error .= ' - check database storage space.'; |
|
776 | + } else |
|
723 | 777 | { |
724 | - if (!isset($txt['mysql_error_space'])) |
|
725 | - loadLanguage('Errors'); |
|
778 | + if (!isset($txt['mysql_error_space'])) { |
|
779 | + loadLanguage('Errors'); |
|
780 | + } |
|
726 | 781 | |
727 | 782 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
728 | 783 | } |
@@ -730,15 +785,17 @@ discard block |
||
730 | 785 | } |
731 | 786 | |
732 | 787 | // Nothing's defined yet... just die with it. |
733 | - if (empty($context) || empty($txt)) |
|
734 | - die($query_error); |
|
788 | + if (empty($context) || empty($txt)) { |
|
789 | + die($query_error); |
|
790 | + } |
|
735 | 791 | |
736 | 792 | // Show an error message, if possible. |
737 | 793 | $context['error_title'] = $txt['database_error']; |
738 | - if (allowedTo('admin_forum')) |
|
739 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
740 | - else |
|
741 | - $context['error_message'] = $txt['try_again']; |
|
794 | + if (allowedTo('admin_forum')) { |
|
795 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
796 | + } else { |
|
797 | + $context['error_message'] = $txt['try_again']; |
|
798 | + } |
|
742 | 799 | |
743 | 800 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
744 | 801 | { |
@@ -768,25 +825,28 @@ discard block |
||
768 | 825 | $connection = $connection === null ? $db_connection : $connection; |
769 | 826 | |
770 | 827 | // With nothing to insert, simply return. |
771 | - if (empty($data)) |
|
772 | - return; |
|
828 | + if (empty($data)) { |
|
829 | + return; |
|
830 | + } |
|
773 | 831 | |
774 | 832 | // Replace the prefix holder with the actual prefix. |
775 | 833 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
776 | 834 | |
777 | 835 | // Inserting data as a single row can be done as a single array. |
778 | - if (!is_array($data[array_rand($data)])) |
|
779 | - $data = array($data); |
|
836 | + if (!is_array($data[array_rand($data)])) { |
|
837 | + $data = array($data); |
|
838 | + } |
|
780 | 839 | |
781 | 840 | // Create the mold for a single row insert. |
782 | 841 | $insertData = '('; |
783 | 842 | foreach ($columns as $columnName => $type) |
784 | 843 | { |
785 | 844 | // Are we restricting the length? |
786 | - if (strpos($type, 'string-') !== false) |
|
787 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
788 | - else |
|
789 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
845 | + if (strpos($type, 'string-') !== false) { |
|
846 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
847 | + } else { |
|
848 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
849 | + } |
|
790 | 850 | } |
791 | 851 | $insertData = substr($insertData, 0, -2) . ')'; |
792 | 852 | |
@@ -795,8 +855,9 @@ discard block |
||
795 | 855 | |
796 | 856 | // Here's where the variables are injected to the query. |
797 | 857 | $insertRows = array(); |
798 | - foreach ($data as $dataRow) |
|
799 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
858 | + foreach ($data as $dataRow) { |
|
859 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
860 | + } |
|
800 | 861 | |
801 | 862 | // Determine the method of insertion. |
802 | 863 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -816,15 +877,16 @@ discard block |
||
816 | 877 | |
817 | 878 | if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0) |
818 | 879 | { |
819 | - if ($returnmode == 1) |
|
820 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
821 | - else if ($returnmode == 2) |
|
880 | + if ($returnmode == 1) { |
|
881 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
882 | + } else if ($returnmode == 2) |
|
822 | 883 | { |
823 | 884 | $return_var = array(); |
824 | 885 | $count = count($insertRows); |
825 | 886 | $start = smf_db_insert_id($table, $keys[0]); |
826 | - for ($i = 0; $i < $count; $i++ ) |
|
827 | - $return_var[] = $start + $i; |
|
887 | + for ($i = 0; $i < $count; $i++ ) { |
|
888 | + $return_var[] = $start + $i; |
|
889 | + } |
|
828 | 890 | } |
829 | 891 | return $return_var; |
830 | 892 | } |
@@ -842,8 +904,9 @@ discard block |
||
842 | 904 | */ |
843 | 905 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
844 | 906 | { |
845 | - if (empty($log_message)) |
|
846 | - $log_message = $error_message; |
|
907 | + if (empty($log_message)) { |
|
908 | + $log_message = $error_message; |
|
909 | + } |
|
847 | 910 | |
848 | 911 | foreach (debug_backtrace() as $step) |
849 | 912 | { |
@@ -862,12 +925,14 @@ discard block |
||
862 | 925 | } |
863 | 926 | |
864 | 927 | // A special case - we want the file and line numbers for debugging. |
865 | - if ($error_type == 'return') |
|
866 | - return array($file, $line); |
|
928 | + if ($error_type == 'return') { |
|
929 | + return array($file, $line); |
|
930 | + } |
|
867 | 931 | |
868 | 932 | // Is always a critical error. |
869 | - if (function_exists('log_error')) |
|
870 | - log_error($log_message, 'critical', $file, $line); |
|
933 | + if (function_exists('log_error')) { |
|
934 | + log_error($log_message, 'critical', $file, $line); |
|
935 | + } |
|
871 | 936 | |
872 | 937 | if (function_exists('fatal_error')) |
873 | 938 | { |
@@ -875,12 +940,12 @@ discard block |
||
875 | 940 | |
876 | 941 | // Cannot continue... |
877 | 942 | exit; |
943 | + } elseif ($error_type) { |
|
944 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
945 | + } else { |
|
946 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
947 | + } |
|
878 | 948 | } |
879 | - elseif ($error_type) |
|
880 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
881 | - else |
|
882 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
883 | -} |
|
884 | 949 | |
885 | 950 | /** |
886 | 951 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -897,10 +962,11 @@ discard block |
||
897 | 962 | '\\' => '\\\\', |
898 | 963 | ); |
899 | 964 | |
900 | - if ($translate_human_wildcards) |
|
901 | - $replacements += array( |
|
965 | + if ($translate_human_wildcards) { |
|
966 | + $replacements += array( |
|
902 | 967 | '*' => '%', |
903 | 968 | ); |
969 | + } |
|
904 | 970 | |
905 | 971 | return strtr($string, $replacements); |
906 | 972 | } |
@@ -914,8 +980,9 @@ discard block |
||
914 | 980 | */ |
915 | 981 | function smf_is_resource($result) |
916 | 982 | { |
917 | - if ($result instanceof mysqli_result) |
|
918 | - return true; |
|
983 | + if ($result instanceof mysqli_result) { |
|
984 | + return true; |
|
985 | + } |
|
919 | 986 | |
920 | 987 | return false; |
921 | 988 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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) |
@@ -34,8 +35,8 @@ discard block |
||
34 | 35 | global $smcFunc; |
35 | 36 | |
36 | 37 | // Map some database specific functions, only do this once. |
37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
38 | - $smcFunc += array( |
|
38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
39 | + $smcFunc += array( |
|
39 | 40 | 'db_query' => 'smf_db_query', |
40 | 41 | 'db_quote' => 'smf_db_quote', |
41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -59,11 +60,13 @@ discard block |
||
59 | 60 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
60 | 61 | 'db_is_resource' => 'is_resource', |
61 | 62 | ); |
63 | + } |
|
62 | 64 | |
63 | - if (!empty($db_options['persist'])) |
|
64 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
65 | - else |
|
66 | - $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
65 | + if (!empty($db_options['persist'])) { |
|
66 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
67 | + } else { |
|
68 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
69 | + } |
|
67 | 70 | |
68 | 71 | // Something's wrong, show an error if its fatal (which we assume it is) |
69 | 72 | if (!$connection) |
@@ -71,8 +74,7 @@ discard block |
||
71 | 74 | if (!empty($db_options['non_fatal'])) |
72 | 75 | { |
73 | 76 | return null; |
74 | - } |
|
75 | - else |
|
77 | + } else |
|
76 | 78 | { |
77 | 79 | display_db_error(); |
78 | 80 | } |
@@ -123,34 +125,42 @@ discard block |
||
123 | 125 | |
124 | 126 | list ($values, $connection) = $db_callback; |
125 | 127 | |
126 | - if ($matches[1] === 'db_prefix') |
|
127 | - return $db_prefix; |
|
128 | + if ($matches[1] === 'db_prefix') { |
|
129 | + return $db_prefix; |
|
130 | + } |
|
128 | 131 | |
129 | - if ($matches[1] === 'query_see_board') |
|
130 | - return $user_info['query_see_board']; |
|
132 | + if ($matches[1] === 'query_see_board') { |
|
133 | + return $user_info['query_see_board']; |
|
134 | + } |
|
131 | 135 | |
132 | - if ($matches[1] === 'query_wanna_see_board') |
|
133 | - return $user_info['query_wanna_see_board']; |
|
136 | + if ($matches[1] === 'query_wanna_see_board') { |
|
137 | + return $user_info['query_wanna_see_board']; |
|
138 | + } |
|
134 | 139 | |
135 | - if ($matches[1] === 'empty') |
|
136 | - return '\'\''; |
|
140 | + if ($matches[1] === 'empty') { |
|
141 | + return '\'\''; |
|
142 | + } |
|
137 | 143 | |
138 | - if (!isset($matches[2])) |
|
139 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
144 | + if (!isset($matches[2])) { |
|
145 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
146 | + } |
|
140 | 147 | |
141 | - if ($matches[1] === 'literal') |
|
142 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
148 | + if ($matches[1] === 'literal') { |
|
149 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
150 | + } |
|
143 | 151 | |
144 | - if (!isset($values[$matches[2]])) |
|
145 | - 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__); |
|
152 | + if (!isset($values[$matches[2]])) { |
|
153 | + 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__); |
|
154 | + } |
|
146 | 155 | |
147 | 156 | $replacement = $values[$matches[2]]; |
148 | 157 | |
149 | 158 | switch ($matches[1]) |
150 | 159 | { |
151 | 160 | case 'int': |
152 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
153 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
161 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
162 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
163 | + } |
|
154 | 164 | return (string) (int) $replacement; |
155 | 165 | break; |
156 | 166 | |
@@ -162,56 +172,63 @@ discard block |
||
162 | 172 | case 'array_int': |
163 | 173 | if (is_array($replacement)) |
164 | 174 | { |
165 | - if (empty($replacement)) |
|
166 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
175 | + if (empty($replacement)) { |
|
176 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
177 | + } |
|
167 | 178 | |
168 | 179 | foreach ($replacement as $key => $value) |
169 | 180 | { |
170 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
171 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
181 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
182 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
183 | + } |
|
172 | 184 | |
173 | 185 | $replacement[$key] = (string) (int) $value; |
174 | 186 | } |
175 | 187 | |
176 | 188 | return implode(', ', $replacement); |
189 | + } else { |
|
190 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
177 | 191 | } |
178 | - else |
|
179 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
180 | 192 | |
181 | 193 | break; |
182 | 194 | |
183 | 195 | case 'array_string': |
184 | 196 | if (is_array($replacement)) |
185 | 197 | { |
186 | - if (empty($replacement)) |
|
187 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
198 | + if (empty($replacement)) { |
|
199 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
200 | + } |
|
188 | 201 | |
189 | - foreach ($replacement as $key => $value) |
|
190 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
202 | + foreach ($replacement as $key => $value) { |
|
203 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
204 | + } |
|
191 | 205 | |
192 | 206 | return implode(', ', $replacement); |
207 | + } else { |
|
208 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
193 | 209 | } |
194 | - else |
|
195 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
196 | 210 | break; |
197 | 211 | |
198 | 212 | case 'date': |
199 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
200 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
201 | - else |
|
202 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
213 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
214 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
215 | + } else { |
|
216 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
217 | + } |
|
203 | 218 | break; |
204 | 219 | |
205 | 220 | case 'time': |
206 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
207 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
208 | - else |
|
209 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
221 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
222 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
223 | + } else { |
|
224 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
225 | + } |
|
210 | 226 | break; |
211 | 227 | |
212 | 228 | case 'float': |
213 | - if (!is_numeric($replacement)) |
|
214 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
229 | + if (!is_numeric($replacement)) { |
|
230 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
231 | + } |
|
215 | 232 | return (string) (float) $replacement; |
216 | 233 | break; |
217 | 234 | |
@@ -224,31 +241,36 @@ discard block |
||
224 | 241 | break; |
225 | 242 | |
226 | 243 | case 'inet': |
227 | - if ($replacement == 'null' || $replacement == '') |
|
228 | - return 'null'; |
|
229 | - if (inet_pton($replacement) === false) |
|
230 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
244 | + if ($replacement == 'null' || $replacement == '') { |
|
245 | + return 'null'; |
|
246 | + } |
|
247 | + if (inet_pton($replacement) === false) { |
|
248 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
249 | + } |
|
231 | 250 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
232 | 251 | |
233 | 252 | case 'array_inet': |
234 | 253 | if (is_array($replacement)) |
235 | 254 | { |
236 | - if (empty($replacement)) |
|
237 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
255 | + if (empty($replacement)) { |
|
256 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
257 | + } |
|
238 | 258 | |
239 | 259 | foreach ($replacement as $key => $value) |
240 | 260 | { |
241 | - if ($replacement == 'null' || $replacement == '') |
|
242 | - $replacement[$key] = 'null'; |
|
243 | - if (!isValidIP($value)) |
|
244 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
261 | + if ($replacement == 'null' || $replacement == '') { |
|
262 | + $replacement[$key] = 'null'; |
|
263 | + } |
|
264 | + if (!isValidIP($value)) { |
|
265 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
266 | + } |
|
245 | 267 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
246 | 268 | } |
247 | 269 | |
248 | 270 | return implode(', ', $replacement); |
271 | + } else { |
|
272 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
249 | 273 | } |
250 | - else |
|
251 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
252 | 274 | break; |
253 | 275 | |
254 | 276 | default: |
@@ -335,14 +357,16 @@ discard block |
||
335 | 357 | ), |
336 | 358 | ); |
337 | 359 | |
338 | - if (isset($replacements[$identifier])) |
|
339 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
360 | + if (isset($replacements[$identifier])) { |
|
361 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
362 | + } |
|
340 | 363 | |
341 | 364 | // Limits need to be a little different. |
342 | 365 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
343 | 366 | |
344 | - if (trim($db_string) == '') |
|
345 | - return false; |
|
367 | + if (trim($db_string) == '') { |
|
368 | + return false; |
|
369 | + } |
|
346 | 370 | |
347 | 371 | // Comments that are allowed in a query are preg_removed. |
348 | 372 | static $allowed_comments_from = array( |
@@ -362,8 +386,9 @@ discard block |
||
362 | 386 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
363 | 387 | $db_replace_result = 0; |
364 | 388 | |
365 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
366 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
389 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
390 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
391 | + } |
|
367 | 392 | |
368 | 393 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
369 | 394 | { |
@@ -384,8 +409,9 @@ discard block |
||
384 | 409 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
385 | 410 | |
386 | 411 | // Initialize $db_cache if not already initialized. |
387 | - if (!isset($db_cache)) |
|
388 | - $db_cache = array(); |
|
412 | + if (!isset($db_cache)) { |
|
413 | + $db_cache = array(); |
|
414 | + } |
|
389 | 415 | |
390 | 416 | if (!empty($_SESSION['debug_redirect'])) |
391 | 417 | { |
@@ -411,17 +437,18 @@ discard block |
||
411 | 437 | while (true) |
412 | 438 | { |
413 | 439 | $pos = strpos($db_string, '\'', $pos + 1); |
414 | - if ($pos === false) |
|
415 | - break; |
|
440 | + if ($pos === false) { |
|
441 | + break; |
|
442 | + } |
|
416 | 443 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
417 | 444 | |
418 | 445 | while (true) |
419 | 446 | { |
420 | 447 | $pos1 = strpos($db_string, '\'', $pos + 1); |
421 | 448 | $pos2 = strpos($db_string, '\\', $pos + 1); |
422 | - if ($pos1 === false) |
|
423 | - break; |
|
424 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
449 | + if ($pos1 === false) { |
|
450 | + break; |
|
451 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
425 | 452 | { |
426 | 453 | $pos = $pos1; |
427 | 454 | break; |
@@ -437,26 +464,31 @@ discard block |
||
437 | 464 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
438 | 465 | |
439 | 466 | // Comments? We don't use comments in our queries, we leave 'em outside! |
440 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
441 | - $fail = true; |
|
467 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
468 | + $fail = true; |
|
469 | + } |
|
442 | 470 | // Trying to change passwords, slow us down, or something? |
443 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
444 | - $fail = true; |
|
445 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
446 | - $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 | + } |
|
447 | 476 | |
448 | - if (!empty($fail) && function_exists('log_error')) |
|
449 | - 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 | + } |
|
450 | 480 | } |
451 | 481 | |
452 | 482 | $db_last_result = @pg_query($connection, $db_string); |
453 | 483 | |
454 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
455 | - $db_last_result = smf_db_error($db_string, $connection); |
|
484 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
485 | + $db_last_result = smf_db_error($db_string, $connection); |
|
486 | + } |
|
456 | 487 | |
457 | 488 | // Debugging. |
458 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
459 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
489 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
490 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
491 | + } |
|
460 | 492 | |
461 | 493 | return $db_last_result; |
462 | 494 | } |
@@ -469,10 +501,11 @@ discard block |
||
469 | 501 | { |
470 | 502 | global $db_last_result, $db_replace_result; |
471 | 503 | |
472 | - if ($db_replace_result) |
|
473 | - return $db_replace_result; |
|
474 | - elseif ($result === null && !$db_last_result) |
|
475 | - return 0; |
|
504 | + if ($db_replace_result) { |
|
505 | + return $db_replace_result; |
|
506 | + } elseif ($result === null && !$db_last_result) { |
|
507 | + return 0; |
|
508 | + } |
|
476 | 509 | |
477 | 510 | return pg_affected_rows($result === null ? $db_last_result : $result); |
478 | 511 | } |
@@ -496,8 +529,9 @@ discard block |
||
496 | 529 | array( |
497 | 530 | ) |
498 | 531 | ); |
499 | - if (!$request) |
|
500 | - return false; |
|
532 | + if (!$request) { |
|
533 | + return false; |
|
534 | + } |
|
501 | 535 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
502 | 536 | $smcFunc['db_free_result']($request); |
503 | 537 | |
@@ -518,12 +552,13 @@ discard block |
||
518 | 552 | // Decide which connection to use |
519 | 553 | $connection = $connection === null ? $db_connection : $connection; |
520 | 554 | |
521 | - if ($type == 'begin') |
|
522 | - return @pg_query($connection, 'BEGIN'); |
|
523 | - elseif ($type == 'rollback') |
|
524 | - return @pg_query($connection, 'ROLLBACK'); |
|
525 | - elseif ($type == 'commit') |
|
526 | - return @pg_query($connection, 'COMMIT'); |
|
555 | + if ($type == 'begin') { |
|
556 | + return @pg_query($connection, 'BEGIN'); |
|
557 | + } elseif ($type == 'rollback') { |
|
558 | + return @pg_query($connection, 'ROLLBACK'); |
|
559 | + } elseif ($type == 'commit') { |
|
560 | + return @pg_query($connection, 'COMMIT'); |
|
561 | + } |
|
527 | 562 | |
528 | 563 | return false; |
529 | 564 | } |
@@ -551,19 +586,22 @@ discard block |
||
551 | 586 | $query_error = @pg_last_error($connection); |
552 | 587 | |
553 | 588 | // Log the error. |
554 | - if (function_exists('log_error')) |
|
555 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
589 | + if (function_exists('log_error')) { |
|
590 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
591 | + } |
|
556 | 592 | |
557 | 593 | // Nothing's defined yet... just die with it. |
558 | - if (empty($context) || empty($txt)) |
|
559 | - die($query_error); |
|
594 | + if (empty($context) || empty($txt)) { |
|
595 | + die($query_error); |
|
596 | + } |
|
560 | 597 | |
561 | 598 | // Show an error message, if possible. |
562 | 599 | $context['error_title'] = $txt['database_error']; |
563 | - if (allowedTo('admin_forum')) |
|
564 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
565 | - else |
|
566 | - $context['error_message'] = $txt['try_again']; |
|
600 | + if (allowedTo('admin_forum')) { |
|
601 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
602 | + } else { |
|
603 | + $context['error_message'] = $txt['try_again']; |
|
604 | + } |
|
567 | 605 | |
568 | 606 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
569 | 607 | { |
@@ -585,12 +623,14 @@ discard block |
||
585 | 623 | { |
586 | 624 | global $db_row_count; |
587 | 625 | |
588 | - if ($counter !== false) |
|
589 | - return pg_fetch_row($request, $counter); |
|
626 | + if ($counter !== false) { |
|
627 | + return pg_fetch_row($request, $counter); |
|
628 | + } |
|
590 | 629 | |
591 | 630 | // Reset the row counter... |
592 | - if (!isset($db_row_count[(int) $request])) |
|
593 | - $db_row_count[(int) $request] = 0; |
|
631 | + if (!isset($db_row_count[(int) $request])) { |
|
632 | + $db_row_count[(int) $request] = 0; |
|
633 | + } |
|
594 | 634 | |
595 | 635 | // Return the right row. |
596 | 636 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -607,12 +647,14 @@ discard block |
||
607 | 647 | { |
608 | 648 | global $db_row_count; |
609 | 649 | |
610 | - if ($counter !== false) |
|
611 | - return pg_fetch_assoc($request, $counter); |
|
650 | + if ($counter !== false) { |
|
651 | + return pg_fetch_assoc($request, $counter); |
|
652 | + } |
|
612 | 653 | |
613 | 654 | // Reset the row counter... |
614 | - if (!isset($db_row_count[(int) $request])) |
|
615 | - $db_row_count[(int) $request] = 0; |
|
655 | + if (!isset($db_row_count[(int) $request])) { |
|
656 | + $db_row_count[(int) $request] = 0; |
|
657 | + } |
|
616 | 658 | |
617 | 659 | // Return the right row. |
618 | 660 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -665,11 +707,13 @@ discard block |
||
665 | 707 | |
666 | 708 | $replace = ''; |
667 | 709 | |
668 | - if (empty($data)) |
|
669 | - return; |
|
710 | + if (empty($data)) { |
|
711 | + return; |
|
712 | + } |
|
670 | 713 | |
671 | - if (!is_array($data[array_rand($data)])) |
|
672 | - $data = array($data); |
|
714 | + if (!is_array($data[array_rand($data)])) { |
|
715 | + $data = array($data); |
|
716 | + } |
|
673 | 717 | |
674 | 718 | // Replace the prefix holder with the actual prefix. |
675 | 719 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -688,11 +732,13 @@ discard block |
||
688 | 732 | //pg 9.5 got replace support |
689 | 733 | $pg_version = $smcFunc['db_get_version'](); |
690 | 734 | // if we got a Beta Version |
691 | - if (stripos($pg_version, 'beta') !== false) |
|
692 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
735 | + if (stripos($pg_version, 'beta') !== false) { |
|
736 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
737 | + } |
|
693 | 738 | // or RC |
694 | - if (stripos($pg_version, 'rc') !== false) |
|
695 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
739 | + if (stripos($pg_version, 'rc') !== false) { |
|
740 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
741 | + } |
|
696 | 742 | |
697 | 743 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
698 | 744 | } |
@@ -711,8 +757,7 @@ discard block |
||
711 | 757 | $key_str .= ($count_pk > 0 ? ',' : ''); |
712 | 758 | $key_str .= $columnName; |
713 | 759 | $count_pk++; |
714 | - } |
|
715 | - else //normal field |
|
760 | + } else //normal field |
|
716 | 761 | { |
717 | 762 | $col_str .= ($count > 0 ? ',' : ''); |
718 | 763 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
@@ -720,20 +765,21 @@ discard block |
||
720 | 765 | } |
721 | 766 | } |
722 | 767 | $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
723 | - } |
|
724 | - else |
|
768 | + } else |
|
725 | 769 | { |
726 | 770 | foreach ($columns as $columnName => $type) |
727 | 771 | { |
728 | 772 | // Are we restricting the length? |
729 | - if (strpos($type, 'string-') !== false) |
|
730 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
731 | - else |
|
732 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
773 | + if (strpos($type, 'string-') !== false) { |
|
774 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
775 | + } else { |
|
776 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
777 | + } |
|
733 | 778 | |
734 | 779 | // A key? That's what we were looking for. |
735 | - if (in_array($columnName, $keys)) |
|
736 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
780 | + if (in_array($columnName, $keys)) { |
|
781 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
782 | + } |
|
737 | 783 | $count++; |
738 | 784 | } |
739 | 785 | |
@@ -769,10 +815,11 @@ discard block |
||
769 | 815 | foreach ($columns as $columnName => $type) |
770 | 816 | { |
771 | 817 | // Are we restricting the length? |
772 | - if (strpos($type, 'string-') !== false) |
|
773 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
774 | - else |
|
775 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
818 | + if (strpos($type, 'string-') !== false) { |
|
819 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
820 | + } else { |
|
821 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
822 | + } |
|
776 | 823 | } |
777 | 824 | $insertData = substr($insertData, 0, -2) . ')'; |
778 | 825 | |
@@ -781,8 +828,9 @@ discard block |
||
781 | 828 | |
782 | 829 | // Here's where the variables are injected to the query. |
783 | 830 | $insertRows = array(); |
784 | - foreach ($data as $dataRow) |
|
785 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
831 | + foreach ($data as $dataRow) { |
|
832 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
833 | + } |
|
786 | 834 | |
787 | 835 | // Do the insert. |
788 | 836 | $request = $smcFunc['db_query']('', ' |
@@ -799,19 +847,21 @@ discard block |
||
799 | 847 | |
800 | 848 | if ($with_returning && $request !== false) |
801 | 849 | { |
802 | - if ($returnmode === 2) |
|
803 | - $return_var = array(); |
|
850 | + if ($returnmode === 2) { |
|
851 | + $return_var = array(); |
|
852 | + } |
|
804 | 853 | |
805 | 854 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
806 | 855 | { |
807 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
856 | + if (is_numeric($row[0])) { |
|
857 | + // try to emulate mysql limitation |
|
808 | 858 | { |
809 | 859 | if ($returnmode === 1) |
810 | 860 | $return_var = $row[0]; |
811 | - elseif ($returnmode === 2) |
|
812 | - $return_var[] = $row[0]; |
|
813 | - } |
|
814 | - else |
|
861 | + } elseif ($returnmode === 2) { |
|
862 | + $return_var[] = $row[0]; |
|
863 | + } |
|
864 | + } else |
|
815 | 865 | { |
816 | 866 | $with_returning = false; |
817 | 867 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -820,9 +870,10 @@ discard block |
||
820 | 870 | } |
821 | 871 | } |
822 | 872 | |
823 | - if ($with_returning && !empty($return_var)) |
|
824 | - return $return_var; |
|
825 | -} |
|
873 | + if ($with_returning && !empty($return_var)) { |
|
874 | + return $return_var; |
|
875 | + } |
|
876 | + } |
|
826 | 877 | |
827 | 878 | /** |
828 | 879 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -859,8 +910,9 @@ discard block |
||
859 | 910 | */ |
860 | 911 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
861 | 912 | { |
862 | - if (empty($log_message)) |
|
863 | - $log_message = $error_message; |
|
913 | + if (empty($log_message)) { |
|
914 | + $log_message = $error_message; |
|
915 | + } |
|
864 | 916 | |
865 | 917 | foreach (debug_backtrace() as $step) |
866 | 918 | { |
@@ -879,12 +931,14 @@ discard block |
||
879 | 931 | } |
880 | 932 | |
881 | 933 | // A special case - we want the file and line numbers for debugging. |
882 | - if ($error_type == 'return') |
|
883 | - return array($file, $line); |
|
934 | + if ($error_type == 'return') { |
|
935 | + return array($file, $line); |
|
936 | + } |
|
884 | 937 | |
885 | 938 | // Is always a critical error. |
886 | - if (function_exists('log_error')) |
|
887 | - log_error($log_message, 'critical', $file, $line); |
|
939 | + if (function_exists('log_error')) { |
|
940 | + log_error($log_message, 'critical', $file, $line); |
|
941 | + } |
|
888 | 942 | |
889 | 943 | if (function_exists('fatal_error')) |
890 | 944 | { |
@@ -892,12 +946,12 @@ discard block |
||
892 | 946 | |
893 | 947 | // Cannot continue... |
894 | 948 | exit; |
949 | + } elseif ($error_type) { |
|
950 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
951 | + } else { |
|
952 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
953 | + } |
|
895 | 954 | } |
896 | - elseif ($error_type) |
|
897 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
898 | - else |
|
899 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
900 | -} |
|
901 | 955 | |
902 | 956 | /** |
903 | 957 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -914,10 +968,11 @@ discard block |
||
914 | 968 | '\\' => '\\\\', |
915 | 969 | ); |
916 | 970 | |
917 | - if ($translate_human_wildcards) |
|
918 | - $replacements += array( |
|
971 | + if ($translate_human_wildcards) { |
|
972 | + $replacements += array( |
|
919 | 973 | '*' => '%', |
920 | 974 | ); |
975 | + } |
|
921 | 976 | |
922 | 977 | return strtr($string, $replacements); |
923 | 978 | } |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
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 current directory is still valid or not. |
@@ -28,22 +29,24 @@ discard block |
||
28 | 29 | global $boarddir, $modSettings, $context; |
29 | 30 | |
30 | 31 | // Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found. |
31 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') |
|
32 | - $doit = true; |
|
33 | - elseif (empty($modSettings['automanage_attachments'])) |
|
34 | - return; |
|
35 | - elseif (!isset($_FILES)) |
|
36 | - return; |
|
37 | - elseif (isset($_FILES['attachment'])) |
|
38 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
32 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') { |
|
33 | + $doit = true; |
|
34 | + } elseif (empty($modSettings['automanage_attachments'])) { |
|
35 | + return; |
|
36 | + } elseif (!isset($_FILES)) { |
|
37 | + return; |
|
38 | + } elseif (isset($_FILES['attachment'])) { |
|
39 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
39 | 40 | if (!empty($dummy)) |
40 | 41 | { |
41 | 42 | $doit = true; |
43 | + } |
|
42 | 44 | break; |
43 | 45 | } |
44 | 46 | |
45 | - if (!isset($doit)) |
|
46 | - return; |
|
47 | + if (!isset($doit)) { |
|
48 | + return; |
|
49 | + } |
|
47 | 50 | |
48 | 51 | $year = date('Y'); |
49 | 52 | $month = date('m'); |
@@ -54,21 +57,25 @@ discard block |
||
54 | 57 | |
55 | 58 | if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments'])) |
56 | 59 | { |
57 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
58 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
60 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
61 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
62 | + } |
|
59 | 63 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
64 | + } else { |
|
65 | + $base_dir = 0; |
|
60 | 66 | } |
61 | - else |
|
62 | - $base_dir = 0; |
|
63 | 67 | |
64 | 68 | if ($modSettings['automanage_attachments'] == 1) |
65 | 69 | { |
66 | - if (!isset($modSettings['last_attachments_directory'])) |
|
67 | - $modSettings['last_attachments_directory'] = array(); |
|
68 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
69 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
70 | - if (!isset($modSettings['last_attachments_directory'][$base_dir])) |
|
71 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
70 | + if (!isset($modSettings['last_attachments_directory'])) { |
|
71 | + $modSettings['last_attachments_directory'] = array(); |
|
72 | + } |
|
73 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
74 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
75 | + } |
|
76 | + if (!isset($modSettings['last_attachments_directory'][$base_dir])) { |
|
77 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
78 | + } |
|
72 | 79 | } |
73 | 80 | |
74 | 81 | $basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
@@ -97,12 +104,14 @@ discard block |
||
97 | 104 | $updir = ''; |
98 | 105 | } |
99 | 106 | |
100 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
101 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
102 | - if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) |
|
103 | - $outputCreation = automanage_attachments_create_directory($updir); |
|
104 | - elseif (in_array($updir, $modSettings['attachmentUploadDir'])) |
|
105 | - $outputCreation = true; |
|
107 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
108 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
109 | + } |
|
110 | + if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) { |
|
111 | + $outputCreation = automanage_attachments_create_directory($updir); |
|
112 | + } elseif (in_array($updir, $modSettings['attachmentUploadDir'])) { |
|
113 | + $outputCreation = true; |
|
114 | + } |
|
106 | 115 | |
107 | 116 | if ($outputCreation) |
108 | 117 | { |
@@ -139,8 +148,9 @@ discard block |
||
139 | 148 | $count = count($tree); |
140 | 149 | |
141 | 150 | $directory = attachments_init_dir($tree, $count); |
142 | - if ($directory === false) |
|
143 | - return false; |
|
151 | + if ($directory === false) { |
|
152 | + return false; |
|
153 | + } |
|
144 | 154 | } |
145 | 155 | |
146 | 156 | $directory .= DIRECTORY_SEPARATOR . array_shift($tree); |
@@ -168,8 +178,9 @@ discard block |
||
168 | 178 | } |
169 | 179 | |
170 | 180 | // Everything seems fine...let's create the .htaccess |
171 | - if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) |
|
172 | - secureDirectory($updir, true); |
|
181 | + if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) { |
|
182 | + secureDirectory($updir, true); |
|
183 | + } |
|
173 | 184 | |
174 | 185 | $sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR; |
175 | 186 | $updir = rtrim($updir, $sep); |
@@ -201,8 +212,9 @@ discard block |
||
201 | 212 | { |
202 | 213 | global $modSettings, $boarddir; |
203 | 214 | |
204 | - if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) |
|
205 | - return; |
|
215 | + if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) { |
|
216 | + return; |
|
217 | + } |
|
206 | 218 | |
207 | 219 | $basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir; |
208 | 220 | // Just to be sure: I don't want directory separators at the end |
@@ -214,13 +226,14 @@ discard block |
||
214 | 226 | { |
215 | 227 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
216 | 228 | $base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0; |
229 | + } else { |
|
230 | + $base_dir = 0; |
|
217 | 231 | } |
218 | - else |
|
219 | - $base_dir = 0; |
|
220 | 232 | |
221 | 233 | // Get the last attachment directory for that base directory |
222 | - if (empty($modSettings['last_attachments_directory'][$base_dir])) |
|
223 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
234 | + if (empty($modSettings['last_attachments_directory'][$base_dir])) { |
|
235 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
236 | + } |
|
224 | 237 | // And increment it. |
225 | 238 | $modSettings['last_attachments_directory'][$base_dir]++; |
226 | 239 | |
@@ -235,10 +248,10 @@ discard block |
||
235 | 248 | $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
236 | 249 | |
237 | 250 | return true; |
251 | + } else { |
|
252 | + return false; |
|
253 | + } |
|
238 | 254 | } |
239 | - else |
|
240 | - return false; |
|
241 | -} |
|
242 | 255 | |
243 | 256 | /** |
244 | 257 | * Split a path into a list of all directories and subdirectories |
@@ -256,12 +269,13 @@ discard block |
||
256 | 269 | * in Windows we need to explode for both \ and / |
257 | 270 | * while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR) |
258 | 271 | */ |
259 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
260 | - $tree = preg_split('#[\\\/]#', $directory); |
|
261 | - else |
|
272 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
273 | + $tree = preg_split('#[\\\/]#', $directory); |
|
274 | + } else |
|
262 | 275 | { |
263 | - if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) |
|
264 | - return false; |
|
276 | + if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { |
|
277 | + return false; |
|
278 | + } |
|
265 | 279 | |
266 | 280 | $tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR)); |
267 | 281 | } |
@@ -285,10 +299,11 @@ discard block |
||
285 | 299 | //Better be sure that the first part of the path is actually a drive letter... |
286 | 300 | //...even if, I should check this in the admin page...isn't it? |
287 | 301 | //...NHAAA Let's leave space for users' complains! :P |
288 | - if (preg_match('/^[a-z]:$/i', $tree[0])) |
|
289 | - $directory = array_shift($tree); |
|
290 | - else |
|
291 | - return false; |
|
302 | + if (preg_match('/^[a-z]:$/i', $tree[0])) { |
|
303 | + $directory = array_shift($tree); |
|
304 | + } else { |
|
305 | + return false; |
|
306 | + } |
|
292 | 307 | |
293 | 308 | $count--; |
294 | 309 | } |
@@ -303,18 +318,20 @@ discard block |
||
303 | 318 | global $context, $modSettings, $smcFunc, $txt, $user_info; |
304 | 319 | |
305 | 320 | // Make sure we're uploading to the right place. |
306 | - if (!empty($modSettings['automanage_attachments'])) |
|
307 | - automanage_attachments_check_directory(); |
|
321 | + if (!empty($modSettings['automanage_attachments'])) { |
|
322 | + automanage_attachments_check_directory(); |
|
323 | + } |
|
308 | 324 | |
309 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
310 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
325 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
326 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
327 | + } |
|
311 | 328 | |
312 | 329 | $context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
313 | 330 | |
314 | 331 | // Is the attachments folder actualy there? |
315 | - if (!empty($context['dir_creation_error'])) |
|
316 | - $initial_error = $context['dir_creation_error']; |
|
317 | - elseif (!is_dir($context['attach_dir'])) |
|
332 | + if (!empty($context['dir_creation_error'])) { |
|
333 | + $initial_error = $context['dir_creation_error']; |
|
334 | + } elseif (!is_dir($context['attach_dir'])) |
|
318 | 335 | { |
319 | 336 | $initial_error = 'attach_folder_warning'; |
320 | 337 | log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical'); |
@@ -337,12 +354,12 @@ discard block |
||
337 | 354 | ); |
338 | 355 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
339 | 356 | $smcFunc['db_free_result']($request); |
340 | - } |
|
341 | - else |
|
342 | - $context['attachments'] = array( |
|
357 | + } else { |
|
358 | + $context['attachments'] = array( |
|
343 | 359 | 'quantity' => 0, |
344 | 360 | 'total_size' => 0, |
345 | 361 | ); |
362 | + } |
|
346 | 363 | } |
347 | 364 | |
348 | 365 | // Hmm. There are still files in session. |
@@ -352,39 +369,44 @@ discard block |
||
352 | 369 | // Let's try to keep them. But... |
353 | 370 | $ignore_temp = true; |
354 | 371 | // If new files are being added. We can't ignore those |
355 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
356 | - if (!empty($dummy)) |
|
372 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) { |
|
373 | + if (!empty($dummy)) |
|
357 | 374 | { |
358 | 375 | $ignore_temp = false; |
376 | + } |
|
359 | 377 | break; |
360 | 378 | } |
361 | 379 | |
362 | 380 | // Need to make space for the new files. So, bye bye. |
363 | 381 | if (!$ignore_temp) |
364 | 382 | { |
365 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
366 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
383 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
384 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
367 | 385 | unlink($attachment['tmp_name']); |
386 | + } |
|
368 | 387 | |
369 | 388 | $context['we_are_history'] = $txt['error_temp_attachments_flushed']; |
370 | 389 | $_SESSION['temp_attachments'] = array(); |
371 | 390 | } |
372 | 391 | } |
373 | 392 | |
374 | - if (!isset($_FILES['attachment']['name'])) |
|
375 | - $_FILES['attachment']['tmp_name'] = array(); |
|
393 | + if (!isset($_FILES['attachment']['name'])) { |
|
394 | + $_FILES['attachment']['tmp_name'] = array(); |
|
395 | + } |
|
376 | 396 | |
377 | - if (!isset($_SESSION['temp_attachments'])) |
|
378 | - $_SESSION['temp_attachments'] = array(); |
|
397 | + if (!isset($_SESSION['temp_attachments'])) { |
|
398 | + $_SESSION['temp_attachments'] = array(); |
|
399 | + } |
|
379 | 400 | |
380 | 401 | // Remember where we are at. If it's anywhere at all. |
381 | - if (!$ignore_temp) |
|
382 | - $_SESSION['temp_attachments']['post'] = array( |
|
402 | + if (!$ignore_temp) { |
|
403 | + $_SESSION['temp_attachments']['post'] = array( |
|
383 | 404 | 'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0, |
384 | 405 | 'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0, |
385 | 406 | 'topic' => !empty($topic) ? $topic : 0, |
386 | 407 | 'board' => !empty($board) ? $board : 0, |
387 | 408 | ); |
409 | + } |
|
388 | 410 | |
389 | 411 | // If we have an initial error, lets just display it. |
390 | 412 | if (!empty($initial_error)) |
@@ -392,9 +414,10 @@ discard block |
||
392 | 414 | $_SESSION['temp_attachments']['initial_error'] = $initial_error; |
393 | 415 | |
394 | 416 | // And delete the files 'cos they ain't going nowhere. |
395 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
396 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
417 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
418 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
397 | 419 | unlink($_FILES['attachment']['tmp_name'][$n]); |
420 | + } |
|
398 | 421 | |
399 | 422 | $_FILES['attachment']['tmp_name'] = array(); |
400 | 423 | } |
@@ -402,21 +425,24 @@ discard block |
||
402 | 425 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
403 | 426 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
404 | 427 | { |
405 | - if ($_FILES['attachment']['name'][$n] == '') |
|
406 | - continue; |
|
428 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
429 | + continue; |
|
430 | + } |
|
407 | 431 | |
408 | 432 | // First, let's first check for PHP upload errors. |
409 | 433 | $errors = array(); |
410 | 434 | if (!empty($_FILES['attachment']['error'][$n])) |
411 | 435 | { |
412 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
413 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
414 | - elseif ($_FILES['attachment']['error'][$n] == 6) |
|
415 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
416 | - else |
|
417 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
418 | - if (empty($errors)) |
|
419 | - $errors[] = 'attach_php_error'; |
|
436 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
437 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
438 | + } elseif ($_FILES['attachment']['error'][$n] == 6) { |
|
439 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
440 | + } else { |
|
441 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
442 | + } |
|
443 | + if (empty($errors)) { |
|
444 | + $errors[] = 'attach_php_error'; |
|
445 | + } |
|
420 | 446 | } |
421 | 447 | |
422 | 448 | // Try to move and rename the file before doing any more checks on it. |
@@ -426,8 +452,9 @@ discard block |
||
426 | 452 | { |
427 | 453 | // The reported MIME type of the attachment might not be reliable. |
428 | 454 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
429 | - if (function_exists('mime_content_type')) |
|
430 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
455 | + if (function_exists('mime_content_type')) { |
|
456 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
457 | + } |
|
431 | 458 | |
432 | 459 | $_SESSION['temp_attachments'][$attachID] = array( |
433 | 460 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -439,16 +466,16 @@ discard block |
||
439 | 466 | ); |
440 | 467 | |
441 | 468 | // Move the file to the attachments folder with a temp name for now. |
442 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
443 | - smf_chmod($destName, 0644); |
|
444 | - else |
|
469 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
470 | + smf_chmod($destName, 0644); |
|
471 | + } else |
|
445 | 472 | { |
446 | 473 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
447 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
448 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
474 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
475 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
476 | + } |
|
449 | 477 | } |
450 | - } |
|
451 | - else |
|
478 | + } else |
|
452 | 479 | { |
453 | 480 | $_SESSION['temp_attachments'][$attachID] = array( |
454 | 481 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -456,12 +483,14 @@ discard block |
||
456 | 483 | 'errors' => $errors, |
457 | 484 | ); |
458 | 485 | |
459 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
460 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
486 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
487 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
488 | + } |
|
461 | 489 | } |
462 | 490 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
463 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
464 | - attachmentChecks($attachID); |
|
491 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
492 | + attachmentChecks($attachID); |
|
493 | + } |
|
465 | 494 | } |
466 | 495 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
467 | 496 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
@@ -488,21 +517,20 @@ discard block |
||
488 | 517 | global $modSettings, $context, $sourcedir, $smcFunc; |
489 | 518 | |
490 | 519 | // No data or missing data .... Not necessarily needed, but in case a mod author missed something. |
491 | - if (empty($_SESSION['temp_attachments'][$attachID])) |
|
492 | - $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
493 | - |
|
494 | - elseif (empty($attachID)) |
|
495 | - $error = '$attachID'; |
|
496 | - |
|
497 | - elseif (empty($context['attachments'])) |
|
498 | - $error = '$context[\'attachments\']'; |
|
499 | - |
|
500 | - elseif (empty($context['attach_dir'])) |
|
501 | - $error = '$context[\'attach_dir\']'; |
|
520 | + if (empty($_SESSION['temp_attachments'][$attachID])) { |
|
521 | + $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
522 | + } elseif (empty($attachID)) { |
|
523 | + $error = '$attachID'; |
|
524 | + } elseif (empty($context['attachments'])) { |
|
525 | + $error = '$context[\'attachments\']'; |
|
526 | + } elseif (empty($context['attach_dir'])) { |
|
527 | + $error = '$context[\'attach_dir\']'; |
|
528 | + } |
|
502 | 529 | |
503 | 530 | // Let's get their attention. |
504 | - if (!empty($error)) |
|
505 | - fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
531 | + if (!empty($error)) { |
|
532 | + fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
533 | + } |
|
506 | 534 | |
507 | 535 | // Just in case this slipped by the first checks, we stop it here and now |
508 | 536 | if ($_SESSION['temp_attachments'][$attachID]['size'] == 0) |
@@ -531,8 +559,9 @@ discard block |
||
531 | 559 | $size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']); |
532 | 560 | if (!(empty($size)) && ($size[2] != $old_format)) |
533 | 561 | { |
534 | - if (isset($context['validImageTypes'][$size[2]])) |
|
535 | - $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
562 | + if (isset($context['validImageTypes'][$size[2]])) { |
|
563 | + $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
564 | + } |
|
536 | 565 | } |
537 | 566 | } |
538 | 567 | } |
@@ -586,42 +615,48 @@ discard block |
||
586 | 615 | // Or, let the user know that it ain't gonna happen. |
587 | 616 | else |
588 | 617 | { |
589 | - if (isset($context['dir_creation_error'])) |
|
590 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
591 | - else |
|
592 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
618 | + if (isset($context['dir_creation_error'])) { |
|
619 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
620 | + } else { |
|
621 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
622 | + } |
|
593 | 623 | } |
624 | + } else { |
|
625 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
594 | 626 | } |
595 | - else |
|
596 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
597 | 627 | } |
598 | 628 | } |
599 | 629 | |
600 | 630 | // Is the file too big? |
601 | 631 | $context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size']; |
602 | - if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) |
|
603 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
632 | + if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) { |
|
633 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
634 | + } |
|
604 | 635 | |
605 | 636 | // Check the total upload size for this post... |
606 | - if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) |
|
607 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
637 | + if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) { |
|
638 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
639 | + } |
|
608 | 640 | |
609 | 641 | // Have we reached the maximum number of files we are allowed? |
610 | 642 | $context['attachments']['quantity']++; |
611 | 643 | |
612 | 644 | // Set a max limit if none exists |
613 | - if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) |
|
614 | - $modSettings['attachmentNumPerPostLimit'] = 50; |
|
645 | + if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) { |
|
646 | + $modSettings['attachmentNumPerPostLimit'] = 50; |
|
647 | + } |
|
615 | 648 | |
616 | - if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) |
|
617 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
649 | + if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) { |
|
650 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
651 | + } |
|
618 | 652 | |
619 | 653 | // File extension check |
620 | 654 | if (!empty($modSettings['attachmentCheckExtensions'])) |
621 | 655 | { |
622 | 656 | $allowed = explode(',', strtolower($modSettings['attachmentExtensions'])); |
623 | - foreach ($allowed as $k => $dummy) |
|
624 | - $allowed[$k] = trim($dummy); |
|
657 | + foreach ($allowed as $k => $dummy) { |
|
658 | + $allowed[$k] = trim($dummy); |
|
659 | + } |
|
625 | 660 | |
626 | 661 | if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) |
627 | 662 | { |
@@ -633,10 +668,12 @@ discard block |
||
633 | 668 | // Undo the math if there's an error |
634 | 669 | if (!empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
635 | 670 | { |
636 | - if (isset($context['dir_size'])) |
|
637 | - $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
638 | - if (isset($context['dir_files'])) |
|
639 | - $context['dir_files']--; |
|
671 | + if (isset($context['dir_size'])) { |
|
672 | + $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
673 | + } |
|
674 | + if (isset($context['dir_files'])) { |
|
675 | + $context['dir_files']--; |
|
676 | + } |
|
640 | 677 | $context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
641 | 678 | $context['attachments']['quantity']--; |
642 | 679 | return false; |
@@ -668,12 +705,14 @@ discard block |
||
668 | 705 | if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) |
669 | 706 | { |
670 | 707 | // Got a proper mime type? |
671 | - if (!empty($size['mime'])) |
|
672 | - $attachmentOptions['mime_type'] = $size['mime']; |
|
708 | + if (!empty($size['mime'])) { |
|
709 | + $attachmentOptions['mime_type'] = $size['mime']; |
|
710 | + } |
|
673 | 711 | |
674 | 712 | // Otherwise a valid one? |
675 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
676 | - $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
713 | + elseif (isset($context['validImageTypes'][$size[2]])) { |
|
714 | + $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
715 | + } |
|
677 | 716 | } |
678 | 717 | |
679 | 718 | // It is possible we might have a MIME type that isn't actually an image but still have a size. |
@@ -685,15 +724,17 @@ discard block |
||
685 | 724 | } |
686 | 725 | |
687 | 726 | // Get the hash if no hash has been given yet. |
688 | - if (empty($attachmentOptions['file_hash'])) |
|
689 | - $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
727 | + if (empty($attachmentOptions['file_hash'])) { |
|
728 | + $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
729 | + } |
|
690 | 730 | |
691 | 731 | // Assuming no-one set the extension let's take a look at it. |
692 | 732 | if (empty($attachmentOptions['fileext'])) |
693 | 733 | { |
694 | 734 | $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : ''); |
695 | - if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) |
|
696 | - $attachmentOptions['fileext'] = ''; |
|
735 | + if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) { |
|
736 | + $attachmentOptions['fileext'] = ''; |
|
737 | + } |
|
697 | 738 | } |
698 | 739 | |
699 | 740 | // Last chance to change stuff! |
@@ -702,8 +743,9 @@ discard block |
||
702 | 743 | // Make sure the folder is valid... |
703 | 744 | $tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true); |
704 | 745 | $folders = array_keys($tmp); |
705 | - if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) |
|
706 | - $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
746 | + if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) { |
|
747 | + $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
748 | + } |
|
707 | 749 | |
708 | 750 | $attachmentOptions['id'] = $smcFunc['db_insert']('', |
709 | 751 | '{db_prefix}attachments', |
@@ -734,8 +776,8 @@ discard block |
||
734 | 776 | rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']); |
735 | 777 | |
736 | 778 | // If it's not approved then add to the approval queue. |
737 | - if (!$attachmentOptions['approved']) |
|
738 | - $smcFunc['db_insert']('', |
|
779 | + if (!$attachmentOptions['approved']) { |
|
780 | + $smcFunc['db_insert']('', |
|
739 | 781 | '{db_prefix}approval_queue', |
740 | 782 | array( |
741 | 783 | 'id_attach' => 'int', 'id_msg' => 'int', |
@@ -745,9 +787,11 @@ discard block |
||
745 | 787 | ), |
746 | 788 | array() |
747 | 789 | ); |
790 | + } |
|
748 | 791 | |
749 | - if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) |
|
750 | - return true; |
|
792 | + if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) { |
|
793 | + return true; |
|
794 | + } |
|
751 | 795 | |
752 | 796 | // Like thumbnails, do we? |
753 | 797 | if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) |
@@ -758,13 +802,15 @@ discard block |
||
758 | 802 | $size = @getimagesize($attachmentOptions['destination'] . '_thumb'); |
759 | 803 | list ($thumb_width, $thumb_height) = $size; |
760 | 804 | |
761 | - if (!empty($size['mime'])) |
|
762 | - $thumb_mime = $size['mime']; |
|
763 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
764 | - $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
805 | + if (!empty($size['mime'])) { |
|
806 | + $thumb_mime = $size['mime']; |
|
807 | + } elseif (isset($context['validImageTypes'][$size[2]])) { |
|
808 | + $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
809 | + } |
|
765 | 810 | // Lord only knows how this happened... |
766 | - else |
|
767 | - $thumb_mime = ''; |
|
811 | + else { |
|
812 | + $thumb_mime = ''; |
|
813 | + } |
|
768 | 814 | |
769 | 815 | $thumb_filename = $attachmentOptions['name'] . '_thumb'; |
770 | 816 | $thumb_size = filesize($attachmentOptions['destination'] . '_thumb'); |
@@ -844,15 +890,17 @@ discard block |
||
844 | 890 | global $smcFunc; |
845 | 891 | |
846 | 892 | // Oh, come on! |
847 | - if (empty($attachIDs) || empty($msgID)) |
|
848 | - return false; |
|
893 | + if (empty($attachIDs) || empty($msgID)) { |
|
894 | + return false; |
|
895 | + } |
|
849 | 896 | |
850 | 897 | // "I see what is right and approve, but I do what is wrong." |
851 | 898 | call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID)); |
852 | 899 | |
853 | 900 | // One last check |
854 | - if (empty($attachIDs)) |
|
855 | - return false; |
|
901 | + if (empty($attachIDs)) { |
|
902 | + return false; |
|
903 | + } |
|
856 | 904 | |
857 | 905 | // Perform. |
858 | 906 | $smcFunc['db_query']('', ' |
@@ -882,8 +930,9 @@ discard block |
||
882 | 930 | $externalParse = false; |
883 | 931 | |
884 | 932 | // Meh... |
885 | - if (empty($attachID)) |
|
886 | - return 'attachments_no_data_loaded'; |
|
933 | + if (empty($attachID)) { |
|
934 | + return 'attachments_no_data_loaded'; |
|
935 | + } |
|
887 | 936 | |
888 | 937 | // Make it easy. |
889 | 938 | $msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0; |
@@ -892,20 +941,23 @@ discard block |
||
892 | 941 | $externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID)); |
893 | 942 | |
894 | 943 | // "I am innocent of the blood of this just person: see ye to it." |
895 | - if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) |
|
896 | - return $externalParse; |
|
944 | + if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) { |
|
945 | + return $externalParse; |
|
946 | + } |
|
897 | 947 | |
898 | 948 | //Are attachments enable? |
899 | - if (empty($modSettings['attachmentEnable'])) |
|
900 | - return 'attachments_not_enable'; |
|
949 | + if (empty($modSettings['attachmentEnable'])) { |
|
950 | + return 'attachments_not_enable'; |
|
951 | + } |
|
901 | 952 | |
902 | 953 | // Previewing much? no msg ID has been set yet. |
903 | 954 | if (!empty($context['preview_message'])) |
904 | 955 | { |
905 | 956 | $allAttachments = getAttachsByMsg(0); |
906 | 957 | |
907 | - if (empty($allAttachments[0][$attachID])) |
|
908 | - return 'attachments_no_data_loaded'; |
|
958 | + if (empty($allAttachments[0][$attachID])) { |
|
959 | + return 'attachments_no_data_loaded'; |
|
960 | + } |
|
909 | 961 | |
910 | 962 | $attachLoaded = loadAttachmentContext(0, $allAttachments); |
911 | 963 | |
@@ -917,57 +969,66 @@ discard block |
||
917 | 969 | $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
918 | 970 | |
919 | 971 | // Fix the thumbnail too, if the image has one. |
920 | - if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) |
|
921 | - $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
972 | + if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) { |
|
973 | + $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
974 | + } |
|
922 | 975 | |
923 | 976 | return $attachContext; |
924 | 977 | } |
925 | 978 | |
926 | 979 | // There is always the chance someone else has already done our dirty work... |
927 | 980 | // If so, all pertinent checks were already done. Hopefully... |
928 | - if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) |
|
929 | - return $context['current_attachments'][$attachID]; |
|
981 | + if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) { |
|
982 | + return $context['current_attachments'][$attachID]; |
|
983 | + } |
|
930 | 984 | |
931 | 985 | // If we are lucky enough to be in $board's scope then check it! |
932 | - if (!empty($board) && !allowedTo('view_attachments', $board)) |
|
933 | - return 'attachments_not_allowed_to_see'; |
|
986 | + if (!empty($board) && !allowedTo('view_attachments', $board)) { |
|
987 | + return 'attachments_not_allowed_to_see'; |
|
988 | + } |
|
934 | 989 | |
935 | 990 | // Get the message info associated with this particular attach ID. |
936 | 991 | $attachInfo = getAttachMsgInfo($attachID); |
937 | 992 | |
938 | 993 | // There is always the chance this attachment no longer exists or isn't associated to a message anymore... |
939 | - if (empty($attachInfo) || empty($attachInfo['msg'])) |
|
940 | - return 'attachments_no_msg_associated'; |
|
994 | + if (empty($attachInfo) || empty($attachInfo['msg'])) { |
|
995 | + return 'attachments_no_msg_associated'; |
|
996 | + } |
|
941 | 997 | |
942 | 998 | // Hold it! got the info now check if you can see this attachment. |
943 | - if (!allowedTo('view_attachments', $attachInfo['board'])) |
|
944 | - return 'attachments_not_allowed_to_see'; |
|
999 | + if (!allowedTo('view_attachments', $attachInfo['board'])) { |
|
1000 | + return 'attachments_not_allowed_to_see'; |
|
1001 | + } |
|
945 | 1002 | |
946 | 1003 | $allAttachments = getAttachsByMsg($attachInfo['msg']); |
947 | 1004 | $attachContext = $allAttachments[$attachInfo['msg']][$attachID]; |
948 | 1005 | |
949 | 1006 | // No point in keep going further. |
950 | - if (!allowedTo('view_attachments', $attachContext['board'])) |
|
951 | - return 'attachments_not_allowed_to_see'; |
|
1007 | + if (!allowedTo('view_attachments', $attachContext['board'])) { |
|
1008 | + return 'attachments_not_allowed_to_see'; |
|
1009 | + } |
|
952 | 1010 | |
953 | 1011 | // Load this particular attach's context. |
954 | - if (!empty($attachContext)) |
|
955 | - $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1012 | + if (!empty($attachContext)) { |
|
1013 | + $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1014 | + } |
|
956 | 1015 | |
957 | 1016 | // One last check, you know, gotta be paranoid... |
958 | - else |
|
959 | - return 'attachments_no_data_loaded'; |
|
1017 | + else { |
|
1018 | + return 'attachments_no_data_loaded'; |
|
1019 | + } |
|
960 | 1020 | |
961 | 1021 | // This is the last "if" I promise! |
962 | - if (empty($attachLoaded)) |
|
963 | - return 'attachments_no_data_loaded'; |
|
964 | - |
|
965 | - else |
|
966 | - $attachContext = $attachLoaded[$attachID]; |
|
1022 | + if (empty($attachLoaded)) { |
|
1023 | + return 'attachments_no_data_loaded'; |
|
1024 | + } else { |
|
1025 | + $attachContext = $attachLoaded[$attachID]; |
|
1026 | + } |
|
967 | 1027 | |
968 | 1028 | // You may or may not want to show this under the post. |
969 | - if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) |
|
970 | - $context['show_attach_under_post'][$attachID] = $attachID; |
|
1029 | + if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) { |
|
1030 | + $context['show_attach_under_post'][$attachID] = $attachID; |
|
1031 | + } |
|
971 | 1032 | |
972 | 1033 | // Last minute changes? |
973 | 1034 | call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext)); |
@@ -987,8 +1048,9 @@ discard block |
||
987 | 1048 | { |
988 | 1049 | global $smcFunc, $modSettings; |
989 | 1050 | |
990 | - if (empty($attachIDs)) |
|
991 | - return array(); |
|
1051 | + if (empty($attachIDs)) { |
|
1052 | + return array(); |
|
1053 | + } |
|
992 | 1054 | |
993 | 1055 | $return = array(); |
994 | 1056 | |
@@ -1004,11 +1066,12 @@ discard block |
||
1004 | 1066 | ) |
1005 | 1067 | ); |
1006 | 1068 | |
1007 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1008 | - return array(); |
|
1069 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1070 | + return array(); |
|
1071 | + } |
|
1009 | 1072 | |
1010 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1011 | - $return[$row['id_attach']] = array( |
|
1073 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1074 | + $return[$row['id_attach']] = array( |
|
1012 | 1075 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
1013 | 1076 | 'size' => $row['size'], |
1014 | 1077 | 'attachID' => $row['id_attach'], |
@@ -1017,6 +1080,7 @@ discard block |
||
1017 | 1080 | 'mime_type' => $row['mime_type'], |
1018 | 1081 | 'thumb' => $row['id_thumb'], |
1019 | 1082 | ); |
1083 | + } |
|
1020 | 1084 | $smcFunc['db_free_result']($request); |
1021 | 1085 | |
1022 | 1086 | return $return; |
@@ -1033,8 +1097,9 @@ discard block |
||
1033 | 1097 | { |
1034 | 1098 | global $smcFunc; |
1035 | 1099 | |
1036 | - if (empty($attachID)) |
|
1037 | - return array(); |
|
1100 | + if (empty($attachID)) { |
|
1101 | + return array(); |
|
1102 | + } |
|
1038 | 1103 | |
1039 | 1104 | $request = $smcFunc['db_query']('', ' |
1040 | 1105 | SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board |
@@ -1047,8 +1112,9 @@ discard block |
||
1047 | 1112 | ) |
1048 | 1113 | ); |
1049 | 1114 | |
1050 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1051 | - return array(); |
|
1115 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1116 | + return array(); |
|
1117 | + } |
|
1052 | 1118 | |
1053 | 1119 | $row = $smcFunc['db_fetch_assoc']($request); |
1054 | 1120 | $smcFunc['db_free_result']($request); |
@@ -1089,8 +1155,9 @@ discard block |
||
1089 | 1155 | $temp = array(); |
1090 | 1156 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1091 | 1157 | { |
1092 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1093 | - continue; |
|
1158 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1159 | + continue; |
|
1160 | + } |
|
1094 | 1161 | |
1095 | 1162 | $temp[$row['id_attach']] = $row; |
1096 | 1163 | } |
@@ -1119,8 +1186,9 @@ discard block |
||
1119 | 1186 | { |
1120 | 1187 | global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc; |
1121 | 1188 | |
1122 | - if (empty($attachments) || empty($attachments[$id_msg])) |
|
1123 | - return array(); |
|
1189 | + if (empty($attachments) || empty($attachments[$id_msg])) { |
|
1190 | + return array(); |
|
1191 | + } |
|
1124 | 1192 | |
1125 | 1193 | // Set up the attachment info - based on code by Meriadoc. |
1126 | 1194 | $attachmentData = array(); |
@@ -1144,11 +1212,13 @@ discard block |
||
1144 | 1212 | ); |
1145 | 1213 | |
1146 | 1214 | // If something is unapproved we'll note it so we can sort them. |
1147 | - if (!$attachment['approved']) |
|
1148 | - $have_unapproved = true; |
|
1215 | + if (!$attachment['approved']) { |
|
1216 | + $have_unapproved = true; |
|
1217 | + } |
|
1149 | 1218 | |
1150 | - if (!$attachmentData[$i]['is_image']) |
|
1151 | - continue; |
|
1219 | + if (!$attachmentData[$i]['is_image']) { |
|
1220 | + continue; |
|
1221 | + } |
|
1152 | 1222 | |
1153 | 1223 | $attachmentData[$i]['real_width'] = $attachment['width']; |
1154 | 1224 | $attachmentData[$i]['width'] = $attachment['width']; |
@@ -1169,12 +1239,12 @@ discard block |
||
1169 | 1239 | // So what folder are we putting this image in? |
1170 | 1240 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
1171 | 1241 | { |
1172 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
1173 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
1242 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
1243 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
1244 | + } |
|
1174 | 1245 | $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
1175 | 1246 | $id_folder_thumb = $modSettings['currentAttachmentUploadDir']; |
1176 | - } |
|
1177 | - else |
|
1247 | + } else |
|
1178 | 1248 | { |
1179 | 1249 | $path = $modSettings['attachmentUploadDir']; |
1180 | 1250 | $id_folder_thumb = 1; |
@@ -1189,10 +1259,11 @@ discard block |
||
1189 | 1259 | $thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : ''; |
1190 | 1260 | |
1191 | 1261 | // Figure out the mime type. |
1192 | - if (!empty($size['mime'])) |
|
1193 | - $thumb_mime = $size['mime']; |
|
1194 | - else |
|
1195 | - $thumb_mime = 'image/' . $thumb_ext; |
|
1262 | + if (!empty($size['mime'])) { |
|
1263 | + $thumb_mime = $size['mime']; |
|
1264 | + } else { |
|
1265 | + $thumb_mime = 'image/' . $thumb_ext; |
|
1266 | + } |
|
1196 | 1267 | |
1197 | 1268 | $thumb_filename = $attachment['filename'] . '_thumb'; |
1198 | 1269 | $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true); |
@@ -1239,11 +1310,12 @@ discard block |
||
1239 | 1310 | } |
1240 | 1311 | } |
1241 | 1312 | |
1242 | - if (!empty($attachment['id_thumb'])) |
|
1243 | - $attachmentData[$i]['thumbnail'] = array( |
|
1313 | + if (!empty($attachment['id_thumb'])) { |
|
1314 | + $attachmentData[$i]['thumbnail'] = array( |
|
1244 | 1315 | 'id' => $attachment['id_thumb'], |
1245 | 1316 | 'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image', |
1246 | 1317 | ); |
1318 | + } |
|
1247 | 1319 | $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']); |
1248 | 1320 | |
1249 | 1321 | // If thumbnails are disabled, check the maximum size of the image. |
@@ -1253,30 +1325,31 @@ discard block |
||
1253 | 1325 | { |
1254 | 1326 | $attachmentData[$i]['width'] = $modSettings['max_image_width']; |
1255 | 1327 | $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']); |
1256 | - } |
|
1257 | - elseif (!empty($modSettings['max_image_width'])) |
|
1328 | + } elseif (!empty($modSettings['max_image_width'])) |
|
1258 | 1329 | { |
1259 | 1330 | $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']); |
1260 | 1331 | $attachmentData[$i]['height'] = $modSettings['max_image_height']; |
1261 | 1332 | } |
1262 | - } |
|
1263 | - elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1333 | + } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1264 | 1334 | { |
1265 | 1335 | // If the image is too large to show inline, make it a popup. |
1266 | - if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) |
|
1267 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1268 | - else |
|
1269 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1336 | + if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) { |
|
1337 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1338 | + } else { |
|
1339 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1340 | + } |
|
1270 | 1341 | } |
1271 | 1342 | |
1272 | - if (!$attachmentData[$i]['thumbnail']['has_thumb']) |
|
1273 | - $attachmentData[$i]['downloads']++; |
|
1343 | + if (!$attachmentData[$i]['thumbnail']['has_thumb']) { |
|
1344 | + $attachmentData[$i]['downloads']++; |
|
1345 | + } |
|
1274 | 1346 | } |
1275 | 1347 | } |
1276 | 1348 | |
1277 | 1349 | // Do we need to instigate a sort? |
1278 | - if ($have_unapproved) |
|
1279 | - usort($attachmentData, 'approved_attach_sort'); |
|
1350 | + if ($have_unapproved) { |
|
1351 | + usort($attachmentData, 'approved_attach_sort'); |
|
1352 | + } |
|
1280 | 1353 | |
1281 | 1354 | return $attachmentData; |
1282 | 1355 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Outputs xml data representing recent information or a profile. |
@@ -37,8 +38,9 @@ discard block |
||
37 | 38 | global $query_this_board, $smcFunc, $forum_version; |
38 | 39 | |
39 | 40 | // If it's not enabled, die. |
40 | - if (empty($modSettings['xmlnews_enable'])) |
|
41 | - obExit(false); |
|
41 | + if (empty($modSettings['xmlnews_enable'])) { |
|
42 | + obExit(false); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | loadLanguage('Stats'); |
44 | 46 | |
@@ -63,8 +65,9 @@ discard block |
||
63 | 65 | if (!empty($_REQUEST['c']) && empty($board)) |
64 | 66 | { |
65 | 67 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
66 | - foreach ($_REQUEST['c'] as $i => $c) |
|
67 | - $_REQUEST['c'][$i] = (int) $c; |
|
68 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
69 | + $_REQUEST['c'][$i] = (int) $c; |
|
70 | + } |
|
68 | 71 | |
69 | 72 | if (count($_REQUEST['c']) == 1) |
70 | 73 | { |
@@ -100,18 +103,20 @@ discard block |
||
100 | 103 | } |
101 | 104 | $smcFunc['db_free_result']($request); |
102 | 105 | |
103 | - if (!empty($boards)) |
|
104 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
106 | + if (!empty($boards)) { |
|
107 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
108 | + } |
|
105 | 109 | |
106 | 110 | // Try to limit the number of messages we look through. |
107 | - if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) |
|
108 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
109 | - } |
|
110 | - elseif (!empty($_REQUEST['boards'])) |
|
111 | + if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) { |
|
112 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
113 | + } |
|
114 | + } elseif (!empty($_REQUEST['boards'])) |
|
111 | 115 | { |
112 | 116 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
113 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
114 | - $_REQUEST['boards'][$i] = (int) $b; |
|
117 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
118 | + $_REQUEST['boards'][$i] = (int) $b; |
|
119 | + } |
|
115 | 120 | |
116 | 121 | $request = $smcFunc['db_query']('', ' |
117 | 122 | SELECT b.id_board, b.num_posts, b.name |
@@ -127,29 +132,32 @@ discard block |
||
127 | 132 | |
128 | 133 | // Either the board specified doesn't exist or you have no access. |
129 | 134 | $num_boards = $smcFunc['db_num_rows']($request); |
130 | - if ($num_boards == 0) |
|
131 | - fatal_lang_error('no_board'); |
|
135 | + if ($num_boards == 0) { |
|
136 | + fatal_lang_error('no_board'); |
|
137 | + } |
|
132 | 138 | |
133 | 139 | $total_posts = 0; |
134 | 140 | $boards = array(); |
135 | 141 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
136 | 142 | { |
137 | - if ($num_boards == 1) |
|
138 | - $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
143 | + if ($num_boards == 1) { |
|
144 | + $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
145 | + } |
|
139 | 146 | |
140 | 147 | $boards[] = $row['id_board']; |
141 | 148 | $total_posts += $row['num_posts']; |
142 | 149 | } |
143 | 150 | $smcFunc['db_free_result']($request); |
144 | 151 | |
145 | - if (!empty($boards)) |
|
146 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
152 | + if (!empty($boards)) { |
|
153 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
154 | + } |
|
147 | 155 | |
148 | 156 | // The more boards, the more we're going to look through... |
149 | - if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) |
|
150 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
151 | - } |
|
152 | - elseif (!empty($board)) |
|
157 | + if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) { |
|
158 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
159 | + } |
|
160 | + } elseif (!empty($board)) |
|
153 | 161 | { |
154 | 162 | $request = $smcFunc['db_query']('', ' |
155 | 163 | SELECT num_posts |
@@ -168,10 +176,10 @@ discard block |
||
168 | 176 | $query_this_board = 'b.id_board = ' . $board; |
169 | 177 | |
170 | 178 | // Try to look through just a few messages, if at all possible. |
171 | - if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) |
|
172 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
173 | - } |
|
174 | - else |
|
179 | + if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) { |
|
180 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
181 | + } |
|
182 | + } else |
|
175 | 183 | { |
176 | 184 | $query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
177 | 185 | AND b.id_board != ' . $modSettings['recycle_board'] : ''); |
@@ -194,30 +202,35 @@ discard block |
||
194 | 202 | // Easy adding of sub actions |
195 | 203 | call_integration_hook('integrate_xmlfeeds', array(&$subActions)); |
196 | 204 | |
197 | - if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) |
|
198 | - $_GET['sa'] = 'recent'; |
|
205 | + if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) { |
|
206 | + $_GET['sa'] = 'recent'; |
|
207 | + } |
|
199 | 208 | |
200 | 209 | // We only want some information, not all of it. |
201 | 210 | $cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']); |
202 | - foreach (array('board', 'boards', 'c') as $var) |
|
203 | - if (isset($_REQUEST[$var])) |
|
211 | + foreach (array('board', 'boards', 'c') as $var) { |
|
212 | + if (isset($_REQUEST[$var])) |
|
204 | 213 | $cachekey[] = $_REQUEST[$var]; |
214 | + } |
|
205 | 215 | $cachekey = md5(json_encode($cachekey) . (!empty($query_this_board) ? $query_this_board : '')); |
206 | 216 | $cache_t = microtime(); |
207 | 217 | |
208 | 218 | // Get the associative array representing the xml. |
209 | - if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) |
|
210 | - $xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
219 | + if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) { |
|
220 | + $xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
221 | + } |
|
211 | 222 | if (empty($xml)) |
212 | 223 | { |
213 | 224 | $call = call_helper($subActions[$_GET['sa']][0], true); |
214 | 225 | |
215 | - if (!empty($call)) |
|
216 | - $xml = call_user_func($call, $xml_format); |
|
226 | + if (!empty($call)) { |
|
227 | + $xml = call_user_func($call, $xml_format); |
|
228 | + } |
|
217 | 229 | |
218 | 230 | if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3) |
219 | - || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) |
|
220 | - cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240); |
|
231 | + || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) { |
|
232 | + cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240); |
|
233 | + } |
|
221 | 234 | } |
222 | 235 | |
223 | 236 | $feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : ''); |
@@ -272,32 +285,36 @@ discard block |
||
272 | 285 | $ns_string = ''; |
273 | 286 | if (!empty($namespaces[$xml_format])) |
274 | 287 | { |
275 | - foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) |
|
276 | - $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
288 | + foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) { |
|
289 | + $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
290 | + } |
|
277 | 291 | } |
278 | 292 | |
279 | 293 | $extraFeedTags_string = ''; |
280 | 294 | if (!empty($extraFeedTags[$xml_format])) |
281 | 295 | { |
282 | - foreach ($extraFeedTags[$xml_format] as $extraTag) |
|
283 | - $extraFeedTags_string .= "\n\t\t" . $extraTag; |
|
296 | + foreach ($extraFeedTags[$xml_format] as $extraTag) { |
|
297 | + $extraFeedTags_string .= "\n\t\t" . $extraTag; |
|
298 | + } |
|
284 | 299 | } |
285 | 300 | |
286 | 301 | // This is an xml file.... |
287 | 302 | ob_end_clean(); |
288 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
289 | - @ob_start('ob_gzhandler'); |
|
290 | - else |
|
291 | - ob_start(); |
|
303 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
304 | + @ob_start('ob_gzhandler'); |
|
305 | + } else { |
|
306 | + ob_start(); |
|
307 | + } |
|
292 | 308 | |
293 | - if ($xml_format == 'smf' || isset($_REQUEST['debug'])) |
|
294 | - header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
295 | - elseif ($xml_format == 'rss' || $xml_format == 'rss2') |
|
296 | - header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
297 | - elseif ($xml_format == 'atom') |
|
298 | - header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
299 | - elseif ($xml_format == 'rdf') |
|
300 | - header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
309 | + if ($xml_format == 'smf' || isset($_REQUEST['debug'])) { |
|
310 | + header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
311 | + } elseif ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
312 | + header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
313 | + } elseif ($xml_format == 'atom') { |
|
314 | + header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
315 | + } elseif ($xml_format == 'rdf') { |
|
316 | + header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
317 | + } |
|
301 | 318 | |
302 | 319 | // First, output the xml header. |
303 | 320 | echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>'; |
@@ -305,10 +322,11 @@ discard block |
||
305 | 322 | // Are we outputting an rss feed or one with more information? |
306 | 323 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
307 | 324 | { |
308 | - if ($xml_format == 'rss2') |
|
309 | - foreach ($_REQUEST as $var => $val) |
|
325 | + if ($xml_format == 'rss2') { |
|
326 | + foreach ($_REQUEST as $var => $val) |
|
310 | 327 | if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
311 | 328 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
329 | + } |
|
312 | 330 | |
313 | 331 | // Start with an RSS 2.0 header. |
314 | 332 | echo ' |
@@ -327,9 +345,10 @@ discard block |
||
327 | 345 | <copyright>' . $feed_meta['rights'] . '</copyright>' : ''; |
328 | 346 | |
329 | 347 | // RSS2 calls for this. |
330 | - if ($xml_format == 'rss2') |
|
331 | - echo ' |
|
348 | + if ($xml_format == 'rss2') { |
|
349 | + echo ' |
|
332 | 350 | <atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />'; |
351 | + } |
|
333 | 352 | |
334 | 353 | echo $extraFeedTags_string; |
335 | 354 | |
@@ -340,12 +359,12 @@ discard block |
||
340 | 359 | echo ' |
341 | 360 | </channel> |
342 | 361 | </rss>'; |
343 | - } |
|
344 | - elseif ($xml_format == 'atom') |
|
362 | + } elseif ($xml_format == 'atom') |
|
345 | 363 | { |
346 | - foreach ($_REQUEST as $var => $val) |
|
347 | - if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
364 | + foreach ($_REQUEST as $var => $val) { |
|
365 | + if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
348 | 366 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
367 | + } |
|
349 | 368 | |
350 | 369 | echo ' |
351 | 370 | <feed', $ns_string, '> |
@@ -371,8 +390,7 @@ discard block |
||
371 | 390 | |
372 | 391 | echo ' |
373 | 392 | </feed>'; |
374 | - } |
|
375 | - elseif ($xml_format == 'rdf') |
|
393 | + } elseif ($xml_format == 'rdf') |
|
376 | 394 | { |
377 | 395 | echo ' |
378 | 396 | <rdf:RDF', $ns_string, '> |
@@ -437,13 +455,15 @@ discard block |
||
437 | 455 | { |
438 | 456 | global $modSettings, $context, $scripturl; |
439 | 457 | |
440 | - if (substr($val, 0, strlen($scripturl)) != $scripturl) |
|
441 | - return $val; |
|
458 | + if (substr($val, 0, strlen($scripturl)) != $scripturl) { |
|
459 | + return $val; |
|
460 | + } |
|
442 | 461 | |
443 | 462 | call_integration_hook('integrate_fix_url', array(&$val)); |
444 | 463 | |
445 | - if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) |
|
446 | - return $val; |
|
464 | + if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) { |
|
465 | + return $val; |
|
466 | + } |
|
447 | 467 | |
448 | 468 | $val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl) |
449 | 469 | { |
@@ -466,8 +486,9 @@ discard block |
||
466 | 486 | global $smcFunc; |
467 | 487 | |
468 | 488 | // Do we even need to do this? |
469 | - if (strpbrk($data, '<>&') == false && $force !== true) |
|
470 | - return $data; |
|
489 | + if (strpbrk($data, '<>&') == false && $force !== true) { |
|
490 | + return $data; |
|
491 | + } |
|
471 | 492 | |
472 | 493 | $cdata = '<, |
478 | 499 | $smcFunc['strpos']($data, ']', $pos), |
479 | 500 | ); |
480 | - if ($ns != '') |
|
481 | - $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
501 | + if ($ns != '') { |
|
502 | + $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
503 | + } |
|
482 | 504 | foreach ($positions as $k => $dummy) |
483 | 505 | { |
484 | - if ($dummy === false) |
|
485 | - unset($positions[$k]); |
|
506 | + if ($dummy === false) { |
|
507 | + unset($positions[$k]); |
|
508 | + } |
|
486 | 509 | } |
487 | 510 | |
488 | 511 | $old = $pos; |
489 | 512 | $pos = empty($positions) ? $n : min($positions); |
490 | 513 | |
491 | - if ($pos - $old > 0) |
|
492 | - $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
493 | - if ($pos >= $n) |
|
494 | - break; |
|
514 | + if ($pos - $old > 0) { |
|
515 | + $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
516 | + } |
|
517 | + if ($pos >= $n) { |
|
518 | + break; |
|
519 | + } |
|
495 | 520 | |
496 | 521 | if ($smcFunc['substr']($data, $pos, 1) == '<') |
497 | 522 | { |
498 | 523 | $pos2 = $smcFunc['strpos']($data, '>', $pos); |
499 | - if ($pos2 === false) |
|
500 | - $pos2 = $n; |
|
501 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '/') |
|
502 | - $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
503 | - else |
|
504 | - $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == '/') { |
|
528 | + $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
529 | + } else { |
|
530 | + $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == ']') |
|
533 | + } elseif ($smcFunc['substr']($data, $pos, 1) == ']') |
|
508 | 534 | { |
509 | 535 | $cdata .= ']]>]< == '&') |
|
537 | + } elseif ($smcFunc['substr']($data, $pos, 1) == '&') |
|
513 | 538 | { |
514 | 539 | $pos2 = $smcFunc['strpos']($data, ';', $pos); |
515 | - if ($pos2 === false) |
|
516 | - $pos2 = $n; |
|
540 | + if ($pos2 === false) { |
|
541 | + $pos2 = $n; |
|
542 | + } |
|
517 | 543 | $ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1); |
518 | 544 | |
519 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '#') |
|
520 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
521 | - elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) |
|
522 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '< == '#') { |
|
546 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
547 | + } elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) { |
|
548 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
549 | + } |
|
523 | 550 | |
524 | 551 | $pos = $pos2 + 1; |
525 | 552 | } |
@@ -558,8 +585,9 @@ discard block |
||
558 | 585 | 'gender', |
559 | 586 | 'blurb', |
560 | 587 | ); |
561 | - if ($xml_format != 'atom') |
|
562 | - $keysToCdata[] = 'category'; |
|
588 | + if ($xml_format != 'atom') { |
|
589 | + $keysToCdata[] = 'category'; |
|
590 | + } |
|
563 | 591 | |
564 | 592 | if (!empty($forceCdataKeys)) |
565 | 593 | { |
@@ -576,8 +604,9 @@ discard block |
||
576 | 604 | $attrs = isset($element['attributes']) ? $element['attributes'] : null; |
577 | 605 | |
578 | 606 | // Skip it, it's been set to null. |
579 | - if ($key === null || ($val === null && $attrs === null)) |
|
580 | - continue; |
|
607 | + if ($key === null || ($val === null && $attrs === null)) { |
|
608 | + continue; |
|
609 | + } |
|
581 | 610 | |
582 | 611 | $forceCdata = in_array($key, $forceCdataKeys); |
583 | 612 | $ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : ''; |
@@ -590,16 +619,16 @@ discard block |
||
590 | 619 | |
591 | 620 | if (!empty($attrs)) |
592 | 621 | { |
593 | - foreach ($attrs as $attr_key => $attr_value) |
|
594 | - echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
622 | + foreach ($attrs as $attr_key => $attr_value) { |
|
623 | + echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
624 | + } |
|
595 | 625 | } |
596 | 626 | |
597 | 627 | // If it's empty, simply output an empty element. |
598 | 628 | if (empty($val)) |
599 | 629 | { |
600 | 630 | echo ' />'; |
601 | - } |
|
602 | - else |
|
631 | + } else |
|
603 | 632 | { |
604 | 633 | echo '>'; |
605 | 634 | |
@@ -611,11 +640,13 @@ discard block |
||
611 | 640 | echo "\n", str_repeat("\t", $i); |
612 | 641 | } |
613 | 642 | // A string with returns in it.... show this as a multiline element. |
614 | - elseif (strpos($val, "\n") !== false) |
|
615 | - echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
643 | + elseif (strpos($val, "\n") !== false) { |
|
644 | + echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
645 | + } |
|
616 | 646 | // A simple string. |
617 | - else |
|
618 | - echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
647 | + else { |
|
648 | + echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
649 | + } |
|
619 | 650 | |
620 | 651 | // Ending tag. |
621 | 652 | echo '</', $key, '>'; |
@@ -635,8 +666,9 @@ discard block |
||
635 | 666 | { |
636 | 667 | global $scripturl, $smcFunc; |
637 | 668 | |
638 | - if (!allowedTo('view_mlist')) |
|
639 | - return array(); |
|
669 | + if (!allowedTo('view_mlist')) { |
|
670 | + return array(); |
|
671 | + } |
|
640 | 672 | |
641 | 673 | // Find the most recent members. |
642 | 674 | $request = $smcFunc['db_query']('', ' |
@@ -652,8 +684,8 @@ discard block |
||
652 | 684 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
653 | 685 | { |
654 | 686 | // Make the data look rss-ish. |
655 | - if ($xml_format == 'rss' || $xml_format == 'rss2') |
|
656 | - $data[] = array( |
|
687 | + if ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
688 | + $data[] = array( |
|
657 | 689 | 'tag' => 'item', |
658 | 690 | 'content' => array( |
659 | 691 | array( |
@@ -678,8 +710,8 @@ discard block |
||
678 | 710 | ), |
679 | 711 | ), |
680 | 712 | ); |
681 | - elseif ($xml_format == 'rdf') |
|
682 | - $data[] = array( |
|
713 | + } elseif ($xml_format == 'rdf') { |
|
714 | + $data[] = array( |
|
683 | 715 | 'tag' => 'item', |
684 | 716 | 'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']), |
685 | 717 | 'content' => array( |
@@ -697,8 +729,8 @@ discard block |
||
697 | 729 | ), |
698 | 730 | ), |
699 | 731 | ); |
700 | - elseif ($xml_format == 'atom') |
|
701 | - $data[] = array( |
|
732 | + } elseif ($xml_format == 'atom') { |
|
733 | + $data[] = array( |
|
702 | 734 | 'tag' => 'entry', |
703 | 735 | 'content' => array( |
704 | 736 | array( |
@@ -727,9 +759,10 @@ discard block |
||
727 | 759 | ), |
728 | 760 | ), |
729 | 761 | ); |
762 | + } |
|
730 | 763 | // More logical format for the data, but harder to apply. |
731 | - else |
|
732 | - $data[] = array( |
|
764 | + else { |
|
765 | + $data[] = array( |
|
733 | 766 | 'tag' => 'member', |
734 | 767 | 'content' => array( |
735 | 768 | array( |
@@ -750,6 +783,7 @@ discard block |
||
750 | 783 | ), |
751 | 784 | ), |
752 | 785 | ); |
786 | + } |
|
753 | 787 | } |
754 | 788 | $smcFunc['db_free_result']($request); |
755 | 789 | |
@@ -810,22 +844,24 @@ discard block |
||
810 | 844 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
811 | 845 | { |
812 | 846 | $smcFunc['db_free_result']($request); |
813 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
814 | - unset($context['optimize_msg']['lowest']); |
|
815 | - else |
|
816 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
847 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
848 | + unset($context['optimize_msg']['lowest']); |
|
849 | + } else { |
|
850 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
851 | + } |
|
817 | 852 | $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg'; |
818 | 853 | $loops++; |
854 | + } else { |
|
855 | + $done = true; |
|
819 | 856 | } |
820 | - else |
|
821 | - $done = true; |
|
822 | 857 | } |
823 | 858 | $data = array(); |
824 | 859 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
825 | 860 | { |
826 | 861 | // Limit the length of the message, if the option is set. |
827 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
828 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
862 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
863 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
864 | + } |
|
829 | 865 | |
830 | 866 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
831 | 867 | |
@@ -852,8 +888,9 @@ discard block |
||
852 | 888 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
853 | 889 | { |
854 | 890 | // Include approved attachments only |
855 | - if ($attach['approved']) |
|
856 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
891 | + if ($attach['approved']) { |
|
892 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
893 | + } |
|
857 | 894 | } |
858 | 895 | $smcFunc['db_free_result']($attach_request); |
859 | 896 | |
@@ -861,16 +898,17 @@ discard block |
||
861 | 898 | if (!empty($loaded_attachments)) |
862 | 899 | { |
863 | 900 | uasort($loaded_attachments, function($a, $b) { |
864 | - if ($a['filesize'] == $b['filesize']) |
|
865 | - return 0; |
|
901 | + if ($a['filesize'] == $b['filesize']) { |
|
902 | + return 0; |
|
903 | + } |
|
866 | 904 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
867 | 905 | }); |
906 | + } else { |
|
907 | + $loaded_attachments = null; |
|
868 | 908 | } |
869 | - else |
|
870 | - $loaded_attachments = null; |
|
909 | + } else { |
|
910 | + $loaded_attachments = null; |
|
871 | 911 | } |
872 | - else |
|
873 | - $loaded_attachments = null; |
|
874 | 912 | |
875 | 913 | // Being news, this actually makes sense in rss format. |
876 | 914 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
@@ -884,9 +922,9 @@ discard block |
||
884 | 922 | 'length' => $attachment['filesize'], |
885 | 923 | 'type' => $attachment['mime_type'], |
886 | 924 | ); |
925 | + } else { |
|
926 | + $enclosure = null; |
|
887 | 927 | } |
888 | - else |
|
889 | - $enclosure = null; |
|
890 | 928 | |
891 | 929 | $data[] = array( |
892 | 930 | 'tag' => 'item', |
@@ -929,8 +967,7 @@ discard block |
||
929 | 967 | ), |
930 | 968 | ), |
931 | 969 | ); |
932 | - } |
|
933 | - elseif ($xml_format == 'rdf') |
|
970 | + } elseif ($xml_format == 'rdf') |
|
934 | 971 | { |
935 | 972 | $data[] = array( |
936 | 973 | 'tag' => 'item', |
@@ -954,8 +991,7 @@ discard block |
||
954 | 991 | ), |
955 | 992 | ), |
956 | 993 | ); |
957 | - } |
|
958 | - elseif ($xml_format == 'atom') |
|
994 | + } elseif ($xml_format == 'atom') |
|
959 | 995 | { |
960 | 996 | // Only one attachment allowed |
961 | 997 | if (!empty($loaded_attachments)) |
@@ -967,9 +1003,9 @@ discard block |
||
967 | 1003 | 'length' => $attachment['filesize'], |
968 | 1004 | 'type' => $attachment['mime_type'], |
969 | 1005 | ); |
1006 | + } else { |
|
1007 | + $enclosure = null; |
|
970 | 1008 | } |
971 | - else |
|
972 | - $enclosure = null; |
|
973 | 1009 | |
974 | 1010 | $data[] = array( |
975 | 1011 | 'tag' => 'entry', |
@@ -1069,9 +1105,9 @@ discard block |
||
1069 | 1105 | ) |
1070 | 1106 | ); |
1071 | 1107 | } |
1108 | + } else { |
|
1109 | + $attachments = null; |
|
1072 | 1110 | } |
1073 | - else |
|
1074 | - $attachments = null; |
|
1075 | 1111 | |
1076 | 1112 | $data[] = array( |
1077 | 1113 | 'tag' => 'article', |
@@ -1189,22 +1225,25 @@ discard block |
||
1189 | 1225 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
1190 | 1226 | { |
1191 | 1227 | $smcFunc['db_free_result']($request); |
1192 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
1193 | - unset($context['optimize_msg']['lowest']); |
|
1194 | - else |
|
1195 | - $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1228 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
1229 | + unset($context['optimize_msg']['lowest']); |
|
1230 | + } else { |
|
1231 | + $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1232 | + } |
|
1196 | 1233 | $loops++; |
1234 | + } else { |
|
1235 | + $done = true; |
|
1197 | 1236 | } |
1198 | - else |
|
1199 | - $done = true; |
|
1200 | 1237 | } |
1201 | 1238 | $messages = array(); |
1202 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1203 | - $messages[] = $row['id_msg']; |
|
1239 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1240 | + $messages[] = $row['id_msg']; |
|
1241 | + } |
|
1204 | 1242 | $smcFunc['db_free_result']($request); |
1205 | 1243 | |
1206 | - if (empty($messages)) |
|
1207 | - return array(); |
|
1244 | + if (empty($messages)) { |
|
1245 | + return array(); |
|
1246 | + } |
|
1208 | 1247 | |
1209 | 1248 | // Find the most recent posts this user can see. |
1210 | 1249 | $request = $smcFunc['db_query']('', ' |
@@ -1234,8 +1273,9 @@ discard block |
||
1234 | 1273 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1235 | 1274 | { |
1236 | 1275 | // Limit the length of the message, if the option is set. |
1237 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
1238 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1276 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
1277 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1278 | + } |
|
1239 | 1279 | |
1240 | 1280 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
1241 | 1281 | |
@@ -1262,8 +1302,9 @@ discard block |
||
1262 | 1302 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
1263 | 1303 | { |
1264 | 1304 | // Include approved attachments only |
1265 | - if ($attach['approved']) |
|
1266 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1305 | + if ($attach['approved']) { |
|
1306 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1307 | + } |
|
1267 | 1308 | } |
1268 | 1309 | $smcFunc['db_free_result']($attach_request); |
1269 | 1310 | |
@@ -1271,16 +1312,17 @@ discard block |
||
1271 | 1312 | if (!empty($loaded_attachments)) |
1272 | 1313 | { |
1273 | 1314 | uasort($loaded_attachments, function($a, $b) { |
1274 | - if ($a['filesize'] == $b['filesize']) |
|
1275 | - return 0; |
|
1315 | + if ($a['filesize'] == $b['filesize']) { |
|
1316 | + return 0; |
|
1317 | + } |
|
1276 | 1318 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
1277 | 1319 | }); |
1320 | + } else { |
|
1321 | + $loaded_attachments = null; |
|
1278 | 1322 | } |
1279 | - else |
|
1280 | - $loaded_attachments = null; |
|
1323 | + } else { |
|
1324 | + $loaded_attachments = null; |
|
1281 | 1325 | } |
1282 | - else |
|
1283 | - $loaded_attachments = null; |
|
1284 | 1326 | |
1285 | 1327 | // Doesn't work as well as news, but it kinda does.. |
1286 | 1328 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
@@ -1294,9 +1336,9 @@ discard block |
||
1294 | 1336 | 'length' => $attachment['filesize'], |
1295 | 1337 | 'type' => $attachment['mime_type'], |
1296 | 1338 | ); |
1339 | + } else { |
|
1340 | + $enclosure = null; |
|
1297 | 1341 | } |
1298 | - else |
|
1299 | - $enclosure = null; |
|
1300 | 1342 | |
1301 | 1343 | $data[] = array( |
1302 | 1344 | 'tag' => 'item', |
@@ -1339,8 +1381,7 @@ discard block |
||
1339 | 1381 | ), |
1340 | 1382 | ), |
1341 | 1383 | ); |
1342 | - } |
|
1343 | - elseif ($xml_format == 'rdf') |
|
1384 | + } elseif ($xml_format == 'rdf') |
|
1344 | 1385 | { |
1345 | 1386 | $data[] = array( |
1346 | 1387 | 'tag' => 'item', |
@@ -1364,8 +1405,7 @@ discard block |
||
1364 | 1405 | ), |
1365 | 1406 | ), |
1366 | 1407 | ); |
1367 | - } |
|
1368 | - elseif ($xml_format == 'atom') |
|
1408 | + } elseif ($xml_format == 'atom') |
|
1369 | 1409 | { |
1370 | 1410 | // Only one attachment allowed |
1371 | 1411 | if (!empty($loaded_attachments)) |
@@ -1377,9 +1417,9 @@ discard block |
||
1377 | 1417 | 'length' => $attachment['filesize'], |
1378 | 1418 | 'type' => $attachment['mime_type'], |
1379 | 1419 | ); |
1420 | + } else { |
|
1421 | + $enclosure = null; |
|
1380 | 1422 | } |
1381 | - else |
|
1382 | - $enclosure = null; |
|
1383 | 1423 | |
1384 | 1424 | $data[] = array( |
1385 | 1425 | 'tag' => 'entry', |
@@ -1479,9 +1519,9 @@ discard block |
||
1479 | 1519 | ) |
1480 | 1520 | ); |
1481 | 1521 | } |
1522 | + } else { |
|
1523 | + $attachments = null; |
|
1482 | 1524 | } |
1483 | - else |
|
1484 | - $attachments = null; |
|
1485 | 1525 | |
1486 | 1526 | $data[] = array( |
1487 | 1527 | 'tag' => 'recent-post', |
@@ -1600,14 +1640,16 @@ discard block |
||
1600 | 1640 | global $scripturl, $memberContext, $user_profile, $user_info; |
1601 | 1641 | |
1602 | 1642 | // You must input a valid user.... |
1603 | - if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) |
|
1604 | - return array(); |
|
1643 | + if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) { |
|
1644 | + return array(); |
|
1645 | + } |
|
1605 | 1646 | |
1606 | 1647 | // Make sure the id is a number and not "I like trying to hack the database". |
1607 | 1648 | $_GET['u'] = (int) $_GET['u']; |
1608 | 1649 | // Load the member's contextual information! |
1609 | - if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) |
|
1610 | - return array(); |
|
1650 | + if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) { |
|
1651 | + return array(); |
|
1652 | + } |
|
1611 | 1653 | |
1612 | 1654 | // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type. |
1613 | 1655 | $profile = &$memberContext[$_GET['u']]; |
@@ -1643,8 +1685,7 @@ discard block |
||
1643 | 1685 | ), |
1644 | 1686 | ) |
1645 | 1687 | ); |
1646 | - } |
|
1647 | - elseif ($xml_format == 'rdf') |
|
1688 | + } elseif ($xml_format == 'rdf') |
|
1648 | 1689 | { |
1649 | 1690 | $data[] = array( |
1650 | 1691 | 'tag' => 'item', |
@@ -1668,8 +1709,7 @@ discard block |
||
1668 | 1709 | ), |
1669 | 1710 | ) |
1670 | 1711 | ); |
1671 | - } |
|
1672 | - elseif ($xml_format == 'atom') |
|
1712 | + } elseif ($xml_format == 'atom') |
|
1673 | 1713 | { |
1674 | 1714 | $data[] = array( |
1675 | 1715 | 'tag' => 'entry', |
@@ -1722,8 +1762,7 @@ discard block |
||
1722 | 1762 | ), |
1723 | 1763 | ) |
1724 | 1764 | ); |
1725 | - } |
|
1726 | - else |
|
1765 | + } else |
|
1727 | 1766 | { |
1728 | 1767 | $data = array( |
1729 | 1768 | array( |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | loadLanguage('Drafts'); |
21 | 22 | |
@@ -33,8 +34,9 @@ discard block |
||
33 | 34 | global $context, $user_info, $smcFunc, $modSettings, $board; |
34 | 35 | |
35 | 36 | // can you be, should you be ... here? |
36 | - if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) |
|
37 | - return false; |
|
37 | + if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) { |
|
38 | + return false; |
|
39 | + } |
|
38 | 40 | |
39 | 41 | // read in what they sent us, if anything |
40 | 42 | $id_draft = (int) $_POST['id_draft']; |
@@ -46,14 +48,16 @@ discard block |
||
46 | 48 | $context['draft_saved_on'] = $draft_info['poster_time']; |
47 | 49 | |
48 | 50 | // since we were called from the autosave function, send something back |
49 | - if (!empty($id_draft)) |
|
50 | - XmlDraft($id_draft); |
|
51 | + if (!empty($id_draft)) { |
|
52 | + XmlDraft($id_draft); |
|
53 | + } |
|
51 | 54 | |
52 | 55 | return true; |
53 | 56 | } |
54 | 57 | |
55 | - if (!isset($_POST['message'])) |
|
56 | - $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
58 | + if (!isset($_POST['message'])) { |
|
59 | + $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
60 | + } |
|
57 | 61 | |
58 | 62 | // prepare any data from the form |
59 | 63 | $topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic']; |
@@ -66,8 +70,9 @@ discard block |
||
66 | 70 | |
67 | 71 | // message and subject still need a bit more work |
68 | 72 | preparsecode($draft['body']); |
69 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
70 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
73 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
74 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
75 | + } |
|
71 | 76 | |
72 | 77 | // Modifying an existing draft, like hitting the save draft button or autosave enabled? |
73 | 78 | if (!empty($id_draft) && !empty($draft_info)) |
@@ -148,9 +153,9 @@ discard block |
||
148 | 153 | { |
149 | 154 | $context['draft_saved'] = true; |
150 | 155 | $context['id_draft'] = $id_draft; |
156 | + } else { |
|
157 | + $post_errors[] = 'draft_not_saved'; |
|
151 | 158 | } |
152 | - else |
|
153 | - $post_errors[] = 'draft_not_saved'; |
|
154 | 159 | |
155 | 160 | // cleanup |
156 | 161 | unset($_POST['save_draft']); |
@@ -180,8 +185,9 @@ discard block |
||
180 | 185 | global $context, $user_info, $smcFunc, $modSettings; |
181 | 186 | |
182 | 187 | // PM survey says ... can you stay or must you go |
183 | - if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) |
|
184 | - return false; |
|
188 | + if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) { |
|
189 | + return false; |
|
190 | + } |
|
185 | 191 | |
186 | 192 | // read in what you sent us |
187 | 193 | $id_pm_draft = (int) $_POST['id_pm_draft']; |
@@ -193,8 +199,9 @@ discard block |
||
193 | 199 | $context['draft_saved_on'] = $draft_info['poster_time']; |
194 | 200 | |
195 | 201 | // Send something back to the javascript caller |
196 | - if (!empty($id_draft)) |
|
197 | - XmlDraft($id_draft); |
|
202 | + if (!empty($id_draft)) { |
|
203 | + XmlDraft($id_draft); |
|
204 | + } |
|
198 | 205 | |
199 | 206 | return true; |
200 | 207 | } |
@@ -204,9 +211,9 @@ discard block |
||
204 | 211 | { |
205 | 212 | $recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); |
206 | 213 | $recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); |
214 | + } elseif (!empty($draft_info['to_list']) && empty($recipientList)) { |
|
215 | + $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
207 | 216 | } |
208 | - elseif (!empty($draft_info['to_list']) && empty($recipientList)) |
|
209 | - $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
210 | 217 | |
211 | 218 | // prepare the data we got from the form |
212 | 219 | $reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to']; |
@@ -215,8 +222,9 @@ discard block |
||
215 | 222 | |
216 | 223 | // message and subject always need a bit more work |
217 | 224 | preparsecode($draft['body']); |
218 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
219 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
225 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
226 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
227 | + } |
|
220 | 228 | |
221 | 229 | // Modifying an existing PM draft? |
222 | 230 | if (!empty($id_pm_draft) && !empty($draft_info)) |
@@ -280,9 +288,9 @@ discard block |
||
280 | 288 | { |
281 | 289 | $context['draft_saved'] = true; |
282 | 290 | $context['id_pm_draft'] = $id_pm_draft; |
291 | + } else { |
|
292 | + $post_errors[] = 'draft_not_saved'; |
|
283 | 293 | } |
284 | - else |
|
285 | - $post_errors[] = 'draft_not_saved'; |
|
286 | 294 | } |
287 | 295 | |
288 | 296 | // if we were called from the autosave function, send something back |
@@ -315,8 +323,9 @@ discard block |
||
315 | 323 | $type = (int) $type; |
316 | 324 | |
317 | 325 | // nothing to read, nothing to do |
318 | - if (empty($id_draft)) |
|
319 | - return false; |
|
326 | + if (empty($id_draft)) { |
|
327 | + return false; |
|
328 | + } |
|
320 | 329 | |
321 | 330 | // load in this draft from the DB |
322 | 331 | $request = $smcFunc['db_query']('', ' |
@@ -337,8 +346,9 @@ discard block |
||
337 | 346 | ); |
338 | 347 | |
339 | 348 | // no results? |
340 | - if (!$smcFunc['db_num_rows']($request)) |
|
341 | - return false; |
|
349 | + if (!$smcFunc['db_num_rows']($request)) { |
|
350 | + return false; |
|
351 | + } |
|
342 | 352 | |
343 | 353 | // load up the data |
344 | 354 | $draft_info = $smcFunc['db_fetch_assoc']($request); |
@@ -358,8 +368,7 @@ discard block |
||
358 | 368 | $context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
359 | 369 | $context['board'] = !empty($draft_info['id_board']) ? $draft_info['id_board'] : ''; |
360 | 370 | $context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0; |
361 | - } |
|
362 | - elseif ($type === 1) |
|
371 | + } elseif ($type === 1) |
|
363 | 372 | { |
364 | 373 | // one of those pm drafts? then set it up like we have an error |
365 | 374 | $_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
@@ -395,12 +404,14 @@ discard block |
||
395 | 404 | global $user_info, $smcFunc; |
396 | 405 | |
397 | 406 | // Only a single draft. |
398 | - if (is_numeric($id_draft)) |
|
399 | - $id_draft = array($id_draft); |
|
407 | + if (is_numeric($id_draft)) { |
|
408 | + $id_draft = array($id_draft); |
|
409 | + } |
|
400 | 410 | |
401 | 411 | // can't delete nothing |
402 | - if (empty($id_draft) || ($check && empty($user_info['id']))) |
|
403 | - return false; |
|
412 | + if (empty($id_draft) || ($check && empty($user_info['id']))) { |
|
413 | + return false; |
|
414 | + } |
|
404 | 415 | |
405 | 416 | $smcFunc['db_query']('', ' |
406 | 417 | DELETE FROM {db_prefix}user_drafts |
@@ -429,14 +440,16 @@ discard block |
||
429 | 440 | global $smcFunc, $scripturl, $context, $txt, $modSettings; |
430 | 441 | |
431 | 442 | // Permissions |
432 | - if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) |
|
433 | - return false; |
|
443 | + if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) { |
|
444 | + return false; |
|
445 | + } |
|
434 | 446 | |
435 | 447 | $context['drafts'] = array(); |
436 | 448 | |
437 | 449 | // has a specific draft has been selected? Load it up if there is not a message already in the editor |
438 | - if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) |
|
439 | - ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
450 | + if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) { |
|
451 | + ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
452 | + } |
|
440 | 453 | |
441 | 454 | // load the drafts this user has available |
442 | 455 | $request = $smcFunc['db_query']('', ' |
@@ -459,8 +472,9 @@ discard block |
||
459 | 472 | // add them to the draft array for display |
460 | 473 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
461 | 474 | { |
462 | - if (empty($row['subject'])) |
|
463 | - $row['subject'] = $txt['no_subject']; |
|
475 | + if (empty($row['subject'])) { |
|
476 | + $row['subject'] = $txt['no_subject']; |
|
477 | + } |
|
464 | 478 | |
465 | 479 | // Post drafts |
466 | 480 | if ($draft_type === 0) |
@@ -545,8 +559,9 @@ discard block |
||
545 | 559 | } |
546 | 560 | |
547 | 561 | // Default to 10. |
548 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
549 | - $_REQUEST['viewscount'] = 10; |
|
562 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
563 | + $_REQUEST['viewscount'] = 10; |
|
564 | + } |
|
550 | 565 | |
551 | 566 | // Get the count of applicable drafts on the boards they can (still) see ... |
552 | 567 | // @todo .. should we just let them see their drafts even if they have lost board access ? |
@@ -611,12 +626,14 @@ discard block |
||
611 | 626 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
612 | 627 | { |
613 | 628 | // Censor.... |
614 | - if (empty($row['body'])) |
|
615 | - $row['body'] = ''; |
|
629 | + if (empty($row['body'])) { |
|
630 | + $row['body'] = ''; |
|
631 | + } |
|
616 | 632 | |
617 | 633 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
618 | - if (empty($row['subject'])) |
|
619 | - $row['subject'] = $txt['no_subject']; |
|
634 | + if (empty($row['subject'])) { |
|
635 | + $row['subject'] = $txt['no_subject']; |
|
636 | + } |
|
620 | 637 | |
621 | 638 | censorText($row['body']); |
622 | 639 | censorText($row['subject']); |
@@ -648,8 +665,9 @@ discard block |
||
648 | 665 | $smcFunc['db_free_result']($request); |
649 | 666 | |
650 | 667 | // If the drafts were retrieved in reverse order, get them right again. |
651 | - if ($reverse) |
|
652 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
668 | + if ($reverse) { |
|
669 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
670 | + } |
|
653 | 671 | |
654 | 672 | // Menu tab |
655 | 673 | $context[$context['profile_menu_name']]['tab_data'] = array( |
@@ -707,8 +725,9 @@ discard block |
||
707 | 725 | } |
708 | 726 | |
709 | 727 | // Default to 10. |
710 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
711 | - $_REQUEST['viewscount'] = 10; |
|
728 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
729 | + $_REQUEST['viewscount'] = 10; |
|
730 | + } |
|
712 | 731 | |
713 | 732 | // Get the count of applicable drafts |
714 | 733 | $request = $smcFunc['db_query']('', ' |
@@ -767,12 +786,14 @@ discard block |
||
767 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
768 | 787 | { |
769 | 788 | // Censor.... |
770 | - if (empty($row['body'])) |
|
771 | - $row['body'] = ''; |
|
789 | + if (empty($row['body'])) { |
|
790 | + $row['body'] = ''; |
|
791 | + } |
|
772 | 792 | |
773 | 793 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
774 | - if (empty($row['subject'])) |
|
775 | - $row['subject'] = $txt['no_subject']; |
|
794 | + if (empty($row['subject'])) { |
|
795 | + $row['subject'] = $txt['no_subject']; |
|
796 | + } |
|
776 | 797 | |
777 | 798 | censorText($row['body']); |
778 | 799 | censorText($row['subject']); |
@@ -827,8 +848,9 @@ discard block |
||
827 | 848 | $smcFunc['db_free_result']($request); |
828 | 849 | |
829 | 850 | // if the drafts were retrieved in reverse order, then put them in the right order again. |
830 | - if ($reverse) |
|
831 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
851 | + if ($reverse) { |
|
852 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
853 | + } |
|
832 | 854 | |
833 | 855 | // off to the template we go |
834 | 856 | $context['page_title'] = $txt['drafts']; |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | class Attachments |
20 | 21 | { |
@@ -70,16 +71,18 @@ discard block |
||
70 | 71 | |
71 | 72 | $this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false; |
72 | 73 | |
73 | - if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) |
|
74 | - $this->{$this->_sa}(); |
|
74 | + if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) { |
|
75 | + $this->{$this->_sa}(); |
|
76 | + } |
|
75 | 77 | |
76 | 78 | // Just send a generic message. |
77 | - else |
|
78 | - $this->setResponse(array( |
|
79 | + else { |
|
80 | + $this->setResponse(array( |
|
79 | 81 | 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
80 | 82 | 'type' => 'error', |
81 | 83 | 'data' => false, |
82 | 84 | )); |
85 | + } |
|
83 | 86 | |
84 | 87 | // Back to the future, oh, to the browser! |
85 | 88 | $this->sendResponse(); |
@@ -95,12 +98,13 @@ discard block |
||
95 | 98 | $attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0; |
96 | 99 | |
97 | 100 | // Need something to work with. |
98 | - if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) |
|
99 | - return $this->setResponse(array( |
|
101 | + if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) { |
|
102 | + return $this->setResponse(array( |
|
100 | 103 | 'text' => 'attached_file_deleted_error', |
101 | 104 | 'type' => 'error', |
102 | 105 | 'data' => false, |
103 | 106 | )); |
107 | + } |
|
104 | 108 | |
105 | 109 | // Lets pass some params and see what happens :P |
106 | 110 | $affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true); |
@@ -119,19 +123,21 @@ discard block |
||
119 | 123 | public function add() |
120 | 124 | { |
121 | 125 | // You gotta be able to post attachments. |
122 | - if (!$this->_canPostAttachment) |
|
123 | - return $this->setResponse(array( |
|
126 | + if (!$this->_canPostAttachment) { |
|
127 | + return $this->setResponse(array( |
|
124 | 128 | 'text' => 'attached_file_cannot', |
125 | 129 | 'type' => 'error', |
126 | 130 | 'data' => false, |
127 | 131 | )); |
132 | + } |
|
128 | 133 | |
129 | 134 | // Process them at once! |
130 | 135 | $this->processAttachments(); |
131 | 136 | |
132 | 137 | // The attachments was created and moved the the right folder, time to update the DB. |
133 | - if (!empty($_SESSION['temp_attachments'])) |
|
134 | - $this->createAtttach(); |
|
138 | + if (!empty($_SESSION['temp_attachments'])) { |
|
139 | + $this->createAtttach(); |
|
140 | + } |
|
135 | 141 | |
136 | 142 | // Set the response. |
137 | 143 | $this->setResponse(); |
@@ -144,8 +150,9 @@ discard block |
||
144 | 150 | { |
145 | 151 | global $context, $modSettings, $smcFunc, $user_info, $txt; |
146 | 152 | |
147 | - if (!isset($_FILES['attachment']['name'])) |
|
148 | - $_FILES['attachment']['tmp_name'] = array(); |
|
153 | + if (!isset($_FILES['attachment']['name'])) { |
|
154 | + $_FILES['attachment']['tmp_name'] = array(); |
|
155 | + } |
|
149 | 156 | |
150 | 157 | // If there are attachments, calculate the total size and how many. |
151 | 158 | $context['attachments']['total_size'] = 0; |
@@ -155,25 +162,30 @@ discard block |
||
155 | 162 | if (isset($_REQUEST['msg'])) |
156 | 163 | { |
157 | 164 | $context['attachments']['quantity'] = count($context['current_attachments']); |
158 | - foreach ($context['current_attachments'] as $attachment) |
|
159 | - $context['attachments']['total_size'] += $attachment['size']; |
|
165 | + foreach ($context['current_attachments'] as $attachment) { |
|
166 | + $context['attachments']['total_size'] += $attachment['size']; |
|
167 | + } |
|
160 | 168 | } |
161 | 169 | |
162 | 170 | // A bit of house keeping first. |
163 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
164 | - unset($_SESSION['temp_attachments']); |
|
171 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
172 | + unset($_SESSION['temp_attachments']); |
|
173 | + } |
|
165 | 174 | |
166 | 175 | // Our infamous SESSION var, we are gonna have soo much fun with it! |
167 | - if (!isset($_SESSION['temp_attachments'])) |
|
168 | - $_SESSION['temp_attachments'] = array(); |
|
176 | + if (!isset($_SESSION['temp_attachments'])) { |
|
177 | + $_SESSION['temp_attachments'] = array(); |
|
178 | + } |
|
169 | 179 | |
170 | 180 | // Make sure we're uploading to the right place. |
171 | - if (!empty($modSettings['automanage_attachments'])) |
|
172 | - automanage_attachments_check_directory(); |
|
181 | + if (!empty($modSettings['automanage_attachments'])) { |
|
182 | + automanage_attachments_check_directory(); |
|
183 | + } |
|
173 | 184 | |
174 | 185 | // Is the attachments folder actually there? |
175 | - if (!empty($context['dir_creation_error'])) |
|
176 | - $this->_generalErrors[] = $context['dir_creation_error']; |
|
186 | + if (!empty($context['dir_creation_error'])) { |
|
187 | + $this->_generalErrors[] = $context['dir_creation_error']; |
|
188 | + } |
|
177 | 189 | |
178 | 190 | // The current attach folder ha some issues... |
179 | 191 | elseif (!is_dir($this->_attchDir)) |
@@ -198,13 +210,12 @@ discard block |
||
198 | 210 | ); |
199 | 211 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
200 | 212 | $smcFunc['db_free_result']($request); |
201 | - } |
|
202 | - |
|
203 | - else |
|
204 | - $context['attachments'] = array( |
|
213 | + } else { |
|
214 | + $context['attachments'] = array( |
|
205 | 215 | 'quantity' => 0, |
206 | 216 | 'total_size' => 0, |
207 | 217 | ); |
218 | + } |
|
208 | 219 | |
209 | 220 | // Check for other general errors here. |
210 | 221 | |
@@ -212,9 +223,10 @@ discard block |
||
212 | 223 | if (!empty($this->_generalErrors)) |
213 | 224 | { |
214 | 225 | // And delete the files 'cos they ain't going nowhere. |
215 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
216 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
226 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
227 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
217 | 228 | unlink($_FILES['attachment']['tmp_name'][$n]); |
229 | + } |
|
218 | 230 | |
219 | 231 | $_FILES['attachment']['tmp_name'] = array(); |
220 | 232 | |
@@ -225,26 +237,29 @@ discard block |
||
225 | 237 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
226 | 238 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
227 | 239 | { |
228 | - if ($_FILES['attachment']['name'][$n] == '') |
|
229 | - continue; |
|
240 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
241 | + continue; |
|
242 | + } |
|
230 | 243 | |
231 | 244 | // First, let's first check for PHP upload errors. |
232 | 245 | $errors = array(); |
233 | 246 | if (!empty($_FILES['attachment']['error'][$n])) |
234 | 247 | { |
235 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
236 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
237 | - |
|
238 | - else |
|
239 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
248 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
249 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
250 | + } else { |
|
251 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
252 | + } |
|
240 | 253 | |
241 | 254 | // Log this one, because... |
242 | - if ($_FILES['attachment']['error'][$n] == 6) |
|
243 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
255 | + if ($_FILES['attachment']['error'][$n] == 6) { |
|
256 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
257 | + } |
|
244 | 258 | |
245 | 259 | // Weird, no errors were cached, still fill out a generic one. |
246 | - if (empty($errors)) |
|
247 | - $errors[] = 'attach_php_error'; |
|
260 | + if (empty($errors)) { |
|
261 | + $errors[] = 'attach_php_error'; |
|
262 | + } |
|
248 | 263 | } |
249 | 264 | |
250 | 265 | // Try to move and rename the file before doing any more checks on it. |
@@ -256,8 +271,9 @@ discard block |
||
256 | 271 | { |
257 | 272 | // The reported MIME type of the attachment might not be reliable. |
258 | 273 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
259 | - if (function_exists('mime_content_type')) |
|
260 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
274 | + if (function_exists('mime_content_type')) { |
|
275 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
276 | + } |
|
261 | 277 | |
262 | 278 | $_SESSION['temp_attachments'][$attachID] = array( |
263 | 279 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -269,16 +285,18 @@ discard block |
||
269 | 285 | ); |
270 | 286 | |
271 | 287 | // Move the file to the attachments folder with a temp name for now. |
272 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
273 | - smf_chmod($destName, 0644); |
|
288 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
289 | + smf_chmod($destName, 0644); |
|
290 | + } |
|
274 | 291 | |
275 | 292 | // This is madness!! |
276 | 293 | else |
277 | 294 | { |
278 | 295 | // File couldn't be moved. |
279 | 296 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
280 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
281 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
297 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
298 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
299 | + } |
|
282 | 300 | } |
283 | 301 | } |
284 | 302 | |
@@ -291,13 +309,15 @@ discard block |
||
291 | 309 | 'errors' => $errors, |
292 | 310 | ); |
293 | 311 | |
294 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
295 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
312 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
313 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
314 | + } |
|
296 | 315 | } |
297 | 316 | |
298 | 317 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
299 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
300 | - attachmentChecks($attachID); |
|
318 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
319 | + attachmentChecks($attachID); |
|
320 | + } |
|
301 | 321 | } |
302 | 322 | |
303 | 323 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
@@ -344,14 +364,15 @@ discard block |
||
344 | 364 | |
345 | 365 | $_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID']; |
346 | 366 | |
347 | - if (!empty($attachmentOptions['thumb'])) |
|
348 | - $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
367 | + if (!empty($attachmentOptions['thumb'])) { |
|
368 | + $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
369 | + } |
|
349 | 370 | |
350 | - if ($this->_msg) |
|
351 | - assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
371 | + if ($this->_msg) { |
|
372 | + assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
373 | + } |
|
352 | 374 | } |
353 | - } |
|
354 | - else |
|
375 | + } else |
|
355 | 376 | { |
356 | 377 | // Sort out the errors for display and delete any associated files. |
357 | 378 | $log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file'); |
@@ -363,14 +384,16 @@ discard block |
||
363 | 384 | if (!is_array($error)) |
364 | 385 | { |
365 | 386 | $attachmentOptions['errors'][] = $txt[$error]; |
366 | - if (in_array($error, $log_these)) |
|
367 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
387 | + if (in_array($error, $log_these)) { |
|
388 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
389 | + } |
|
390 | + } else { |
|
391 | + $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
368 | 392 | } |
369 | - else |
|
370 | - $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
371 | 393 | } |
372 | - if (file_exists($attachment['tmp_name'])) |
|
373 | - unlink($attachment['tmp_name']); |
|
394 | + if (file_exists($attachment['tmp_name'])) { |
|
395 | + unlink($attachment['tmp_name']); |
|
396 | + } |
|
374 | 397 | } |
375 | 398 | |
376 | 399 | // Regardless of errors, pass the results. |
@@ -378,8 +401,9 @@ discard block |
||
378 | 401 | } |
379 | 402 | |
380 | 403 | // Temp save this on the db. |
381 | - if (!empty($_SESSION['already_attached'])) |
|
382 | - $this->_attachSuccess = $_SESSION['already_attached']; |
|
404 | + if (!empty($_SESSION['already_attached'])) { |
|
405 | + $this->_attachSuccess = $_SESSION['already_attached']; |
|
406 | + } |
|
383 | 407 | |
384 | 408 | unset($_SESSION['temp_attachments']); |
385 | 409 | } |
@@ -399,14 +423,16 @@ discard block |
||
399 | 423 | if ($this->_sa == 'add') |
400 | 424 | { |
401 | 425 | // Is there any generic errors? made some sense out of them! |
402 | - if ($this->_generalErrors) |
|
403 | - foreach ($this->_generalErrors as $k => $v) |
|
426 | + if ($this->_generalErrors) { |
|
427 | + foreach ($this->_generalErrors as $k => $v) |
|
404 | 428 | $this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]); |
429 | + } |
|
405 | 430 | |
406 | 431 | // Gotta urlencode the filename. |
407 | - if ($this->_attachResults) |
|
408 | - foreach ($this->_attachResults as $k => $v) |
|
432 | + if ($this->_attachResults) { |
|
433 | + foreach ($this->_attachResults as $k => $v) |
|
409 | 434 | $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
435 | + } |
|
410 | 436 | |
411 | 437 | $this->_response = array( |
412 | 438 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -415,9 +441,10 @@ discard block |
||
415 | 441 | } |
416 | 442 | |
417 | 443 | // Rest of us mere mortals gets no special treatment... |
418 | - elseif (!empty($data)) |
|
419 | - if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
444 | + elseif (!empty($data)) { |
|
445 | + if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
420 | 446 | $this->_response['text'] = $txt[$data['text']]; |
447 | + } |
|
421 | 448 | } |
422 | 449 | |
423 | 450 | protected function sendResponse() |
@@ -426,11 +453,11 @@ discard block |
||
426 | 453 | |
427 | 454 | ob_end_clean(); |
428 | 455 | |
429 | - if (!empty($modSettings['CompressedOutput'])) |
|
430 | - @ob_start('ob_gzhandler'); |
|
431 | - |
|
432 | - else |
|
433 | - ob_start(); |
|
456 | + if (!empty($modSettings['CompressedOutput'])) { |
|
457 | + @ob_start('ob_gzhandler'); |
|
458 | + } else { |
|
459 | + ob_start(); |
|
460 | + } |
|
434 | 461 | |
435 | 462 | // Set the header. |
436 | 463 | header('Content-Type: application/json; charset='. $context['character_set'] .''); |
@@ -17,25 +17,29 @@ discard block |
||
17 | 17 | ); |
18 | 18 | |
19 | 19 | // No file? Thats bad. |
20 | -if (!isset($_SERVER['argv'], $_SERVER['argv'][1])) |
|
20 | +if (!isset($_SERVER['argv'], $_SERVER['argv'][1])) { |
|
21 | 21 | die('Error: No File specified' . "\n"); |
22 | +} |
|
22 | 23 | |
23 | 24 | // The file has to exist. |
24 | 25 | $currentFile = $_SERVER['argv'][1]; |
25 | -if (!file_exists($currentFile)) |
|
26 | +if (!file_exists($currentFile)) { |
|
26 | 27 | die('Error: File does not exist' . "\n"); |
28 | +} |
|
27 | 29 | |
28 | 30 | // Is this ignored? |
29 | -foreach ($ignoreFiles as $if) |
|
31 | +foreach ($ignoreFiles as $if) { |
|
30 | 32 | if (preg_match('~' . $if . '~i', $currentFile)) |
31 | 33 | die; |
34 | +} |
|
32 | 35 | |
33 | 36 | // Lets get the main index.php for $forum_version and $software_year. |
34 | 37 | $upgradeFile = fopen('./other/upgrade.php', 'r'); |
35 | 38 | $upgradeContents = fread($upgradeFile, 500); |
36 | 39 | |
37 | -if (!preg_match('~define\(\'SMF_LANG_VERSION\', \'([^\']+)\'\);~i', $upgradeContents, $versionResults)) |
|
40 | +if (!preg_match('~define\(\'SMF_LANG_VERSION\', \'([^\']+)\'\);~i', $upgradeContents, $versionResults)) { |
|
38 | 41 | die('Error: Could not locate SMF_LANG_VERSION' . "\n"); |
42 | +} |
|
39 | 43 | $currentVersion = $versionResults[1]; |
40 | 44 | |
41 | 45 | $file = fopen($currentFile, 'r'); |
@@ -44,15 +48,18 @@ discard block |
||
44 | 48 | |
45 | 49 | // Just see if the basic match is there. |
46 | 50 | $match = '// Version: ' . $currentVersion; |
47 | -if (!preg_match('~' . $match . '~i', $contents)) |
|
51 | +if (!preg_match('~' . $match . '~i', $contents)) { |
|
48 | 52 | die('Error: The version is missing or incorrect in ' . $currentFile . "\n"); |
53 | +} |
|
49 | 54 | |
50 | 55 | // Get the file prefix. |
51 | 56 | preg_match('~([A-Za-z]+)\.english\.php~i', $currentFile, $fileMatch); |
52 | -if (empty($fileMatch)) |
|
57 | +if (empty($fileMatch)) { |
|
53 | 58 | die('Error: Could not locate locate the file name in ' . $currentFile . "\n"); |
59 | +} |
|
54 | 60 | |
55 | 61 | // Now match that prefix in a more strict mode. |
56 | 62 | $match = '// Version: ' . $currentVersion . '; ' . $fileMatch[1]; |
57 | -if (!preg_match('~' . $match . '~i', $contents)) |
|
58 | - die('Error: The version with file name is missing or incorrect in ' . $currentFile . "\n"); |
|
59 | 63 | \ No newline at end of file |
64 | +if (!preg_match('~' . $match . '~i', $contents)) { |
|
65 | + die('Error: The version with file name is missing or incorrect in ' . $currentFile . "\n"); |
|
66 | +} |
@@ -47,29 +47,34 @@ discard block |
||
47 | 47 | ); |
48 | 48 | |
49 | 49 | // No file? Thats bad. |
50 | -if (!isset($_SERVER['argv'], $_SERVER['argv'][1])) |
|
50 | +if (!isset($_SERVER['argv'], $_SERVER['argv'][1])) { |
|
51 | 51 | die('Error: No File specified' . "\n"); |
52 | +} |
|
52 | 53 | |
53 | 54 | // The file has to exist. |
54 | 55 | $currentFile = $_SERVER['argv'][1]; |
55 | -if (!file_exists($currentFile)) |
|
56 | +if (!file_exists($currentFile)) { |
|
56 | 57 | die('Error: File does not exist' . "\n"); |
58 | +} |
|
57 | 59 | |
58 | 60 | // Is this ignored? |
59 | -foreach ($ignoreFiles as $if) |
|
61 | +foreach ($ignoreFiles as $if) { |
|
60 | 62 | if (preg_match('~' . $if . '~i', $currentFile)) |
61 | 63 | die; |
64 | +} |
|
62 | 65 | |
63 | 66 | // Lets get the main index.php for $forum_version and $software_year. |
64 | 67 | $indexFile = fopen('./index.php', 'r'); |
65 | 68 | $indexContents = fread($indexFile, 850); |
66 | 69 | |
67 | -if (!preg_match('~\$forum_version = \'SMF ([^\']+)\';~i', $indexContents, $versionResults)) |
|
70 | +if (!preg_match('~\$forum_version = \'SMF ([^\']+)\';~i', $indexContents, $versionResults)) { |
|
68 | 71 | die('Error: Could not locate $forum_version' . "\n"); |
72 | +} |
|
69 | 73 | $currentVersion = $versionResults[1]; |
70 | 74 | |
71 | -if (!preg_match('~\$software_year = \'(\d{4})\';~i', $indexContents, $yearResults)) |
|
75 | +if (!preg_match('~\$software_year = \'(\d{4})\';~i', $indexContents, $yearResults)) { |
|
72 | 76 | die('Error: Could not locate $software_year' . "\n"); |
77 | +} |
|
73 | 78 | $currentSoftwareYear = (int) $yearResults[1]; |
74 | 79 | |
75 | 80 | $file = fopen($currentFile, 'r'); |
@@ -90,17 +95,20 @@ discard block |
||
90 | 95 | ); |
91 | 96 | |
92 | 97 | // Just see if the license is there. |
93 | -if (!preg_match('~' . implode('', $match) . '~i', $contents)) |
|
98 | +if (!preg_match('~' . implode('', $match) . '~i', $contents)) { |
|
94 | 99 | die('Error: License File is invalid or not found in ' . $currentFile . "\n"); |
100 | +} |
|
95 | 101 | |
96 | 102 | // Check the year is correct. |
97 | 103 | $yearMatch = $match; |
98 | 104 | $yearMatch[4] = ' \* @copyright ' . $currentSoftwareYear . ' Simple Machines and individual contributors' . '[\r]?\n'; |
99 | -if (!preg_match('~' . implode('', $yearMatch) . '~i', $contents)) |
|
105 | +if (!preg_match('~' . implode('', $yearMatch) . '~i', $contents)) { |
|
100 | 106 | die('Error: The software year is incorrect in ' . $currentFile . "\n"); |
107 | +} |
|
101 | 108 | |
102 | 109 | // Check the version is correct. |
103 | 110 | $versionMatch = $match; |
104 | 111 | $versionMatch[7] = ' \* @version ' . $currentVersion . '[\r]?\n'; |
105 | -if (!preg_match('~' . implode('', $versionMatch) . '~i', $contents)) |
|
106 | - die('Error: The version is incorrect in ' . $currentFile . "\n"); |
|
107 | 112 | \ No newline at end of file |
113 | +if (!preg_match('~' . implode('', $versionMatch) . '~i', $contents)) { |
|
114 | + die('Error: The version is incorrect in ' . $currentFile . "\n"); |
|
115 | +} |
@@ -21,6 +21,7 @@ |
||
21 | 21 | { |
22 | 22 | // Try 2. |
23 | 23 | $result2 = stripos($lastLine, 'Signed by'); |
24 | - if ($result2 === false) |
|
25 | - die('Error: Signed-off-by not found in commit message [' . $lastLine . ']' . '[' . $message . ']' . "\n"); |
|
26 | -} |
|
27 | 24 | \ No newline at end of file |
25 | + if ($result2 === false) { |
|
26 | + die('Error: Signed-off-by not found in commit message [' . $lastLine . ']' . '[' . $message . ']' . "\n"); |
|
27 | + } |
|
28 | + } |
|
28 | 29 | \ No newline at end of file |