@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /* The contents of this file handle the deletion of topics, posts, and related |
| 21 | 22 | paraphernalia. It has the following functions: |
@@ -37,8 +38,9 @@ discard block |
||
| 37 | 38 | require_once($sourcedir . '/Subs-Post.php'); |
| 38 | 39 | |
| 39 | 40 | // Trying to fool us around, are we? |
| 40 | - if (empty($topic)) |
|
| 41 | - redirectexit(); |
|
| 41 | + if (empty($topic)) { |
|
| 42 | + redirectexit(); |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | removeDeleteConcurrence(); |
| 44 | 46 | |
@@ -55,20 +57,23 @@ discard block |
||
| 55 | 57 | list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request); |
| 56 | 58 | $smcFunc['db_free_result']($request); |
| 57 | 59 | |
| 58 | - if ($starter == $user_info['id'] && !allowedTo('remove_any')) |
|
| 59 | - isAllowedTo('remove_own'); |
|
| 60 | - else |
|
| 61 | - isAllowedTo('remove_any'); |
|
| 60 | + if ($starter == $user_info['id'] && !allowedTo('remove_any')) { |
|
| 61 | + isAllowedTo('remove_own'); |
|
| 62 | + } else { |
|
| 63 | + isAllowedTo('remove_any'); |
|
| 64 | + } |
|
| 62 | 65 | |
| 63 | 66 | // Can they see the topic? |
| 64 | - if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) |
|
| 65 | - isAllowedTo('approve_posts'); |
|
| 67 | + if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) { |
|
| 68 | + isAllowedTo('approve_posts'); |
|
| 69 | + } |
|
| 66 | 70 | |
| 67 | 71 | // Ok, we got that far, but is it locked? |
| 68 | 72 | if ($locked) |
| 69 | 73 | { |
| 70 | - if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) |
|
| 71 | - fatal_lang_error('cannot_remove_locked', 'user'); |
|
| 74 | + if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) { |
|
| 75 | + fatal_lang_error('cannot_remove_locked', 'user'); |
|
| 76 | + } |
|
| 72 | 77 | } |
| 73 | 78 | |
| 74 | 79 | // Notify people that this topic has been removed. |
@@ -77,8 +82,9 @@ discard block |
||
| 77 | 82 | removeTopics($topic); |
| 78 | 83 | |
| 79 | 84 | // Note, only log topic ID in native form if it's not gone forever. |
| 80 | - if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) |
|
| 81 | - logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board)); |
|
| 85 | + if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) { |
|
| 86 | + logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board)); |
|
| 87 | + } |
|
| 82 | 88 | |
| 83 | 89 | redirectexit('board=' . $board . '.0'); |
| 84 | 90 | } |
@@ -96,8 +102,9 @@ discard block |
||
| 96 | 102 | $_REQUEST['msg'] = (int) $_REQUEST['msg']; |
| 97 | 103 | |
| 98 | 104 | // Is $topic set? |
| 99 | - if (empty($topic) && isset($_REQUEST['topic'])) |
|
| 100 | - $topic = (int) $_REQUEST['topic']; |
|
| 105 | + if (empty($topic) && isset($_REQUEST['topic'])) { |
|
| 106 | + $topic = (int) $_REQUEST['topic']; |
|
| 107 | + } |
|
| 101 | 108 | |
| 102 | 109 | removeDeleteConcurrence(); |
| 103 | 110 | |
@@ -116,44 +123,48 @@ discard block |
||
| 116 | 123 | $smcFunc['db_free_result']($request); |
| 117 | 124 | |
| 118 | 125 | // Verify they can see this! |
| 119 | - if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) |
|
| 120 | - isAllowedTo('approve_posts'); |
|
| 126 | + if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) { |
|
| 127 | + isAllowedTo('approve_posts'); |
|
| 128 | + } |
|
| 121 | 129 | |
| 122 | 130 | if ($poster == $user_info['id']) |
| 123 | 131 | { |
| 124 | 132 | if (!allowedTo('delete_own')) |
| 125 | 133 | { |
| 126 | - if ($starter == $user_info['id'] && !allowedTo('delete_any')) |
|
| 127 | - isAllowedTo('delete_replies'); |
|
| 128 | - elseif (!allowedTo('delete_any')) |
|
| 129 | - isAllowedTo('delete_own'); |
|
| 134 | + if ($starter == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 135 | + isAllowedTo('delete_replies'); |
|
| 136 | + } elseif (!allowedTo('delete_any')) { |
|
| 137 | + isAllowedTo('delete_own'); |
|
| 138 | + } |
|
| 139 | + } elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 140 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 130 | 141 | } |
| 131 | - elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 132 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 142 | + } elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 143 | + isAllowedTo('delete_replies'); |
|
| 144 | + } else { |
|
| 145 | + isAllowedTo('delete_any'); |
|
| 133 | 146 | } |
| 134 | - elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) |
|
| 135 | - isAllowedTo('delete_replies'); |
|
| 136 | - else |
|
| 137 | - isAllowedTo('delete_any'); |
|
| 138 | 147 | |
| 139 | 148 | // If the full topic was removed go back to the board. |
| 140 | 149 | $full_topic = removeMessage($_REQUEST['msg']); |
| 141 | 150 | |
| 142 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) |
|
| 143 | - logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board)); |
|
| 151 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) { |
|
| 152 | + logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board)); |
|
| 153 | + } |
|
| 144 | 154 | |
| 145 | 155 | // We want to redirect back to recent action. |
| 146 | - if (isset($_REQUEST['modcenter'])) |
|
| 147 | - redirectexit('action=moderate;area=reportedposts;done'); |
|
| 148 | - elseif (isset($_REQUEST['recent'])) |
|
| 149 | - redirectexit('action=recent'); |
|
| 150 | - elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) |
|
| 151 | - redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']); |
|
| 152 | - elseif ($full_topic) |
|
| 153 | - redirectexit('board=' . $board . '.0'); |
|
| 154 | - else |
|
| 155 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 156 | -} |
|
| 156 | + if (isset($_REQUEST['modcenter'])) { |
|
| 157 | + redirectexit('action=moderate;area=reportedposts;done'); |
|
| 158 | + } elseif (isset($_REQUEST['recent'])) { |
|
| 159 | + redirectexit('action=recent'); |
|
| 160 | + } elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) { |
|
| 161 | + redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']); |
|
| 162 | + } elseif ($full_topic) { |
|
| 163 | + redirectexit('board=' . $board . '.0'); |
|
| 164 | + } else { |
|
| 165 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 166 | + } |
|
| 167 | + } |
|
| 157 | 168 | |
| 158 | 169 | /** |
| 159 | 170 | * So long as you are sure... all old posts will be gone. |
@@ -167,8 +178,9 @@ discard block |
||
| 167 | 178 | checkSession('post', 'admin'); |
| 168 | 179 | |
| 169 | 180 | // No boards at all? Forget it then :/. |
| 170 | - if (empty($_POST['boards'])) |
|
| 171 | - redirectexit('action=admin;area=maintain;sa=topics'); |
|
| 181 | + if (empty($_POST['boards'])) { |
|
| 182 | + redirectexit('action=admin;area=maintain;sa=topics'); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | // This should exist, but we can make sure. |
| 174 | 186 | $_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing'; |
@@ -222,8 +234,9 @@ discard block |
||
| 222 | 234 | $condition_params |
| 223 | 235 | ); |
| 224 | 236 | $topics = array(); |
| 225 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 226 | - $topics[] = $row['id_topic']; |
|
| 237 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 238 | + $topics[] = $row['id_topic']; |
|
| 239 | + } |
|
| 227 | 240 | $smcFunc['db_free_result']($request); |
| 228 | 241 | |
| 229 | 242 | removeTopics($topics, false, true); |
@@ -247,11 +260,13 @@ discard block |
||
| 247 | 260 | global $sourcedir, $modSettings, $smcFunc; |
| 248 | 261 | |
| 249 | 262 | // Nothing to do? |
| 250 | - if (empty($topics)) |
|
| 251 | - return; |
|
| 263 | + if (empty($topics)) { |
|
| 264 | + return; |
|
| 265 | + } |
|
| 252 | 266 | // Only a single topic. |
| 253 | - if (is_numeric($topics)) |
|
| 254 | - $topics = array($topics); |
|
| 267 | + if (is_numeric($topics)) { |
|
| 268 | + $topics = array($topics); |
|
| 269 | + } |
|
| 255 | 270 | |
| 256 | 271 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
| 257 | 272 | |
@@ -276,8 +291,9 @@ discard block |
||
| 276 | 291 | ); |
| 277 | 292 | if ($smcFunc['db_num_rows']($requestMembers) > 0) |
| 278 | 293 | { |
| 279 | - while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) |
|
| 280 | - updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts'])); |
|
| 294 | + while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) { |
|
| 295 | + updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts'])); |
|
| 296 | + } |
|
| 281 | 297 | } |
| 282 | 298 | $smcFunc['db_free_result']($requestMembers); |
| 283 | 299 | } |
@@ -303,8 +319,9 @@ discard block |
||
| 303 | 319 | $recycleTopics = array(); |
| 304 | 320 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 305 | 321 | { |
| 306 | - if (function_exists('apache_reset_timeout')) |
|
| 307 | - @apache_reset_timeout(); |
|
| 322 | + if (function_exists('apache_reset_timeout')) { |
|
| 323 | + @apache_reset_timeout(); |
|
| 324 | + } |
|
| 308 | 325 | |
| 309 | 326 | $recycleTopics[] = $row['id_topic']; |
| 310 | 327 | |
@@ -346,20 +363,22 @@ discard block |
||
| 346 | 363 | |
| 347 | 364 | // Topics that were recycled don't need to be deleted, so subtract them. |
| 348 | 365 | $topics = array_diff($topics, $recycleTopics); |
| 366 | + } else { |
|
| 367 | + $smcFunc['db_free_result']($request); |
|
| 349 | 368 | } |
| 350 | - else |
|
| 351 | - $smcFunc['db_free_result']($request); |
|
| 352 | 369 | } |
| 353 | 370 | |
| 354 | 371 | // Still topics left to delete? |
| 355 | - if (empty($topics)) |
|
| 356 | - return; |
|
| 372 | + if (empty($topics)) { |
|
| 373 | + return; |
|
| 374 | + } |
|
| 357 | 375 | |
| 358 | 376 | // Callback for search APIs to do their thing |
| 359 | 377 | require_once($sourcedir . '/Search.php'); |
| 360 | 378 | $searchAPI = findSearchAPI(); |
| 361 | - if ($searchAPI->supportsMethod('topicsRemoved')) |
|
| 362 | - $searchAPI->topicsRemoved($topics); |
|
| 379 | + if ($searchAPI->supportsMethod('topicsRemoved')) { |
|
| 380 | + $searchAPI->topicsRemoved($topics); |
|
| 381 | + } |
|
| 363 | 382 | |
| 364 | 383 | $adjustBoards = array(); |
| 365 | 384 | |
@@ -391,10 +410,11 @@ discard block |
||
| 391 | 410 | $adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
| 392 | 411 | |
| 393 | 412 | // Add the topics to the right type. |
| 394 | - if ($row['approved']) |
|
| 395 | - $adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
| 396 | - else |
|
| 397 | - $adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
| 413 | + if ($row['approved']) { |
|
| 414 | + $adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
| 415 | + } else { |
|
| 416 | + $adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
| 417 | + } |
|
| 398 | 418 | } |
| 399 | 419 | $smcFunc['db_free_result']($request); |
| 400 | 420 | |
@@ -403,8 +423,9 @@ discard block |
||
| 403 | 423 | // Decrease the posts/topics... |
| 404 | 424 | foreach ($adjustBoards as $stats) |
| 405 | 425 | { |
| 406 | - if (function_exists('apache_reset_timeout')) |
|
| 407 | - @apache_reset_timeout(); |
|
| 426 | + if (function_exists('apache_reset_timeout')) { |
|
| 427 | + @apache_reset_timeout(); |
|
| 428 | + } |
|
| 408 | 429 | |
| 409 | 430 | $smcFunc['db_query']('', ' |
| 410 | 431 | UPDATE {db_prefix}boards |
@@ -438,8 +459,9 @@ discard block |
||
| 438 | 459 | ) |
| 439 | 460 | ); |
| 440 | 461 | $polls = array(); |
| 441 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 442 | - $polls[] = $row['id_poll']; |
|
| 462 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 463 | + $polls[] = $row['id_poll']; |
|
| 464 | + } |
|
| 443 | 465 | $smcFunc['db_free_result']($request); |
| 444 | 466 | |
| 445 | 467 | if (!empty($polls)) |
@@ -492,8 +514,9 @@ discard block |
||
| 492 | 514 | ); |
| 493 | 515 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 494 | 516 | { |
| 495 | - if (function_exists('apache_reset_timeout')) |
|
| 496 | - @apache_reset_timeout(); |
|
| 517 | + if (function_exists('apache_reset_timeout')) { |
|
| 518 | + @apache_reset_timeout(); |
|
| 519 | + } |
|
| 497 | 520 | |
| 498 | 521 | $words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true)); |
| 499 | 522 | $messages[] = $row['id_msg']; |
@@ -501,8 +524,8 @@ discard block |
||
| 501 | 524 | $smcFunc['db_free_result']($request); |
| 502 | 525 | $words = array_unique($words); |
| 503 | 526 | |
| 504 | - if (!empty($words) && !empty($messages)) |
|
| 505 | - $smcFunc['db_query']('', ' |
|
| 527 | + if (!empty($words) && !empty($messages)) { |
|
| 528 | + $smcFunc['db_query']('', ' |
|
| 506 | 529 | DELETE FROM {db_prefix}log_search_words |
| 507 | 530 | WHERE id_word IN ({array_int:word_list}) |
| 508 | 531 | AND id_msg IN ({array_int:message_list})', |
@@ -511,6 +534,7 @@ discard block |
||
| 511 | 534 | 'message_list' => $messages, |
| 512 | 535 | ) |
| 513 | 536 | ); |
| 537 | + } |
|
| 514 | 538 | } |
| 515 | 539 | |
| 516 | 540 | // Delete anything related to the topic. |
@@ -569,8 +593,9 @@ discard block |
||
| 569 | 593 | |
| 570 | 594 | require_once($sourcedir . '/Subs-Post.php'); |
| 571 | 595 | $updates = array(); |
| 572 | - foreach ($adjustBoards as $stats) |
|
| 573 | - $updates[] = $stats['id_board']; |
|
| 596 | + foreach ($adjustBoards as $stats) { |
|
| 597 | + $updates[] = $stats['id_board']; |
|
| 598 | + } |
|
| 574 | 599 | updateLastMessages($updates); |
| 575 | 600 | } |
| 576 | 601 | |
@@ -587,8 +612,9 @@ discard block |
||
| 587 | 612 | { |
| 588 | 613 | global $board, $sourcedir, $modSettings, $user_info, $smcFunc; |
| 589 | 614 | |
| 590 | - if (empty($message) || !is_numeric($message)) |
|
| 591 | - return false; |
|
| 615 | + if (empty($message) || !is_numeric($message)) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 592 | 618 | |
| 593 | 619 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
| 594 | 620 | |
@@ -607,8 +633,9 @@ discard block |
||
| 607 | 633 | 'id_msg' => $message, |
| 608 | 634 | ) |
| 609 | 635 | ); |
| 610 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 611 | - return false; |
|
| 636 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 637 | + return false; |
|
| 638 | + } |
|
| 612 | 639 | $row = $smcFunc['db_fetch_assoc']($request); |
| 613 | 640 | $smcFunc['db_free_result']($request); |
| 614 | 641 | |
@@ -629,54 +656,57 @@ discard block |
||
| 629 | 656 | { |
| 630 | 657 | if ($row['id_member_poster'] == $user_info['id']) |
| 631 | 658 | { |
| 632 | - if (!$delete_replies) |
|
| 633 | - fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 659 | + if (!$delete_replies) { |
|
| 660 | + fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 661 | + } |
|
| 662 | + } else { |
|
| 663 | + fatal_lang_error('cannot_delete_own', 'permission'); |
|
| 634 | 664 | } |
| 635 | - else |
|
| 636 | - fatal_lang_error('cannot_delete_own', 'permission'); |
|
| 665 | + } elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 666 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 637 | 667 | } |
| 638 | - elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 639 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 640 | - } |
|
| 641 | - elseif ($row['id_member_poster'] == $user_info['id']) |
|
| 668 | + } elseif ($row['id_member_poster'] == $user_info['id']) |
|
| 642 | 669 | { |
| 643 | - if (!$delete_replies) |
|
| 644 | - fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 670 | + if (!$delete_replies) { |
|
| 671 | + fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 672 | + } |
|
| 673 | + } else { |
|
| 674 | + fatal_lang_error('cannot_delete_any', 'permission'); |
|
| 645 | 675 | } |
| 646 | - else |
|
| 647 | - fatal_lang_error('cannot_delete_any', 'permission'); |
|
| 648 | 676 | } |
| 649 | 677 | |
| 650 | 678 | // Can't delete an unapproved message, if you can't see it! |
| 651 | 679 | if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any))) |
| 652 | 680 | { |
| 653 | 681 | $approve_posts = boardsAllowedTo('approve_posts'); |
| 654 | - if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) |
|
| 655 | - return false; |
|
| 682 | + if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) { |
|
| 683 | + return false; |
|
| 684 | + } |
|
| 656 | 685 | } |
| 657 | - } |
|
| 658 | - else |
|
| 686 | + } else |
|
| 659 | 687 | { |
| 660 | 688 | // Check permissions to delete this message. |
| 661 | 689 | if ($row['id_member'] == $user_info['id']) |
| 662 | 690 | { |
| 663 | 691 | if (!allowedTo('delete_own')) |
| 664 | 692 | { |
| 665 | - if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) |
|
| 666 | - isAllowedTo('delete_replies'); |
|
| 667 | - elseif (!allowedTo('delete_any')) |
|
| 668 | - isAllowedTo('delete_own'); |
|
| 693 | + if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 694 | + isAllowedTo('delete_replies'); |
|
| 695 | + } elseif (!allowedTo('delete_any')) { |
|
| 696 | + isAllowedTo('delete_own'); |
|
| 697 | + } |
|
| 698 | + } elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 699 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 669 | 700 | } |
| 670 | - elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 671 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 701 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 702 | + isAllowedTo('delete_replies'); |
|
| 703 | + } else { |
|
| 704 | + isAllowedTo('delete_any'); |
|
| 672 | 705 | } |
| 673 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) |
|
| 674 | - isAllowedTo('delete_replies'); |
|
| 675 | - else |
|
| 676 | - isAllowedTo('delete_any'); |
|
| 677 | 706 | |
| 678 | - if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) |
|
| 679 | - isAllowedTo('approve_posts'); |
|
| 707 | + if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) { |
|
| 708 | + isAllowedTo('approve_posts'); |
|
| 709 | + } |
|
| 680 | 710 | } |
| 681 | 711 | |
| 682 | 712 | // Delete the *whole* topic, but only if the topic consists of one message. |
@@ -692,31 +722,34 @@ discard block |
||
| 692 | 722 | $remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own); |
| 693 | 723 | } |
| 694 | 724 | |
| 695 | - if ($row['id_member'] != $user_info['id'] && !$remove_any) |
|
| 696 | - fatal_lang_error('cannot_remove_any', 'permission'); |
|
| 697 | - elseif (!$remove_any && !$remove_own) |
|
| 698 | - fatal_lang_error('cannot_remove_own', 'permission'); |
|
| 699 | - } |
|
| 700 | - else |
|
| 725 | + if ($row['id_member'] != $user_info['id'] && !$remove_any) { |
|
| 726 | + fatal_lang_error('cannot_remove_any', 'permission'); |
|
| 727 | + } elseif (!$remove_any && !$remove_own) { |
|
| 728 | + fatal_lang_error('cannot_remove_own', 'permission'); |
|
| 729 | + } |
|
| 730 | + } else |
|
| 701 | 731 | { |
| 702 | 732 | // Check permissions to delete a whole topic. |
| 703 | - if ($row['id_member'] != $user_info['id']) |
|
| 704 | - isAllowedTo('remove_any'); |
|
| 705 | - elseif (!allowedTo('remove_any')) |
|
| 706 | - isAllowedTo('remove_own'); |
|
| 733 | + if ($row['id_member'] != $user_info['id']) { |
|
| 734 | + isAllowedTo('remove_any'); |
|
| 735 | + } elseif (!allowedTo('remove_any')) { |
|
| 736 | + isAllowedTo('remove_own'); |
|
| 737 | + } |
|
| 707 | 738 | } |
| 708 | 739 | |
| 709 | 740 | // ...if there is only one post. |
| 710 | - if (!empty($row['num_replies'])) |
|
| 711 | - fatal_lang_error('delFirstPost', false); |
|
| 741 | + if (!empty($row['num_replies'])) { |
|
| 742 | + fatal_lang_error('delFirstPost', false); |
|
| 743 | + } |
|
| 712 | 744 | |
| 713 | 745 | removeTopics($row['id_topic']); |
| 714 | 746 | return true; |
| 715 | 747 | } |
| 716 | 748 | |
| 717 | 749 | // Deleting a recycled message can not lower anyone's post count. |
| 718 | - if (!empty($recycle_board) && $row['id_board'] == $recycle_board) |
|
| 719 | - $decreasePostCount = false; |
|
| 750 | + if (!empty($recycle_board) && $row['id_board'] == $recycle_board) { |
|
| 751 | + $decreasePostCount = false; |
|
| 752 | + } |
|
| 720 | 753 | |
| 721 | 754 | // This is the last post, update the last post on the board. |
| 722 | 755 | if ($row['id_last_msg'] == $message) |
@@ -755,8 +788,8 @@ discard block |
||
| 755 | 788 | ); |
| 756 | 789 | } |
| 757 | 790 | // Only decrease post counts. |
| 758 | - else |
|
| 759 | - $smcFunc['db_query']('', ' |
|
| 791 | + else { |
|
| 792 | + $smcFunc['db_query']('', ' |
|
| 760 | 793 | UPDATE {db_prefix}topics |
| 761 | 794 | SET ' . ($row['approved'] ? ' |
| 762 | 795 | num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : ' |
@@ -768,6 +801,7 @@ discard block |
||
| 768 | 801 | 'id_topic' => $row['id_topic'], |
| 769 | 802 | ) |
| 770 | 803 | ); |
| 804 | + } |
|
| 771 | 805 | |
| 772 | 806 | // Default recycle to false. |
| 773 | 807 | $recycle = false; |
@@ -787,8 +821,9 @@ discard block |
||
| 787 | 821 | 'recycle_board' => $modSettings['recycle_board'], |
| 788 | 822 | ) |
| 789 | 823 | ); |
| 790 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 791 | - fatal_lang_error('recycle_no_valid_board'); |
|
| 824 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 825 | + fatal_lang_error('recycle_no_valid_board'); |
|
| 826 | + } |
|
| 792 | 827 | list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request); |
| 793 | 828 | $smcFunc['db_free_result']($request); |
| 794 | 829 | |
@@ -807,8 +842,8 @@ discard block |
||
| 807 | 842 | $smcFunc['db_free_result']($request); |
| 808 | 843 | |
| 809 | 844 | // Insert a new topic in the recycle board if $id_recycle_topic is empty. |
| 810 | - if (empty($id_recycle_topic)) |
|
| 811 | - $id_topic = $smcFunc['db_insert']('', |
|
| 845 | + if (empty($id_recycle_topic)) { |
|
| 846 | + $id_topic = $smcFunc['db_insert']('', |
|
| 812 | 847 | '{db_prefix}topics', |
| 813 | 848 | array( |
| 814 | 849 | 'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int', |
@@ -821,6 +856,7 @@ discard block |
||
| 821 | 856 | array('id_topic'), |
| 822 | 857 | 1 |
| 823 | 858 | ); |
| 859 | + } |
|
| 824 | 860 | |
| 825 | 861 | // Capture the ID of the new topic... |
| 826 | 862 | $topicID = empty($id_recycle_topic) ? $id_topic : $id_recycle_topic; |
@@ -858,22 +894,24 @@ discard block |
||
| 858 | 894 | ); |
| 859 | 895 | |
| 860 | 896 | // Mark recycled topic as read. |
| 861 | - if (!$user_info['is_guest']) |
|
| 862 | - $smcFunc['db_insert']('replace', |
|
| 897 | + if (!$user_info['is_guest']) { |
|
| 898 | + $smcFunc['db_insert']('replace', |
|
| 863 | 899 | '{db_prefix}log_topics', |
| 864 | 900 | array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'), |
| 865 | 901 | array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0), |
| 866 | 902 | array('id_topic', 'id_member') |
| 867 | 903 | ); |
| 904 | + } |
|
| 868 | 905 | |
| 869 | 906 | // Mark recycle board as seen, if it was marked as seen before. |
| 870 | - if (!empty($isRead) && !$user_info['is_guest']) |
|
| 871 | - $smcFunc['db_insert']('replace', |
|
| 907 | + if (!empty($isRead) && !$user_info['is_guest']) { |
|
| 908 | + $smcFunc['db_insert']('replace', |
|
| 872 | 909 | '{db_prefix}log_boards', |
| 873 | 910 | array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), |
| 874 | 911 | array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']), |
| 875 | 912 | array('id_board', 'id_member') |
| 876 | 913 | ); |
| 914 | + } |
|
| 877 | 915 | |
| 878 | 916 | // Add one topic and post to the recycle bin board. |
| 879 | 917 | $smcFunc['db_query']('', ' |
@@ -891,8 +929,8 @@ discard block |
||
| 891 | 929 | ); |
| 892 | 930 | |
| 893 | 931 | // Lets increase the num_replies, and the first/last message ID as appropriate. |
| 894 | - if (!empty($id_recycle_topic)) |
|
| 895 | - $smcFunc['db_query']('', ' |
|
| 932 | + if (!empty($id_recycle_topic)) { |
|
| 933 | + $smcFunc['db_query']('', ' |
|
| 896 | 934 | UPDATE {db_prefix}topics |
| 897 | 935 | SET num_replies = num_replies + 1' . |
| 898 | 936 | ($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') . |
@@ -903,6 +941,7 @@ discard block |
||
| 903 | 941 | 'id_merged_msg' => $message, |
| 904 | 942 | ) |
| 905 | 943 | ); |
| 944 | + } |
|
| 906 | 945 | |
| 907 | 946 | // Make sure this message isn't getting deleted later on. |
| 908 | 947 | $recycle = true; |
@@ -912,8 +951,8 @@ discard block |
||
| 912 | 951 | } |
| 913 | 952 | |
| 914 | 953 | // If it wasn't approved don't keep it in the queue. |
| 915 | - if (!$row['approved']) |
|
| 916 | - $smcFunc['db_query']('', ' |
|
| 954 | + if (!$row['approved']) { |
|
| 955 | + $smcFunc['db_query']('', ' |
|
| 917 | 956 | DELETE FROM {db_prefix}approval_queue |
| 918 | 957 | WHERE id_msg = {int:id_msg} |
| 919 | 958 | AND id_attach = {int:id_attach}', |
@@ -922,6 +961,7 @@ discard block |
||
| 922 | 961 | 'id_attach' => 0, |
| 923 | 962 | ) |
| 924 | 963 | ); |
| 964 | + } |
|
| 925 | 965 | } |
| 926 | 966 | |
| 927 | 967 | $smcFunc['db_query']('', ' |
@@ -939,8 +979,9 @@ discard block |
||
| 939 | 979 | |
| 940 | 980 | // If the poster was registered and the board this message was on incremented |
| 941 | 981 | // the member's posts when it was posted, decrease his or her post count. |
| 942 | - if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) |
|
| 943 | - updateMemberData($row['id_member'], array('posts' => '-')); |
|
| 982 | + if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) { |
|
| 983 | + updateMemberData($row['id_member'], array('posts' => '-')); |
|
| 984 | + } |
|
| 944 | 985 | |
| 945 | 986 | // Only remove posts if they're not recycled. |
| 946 | 987 | if (!$recycle) |
@@ -948,8 +989,9 @@ discard block |
||
| 948 | 989 | // Callback for search APIs to do their thing |
| 949 | 990 | require_once($sourcedir . '/Search.php'); |
| 950 | 991 | $searchAPI = findSearchAPI(); |
| 951 | - if ($searchAPI->supportsMethod('postRemoved')) |
|
| 952 | - $searchAPI->postRemoved($message); |
|
| 992 | + if ($searchAPI->supportsMethod('postRemoved')) { |
|
| 993 | + $searchAPI->postRemoved($message); |
|
| 994 | + } |
|
| 953 | 995 | |
| 954 | 996 | // Remove the message! |
| 955 | 997 | $smcFunc['db_query']('', ' |
@@ -964,8 +1006,8 @@ discard block |
||
| 964 | 1006 | { |
| 965 | 1007 | $customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true); |
| 966 | 1008 | $words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true); |
| 967 | - if (!empty($words)) |
|
| 968 | - $smcFunc['db_query']('', ' |
|
| 1009 | + if (!empty($words)) { |
|
| 1010 | + $smcFunc['db_query']('', ' |
|
| 969 | 1011 | DELETE FROM {db_prefix}log_search_words |
| 970 | 1012 | WHERE id_word IN ({array_int:word_list}) |
| 971 | 1013 | AND id_msg = {int:id_msg}', |
@@ -974,6 +1016,7 @@ discard block |
||
| 974 | 1016 | 'id_msg' => $message, |
| 975 | 1017 | ) |
| 976 | 1018 | ); |
| 1019 | + } |
|
| 977 | 1020 | } |
| 978 | 1021 | |
| 979 | 1022 | // Delete attachment(s) if they exist. |
@@ -997,10 +1040,11 @@ discard block |
||
| 997 | 1040 | |
| 998 | 1041 | // And now to update the last message of each board we messed with. |
| 999 | 1042 | require_once($sourcedir . '/Subs-Post.php'); |
| 1000 | - if ($recycle) |
|
| 1001 | - updateLastMessages(array($row['id_board'], $modSettings['recycle_board'])); |
|
| 1002 | - else |
|
| 1003 | - updateLastMessages($row['id_board']); |
|
| 1043 | + if ($recycle) { |
|
| 1044 | + updateLastMessages(array($row['id_board'], $modSettings['recycle_board'])); |
|
| 1045 | + } else { |
|
| 1046 | + updateLastMessages($row['id_board']); |
|
| 1047 | + } |
|
| 1004 | 1048 | |
| 1005 | 1049 | // Close any moderation reports for this message. |
| 1006 | 1050 | $smcFunc['db_query']('', ' |
@@ -1033,8 +1077,9 @@ discard block |
||
| 1033 | 1077 | checkSession('get'); |
| 1034 | 1078 | |
| 1035 | 1079 | // Is recycled board enabled? |
| 1036 | - if (empty($modSettings['recycle_enable'])) |
|
| 1037 | - fatal_lang_error('restored_disabled', 'critical'); |
|
| 1080 | + if (empty($modSettings['recycle_enable'])) { |
|
| 1081 | + fatal_lang_error('restored_disabled', 'critical'); |
|
| 1082 | + } |
|
| 1038 | 1083 | |
| 1039 | 1084 | // Can we be in here? |
| 1040 | 1085 | isAllowedTo('move_any', $modSettings['recycle_board']); |
@@ -1049,8 +1094,9 @@ discard block |
||
| 1049 | 1094 | if (!empty($_REQUEST['msgs'])) |
| 1050 | 1095 | { |
| 1051 | 1096 | $msgs = explode(',', $_REQUEST['msgs']); |
| 1052 | - foreach ($msgs as $k => $msg) |
|
| 1053 | - $msgs[$k] = (int) $msg; |
|
| 1097 | + foreach ($msgs as $k => $msg) { |
|
| 1098 | + $msgs[$k] = (int) $msg; |
|
| 1099 | + } |
|
| 1054 | 1100 | |
| 1055 | 1101 | // Get the id_previous_board and id_previous_topic. |
| 1056 | 1102 | $request = $smcFunc['db_query']('', ' |
@@ -1084,8 +1130,8 @@ discard block |
||
| 1084 | 1130 | } |
| 1085 | 1131 | |
| 1086 | 1132 | $previous_topics[] = $row['id_previous_topic']; |
| 1087 | - if (empty($actioned_messages[$row['id_previous_topic']])) |
|
| 1088 | - $actioned_messages[$row['id_previous_topic']] = array( |
|
| 1133 | + if (empty($actioned_messages[$row['id_previous_topic']])) { |
|
| 1134 | + $actioned_messages[$row['id_previous_topic']] = array( |
|
| 1089 | 1135 | 'msgs' => array(), |
| 1090 | 1136 | 'count_posts' => $row['count_posts'], |
| 1091 | 1137 | 'subject' => $row['subject'], |
@@ -1095,17 +1141,20 @@ discard block |
||
| 1095 | 1141 | 'current_board' => $row['id_board'], |
| 1096 | 1142 | 'members' => array(), |
| 1097 | 1143 | ); |
| 1144 | + } |
|
| 1098 | 1145 | |
| 1099 | 1146 | $actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject']; |
| 1100 | - if ($row['id_member']) |
|
| 1101 | - $actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member']; |
|
| 1147 | + if ($row['id_member']) { |
|
| 1148 | + $actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member']; |
|
| 1149 | + } |
|
| 1102 | 1150 | } |
| 1103 | 1151 | $smcFunc['db_free_result']($request); |
| 1104 | 1152 | |
| 1105 | 1153 | // Check for topics we are going to fully restore. |
| 1106 | - foreach ($actioned_messages as $topic => $data) |
|
| 1107 | - if (in_array($topic, $topics_to_restore)) |
|
| 1154 | + foreach ($actioned_messages as $topic => $data) { |
|
| 1155 | + if (in_array($topic, $topics_to_restore)) |
|
| 1108 | 1156 | unset($actioned_messages[$topic]); |
| 1157 | + } |
|
| 1109 | 1158 | |
| 1110 | 1159 | // Load any previous topics to check they exist. |
| 1111 | 1160 | if (!empty($previous_topics)) |
@@ -1120,11 +1169,12 @@ discard block |
||
| 1120 | 1169 | ) |
| 1121 | 1170 | ); |
| 1122 | 1171 | $previous_topics = array(); |
| 1123 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1124 | - $previous_topics[$row['id_topic']] = array( |
|
| 1172 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1173 | + $previous_topics[$row['id_topic']] = array( |
|
| 1125 | 1174 | 'board' => $row['id_board'], |
| 1126 | 1175 | 'subject' => $row['subject'], |
| 1127 | 1176 | ); |
| 1177 | + } |
|
| 1128 | 1178 | $smcFunc['db_free_result']($request); |
| 1129 | 1179 | } |
| 1130 | 1180 | |
@@ -1146,11 +1196,11 @@ discard block |
||
| 1146 | 1196 | // Log em. |
| 1147 | 1197 | logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board'])); |
| 1148 | 1198 | $messages = array_merge(array_keys($data['msgs']), $messages); |
| 1149 | - } |
|
| 1150 | - else |
|
| 1199 | + } else |
|
| 1151 | 1200 | { |
| 1152 | - foreach ($data['msgs'] as $msg) |
|
| 1153 | - $unfound_messages[$msg['id']] = $msg['subject']; |
|
| 1201 | + foreach ($data['msgs'] as $msg) { |
|
| 1202 | + $unfound_messages[$msg['id']] = $msg['subject']; |
|
| 1203 | + } |
|
| 1154 | 1204 | } |
| 1155 | 1205 | } |
| 1156 | 1206 | } |
@@ -1159,8 +1209,9 @@ discard block |
||
| 1159 | 1209 | if (!empty($_REQUEST['topics'])) |
| 1160 | 1210 | { |
| 1161 | 1211 | $topics = explode(',', $_REQUEST['topics']); |
| 1162 | - foreach ($topics as $id) |
|
| 1163 | - $topics_to_restore[] = (int) $id; |
|
| 1212 | + foreach ($topics as $id) { |
|
| 1213 | + $topics_to_restore[] = (int) $id; |
|
| 1214 | + } |
|
| 1164 | 1215 | } |
| 1165 | 1216 | |
| 1166 | 1217 | if (!empty($topics_to_restore)) |
@@ -1214,8 +1265,9 @@ discard block |
||
| 1214 | 1265 | ) |
| 1215 | 1266 | ); |
| 1216 | 1267 | |
| 1217 | - while ($member = $smcFunc['db_fetch_assoc']($request2)) |
|
| 1218 | - updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count'])); |
|
| 1268 | + while ($member = $smcFunc['db_fetch_assoc']($request2)) { |
|
| 1269 | + updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count'])); |
|
| 1270 | + } |
|
| 1219 | 1271 | $smcFunc['db_free_result']($request2); |
| 1220 | 1272 | } |
| 1221 | 1273 | |
@@ -1226,8 +1278,9 @@ discard block |
||
| 1226 | 1278 | } |
| 1227 | 1279 | |
| 1228 | 1280 | // Didn't find some things? |
| 1229 | - if (!empty($unfound_messages)) |
|
| 1230 | - fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages))); |
|
| 1281 | + if (!empty($unfound_messages)) { |
|
| 1282 | + fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages))); |
|
| 1283 | + } |
|
| 1231 | 1284 | |
| 1232 | 1285 | // Just send them to the index if they get here. |
| 1233 | 1286 | redirectexit(); |
@@ -1247,12 +1300,14 @@ discard block |
||
| 1247 | 1300 | //!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient. |
| 1248 | 1301 | |
| 1249 | 1302 | // Is it an array? |
| 1250 | - if (!is_array($msgs)) |
|
| 1251 | - $msgs = array($msgs); |
|
| 1303 | + if (!is_array($msgs)) { |
|
| 1304 | + $msgs = array($msgs); |
|
| 1305 | + } |
|
| 1252 | 1306 | |
| 1253 | 1307 | // Lets make sure they are int. |
| 1254 | - foreach ($msgs as $key => $msg) |
|
| 1255 | - $msgs[$key] = (int) $msg; |
|
| 1308 | + foreach ($msgs as $key => $msg) { |
|
| 1309 | + $msgs[$key] = (int) $msg; |
|
| 1310 | + } |
|
| 1256 | 1311 | |
| 1257 | 1312 | // Get the source information. |
| 1258 | 1313 | $request = $smcFunc['db_query']('', ' |
@@ -1295,8 +1350,9 @@ discard block |
||
| 1295 | 1350 | ) |
| 1296 | 1351 | ); |
| 1297 | 1352 | |
| 1298 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1299 | - updateMemberData($row['id_member'], array('posts' => '+')); |
|
| 1353 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1354 | + updateMemberData($row['id_member'], array('posts' => '+')); |
|
| 1355 | + } |
|
| 1300 | 1356 | } |
| 1301 | 1357 | |
| 1302 | 1358 | // Time to move the messages. |
@@ -1332,13 +1388,15 @@ discard block |
||
| 1332 | 1388 | ); |
| 1333 | 1389 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1334 | 1390 | { |
| 1335 | - if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) |
|
| 1336 | - $target_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1391 | + if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) { |
|
| 1392 | + $target_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1393 | + } |
|
| 1337 | 1394 | $target_topic_data['id_last_msg'] = $row['id_last_msg']; |
| 1338 | - if (!$row['approved']) |
|
| 1339 | - $target_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1340 | - else |
|
| 1341 | - $target_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1395 | + if (!$row['approved']) { |
|
| 1396 | + $target_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1397 | + } else { |
|
| 1398 | + $target_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1399 | + } |
|
| 1342 | 1400 | } |
| 1343 | 1401 | $smcFunc['db_free_result']($request); |
| 1344 | 1402 | |
@@ -1397,13 +1455,15 @@ discard block |
||
| 1397 | 1455 | ); |
| 1398 | 1456 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1399 | 1457 | { |
| 1400 | - if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) |
|
| 1401 | - $source_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1458 | + if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) { |
|
| 1459 | + $source_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1460 | + } |
|
| 1402 | 1461 | $source_topic_data['id_last_msg'] = $row['id_last_msg']; |
| 1403 | - if (!$row['approved']) |
|
| 1404 | - $source_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1405 | - else |
|
| 1406 | - $source_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1462 | + if (!$row['approved']) { |
|
| 1463 | + $source_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1464 | + } else { |
|
| 1465 | + $source_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1466 | + } |
|
| 1407 | 1467 | } |
| 1408 | 1468 | $smcFunc['db_free_result']($request); |
| 1409 | 1469 | |
@@ -1467,10 +1527,12 @@ discard block |
||
| 1467 | 1527 | |
| 1468 | 1528 | // Subject cache? |
| 1469 | 1529 | $cache_updates = array(); |
| 1470 | - if ($target_first_msg != $target_topic_data['id_first_msg']) |
|
| 1471 | - $cache_updates[] = $target_topic_data['id_first_msg']; |
|
| 1472 | - if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) |
|
| 1473 | - $cache_updates[] = $source_topic_data['id_first_msg']; |
|
| 1530 | + if ($target_first_msg != $target_topic_data['id_first_msg']) { |
|
| 1531 | + $cache_updates[] = $target_topic_data['id_first_msg']; |
|
| 1532 | + } |
|
| 1533 | + if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) { |
|
| 1534 | + $cache_updates[] = $source_topic_data['id_first_msg']; |
|
| 1535 | + } |
|
| 1474 | 1536 | |
| 1475 | 1537 | if (!empty($cache_updates)) |
| 1476 | 1538 | { |
@@ -1482,8 +1544,9 @@ discard block |
||
| 1482 | 1544 | 'first_messages' => $cache_updates, |
| 1483 | 1545 | ) |
| 1484 | 1546 | ); |
| 1485 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1486 | - updateStats('subject', $row['id_topic'], $row['subject']); |
|
| 1547 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1548 | + updateStats('subject', $row['id_topic'], $row['subject']); |
|
| 1549 | + } |
|
| 1487 | 1550 | $smcFunc['db_free_result']($request); |
| 1488 | 1551 | } |
| 1489 | 1552 | |
@@ -1499,22 +1562,26 @@ discard block |
||
| 1499 | 1562 | global $modSettings, $board, $scripturl, $context; |
| 1500 | 1563 | |
| 1501 | 1564 | // No recycle no need to go further |
| 1502 | - if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) |
|
| 1503 | - return false; |
|
| 1565 | + if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) { |
|
| 1566 | + return false; |
|
| 1567 | + } |
|
| 1504 | 1568 | |
| 1505 | 1569 | // If it's confirmed go on and delete (from recycle) |
| 1506 | - if (isset($_GET['confirm_delete'])) |
|
| 1507 | - return true; |
|
| 1570 | + if (isset($_GET['confirm_delete'])) { |
|
| 1571 | + return true; |
|
| 1572 | + } |
|
| 1508 | 1573 | |
| 1509 | - if (empty($board)) |
|
| 1510 | - return false; |
|
| 1574 | + if (empty($board)) { |
|
| 1575 | + return false; |
|
| 1576 | + } |
|
| 1511 | 1577 | |
| 1512 | - if ($modSettings['recycle_board'] != $board) |
|
| 1513 | - return true; |
|
| 1514 | - elseif (isset($_REQUEST['msg'])) |
|
| 1515 | - $confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1516 | - else |
|
| 1517 | - $confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1578 | + if ($modSettings['recycle_board'] != $board) { |
|
| 1579 | + return true; |
|
| 1580 | + } elseif (isset($_REQUEST['msg'])) { |
|
| 1581 | + $confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1582 | + } else { |
|
| 1583 | + $confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1584 | + } |
|
| 1518 | 1585 | |
| 1519 | 1586 | fatal_lang_error('post_already_deleted', false, array($confirm_url)); |
| 1520 | 1587 | } |
@@ -763,10 +763,10 @@ discard block |
||
| 763 | 763 | $returning = ''; |
| 764 | 764 | $with_returning = false; |
| 765 | 765 | // lets build the returning string, mysql allow only in normal mode |
| 766 | - if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0) |
|
| 766 | + if (!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0) |
|
| 767 | 767 | { |
| 768 | 768 | // we only take the first key |
| 769 | - $returning = ' RETURNING '.$keys[0]; |
|
| 769 | + $returning = ' RETURNING ' . $keys[0]; |
|
| 770 | 770 | $with_returning = true; |
| 771 | 771 | } |
| 772 | 772 | |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 798 | 798 | VALUES |
| 799 | 799 | ' . implode(', |
| 800 | - ', $insertRows).$replace.$returning, |
|
| 800 | + ', $insertRows) . $replace . $returning, |
|
| 801 | 801 | array( |
| 802 | 802 | 'security_override' => true, |
| 803 | 803 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | if ($returnmode === 2) |
| 811 | 811 | $return_var = array(); |
| 812 | 812 | |
| 813 | - while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 813 | + while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 814 | 814 | { |
| 815 | 815 | if (is_numeric($row[0])) // try to emulate mysql limitation |
| 816 | 816 | { |
@@ -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,56 +172,63 @@ discard block |
||
| 162 | 172 | case 'array_int': |
| 163 | 173 | if (is_array($replacement)) |
| 164 | 174 | { |
| 165 | - if (empty($replacement)) |
|
| 166 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 175 | + if (empty($replacement)) { |
|
| 176 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | + } |
|
| 167 | 178 | |
| 168 | 179 | foreach ($replacement as $key => $value) |
| 169 | 180 | { |
| 170 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 171 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 181 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 182 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | $replacement[$key] = (string) (int) $value; |
| 174 | 186 | } |
| 175 | 187 | |
| 176 | 188 | return implode(', ', $replacement); |
| 189 | + } else { |
|
| 190 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | 191 | } |
| 178 | - else |
|
| 179 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 180 | 192 | |
| 181 | 193 | break; |
| 182 | 194 | |
| 183 | 195 | case 'array_string': |
| 184 | 196 | if (is_array($replacement)) |
| 185 | 197 | { |
| 186 | - if (empty($replacement)) |
|
| 187 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | + if (empty($replacement)) { |
|
| 199 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 200 | + } |
|
| 188 | 201 | |
| 189 | - foreach ($replacement as $key => $value) |
|
| 190 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 202 | + foreach ($replacement as $key => $value) { |
|
| 203 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 204 | + } |
|
| 191 | 205 | |
| 192 | 206 | return implode(', ', $replacement); |
| 207 | + } else { |
|
| 208 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 193 | 209 | } |
| 194 | - else |
|
| 195 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | 210 | break; |
| 197 | 211 | |
| 198 | 212 | case 'date': |
| 199 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 200 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 201 | - else |
|
| 202 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 214 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 215 | + } else { |
|
| 216 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 217 | + } |
|
| 203 | 218 | break; |
| 204 | 219 | |
| 205 | 220 | case 'time': |
| 206 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 207 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 208 | - else |
|
| 209 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 222 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 223 | + } else { |
|
| 224 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 225 | + } |
|
| 210 | 226 | break; |
| 211 | 227 | |
| 212 | 228 | case 'float': |
| 213 | - if (!is_numeric($replacement)) |
|
| 214 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 229 | + if (!is_numeric($replacement)) { |
|
| 230 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 231 | + } |
|
| 215 | 232 | return (string) (float) $replacement; |
| 216 | 233 | break; |
| 217 | 234 | |
@@ -224,31 +241,36 @@ discard block |
||
| 224 | 241 | break; |
| 225 | 242 | |
| 226 | 243 | case 'inet': |
| 227 | - if ($replacement == 'null' || $replacement == '') |
|
| 228 | - return 'null'; |
|
| 229 | - if (inet_pton($replacement) === false) |
|
| 230 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 244 | + if ($replacement == 'null' || $replacement == '') { |
|
| 245 | + return 'null'; |
|
| 246 | + } |
|
| 247 | + if (inet_pton($replacement) === false) { |
|
| 248 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 249 | + } |
|
| 231 | 250 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 232 | 251 | |
| 233 | 252 | case 'array_inet': |
| 234 | 253 | if (is_array($replacement)) |
| 235 | 254 | { |
| 236 | - if (empty($replacement)) |
|
| 237 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 255 | + if (empty($replacement)) { |
|
| 256 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 257 | + } |
|
| 238 | 258 | |
| 239 | 259 | foreach ($replacement as $key => $value) |
| 240 | 260 | { |
| 241 | - if ($replacement == 'null' || $replacement == '') |
|
| 242 | - $replacement[$key] = 'null'; |
|
| 243 | - if (!isValidIP($value)) |
|
| 244 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 261 | + if ($replacement == 'null' || $replacement == '') { |
|
| 262 | + $replacement[$key] = 'null'; |
|
| 263 | + } |
|
| 264 | + if (!isValidIP($value)) { |
|
| 265 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 266 | + } |
|
| 245 | 267 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 246 | 268 | } |
| 247 | 269 | |
| 248 | 270 | return implode(', ', $replacement); |
| 271 | + } else { |
|
| 272 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 249 | 273 | } |
| 250 | - else |
|
| 251 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 252 | 274 | break; |
| 253 | 275 | |
| 254 | 276 | default: |
@@ -335,14 +357,16 @@ discard block |
||
| 335 | 357 | ), |
| 336 | 358 | ); |
| 337 | 359 | |
| 338 | - if (isset($replacements[$identifier])) |
|
| 339 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 360 | + if (isset($replacements[$identifier])) { |
|
| 361 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 362 | + } |
|
| 340 | 363 | |
| 341 | 364 | // Limits need to be a little different. |
| 342 | 365 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 343 | 366 | |
| 344 | - if (trim($db_string) == '') |
|
| 345 | - return false; |
|
| 367 | + if (trim($db_string) == '') { |
|
| 368 | + return false; |
|
| 369 | + } |
|
| 346 | 370 | |
| 347 | 371 | // Comments that are allowed in a query are preg_removed. |
| 348 | 372 | static $allowed_comments_from = array( |
@@ -362,8 +386,9 @@ discard block |
||
| 362 | 386 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 363 | 387 | $db_replace_result = 0; |
| 364 | 388 | |
| 365 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 366 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 389 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 390 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 391 | + } |
|
| 367 | 392 | |
| 368 | 393 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 369 | 394 | { |
@@ -384,8 +409,9 @@ discard block |
||
| 384 | 409 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 385 | 410 | |
| 386 | 411 | // Initialize $db_cache if not already initialized. |
| 387 | - if (!isset($db_cache)) |
|
| 388 | - $db_cache = array(); |
|
| 412 | + if (!isset($db_cache)) { |
|
| 413 | + $db_cache = array(); |
|
| 414 | + } |
|
| 389 | 415 | |
| 390 | 416 | if (!empty($_SESSION['debug_redirect'])) |
| 391 | 417 | { |
@@ -411,17 +437,18 @@ discard block |
||
| 411 | 437 | while (true) |
| 412 | 438 | { |
| 413 | 439 | $pos = strpos($db_string, '\'', $pos + 1); |
| 414 | - if ($pos === false) |
|
| 415 | - break; |
|
| 440 | + if ($pos === false) { |
|
| 441 | + break; |
|
| 442 | + } |
|
| 416 | 443 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 417 | 444 | |
| 418 | 445 | while (true) |
| 419 | 446 | { |
| 420 | 447 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 421 | 448 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 422 | - if ($pos1 === false) |
|
| 423 | - break; |
|
| 424 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 449 | + if ($pos1 === false) { |
|
| 450 | + break; |
|
| 451 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 425 | 452 | { |
| 426 | 453 | $pos = $pos1; |
| 427 | 454 | break; |
@@ -437,26 +464,31 @@ discard block |
||
| 437 | 464 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 438 | 465 | |
| 439 | 466 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 440 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 441 | - $fail = true; |
|
| 467 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 468 | + $fail = true; |
|
| 469 | + } |
|
| 442 | 470 | // Trying to change passwords, slow us down, or something? |
| 443 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 444 | - $fail = true; |
|
| 445 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 446 | - $fail = true; |
|
| 471 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 472 | + $fail = true; |
|
| 473 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 474 | + $fail = true; |
|
| 475 | + } |
|
| 447 | 476 | |
| 448 | - if (!empty($fail) && function_exists('log_error')) |
|
| 449 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 477 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 478 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 479 | + } |
|
| 450 | 480 | } |
| 451 | 481 | |
| 452 | 482 | $db_last_result = @pg_query($connection, $db_string); |
| 453 | 483 | |
| 454 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 455 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 484 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 485 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 486 | + } |
|
| 456 | 487 | |
| 457 | 488 | // Debugging. |
| 458 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 459 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 489 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 490 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 491 | + } |
|
| 460 | 492 | |
| 461 | 493 | return $db_last_result; |
| 462 | 494 | } |
@@ -469,10 +501,11 @@ discard block |
||
| 469 | 501 | { |
| 470 | 502 | global $db_last_result, $db_replace_result; |
| 471 | 503 | |
| 472 | - if ($db_replace_result) |
|
| 473 | - return $db_replace_result; |
|
| 474 | - elseif ($result === null && !$db_last_result) |
|
| 475 | - return 0; |
|
| 504 | + if ($db_replace_result) { |
|
| 505 | + return $db_replace_result; |
|
| 506 | + } elseif ($result === null && !$db_last_result) { |
|
| 507 | + return 0; |
|
| 508 | + } |
|
| 476 | 509 | |
| 477 | 510 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 478 | 511 | } |
@@ -496,8 +529,9 @@ discard block |
||
| 496 | 529 | array( |
| 497 | 530 | ) |
| 498 | 531 | ); |
| 499 | - if (!$request) |
|
| 500 | - return false; |
|
| 532 | + if (!$request) { |
|
| 533 | + return false; |
|
| 534 | + } |
|
| 501 | 535 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 502 | 536 | $smcFunc['db_free_result']($request); |
| 503 | 537 | |
@@ -518,12 +552,13 @@ discard block |
||
| 518 | 552 | // Decide which connection to use |
| 519 | 553 | $connection = $connection === null ? $db_connection : $connection; |
| 520 | 554 | |
| 521 | - if ($type == 'begin') |
|
| 522 | - return @pg_query($connection, 'BEGIN'); |
|
| 523 | - elseif ($type == 'rollback') |
|
| 524 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 525 | - elseif ($type == 'commit') |
|
| 526 | - return @pg_query($connection, 'COMMIT'); |
|
| 555 | + if ($type == 'begin') { |
|
| 556 | + return @pg_query($connection, 'BEGIN'); |
|
| 557 | + } elseif ($type == 'rollback') { |
|
| 558 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 559 | + } elseif ($type == 'commit') { |
|
| 560 | + return @pg_query($connection, 'COMMIT'); |
|
| 561 | + } |
|
| 527 | 562 | |
| 528 | 563 | return false; |
| 529 | 564 | } |
@@ -551,19 +586,22 @@ discard block |
||
| 551 | 586 | $query_error = @pg_last_error($connection); |
| 552 | 587 | |
| 553 | 588 | // Log the error. |
| 554 | - if (function_exists('log_error')) |
|
| 555 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 589 | + if (function_exists('log_error')) { |
|
| 590 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 591 | + } |
|
| 556 | 592 | |
| 557 | 593 | // Nothing's defined yet... just die with it. |
| 558 | - if (empty($context) || empty($txt)) |
|
| 559 | - die($query_error); |
|
| 594 | + if (empty($context) || empty($txt)) { |
|
| 595 | + die($query_error); |
|
| 596 | + } |
|
| 560 | 597 | |
| 561 | 598 | // Show an error message, if possible. |
| 562 | 599 | $context['error_title'] = $txt['database_error']; |
| 563 | - if (allowedTo('admin_forum')) |
|
| 564 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 565 | - else |
|
| 566 | - $context['error_message'] = $txt['try_again']; |
|
| 600 | + if (allowedTo('admin_forum')) { |
|
| 601 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 602 | + } else { |
|
| 603 | + $context['error_message'] = $txt['try_again']; |
|
| 604 | + } |
|
| 567 | 605 | |
| 568 | 606 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 569 | 607 | { |
@@ -585,12 +623,14 @@ discard block |
||
| 585 | 623 | { |
| 586 | 624 | global $db_row_count; |
| 587 | 625 | |
| 588 | - if ($counter !== false) |
|
| 589 | - return pg_fetch_row($request, $counter); |
|
| 626 | + if ($counter !== false) { |
|
| 627 | + return pg_fetch_row($request, $counter); |
|
| 628 | + } |
|
| 590 | 629 | |
| 591 | 630 | // Reset the row counter... |
| 592 | - if (!isset($db_row_count[(int) $request])) |
|
| 593 | - $db_row_count[(int) $request] = 0; |
|
| 631 | + if (!isset($db_row_count[(int) $request])) { |
|
| 632 | + $db_row_count[(int) $request] = 0; |
|
| 633 | + } |
|
| 594 | 634 | |
| 595 | 635 | // Return the right row. |
| 596 | 636 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -607,12 +647,14 @@ discard block |
||
| 607 | 647 | { |
| 608 | 648 | global $db_row_count; |
| 609 | 649 | |
| 610 | - if ($counter !== false) |
|
| 611 | - return pg_fetch_assoc($request, $counter); |
|
| 650 | + if ($counter !== false) { |
|
| 651 | + return pg_fetch_assoc($request, $counter); |
|
| 652 | + } |
|
| 612 | 653 | |
| 613 | 654 | // Reset the row counter... |
| 614 | - if (!isset($db_row_count[(int) $request])) |
|
| 615 | - $db_row_count[(int) $request] = 0; |
|
| 655 | + if (!isset($db_row_count[(int) $request])) { |
|
| 656 | + $db_row_count[(int) $request] = 0; |
|
| 657 | + } |
|
| 616 | 658 | |
| 617 | 659 | // Return the right row. |
| 618 | 660 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -665,11 +707,13 @@ discard block |
||
| 665 | 707 | |
| 666 | 708 | $replace = ''; |
| 667 | 709 | |
| 668 | - if (empty($data)) |
|
| 669 | - return; |
|
| 710 | + if (empty($data)) { |
|
| 711 | + return; |
|
| 712 | + } |
|
| 670 | 713 | |
| 671 | - if (!is_array($data[array_rand($data)])) |
|
| 672 | - $data = array($data); |
|
| 714 | + if (!is_array($data[array_rand($data)])) { |
|
| 715 | + $data = array($data); |
|
| 716 | + } |
|
| 673 | 717 | |
| 674 | 718 | // Replace the prefix holder with the actual prefix. |
| 675 | 719 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -688,11 +732,13 @@ discard block |
||
| 688 | 732 | //pg 9.5 got replace support |
| 689 | 733 | $pg_version = $smcFunc['db_get_version'](); |
| 690 | 734 | // if we got a Beta Version |
| 691 | - if (stripos($pg_version, 'beta') !== false) |
|
| 692 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 735 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 736 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 737 | + } |
|
| 693 | 738 | // or RC |
| 694 | - if (stripos($pg_version, 'rc') !== false) |
|
| 695 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 739 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 740 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 741 | + } |
|
| 696 | 742 | |
| 697 | 743 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
| 698 | 744 | } |
@@ -711,8 +757,7 @@ discard block |
||
| 711 | 757 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 712 | 758 | $key_str .= $columnName; |
| 713 | 759 | $count_pk++; |
| 714 | - } |
|
| 715 | - else //normal field |
|
| 760 | + } else //normal field |
|
| 716 | 761 | { |
| 717 | 762 | $col_str .= ($count > 0 ? ',' : ''); |
| 718 | 763 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
@@ -720,20 +765,21 @@ discard block |
||
| 720 | 765 | } |
| 721 | 766 | } |
| 722 | 767 | $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
| 723 | - } |
|
| 724 | - else |
|
| 768 | + } else |
|
| 725 | 769 | { |
| 726 | 770 | foreach ($columns as $columnName => $type) |
| 727 | 771 | { |
| 728 | 772 | // Are we restricting the length? |
| 729 | - if (strpos($type, 'string-') !== false) |
|
| 730 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 731 | - else |
|
| 732 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 773 | + if (strpos($type, 'string-') !== false) { |
|
| 774 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 775 | + } else { |
|
| 776 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 777 | + } |
|
| 733 | 778 | |
| 734 | 779 | // A key? That's what we were looking for. |
| 735 | - if (in_array($columnName, $keys)) |
|
| 736 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 780 | + if (in_array($columnName, $keys)) { |
|
| 781 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 782 | + } |
|
| 737 | 783 | $count++; |
| 738 | 784 | } |
| 739 | 785 | |
@@ -769,10 +815,11 @@ discard block |
||
| 769 | 815 | foreach ($columns as $columnName => $type) |
| 770 | 816 | { |
| 771 | 817 | // Are we restricting the length? |
| 772 | - if (strpos($type, 'string-') !== false) |
|
| 773 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 774 | - else |
|
| 775 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 818 | + if (strpos($type, 'string-') !== false) { |
|
| 819 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 820 | + } else { |
|
| 821 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 822 | + } |
|
| 776 | 823 | } |
| 777 | 824 | $insertData = substr($insertData, 0, -2) . ')'; |
| 778 | 825 | |
@@ -781,8 +828,9 @@ discard block |
||
| 781 | 828 | |
| 782 | 829 | // Here's where the variables are injected to the query. |
| 783 | 830 | $insertRows = array(); |
| 784 | - foreach ($data as $dataRow) |
|
| 785 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 831 | + foreach ($data as $dataRow) { |
|
| 832 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 833 | + } |
|
| 786 | 834 | |
| 787 | 835 | // Do the insert. |
| 788 | 836 | $request = $smcFunc['db_query']('', ' |
@@ -799,19 +847,21 @@ discard block |
||
| 799 | 847 | |
| 800 | 848 | if ($with_returning && $request !== false) |
| 801 | 849 | { |
| 802 | - if ($returnmode === 2) |
|
| 803 | - $return_var = array(); |
|
| 850 | + if ($returnmode === 2) { |
|
| 851 | + $return_var = array(); |
|
| 852 | + } |
|
| 804 | 853 | |
| 805 | 854 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
| 806 | 855 | { |
| 807 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
| 856 | + if (is_numeric($row[0])) { |
|
| 857 | + // try to emulate mysql limitation |
|
| 808 | 858 | { |
| 809 | 859 | if ($returnmode === 1) |
| 810 | 860 | $return_var = $row[0]; |
| 811 | - elseif ($returnmode === 2) |
|
| 812 | - $return_var[] = $row[0]; |
|
| 813 | - } |
|
| 814 | - else |
|
| 861 | + } elseif ($returnmode === 2) { |
|
| 862 | + $return_var[] = $row[0]; |
|
| 863 | + } |
|
| 864 | + } else |
|
| 815 | 865 | { |
| 816 | 866 | $with_returning = false; |
| 817 | 867 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -820,9 +870,10 @@ discard block |
||
| 820 | 870 | } |
| 821 | 871 | } |
| 822 | 872 | |
| 823 | - if ($with_returning && !empty($return_var)) |
|
| 824 | - return $return_var; |
|
| 825 | -} |
|
| 873 | + if ($with_returning && !empty($return_var)) { |
|
| 874 | + return $return_var; |
|
| 875 | + } |
|
| 876 | + } |
|
| 826 | 877 | |
| 827 | 878 | /** |
| 828 | 879 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -859,8 +910,9 @@ discard block |
||
| 859 | 910 | */ |
| 860 | 911 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 861 | 912 | { |
| 862 | - if (empty($log_message)) |
|
| 863 | - $log_message = $error_message; |
|
| 913 | + if (empty($log_message)) { |
|
| 914 | + $log_message = $error_message; |
|
| 915 | + } |
|
| 864 | 916 | |
| 865 | 917 | foreach (debug_backtrace() as $step) |
| 866 | 918 | { |
@@ -879,12 +931,14 @@ discard block |
||
| 879 | 931 | } |
| 880 | 932 | |
| 881 | 933 | // A special case - we want the file and line numbers for debugging. |
| 882 | - if ($error_type == 'return') |
|
| 883 | - return array($file, $line); |
|
| 934 | + if ($error_type == 'return') { |
|
| 935 | + return array($file, $line); |
|
| 936 | + } |
|
| 884 | 937 | |
| 885 | 938 | // Is always a critical error. |
| 886 | - if (function_exists('log_error')) |
|
| 887 | - log_error($log_message, 'critical', $file, $line); |
|
| 939 | + if (function_exists('log_error')) { |
|
| 940 | + log_error($log_message, 'critical', $file, $line); |
|
| 941 | + } |
|
| 888 | 942 | |
| 889 | 943 | if (function_exists('fatal_error')) |
| 890 | 944 | { |
@@ -892,12 +946,12 @@ discard block |
||
| 892 | 946 | |
| 893 | 947 | // Cannot continue... |
| 894 | 948 | exit; |
| 949 | + } elseif ($error_type) { |
|
| 950 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 951 | + } else { |
|
| 952 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 953 | + } |
|
| 895 | 954 | } |
| 896 | - elseif ($error_type) |
|
| 897 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 898 | - else |
|
| 899 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 900 | -} |
|
| 901 | 955 | |
| 902 | 956 | /** |
| 903 | 957 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -914,10 +968,11 @@ discard block |
||
| 914 | 968 | '\\' => '\\\\', |
| 915 | 969 | ); |
| 916 | 970 | |
| 917 | - if ($translate_human_wildcards) |
|
| 918 | - $replacements += array( |
|
| 971 | + if ($translate_human_wildcards) { |
|
| 972 | + $replacements += array( |
|
| 919 | 973 | '*' => '%', |
| 920 | 974 | ); |
| 975 | + } |
|
| 921 | 976 | |
| 922 | 977 | return strtr($string, $replacements); |
| 923 | 978 | } |