@@ -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']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc') |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_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,49 +222,55 @@ 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 'float': |
| 250 | - if (!is_numeric($replacement)) |
|
| 251 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 271 | + if (!is_numeric($replacement)) { |
|
| 272 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 273 | + } |
|
| 252 | 274 | return (string) (float) $replacement; |
| 253 | 275 | break; |
| 254 | 276 | |
@@ -262,32 +284,37 @@ discard block |
||
| 262 | 284 | break; |
| 263 | 285 | |
| 264 | 286 | case 'inet': |
| 265 | - if ($replacement == 'null' || $replacement == '') |
|
| 266 | - return 'null'; |
|
| 267 | - if (!isValidIP($replacement)) |
|
| 268 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 287 | + if ($replacement == 'null' || $replacement == '') { |
|
| 288 | + return 'null'; |
|
| 289 | + } |
|
| 290 | + if (!isValidIP($replacement)) { |
|
| 291 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 292 | + } |
|
| 269 | 293 | //we don't use the native support of mysql > 5.6.2 |
| 270 | 294 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 271 | 295 | |
| 272 | 296 | case 'array_inet': |
| 273 | 297 | if (is_array($replacement)) |
| 274 | 298 | { |
| 275 | - if (empty($replacement)) |
|
| 276 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 299 | + if (empty($replacement)) { |
|
| 300 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 301 | + } |
|
| 277 | 302 | |
| 278 | 303 | foreach ($replacement as $key => $value) |
| 279 | 304 | { |
| 280 | - if ($replacement == 'null' || $replacement == '') |
|
| 281 | - $replacement[$key] = 'null'; |
|
| 282 | - if (!isValidIP($value)) |
|
| 283 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 305 | + if ($replacement == 'null' || $replacement == '') { |
|
| 306 | + $replacement[$key] = 'null'; |
|
| 307 | + } |
|
| 308 | + if (!isValidIP($value)) { |
|
| 309 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 310 | + } |
|
| 284 | 311 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 285 | 312 | } |
| 286 | 313 | |
| 287 | 314 | return implode(', ', $replacement); |
| 315 | + } else { |
|
| 316 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 288 | 317 | } |
| 289 | - else |
|
| 290 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 291 | 318 | break; |
| 292 | 319 | |
| 293 | 320 | default: |
@@ -363,22 +390,25 @@ discard block |
||
| 363 | 390 | // Are we in SSI mode? If so try that username and password first |
| 364 | 391 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 365 | 392 | { |
| 366 | - if (empty($db_persist)) |
|
| 367 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 368 | - else |
|
| 369 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 393 | + if (empty($db_persist)) { |
|
| 394 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 395 | + } else { |
|
| 396 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 397 | + } |
|
| 370 | 398 | } |
| 371 | 399 | // Fall back to the regular username and password if need be |
| 372 | 400 | if (!$db_connection) |
| 373 | 401 | { |
| 374 | - if (empty($db_persist)) |
|
| 375 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 376 | - else |
|
| 377 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 402 | + if (empty($db_persist)) { |
|
| 403 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 404 | + } else { |
|
| 405 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 406 | + } |
|
| 378 | 407 | } |
| 379 | 408 | |
| 380 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 381 | - $db_connection = false; |
|
| 409 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 410 | + $db_connection = false; |
|
| 411 | + } |
|
| 382 | 412 | |
| 383 | 413 | $connection = $db_connection; |
| 384 | 414 | } |
@@ -386,18 +416,20 @@ discard block |
||
| 386 | 416 | // One more query.... |
| 387 | 417 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 388 | 418 | |
| 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__); |
|
| 419 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 420 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 421 | + } |
|
| 391 | 422 | |
| 392 | 423 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 393 | 424 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 394 | 425 | { |
| 395 | 426 | // Add before LIMIT |
| 396 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 397 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 398 | - else |
|
| 399 | - // Append it. |
|
| 427 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 428 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 429 | + } else { |
|
| 430 | + // Append it. |
|
| 400 | 431 | $db_string .= "\n\t\t\tORDER BY null"; |
| 432 | + } |
|
| 401 | 433 | } |
| 402 | 434 | |
| 403 | 435 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -419,8 +451,9 @@ discard block |
||
| 419 | 451 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 420 | 452 | |
| 421 | 453 | // Initialize $db_cache if not already initialized. |
| 422 | - if (!isset($db_cache)) |
|
| 423 | - $db_cache = array(); |
|
| 454 | + if (!isset($db_cache)) { |
|
| 455 | + $db_cache = array(); |
|
| 456 | + } |
|
| 424 | 457 | |
| 425 | 458 | if (!empty($_SESSION['debug_redirect'])) |
| 426 | 459 | { |
@@ -446,17 +479,18 @@ discard block |
||
| 446 | 479 | while (true) |
| 447 | 480 | { |
| 448 | 481 | $pos = strpos($db_string, '\'', $pos + 1); |
| 449 | - if ($pos === false) |
|
| 450 | - break; |
|
| 482 | + if ($pos === false) { |
|
| 483 | + break; |
|
| 484 | + } |
|
| 451 | 485 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 452 | 486 | |
| 453 | 487 | while (true) |
| 454 | 488 | { |
| 455 | 489 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 456 | 490 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 457 | - if ($pos1 === false) |
|
| 458 | - break; |
|
| 459 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 491 | + if ($pos1 === false) { |
|
| 492 | + break; |
|
| 493 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 460 | 494 | { |
| 461 | 495 | $pos = $pos1; |
| 462 | 496 | break; |
@@ -472,29 +506,35 @@ discard block |
||
| 472 | 506 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 473 | 507 | |
| 474 | 508 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 475 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 476 | - $fail = true; |
|
| 509 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 510 | + $fail = true; |
|
| 511 | + } |
|
| 477 | 512 | // Trying to change passwords, slow us down, or something? |
| 478 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 479 | - $fail = true; |
|
| 480 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 481 | - $fail = true; |
|
| 513 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 514 | + $fail = true; |
|
| 515 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 516 | + $fail = true; |
|
| 517 | + } |
|
| 482 | 518 | |
| 483 | - if (!empty($fail) && function_exists('log_error')) |
|
| 484 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 519 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 520 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 521 | + } |
|
| 485 | 522 | } |
| 486 | 523 | |
| 487 | - if (empty($db_unbuffered)) |
|
| 488 | - $ret = @mysqli_query($connection, $db_string); |
|
| 489 | - else |
|
| 490 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 524 | + if (empty($db_unbuffered)) { |
|
| 525 | + $ret = @mysqli_query($connection, $db_string); |
|
| 526 | + } else { |
|
| 527 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 528 | + } |
|
| 491 | 529 | |
| 492 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 493 | - $ret = smf_db_error($db_string, $connection); |
|
| 530 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 531 | + $ret = smf_db_error($db_string, $connection); |
|
| 532 | + } |
|
| 494 | 533 | |
| 495 | 534 | // Debugging. |
| 496 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 497 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 535 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 536 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 537 | + } |
|
| 498 | 538 | |
| 499 | 539 | return $ret; |
| 500 | 540 | } |
@@ -543,12 +583,13 @@ discard block |
||
| 543 | 583 | // Decide which connection to use |
| 544 | 584 | $connection = $connection === null ? $db_connection : $connection; |
| 545 | 585 | |
| 546 | - if ($type == 'begin') |
|
| 547 | - return @mysqli_query($connection, 'BEGIN'); |
|
| 548 | - elseif ($type == 'rollback') |
|
| 549 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
| 550 | - elseif ($type == 'commit') |
|
| 551 | - return @mysqli_query($connection, 'COMMIT'); |
|
| 586 | + if ($type == 'begin') { |
|
| 587 | + return @mysqli_query($connection, 'BEGIN'); |
|
| 588 | + } elseif ($type == 'rollback') { |
|
| 589 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
| 590 | + } elseif ($type == 'commit') { |
|
| 591 | + return @mysqli_query($connection, 'COMMIT'); |
|
| 592 | + } |
|
| 552 | 593 | |
| 553 | 594 | return false; |
| 554 | 595 | } |
@@ -588,8 +629,9 @@ discard block |
||
| 588 | 629 | // 2013: Lost connection to server during query. |
| 589 | 630 | |
| 590 | 631 | // Log the error. |
| 591 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 592 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 632 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 633 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 634 | + } |
|
| 593 | 635 | |
| 594 | 636 | // Database error auto fixing ;). |
| 595 | 637 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -598,8 +640,9 @@ discard block |
||
| 598 | 640 | $old_cache = @$modSettings['cache_enable']; |
| 599 | 641 | $modSettings['cache_enable'] = '1'; |
| 600 | 642 | |
| 601 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 602 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 643 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 644 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 645 | + } |
|
| 603 | 646 | |
| 604 | 647 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 605 | 648 | { |
@@ -615,8 +658,9 @@ discard block |
||
| 615 | 658 | foreach ($tables as $table) |
| 616 | 659 | { |
| 617 | 660 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 618 | - if (trim($table) != '') |
|
| 619 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 661 | + if (trim($table) != '') { |
|
| 662 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 663 | + } |
|
| 620 | 664 | } |
| 621 | 665 | } |
| 622 | 666 | |
@@ -625,8 +669,9 @@ discard block |
||
| 625 | 669 | // Table crashed. Let's try to fix it. |
| 626 | 670 | elseif ($query_errno == 1016) |
| 627 | 671 | { |
| 628 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 629 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 672 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 673 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 674 | + } |
|
| 630 | 675 | } |
| 631 | 676 | // Indexes crashed. Should be easy to fix! |
| 632 | 677 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -645,13 +690,15 @@ discard block |
||
| 645 | 690 | |
| 646 | 691 | // Make a note of the REPAIR... |
| 647 | 692 | cache_put_data('db_last_error', time(), 600); |
| 648 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 649 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 693 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 694 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 695 | + } |
|
| 650 | 696 | |
| 651 | 697 | // Attempt to find and repair the broken table. |
| 652 | - foreach ($fix_tables as $table) |
|
| 653 | - $smcFunc['db_query']('', " |
|
| 698 | + foreach ($fix_tables as $table) { |
|
| 699 | + $smcFunc['db_query']('', " |
|
| 654 | 700 | REPAIR TABLE $table", false, false); |
| 701 | + } |
|
| 655 | 702 | |
| 656 | 703 | // And send off an email! |
| 657 | 704 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -660,11 +707,12 @@ discard block |
||
| 660 | 707 | |
| 661 | 708 | // Try the query again...? |
| 662 | 709 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 663 | - if ($ret !== false) |
|
| 664 | - return $ret; |
|
| 710 | + if ($ret !== false) { |
|
| 711 | + return $ret; |
|
| 712 | + } |
|
| 713 | + } else { |
|
| 714 | + $modSettings['cache_enable'] = $old_cache; |
|
| 665 | 715 | } |
| 666 | - else |
|
| 667 | - $modSettings['cache_enable'] = $old_cache; |
|
| 668 | 716 | |
| 669 | 717 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 670 | 718 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -674,22 +722,25 @@ discard block |
||
| 674 | 722 | // Are we in SSI mode? If so try that username and password first |
| 675 | 723 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 676 | 724 | { |
| 677 | - if (empty($db_persist)) |
|
| 678 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 679 | - else |
|
| 680 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 725 | + if (empty($db_persist)) { |
|
| 726 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 727 | + } else { |
|
| 728 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 729 | + } |
|
| 681 | 730 | } |
| 682 | 731 | // Fall back to the regular username and password if need be |
| 683 | 732 | if (!$db_connection) |
| 684 | 733 | { |
| 685 | - if (empty($db_persist)) |
|
| 686 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 687 | - else |
|
| 688 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 734 | + if (empty($db_persist)) { |
|
| 735 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 736 | + } else { |
|
| 737 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 738 | + } |
|
| 689 | 739 | } |
| 690 | 740 | |
| 691 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 692 | - $db_connection = false; |
|
| 741 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 742 | + $db_connection = false; |
|
| 743 | + } |
|
| 693 | 744 | } |
| 694 | 745 | |
| 695 | 746 | if ($db_connection) |
@@ -700,24 +751,27 @@ discard block |
||
| 700 | 751 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 701 | 752 | |
| 702 | 753 | $new_errno = mysqli_errno($db_connection); |
| 703 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 704 | - break; |
|
| 754 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 755 | + break; |
|
| 756 | + } |
|
| 705 | 757 | } |
| 706 | 758 | |
| 707 | 759 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 708 | - if ($ret !== false) |
|
| 709 | - return $ret; |
|
| 760 | + if ($ret !== false) { |
|
| 761 | + return $ret; |
|
| 762 | + } |
|
| 710 | 763 | } |
| 711 | 764 | } |
| 712 | 765 | // Are they out of space, perhaps? |
| 713 | 766 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 714 | 767 | { |
| 715 | - if (!isset($txt)) |
|
| 716 | - $query_error .= ' - check database storage space.'; |
|
| 717 | - else |
|
| 768 | + if (!isset($txt)) { |
|
| 769 | + $query_error .= ' - check database storage space.'; |
|
| 770 | + } else |
|
| 718 | 771 | { |
| 719 | - if (!isset($txt['mysql_error_space'])) |
|
| 720 | - loadLanguage('Errors'); |
|
| 772 | + if (!isset($txt['mysql_error_space'])) { |
|
| 773 | + loadLanguage('Errors'); |
|
| 774 | + } |
|
| 721 | 775 | |
| 722 | 776 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 723 | 777 | } |
@@ -725,15 +779,17 @@ discard block |
||
| 725 | 779 | } |
| 726 | 780 | |
| 727 | 781 | // Nothing's defined yet... just die with it. |
| 728 | - if (empty($context) || empty($txt)) |
|
| 729 | - die($query_error); |
|
| 782 | + if (empty($context) || empty($txt)) { |
|
| 783 | + die($query_error); |
|
| 784 | + } |
|
| 730 | 785 | |
| 731 | 786 | // Show an error message, if possible. |
| 732 | 787 | $context['error_title'] = $txt['database_error']; |
| 733 | - if (allowedTo('admin_forum')) |
|
| 734 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 735 | - else |
|
| 736 | - $context['error_message'] = $txt['try_again']; |
|
| 788 | + if (allowedTo('admin_forum')) { |
|
| 789 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 790 | + } else { |
|
| 791 | + $context['error_message'] = $txt['try_again']; |
|
| 792 | + } |
|
| 737 | 793 | |
| 738 | 794 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 739 | 795 | { |
@@ -762,25 +818,28 @@ discard block |
||
| 762 | 818 | $connection = $connection === null ? $db_connection : $connection; |
| 763 | 819 | |
| 764 | 820 | // With nothing to insert, simply return. |
| 765 | - if (empty($data)) |
|
| 766 | - return; |
|
| 821 | + if (empty($data)) { |
|
| 822 | + return; |
|
| 823 | + } |
|
| 767 | 824 | |
| 768 | 825 | // Replace the prefix holder with the actual prefix. |
| 769 | 826 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 770 | 827 | |
| 771 | 828 | // Inserting data as a single row can be done as a single array. |
| 772 | - if (!is_array($data[array_rand($data)])) |
|
| 773 | - $data = array($data); |
|
| 829 | + if (!is_array($data[array_rand($data)])) { |
|
| 830 | + $data = array($data); |
|
| 831 | + } |
|
| 774 | 832 | |
| 775 | 833 | // Create the mold for a single row insert. |
| 776 | 834 | $insertData = '('; |
| 777 | 835 | foreach ($columns as $columnName => $type) |
| 778 | 836 | { |
| 779 | 837 | // Are we restricting the length? |
| 780 | - if (strpos($type, 'string-') !== false) |
|
| 781 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 782 | - else |
|
| 783 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 838 | + if (strpos($type, 'string-') !== false) { |
|
| 839 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 840 | + } else { |
|
| 841 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 842 | + } |
|
| 784 | 843 | } |
| 785 | 844 | $insertData = substr($insertData, 0, -2) . ')'; |
| 786 | 845 | |
@@ -789,8 +848,9 @@ discard block |
||
| 789 | 848 | |
| 790 | 849 | // Here's where the variables are injected to the query. |
| 791 | 850 | $insertRows = array(); |
| 792 | - foreach ($data as $dataRow) |
|
| 793 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 851 | + foreach ($data as $dataRow) { |
|
| 852 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 853 | + } |
|
| 794 | 854 | |
| 795 | 855 | // Determine the method of insertion. |
| 796 | 856 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -821,8 +881,9 @@ discard block |
||
| 821 | 881 | */ |
| 822 | 882 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 823 | 883 | { |
| 824 | - if (empty($log_message)) |
|
| 825 | - $log_message = $error_message; |
|
| 884 | + if (empty($log_message)) { |
|
| 885 | + $log_message = $error_message; |
|
| 886 | + } |
|
| 826 | 887 | |
| 827 | 888 | foreach (debug_backtrace() as $step) |
| 828 | 889 | { |
@@ -841,12 +902,14 @@ discard block |
||
| 841 | 902 | } |
| 842 | 903 | |
| 843 | 904 | // A special case - we want the file and line numbers for debugging. |
| 844 | - if ($error_type == 'return') |
|
| 845 | - return array($file, $line); |
|
| 905 | + if ($error_type == 'return') { |
|
| 906 | + return array($file, $line); |
|
| 907 | + } |
|
| 846 | 908 | |
| 847 | 909 | // Is always a critical error. |
| 848 | - if (function_exists('log_error')) |
|
| 849 | - log_error($log_message, 'critical', $file, $line); |
|
| 910 | + if (function_exists('log_error')) { |
|
| 911 | + log_error($log_message, 'critical', $file, $line); |
|
| 912 | + } |
|
| 850 | 913 | |
| 851 | 914 | if (function_exists('fatal_error')) |
| 852 | 915 | { |
@@ -854,12 +917,12 @@ discard block |
||
| 854 | 917 | |
| 855 | 918 | // Cannot continue... |
| 856 | 919 | exit; |
| 920 | + } elseif ($error_type) { |
|
| 921 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 922 | + } else { |
|
| 923 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 924 | + } |
|
| 857 | 925 | } |
| 858 | - elseif ($error_type) |
|
| 859 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 860 | - else |
|
| 861 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 862 | -} |
|
| 863 | 926 | |
| 864 | 927 | /** |
| 865 | 928 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -876,10 +939,11 @@ discard block |
||
| 876 | 939 | '\\' => '\\\\', |
| 877 | 940 | ); |
| 878 | 941 | |
| 879 | - if ($translate_human_wildcards) |
|
| 880 | - $replacements += array( |
|
| 942 | + if ($translate_human_wildcards) { |
|
| 943 | + $replacements += array( |
|
| 881 | 944 | '*' => '%', |
| 882 | 945 | ); |
| 946 | + } |
|
| 883 | 947 | |
| 884 | 948 | return strtr($string, $replacements); |
| 885 | 949 | } |
@@ -893,8 +957,9 @@ discard block |
||
| 893 | 957 | */ |
| 894 | 958 | function smf_is_resource($result) |
| 895 | 959 | { |
| 896 | - if ($result instanceof mysqli_result) |
|
| 897 | - return true; |
|
| 960 | + if ($result instanceof mysqli_result) { |
|
| 961 | + return true; |
|
| 962 | + } |
|
| 898 | 963 | |
| 899 | 964 | return false; |
| 900 | 965 | } |
@@ -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']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') { |
|
| 38 | + $smcFunc += array( |
|
| 38 | 39 | 'db_query' => 'smf_db_query', |
| 39 | 40 | 'db_quote' => 'smf_db_quote', |
| 40 | 41 | 'db_fetch_assoc' => 'mysql_fetch_assoc', |
@@ -58,36 +59,42 @@ discard block |
||
| 58 | 59 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 59 | 60 | 'db_is_resource' => 'is_resource', |
| 60 | 61 | ); |
| 62 | + } |
|
| 61 | 63 | |
| 62 | - if (!empty($db_options['port'])) |
|
| 63 | - $db_server .= ':' . $db_options['port']; |
|
| 64 | + if (!empty($db_options['port'])) { |
|
| 65 | + $db_server .= ':' . $db_options['port']; |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | $flags = 2; //#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ |
| 66 | 69 | |
| 67 | - if (!empty($db_options['persist'])) |
|
| 68 | - $connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags); |
|
| 69 | - else |
|
| 70 | - $connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags); |
|
| 70 | + if (!empty($db_options['persist'])) { |
|
| 71 | + $connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags); |
|
| 72 | + } else { |
|
| 73 | + $connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags); |
|
| 74 | + } |
|
| 71 | 75 | |
| 72 | 76 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 73 | 77 | if (!$connection) |
| 74 | 78 | { |
| 75 | - if (!empty($db_options['non_fatal'])) |
|
| 76 | - return null; |
|
| 77 | - else |
|
| 78 | - display_db_error(); |
|
| 79 | + if (!empty($db_options['non_fatal'])) { |
|
| 80 | + return null; |
|
| 81 | + } else { |
|
| 82 | + display_db_error(); |
|
| 83 | + } |
|
| 79 | 84 | } |
| 80 | 85 | |
| 81 | 86 | // Select the database, unless told not to |
| 82 | - if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) |
|
| 83 | - display_db_error(); |
|
| 87 | + if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) { |
|
| 88 | + display_db_error(); |
|
| 89 | + } |
|
| 84 | 90 | |
| 85 | 91 | // This makes it possible to have SMF automatically change the sql_mode and autocommit if needed. |
| 86 | - if (isset($mysql_set_mode) && $mysql_set_mode === true) |
|
| 87 | - $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 92 | + if (isset($mysql_set_mode) && $mysql_set_mode === true) { |
|
| 93 | + $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 88 | 94 | array(), |
| 89 | 95 | false |
| 90 | 96 | ); |
| 97 | + } |
|
| 91 | 98 | |
| 92 | 99 | return $connection; |
| 93 | 100 | } |
@@ -134,37 +141,46 @@ discard block |
||
| 134 | 141 | list ($values, $connection) = $db_callback; |
| 135 | 142 | |
| 136 | 143 | // Connection gone??? This should *never* happen at this point, yet it does :'( |
| 137 | - if (!is_resource($connection)) |
|
| 138 | - display_db_error(); |
|
| 144 | + if (!is_resource($connection)) { |
|
| 145 | + display_db_error(); |
|
| 146 | + } |
|
| 139 | 147 | |
| 140 | - if ($matches[1] === 'db_prefix') |
|
| 141 | - return $db_prefix; |
|
| 148 | + if ($matches[1] === 'db_prefix') { |
|
| 149 | + return $db_prefix; |
|
| 150 | + } |
|
| 142 | 151 | |
| 143 | - if ($matches[1] === 'query_see_board') |
|
| 144 | - return $user_info['query_see_board']; |
|
| 152 | + if ($matches[1] === 'query_see_board') { |
|
| 153 | + return $user_info['query_see_board']; |
|
| 154 | + } |
|
| 145 | 155 | |
| 146 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 147 | - return $user_info['query_wanna_see_board']; |
|
| 156 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 157 | + return $user_info['query_wanna_see_board']; |
|
| 158 | + } |
|
| 148 | 159 | |
| 149 | - if ($matches[1] === 'empty') |
|
| 150 | - return '\'\''; |
|
| 160 | + if ($matches[1] === 'empty') { |
|
| 161 | + return '\'\''; |
|
| 162 | + } |
|
| 151 | 163 | |
| 152 | - if (!isset($matches[2])) |
|
| 153 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 164 | + if (!isset($matches[2])) { |
|
| 165 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 166 | + } |
|
| 154 | 167 | |
| 155 | - if ($matches[1] === 'literal') |
|
| 156 | - return '\'' . mysql_real_escape_string($matches[2], $connection) . '\''; |
|
| 168 | + if ($matches[1] === 'literal') { |
|
| 169 | + return '\'' . mysql_real_escape_string($matches[2], $connection) . '\''; |
|
| 170 | + } |
|
| 157 | 171 | |
| 158 | - if (!isset($values[$matches[2]])) |
|
| 159 | - 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__); |
|
| 172 | + if (!isset($values[$matches[2]])) { |
|
| 173 | + 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__); |
|
| 174 | + } |
|
| 160 | 175 | |
| 161 | 176 | $replacement = $values[$matches[2]]; |
| 162 | 177 | |
| 163 | 178 | switch ($matches[1]) |
| 164 | 179 | { |
| 165 | 180 | case 'int': |
| 166 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 167 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 181 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 182 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 183 | + } |
|
| 168 | 184 | return (string) (int) $replacement; |
| 169 | 185 | break; |
| 170 | 186 | |
@@ -176,49 +192,55 @@ discard block |
||
| 176 | 192 | case 'array_int': |
| 177 | 193 | if (is_array($replacement)) |
| 178 | 194 | { |
| 179 | - if (empty($replacement)) |
|
| 180 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 195 | + if (empty($replacement)) { |
|
| 196 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 197 | + } |
|
| 181 | 198 | |
| 182 | 199 | foreach ($replacement as $key => $value) |
| 183 | 200 | { |
| 184 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 185 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 201 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 202 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 203 | + } |
|
| 186 | 204 | |
| 187 | 205 | $replacement[$key] = (string) (int) $value; |
| 188 | 206 | } |
| 189 | 207 | |
| 190 | 208 | return implode(', ', $replacement); |
| 209 | + } else { |
|
| 210 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 191 | 211 | } |
| 192 | - else |
|
| 193 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 194 | 212 | |
| 195 | 213 | break; |
| 196 | 214 | |
| 197 | 215 | case 'array_string': |
| 198 | 216 | if (is_array($replacement)) |
| 199 | 217 | { |
| 200 | - if (empty($replacement)) |
|
| 201 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 218 | + if (empty($replacement)) { |
|
| 219 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 220 | + } |
|
| 202 | 221 | |
| 203 | - foreach ($replacement as $key => $value) |
|
| 204 | - $replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection)); |
|
| 222 | + foreach ($replacement as $key => $value) { |
|
| 223 | + $replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection)); |
|
| 224 | + } |
|
| 205 | 225 | |
| 206 | 226 | return implode(', ', $replacement); |
| 227 | + } else { |
|
| 228 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 207 | 229 | } |
| 208 | - else |
|
| 209 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 210 | 230 | break; |
| 211 | 231 | |
| 212 | 232 | case 'date': |
| 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__); |
|
| 233 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 234 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 235 | + } else { |
|
| 236 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 237 | + } |
|
| 217 | 238 | break; |
| 218 | 239 | |
| 219 | 240 | case 'float': |
| 220 | - if (!is_numeric($replacement)) |
|
| 221 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 241 | + if (!is_numeric($replacement)) { |
|
| 242 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 243 | + } |
|
| 222 | 244 | return (string) (float) $replacement; |
| 223 | 245 | break; |
| 224 | 246 | |
@@ -232,32 +254,37 @@ discard block |
||
| 232 | 254 | break; |
| 233 | 255 | |
| 234 | 256 | case 'inet': |
| 235 | - if ($replacement == 'null' || $replacement == '') |
|
| 236 | - return 'null'; |
|
| 237 | - if (!isValidIP($replacement)) |
|
| 238 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 257 | + if ($replacement == 'null' || $replacement == '') { |
|
| 258 | + return 'null'; |
|
| 259 | + } |
|
| 260 | + if (!isValidIP($replacement)) { |
|
| 261 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 262 | + } |
|
| 239 | 263 | //we don't use the native support of mysql > 5.6.2 |
| 240 | 264 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 241 | 265 | |
| 242 | 266 | case 'array_inet': |
| 243 | 267 | if (is_array($replacement)) |
| 244 | 268 | { |
| 245 | - if (empty($replacement)) |
|
| 246 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 269 | + if (empty($replacement)) { |
|
| 270 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 271 | + } |
|
| 247 | 272 | |
| 248 | 273 | foreach ($replacement as $key => $value) |
| 249 | 274 | { |
| 250 | - if ($replacement == 'null' || $replacement == '') |
|
| 251 | - $replacement[$key] = 'null'; |
|
| 252 | - if (!isValidIP($value)) |
|
| 253 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 275 | + if ($replacement == 'null' || $replacement == '') { |
|
| 276 | + $replacement[$key] = 'null'; |
|
| 277 | + } |
|
| 278 | + if (!isValidIP($value)) { |
|
| 279 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 280 | + } |
|
| 254 | 281 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 255 | 282 | } |
| 256 | 283 | |
| 257 | 284 | return implode(', ', $replacement); |
| 285 | + } else { |
|
| 286 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 258 | 287 | } |
| 259 | - else |
|
| 260 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 261 | 288 | break; |
| 262 | 289 | |
| 263 | 290 | default: |
@@ -328,18 +355,20 @@ discard block |
||
| 328 | 355 | // One more query.... |
| 329 | 356 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 330 | 357 | |
| 331 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 332 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 358 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 359 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 360 | + } |
|
| 333 | 361 | |
| 334 | 362 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 335 | 363 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 336 | 364 | { |
| 337 | 365 | // Add before LIMIT |
| 338 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 339 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 340 | - else |
|
| 341 | - // Append it. |
|
| 366 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 367 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 368 | + } else { |
|
| 369 | + // Append it. |
|
| 342 | 370 | $db_string .= "\n\t\t\tORDER BY null"; |
| 371 | + } |
|
| 343 | 372 | } |
| 344 | 373 | |
| 345 | 374 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -361,8 +390,9 @@ discard block |
||
| 361 | 390 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 362 | 391 | |
| 363 | 392 | // Initialize $db_cache if not already initialized. |
| 364 | - if (!isset($db_cache)) |
|
| 365 | - $db_cache = array(); |
|
| 393 | + if (!isset($db_cache)) { |
|
| 394 | + $db_cache = array(); |
|
| 395 | + } |
|
| 366 | 396 | |
| 367 | 397 | if (!empty($_SESSION['debug_redirect'])) |
| 368 | 398 | { |
@@ -388,17 +418,18 @@ discard block |
||
| 388 | 418 | while (true) |
| 389 | 419 | { |
| 390 | 420 | $pos = strpos($db_string, '\'', $pos + 1); |
| 391 | - if ($pos === false) |
|
| 392 | - break; |
|
| 421 | + if ($pos === false) { |
|
| 422 | + break; |
|
| 423 | + } |
|
| 393 | 424 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 394 | 425 | |
| 395 | 426 | while (true) |
| 396 | 427 | { |
| 397 | 428 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 398 | 429 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 399 | - if ($pos1 === false) |
|
| 400 | - break; |
|
| 401 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 430 | + if ($pos1 === false) { |
|
| 431 | + break; |
|
| 432 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 402 | 433 | { |
| 403 | 434 | $pos = $pos1; |
| 404 | 435 | break; |
@@ -414,29 +445,35 @@ discard block |
||
| 414 | 445 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 415 | 446 | |
| 416 | 447 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 417 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 418 | - $fail = true; |
|
| 448 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 449 | + $fail = true; |
|
| 450 | + } |
|
| 419 | 451 | // Trying to change passwords, slow us down, or something? |
| 420 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 421 | - $fail = true; |
|
| 422 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 423 | - $fail = true; |
|
| 452 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 453 | + $fail = true; |
|
| 454 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 455 | + $fail = true; |
|
| 456 | + } |
|
| 424 | 457 | |
| 425 | - if (!empty($fail) && function_exists('log_error')) |
|
| 426 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 458 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 459 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 460 | + } |
|
| 427 | 461 | } |
| 428 | 462 | |
| 429 | - if (empty($db_unbuffered)) |
|
| 430 | - $ret = @mysql_query($db_string, $connection); |
|
| 431 | - else |
|
| 432 | - $ret = @mysql_unbuffered_query($db_string, $connection); |
|
| 463 | + if (empty($db_unbuffered)) { |
|
| 464 | + $ret = @mysql_query($db_string, $connection); |
|
| 465 | + } else { |
|
| 466 | + $ret = @mysql_unbuffered_query($db_string, $connection); |
|
| 467 | + } |
|
| 433 | 468 | |
| 434 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 435 | - $ret = smf_db_error($db_string, $connection); |
|
| 469 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 470 | + $ret = smf_db_error($db_string, $connection); |
|
| 471 | + } |
|
| 436 | 472 | |
| 437 | 473 | // Debugging. |
| 438 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 439 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 474 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 475 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 476 | + } |
|
| 440 | 477 | |
| 441 | 478 | return $ret; |
| 442 | 479 | } |
@@ -485,12 +522,13 @@ discard block |
||
| 485 | 522 | // Decide which connection to use |
| 486 | 523 | $connection = $connection === null ? $db_connection : $connection; |
| 487 | 524 | |
| 488 | - if ($type == 'begin') |
|
| 489 | - return @mysql_query('BEGIN', $connection); |
|
| 490 | - elseif ($type == 'rollback') |
|
| 491 | - return @mysql_query('ROLLBACK', $connection); |
|
| 492 | - elseif ($type == 'commit') |
|
| 493 | - return @mysql_query('COMMIT', $connection); |
|
| 525 | + if ($type == 'begin') { |
|
| 526 | + return @mysql_query('BEGIN', $connection); |
|
| 527 | + } elseif ($type == 'rollback') { |
|
| 528 | + return @mysql_query('ROLLBACK', $connection); |
|
| 529 | + } elseif ($type == 'commit') { |
|
| 530 | + return @mysql_query('COMMIT', $connection); |
|
| 531 | + } |
|
| 494 | 532 | |
| 495 | 533 | return false; |
| 496 | 534 | } |
@@ -530,8 +568,9 @@ discard block |
||
| 530 | 568 | // 2013: Lost connection to server during query. |
| 531 | 569 | |
| 532 | 570 | // Log the error. |
| 533 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 534 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 571 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 572 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 573 | + } |
|
| 535 | 574 | |
| 536 | 575 | // Database error auto fixing ;). |
| 537 | 576 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -540,8 +579,9 @@ discard block |
||
| 540 | 579 | $old_cache = @$modSettings['cache_enable']; |
| 541 | 580 | $modSettings['cache_enable'] = '1'; |
| 542 | 581 | |
| 543 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 544 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 582 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 583 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 584 | + } |
|
| 545 | 585 | |
| 546 | 586 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 547 | 587 | { |
@@ -557,8 +597,9 @@ discard block |
||
| 557 | 597 | foreach ($tables as $table) |
| 558 | 598 | { |
| 559 | 599 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 560 | - if (trim($table) != '') |
|
| 561 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 600 | + if (trim($table) != '') { |
|
| 601 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 602 | + } |
|
| 562 | 603 | } |
| 563 | 604 | } |
| 564 | 605 | |
@@ -567,8 +608,9 @@ discard block |
||
| 567 | 608 | // Table crashed. Let's try to fix it. |
| 568 | 609 | elseif ($query_errno == 1016) |
| 569 | 610 | { |
| 570 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 571 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 611 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 612 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 613 | + } |
|
| 572 | 614 | } |
| 573 | 615 | // Indexes crashed. Should be easy to fix! |
| 574 | 616 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -587,13 +629,15 @@ discard block |
||
| 587 | 629 | |
| 588 | 630 | // Make a note of the REPAIR... |
| 589 | 631 | cache_put_data('db_last_error', time(), 600); |
| 590 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 591 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 632 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 633 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 634 | + } |
|
| 592 | 635 | |
| 593 | 636 | // Attempt to find and repair the broken table. |
| 594 | - foreach ($fix_tables as $table) |
|
| 595 | - $smcFunc['db_query']('', " |
|
| 637 | + foreach ($fix_tables as $table) { |
|
| 638 | + $smcFunc['db_query']('', " |
|
| 596 | 639 | REPAIR TABLE $table", false, false); |
| 640 | + } |
|
| 597 | 641 | |
| 598 | 642 | // And send off an email! |
| 599 | 643 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -602,11 +646,12 @@ discard block |
||
| 602 | 646 | |
| 603 | 647 | // Try the query again...? |
| 604 | 648 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 605 | - if ($ret !== false) |
|
| 606 | - return $ret; |
|
| 649 | + if ($ret !== false) { |
|
| 650 | + return $ret; |
|
| 651 | + } |
|
| 652 | + } else { |
|
| 653 | + $modSettings['cache_enable'] = $old_cache; |
|
| 607 | 654 | } |
| 608 | - else |
|
| 609 | - $modSettings['cache_enable'] = $old_cache; |
|
| 610 | 655 | |
| 611 | 656 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 612 | 657 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -616,22 +661,25 @@ discard block |
||
| 616 | 661 | // Are we in SSI mode? If so try that username and password first |
| 617 | 662 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 618 | 663 | { |
| 619 | - if (empty($db_persist)) |
|
| 620 | - $db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 621 | - else |
|
| 622 | - $db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 664 | + if (empty($db_persist)) { |
|
| 665 | + $db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 666 | + } else { |
|
| 667 | + $db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 668 | + } |
|
| 623 | 669 | } |
| 624 | 670 | // Fall back to the regular username and password if need be |
| 625 | 671 | if (!$db_connection) |
| 626 | 672 | { |
| 627 | - if (empty($db_persist)) |
|
| 628 | - $db_connection = @mysql_connect($db_server, $db_user, $db_passwd); |
|
| 629 | - else |
|
| 630 | - $db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd); |
|
| 673 | + if (empty($db_persist)) { |
|
| 674 | + $db_connection = @mysql_connect($db_server, $db_user, $db_passwd); |
|
| 675 | + } else { |
|
| 676 | + $db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd); |
|
| 677 | + } |
|
| 631 | 678 | } |
| 632 | 679 | |
| 633 | - if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) |
|
| 634 | - $db_connection = false; |
|
| 680 | + if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) { |
|
| 681 | + $db_connection = false; |
|
| 682 | + } |
|
| 635 | 683 | } |
| 636 | 684 | |
| 637 | 685 | if ($db_connection) |
@@ -642,24 +690,27 @@ discard block |
||
| 642 | 690 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 643 | 691 | |
| 644 | 692 | $new_errno = mysql_errno($db_connection); |
| 645 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 646 | - break; |
|
| 693 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 694 | + break; |
|
| 695 | + } |
|
| 647 | 696 | } |
| 648 | 697 | |
| 649 | 698 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 650 | - if ($ret !== false) |
|
| 651 | - return $ret; |
|
| 699 | + if ($ret !== false) { |
|
| 700 | + return $ret; |
|
| 701 | + } |
|
| 652 | 702 | } |
| 653 | 703 | } |
| 654 | 704 | // Are they out of space, perhaps? |
| 655 | 705 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 656 | 706 | { |
| 657 | - if (!isset($txt)) |
|
| 658 | - $query_error .= ' - check database storage space.'; |
|
| 659 | - else |
|
| 707 | + if (!isset($txt)) { |
|
| 708 | + $query_error .= ' - check database storage space.'; |
|
| 709 | + } else |
|
| 660 | 710 | { |
| 661 | - if (!isset($txt['mysql_error_space'])) |
|
| 662 | - loadLanguage('Errors'); |
|
| 711 | + if (!isset($txt['mysql_error_space'])) { |
|
| 712 | + loadLanguage('Errors'); |
|
| 713 | + } |
|
| 663 | 714 | |
| 664 | 715 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 665 | 716 | } |
@@ -667,15 +718,17 @@ discard block |
||
| 667 | 718 | } |
| 668 | 719 | |
| 669 | 720 | // Nothing's defined yet... just die with it. |
| 670 | - if (empty($context) || empty($txt)) |
|
| 671 | - die($query_error); |
|
| 721 | + if (empty($context) || empty($txt)) { |
|
| 722 | + die($query_error); |
|
| 723 | + } |
|
| 672 | 724 | |
| 673 | 725 | // Show an error message, if possible. |
| 674 | 726 | $context['error_title'] = $txt['database_error']; |
| 675 | - if (allowedTo('admin_forum')) |
|
| 676 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 677 | - else |
|
| 678 | - $context['error_message'] = $txt['try_again']; |
|
| 727 | + if (allowedTo('admin_forum')) { |
|
| 728 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 729 | + } else { |
|
| 730 | + $context['error_message'] = $txt['try_again']; |
|
| 731 | + } |
|
| 679 | 732 | |
| 680 | 733 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 681 | 734 | { |
@@ -704,25 +757,28 @@ discard block |
||
| 704 | 757 | $connection = $connection === null ? $db_connection : $connection; |
| 705 | 758 | |
| 706 | 759 | // With nothing to insert, simply return. |
| 707 | - if (empty($data)) |
|
| 708 | - return; |
|
| 760 | + if (empty($data)) { |
|
| 761 | + return; |
|
| 762 | + } |
|
| 709 | 763 | |
| 710 | 764 | // Replace the prefix holder with the actual prefix. |
| 711 | 765 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 712 | 766 | |
| 713 | 767 | // Inserting data as a single row can be done as a single array. |
| 714 | - if (!is_array($data[array_rand($data)])) |
|
| 715 | - $data = array($data); |
|
| 768 | + if (!is_array($data[array_rand($data)])) { |
|
| 769 | + $data = array($data); |
|
| 770 | + } |
|
| 716 | 771 | |
| 717 | 772 | // Create the mold for a single row insert. |
| 718 | 773 | $insertData = '('; |
| 719 | 774 | foreach ($columns as $columnName => $type) |
| 720 | 775 | { |
| 721 | 776 | // Are we restricting the length? |
| 722 | - if (strpos($type, 'string-') !== false) |
|
| 723 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 724 | - else |
|
| 725 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 777 | + if (strpos($type, 'string-') !== false) { |
|
| 778 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 779 | + } else { |
|
| 780 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 781 | + } |
|
| 726 | 782 | } |
| 727 | 783 | $insertData = substr($insertData, 0, -2) . ')'; |
| 728 | 784 | |
@@ -731,8 +787,9 @@ discard block |
||
| 731 | 787 | |
| 732 | 788 | // Here's where the variables are injected to the query. |
| 733 | 789 | $insertRows = array(); |
| 734 | - foreach ($data as $dataRow) |
|
| 735 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 790 | + foreach ($data as $dataRow) { |
|
| 791 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 792 | + } |
|
| 736 | 793 | |
| 737 | 794 | // Determine the method of insertion. |
| 738 | 795 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -763,8 +820,9 @@ discard block |
||
| 763 | 820 | */ |
| 764 | 821 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 765 | 822 | { |
| 766 | - if (empty($log_message)) |
|
| 767 | - $log_message = $error_message; |
|
| 823 | + if (empty($log_message)) { |
|
| 824 | + $log_message = $error_message; |
|
| 825 | + } |
|
| 768 | 826 | |
| 769 | 827 | foreach (debug_backtrace() as $step) |
| 770 | 828 | { |
@@ -783,12 +841,14 @@ discard block |
||
| 783 | 841 | } |
| 784 | 842 | |
| 785 | 843 | // A special case - we want the file and line numbers for debugging. |
| 786 | - if ($error_type == 'return') |
|
| 787 | - return array($file, $line); |
|
| 844 | + if ($error_type == 'return') { |
|
| 845 | + return array($file, $line); |
|
| 846 | + } |
|
| 788 | 847 | |
| 789 | 848 | // Is always a critical error. |
| 790 | - if (function_exists('log_error')) |
|
| 791 | - log_error($log_message, 'critical', $file, $line); |
|
| 849 | + if (function_exists('log_error')) { |
|
| 850 | + log_error($log_message, 'critical', $file, $line); |
|
| 851 | + } |
|
| 792 | 852 | |
| 793 | 853 | if (function_exists('fatal_error')) |
| 794 | 854 | { |
@@ -796,12 +856,12 @@ discard block |
||
| 796 | 856 | |
| 797 | 857 | // Cannot continue... |
| 798 | 858 | exit; |
| 859 | + } elseif ($error_type) { |
|
| 860 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 861 | + } else { |
|
| 862 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 863 | + } |
|
| 799 | 864 | } |
| 800 | - elseif ($error_type) |
|
| 801 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 802 | - else |
|
| 803 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 804 | -} |
|
| 805 | 865 | |
| 806 | 866 | /** |
| 807 | 867 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -818,10 +878,11 @@ discard block |
||
| 818 | 878 | '\\' => '\\\\', |
| 819 | 879 | ); |
| 820 | 880 | |
| 821 | - if ($translate_human_wildcards) |
|
| 822 | - $replacements += array( |
|
| 881 | + if ($translate_human_wildcards) { |
|
| 882 | + $replacements += array( |
|
| 823 | 883 | '*' => '%', |
| 824 | 884 | ); |
| 885 | + } |
|
| 825 | 886 | |
| 826 | 887 | return strtr($string, $replacements); |
| 827 | 888 | } |
@@ -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']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') |
|
| 38 | - $smcFunc += array( |
|
| 38 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_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,49 +172,55 @@ 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 'float': |
| 206 | - if (!is_numeric($replacement)) |
|
| 207 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | + if (!is_numeric($replacement)) { |
|
| 222 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 223 | + } |
|
| 208 | 224 | return (string) (float) $replacement; |
| 209 | 225 | break; |
| 210 | 226 | |
@@ -217,31 +233,36 @@ discard block |
||
| 217 | 233 | break; |
| 218 | 234 | |
| 219 | 235 | case 'inet': |
| 220 | - if ($replacement == 'null' || $replacement == '') |
|
| 221 | - return 'null'; |
|
| 222 | - if (inet_pton($replacement) === false) |
|
| 223 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 236 | + if ($replacement == 'null' || $replacement == '') { |
|
| 237 | + return 'null'; |
|
| 238 | + } |
|
| 239 | + if (inet_pton($replacement) === false) { |
|
| 240 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 241 | + } |
|
| 224 | 242 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 225 | 243 | |
| 226 | 244 | case 'array_inet': |
| 227 | 245 | if (is_array($replacement)) |
| 228 | 246 | { |
| 229 | - if (empty($replacement)) |
|
| 230 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 247 | + if (empty($replacement)) { |
|
| 248 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 249 | + } |
|
| 231 | 250 | |
| 232 | 251 | foreach ($replacement as $key => $value) |
| 233 | 252 | { |
| 234 | - if ($replacement == 'null' || $replacement == '') |
|
| 235 | - $replacement[$key] = 'null'; |
|
| 236 | - if (!isValidIP($value)) |
|
| 237 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 253 | + if ($replacement == 'null' || $replacement == '') { |
|
| 254 | + $replacement[$key] = 'null'; |
|
| 255 | + } |
|
| 256 | + if (!isValidIP($value)) { |
|
| 257 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 258 | + } |
|
| 238 | 259 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 239 | 260 | } |
| 240 | 261 | |
| 241 | 262 | return implode(', ', $replacement); |
| 263 | + } else { |
|
| 264 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 242 | 265 | } |
| 243 | - else |
|
| 244 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 245 | 266 | break; |
| 246 | 267 | |
| 247 | 268 | default: |
@@ -328,14 +349,16 @@ discard block |
||
| 328 | 349 | ), |
| 329 | 350 | ); |
| 330 | 351 | |
| 331 | - if (isset($replacements[$identifier])) |
|
| 332 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 352 | + if (isset($replacements[$identifier])) { |
|
| 353 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 354 | + } |
|
| 333 | 355 | |
| 334 | 356 | // Limits need to be a little different. |
| 335 | 357 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 336 | 358 | |
| 337 | - if (trim($db_string) == '') |
|
| 338 | - return false; |
|
| 359 | + if (trim($db_string) == '') { |
|
| 360 | + return false; |
|
| 361 | + } |
|
| 339 | 362 | |
| 340 | 363 | // Comments that are allowed in a query are preg_removed. |
| 341 | 364 | static $allowed_comments_from = array( |
@@ -355,8 +378,9 @@ discard block |
||
| 355 | 378 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 356 | 379 | $db_replace_result = 0; |
| 357 | 380 | |
| 358 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 359 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 381 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 382 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 383 | + } |
|
| 360 | 384 | |
| 361 | 385 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 362 | 386 | { |
@@ -377,8 +401,9 @@ discard block |
||
| 377 | 401 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 378 | 402 | |
| 379 | 403 | // Initialize $db_cache if not already initialized. |
| 380 | - if (!isset($db_cache)) |
|
| 381 | - $db_cache = array(); |
|
| 404 | + if (!isset($db_cache)) { |
|
| 405 | + $db_cache = array(); |
|
| 406 | + } |
|
| 382 | 407 | |
| 383 | 408 | if (!empty($_SESSION['debug_redirect'])) |
| 384 | 409 | { |
@@ -404,17 +429,18 @@ discard block |
||
| 404 | 429 | while (true) |
| 405 | 430 | { |
| 406 | 431 | $pos = strpos($db_string, '\'', $pos + 1); |
| 407 | - if ($pos === false) |
|
| 408 | - break; |
|
| 432 | + if ($pos === false) { |
|
| 433 | + break; |
|
| 434 | + } |
|
| 409 | 435 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 410 | 436 | |
| 411 | 437 | while (true) |
| 412 | 438 | { |
| 413 | 439 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 414 | 440 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 415 | - if ($pos1 === false) |
|
| 416 | - break; |
|
| 417 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 441 | + if ($pos1 === false) { |
|
| 442 | + break; |
|
| 443 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 418 | 444 | { |
| 419 | 445 | $pos = $pos1; |
| 420 | 446 | break; |
@@ -430,26 +456,31 @@ discard block |
||
| 430 | 456 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 431 | 457 | |
| 432 | 458 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 433 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 434 | - $fail = true; |
|
| 459 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 460 | + $fail = true; |
|
| 461 | + } |
|
| 435 | 462 | // Trying to change passwords, slow us down, or something? |
| 436 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 437 | - $fail = true; |
|
| 438 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 439 | - $fail = true; |
|
| 463 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 464 | + $fail = true; |
|
| 465 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 466 | + $fail = true; |
|
| 467 | + } |
|
| 440 | 468 | |
| 441 | - if (!empty($fail) && function_exists('log_error')) |
|
| 442 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 469 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 470 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 471 | + } |
|
| 443 | 472 | } |
| 444 | 473 | |
| 445 | 474 | $db_last_result = @pg_query($connection, $db_string); |
| 446 | 475 | |
| 447 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 448 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 476 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 477 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 478 | + } |
|
| 449 | 479 | |
| 450 | 480 | // Debugging. |
| 451 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 452 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 481 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 482 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 483 | + } |
|
| 453 | 484 | |
| 454 | 485 | return $db_last_result; |
| 455 | 486 | } |
@@ -462,10 +493,11 @@ discard block |
||
| 462 | 493 | { |
| 463 | 494 | global $db_last_result, $db_replace_result; |
| 464 | 495 | |
| 465 | - if ($db_replace_result) |
|
| 466 | - return $db_replace_result; |
|
| 467 | - elseif ($result === null && !$db_last_result) |
|
| 468 | - return 0; |
|
| 496 | + if ($db_replace_result) { |
|
| 497 | + return $db_replace_result; |
|
| 498 | + } elseif ($result === null && !$db_last_result) { |
|
| 499 | + return 0; |
|
| 500 | + } |
|
| 469 | 501 | |
| 470 | 502 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 471 | 503 | } |
@@ -484,16 +516,18 @@ discard block |
||
| 484 | 516 | |
| 485 | 517 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 486 | 518 | |
| 487 | - if ($connection === false) |
|
| 488 | - $connection = $db_connection; |
|
| 519 | + if ($connection === false) { |
|
| 520 | + $connection = $db_connection; |
|
| 521 | + } |
|
| 489 | 522 | |
| 490 | 523 | // Try get the last ID for the auto increment field. |
| 491 | 524 | $request = $smcFunc['db_query']('', 'SELECT CURRVAL(\'' . $table . '_seq\') AS insertID', |
| 492 | 525 | array( |
| 493 | 526 | ) |
| 494 | 527 | ); |
| 495 | - if (!$request) |
|
| 496 | - return false; |
|
| 528 | + if (!$request) { |
|
| 529 | + return false; |
|
| 530 | + } |
|
| 497 | 531 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 498 | 532 | $smcFunc['db_free_result']($request); |
| 499 | 533 | |
@@ -514,12 +548,13 @@ discard block |
||
| 514 | 548 | // Decide which connection to use |
| 515 | 549 | $connection = $connection === null ? $db_connection : $connection; |
| 516 | 550 | |
| 517 | - if ($type == 'begin') |
|
| 518 | - return @pg_query($connection, 'BEGIN'); |
|
| 519 | - elseif ($type == 'rollback') |
|
| 520 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 521 | - elseif ($type == 'commit') |
|
| 522 | - return @pg_query($connection, 'COMMIT'); |
|
| 551 | + if ($type == 'begin') { |
|
| 552 | + return @pg_query($connection, 'BEGIN'); |
|
| 553 | + } elseif ($type == 'rollback') { |
|
| 554 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 555 | + } elseif ($type == 'commit') { |
|
| 556 | + return @pg_query($connection, 'COMMIT'); |
|
| 557 | + } |
|
| 523 | 558 | |
| 524 | 559 | return false; |
| 525 | 560 | } |
@@ -547,19 +582,22 @@ discard block |
||
| 547 | 582 | $query_error = @pg_last_error($connection); |
| 548 | 583 | |
| 549 | 584 | // Log the error. |
| 550 | - if (function_exists('log_error')) |
|
| 551 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 585 | + if (function_exists('log_error')) { |
|
| 586 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 587 | + } |
|
| 552 | 588 | |
| 553 | 589 | // Nothing's defined yet... just die with it. |
| 554 | - if (empty($context) || empty($txt)) |
|
| 555 | - die($query_error); |
|
| 590 | + if (empty($context) || empty($txt)) { |
|
| 591 | + die($query_error); |
|
| 592 | + } |
|
| 556 | 593 | |
| 557 | 594 | // Show an error message, if possible. |
| 558 | 595 | $context['error_title'] = $txt['database_error']; |
| 559 | - if (allowedTo('admin_forum')) |
|
| 560 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 561 | - else |
|
| 562 | - $context['error_message'] = $txt['try_again']; |
|
| 596 | + if (allowedTo('admin_forum')) { |
|
| 597 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 598 | + } else { |
|
| 599 | + $context['error_message'] = $txt['try_again']; |
|
| 600 | + } |
|
| 563 | 601 | |
| 564 | 602 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 565 | 603 | { |
@@ -581,12 +619,14 @@ discard block |
||
| 581 | 619 | { |
| 582 | 620 | global $db_row_count; |
| 583 | 621 | |
| 584 | - if ($counter !== false) |
|
| 585 | - return pg_fetch_row($request, $counter); |
|
| 622 | + if ($counter !== false) { |
|
| 623 | + return pg_fetch_row($request, $counter); |
|
| 624 | + } |
|
| 586 | 625 | |
| 587 | 626 | // Reset the row counter... |
| 588 | - if (!isset($db_row_count[(int) $request])) |
|
| 589 | - $db_row_count[(int) $request] = 0; |
|
| 627 | + if (!isset($db_row_count[(int) $request])) { |
|
| 628 | + $db_row_count[(int) $request] = 0; |
|
| 629 | + } |
|
| 590 | 630 | |
| 591 | 631 | // Return the right row. |
| 592 | 632 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -603,12 +643,14 @@ discard block |
||
| 603 | 643 | { |
| 604 | 644 | global $db_row_count; |
| 605 | 645 | |
| 606 | - if ($counter !== false) |
|
| 607 | - return pg_fetch_assoc($request, $counter); |
|
| 646 | + if ($counter !== false) { |
|
| 647 | + return pg_fetch_assoc($request, $counter); |
|
| 648 | + } |
|
| 608 | 649 | |
| 609 | 650 | // Reset the row counter... |
| 610 | - if (!isset($db_row_count[(int) $request])) |
|
| 611 | - $db_row_count[(int) $request] = 0; |
|
| 651 | + if (!isset($db_row_count[(int) $request])) { |
|
| 652 | + $db_row_count[(int) $request] = 0; |
|
| 653 | + } |
|
| 612 | 654 | |
| 613 | 655 | // Return the right row. |
| 614 | 656 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -660,11 +702,13 @@ discard block |
||
| 660 | 702 | |
| 661 | 703 | $replace = ''; |
| 662 | 704 | |
| 663 | - if (empty($data)) |
|
| 664 | - return; |
|
| 705 | + if (empty($data)) { |
|
| 706 | + return; |
|
| 707 | + } |
|
| 665 | 708 | |
| 666 | - if (!is_array($data[array_rand($data)])) |
|
| 667 | - $data = array($data); |
|
| 709 | + if (!is_array($data[array_rand($data)])) { |
|
| 710 | + $data = array($data); |
|
| 711 | + } |
|
| 668 | 712 | |
| 669 | 713 | // Replace the prefix holder with the actual prefix. |
| 670 | 714 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -690,11 +734,13 @@ discard block |
||
| 690 | 734 | //pg 9.5 got replace support |
| 691 | 735 | $pg_version = $smcFunc['db_get_version'](); |
| 692 | 736 | // if we got a Beta Version |
| 693 | - if (stripos($pg_version, 'beta') !== false) |
|
| 694 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 737 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 738 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 739 | + } |
|
| 695 | 740 | // or RC |
| 696 | - if (stripos($pg_version, 'rc') !== false) |
|
| 697 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 741 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 742 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 743 | + } |
|
| 698 | 744 | |
| 699 | 745 | $replace_support = (version_compare($pg_version,'9.5.0','>=') ? true : false); |
| 700 | 746 | } |
@@ -713,8 +759,7 @@ discard block |
||
| 713 | 759 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 714 | 760 | $key_str .= $columnName; |
| 715 | 761 | $count_pk++; |
| 716 | - } |
|
| 717 | - else //normal field |
|
| 762 | + } else //normal field |
|
| 718 | 763 | { |
| 719 | 764 | $col_str .= ($count > 0 ? ',' : ''); |
| 720 | 765 | $col_str .= $columnName.' = EXCLUDED.'.$columnName; |
@@ -722,20 +767,21 @@ discard block |
||
| 722 | 767 | } |
| 723 | 768 | } |
| 724 | 769 | $replace = ' ON CONFLICT ('.$key_str.') DO UPDATE SET '.$col_str; |
| 725 | - } |
|
| 726 | - else |
|
| 770 | + } else |
|
| 727 | 771 | { |
| 728 | 772 | foreach ($columns as $columnName => $type) |
| 729 | 773 | { |
| 730 | 774 | // Are we restricting the length? |
| 731 | - if (strpos($type, 'string-') !== false) |
|
| 732 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 733 | - else |
|
| 734 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 775 | + if (strpos($type, 'string-') !== false) { |
|
| 776 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 777 | + } else { |
|
| 778 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 779 | + } |
|
| 735 | 780 | |
| 736 | 781 | // A key? That's what we were looking for. |
| 737 | - if (in_array($columnName, $keys)) |
|
| 738 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 782 | + if (in_array($columnName, $keys)) { |
|
| 783 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 784 | + } |
|
| 739 | 785 | $count++; |
| 740 | 786 | } |
| 741 | 787 | |
@@ -761,10 +807,11 @@ discard block |
||
| 761 | 807 | foreach ($columns as $columnName => $type) |
| 762 | 808 | { |
| 763 | 809 | // Are we restricting the length? |
| 764 | - if (strpos($type, 'string-') !== false) |
|
| 765 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 766 | - else |
|
| 767 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 810 | + if (strpos($type, 'string-') !== false) { |
|
| 811 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 812 | + } else { |
|
| 813 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 814 | + } |
|
| 768 | 815 | } |
| 769 | 816 | $insertData = substr($insertData, 0, -2) . ')'; |
| 770 | 817 | |
@@ -773,11 +820,12 @@ discard block |
||
| 773 | 820 | |
| 774 | 821 | // Here's where the variables are injected to the query. |
| 775 | 822 | $insertRows = array(); |
| 776 | - foreach ($data as $dataRow) |
|
| 777 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 823 | + foreach ($data as $dataRow) { |
|
| 824 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 825 | + } |
|
| 778 | 826 | |
| 779 | - foreach ($insertRows as $entry) |
|
| 780 | - // Do the insert. |
|
| 827 | + foreach ($insertRows as $entry) { |
|
| 828 | + // Do the insert. |
|
| 781 | 829 | $smcFunc['db_query']('', ' |
| 782 | 830 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 783 | 831 | VALUES |
@@ -788,11 +836,13 @@ discard block |
||
| 788 | 836 | ), |
| 789 | 837 | $connection |
| 790 | 838 | ); |
| 839 | + } |
|
| 791 | 840 | } |
| 792 | 841 | |
| 793 | - if ($priv_trans) |
|
| 794 | - $smcFunc['db_transaction']('commit', $connection); |
|
| 795 | -} |
|
| 842 | + if ($priv_trans) { |
|
| 843 | + $smcFunc['db_transaction']('commit', $connection); |
|
| 844 | + } |
|
| 845 | + } |
|
| 796 | 846 | |
| 797 | 847 | /** |
| 798 | 848 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -829,8 +879,9 @@ discard block |
||
| 829 | 879 | */ |
| 830 | 880 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 831 | 881 | { |
| 832 | - if (empty($log_message)) |
|
| 833 | - $log_message = $error_message; |
|
| 882 | + if (empty($log_message)) { |
|
| 883 | + $log_message = $error_message; |
|
| 884 | + } |
|
| 834 | 885 | |
| 835 | 886 | foreach (debug_backtrace() as $step) |
| 836 | 887 | { |
@@ -849,12 +900,14 @@ discard block |
||
| 849 | 900 | } |
| 850 | 901 | |
| 851 | 902 | // A special case - we want the file and line numbers for debugging. |
| 852 | - if ($error_type == 'return') |
|
| 853 | - return array($file, $line); |
|
| 903 | + if ($error_type == 'return') { |
|
| 904 | + return array($file, $line); |
|
| 905 | + } |
|
| 854 | 906 | |
| 855 | 907 | // Is always a critical error. |
| 856 | - if (function_exists('log_error')) |
|
| 857 | - log_error($log_message, 'critical', $file, $line); |
|
| 908 | + if (function_exists('log_error')) { |
|
| 909 | + log_error($log_message, 'critical', $file, $line); |
|
| 910 | + } |
|
| 858 | 911 | |
| 859 | 912 | if (function_exists('fatal_error')) |
| 860 | 913 | { |
@@ -862,12 +915,12 @@ discard block |
||
| 862 | 915 | |
| 863 | 916 | // Cannot continue... |
| 864 | 917 | exit; |
| 918 | + } elseif ($error_type) { |
|
| 919 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 920 | + } else { |
|
| 921 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 922 | + } |
|
| 865 | 923 | } |
| 866 | - elseif ($error_type) |
|
| 867 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 868 | - else |
|
| 869 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 870 | -} |
|
| 871 | 924 | |
| 872 | 925 | /** |
| 873 | 926 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -884,10 +937,11 @@ discard block |
||
| 884 | 937 | '\\' => '\\\\', |
| 885 | 938 | ); |
| 886 | 939 | |
| 887 | - if ($translate_human_wildcards) |
|
| 888 | - $replacements += array( |
|
| 940 | + if ($translate_human_wildcards) { |
|
| 941 | + $replacements += array( |
|
| 889 | 942 | '*' => '%', |
| 890 | 943 | ); |
| 944 | + } |
|
| 891 | 945 | |
| 892 | 946 | return strtr($string, $replacements); |
| 893 | 947 | } |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Takes a message and parses it, returning nothing. |
@@ -52,17 +53,19 @@ discard block |
||
| 52 | 53 | $message = preg_replace('~\.{100,}~', '...', $message); |
| 53 | 54 | |
| 54 | 55 | // Trim off trailing quotes - these often happen by accident. |
| 55 | - while (substr($message, -7) == '[quote]') |
|
| 56 | - $message = substr($message, 0, -7); |
|
| 57 | - while (substr($message, 0, 8) == '[/quote]') |
|
| 58 | - $message = substr($message, 8); |
|
| 56 | + while (substr($message, -7) == '[quote]') { |
|
| 57 | + $message = substr($message, 0, -7); |
|
| 58 | + } |
|
| 59 | + while (substr($message, 0, 8) == '[/quote]') { |
|
| 60 | + $message = substr($message, 8); |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | // Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed. |
| 61 | 64 | $in_tag = false; |
| 62 | 65 | $had_tag = false; |
| 63 | 66 | $codeopen = 0; |
| 64 | - if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) |
|
| 65 | - foreach ($matches[0] as $index => $dummy) |
|
| 67 | + if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) { |
|
| 68 | + foreach ($matches[0] as $index => $dummy) |
|
| 66 | 69 | { |
| 67 | 70 | // Closing? |
| 68 | 71 | if (!empty($matches[2][$index])) |
@@ -70,6 +73,7 @@ discard block |
||
| 70 | 73 | // If it's closing and we're not in a tag we need to open it... |
| 71 | 74 | if (!$in_tag) |
| 72 | 75 | $codeopen = true; |
| 76 | + } |
|
| 73 | 77 | // Either way we ain't in one any more. |
| 74 | 78 | $in_tag = false; |
| 75 | 79 | } |
@@ -78,17 +82,20 @@ discard block |
||
| 78 | 82 | { |
| 79 | 83 | $had_tag = true; |
| 80 | 84 | // If we're in a tag don't do nought! |
| 81 | - if (!$in_tag) |
|
| 82 | - $in_tag = true; |
|
| 85 | + if (!$in_tag) { |
|
| 86 | + $in_tag = true; |
|
| 87 | + } |
|
| 83 | 88 | } |
| 84 | 89 | } |
| 85 | 90 | |
| 86 | 91 | // If we have an open tag, close it. |
| 87 | - if ($in_tag) |
|
| 88 | - $message .= '[/code]'; |
|
| 92 | + if ($in_tag) { |
|
| 93 | + $message .= '[/code]'; |
|
| 94 | + } |
|
| 89 | 95 | // Open any ones that need to be open, only if we've never had a tag. |
| 90 | - if ($codeopen && !$had_tag) |
|
| 91 | - $message = '[code]' . $message; |
|
| 96 | + if ($codeopen && !$had_tag) { |
|
| 97 | + $message = '[code]' . $message; |
|
| 98 | + } |
|
| 92 | 99 | |
| 93 | 100 | // Now that we've fixed all the code tags, let's fix the img and url tags... |
| 94 | 101 | $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE); |
@@ -114,23 +121,26 @@ discard block |
||
| 114 | 121 | fixTags($message); |
| 115 | 122 | |
| 116 | 123 | // Replace /me.+?\n with [me=name]dsf[/me]\n. |
| 117 | - if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) |
|
| 118 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
| 119 | - else |
|
| 120 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
| 124 | + if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) { |
|
| 125 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
| 126 | + } else { |
|
| 127 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
| 128 | + } |
|
| 121 | 129 | |
| 122 | 130 | if (!$previewing && strpos($message, '[html]') !== false) |
| 123 | 131 | { |
| 124 | - if (allowedTo('admin_forum')) |
|
| 125 | - $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) { |
|
| 132 | + if (allowedTo('admin_forum')) { |
|
| 133 | + $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) { |
|
| 126 | 134 | return '[html]' . strtr(un_htmlspecialchars($m), array("\n" => ' ', ' ' => '  ', '[' => '[', ']' => ']')) . '[/html]'; |
| 135 | + } |
|
| 127 | 136 | }, $message); |
| 128 | 137 | |
| 129 | 138 | // We should edit them out, or else if an admin edits the message they will get shown... |
| 130 | 139 | else |
| 131 | 140 | { |
| 132 | - while (strpos($message, '[html]') !== false) |
|
| 133 | - $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
| 141 | + while (strpos($message, '[html]') !== false) { |
|
| 142 | + $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
| 143 | + } |
|
| 134 | 144 | } |
| 135 | 145 | } |
| 136 | 146 | |
@@ -152,10 +162,12 @@ discard block |
||
| 152 | 162 | |
| 153 | 163 | $list_open = substr_count($message, '[list]') + substr_count($message, '[list '); |
| 154 | 164 | $list_close = substr_count($message, '[/list]'); |
| 155 | - if ($list_close - $list_open > 0) |
|
| 156 | - $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
| 157 | - if ($list_open - $list_close > 0) |
|
| 158 | - $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
| 165 | + if ($list_close - $list_open > 0) { |
|
| 166 | + $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
| 167 | + } |
|
| 168 | + if ($list_open - $list_close > 0) { |
|
| 169 | + $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
| 170 | + } |
|
| 159 | 171 | |
| 160 | 172 | $mistake_fixes = array( |
| 161 | 173 | // Find [table]s not followed by [tr]. |
@@ -204,8 +216,9 @@ discard block |
||
| 204 | 216 | ); |
| 205 | 217 | |
| 206 | 218 | // Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.) |
| 207 | - for ($j = 0; $j < 3; $j++) |
|
| 208 | - $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
| 219 | + for ($j = 0; $j < 3; $j++) { |
|
| 220 | + $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
| 221 | + } |
|
| 209 | 222 | |
| 210 | 223 | // Remove empty bbc from the sections outside the code tags |
| 211 | 224 | $message = preg_replace('~\[[bisu]\]\s*\[/[bisu]\]~', '', $message); |
@@ -213,14 +226,16 @@ discard block |
||
| 213 | 226 | $message = preg_replace('~\[color=(?:#[\da-fA-F]{3}|#[\da-fA-F]{6}|[A-Za-z]{1,20}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\))\]\s*\[/color\]~', '', $message); |
| 214 | 227 | |
| 215 | 228 | // Restore code blocks |
| 216 | - if (!empty($code_tags)) |
|
| 217 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 229 | + if (!empty($code_tags)) { |
|
| 230 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 231 | + } |
|
| 218 | 232 | |
| 219 | 233 | // Restore white space entities |
| 220 | - if (!$previewing) |
|
| 221 | - $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 222 | - else |
|
| 223 | - $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 234 | + if (!$previewing) { |
|
| 235 | + $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 236 | + } else { |
|
| 237 | + $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 238 | + } |
|
| 224 | 239 | |
| 225 | 240 | // Now let's quickly clean up things that will slow our parser (which are common in posted code.) |
| 226 | 241 | $message = strtr($message, array('[]' => '[]', '['' => '['')); |
@@ -263,8 +278,9 @@ discard block |
||
| 263 | 278 | return "[time]" . timeformat("$m[1]", false) . "[/time]"; |
| 264 | 279 | }, $message); |
| 265 | 280 | |
| 266 | - if (!empty($code_tags)) |
|
| 267 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 281 | + if (!empty($code_tags)) { |
|
| 282 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 283 | + } |
|
| 268 | 284 | |
| 269 | 285 | // Change breaks back to \n's and &nsbp; back to spaces. |
| 270 | 286 | return preg_replace('~<br( /)?' . '>~', "\n", str_replace(' ', ' ', $message)); |
@@ -345,8 +361,9 @@ discard block |
||
| 345 | 361 | ); |
| 346 | 362 | |
| 347 | 363 | // Fix each type of tag. |
| 348 | - foreach ($fixArray as $param) |
|
| 349 | - fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
| 364 | + foreach ($fixArray as $param) { |
|
| 365 | + fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
| 366 | + } |
|
| 350 | 367 | |
| 351 | 368 | // Now fix possible security problems with images loading links automatically... |
| 352 | 369 | $message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function ($m) |
@@ -382,16 +399,19 @@ discard block |
||
| 382 | 399 | $desired_height = $height; |
| 383 | 400 | } |
| 384 | 401 | // Scale it to the width... |
| 385 | - elseif (empty($desired_width) && !empty($height)) |
|
| 386 | - $desired_width = (int) (($desired_height * $width) / $height); |
|
| 402 | + elseif (empty($desired_width) && !empty($height)) { |
|
| 403 | + $desired_width = (int) (($desired_height * $width) / $height); |
|
| 404 | + } |
|
| 387 | 405 | // Scale if to the height. |
| 388 | - elseif (!empty($width)) |
|
| 389 | - $desired_height = (int) (($desired_width * $height) / $width); |
|
| 406 | + elseif (!empty($width)) { |
|
| 407 | + $desired_height = (int) (($desired_width * $height) / $width); |
|
| 408 | + } |
|
| 390 | 409 | } |
| 391 | 410 | |
| 392 | 411 | // If the width and height are fine, just continue along... |
| 393 | - if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) |
|
| 394 | - continue; |
|
| 412 | + if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) { |
|
| 413 | + continue; |
|
| 414 | + } |
|
| 395 | 415 | |
| 396 | 416 | // Too bad, it's too wide. Make it as wide as the maximum. |
| 397 | 417 | if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width'])) |
@@ -411,8 +431,9 @@ discard block |
||
| 411 | 431 | } |
| 412 | 432 | |
| 413 | 433 | // If any img tags were actually changed... |
| 414 | - if (!empty($replaces)) |
|
| 415 | - $message = strtr($message, $replaces); |
|
| 434 | + if (!empty($replaces)) { |
|
| 435 | + $message = strtr($message, $replaces); |
|
| 436 | + } |
|
| 416 | 437 | } |
| 417 | 438 | } |
| 418 | 439 | |
@@ -431,10 +452,11 @@ discard block |
||
| 431 | 452 | { |
| 432 | 453 | global $boardurl, $scripturl; |
| 433 | 454 | |
| 434 | - if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) |
|
| 435 | - $domain_url = $match[1]; |
|
| 436 | - else |
|
| 437 | - $domain_url = $boardurl . '/'; |
|
| 455 | + if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) { |
|
| 456 | + $domain_url = $match[1]; |
|
| 457 | + } else { |
|
| 458 | + $domain_url = $boardurl . '/'; |
|
| 459 | + } |
|
| 438 | 460 | |
| 439 | 461 | $replaces = array(); |
| 440 | 462 | |
@@ -442,11 +464,11 @@ discard block |
||
| 442 | 464 | { |
| 443 | 465 | $quoted = preg_match('~\[(' . $myTag . ')="~', $message); |
| 444 | 466 | preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '"(.*?)"' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
| 467 | + } elseif ($hasEqualSign) { |
|
| 468 | + preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
| 469 | + } else { |
|
| 470 | + preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
| 445 | 471 | } |
| 446 | - elseif ($hasEqualSign) |
|
| 447 | - preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
| 448 | - else |
|
| 449 | - preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
| 450 | 472 | |
| 451 | 473 | foreach ($matches[0] as $k => $dummy) |
| 452 | 474 | { |
@@ -459,49 +481,53 @@ discard block |
||
| 459 | 481 | foreach ($protocols as $protocol) |
| 460 | 482 | { |
| 461 | 483 | $found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0; |
| 462 | - if ($found) |
|
| 463 | - break; |
|
| 484 | + if ($found) { |
|
| 485 | + break; |
|
| 486 | + } |
|
| 464 | 487 | } |
| 465 | 488 | |
| 466 | 489 | if (!$found && $protocols[0] == 'http') |
| 467 | 490 | { |
| 468 | - if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') |
|
| 469 | - $replace = $domain_url . $replace; |
|
| 470 | - elseif (substr($replace, 0, 1) == '?') |
|
| 471 | - $replace = $scripturl . $replace; |
|
| 472 | - elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
| 491 | + if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') { |
|
| 492 | + $replace = $domain_url . $replace; |
|
| 493 | + } elseif (substr($replace, 0, 1) == '?') { |
|
| 494 | + $replace = $scripturl . $replace; |
|
| 495 | + } elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
| 473 | 496 | { |
| 474 | 497 | $replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1)); |
| 475 | 498 | $this_tag = 'iurl'; |
| 476 | 499 | $this_close = 'iurl'; |
| 500 | + } elseif (substr($replace, 0, 2) != '//') { |
|
| 501 | + $replace = $protocols[0] . '://' . $replace; |
|
| 477 | 502 | } |
| 478 | - elseif (substr($replace, 0, 2) != '//') |
|
| 479 | - $replace = $protocols[0] . '://' . $replace; |
|
| 480 | - } |
|
| 481 | - elseif (!$found && $protocols[0] == 'ftp') |
|
| 482 | - $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
| 483 | - elseif (!$found) |
|
| 484 | - $replace = $protocols[0] . '://' . $replace; |
|
| 485 | - |
|
| 486 | - if ($hasEqualSign && $embeddedUrl) |
|
| 487 | - $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
| 488 | - elseif ($hasEqualSign) |
|
| 489 | - $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
| 490 | - elseif ($embeddedUrl) |
|
| 491 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
| 492 | - else |
|
| 493 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
| 503 | + } elseif (!$found && $protocols[0] == 'ftp') { |
|
| 504 | + $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
| 505 | + } elseif (!$found) { |
|
| 506 | + $replace = $protocols[0] . '://' . $replace; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + if ($hasEqualSign && $embeddedUrl) { |
|
| 510 | + $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
| 511 | + } elseif ($hasEqualSign) { |
|
| 512 | + $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
| 513 | + } elseif ($embeddedUrl) { |
|
| 514 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
| 515 | + } else { |
|
| 516 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
| 517 | + } |
|
| 494 | 518 | } |
| 495 | 519 | |
| 496 | 520 | foreach ($replaces as $k => $v) |
| 497 | 521 | { |
| 498 | - if ($k == $v) |
|
| 499 | - unset($replaces[$k]); |
|
| 522 | + if ($k == $v) { |
|
| 523 | + unset($replaces[$k]); |
|
| 524 | + } |
|
| 500 | 525 | } |
| 501 | 526 | |
| 502 | - if (!empty($replaces)) |
|
| 503 | - $message = strtr($message, $replaces); |
|
| 504 | -} |
|
| 527 | + if (!empty($replaces)) { |
|
| 528 | + $message = strtr($message, $replaces); |
|
| 529 | + } |
|
| 530 | + } |
|
| 505 | 531 | |
| 506 | 532 | /** |
| 507 | 533 | * This function sends an email to the specified recipient(s). |
@@ -545,8 +571,9 @@ discard block |
||
| 545 | 571 | } |
| 546 | 572 | |
| 547 | 573 | // Nothing left? Nothing else to do |
| 548 | - if (empty($to_array)) |
|
| 549 | - return true; |
|
| 574 | + if (empty($to_array)) { |
|
| 575 | + return true; |
|
| 576 | + } |
|
| 550 | 577 | |
| 551 | 578 | // Once upon a time, Hotmail could not interpret non-ASCII mails. |
| 552 | 579 | // In honour of those days, it's still called the 'hotmail fix'. |
@@ -563,15 +590,17 @@ discard block |
||
| 563 | 590 | } |
| 564 | 591 | |
| 565 | 592 | // Call this function recursively for the hotmail addresses. |
| 566 | - if (!empty($hotmail_to)) |
|
| 567 | - $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
| 593 | + if (!empty($hotmail_to)) { |
|
| 594 | + $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
| 595 | + } |
|
| 568 | 596 | |
| 569 | 597 | // The remaining addresses no longer need the fix. |
| 570 | 598 | $hotmail_fix = false; |
| 571 | 599 | |
| 572 | 600 | // No other addresses left? Return instantly. |
| 573 | - if (empty($to_array)) |
|
| 574 | - return $mail_result; |
|
| 601 | + if (empty($to_array)) { |
|
| 602 | + return $mail_result; |
|
| 603 | + } |
|
| 575 | 604 | } |
| 576 | 605 | |
| 577 | 606 | // Get rid of entities. |
@@ -596,13 +625,15 @@ discard block |
||
| 596 | 625 | $headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break; |
| 597 | 626 | $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break; |
| 598 | 627 | |
| 599 | - if ($message_id !== null && empty($modSettings['mail_no_message_id'])) |
|
| 600 | - $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
| 628 | + if ($message_id !== null && empty($modSettings['mail_no_message_id'])) { |
|
| 629 | + $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
| 630 | + } |
|
| 601 | 631 | $headers .= 'X-Mailer: SMF' . $line_break; |
| 602 | 632 | |
| 603 | 633 | // Pass this to the integration before we start modifying the output -- it'll make it easier later. |
| 604 | - if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) |
|
| 605 | - return false; |
|
| 634 | + if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) { |
|
| 635 | + return false; |
|
| 636 | + } |
|
| 606 | 637 | |
| 607 | 638 | // Save the original message... |
| 608 | 639 | $orig_message = $message; |
@@ -651,17 +682,19 @@ discard block |
||
| 651 | 682 | } |
| 652 | 683 | |
| 653 | 684 | // Are we using the mail queue, if so this is where we butt in... |
| 654 | - if ($priority != 0) |
|
| 655 | - return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
| 685 | + if ($priority != 0) { |
|
| 686 | + return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
| 687 | + } |
|
| 656 | 688 | |
| 657 | 689 | // If it's a priority mail, send it now - note though that this should NOT be used for sending many at once. |
| 658 | 690 | elseif (!empty($modSettings['mail_limit'])) |
| 659 | 691 | { |
| 660 | 692 | list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']); |
| 661 | - if (empty($mails_this_minute) || time() > $last_mail_time + 60) |
|
| 662 | - $new_queue_stat = time() . '|' . 1; |
|
| 663 | - else |
|
| 664 | - $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
| 693 | + if (empty($mails_this_minute) || time() > $last_mail_time + 60) { |
|
| 694 | + $new_queue_stat = time() . '|' . 1; |
|
| 695 | + } else { |
|
| 696 | + $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
| 697 | + } |
|
| 665 | 698 | |
| 666 | 699 | updateSettings(array('mail_recent' => $new_queue_stat)); |
| 667 | 700 | } |
@@ -686,12 +719,13 @@ discard block |
||
| 686 | 719 | |
| 687 | 720 | // Wait, wait, I'm still sending here! |
| 688 | 721 | @set_time_limit(300); |
| 689 | - if (function_exists('apache_reset_timeout')) |
|
| 690 | - @apache_reset_timeout(); |
|
| 722 | + if (function_exists('apache_reset_timeout')) { |
|
| 723 | + @apache_reset_timeout(); |
|
| 724 | + } |
|
| 691 | 725 | } |
| 726 | + } else { |
|
| 727 | + $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
| 692 | 728 | } |
| 693 | - else |
|
| 694 | - $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
| 695 | 729 | |
| 696 | 730 | // Everything go smoothly? |
| 697 | 731 | return $mail_result; |
@@ -717,8 +751,9 @@ discard block |
||
| 717 | 751 | static $cur_insert = array(); |
| 718 | 752 | static $cur_insert_len = 0; |
| 719 | 753 | |
| 720 | - if ($cur_insert_len == 0) |
|
| 721 | - $cur_insert = array(); |
|
| 754 | + if ($cur_insert_len == 0) { |
|
| 755 | + $cur_insert = array(); |
|
| 756 | + } |
|
| 722 | 757 | |
| 723 | 758 | // If we're flushing, make the final inserts - also if we're near the MySQL length limit! |
| 724 | 759 | if (($flush || $cur_insert_len > 800000) && !empty($cur_insert)) |
@@ -793,8 +828,9 @@ discard block |
||
| 793 | 828 | } |
| 794 | 829 | |
| 795 | 830 | // If they are using SSI there is a good chance obExit will never be called. So lets be nice and flush it for them. |
| 796 | - if (SMF === 'SSI' || SMF === 'BACKGROUND') |
|
| 797 | - return AddMailQueue(true); |
|
| 831 | + if (SMF === 'SSI' || SMF === 'BACKGROUND') { |
|
| 832 | + return AddMailQueue(true); |
|
| 833 | + } |
|
| 798 | 834 | |
| 799 | 835 | return true; |
| 800 | 836 | } |
@@ -827,23 +863,26 @@ discard block |
||
| 827 | 863 | 'sent' => array() |
| 828 | 864 | ); |
| 829 | 865 | |
| 830 | - if ($from === null) |
|
| 831 | - $from = array( |
|
| 866 | + if ($from === null) { |
|
| 867 | + $from = array( |
|
| 832 | 868 | 'id' => $user_info['id'], |
| 833 | 869 | 'name' => $user_info['name'], |
| 834 | 870 | 'username' => $user_info['username'] |
| 835 | 871 | ); |
| 872 | + } |
|
| 836 | 873 | |
| 837 | 874 | // This is the one that will go in their inbox. |
| 838 | 875 | $htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES); |
| 839 | 876 | preparsecode($htmlmessage); |
| 840 | 877 | $htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => '')); |
| 841 | - if ($smcFunc['strlen']($htmlsubject) > 100) |
|
| 842 | - $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
| 878 | + if ($smcFunc['strlen']($htmlsubject) > 100) { |
|
| 879 | + $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
| 880 | + } |
|
| 843 | 881 | |
| 844 | 882 | // Make sure is an array |
| 845 | - if (!is_array($recipients)) |
|
| 846 | - $recipients = array($recipients); |
|
| 883 | + if (!is_array($recipients)) { |
|
| 884 | + $recipients = array($recipients); |
|
| 885 | + } |
|
| 847 | 886 | |
| 848 | 887 | // Integrated PMs |
| 849 | 888 | call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message)); |
@@ -871,21 +910,23 @@ discard block |
||
| 871 | 910 | 'usernames' => array_keys($usernames), |
| 872 | 911 | ) |
| 873 | 912 | ); |
| 874 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 875 | - if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
| 913 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 914 | + if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
| 876 | 915 | $usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member']; |
| 916 | + } |
|
| 877 | 917 | $smcFunc['db_free_result']($request); |
| 878 | 918 | |
| 879 | 919 | // Replace the usernames with IDs. Drop usernames that couldn't be found. |
| 880 | - foreach ($recipients as $rec_type => $rec) |
|
| 881 | - foreach ($rec as $id => $member) |
|
| 920 | + foreach ($recipients as $rec_type => $rec) { |
|
| 921 | + foreach ($rec as $id => $member) |
|
| 882 | 922 | { |
| 883 | 923 | if (is_numeric($recipients[$rec_type][$id])) |
| 884 | 924 | continue; |
| 925 | + } |
|
| 885 | 926 | |
| 886 | - if (!empty($usernames[$member])) |
|
| 887 | - $recipients[$rec_type][$id] = $usernames[$member]; |
|
| 888 | - else |
|
| 927 | + if (!empty($usernames[$member])) { |
|
| 928 | + $recipients[$rec_type][$id] = $usernames[$member]; |
|
| 929 | + } else |
|
| 889 | 930 | { |
| 890 | 931 | $log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]); |
| 891 | 932 | unset($recipients[$rec_type][$id]); |
@@ -924,8 +965,9 @@ discard block |
||
| 924 | 965 | foreach ($criteria as $criterium) |
| 925 | 966 | { |
| 926 | 967 | $match = false; |
| 927 | - if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) |
|
| 928 | - $delete = true; |
|
| 968 | + if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) { |
|
| 969 | + $delete = true; |
|
| 970 | + } |
|
| 929 | 971 | // If we're adding and one criteria don't match then we stop! |
| 930 | 972 | elseif (!$row['is_or']) |
| 931 | 973 | { |
@@ -933,8 +975,9 @@ discard block |
||
| 933 | 975 | break; |
| 934 | 976 | } |
| 935 | 977 | } |
| 936 | - if ($delete) |
|
| 937 | - $deletes[$row['id_member']] = 1; |
|
| 978 | + if ($delete) { |
|
| 979 | + $deletes[$row['id_member']] = 1; |
|
| 980 | + } |
|
| 938 | 981 | } |
| 939 | 982 | $smcFunc['db_free_result']($request); |
| 940 | 983 | |
@@ -949,8 +992,9 @@ discard block |
||
| 949 | 992 | array( |
| 950 | 993 | ) |
| 951 | 994 | ); |
| 952 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 953 | - $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
| 995 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 996 | + $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
| 997 | + } |
|
| 954 | 998 | $smcFunc['db_free_result']($request); |
| 955 | 999 | } |
| 956 | 1000 | |
@@ -958,8 +1002,9 @@ discard block |
||
| 958 | 1002 | require_once($sourcedir . '/Subs-Members.php'); |
| 959 | 1003 | $pmReadGroups = groupsAllowedTo('pm_read'); |
| 960 | 1004 | |
| 961 | - if (empty($modSettings['permission_enable_deny'])) |
|
| 962 | - $pmReadGroups['denied'] = array(); |
|
| 1005 | + if (empty($modSettings['permission_enable_deny'])) { |
|
| 1006 | + $pmReadGroups['denied'] = array(); |
|
| 1007 | + } |
|
| 963 | 1008 | |
| 964 | 1009 | // Load their alert preferences |
| 965 | 1010 | require_once($sourcedir . '/Subs-Notify.php'); |
@@ -991,8 +1036,9 @@ discard block |
||
| 991 | 1036 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 992 | 1037 | { |
| 993 | 1038 | // Don't do anything for members to be deleted! |
| 994 | - if (isset($deletes[$row['id_member']])) |
|
| 995 | - continue; |
|
| 1039 | + if (isset($deletes[$row['id_member']])) { |
|
| 1040 | + continue; |
|
| 1041 | + } |
|
| 996 | 1042 | |
| 997 | 1043 | // Load the preferences for this member (if any) |
| 998 | 1044 | $prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array(); |
@@ -1013,8 +1059,9 @@ discard block |
||
| 1013 | 1059 | { |
| 1014 | 1060 | foreach ($groups as $id) |
| 1015 | 1061 | { |
| 1016 | - if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) |
|
| 1017 | - $message_limit = $message_limit_cache[$id]; |
|
| 1062 | + if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) { |
|
| 1063 | + $message_limit = $message_limit_cache[$id]; |
|
| 1064 | + } |
|
| 1018 | 1065 | } |
| 1019 | 1066 | |
| 1020 | 1067 | if ($message_limit > 0 && $message_limit <= $row['instant_messages']) |
@@ -1062,8 +1109,9 @@ discard block |
||
| 1062 | 1109 | $smcFunc['db_free_result']($request); |
| 1063 | 1110 | |
| 1064 | 1111 | // Only 'send' the message if there are any recipients left. |
| 1065 | - if (empty($all_to)) |
|
| 1066 | - return $log; |
|
| 1112 | + if (empty($all_to)) { |
|
| 1113 | + return $log; |
|
| 1114 | + } |
|
| 1067 | 1115 | |
| 1068 | 1116 | // Insert the message itself and then grab the last insert id. |
| 1069 | 1117 | $smcFunc['db_insert']('', |
@@ -1084,8 +1132,8 @@ discard block |
||
| 1084 | 1132 | if (!empty($id_pm)) |
| 1085 | 1133 | { |
| 1086 | 1134 | // If this is new we need to set it part of it's own conversation. |
| 1087 | - if (empty($pm_head)) |
|
| 1088 | - $smcFunc['db_query']('', ' |
|
| 1135 | + if (empty($pm_head)) { |
|
| 1136 | + $smcFunc['db_query']('', ' |
|
| 1089 | 1137 | UPDATE {db_prefix}personal_messages |
| 1090 | 1138 | SET id_pm_head = {int:id_pm_head} |
| 1091 | 1139 | WHERE id_pm = {int:id_pm_head}', |
@@ -1093,6 +1141,7 @@ discard block |
||
| 1093 | 1141 | 'id_pm_head' => $id_pm, |
| 1094 | 1142 | ) |
| 1095 | 1143 | ); |
| 1144 | + } |
|
| 1096 | 1145 | |
| 1097 | 1146 | // Some people think manually deleting personal_messages is fun... it's not. We protect against it though :) |
| 1098 | 1147 | $smcFunc['db_query']('', ' |
@@ -1108,8 +1157,9 @@ discard block |
||
| 1108 | 1157 | foreach ($all_to as $to) |
| 1109 | 1158 | { |
| 1110 | 1159 | $insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1); |
| 1111 | - if (!in_array($to, $recipients['bcc'])) |
|
| 1112 | - $to_list[] = $to; |
|
| 1160 | + if (!in_array($to, $recipients['bcc'])) { |
|
| 1161 | + $to_list[] = $to; |
|
| 1162 | + } |
|
| 1113 | 1163 | } |
| 1114 | 1164 | |
| 1115 | 1165 | $smcFunc['db_insert']('insert', |
@@ -1127,9 +1177,9 @@ discard block |
||
| 1127 | 1177 | { |
| 1128 | 1178 | censorText($message); |
| 1129 | 1179 | $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']'))))); |
| 1180 | + } else { |
|
| 1181 | + $message = ''; |
|
| 1130 | 1182 | } |
| 1131 | - else |
|
| 1132 | - $message = ''; |
|
| 1133 | 1183 | |
| 1134 | 1184 | $to_names = array(); |
| 1135 | 1185 | if (count($to_list) > 1) |
@@ -1142,8 +1192,9 @@ discard block |
||
| 1142 | 1192 | 'to_members' => $to_list, |
| 1143 | 1193 | ) |
| 1144 | 1194 | ); |
| 1145 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1146 | - $to_names[] = un_htmlspecialchars($row['real_name']); |
|
| 1195 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1196 | + $to_names[] = un_htmlspecialchars($row['real_name']); |
|
| 1197 | + } |
|
| 1147 | 1198 | $smcFunc['db_free_result']($request); |
| 1148 | 1199 | } |
| 1149 | 1200 | $replacements = array( |
@@ -1171,11 +1222,13 @@ discard block |
||
| 1171 | 1222 | loadLanguage('index+PersonalMessage'); |
| 1172 | 1223 | |
| 1173 | 1224 | // Add one to their unread and read message counts. |
| 1174 | - foreach ($all_to as $k => $id) |
|
| 1175 | - if (isset($deletes[$id])) |
|
| 1225 | + foreach ($all_to as $k => $id) { |
|
| 1226 | + if (isset($deletes[$id])) |
|
| 1176 | 1227 | unset($all_to[$k]); |
| 1177 | - if (!empty($all_to)) |
|
| 1178 | - updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
| 1228 | + } |
|
| 1229 | + if (!empty($all_to)) { |
|
| 1230 | + updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
| 1231 | + } |
|
| 1179 | 1232 | |
| 1180 | 1233 | return $log; |
| 1181 | 1234 | } |
@@ -1205,15 +1258,17 @@ discard block |
||
| 1205 | 1258 | // Let's, for now, assume there are only 'ish characters. |
| 1206 | 1259 | $simple = true; |
| 1207 | 1260 | |
| 1208 | - foreach ($matches[1] as $entity) |
|
| 1209 | - if ($entity > 128) |
|
| 1261 | + foreach ($matches[1] as $entity) { |
|
| 1262 | + if ($entity > 128) |
|
| 1210 | 1263 | $simple = false; |
| 1264 | + } |
|
| 1211 | 1265 | unset($matches); |
| 1212 | 1266 | |
| 1213 | - if ($simple) |
|
| 1214 | - $string = preg_replace_callback('~&#(\d{3,8});~', function ($m) |
|
| 1267 | + if ($simple) { |
|
| 1268 | + $string = preg_replace_callback('~&#(\d{3,8});~', function ($m) |
|
| 1215 | 1269 | { |
| 1216 | 1270 | return chr("$m[1]"); |
| 1271 | + } |
|
| 1217 | 1272 | }, $string); |
| 1218 | 1273 | else |
| 1219 | 1274 | { |
@@ -1221,8 +1276,9 @@ discard block |
||
| 1221 | 1276 | if (!$context['utf8'] && function_exists('iconv')) |
| 1222 | 1277 | { |
| 1223 | 1278 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
| 1224 | - if ($newstring) |
|
| 1225 | - $string = $newstring; |
|
| 1279 | + if ($newstring) { |
|
| 1280 | + $string = $newstring; |
|
| 1281 | + } |
|
| 1226 | 1282 | } |
| 1227 | 1283 | |
| 1228 | 1284 | $string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string); |
@@ -1238,23 +1294,25 @@ discard block |
||
| 1238 | 1294 | if (!$context['utf8'] && function_exists('iconv')) |
| 1239 | 1295 | { |
| 1240 | 1296 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
| 1241 | - if ($newstring) |
|
| 1242 | - $string = $newstring; |
|
| 1297 | + if ($newstring) { |
|
| 1298 | + $string = $newstring; |
|
| 1299 | + } |
|
| 1243 | 1300 | } |
| 1244 | 1301 | |
| 1245 | 1302 | $entityConvert = function ($m) |
| 1246 | 1303 | { |
| 1247 | 1304 | $c = $m[1]; |
| 1248 | - if (strlen($c) === 1 && ord($c[0]) <= 0x7F) |
|
| 1249 | - return $c; |
|
| 1250 | - elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) |
|
| 1251 | - return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
| 1252 | - elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) |
|
| 1253 | - return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
| 1254 | - elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) |
|
| 1255 | - return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
| 1256 | - else |
|
| 1257 | - return ""; |
|
| 1305 | + if (strlen($c) === 1 && ord($c[0]) <= 0x7F) { |
|
| 1306 | + return $c; |
|
| 1307 | + } elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) { |
|
| 1308 | + return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
| 1309 | + } elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) { |
|
| 1310 | + return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
| 1311 | + } elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) { |
|
| 1312 | + return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
| 1313 | + } else { |
|
| 1314 | + return ""; |
|
| 1315 | + } |
|
| 1258 | 1316 | }; |
| 1259 | 1317 | |
| 1260 | 1318 | // Convert all 'special' characters to HTML entities. |
@@ -1268,19 +1326,20 @@ discard block |
||
| 1268 | 1326 | $string = base64_encode($string); |
| 1269 | 1327 | |
| 1270 | 1328 | // Show the characterset and the transfer-encoding for header strings. |
| 1271 | - if ($with_charset) |
|
| 1272 | - $string = '=?' . $charset . '?B?' . $string . '?='; |
|
| 1329 | + if ($with_charset) { |
|
| 1330 | + $string = '=?' . $charset . '?B?' . $string . '?='; |
|
| 1331 | + } |
|
| 1273 | 1332 | |
| 1274 | 1333 | // Break it up in lines (mail body). |
| 1275 | - else |
|
| 1276 | - $string = chunk_split($string, 76, $line_break); |
|
| 1334 | + else { |
|
| 1335 | + $string = chunk_split($string, 76, $line_break); |
|
| 1336 | + } |
|
| 1277 | 1337 | |
| 1278 | 1338 | return array($charset, $string, 'base64'); |
| 1339 | + } else { |
|
| 1340 | + return array($charset, $string, '7bit'); |
|
| 1341 | + } |
|
| 1279 | 1342 | } |
| 1280 | - |
|
| 1281 | - else |
|
| 1282 | - return array($charset, $string, '7bit'); |
|
| 1283 | -} |
|
| 1284 | 1343 | |
| 1285 | 1344 | /** |
| 1286 | 1345 | * Sends mail, like mail() but over SMTP. |
@@ -1304,8 +1363,9 @@ discard block |
||
| 1304 | 1363 | if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
| 1305 | 1364 | { |
| 1306 | 1365 | $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2); |
| 1307 | - if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) |
|
| 1308 | - $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
| 1366 | + if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) { |
|
| 1367 | + $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
| 1368 | + } |
|
| 1309 | 1369 | |
| 1310 | 1370 | if ($socket) |
| 1311 | 1371 | { |
@@ -1326,8 +1386,9 @@ discard block |
||
| 1326 | 1386 | // Maybe we can still save this? The port might be wrong. |
| 1327 | 1387 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
| 1328 | 1388 | { |
| 1329 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
| 1330 | - log_error($txt['smtp_port_ssl']); |
|
| 1389 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
| 1390 | + log_error($txt['smtp_port_ssl']); |
|
| 1391 | + } |
|
| 1331 | 1392 | } |
| 1332 | 1393 | |
| 1333 | 1394 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1339,20 +1400,23 @@ discard block |
||
| 1339 | 1400 | } |
| 1340 | 1401 | |
| 1341 | 1402 | // Wait for a response of 220, without "-" continuer. |
| 1342 | - if (!server_parse(null, $socket, '220')) |
|
| 1343 | - return false; |
|
| 1403 | + if (!server_parse(null, $socket, '220')) { |
|
| 1404 | + return false; |
|
| 1405 | + } |
|
| 1344 | 1406 | |
| 1345 | 1407 | // Try and determine the servers name, fall back to the mail servers if not found |
| 1346 | 1408 | $helo = false; |
| 1347 | - if (function_exists('gethostname') && gethostname() !== false) |
|
| 1348 | - $helo = gethostname(); |
|
| 1349 | - elseif (function_exists('php_uname')) |
|
| 1350 | - $helo = php_uname('n'); |
|
| 1351 | - elseif (array_key_exists('SERVER_NAME',$_SERVER) && !empty($_SERVER['SERVER_NAME'])) |
|
| 1352 | - $helo = $_SERVER['SERVER_NAME']; |
|
| 1409 | + if (function_exists('gethostname') && gethostname() !== false) { |
|
| 1410 | + $helo = gethostname(); |
|
| 1411 | + } elseif (function_exists('php_uname')) { |
|
| 1412 | + $helo = php_uname('n'); |
|
| 1413 | + } elseif (array_key_exists('SERVER_NAME',$_SERVER) && !empty($_SERVER['SERVER_NAME'])) { |
|
| 1414 | + $helo = $_SERVER['SERVER_NAME']; |
|
| 1415 | + } |
|
| 1353 | 1416 | |
| 1354 | - if (empty($helo)) |
|
| 1355 | - $helo = $modSettings['smtp_host']; |
|
| 1417 | + if (empty($helo)) { |
|
| 1418 | + $helo = $modSettings['smtp_host']; |
|
| 1419 | + } |
|
| 1356 | 1420 | |
| 1357 | 1421 | // SMTP = 1, SMTP - STARTTLS = 2 |
| 1358 | 1422 | if (in_array($modSettings['mail_type'], array(1,2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
@@ -1364,33 +1428,39 @@ discard block |
||
| 1364 | 1428 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
| 1365 | 1429 | { |
| 1366 | 1430 | // Send STARTTLS to enable encryption |
| 1367 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
| 1368 | - return false; |
|
| 1431 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
| 1432 | + return false; |
|
| 1433 | + } |
|
| 1369 | 1434 | // Enable the encryption |
| 1370 | - if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) |
|
| 1371 | - return false; |
|
| 1435 | + if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 1436 | + return false; |
|
| 1437 | + } |
|
| 1372 | 1438 | // Send the EHLO command again |
| 1373 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
| 1374 | - return false; |
|
| 1439 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
| 1440 | + return false; |
|
| 1441 | + } |
|
| 1375 | 1442 | } |
| 1376 | 1443 | |
| 1377 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
| 1378 | - return false; |
|
| 1444 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
| 1445 | + return false; |
|
| 1446 | + } |
|
| 1379 | 1447 | // Send the username and password, encoded. |
| 1380 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
| 1381 | - return false; |
|
| 1448 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
| 1449 | + return false; |
|
| 1450 | + } |
|
| 1382 | 1451 | // The password is already encoded ;) |
| 1383 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
| 1384 | - return false; |
|
| 1452 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
| 1453 | + return false; |
|
| 1454 | + } |
|
| 1455 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
| 1456 | + return false; |
|
| 1385 | 1457 | } |
| 1386 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
| 1387 | - return false; |
|
| 1388 | - } |
|
| 1389 | - else |
|
| 1458 | + } else |
|
| 1390 | 1459 | { |
| 1391 | 1460 | // Just say "helo". |
| 1392 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
| 1393 | - return false; |
|
| 1461 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
| 1462 | + return false; |
|
| 1463 | + } |
|
| 1394 | 1464 | } |
| 1395 | 1465 | |
| 1396 | 1466 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1403,31 +1473,38 @@ discard block |
||
| 1403 | 1473 | // Reset the connection to send another email. |
| 1404 | 1474 | if ($i != 0) |
| 1405 | 1475 | { |
| 1406 | - if (!server_parse('RSET', $socket, '250')) |
|
| 1407 | - return false; |
|
| 1476 | + if (!server_parse('RSET', $socket, '250')) { |
|
| 1477 | + return false; |
|
| 1478 | + } |
|
| 1408 | 1479 | } |
| 1409 | 1480 | |
| 1410 | 1481 | // From, to, and then start the data... |
| 1411 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
| 1412 | - return false; |
|
| 1413 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
| 1414 | - return false; |
|
| 1415 | - if (!server_parse('DATA', $socket, '354')) |
|
| 1416 | - return false; |
|
| 1482 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
| 1483 | + return false; |
|
| 1484 | + } |
|
| 1485 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
| 1486 | + return false; |
|
| 1487 | + } |
|
| 1488 | + if (!server_parse('DATA', $socket, '354')) { |
|
| 1489 | + return false; |
|
| 1490 | + } |
|
| 1417 | 1491 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
| 1418 | - if (strlen($mail_to) > 0) |
|
| 1419 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
| 1492 | + if (strlen($mail_to) > 0) { |
|
| 1493 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
| 1494 | + } |
|
| 1420 | 1495 | fputs($socket, $headers . "\r\n\r\n"); |
| 1421 | 1496 | fputs($socket, $message . "\r\n"); |
| 1422 | 1497 | |
| 1423 | 1498 | // Send a ., or in other words "end of data". |
| 1424 | - if (!server_parse('.', $socket, '250')) |
|
| 1425 | - return false; |
|
| 1499 | + if (!server_parse('.', $socket, '250')) { |
|
| 1500 | + return false; |
|
| 1501 | + } |
|
| 1426 | 1502 | |
| 1427 | 1503 | // Almost done, almost done... don't stop me just yet! |
| 1428 | 1504 | @set_time_limit(300); |
| 1429 | - if (function_exists('apache_reset_timeout')) |
|
| 1430 | - @apache_reset_timeout(); |
|
| 1505 | + if (function_exists('apache_reset_timeout')) { |
|
| 1506 | + @apache_reset_timeout(); |
|
| 1507 | + } |
|
| 1431 | 1508 | } |
| 1432 | 1509 | fputs($socket, 'QUIT' . "\r\n"); |
| 1433 | 1510 | fclose($socket); |
@@ -1451,8 +1528,9 @@ discard block |
||
| 1451 | 1528 | { |
| 1452 | 1529 | global $txt; |
| 1453 | 1530 | |
| 1454 | - if ($message !== null) |
|
| 1455 | - fputs($socket, $message . "\r\n"); |
|
| 1531 | + if ($message !== null) { |
|
| 1532 | + fputs($socket, $message . "\r\n"); |
|
| 1533 | + } |
|
| 1456 | 1534 | |
| 1457 | 1535 | // No response yet. |
| 1458 | 1536 | $server_response = ''; |
@@ -1468,8 +1546,9 @@ discard block |
||
| 1468 | 1546 | $response .= $server_response; |
| 1469 | 1547 | } |
| 1470 | 1548 | |
| 1471 | - if ($code === null) |
|
| 1472 | - return substr($server_response, 0, 3); |
|
| 1549 | + if ($code === null) { |
|
| 1550 | + return substr($server_response, 0, 3); |
|
| 1551 | + } |
|
| 1473 | 1552 | |
| 1474 | 1553 | if (substr($server_response, 0, 3) != $code) |
| 1475 | 1554 | { |
@@ -1499,8 +1578,9 @@ discard block |
||
| 1499 | 1578 | // Create a pspell or enchant dictionary resource |
| 1500 | 1579 | $dict = spell_init(); |
| 1501 | 1580 | |
| 1502 | - if (!isset($_POST['spellstring']) || !$dict) |
|
| 1503 | - die; |
|
| 1581 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
| 1582 | + die; |
|
| 1583 | + } |
|
| 1504 | 1584 | |
| 1505 | 1585 | // Construct a bit of Javascript code. |
| 1506 | 1586 | $context['spell_js'] = ' |
@@ -1518,8 +1598,9 @@ discard block |
||
| 1518 | 1598 | $check_word = explode('|', $alphas[$i]); |
| 1519 | 1599 | |
| 1520 | 1600 | // If the word is a known word, or spelled right... |
| 1521 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
| 1522 | - continue; |
|
| 1601 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
| 1602 | + continue; |
|
| 1603 | + } |
|
| 1523 | 1604 | |
| 1524 | 1605 | // Find the word, and move up the "last occurrence" to here. |
| 1525 | 1606 | $found_words = true; |
@@ -1533,20 +1614,23 @@ discard block |
||
| 1533 | 1614 | if (!empty($suggestions)) |
| 1534 | 1615 | { |
| 1535 | 1616 | // But first check they aren't going to be censored - no naughty words! |
| 1536 | - foreach ($suggestions as $k => $word) |
|
| 1537 | - if ($suggestions[$k] != censorText($word)) |
|
| 1617 | + foreach ($suggestions as $k => $word) { |
|
| 1618 | + if ($suggestions[$k] != censorText($word)) |
|
| 1538 | 1619 | unset($suggestions[$k]); |
| 1620 | + } |
|
| 1539 | 1621 | |
| 1540 | - if (!empty($suggestions)) |
|
| 1541 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
| 1622 | + if (!empty($suggestions)) { |
|
| 1623 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
| 1624 | + } |
|
| 1542 | 1625 | } |
| 1543 | 1626 | |
| 1544 | 1627 | $context['spell_js'] .= ']),'; |
| 1545 | 1628 | } |
| 1546 | 1629 | |
| 1547 | 1630 | // If words were found, take off the last comma. |
| 1548 | - if ($found_words) |
|
| 1549 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
| 1631 | + if ($found_words) { |
|
| 1632 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
| 1633 | + } |
|
| 1550 | 1634 | |
| 1551 | 1635 | $context['spell_js'] .= ' |
| 1552 | 1636 | );'; |
@@ -1581,11 +1665,13 @@ discard block |
||
| 1581 | 1665 | global $user_info, $smcFunc; |
| 1582 | 1666 | |
| 1583 | 1667 | // Can't do it if there's no topics. |
| 1584 | - if (empty($topics)) |
|
| 1585 | - return; |
|
| 1668 | + if (empty($topics)) { |
|
| 1669 | + return; |
|
| 1670 | + } |
|
| 1586 | 1671 | // It must be an array - it must! |
| 1587 | - if (!is_array($topics)) |
|
| 1588 | - $topics = array($topics); |
|
| 1672 | + if (!is_array($topics)) { |
|
| 1673 | + $topics = array($topics); |
|
| 1674 | + } |
|
| 1589 | 1675 | |
| 1590 | 1676 | // Get the subject and body... |
| 1591 | 1677 | $result = $smcFunc['db_query']('', ' |
@@ -1633,14 +1719,15 @@ discard block |
||
| 1633 | 1719 | } |
| 1634 | 1720 | $smcFunc['db_free_result']($result); |
| 1635 | 1721 | |
| 1636 | - if (!empty($task_rows)) |
|
| 1637 | - $smcFunc['db_insert']('', |
|
| 1722 | + if (!empty($task_rows)) { |
|
| 1723 | + $smcFunc['db_insert']('', |
|
| 1638 | 1724 | '{db_prefix}background_tasks', |
| 1639 | 1725 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 1640 | 1726 | $task_rows, |
| 1641 | 1727 | array('id_task') |
| 1642 | 1728 | ); |
| 1643 | -} |
|
| 1729 | + } |
|
| 1730 | + } |
|
| 1644 | 1731 | |
| 1645 | 1732 | /** |
| 1646 | 1733 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1678,9 +1765,9 @@ discard block |
||
| 1678 | 1765 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
| 1679 | 1766 | |
| 1680 | 1767 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
| 1681 | - if (!$modSettings['postmod_active']) |
|
| 1682 | - $topicOptions['is_approved'] = true; |
|
| 1683 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
| 1768 | + if (!$modSettings['postmod_active']) { |
|
| 1769 | + $topicOptions['is_approved'] = true; |
|
| 1770 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
| 1684 | 1771 | { |
| 1685 | 1772 | $request = $smcFunc['db_query']('', ' |
| 1686 | 1773 | SELECT approved |
@@ -1703,8 +1790,7 @@ discard block |
||
| 1703 | 1790 | $posterOptions['id'] = 0; |
| 1704 | 1791 | $posterOptions['name'] = $txt['guest_title']; |
| 1705 | 1792 | $posterOptions['email'] = ''; |
| 1706 | - } |
|
| 1707 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
| 1793 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
| 1708 | 1794 | { |
| 1709 | 1795 | $request = $smcFunc['db_query']('', ' |
| 1710 | 1796 | SELECT member_name, email_address |
@@ -1722,12 +1808,11 @@ discard block |
||
| 1722 | 1808 | $posterOptions['id'] = 0; |
| 1723 | 1809 | $posterOptions['name'] = $txt['guest_title']; |
| 1724 | 1810 | $posterOptions['email'] = ''; |
| 1811 | + } else { |
|
| 1812 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
| 1725 | 1813 | } |
| 1726 | - else |
|
| 1727 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
| 1728 | 1814 | $smcFunc['db_free_result']($request); |
| 1729 | - } |
|
| 1730 | - else |
|
| 1815 | + } else |
|
| 1731 | 1816 | { |
| 1732 | 1817 | $posterOptions['name'] = $user_info['name']; |
| 1733 | 1818 | $posterOptions['email'] = $user_info['email']; |
@@ -1737,8 +1822,9 @@ discard block |
||
| 1737 | 1822 | if (!empty($modSettings['enable_mentions'])) |
| 1738 | 1823 | { |
| 1739 | 1824 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
| 1740 | - if (!empty($msgOptions['mentioned_members'])) |
|
| 1741 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
| 1825 | + if (!empty($msgOptions['mentioned_members'])) { |
|
| 1826 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
| 1827 | + } |
|
| 1742 | 1828 | } |
| 1743 | 1829 | |
| 1744 | 1830 | // It's do or die time: forget any user aborts! |
@@ -1771,12 +1857,13 @@ discard block |
||
| 1771 | 1857 | $msgOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}messages', 'id_msg'); |
| 1772 | 1858 | |
| 1773 | 1859 | // Something went wrong creating the message... |
| 1774 | - if (empty($msgOptions['id'])) |
|
| 1775 | - return false; |
|
| 1860 | + if (empty($msgOptions['id'])) { |
|
| 1861 | + return false; |
|
| 1862 | + } |
|
| 1776 | 1863 | |
| 1777 | 1864 | // Fix the attachments. |
| 1778 | - if (!empty($msgOptions['attachments'])) |
|
| 1779 | - $smcFunc['db_query']('', ' |
|
| 1865 | + if (!empty($msgOptions['attachments'])) { |
|
| 1866 | + $smcFunc['db_query']('', ' |
|
| 1780 | 1867 | UPDATE {db_prefix}attachments |
| 1781 | 1868 | SET id_msg = {int:id_msg} |
| 1782 | 1869 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1785,6 +1872,7 @@ discard block |
||
| 1785 | 1872 | 'id_msg' => $msgOptions['id'], |
| 1786 | 1873 | ) |
| 1787 | 1874 | ); |
| 1875 | + } |
|
| 1788 | 1876 | |
| 1789 | 1877 | // What if we want to export new posts out to a CMS? |
| 1790 | 1878 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1862,20 +1950,23 @@ discard block |
||
| 1862 | 1950 | 'counter_increment' => 1, |
| 1863 | 1951 | ); |
| 1864 | 1952 | $topics_columns = array(); |
| 1865 | - if ($msgOptions['approved']) |
|
| 1866 | - $topics_columns = array( |
|
| 1953 | + if ($msgOptions['approved']) { |
|
| 1954 | + $topics_columns = array( |
|
| 1867 | 1955 | 'id_member_updated = {int:poster_id}', |
| 1868 | 1956 | 'id_last_msg = {int:id_msg}', |
| 1869 | 1957 | 'num_replies = num_replies + {int:counter_increment}', |
| 1870 | 1958 | ); |
| 1871 | - else |
|
| 1872 | - $topics_columns = array( |
|
| 1959 | + } else { |
|
| 1960 | + $topics_columns = array( |
|
| 1873 | 1961 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
| 1874 | 1962 | ); |
| 1875 | - if ($topicOptions['lock_mode'] !== null) |
|
| 1876 | - $topics_columns[] = 'locked = {int:locked}'; |
|
| 1877 | - if ($topicOptions['sticky_mode'] !== null) |
|
| 1878 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
| 1963 | + } |
|
| 1964 | + if ($topicOptions['lock_mode'] !== null) { |
|
| 1965 | + $topics_columns[] = 'locked = {int:locked}'; |
|
| 1966 | + } |
|
| 1967 | + if ($topicOptions['sticky_mode'] !== null) { |
|
| 1968 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
| 1969 | + } |
|
| 1879 | 1970 | |
| 1880 | 1971 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
| 1881 | 1972 | |
@@ -1904,8 +1995,8 @@ discard block |
||
| 1904 | 1995 | ); |
| 1905 | 1996 | |
| 1906 | 1997 | // Increase the number of posts and topics on the board. |
| 1907 | - if ($msgOptions['approved']) |
|
| 1908 | - $smcFunc['db_query']('', ' |
|
| 1998 | + if ($msgOptions['approved']) { |
|
| 1999 | + $smcFunc['db_query']('', ' |
|
| 1909 | 2000 | UPDATE {db_prefix}boards |
| 1910 | 2001 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
| 1911 | 2002 | WHERE id_board = {int:id_board}', |
@@ -1913,7 +2004,7 @@ discard block |
||
| 1913 | 2004 | 'id_board' => $topicOptions['board'], |
| 1914 | 2005 | ) |
| 1915 | 2006 | ); |
| 1916 | - else |
|
| 2007 | + } else |
|
| 1917 | 2008 | { |
| 1918 | 2009 | $smcFunc['db_query']('', ' |
| 1919 | 2010 | UPDATE {db_prefix}boards |
@@ -1983,8 +2074,8 @@ discard block |
||
| 1983 | 2074 | } |
| 1984 | 2075 | } |
| 1985 | 2076 | |
| 1986 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
| 1987 | - $smcFunc['db_insert']('', |
|
| 2077 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
| 2078 | + $smcFunc['db_insert']('', |
|
| 1988 | 2079 | '{db_prefix}background_tasks', |
| 1989 | 2080 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 1990 | 2081 | array( |
@@ -1996,19 +2087,22 @@ discard block |
||
| 1996 | 2087 | ), |
| 1997 | 2088 | array('id_task') |
| 1998 | 2089 | ); |
| 2090 | + } |
|
| 1999 | 2091 | |
| 2000 | 2092 | // If there's a custom search index, it may need updating... |
| 2001 | 2093 | require_once($sourcedir . '/Search.php'); |
| 2002 | 2094 | $searchAPI = findSearchAPI(); |
| 2003 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
| 2004 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
| 2095 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
| 2096 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
| 2097 | + } |
|
| 2005 | 2098 | |
| 2006 | 2099 | // Increase the post counter for the user that created the post. |
| 2007 | 2100 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
| 2008 | 2101 | { |
| 2009 | 2102 | // Are you the one that happened to create this post? |
| 2010 | - if ($user_info['id'] == $posterOptions['id']) |
|
| 2011 | - $user_info['posts']++; |
|
| 2103 | + if ($user_info['id'] == $posterOptions['id']) { |
|
| 2104 | + $user_info['posts']++; |
|
| 2105 | + } |
|
| 2012 | 2106 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
| 2013 | 2107 | } |
| 2014 | 2108 | |
@@ -2016,19 +2110,21 @@ discard block |
||
| 2016 | 2110 | $_SESSION['last_read_topic'] = 0; |
| 2017 | 2111 | |
| 2018 | 2112 | // Better safe than sorry. |
| 2019 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
| 2020 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
| 2113 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
| 2114 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
| 2115 | + } |
|
| 2021 | 2116 | |
| 2022 | 2117 | // Update all the stats so everyone knows about this new topic and message. |
| 2023 | 2118 | updateStats('message', true, $msgOptions['id']); |
| 2024 | 2119 | |
| 2025 | 2120 | // Update the last message on the board assuming it's approved AND the topic is. |
| 2026 | - if ($msgOptions['approved']) |
|
| 2027 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
| 2121 | + if ($msgOptions['approved']) { |
|
| 2122 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
| 2123 | + } |
|
| 2028 | 2124 | |
| 2029 | 2125 | // Queue createPost background notification |
| 2030 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
| 2031 | - $smcFunc['db_insert']('', |
|
| 2126 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
| 2127 | + $smcFunc['db_insert']('', |
|
| 2032 | 2128 | '{db_prefix}background_tasks', |
| 2033 | 2129 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 2034 | 2130 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
@@ -2039,6 +2135,7 @@ discard block |
||
| 2039 | 2135 | )), 0), |
| 2040 | 2136 | array('id_task') |
| 2041 | 2137 | ); |
| 2138 | + } |
|
| 2042 | 2139 | |
| 2043 | 2140 | // Alright, done now... we can abort now, I guess... at least this much is done. |
| 2044 | 2141 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2065,14 +2162,18 @@ discard block |
||
| 2065 | 2162 | |
| 2066 | 2163 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
| 2067 | 2164 | $messages_columns = array(); |
| 2068 | - if (isset($posterOptions['name'])) |
|
| 2069 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
| 2070 | - if (isset($posterOptions['email'])) |
|
| 2071 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
| 2072 | - if (isset($msgOptions['icon'])) |
|
| 2073 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
| 2074 | - if (isset($msgOptions['subject'])) |
|
| 2075 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
| 2165 | + if (isset($posterOptions['name'])) { |
|
| 2166 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
| 2167 | + } |
|
| 2168 | + if (isset($posterOptions['email'])) { |
|
| 2169 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
| 2170 | + } |
|
| 2171 | + if (isset($msgOptions['icon'])) { |
|
| 2172 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
| 2173 | + } |
|
| 2174 | + if (isset($msgOptions['subject'])) { |
|
| 2175 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
| 2176 | + } |
|
| 2076 | 2177 | if (isset($msgOptions['body'])) |
| 2077 | 2178 | { |
| 2078 | 2179 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2099,8 +2200,9 @@ discard block |
||
| 2099 | 2200 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
| 2100 | 2201 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
| 2101 | 2202 | } |
| 2102 | - if (isset($msgOptions['smileys_enabled'])) |
|
| 2103 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
| 2203 | + if (isset($msgOptions['smileys_enabled'])) { |
|
| 2204 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
| 2205 | + } |
|
| 2104 | 2206 | |
| 2105 | 2207 | // Which columns need to be ints? |
| 2106 | 2208 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2118,23 +2220,27 @@ discard block |
||
| 2118 | 2220 | { |
| 2119 | 2221 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
| 2120 | 2222 | |
| 2121 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
| 2122 | - foreach($match[1] as $i => $oldID) |
|
| 2223 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
| 2224 | + foreach($match[1] as $i => $oldID) |
|
| 2123 | 2225 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
| 2226 | + } |
|
| 2124 | 2227 | |
| 2125 | - if (empty($modSettings['search_custom_index_config'])) |
|
| 2126 | - unset($msgOptions['old_body']); |
|
| 2228 | + if (empty($modSettings['search_custom_index_config'])) { |
|
| 2229 | + unset($msgOptions['old_body']); |
|
| 2230 | + } |
|
| 2127 | 2231 | } |
| 2128 | 2232 | |
| 2129 | 2233 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
| 2130 | 2234 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
| 2131 | 2235 | |
| 2132 | 2236 | // Remove the poster. |
| 2133 | - if(isset($mentions[$user_info['id']])) |
|
| 2134 | - unset($mentions[$user_info['id']]); |
|
| 2237 | + if(isset($mentions[$user_info['id']])) { |
|
| 2238 | + unset($mentions[$user_info['id']]); |
|
| 2239 | + } |
|
| 2135 | 2240 | |
| 2136 | - if(isset($oldmentions[$user_info['id']])) |
|
| 2137 | - unset($oldmentions[$user_info['id']]); |
|
| 2241 | + if(isset($oldmentions[$user_info['id']])) { |
|
| 2242 | + unset($oldmentions[$user_info['id']]); |
|
| 2243 | + } |
|
| 2138 | 2244 | |
| 2139 | 2245 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
| 2140 | 2246 | { |
@@ -2164,8 +2270,9 @@ discard block |
||
| 2164 | 2270 | } |
| 2165 | 2271 | |
| 2166 | 2272 | // Nothing to do? |
| 2167 | - if (empty($messages_columns)) |
|
| 2168 | - return true; |
|
| 2273 | + if (empty($messages_columns)) { |
|
| 2274 | + return true; |
|
| 2275 | + } |
|
| 2169 | 2276 | |
| 2170 | 2277 | // Change the post. |
| 2171 | 2278 | $smcFunc['db_query']('', ' |
@@ -2226,8 +2333,9 @@ discard block |
||
| 2226 | 2333 | // If there's a custom search index, it needs to be modified... |
| 2227 | 2334 | require_once($sourcedir . '/Search.php'); |
| 2228 | 2335 | $searchAPI = findSearchAPI(); |
| 2229 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
| 2230 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
| 2336 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
| 2337 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
| 2338 | + } |
|
| 2231 | 2339 | |
| 2232 | 2340 | if (isset($msgOptions['subject'])) |
| 2233 | 2341 | { |
@@ -2241,14 +2349,16 @@ discard block |
||
| 2241 | 2349 | 'id_first_msg' => $msgOptions['id'], |
| 2242 | 2350 | ) |
| 2243 | 2351 | ); |
| 2244 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 2245 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
| 2352 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 2353 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
| 2354 | + } |
|
| 2246 | 2355 | $smcFunc['db_free_result']($request); |
| 2247 | 2356 | } |
| 2248 | 2357 | |
| 2249 | 2358 | // Finally, if we are setting the approved state we need to do much more work :( |
| 2250 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
| 2251 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
| 2359 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
| 2360 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
| 2361 | + } |
|
| 2252 | 2362 | |
| 2253 | 2363 | return true; |
| 2254 | 2364 | } |
@@ -2265,11 +2375,13 @@ discard block |
||
| 2265 | 2375 | { |
| 2266 | 2376 | global $smcFunc; |
| 2267 | 2377 | |
| 2268 | - if (!is_array($msgs)) |
|
| 2269 | - $msgs = array($msgs); |
|
| 2378 | + if (!is_array($msgs)) { |
|
| 2379 | + $msgs = array($msgs); |
|
| 2380 | + } |
|
| 2270 | 2381 | |
| 2271 | - if (empty($msgs)) |
|
| 2272 | - return false; |
|
| 2382 | + if (empty($msgs)) { |
|
| 2383 | + return false; |
|
| 2384 | + } |
|
| 2273 | 2385 | |
| 2274 | 2386 | // May as well start at the beginning, working out *what* we need to change. |
| 2275 | 2387 | $request = $smcFunc['db_query']('', ' |
@@ -2301,20 +2413,22 @@ discard block |
||
| 2301 | 2413 | $topics[] = $row['id_topic']; |
| 2302 | 2414 | |
| 2303 | 2415 | // Ensure our change array exists already. |
| 2304 | - if (!isset($topic_changes[$row['id_topic']])) |
|
| 2305 | - $topic_changes[$row['id_topic']] = array( |
|
| 2416 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
| 2417 | + $topic_changes[$row['id_topic']] = array( |
|
| 2306 | 2418 | 'id_last_msg' => $row['id_last_msg'], |
| 2307 | 2419 | 'approved' => $row['topic_approved'], |
| 2308 | 2420 | 'replies' => 0, |
| 2309 | 2421 | 'unapproved_posts' => 0, |
| 2310 | 2422 | ); |
| 2311 | - if (!isset($board_changes[$row['id_board']])) |
|
| 2312 | - $board_changes[$row['id_board']] = array( |
|
| 2423 | + } |
|
| 2424 | + if (!isset($board_changes[$row['id_board']])) { |
|
| 2425 | + $board_changes[$row['id_board']] = array( |
|
| 2313 | 2426 | 'posts' => 0, |
| 2314 | 2427 | 'topics' => 0, |
| 2315 | 2428 | 'unapproved_posts' => 0, |
| 2316 | 2429 | 'unapproved_topics' => 0, |
| 2317 | 2430 | ); |
| 2431 | + } |
|
| 2318 | 2432 | |
| 2319 | 2433 | // If it's the first message then the topic state changes! |
| 2320 | 2434 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2335,14 +2449,13 @@ discard block |
||
| 2335 | 2449 | 'poster' => $row['id_member'], |
| 2336 | 2450 | 'new_topic' => true, |
| 2337 | 2451 | ); |
| 2338 | - } |
|
| 2339 | - else |
|
| 2452 | + } else |
|
| 2340 | 2453 | { |
| 2341 | 2454 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
| 2342 | 2455 | |
| 2343 | 2456 | // This will be a post... but don't notify unless it's not followed by approved ones. |
| 2344 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
| 2345 | - $notification_posts[$row['id_topic']] = array( |
|
| 2457 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
| 2458 | + $notification_posts[$row['id_topic']] = array( |
|
| 2346 | 2459 | 'id' => $row['id_msg'], |
| 2347 | 2460 | 'body' => $row['body'], |
| 2348 | 2461 | 'subject' => $row['subject'], |
@@ -2353,28 +2466,33 @@ discard block |
||
| 2353 | 2466 | 'new_topic' => false, |
| 2354 | 2467 | 'msg' => $row['id_msg'], |
| 2355 | 2468 | ); |
| 2469 | + } |
|
| 2356 | 2470 | } |
| 2357 | 2471 | |
| 2358 | 2472 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
| 2359 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
| 2360 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
| 2473 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
| 2474 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
| 2475 | + } |
|
| 2361 | 2476 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
| 2362 | - elseif (!$approve) |
|
| 2363 | - // Default to the first message and then we'll override in a bit ;) |
|
| 2477 | + elseif (!$approve) { |
|
| 2478 | + // Default to the first message and then we'll override in a bit ;) |
|
| 2364 | 2479 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
| 2480 | + } |
|
| 2365 | 2481 | |
| 2366 | 2482 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
| 2367 | 2483 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
| 2368 | 2484 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
| 2369 | 2485 | |
| 2370 | 2486 | // Post count for the user? |
| 2371 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
| 2372 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
| 2487 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
| 2488 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
| 2489 | + } |
|
| 2373 | 2490 | } |
| 2374 | 2491 | $smcFunc['db_free_result']($request); |
| 2375 | 2492 | |
| 2376 | - if (empty($msgs)) |
|
| 2377 | - return; |
|
| 2493 | + if (empty($msgs)) { |
|
| 2494 | + return; |
|
| 2495 | + } |
|
| 2378 | 2496 | |
| 2379 | 2497 | // Now we have the differences make the changes, first the easy one. |
| 2380 | 2498 | $smcFunc['db_query']('', ' |
@@ -2401,14 +2519,15 @@ discard block |
||
| 2401 | 2519 | 'approved' => 1, |
| 2402 | 2520 | ) |
| 2403 | 2521 | ); |
| 2404 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2405 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
| 2522 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2523 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
| 2524 | + } |
|
| 2406 | 2525 | $smcFunc['db_free_result']($request); |
| 2407 | 2526 | } |
| 2408 | 2527 | |
| 2409 | 2528 | // ... next the topics... |
| 2410 | - foreach ($topic_changes as $id => $changes) |
|
| 2411 | - $smcFunc['db_query']('', ' |
|
| 2529 | + foreach ($topic_changes as $id => $changes) { |
|
| 2530 | + $smcFunc['db_query']('', ' |
|
| 2412 | 2531 | UPDATE {db_prefix}topics |
| 2413 | 2532 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
| 2414 | 2533 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2421,10 +2540,11 @@ discard block |
||
| 2421 | 2540 | 'id_topic' => $id, |
| 2422 | 2541 | ) |
| 2423 | 2542 | ); |
| 2543 | + } |
|
| 2424 | 2544 | |
| 2425 | 2545 | // ... finally the boards... |
| 2426 | - foreach ($board_changes as $id => $changes) |
|
| 2427 | - $smcFunc['db_query']('', ' |
|
| 2546 | + foreach ($board_changes as $id => $changes) { |
|
| 2547 | + $smcFunc['db_query']('', ' |
|
| 2428 | 2548 | UPDATE {db_prefix}boards |
| 2429 | 2549 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
| 2430 | 2550 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2437,13 +2557,14 @@ discard block |
||
| 2437 | 2557 | 'id_board' => $id, |
| 2438 | 2558 | ) |
| 2439 | 2559 | ); |
| 2560 | + } |
|
| 2440 | 2561 | |
| 2441 | 2562 | // Finally, least importantly, notifications! |
| 2442 | 2563 | if ($approve) |
| 2443 | 2564 | { |
| 2444 | 2565 | $task_rows = array(); |
| 2445 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
| 2446 | - $task_rows[] = array( |
|
| 2566 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
| 2567 | + $task_rows[] = array( |
|
| 2447 | 2568 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
| 2448 | 2569 | 'msgOptions' => array( |
| 2449 | 2570 | 'id' => $topic['msg'], |
@@ -2461,14 +2582,16 @@ discard block |
||
| 2461 | 2582 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
| 2462 | 2583 | )), 0 |
| 2463 | 2584 | ); |
| 2585 | + } |
|
| 2464 | 2586 | |
| 2465 | - if ($notify) |
|
| 2466 | - $smcFunc['db_insert']('', |
|
| 2587 | + if ($notify) { |
|
| 2588 | + $smcFunc['db_insert']('', |
|
| 2467 | 2589 | '{db_prefix}background_tasks', |
| 2468 | 2590 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 2469 | 2591 | $task_rows, |
| 2470 | 2592 | array('id_task') |
| 2471 | 2593 | ); |
| 2594 | + } |
|
| 2472 | 2595 | |
| 2473 | 2596 | $smcFunc['db_query']('', ' |
| 2474 | 2597 | DELETE FROM {db_prefix}approval_queue |
@@ -2484,8 +2607,9 @@ discard block |
||
| 2484 | 2607 | else |
| 2485 | 2608 | { |
| 2486 | 2609 | $msgInserts = array(); |
| 2487 | - foreach ($msgs as $msg) |
|
| 2488 | - $msgInserts[] = array($msg); |
|
| 2610 | + foreach ($msgs as $msg) { |
|
| 2611 | + $msgInserts[] = array($msg); |
|
| 2612 | + } |
|
| 2489 | 2613 | |
| 2490 | 2614 | $smcFunc['db_insert']('ignore', |
| 2491 | 2615 | '{db_prefix}approval_queue', |
@@ -2499,9 +2623,10 @@ discard block |
||
| 2499 | 2623 | updateLastMessages(array_keys($board_changes)); |
| 2500 | 2624 | |
| 2501 | 2625 | // Post count for the members? |
| 2502 | - if (!empty($member_post_changes)) |
|
| 2503 | - foreach ($member_post_changes as $id_member => $count_change) |
|
| 2626 | + if (!empty($member_post_changes)) { |
|
| 2627 | + foreach ($member_post_changes as $id_member => $count_change) |
|
| 2504 | 2628 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
| 2629 | + } |
|
| 2505 | 2630 | |
| 2506 | 2631 | return true; |
| 2507 | 2632 | } |
@@ -2518,11 +2643,13 @@ discard block |
||
| 2518 | 2643 | { |
| 2519 | 2644 | global $smcFunc; |
| 2520 | 2645 | |
| 2521 | - if (!is_array($topics)) |
|
| 2522 | - $topics = array($topics); |
|
| 2646 | + if (!is_array($topics)) { |
|
| 2647 | + $topics = array($topics); |
|
| 2648 | + } |
|
| 2523 | 2649 | |
| 2524 | - if (empty($topics)) |
|
| 2525 | - return false; |
|
| 2650 | + if (empty($topics)) { |
|
| 2651 | + return false; |
|
| 2652 | + } |
|
| 2526 | 2653 | |
| 2527 | 2654 | $approve_type = $approve ? 0 : 1; |
| 2528 | 2655 | |
@@ -2538,8 +2665,9 @@ discard block |
||
| 2538 | 2665 | ) |
| 2539 | 2666 | ); |
| 2540 | 2667 | $msgs = array(); |
| 2541 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2542 | - $msgs[] = $row['id_msg']; |
|
| 2668 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2669 | + $msgs[] = $row['id_msg']; |
|
| 2670 | + } |
|
| 2543 | 2671 | $smcFunc['db_free_result']($request); |
| 2544 | 2672 | |
| 2545 | 2673 | return approvePosts($msgs, $approve); |
@@ -2562,11 +2690,13 @@ discard block |
||
| 2562 | 2690 | global $board_info, $board, $smcFunc; |
| 2563 | 2691 | |
| 2564 | 2692 | // Please - let's be sane. |
| 2565 | - if (empty($setboards)) |
|
| 2566 | - return false; |
|
| 2693 | + if (empty($setboards)) { |
|
| 2694 | + return false; |
|
| 2695 | + } |
|
| 2567 | 2696 | |
| 2568 | - if (!is_array($setboards)) |
|
| 2569 | - $setboards = array($setboards); |
|
| 2697 | + if (!is_array($setboards)) { |
|
| 2698 | + $setboards = array($setboards); |
|
| 2699 | + } |
|
| 2570 | 2700 | |
| 2571 | 2701 | // If we don't know the id_msg we need to find it. |
| 2572 | 2702 | if (!$id_msg) |
@@ -2584,15 +2714,16 @@ discard block |
||
| 2584 | 2714 | ) |
| 2585 | 2715 | ); |
| 2586 | 2716 | $lastMsg = array(); |
| 2587 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2588 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
| 2717 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2718 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
| 2719 | + } |
|
| 2589 | 2720 | $smcFunc['db_free_result']($request); |
| 2590 | - } |
|
| 2591 | - else |
|
| 2721 | + } else |
|
| 2592 | 2722 | { |
| 2593 | 2723 | // Just to note - there should only be one board passed if we are doing this. |
| 2594 | - foreach ($setboards as $id_board) |
|
| 2595 | - $lastMsg[$id_board] = $id_msg; |
|
| 2724 | + foreach ($setboards as $id_board) { |
|
| 2725 | + $lastMsg[$id_board] = $id_msg; |
|
| 2726 | + } |
|
| 2596 | 2727 | } |
| 2597 | 2728 | |
| 2598 | 2729 | $parent_boards = array(); |
@@ -2607,10 +2738,11 @@ discard block |
||
| 2607 | 2738 | $lastModified[$id_board] = 0; |
| 2608 | 2739 | } |
| 2609 | 2740 | |
| 2610 | - if (!empty($board) && $id_board == $board) |
|
| 2611 | - $parents = $board_info['parent_boards']; |
|
| 2612 | - else |
|
| 2613 | - $parents = getBoardParents($id_board); |
|
| 2741 | + if (!empty($board) && $id_board == $board) { |
|
| 2742 | + $parents = $board_info['parent_boards']; |
|
| 2743 | + } else { |
|
| 2744 | + $parents = getBoardParents($id_board); |
|
| 2745 | + } |
|
| 2614 | 2746 | |
| 2615 | 2747 | // Ignore any parents on the top child level. |
| 2616 | 2748 | // @todo Why? |
@@ -2619,10 +2751,11 @@ discard block |
||
| 2619 | 2751 | if ($parent['level'] != 0) |
| 2620 | 2752 | { |
| 2621 | 2753 | // If we're already doing this one as a board, is this a higher last modified? |
| 2622 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
| 2623 | - $lastModified[$id] = $lastModified[$id_board]; |
|
| 2624 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
| 2625 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
| 2754 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
| 2755 | + $lastModified[$id] = $lastModified[$id_board]; |
|
| 2756 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
| 2757 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
| 2758 | + } |
|
| 2626 | 2759 | } |
| 2627 | 2760 | } |
| 2628 | 2761 | } |
@@ -2635,23 +2768,24 @@ discard block |
||
| 2635 | 2768 | // Finally, to save on queries make the changes... |
| 2636 | 2769 | foreach ($parent_boards as $id => $msg) |
| 2637 | 2770 | { |
| 2638 | - if (!isset($parent_updates[$msg])) |
|
| 2639 | - $parent_updates[$msg] = array($id); |
|
| 2640 | - else |
|
| 2641 | - $parent_updates[$msg][] = $id; |
|
| 2771 | + if (!isset($parent_updates[$msg])) { |
|
| 2772 | + $parent_updates[$msg] = array($id); |
|
| 2773 | + } else { |
|
| 2774 | + $parent_updates[$msg][] = $id; |
|
| 2775 | + } |
|
| 2642 | 2776 | } |
| 2643 | 2777 | |
| 2644 | 2778 | foreach ($lastMsg as $id => $msg) |
| 2645 | 2779 | { |
| 2646 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
| 2647 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
| 2780 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
| 2781 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
| 2648 | 2782 | 'id' => $msg, |
| 2649 | 2783 | 'updated' => $lastModified[$id], |
| 2650 | 2784 | 'boards' => array($id) |
| 2651 | 2785 | ); |
| 2652 | - |
|
| 2653 | - else |
|
| 2654 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
| 2786 | + } else { |
|
| 2787 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
| 2788 | + } |
|
| 2655 | 2789 | } |
| 2656 | 2790 | |
| 2657 | 2791 | // Now commit the changes! |
@@ -2743,11 +2877,13 @@ discard block |
||
| 2743 | 2877 | global $txt, $mbname, $scripturl, $settings; |
| 2744 | 2878 | |
| 2745 | 2879 | // First things first, load up the email templates language file, if we need to. |
| 2746 | - if ($loadLang) |
|
| 2747 | - loadLanguage('EmailTemplates', $lang); |
|
| 2880 | + if ($loadLang) { |
|
| 2881 | + loadLanguage('EmailTemplates', $lang); |
|
| 2882 | + } |
|
| 2748 | 2883 | |
| 2749 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
| 2750 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
| 2884 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
| 2885 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
| 2886 | + } |
|
| 2751 | 2887 | |
| 2752 | 2888 | $ret = array( |
| 2753 | 2889 | 'subject' => $txt[$template . '_subject'], |
@@ -2797,17 +2933,18 @@ discard block |
||
| 2797 | 2933 | function user_info_callback($matches) |
| 2798 | 2934 | { |
| 2799 | 2935 | global $user_info; |
| 2800 | - if (empty($matches[1])) |
|
| 2801 | - return ''; |
|
| 2936 | + if (empty($matches[1])) { |
|
| 2937 | + return ''; |
|
| 2938 | + } |
|
| 2802 | 2939 | |
| 2803 | 2940 | $use_ref = true; |
| 2804 | 2941 | $ref = &$user_info; |
| 2805 | 2942 | |
| 2806 | 2943 | foreach (explode('.', $matches[1]) as $index) |
| 2807 | 2944 | { |
| 2808 | - if ($use_ref && isset($ref[$index])) |
|
| 2809 | - $ref = &$ref[$index]; |
|
| 2810 | - else |
|
| 2945 | + if ($use_ref && isset($ref[$index])) { |
|
| 2946 | + $ref = &$ref[$index]; |
|
| 2947 | + } else |
|
| 2811 | 2948 | { |
| 2812 | 2949 | $use_ref = false; |
| 2813 | 2950 | break; |
@@ -2844,8 +2981,7 @@ discard block |
||
| 2844 | 2981 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
| 2845 | 2982 | { |
| 2846 | 2983 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
| 2847 | - } |
|
| 2848 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
| 2984 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
| 2849 | 2985 | { |
| 2850 | 2986 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
| 2851 | 2987 | } |
@@ -2855,8 +2991,7 @@ discard block |
||
| 2855 | 2991 | { |
| 2856 | 2992 | $context['provider'] = 'enchant'; |
| 2857 | 2993 | return $enchant_link; |
| 2858 | - } |
|
| 2859 | - else |
|
| 2994 | + } else |
|
| 2860 | 2995 | { |
| 2861 | 2996 | // Free up any resources used... |
| 2862 | 2997 | @enchant_broker_free($context['enchant_broker']); |
@@ -2877,8 +3012,9 @@ discard block |
||
| 2877 | 3012 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
| 2878 | 3013 | |
| 2879 | 3014 | // Most people don't have anything but English installed... So we use English as a last resort. |
| 2880 | - if (!$pspell_link) |
|
| 2881 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
| 3015 | + if (!$pspell_link) { |
|
| 3016 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
| 3017 | + } |
|
| 2882 | 3018 | |
| 2883 | 3019 | error_reporting($old); |
| 2884 | 3020 | ob_end_clean(); |
@@ -2918,8 +3054,7 @@ discard block |
||
| 2918 | 3054 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
| 2919 | 3055 | } |
| 2920 | 3056 | return enchant_dict_check($dict, $word); |
| 2921 | - } |
|
| 2922 | - elseif ($context['provider'] == 'pspell') |
|
| 3057 | + } elseif ($context['provider'] == 'pspell') |
|
| 2923 | 3058 | { |
| 2924 | 3059 | return pspell_check($dict, $word); |
| 2925 | 3060 | } |
@@ -2955,13 +3090,11 @@ discard block |
||
| 2955 | 3090 | } |
| 2956 | 3091 | |
| 2957 | 3092 | return $suggestions; |
| 2958 | - } |
|
| 2959 | - else |
|
| 3093 | + } else |
|
| 2960 | 3094 | { |
| 2961 | 3095 | return enchant_dict_suggest($dict, $word); |
| 2962 | 3096 | } |
| 2963 | - } |
|
| 2964 | - elseif ($context['provider'] == 'pspell') |
|
| 3097 | + } elseif ($context['provider'] == 'pspell') |
|
| 2965 | 3098 | { |
| 2966 | 3099 | return pspell_suggest($dict, $word); |
| 2967 | 3100 | } |