@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | |
| 20 | 21 | /** |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings'); |
| 45 | 46 | |
| 46 | 47 | // Is it elsewhere? |
| 47 | - if (isset($subActions[$_REQUEST['sa']][2])) |
|
| 48 | - require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
| 48 | + if (isset($subActions[$_REQUEST['sa']][2])) { |
|
| 49 | + require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | // Do the permission check, you might not be allowed her. |
| 51 | 53 | isAllowedTo($subActions[$_REQUEST['sa']][1]); |
@@ -104,19 +106,20 @@ discard block |
||
| 104 | 106 | 'function' => function($rowData) use ($scripturl) |
| 105 | 107 | { |
| 106 | 108 | // Since the moderator group has no explicit members, no link is needed. |
| 107 | - if ($rowData['id_group'] == 3) |
|
| 108 | - $group_name = $rowData['group_name']; |
|
| 109 | - else |
|
| 109 | + if ($rowData['id_group'] == 3) { |
|
| 110 | + $group_name = $rowData['group_name']; |
|
| 111 | + } else |
|
| 110 | 112 | { |
| 111 | 113 | $color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']); |
| 112 | 114 | $group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
| 113 | 115 | } |
| 114 | 116 | |
| 115 | 117 | // Add a help option for moderator and administrator. |
| 116 | - if ($rowData['id_group'] == 1) |
|
| 117 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 118 | - elseif ($rowData['id_group'] == 3) |
|
| 119 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 118 | + if ($rowData['id_group'] == 1) { |
|
| 119 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 120 | + } elseif ($rowData['id_group'] == 3) { |
|
| 121 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 122 | + } |
|
| 120 | 123 | |
| 121 | 124 | return $group_name; |
| 122 | 125 | }, |
@@ -329,12 +332,14 @@ discard block |
||
| 329 | 332 | call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup)); |
| 330 | 333 | |
| 331 | 334 | // Update the post groups now, if this is a post group! |
| 332 | - if (isset($_POST['min_posts'])) |
|
| 333 | - updateStats('postgroups'); |
|
| 335 | + if (isset($_POST['min_posts'])) { |
|
| 336 | + updateStats('postgroups'); |
|
| 337 | + } |
|
| 334 | 338 | |
| 335 | 339 | // You cannot set permissions for post groups if they are disabled. |
| 336 | - if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) |
|
| 337 | - $_POST['perm_type'] = ''; |
|
| 340 | + if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) { |
|
| 341 | + $_POST['perm_type'] = ''; |
|
| 342 | + } |
|
| 338 | 343 | |
| 339 | 344 | if ($_POST['perm_type'] == 'predefined') |
| 340 | 345 | { |
@@ -364,8 +369,9 @@ discard block |
||
| 364 | 369 | $smcFunc['db_free_result']($request); |
| 365 | 370 | |
| 366 | 371 | // Protected groups are... well, protected! |
| 367 | - if ($copy_type == 1) |
|
| 368 | - fatal_lang_error('membergroup_does_not_exist'); |
|
| 372 | + if ($copy_type == 1) { |
|
| 373 | + fatal_lang_error('membergroup_does_not_exist'); |
|
| 374 | + } |
|
| 369 | 375 | } |
| 370 | 376 | |
| 371 | 377 | // Don't allow copying of a real priviledged person! |
@@ -383,18 +389,20 @@ discard block |
||
| 383 | 389 | $inserts = array(); |
| 384 | 390 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 385 | 391 | { |
| 386 | - if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) |
|
| 387 | - $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
| 392 | + if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) { |
|
| 393 | + $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
| 394 | + } |
|
| 388 | 395 | } |
| 389 | 396 | $smcFunc['db_free_result']($request); |
| 390 | 397 | |
| 391 | - if (!empty($inserts)) |
|
| 392 | - $smcFunc['db_insert']('insert', |
|
| 398 | + if (!empty($inserts)) { |
|
| 399 | + $smcFunc['db_insert']('insert', |
|
| 393 | 400 | '{db_prefix}permissions', |
| 394 | 401 | array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
| 395 | 402 | $inserts, |
| 396 | 403 | array('id_group', 'permission') |
| 397 | 404 | ); |
| 405 | + } |
|
| 398 | 406 | |
| 399 | 407 | $request = $smcFunc['db_query']('', ' |
| 400 | 408 | SELECT id_profile, permission, add_deny |
@@ -405,17 +413,19 @@ discard block |
||
| 405 | 413 | ) |
| 406 | 414 | ); |
| 407 | 415 | $inserts = array(); |
| 408 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 409 | - $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
| 416 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 417 | + $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
| 418 | + } |
|
| 410 | 419 | $smcFunc['db_free_result']($request); |
| 411 | 420 | |
| 412 | - if (!empty($inserts)) |
|
| 413 | - $smcFunc['db_insert']('insert', |
|
| 421 | + if (!empty($inserts)) { |
|
| 422 | + $smcFunc['db_insert']('insert', |
|
| 414 | 423 | '{db_prefix}board_permissions', |
| 415 | 424 | array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
| 416 | 425 | $inserts, |
| 417 | 426 | array('id_group', 'id_profile', 'permission') |
| 418 | 427 | ); |
| 428 | + } |
|
| 419 | 429 | |
| 420 | 430 | // Also get some membergroup information if we're copying and not copying from guests... |
| 421 | 431 | if ($copy_id > 0 && $_POST['perm_type'] == 'copy') |
@@ -468,14 +478,15 @@ discard block |
||
| 468 | 478 | $changed_boards['allow'] = array(); |
| 469 | 479 | $changed_boards['deny'] = array(); |
| 470 | 480 | $changed_boards['ignore'] = array(); |
| 471 | - foreach ($accesses as $group_id => $action) |
|
| 472 | - $changed_boards[$action][] = (int) $group_id; |
|
| 481 | + foreach ($accesses as $group_id => $action) { |
|
| 482 | + $changed_boards[$action][] = (int) $group_id; |
|
| 483 | + } |
|
| 473 | 484 | |
| 474 | 485 | foreach (array('allow', 'deny') as $board_action) |
| 475 | 486 | { |
| 476 | 487 | // Only do this if they have special access requirements. |
| 477 | - if (!empty($changed_boards[$board_action])) |
|
| 478 | - $smcFunc['db_query']('', ' |
|
| 488 | + if (!empty($changed_boards[$board_action])) { |
|
| 489 | + $smcFunc['db_query']('', ' |
|
| 479 | 490 | UPDATE {db_prefix}boards |
| 480 | 491 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
| 481 | 492 | WHERE id_board IN ({array_int:board_list})', |
@@ -487,11 +498,13 @@ discard block |
||
| 487 | 498 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 488 | 499 | ) |
| 489 | 500 | ); |
| 501 | + } |
|
| 490 | 502 | } |
| 491 | 503 | |
| 492 | 504 | // If this is joinable then set it to show group membership in people's profiles. |
| 493 | - if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) |
|
| 494 | - updateSettings(array('show_group_membership' => 1)); |
|
| 505 | + if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) { |
|
| 506 | + updateSettings(array('show_group_membership' => 1)); |
|
| 507 | + } |
|
| 495 | 508 | |
| 496 | 509 | // Rebuild the group cache. |
| 497 | 510 | updateSettings(array( |
@@ -512,8 +525,9 @@ discard block |
||
| 512 | 525 | $context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']); |
| 513 | 526 | $context['allow_protected'] = allowedTo('admin_forum'); |
| 514 | 527 | |
| 515 | - if (!empty($modSettings['deny_boards_access'])) |
|
| 516 | - loadLanguage('ManagePermissions'); |
|
| 528 | + if (!empty($modSettings['deny_boards_access'])) { |
|
| 529 | + loadLanguage('ManagePermissions'); |
|
| 530 | + } |
|
| 517 | 531 | |
| 518 | 532 | $result = $smcFunc['db_query']('', ' |
| 519 | 533 | SELECT id_group, group_name |
@@ -530,11 +544,12 @@ discard block |
||
| 530 | 544 | ) |
| 531 | 545 | ); |
| 532 | 546 | $context['groups'] = array(); |
| 533 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 534 | - $context['groups'][] = array( |
|
| 547 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 548 | + $context['groups'][] = array( |
|
| 535 | 549 | 'id' => $row['id_group'], |
| 536 | 550 | 'name' => $row['group_name'] |
| 537 | 551 | ); |
| 552 | + } |
|
| 538 | 553 | $smcFunc['db_free_result']($result); |
| 539 | 554 | |
| 540 | 555 | $request = $smcFunc['db_query']('', ' |
@@ -551,12 +566,13 @@ discard block |
||
| 551 | 566 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 552 | 567 | { |
| 553 | 568 | // This category hasn't been set up yet.. |
| 554 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 555 | - $context['categories'][$row['id_cat']] = array( |
|
| 569 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 570 | + $context['categories'][$row['id_cat']] = array( |
|
| 556 | 571 | 'id' => $row['id_cat'], |
| 557 | 572 | 'name' => $row['cat_name'], |
| 558 | 573 | 'boards' => array() |
| 559 | 574 | ); |
| 575 | + } |
|
| 560 | 576 | |
| 561 | 577 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 562 | 578 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -603,8 +619,9 @@ discard block |
||
| 603 | 619 | require_once($sourcedir . '/Subs-Membergroups.php'); |
| 604 | 620 | $result = deleteMembergroups((int) $_REQUEST['group']); |
| 605 | 621 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
| 606 | - if ($result === 'group_cannot_delete_sub') |
|
| 607 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 622 | + if ($result === 'group_cannot_delete_sub') { |
|
| 623 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 624 | + } |
|
| 608 | 625 | |
| 609 | 626 | // Go back to the membergroup index. |
| 610 | 627 | redirectexit('action=admin;area=membergroups;'); |
@@ -626,8 +643,9 @@ discard block |
||
| 626 | 643 | |
| 627 | 644 | $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0; |
| 628 | 645 | |
| 629 | - if (!empty($modSettings['deny_boards_access'])) |
|
| 630 | - loadLanguage('ManagePermissions'); |
|
| 646 | + if (!empty($modSettings['deny_boards_access'])) { |
|
| 647 | + loadLanguage('ManagePermissions'); |
|
| 648 | + } |
|
| 631 | 649 | |
| 632 | 650 | // Make sure this group is editable. |
| 633 | 651 | if (!empty($_REQUEST['group'])) |
@@ -649,8 +667,9 @@ discard block |
||
| 649 | 667 | } |
| 650 | 668 | |
| 651 | 669 | // Now, do we have a valid id? |
| 652 | - if (empty($_REQUEST['group'])) |
|
| 653 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
| 670 | + if (empty($_REQUEST['group'])) { |
|
| 671 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
| 672 | + } |
|
| 654 | 673 | |
| 655 | 674 | // People who can manage boards are a bit special. |
| 656 | 675 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -681,8 +700,9 @@ discard block |
||
| 681 | 700 | require_once($sourcedir . '/Subs-Membergroups.php'); |
| 682 | 701 | $result = deleteMembergroups($_REQUEST['group']); |
| 683 | 702 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
| 684 | - if ($result === 'group_cannot_delete_sub') |
|
| 685 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 703 | + if ($result === 'group_cannot_delete_sub') { |
|
| 704 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 705 | + } |
|
| 686 | 706 | |
| 687 | 707 | redirectexit('action=admin;area=membergroups;'); |
| 688 | 708 | } |
@@ -759,16 +779,18 @@ discard block |
||
| 759 | 779 | $request = $smcFunc['db_query']('', ' |
| 760 | 780 | SELECT id_board |
| 761 | 781 | FROM {db_prefix}boards'); |
| 762 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 763 | - $accesses[(int) $row['id_board']] = 'allow'; |
|
| 782 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 783 | + $accesses[(int) $row['id_board']] = 'allow'; |
|
| 784 | + } |
|
| 764 | 785 | $smcFunc['db_free_result']($request); |
| 765 | 786 | } |
| 766 | 787 | |
| 767 | 788 | $changed_boards['allow'] = array(); |
| 768 | 789 | $changed_boards['deny'] = array(); |
| 769 | 790 | $changed_boards['ignore'] = array(); |
| 770 | - foreach ($accesses as $group_id => $action) |
|
| 771 | - $changed_boards[$action][] = (int) $group_id; |
|
| 791 | + foreach ($accesses as $group_id => $action) { |
|
| 792 | + $changed_boards[$action][] = (int) $group_id; |
|
| 793 | + } |
|
| 772 | 794 | |
| 773 | 795 | foreach (array('allow', 'deny') as $board_action) |
| 774 | 796 | { |
@@ -784,8 +806,8 @@ discard block |
||
| 784 | 806 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 785 | 807 | ) |
| 786 | 808 | ); |
| 787 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 788 | - $smcFunc['db_query']('', ' |
|
| 809 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 810 | + $smcFunc['db_query']('', ' |
|
| 789 | 811 | UPDATE {db_prefix}boards |
| 790 | 812 | SET {raw:column} = {string:member_group_access} |
| 791 | 813 | WHERE id_board = {int:current_board}', |
@@ -795,11 +817,12 @@ discard block |
||
| 795 | 817 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 796 | 818 | ) |
| 797 | 819 | ); |
| 820 | + } |
|
| 798 | 821 | $smcFunc['db_free_result']($request); |
| 799 | 822 | |
| 800 | 823 | // Add the membergroup to all boards that hadn't been set yet. |
| 801 | - if (!empty($changed_boards[$board_action])) |
|
| 802 | - $smcFunc['db_query']('', ' |
|
| 824 | + if (!empty($changed_boards[$board_action])) { |
|
| 825 | + $smcFunc['db_query']('', ' |
|
| 803 | 826 | UPDATE {db_prefix}boards |
| 804 | 827 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
| 805 | 828 | WHERE id_board IN ({array_int:board_list}) |
@@ -813,6 +836,7 @@ discard block |
||
| 813 | 836 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 814 | 837 | ) |
| 815 | 838 | ); |
| 839 | + } |
|
| 816 | 840 | } |
| 817 | 841 | } |
| 818 | 842 | |
@@ -838,12 +862,14 @@ discard block |
||
| 838 | 862 | ) |
| 839 | 863 | ); |
| 840 | 864 | $updates = array(); |
| 841 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 842 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 865 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 866 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 867 | + } |
|
| 843 | 868 | $smcFunc['db_free_result']($request); |
| 844 | 869 | |
| 845 | - foreach ($updates as $additional_groups => $memberArray) |
|
| 846 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
| 870 | + foreach ($updates as $additional_groups => $memberArray) { |
|
| 871 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
| 872 | + } |
|
| 847 | 873 | |
| 848 | 874 | // Sorry, but post groups can't moderate boards |
| 849 | 875 | $smcFunc['db_query']('', ' |
@@ -853,8 +879,7 @@ discard block |
||
| 853 | 879 | 'current_group' => (int) $_REQUEST['group'], |
| 854 | 880 | ) |
| 855 | 881 | ); |
| 856 | - } |
|
| 857 | - elseif ($_REQUEST['group'] != 3) |
|
| 882 | + } elseif ($_REQUEST['group'] != 3) |
|
| 858 | 883 | { |
| 859 | 884 | // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional). |
| 860 | 885 | if ($_POST['group_hidden'] == 2) |
@@ -869,8 +894,9 @@ discard block |
||
| 869 | 894 | ) |
| 870 | 895 | ); |
| 871 | 896 | $updates = array(); |
| 872 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 873 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 897 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 898 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 899 | + } |
|
| 874 | 900 | $smcFunc['db_free_result']($request); |
| 875 | 901 | |
| 876 | 902 | foreach ($updates as $additional_groups => $memberArray) |
@@ -912,8 +938,9 @@ discard block |
||
| 912 | 938 | $smcFunc['db_free_result']($request); |
| 913 | 939 | |
| 914 | 940 | // Do we need to update the setting? |
| 915 | - if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) |
|
| 916 | - updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
| 941 | + if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) { |
|
| 942 | + updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
| 943 | + } |
|
| 917 | 944 | } |
| 918 | 945 | |
| 919 | 946 | // Do we need to set inherited permissions? |
@@ -946,8 +973,9 @@ discard block |
||
| 946 | 973 | { |
| 947 | 974 | $moderators[$k] = trim($moderators[$k]); |
| 948 | 975 | |
| 949 | - if (strlen($moderators[$k]) == 0) |
|
| 950 | - unset($moderators[$k]); |
|
| 976 | + if (strlen($moderators[$k]) == 0) { |
|
| 977 | + unset($moderators[$k]); |
|
| 978 | + } |
|
| 951 | 979 | } |
| 952 | 980 | |
| 953 | 981 | // Find all the id_member's for the member_name's in the list. |
@@ -963,8 +991,9 @@ discard block |
||
| 963 | 991 | 'count' => count($moderators), |
| 964 | 992 | ) |
| 965 | 993 | ); |
| 966 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 967 | - $group_moderators[] = $row['id_member']; |
|
| 994 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 995 | + $group_moderators[] = $row['id_member']; |
|
| 996 | + } |
|
| 968 | 997 | $smcFunc['db_free_result']($request); |
| 969 | 998 | } |
| 970 | 999 | } |
@@ -972,8 +1001,9 @@ discard block |
||
| 972 | 1001 | if (!empty($_POST['moderator_list'])) |
| 973 | 1002 | { |
| 974 | 1003 | $moderators = array(); |
| 975 | - foreach ($_POST['moderator_list'] as $moderator) |
|
| 976 | - $moderators[] = (int) $moderator; |
|
| 1004 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
| 1005 | + $moderators[] = (int) $moderator; |
|
| 1006 | + } |
|
| 977 | 1007 | |
| 978 | 1008 | if (!empty($moderators)) |
| 979 | 1009 | { |
@@ -987,8 +1017,9 @@ discard block |
||
| 987 | 1017 | 'num_moderators' => count($moderators), |
| 988 | 1018 | ) |
| 989 | 1019 | ); |
| 990 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 991 | - $group_moderators[] = $row['id_member']; |
|
| 1020 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1021 | + $group_moderators[] = $row['id_member']; |
|
| 1022 | + } |
|
| 992 | 1023 | $smcFunc['db_free_result']($request); |
| 993 | 1024 | } |
| 994 | 1025 | } |
@@ -1000,8 +1031,9 @@ discard block |
||
| 1000 | 1031 | if (!empty($group_moderators)) |
| 1001 | 1032 | { |
| 1002 | 1033 | $mod_insert = array(); |
| 1003 | - foreach ($group_moderators as $moderator) |
|
| 1004 | - $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
| 1034 | + foreach ($group_moderators as $moderator) { |
|
| 1035 | + $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
| 1036 | + } |
|
| 1005 | 1037 | |
| 1006 | 1038 | $smcFunc['db_insert']('insert', |
| 1007 | 1039 | '{db_prefix}group_moderators', |
@@ -1035,8 +1067,9 @@ discard block |
||
| 1035 | 1067 | 'current_group' => (int) $_REQUEST['group'], |
| 1036 | 1068 | ) |
| 1037 | 1069 | ); |
| 1038 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1039 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
| 1070 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1071 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
| 1072 | + } |
|
| 1040 | 1073 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1041 | 1074 | $smcFunc['db_free_result']($request); |
| 1042 | 1075 | |
@@ -1073,14 +1106,16 @@ discard block |
||
| 1073 | 1106 | ) |
| 1074 | 1107 | ); |
| 1075 | 1108 | $context['group']['moderators'] = array(); |
| 1076 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1077 | - $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 1109 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1110 | + $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 1111 | + } |
|
| 1078 | 1112 | $smcFunc['db_free_result']($request); |
| 1079 | 1113 | |
| 1080 | 1114 | $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '"' . implode('", "', $context['group']['moderators']) . '"'; |
| 1081 | 1115 | |
| 1082 | - if (!empty($context['group']['moderators'])) |
|
| 1083 | - list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
| 1116 | + if (!empty($context['group']['moderators'])) { |
|
| 1117 | + list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
| 1118 | + } |
|
| 1084 | 1119 | |
| 1085 | 1120 | // Get a list of boards this membergroup is allowed to see. |
| 1086 | 1121 | $context['boards'] = array(); |
@@ -1100,12 +1135,13 @@ discard block |
||
| 1100 | 1135 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1101 | 1136 | { |
| 1102 | 1137 | // This category hasn't been set up yet.. |
| 1103 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 1104 | - $context['categories'][$row['id_cat']] = array( |
|
| 1138 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 1139 | + $context['categories'][$row['id_cat']] = array( |
|
| 1105 | 1140 | 'id' => $row['id_cat'], |
| 1106 | 1141 | 'name' => $row['cat_name'], |
| 1107 | 1142 | 'boards' => array() |
| 1108 | 1143 | ); |
| 1144 | + } |
|
| 1109 | 1145 | |
| 1110 | 1146 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 1111 | 1147 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -1147,14 +1183,16 @@ discard block |
||
| 1147 | 1183 | $ext = pathinfo($settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION); |
| 1148 | 1184 | |
| 1149 | 1185 | // If the extension is not empty, and it is valid |
| 1150 | - if (!empty($ext) && in_array($ext, $imageExts)) |
|
| 1151 | - $context['possible_icons'][] = $value; |
|
| 1186 | + if (!empty($ext) && in_array($ext, $imageExts)) { |
|
| 1187 | + $context['possible_icons'][] = $value; |
|
| 1188 | + } |
|
| 1152 | 1189 | } |
| 1153 | 1190 | } |
| 1154 | 1191 | |
| 1155 | 1192 | // Insert our JS, if we have possible icons. |
| 1156 | - if (!empty($context['possible_icons'])) |
|
| 1157 | - loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown'); |
|
| 1193 | + if (!empty($context['possible_icons'])) { |
|
| 1194 | + loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown'); |
|
| 1195 | + } |
|
| 1158 | 1196 | |
| 1159 | 1197 | loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); |
| 1160 | 1198 | |
@@ -1176,8 +1214,9 @@ discard block |
||
| 1176 | 1214 | ) |
| 1177 | 1215 | ); |
| 1178 | 1216 | $context['inheritable_groups'] = array(); |
| 1179 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1180 | - $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
| 1217 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1218 | + $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
| 1219 | + } |
|
| 1181 | 1220 | $smcFunc['db_free_result']($request); |
| 1182 | 1221 | |
| 1183 | 1222 | call_integration_hook('integrate_view_membergroup'); |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Get the latest post made on the system |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | 'is_approved' => 1, |
| 45 | 46 | ) |
| 46 | 47 | ); |
| 47 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 48 | - return array(); |
|
| 48 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 49 | + return array(); |
|
| 50 | + } |
|
| 49 | 51 | $row = $smcFunc['db_fetch_assoc']($request); |
| 50 | 52 | $smcFunc['db_free_result']($request); |
| 51 | 53 | |
@@ -54,8 +56,9 @@ discard block |
||
| 54 | 56 | censorText($row['body']); |
| 55 | 57 | |
| 56 | 58 | $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled']), array('<br>' => ' '))); |
| 57 | - if ($smcFunc['strlen']($row['body']) > 128) |
|
| 58 | - $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 59 | + if ($smcFunc['strlen']($row['body']) > 128) { |
|
| 60 | + $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | // Send the data. |
| 61 | 64 | return array( |
@@ -83,8 +86,9 @@ discard block |
||
| 83 | 86 | |
| 84 | 87 | $context['is_redirect'] = false; |
| 85 | 88 | |
| 86 | - if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) |
|
| 87 | - $_REQUEST['start'] = 95; |
|
| 89 | + if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) { |
|
| 90 | + $_REQUEST['start'] = 95; |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | $_REQUEST['start'] = (int) $_REQUEST['start']; |
| 90 | 94 | |
@@ -92,8 +96,9 @@ discard block |
||
| 92 | 96 | if (!empty($_REQUEST['c']) && empty($board)) |
| 93 | 97 | { |
| 94 | 98 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
| 95 | - foreach ($_REQUEST['c'] as $i => $c) |
|
| 96 | - $_REQUEST['c'][$i] = (int) $c; |
|
| 99 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
| 100 | + $_REQUEST['c'][$i] = (int) $c; |
|
| 101 | + } |
|
| 97 | 102 | |
| 98 | 103 | if (count($_REQUEST['c']) == 1) |
| 99 | 104 | { |
@@ -109,8 +114,9 @@ discard block |
||
| 109 | 114 | list ($name) = $smcFunc['db_fetch_row']($request); |
| 110 | 115 | $smcFunc['db_free_result']($request); |
| 111 | 116 | |
| 112 | - if (empty($name)) |
|
| 113 | - fatal_lang_error('no_access', false); |
|
| 117 | + if (empty($name)) { |
|
| 118 | + fatal_lang_error('no_access', false); |
|
| 119 | + } |
|
| 114 | 120 | |
| 115 | 121 | $context['linktree'][] = array( |
| 116 | 122 | 'url' => $scripturl . '#c' . (int) $_REQUEST['c'], |
@@ -142,8 +148,9 @@ discard block |
||
| 142 | 148 | } |
| 143 | 149 | $smcFunc['db_free_result']($request); |
| 144 | 150 | |
| 145 | - if (empty($boards)) |
|
| 146 | - fatal_lang_error('error_no_boards_selected'); |
|
| 151 | + if (empty($boards)) { |
|
| 152 | + fatal_lang_error('error_no_boards_selected'); |
|
| 153 | + } |
|
| 147 | 154 | |
| 148 | 155 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
| 149 | 156 | $query_parameters['boards'] = $boards; |
@@ -157,12 +164,12 @@ discard block |
||
| 157 | 164 | } |
| 158 | 165 | |
| 159 | 166 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false); |
| 160 | - } |
|
| 161 | - elseif (!empty($_REQUEST['boards'])) |
|
| 167 | + } elseif (!empty($_REQUEST['boards'])) |
|
| 162 | 168 | { |
| 163 | 169 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 164 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
| 165 | - $_REQUEST['boards'][$i] = (int) $b; |
|
| 170 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
| 171 | + $_REQUEST['boards'][$i] = (int) $b; |
|
| 172 | + } |
|
| 166 | 173 | |
| 167 | 174 | $request = $smcFunc['db_query']('', ' |
| 168 | 175 | SELECT b.id_board, b.num_posts |
@@ -186,8 +193,9 @@ discard block |
||
| 186 | 193 | } |
| 187 | 194 | $smcFunc['db_free_result']($request); |
| 188 | 195 | |
| 189 | - if (empty($boards)) |
|
| 190 | - fatal_lang_error('error_no_boards_selected'); |
|
| 196 | + if (empty($boards)) { |
|
| 197 | + fatal_lang_error('error_no_boards_selected'); |
|
| 198 | + } |
|
| 191 | 199 | |
| 192 | 200 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
| 193 | 201 | $query_parameters['boards'] = $boards; |
@@ -201,8 +209,7 @@ discard block |
||
| 201 | 209 | } |
| 202 | 210 | |
| 203 | 211 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false); |
| 204 | - } |
|
| 205 | - elseif (!empty($board)) |
|
| 212 | + } elseif (!empty($board)) |
|
| 206 | 213 | { |
| 207 | 214 | $request = $smcFunc['db_query']('', ' |
| 208 | 215 | SELECT num_posts, redirect |
@@ -235,8 +242,7 @@ discard block |
||
| 235 | 242 | } |
| 236 | 243 | |
| 237 | 244 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true); |
| 238 | - } |
|
| 239 | - else |
|
| 245 | + } else |
|
| 240 | 246 | { |
| 241 | 247 | $query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
| 242 | 248 | AND b.id_board != {int:recycle_board}' : ''). ' |
@@ -271,8 +277,9 @@ discard block |
||
| 271 | 277 | ); |
| 272 | 278 | |
| 273 | 279 | // If you selected a redirection board, don't try getting posts for it... |
| 274 | - if ($context['is_redirect']) |
|
| 275 | - $messages = 0; |
|
| 280 | + if ($context['is_redirect']) { |
|
| 281 | + $messages = 0; |
|
| 282 | + } |
|
| 276 | 283 | |
| 277 | 284 | $key = 'recent-' . $user_info['id'] . '-' . md5($smcFunc['json_encode'](array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start']; |
| 278 | 285 | if (!$context['is_redirect'] && (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null)) |
@@ -303,16 +310,18 @@ discard block |
||
| 303 | 310 | $query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board); |
| 304 | 311 | $cache_results = true; |
| 305 | 312 | unset($query_parameters['max_id_msg']); |
| 313 | + } else { |
|
| 314 | + $done = true; |
|
| 306 | 315 | } |
| 307 | - else |
|
| 308 | - $done = true; |
|
| 309 | 316 | } |
| 310 | 317 | $messages = array(); |
| 311 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 312 | - $messages[] = $row['id_msg']; |
|
| 318 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 319 | + $messages[] = $row['id_msg']; |
|
| 320 | + } |
|
| 313 | 321 | $smcFunc['db_free_result']($request); |
| 314 | - if (!empty($cache_results)) |
|
| 315 | - cache_put_data($key, $messages, 120); |
|
| 322 | + if (!empty($cache_results)) { |
|
| 323 | + cache_put_data($key, $messages, 120); |
|
| 324 | + } |
|
| 316 | 325 | } |
| 317 | 326 | |
| 318 | 327 | // Nothing here... Or at least, nothing you can see... |
@@ -399,8 +408,9 @@ discard block |
||
| 399 | 408 | 'css_class' => 'windowbg', |
| 400 | 409 | ); |
| 401 | 410 | |
| 402 | - if ($user_info['id'] == $row['id_first_member']) |
|
| 403 | - $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
| 411 | + if ($user_info['id'] == $row['id_first_member']) { |
|
| 412 | + $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
| 413 | + } |
|
| 404 | 414 | $board_ids['any'][$row['id_board']][] = $row['id_msg']; |
| 405 | 415 | } |
| 406 | 416 | $smcFunc['db_free_result']($request); |
@@ -426,20 +436,23 @@ discard block |
||
| 426 | 436 | $boards = boardsAllowedTo($permission); |
| 427 | 437 | |
| 428 | 438 | // If 0 is the only thing in the array, they can do it everywhere! |
| 429 | - if (!empty($boards) && $boards[0] == 0) |
|
| 430 | - $boards = array_keys($board_ids[$type]); |
|
| 439 | + if (!empty($boards) && $boards[0] == 0) { |
|
| 440 | + $boards = array_keys($board_ids[$type]); |
|
| 441 | + } |
|
| 431 | 442 | |
| 432 | 443 | // Go through the boards, and look for posts they can do this on. |
| 433 | 444 | foreach ($boards as $board_id) |
| 434 | 445 | { |
| 435 | 446 | // Hmm, they have permission, but there are no topics from that board on this page. |
| 436 | - if (!isset($board_ids[$type][$board_id])) |
|
| 437 | - continue; |
|
| 447 | + if (!isset($board_ids[$type][$board_id])) { |
|
| 448 | + continue; |
|
| 449 | + } |
|
| 438 | 450 | |
| 439 | 451 | // Okay, looks like they can do it for these posts. |
| 440 | - foreach ($board_ids[$type][$board_id] as $counter) |
|
| 441 | - if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
| 452 | + foreach ($board_ids[$type][$board_id] as $counter) { |
|
| 453 | + if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
| 442 | 454 | $context['posts'][$counter][$allowed] = true; |
| 455 | + } |
|
| 443 | 456 | } |
| 444 | 457 | } |
| 445 | 458 | } |
@@ -482,17 +495,19 @@ discard block |
||
| 482 | 495 | $context['showing_all_topics'] = isset($_GET['all']); |
| 483 | 496 | $context['start'] = (int) $_REQUEST['start']; |
| 484 | 497 | $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
| 485 | - if ($_REQUEST['action'] == 'unread') |
|
| 486 | - $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
| 487 | - else |
|
| 488 | - $context['page_title'] = $txt['unread_replies']; |
|
| 498 | + if ($_REQUEST['action'] == 'unread') { |
|
| 499 | + $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
| 500 | + } else { |
|
| 501 | + $context['page_title'] = $txt['unread_replies']; |
|
| 502 | + } |
|
| 489 | 503 | |
| 490 | - if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) |
|
| 491 | - fatal_lang_error('loadavg_allunread_disabled', false); |
|
| 492 | - elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) |
|
| 493 | - fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
| 494 | - elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) |
|
| 495 | - fatal_lang_error('loadavg_unread_disabled', false); |
|
| 504 | + if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) { |
|
| 505 | + fatal_lang_error('loadavg_allunread_disabled', false); |
|
| 506 | + } elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) { |
|
| 507 | + fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
| 508 | + } elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) { |
|
| 509 | + fatal_lang_error('loadavg_unread_disabled', false); |
|
| 510 | + } |
|
| 496 | 511 | |
| 497 | 512 | // Parameters for the main query. |
| 498 | 513 | $query_parameters = array(); |
@@ -505,12 +520,14 @@ discard block |
||
| 505 | 520 | if (!empty($_REQUEST['boards'])) |
| 506 | 521 | { |
| 507 | 522 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 508 | - foreach ($_REQUEST['boards'] as $b) |
|
| 509 | - $boards[] = (int) $b; |
|
| 523 | + foreach ($_REQUEST['boards'] as $b) { |
|
| 524 | + $boards[] = (int) $b; |
|
| 525 | + } |
|
| 510 | 526 | } |
| 511 | 527 | |
| 512 | - if (!empty($board)) |
|
| 513 | - $boards[] = (int) $board; |
|
| 528 | + if (!empty($board)) { |
|
| 529 | + $boards[] = (int) $board; |
|
| 530 | + } |
|
| 514 | 531 | |
| 515 | 532 | // The easiest thing is to just get all the boards they can see, but since we've specified the top of tree we ignore some of them |
| 516 | 533 | $request = $smcFunc['db_query']('', ' |
@@ -527,30 +544,31 @@ discard block |
||
| 527 | 544 | ) |
| 528 | 545 | ); |
| 529 | 546 | |
| 530 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 531 | - if (in_array($row['id_parent'], $boards)) |
|
| 547 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 548 | + if (in_array($row['id_parent'], $boards)) |
|
| 532 | 549 | $boards[] = $row['id_board']; |
| 550 | + } |
|
| 533 | 551 | |
| 534 | 552 | $smcFunc['db_free_result']($request); |
| 535 | 553 | |
| 536 | - if (empty($boards)) |
|
| 537 | - fatal_lang_error('error_no_boards_selected'); |
|
| 554 | + if (empty($boards)) { |
|
| 555 | + fatal_lang_error('error_no_boards_selected'); |
|
| 556 | + } |
|
| 538 | 557 | |
| 539 | 558 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 540 | 559 | $query_parameters['boards'] = $boards; |
| 541 | 560 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d'; |
| 542 | - } |
|
| 543 | - elseif (!empty($board)) |
|
| 561 | + } elseif (!empty($board)) |
|
| 544 | 562 | { |
| 545 | 563 | $query_this_board = 'id_board = {int:board}'; |
| 546 | 564 | $query_parameters['board'] = $board; |
| 547 | 565 | $context['querystring_board_limits'] = ';board=' . $board . '.%1$d'; |
| 548 | - } |
|
| 549 | - elseif (!empty($_REQUEST['boards'])) |
|
| 566 | + } elseif (!empty($_REQUEST['boards'])) |
|
| 550 | 567 | { |
| 551 | 568 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 552 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
| 553 | - $_REQUEST['boards'][$i] = (int) $b; |
|
| 569 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
| 570 | + $_REQUEST['boards'][$i] = (int) $b; |
|
| 571 | + } |
|
| 554 | 572 | |
| 555 | 573 | $request = $smcFunc['db_query']('', ' |
| 556 | 574 | SELECT b.id_board |
@@ -562,22 +580,24 @@ discard block |
||
| 562 | 580 | ) |
| 563 | 581 | ); |
| 564 | 582 | $boards = array(); |
| 565 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 566 | - $boards[] = $row['id_board']; |
|
| 583 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 584 | + $boards[] = $row['id_board']; |
|
| 585 | + } |
|
| 567 | 586 | $smcFunc['db_free_result']($request); |
| 568 | 587 | |
| 569 | - if (empty($boards)) |
|
| 570 | - fatal_lang_error('error_no_boards_selected'); |
|
| 588 | + if (empty($boards)) { |
|
| 589 | + fatal_lang_error('error_no_boards_selected'); |
|
| 590 | + } |
|
| 571 | 591 | |
| 572 | 592 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 573 | 593 | $query_parameters['boards'] = $boards; |
| 574 | 594 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d'; |
| 575 | - } |
|
| 576 | - elseif (!empty($_REQUEST['c'])) |
|
| 595 | + } elseif (!empty($_REQUEST['c'])) |
|
| 577 | 596 | { |
| 578 | 597 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
| 579 | - foreach ($_REQUEST['c'] as $i => $c) |
|
| 580 | - $_REQUEST['c'][$i] = (int) $c; |
|
| 598 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
| 599 | + $_REQUEST['c'][$i] = (int) $c; |
|
| 600 | + } |
|
| 581 | 601 | |
| 582 | 602 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
| 583 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -590,18 +610,19 @@ discard block |
||
| 590 | 610 | ) |
| 591 | 611 | ); |
| 592 | 612 | $boards = array(); |
| 593 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 594 | - $boards[] = $row['id_board']; |
|
| 613 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 614 | + $boards[] = $row['id_board']; |
|
| 615 | + } |
|
| 595 | 616 | $smcFunc['db_free_result']($request); |
| 596 | 617 | |
| 597 | - if (empty($boards)) |
|
| 598 | - fatal_lang_error('error_no_boards_selected'); |
|
| 618 | + if (empty($boards)) { |
|
| 619 | + fatal_lang_error('error_no_boards_selected'); |
|
| 620 | + } |
|
| 599 | 621 | |
| 600 | 622 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 601 | 623 | $query_parameters['boards'] = $boards; |
| 602 | 624 | $context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d'; |
| 603 | - } |
|
| 604 | - else |
|
| 625 | + } else |
|
| 605 | 626 | { |
| 606 | 627 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
| 607 | 628 | // Don't bother to show deleted posts! |
@@ -615,12 +636,14 @@ discard block |
||
| 615 | 636 | ) |
| 616 | 637 | ); |
| 617 | 638 | $boards = array(); |
| 618 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 619 | - $boards[] = $row['id_board']; |
|
| 639 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 640 | + $boards[] = $row['id_board']; |
|
| 641 | + } |
|
| 620 | 642 | $smcFunc['db_free_result']($request); |
| 621 | 643 | |
| 622 | - if (empty($boards)) |
|
| 623 | - fatal_lang_error('error_no_boards_available', false); |
|
| 644 | + if (empty($boards)) { |
|
| 645 | + fatal_lang_error('error_no_boards_available', false); |
|
| 646 | + } |
|
| 624 | 647 | |
| 625 | 648 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 626 | 649 | $query_parameters['boards'] = $boards; |
@@ -682,13 +705,14 @@ discard block |
||
| 682 | 705 | 'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies'] |
| 683 | 706 | ); |
| 684 | 707 | |
| 685 | - if ($context['showing_all_topics']) |
|
| 686 | - $context['linktree'][] = array( |
|
| 708 | + if ($context['showing_all_topics']) { |
|
| 709 | + $context['linktree'][] = array( |
|
| 687 | 710 | 'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], |
| 688 | 711 | 'name' => $txt['unread_topics_all'] |
| 689 | 712 | ); |
| 690 | - else |
|
| 691 | - $txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'])); |
|
| 713 | + } else { |
|
| 714 | + $txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'])); |
|
| 715 | + } |
|
| 692 | 716 | |
| 693 | 717 | loadTemplate('Recent'); |
| 694 | 718 | loadTemplate('MessageIndex'); |
@@ -696,8 +720,9 @@ discard block |
||
| 696 | 720 | |
| 697 | 721 | // Setup the default topic icons... for checking they exist and the like ;) |
| 698 | 722 | $context['icon_sources'] = array(); |
| 699 | - foreach ($context['stable_icons'] as $icon) |
|
| 700 | - $context['icon_sources'][$icon] = 'images_url'; |
|
| 723 | + foreach ($context['stable_icons'] as $icon) { |
|
| 724 | + $context['icon_sources'][$icon] = 'images_url'; |
|
| 725 | + } |
|
| 701 | 726 | |
| 702 | 727 | $is_topics = $_REQUEST['action'] == 'unread'; |
| 703 | 728 | |
@@ -727,8 +752,7 @@ discard block |
||
| 727 | 752 | ); |
| 728 | 753 | list ($earliest_msg) = $smcFunc['db_fetch_row']($request); |
| 729 | 754 | $smcFunc['db_free_result']($request); |
| 730 | - } |
|
| 731 | - else |
|
| 755 | + } else |
|
| 732 | 756 | { |
| 733 | 757 | $request = $smcFunc['db_query']('', ' |
| 734 | 758 | SELECT MIN(lmr.id_msg) |
@@ -744,14 +768,14 @@ discard block |
||
| 744 | 768 | } |
| 745 | 769 | |
| 746 | 770 | // This is needed in case of topics marked unread. |
| 747 | - if (empty($earliest_msg)) |
|
| 748 | - $earliest_msg = 0; |
|
| 749 | - else |
|
| 771 | + if (empty($earliest_msg)) { |
|
| 772 | + $earliest_msg = 0; |
|
| 773 | + } else |
|
| 750 | 774 | { |
| 751 | 775 | // Using caching, when possible, to ignore the below slow query. |
| 752 | - if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) |
|
| 753 | - $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
| 754 | - else |
|
| 776 | + if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) { |
|
| 777 | + $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
| 778 | + } else |
|
| 755 | 779 | { |
| 756 | 780 | // This query is pretty slow, but it's needed to ensure nothing crucial is ignored. |
| 757 | 781 | $request = $smcFunc['db_query']('', ' |
@@ -766,8 +790,9 @@ discard block |
||
| 766 | 790 | $smcFunc['db_free_result']($request); |
| 767 | 791 | |
| 768 | 792 | // In theory this could be zero, if the first ever post is unread, so fudge it ;) |
| 769 | - if ($earliest_msg2 == 0) |
|
| 770 | - $earliest_msg2 = -1; |
|
| 793 | + if ($earliest_msg2 == 0) { |
|
| 794 | + $earliest_msg2 = -1; |
|
| 795 | + } |
|
| 771 | 796 | |
| 772 | 797 | $_SESSION['cached_log_time'] = array(time(), $earliest_msg2); |
| 773 | 798 | } |
@@ -805,9 +830,9 @@ discard block |
||
| 805 | 830 | 'db_error_skip' => true, |
| 806 | 831 | )) |
| 807 | 832 | ) !== false; |
| 833 | + } else { |
|
| 834 | + $have_temp_table = false; |
|
| 808 | 835 | } |
| 809 | - else |
|
| 810 | - $have_temp_table = false; |
|
| 811 | 836 | |
| 812 | 837 | if ($context['showing_all_topics'] && $have_temp_table) |
| 813 | 838 | { |
@@ -853,14 +878,15 @@ discard block |
||
| 853 | 878 | |
| 854 | 879 | $context['topics'] = array(); |
| 855 | 880 | $context['no_topic_listing'] = true; |
| 856 | - if ($context['querystring_board_limits'] == ';start=%1$d') |
|
| 857 | - $context['querystring_board_limits'] = ''; |
|
| 858 | - else |
|
| 859 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 881 | + if ($context['querystring_board_limits'] == ';start=%1$d') { |
|
| 882 | + $context['querystring_board_limits'] = ''; |
|
| 883 | + } else { |
|
| 884 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 885 | + } |
|
| 860 | 886 | return; |
| 887 | + } else { |
|
| 888 | + $min_message = (int) $min_message; |
|
| 861 | 889 | } |
| 862 | - else |
|
| 863 | - $min_message = (int) $min_message; |
|
| 864 | 890 | |
| 865 | 891 | $request = $smcFunc['db_query']('substring', ' |
| 866 | 892 | SELECT ' . $select_clause . ' |
@@ -889,8 +915,7 @@ discard block |
||
| 889 | 915 | 'limit' => $context['topics_per_page'], |
| 890 | 916 | )) |
| 891 | 917 | ); |
| 892 | - } |
|
| 893 | - elseif ($is_topics) |
|
| 918 | + } elseif ($is_topics) |
|
| 894 | 919 | { |
| 895 | 920 | $request = $smcFunc['db_query']('', ' |
| 896 | 921 | SELECT COUNT(*), MIN(t.id_last_msg) |
@@ -941,14 +966,15 @@ discard block |
||
| 941 | 966 | |
| 942 | 967 | $context['topics'] = array(); |
| 943 | 968 | $context['no_topic_listing'] = true; |
| 944 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
| 945 | - $context['querystring_board_limits'] = ''; |
|
| 946 | - else |
|
| 947 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 969 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
| 970 | + $context['querystring_board_limits'] = ''; |
|
| 971 | + } else { |
|
| 972 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 973 | + } |
|
| 948 | 974 | return; |
| 975 | + } else { |
|
| 976 | + $min_message = (int) $min_message; |
|
| 949 | 977 | } |
| 950 | - else |
|
| 951 | - $min_message = (int) $min_message; |
|
| 952 | 978 | |
| 953 | 979 | $request = $smcFunc['db_query']('substring', ' |
| 954 | 980 | SELECT ' . $select_clause . ' |
@@ -978,8 +1004,7 @@ discard block |
||
| 978 | 1004 | 'limit' => $context['topics_per_page'], |
| 979 | 1005 | )) |
| 980 | 1006 | ); |
| 981 | - } |
|
| 982 | - else |
|
| 1007 | + } else |
|
| 983 | 1008 | { |
| 984 | 1009 | if ($modSettings['totalMessages'] > 100000) |
| 985 | 1010 | { |
@@ -1031,8 +1056,8 @@ discard block |
||
| 1031 | 1056 | ) !== false; |
| 1032 | 1057 | |
| 1033 | 1058 | // If that worked, create a sample of the log_topics table too. |
| 1034 | - if ($have_temp_table) |
|
| 1035 | - $have_temp_table = $smcFunc['db_query']('', ' |
|
| 1059 | + if ($have_temp_table) { |
|
| 1060 | + $have_temp_table = $smcFunc['db_query']('', ' |
|
| 1036 | 1061 | CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in ( |
| 1037 | 1062 | PRIMARY KEY (id_topic) |
| 1038 | 1063 | ) |
@@ -1045,6 +1070,7 @@ discard block |
||
| 1045 | 1070 | 'db_error_skip' => true, |
| 1046 | 1071 | ) |
| 1047 | 1072 | ) !== false; |
| 1073 | + } |
|
| 1048 | 1074 | } |
| 1049 | 1075 | |
| 1050 | 1076 | if (!empty($have_temp_table)) |
@@ -1060,8 +1086,7 @@ discard block |
||
| 1060 | 1086 | ); |
| 1061 | 1087 | list ($num_topics) = $smcFunc['db_fetch_row']($request); |
| 1062 | 1088 | $smcFunc['db_free_result']($request); |
| 1063 | - } |
|
| 1064 | - else |
|
| 1089 | + } else |
|
| 1065 | 1090 | { |
| 1066 | 1091 | $request = $smcFunc['db_query']('unread_fetch_topic_count', ' |
| 1067 | 1092 | SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg) |
@@ -1102,15 +1127,16 @@ discard block |
||
| 1102 | 1127 | { |
| 1103 | 1128 | $context['topics'] = array(); |
| 1104 | 1129 | $context['no_topic_listing'] = true; |
| 1105 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
| 1106 | - $context['querystring_board_limits'] = ''; |
|
| 1107 | - else |
|
| 1108 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1130 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
| 1131 | + $context['querystring_board_limits'] = ''; |
|
| 1132 | + } else { |
|
| 1133 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1134 | + } |
|
| 1109 | 1135 | return; |
| 1110 | 1136 | } |
| 1111 | 1137 | |
| 1112 | - if (!empty($have_temp_table)) |
|
| 1113 | - $request = $smcFunc['db_query']('', ' |
|
| 1138 | + if (!empty($have_temp_table)) { |
|
| 1139 | + $request = $smcFunc['db_query']('', ' |
|
| 1114 | 1140 | SELECT t.id_topic |
| 1115 | 1141 | FROM {db_prefix}topics_posted_in AS t |
| 1116 | 1142 | LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic) |
@@ -1124,8 +1150,8 @@ discard block |
||
| 1124 | 1150 | 'limit' => $context['topics_per_page'], |
| 1125 | 1151 | )) |
| 1126 | 1152 | ); |
| 1127 | - else |
|
| 1128 | - $request = $smcFunc['db_query']('', ' |
|
| 1153 | + } else { |
|
| 1154 | + $request = $smcFunc['db_query']('', ' |
|
| 1129 | 1155 | SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].' |
| 1130 | 1156 | FROM {db_prefix}topics AS t |
| 1131 | 1157 | INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : ' |
@@ -1149,10 +1175,12 @@ discard block |
||
| 1149 | 1175 | 'sort' => $_REQUEST['sort'], |
| 1150 | 1176 | )) |
| 1151 | 1177 | ); |
| 1178 | + } |
|
| 1152 | 1179 | |
| 1153 | 1180 | $topics = array(); |
| 1154 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1155 | - $topics[] = $row['id_topic']; |
|
| 1181 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1182 | + $topics[] = $row['id_topic']; |
|
| 1183 | + } |
|
| 1156 | 1184 | $smcFunc['db_free_result']($request); |
| 1157 | 1185 | |
| 1158 | 1186 | // Sanity... where have you gone? |
@@ -1160,10 +1188,11 @@ discard block |
||
| 1160 | 1188 | { |
| 1161 | 1189 | $context['topics'] = array(); |
| 1162 | 1190 | $context['no_topic_listing'] = true; |
| 1163 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
| 1164 | - $context['querystring_board_limits'] = ''; |
|
| 1165 | - else |
|
| 1166 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1191 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
| 1192 | + $context['querystring_board_limits'] = ''; |
|
| 1193 | + } else { |
|
| 1194 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1195 | + } |
|
| 1167 | 1196 | return; |
| 1168 | 1197 | } |
| 1169 | 1198 | |
@@ -1197,8 +1226,9 @@ discard block |
||
| 1197 | 1226 | |
| 1198 | 1227 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1199 | 1228 | { |
| 1200 | - if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
|
| 1201 | - continue; |
|
| 1229 | + if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') { |
|
| 1230 | + continue; |
|
| 1231 | + } |
|
| 1202 | 1232 | |
| 1203 | 1233 | $topic_ids[] = $row['id_topic']; |
| 1204 | 1234 | |
@@ -1206,11 +1236,13 @@ discard block |
||
| 1206 | 1236 | { |
| 1207 | 1237 | // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise. |
| 1208 | 1238 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
| 1209 | - if ($smcFunc['strlen']($row['first_body']) > 128) |
|
| 1210 | - $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
| 1239 | + if ($smcFunc['strlen']($row['first_body']) > 128) { |
|
| 1240 | + $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
| 1241 | + } |
|
| 1211 | 1242 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
| 1212 | - if ($smcFunc['strlen']($row['last_body']) > 128) |
|
| 1213 | - $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
| 1243 | + if ($smcFunc['strlen']($row['last_body']) > 128) { |
|
| 1244 | + $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
| 1245 | + } |
|
| 1214 | 1246 | |
| 1215 | 1247 | // Censor the subject and message preview. |
| 1216 | 1248 | censorText($row['first_subject']); |
@@ -1221,23 +1253,22 @@ discard block |
||
| 1221 | 1253 | { |
| 1222 | 1254 | $row['last_subject'] = $row['first_subject']; |
| 1223 | 1255 | $row['last_body'] = $row['first_body']; |
| 1224 | - } |
|
| 1225 | - else |
|
| 1256 | + } else |
|
| 1226 | 1257 | { |
| 1227 | 1258 | censorText($row['last_subject']); |
| 1228 | 1259 | censorText($row['last_body']); |
| 1229 | 1260 | } |
| 1230 | - } |
|
| 1231 | - else |
|
| 1261 | + } else |
|
| 1232 | 1262 | { |
| 1233 | 1263 | $row['first_body'] = ''; |
| 1234 | 1264 | $row['last_body'] = ''; |
| 1235 | 1265 | censorText($row['first_subject']); |
| 1236 | 1266 | |
| 1237 | - if ($row['id_first_msg'] == $row['id_last_msg']) |
|
| 1238 | - $row['last_subject'] = $row['first_subject']; |
|
| 1239 | - else |
|
| 1240 | - censorText($row['last_subject']); |
|
| 1267 | + if ($row['id_first_msg'] == $row['id_last_msg']) { |
|
| 1268 | + $row['last_subject'] = $row['first_subject']; |
|
| 1269 | + } else { |
|
| 1270 | + censorText($row['last_subject']); |
|
| 1271 | + } |
|
| 1241 | 1272 | } |
| 1242 | 1273 | |
| 1243 | 1274 | // Decide how many pages the topic should have. |
@@ -1249,22 +1280,24 @@ discard block |
||
| 1249 | 1280 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $topic_length, $messages_per_page, true, false); |
| 1250 | 1281 | |
| 1251 | 1282 | // If we can use all, show all. |
| 1252 | - if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) |
|
| 1253 | - $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
| 1283 | + if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) { |
|
| 1284 | + $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
| 1285 | + } |
|
| 1286 | + } else { |
|
| 1287 | + $pages = ''; |
|
| 1254 | 1288 | } |
| 1255 | 1289 | |
| 1256 | - else |
|
| 1257 | - $pages = ''; |
|
| 1258 | - |
|
| 1259 | 1290 | // We need to check the topic icons exist... you can never be too sure! |
| 1260 | 1291 | if (!empty($modSettings['messageIconChecks_enable'])) |
| 1261 | 1292 | { |
| 1262 | 1293 | // First icon first... as you'd expect. |
| 1263 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
| 1264 | - $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1294 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
| 1295 | + $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1296 | + } |
|
| 1265 | 1297 | // Last icon... last... duh. |
| 1266 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
| 1267 | - $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1298 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
| 1299 | + $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1300 | + } |
|
| 1268 | 1301 | } |
| 1269 | 1302 | |
| 1270 | 1303 | // Force the recycling icon if appropriate |
@@ -1278,12 +1311,14 @@ discard block |
||
| 1278 | 1311 | $colorClass = 'windowbg'; |
| 1279 | 1312 | |
| 1280 | 1313 | // Sticky topics should get a different color, too. |
| 1281 | - if ($row['is_sticky']) |
|
| 1282 | - $colorClass .= ' sticky'; |
|
| 1314 | + if ($row['is_sticky']) { |
|
| 1315 | + $colorClass .= ' sticky'; |
|
| 1316 | + } |
|
| 1283 | 1317 | |
| 1284 | 1318 | // Locked topics get special treatment as well. |
| 1285 | - if ($row['locked']) |
|
| 1286 | - $colorClass .= ' locked'; |
|
| 1319 | + if ($row['locked']) { |
|
| 1320 | + $colorClass .= ' locked'; |
|
| 1321 | + } |
|
| 1287 | 1322 | |
| 1288 | 1323 | // And build the array. |
| 1289 | 1324 | $context['topics'][$row['id_topic']] = array( |
@@ -1380,8 +1415,9 @@ discard block |
||
| 1380 | 1415 | ); |
| 1381 | 1416 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1382 | 1417 | { |
| 1383 | - if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) |
|
| 1384 | - $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
| 1418 | + if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) { |
|
| 1419 | + $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
| 1420 | + } |
|
| 1385 | 1421 | } |
| 1386 | 1422 | $smcFunc['db_free_result']($result); |
| 1387 | 1423 | } |
@@ -1396,28 +1432,30 @@ discard block |
||
| 1396 | 1432 | 'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']), |
| 1397 | 1433 | ); |
| 1398 | 1434 | |
| 1399 | - if ($context['showCheckboxes']) |
|
| 1400 | - $context['recent_buttons']['markselectread'] = array( |
|
| 1435 | + if ($context['showCheckboxes']) { |
|
| 1436 | + $context['recent_buttons']['markselectread'] = array( |
|
| 1401 | 1437 | 'text' => 'quick_mod_markread', |
| 1402 | 1438 | 'image' => 'markselectedread.png', |
| 1403 | 1439 | 'url' => 'javascript:document.quickModForm.submit();', |
| 1404 | 1440 | ); |
| 1441 | + } |
|
| 1405 | 1442 | |
| 1406 | - if (!empty($context['topics']) && !$context['showing_all_topics']) |
|
| 1407 | - $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
| 1408 | - } |
|
| 1409 | - elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
| 1443 | + if (!empty($context['topics']) && !$context['showing_all_topics']) { |
|
| 1444 | + $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
| 1445 | + } |
|
| 1446 | + } elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
| 1410 | 1447 | { |
| 1411 | 1448 | $context['recent_buttons'] = array( |
| 1412 | 1449 | 'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']), |
| 1413 | 1450 | ); |
| 1414 | 1451 | |
| 1415 | - if ($context['showCheckboxes']) |
|
| 1416 | - $context['recent_buttons']['markselectread'] = array( |
|
| 1452 | + if ($context['showCheckboxes']) { |
|
| 1453 | + $context['recent_buttons']['markselectread'] = array( |
|
| 1417 | 1454 | 'text' => 'quick_mod_markread', |
| 1418 | 1455 | 'image' => 'markselectedread.png', |
| 1419 | 1456 | 'url' => 'javascript:document.quickModForm.submit();', |
| 1420 | 1457 | ); |
| 1458 | + } |
|
| 1421 | 1459 | } |
| 1422 | 1460 | |
| 1423 | 1461 | // Allow mods to add additional buttons here |
@@ -23,11 +23,13 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | $editor_context = &$context['controls']['richedit'][$editor_id]; |
| 25 | 25 | |
| 26 | - if ($smileyContainer === null) |
|
| 27 | - $editor_context['sce_options']['emoticonsEnabled'] = false; |
|
| 26 | + if ($smileyContainer === null) { |
|
| 27 | + $editor_context['sce_options']['emoticonsEnabled'] = false; |
|
| 28 | + } |
|
| 28 | 29 | |
| 29 | - if ($bbcContainer === null) |
|
| 30 | - $editor_context['sce_options']['toolbar'] = ''; |
|
| 30 | + if ($bbcContainer === null) { |
|
| 31 | + $editor_context['sce_options']['toolbar'] = ''; |
|
| 32 | + } |
|
| 31 | 33 | |
| 32 | 34 | echo ' |
| 33 | 35 | <textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" cols="600" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="', $context['tabindex']++, '" style="width: ', $editor_context['width'], '; height: ', $editor_context['height'], ';', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '"', !empty($context['editor']['required']) ? ' required' : '', '>', $editor_context['value'], '</textarea> |
@@ -40,18 +42,21 @@ discard block |
||
| 40 | 42 | var textarea = $("#', $editor_id, '").get(0); |
| 41 | 43 | sceditor.create(textarea, ', $smcFunc['json_encode']($editor_context['sce_options'], JSON_PRETTY_PRINT), ');'; |
| 42 | 44 | |
| 43 | - if ($editor_context['sce_options']['emoticonsEnabled']) |
|
| 44 | - echo ' |
|
| 45 | + if ($editor_context['sce_options']['emoticonsEnabled']) { |
|
| 46 | + echo ' |
|
| 45 | 47 | sceditor.instance(textarea).createPermanentDropDown();'; |
| 48 | + } |
|
| 46 | 49 | |
| 47 | - if (empty($editor_context['rich_active'])) |
|
| 48 | - echo ' |
|
| 50 | + if (empty($editor_context['rich_active'])) { |
|
| 51 | + echo ' |
|
| 49 | 52 | sceditor.instance(textarea).toggleSourceMode();'; |
| 53 | + } |
|
| 50 | 54 | |
| 51 | - if (isset($context['post_error']['no_message']) || isset($context['post_error']['long_message'])) |
|
| 52 | - echo ' |
|
| 55 | + if (isset($context['post_error']['no_message']) || isset($context['post_error']['long_message'])) { |
|
| 56 | + echo ' |
|
| 53 | 57 | $(".sceditor-container").find("textarea").each(function() {$(this).css({border: "1px solid red"})}); |
| 54 | 58 | $(".sceditor-container").find("iframe").each(function() {$(this).css({border: "1px solid red"})});'; |
| 59 | + } |
|
| 55 | 60 | |
| 56 | 61 | echo ' |
| 57 | 62 | });'; |
@@ -88,42 +93,47 @@ discard block |
||
| 88 | 93 | |
| 89 | 94 | $tempTab = $context['tabindex']; |
| 90 | 95 | |
| 91 | - if (!empty($context['drafts_pm_save'])) |
|
| 92 | - $tempTab++; |
|
| 93 | - elseif (!empty($context['drafts_save'])) |
|
| 94 | - $tempTab++; |
|
| 95 | - elseif ($editor_context['preview_type']) |
|
| 96 | - $tempTab++; |
|
| 97 | - elseif ($context['show_spellchecking']) |
|
| 98 | - $tempTab++; |
|
| 96 | + if (!empty($context['drafts_pm_save'])) { |
|
| 97 | + $tempTab++; |
|
| 98 | + } elseif (!empty($context['drafts_save'])) { |
|
| 99 | + $tempTab++; |
|
| 100 | + } elseif ($editor_context['preview_type']) { |
|
| 101 | + $tempTab++; |
|
| 102 | + } elseif ($context['show_spellchecking']) { |
|
| 103 | + $tempTab++; |
|
| 104 | + } |
|
| 99 | 105 | |
| 100 | 106 | $tempTab++; |
| 101 | 107 | $context['tabindex'] = $tempTab; |
| 102 | 108 | |
| 103 | - if (!empty($context['drafts_pm_save'])) |
|
| 104 | - echo ' |
|
| 109 | + if (!empty($context['drafts_pm_save'])) { |
|
| 110 | + echo ' |
|
| 105 | 111 | <input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="submitThisOnce(this);" accesskey="d" class="button"> |
| 106 | 112 | <input type="hidden" id="id_pm_draft" name="id_pm_draft" value="', empty($context['id_pm_draft']) ? 0 : $context['id_pm_draft'], '">'; |
| 113 | + } |
|
| 107 | 114 | |
| 108 | - if (!empty($context['drafts_save'])) |
|
| 109 | - echo ' |
|
| 115 | + if (!empty($context['drafts_save'])) { |
|
| 116 | + echo ' |
|
| 110 | 117 | <input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="return confirm(' . JavaScriptEscape($txt['draft_save_note']) . ') && submitThisOnce(this);" accesskey="d" class="button"> |
| 111 | 118 | <input type="hidden" id="id_draft" name="id_draft" value="', empty($context['id_draft']) ? 0 : $context['id_draft'], '">'; |
| 119 | + } |
|
| 112 | 120 | |
| 113 | - if ($context['show_spellchecking']) |
|
| 114 | - echo ' |
|
| 121 | + if ($context['show_spellchecking']) { |
|
| 122 | + echo ' |
|
| 115 | 123 | <input type="button" value="', $txt['spell_check'], '" tabindex="', --$tempTab, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button">'; |
| 124 | + } |
|
| 116 | 125 | |
| 117 | - if ($editor_context['preview_type']) |
|
| 118 | - echo ' |
|
| 126 | + if ($editor_context['preview_type']) { |
|
| 127 | + echo ' |
|
| 119 | 128 | <input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', --$tempTab, '" onclick="', $editor_context['preview_type'] == 2 ? 'return event.ctrlKey || previewPost();' : 'return submitThisOnce(this);', '" accesskey="p" class="button">'; |
| 129 | + } |
|
| 120 | 130 | |
| 121 | 131 | echo ' |
| 122 | 132 | <input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" name="post" tabindex="', --$tempTab, '" onclick="return submitThisOnce(this);" accesskey="s" class="button">'; |
| 123 | 133 | |
| 124 | 134 | // Load in the PM autosaver if it's enabled |
| 125 | - if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave'])) |
|
| 126 | - echo ' |
|
| 135 | + if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave'])) { |
|
| 136 | + echo ' |
|
| 127 | 137 | <span class="righttext padding" style="display: block"> |
| 128 | 138 | <span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon"></span> |
| 129 | 139 | <span id="draft_lastautosave" ></span> |
@@ -141,10 +151,11 @@ discard block |
||
| 141 | 151 | iFreq: ', (empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000), ' |
| 142 | 152 | }); |
| 143 | 153 | </script>'; |
| 154 | + } |
|
| 144 | 155 | |
| 145 | 156 | // Start an instance of the auto saver if its enabled |
| 146 | - if (!empty($context['drafts_save']) && !empty($context['drafts_autosave'])) |
|
| 147 | - echo ' |
|
| 157 | + if (!empty($context['drafts_save']) && !empty($context['drafts_autosave'])) { |
|
| 158 | + echo ' |
|
| 148 | 159 | <span class="righttext padding" style="display: block"> |
| 149 | 160 | <span id="throbber" style="display:none"><img src="', $settings['images_url'], '/loading_sm.gif" alt="" class="centericon"></span> |
| 150 | 161 | <span id="draft_lastautosave" ></span> |
@@ -161,7 +172,8 @@ discard block |
||
| 161 | 172 | iFreq: ', $context['drafts_autosave_frequency'], ' |
| 162 | 173 | }); |
| 163 | 174 | </script>'; |
| 164 | -} |
|
| 175 | + } |
|
| 176 | + } |
|
| 165 | 177 | |
| 166 | 178 | /** |
| 167 | 179 | * This template displays a verification form |
@@ -178,51 +190,57 @@ discard block |
||
| 178 | 190 | $verify_context = &$context['controls']['verification'][$verify_id]; |
| 179 | 191 | |
| 180 | 192 | // Keep track of where we are. |
| 181 | - if (empty($verify_context['tracking']) || $reset) |
|
| 182 | - $verify_context['tracking'] = 0; |
|
| 193 | + if (empty($verify_context['tracking']) || $reset) { |
|
| 194 | + $verify_context['tracking'] = 0; |
|
| 195 | + } |
|
| 183 | 196 | |
| 184 | 197 | // How many items are there to display in total. |
| 185 | 198 | $total_items = count($verify_context['questions']) + ($verify_context['show_visual'] || $verify_context['can_recaptcha'] ? 1 : 0); |
| 186 | 199 | |
| 187 | 200 | // If we've gone too far, stop. |
| 188 | - if ($verify_context['tracking'] > $total_items) |
|
| 189 | - return false; |
|
| 201 | + if ($verify_context['tracking'] > $total_items) { |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 190 | 204 | |
| 191 | 205 | // Loop through each item to show them. |
| 192 | 206 | for ($i = 0; $i < $total_items; $i++) |
| 193 | 207 | { |
| 194 | 208 | // If we're after a single item only show it if we're in the right place. |
| 195 | - if ($display_type == 'single' && $verify_context['tracking'] != $i) |
|
| 196 | - continue; |
|
| 209 | + if ($display_type == 'single' && $verify_context['tracking'] != $i) { |
|
| 210 | + continue; |
|
| 211 | + } |
|
| 197 | 212 | |
| 198 | - if ($display_type != 'single') |
|
| 199 | - echo ' |
|
| 213 | + if ($display_type != 'single') { |
|
| 214 | + echo ' |
|
| 200 | 215 | <div id="verification_control_', $i, '" class="verification_control">'; |
| 216 | + } |
|
| 201 | 217 | |
| 202 | 218 | // Display empty field, but only if we have one, and it's the first time. |
| 203 | - if ($verify_context['empty_field'] && empty($i)) |
|
| 204 | - echo ' |
|
| 219 | + if ($verify_context['empty_field'] && empty($i)) { |
|
| 220 | + echo ' |
|
| 205 | 221 | <div class="smalltext vv_special"> |
| 206 | 222 | ', $txt['visual_verification_hidden'], ': |
| 207 | 223 | <input type="text" name="', $_SESSION[$verify_id . '_vv']['empty_field'], '" autocomplete="off" size="30" value=""> |
| 208 | 224 | </div>'; |
| 225 | + } |
|
| 209 | 226 | |
| 210 | 227 | // Do the actual stuff |
| 211 | 228 | if ($i == 0 && ($verify_context['show_visual'] || $verify_context['can_recaptcha'])) |
| 212 | 229 | { |
| 213 | 230 | if ($verify_context['show_visual']) |
| 214 | 231 | { |
| 215 | - if ($context['use_graphic_library']) |
|
| 216 | - echo ' |
|
| 232 | + if ($context['use_graphic_library']) { |
|
| 233 | + echo ' |
|
| 217 | 234 | <img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '">'; |
| 218 | - else |
|
| 219 | - echo ' |
|
| 235 | + } else { |
|
| 236 | + echo ' |
|
| 220 | 237 | <img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1"> |
| 221 | 238 | <img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2"> |
| 222 | 239 | <img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3"> |
| 223 | 240 | <img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4"> |
| 224 | 241 | <img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5"> |
| 225 | 242 | <img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6">'; |
| 243 | + } |
|
| 226 | 244 | |
| 227 | 245 | echo ' |
| 228 | 246 | <div class="smalltext" style="margin: 4px 0 8px 0;"> |
@@ -240,8 +258,7 @@ discard block |
||
| 240 | 258 | <br> |
| 241 | 259 | <script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl='.$lang.'"></script>'; |
| 242 | 260 | } |
| 243 | - } |
|
| 244 | - else |
|
| 261 | + } else |
|
| 245 | 262 | { |
| 246 | 263 | // Where in the question array is this question? |
| 247 | 264 | $qIndex = $verify_context['show_visual'] ? $i - 1 : $i; |
@@ -253,21 +270,24 @@ discard block |
||
| 253 | 270 | </div>'; |
| 254 | 271 | } |
| 255 | 272 | |
| 256 | - if ($display_type != 'single') |
|
| 257 | - echo ' |
|
| 273 | + if ($display_type != 'single') { |
|
| 274 | + echo ' |
|
| 258 | 275 | </div><!-- #verification_control_[i] -->'; |
| 276 | + } |
|
| 259 | 277 | |
| 260 | 278 | // If we were displaying just one and we did it, break. |
| 261 | - if ($display_type == 'single' && $verify_context['tracking'] == $i) |
|
| 262 | - break; |
|
| 279 | + if ($display_type == 'single' && $verify_context['tracking'] == $i) { |
|
| 280 | + break; |
|
| 281 | + } |
|
| 263 | 282 | } |
| 264 | 283 | |
| 265 | 284 | // Assume we found something, always. |
| 266 | 285 | $verify_context['tracking']++; |
| 267 | 286 | |
| 268 | 287 | // Tell something displaying piecemeal to keep going. |
| 269 | - if ($display_type == 'single') |
|
| 270 | - return true; |
|
| 271 | -} |
|
| 288 | + if ($display_type == 'single') { |
|
| 289 | + return true; |
|
| 290 | + } |
|
| 291 | + } |
|
| 272 | 292 | |
| 273 | 293 | ?> |
| 274 | 294 | \ No newline at end of file |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * The main dispatcher; doesn't do anything, just delegates. |
@@ -92,18 +93,19 @@ discard block |
||
| 92 | 93 | checkSession('get'); |
| 93 | 94 | validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request'); |
| 94 | 95 | |
| 95 | - if ($_REQUEST['move_to'] === 'top') |
|
| 96 | - $boardOptions = array( |
|
| 96 | + if ($_REQUEST['move_to'] === 'top') { |
|
| 97 | + $boardOptions = array( |
|
| 97 | 98 | 'move_to' => $_REQUEST['move_to'], |
| 98 | 99 | 'target_category' => (int) $_REQUEST['target_cat'], |
| 99 | 100 | 'move_first_child' => true, |
| 100 | 101 | ); |
| 101 | - else |
|
| 102 | - $boardOptions = array( |
|
| 102 | + } else { |
|
| 103 | + $boardOptions = array( |
|
| 103 | 104 | 'move_to' => $_REQUEST['move_to'], |
| 104 | 105 | 'target_board' => (int) $_REQUEST['target_board'], |
| 105 | 106 | 'move_first_child' => true, |
| 106 | 107 | ); |
| 108 | + } |
|
| 107 | 109 | modifyBoard((int) $_REQUEST['src_board'], $boardOptions); |
| 108 | 110 | } |
| 109 | 111 | |
@@ -148,15 +150,16 @@ discard block |
||
| 148 | 150 | $security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token']; |
| 149 | 151 | foreach ($boardList[$catid] as $boardid) |
| 150 | 152 | { |
| 151 | - if (!isset($context['categories'][$catid]['move_link'])) |
|
| 152 | - $context['categories'][$catid]['move_link'] = array( |
|
| 153 | + if (!isset($context['categories'][$catid]['move_link'])) { |
|
| 154 | + $context['categories'][$catid]['move_link'] = array( |
|
| 153 | 155 | 'child_level' => 0, |
| 154 | 156 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
| 155 | 157 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security, |
| 156 | 158 | ); |
| 159 | + } |
|
| 157 | 160 | |
| 158 | - if (!$context['categories'][$catid]['boards'][$boardid]['move']) |
|
| 159 | - $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
| 161 | + if (!$context['categories'][$catid]['boards'][$boardid]['move']) { |
|
| 162 | + $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
| 160 | 163 | array( |
| 161 | 164 | 'child_level' => $boards[$boardid]['level'], |
| 162 | 165 | 'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
@@ -170,33 +173,38 @@ discard block |
||
| 170 | 173 | 'class' => 'here', |
| 171 | 174 | ), |
| 172 | 175 | ); |
| 176 | + } |
|
| 173 | 177 | |
| 174 | 178 | $difference = $boards[$boardid]['level'] - $prev_child_level; |
| 175 | - if ($difference == 1) |
|
| 176 | - array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
| 177 | - elseif ($difference < 0) |
|
| 179 | + if ($difference == 1) { |
|
| 180 | + array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
| 181 | + } elseif ($difference < 0) |
|
| 178 | 182 | { |
| 179 | - if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
| 180 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
| 181 | - for ($i = 0; $i < -$difference; $i++) |
|
| 182 | - if (($temp = array_pop($stack)) != null) |
|
| 183 | + if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
| 184 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
| 185 | + } |
|
| 186 | + for ($i = 0; $i < -$difference; $i++) { |
|
| 187 | + if (($temp = array_pop($stack)) != null) |
|
| 183 | 188 | array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp); |
| 189 | + } |
|
| 184 | 190 | } |
| 185 | 191 | |
| 186 | 192 | $prev_board = $boardid; |
| 187 | 193 | $prev_child_level = $boards[$boardid]['level']; |
| 188 | 194 | } |
| 189 | - if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
| 190 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
| 191 | - elseif (!empty($stack)) |
|
| 192 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
| 195 | + if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
| 196 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
| 197 | + } elseif (!empty($stack)) { |
|
| 198 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
| 199 | + } |
|
| 193 | 200 | |
| 194 | - if (empty($boardList[$catid])) |
|
| 195 | - $context['categories'][$catid]['move_link'] = array( |
|
| 201 | + if (empty($boardList[$catid])) { |
|
| 202 | + $context['categories'][$catid]['move_link'] = array( |
|
| 196 | 203 | 'child_level' => 0, |
| 197 | 204 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'', |
| 198 | 205 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security, |
| 199 | 206 | ); |
| 207 | + } |
|
| 200 | 208 | } |
| 201 | 209 | } |
| 202 | 210 | |
@@ -252,9 +260,9 @@ discard block |
||
| 252 | 260 | ); |
| 253 | 261 | } |
| 254 | 262 | // Category doesn't exist, man... sorry. |
| 255 | - elseif (!isset($cat_tree[$_REQUEST['cat']])) |
|
| 256 | - redirectexit('action=admin;area=manageboards'); |
|
| 257 | - else |
|
| 263 | + elseif (!isset($cat_tree[$_REQUEST['cat']])) { |
|
| 264 | + redirectexit('action=admin;area=manageboards'); |
|
| 265 | + } else |
|
| 258 | 266 | { |
| 259 | 267 | $context['category'] = array( |
| 260 | 268 | 'id' => $_REQUEST['cat'], |
@@ -266,30 +274,31 @@ discard block |
||
| 266 | 274 | 'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children']) |
| 267 | 275 | ); |
| 268 | 276 | |
| 269 | - foreach ($boardList[$_REQUEST['cat']] as $child_board) |
|
| 270 | - $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
| 277 | + foreach ($boardList[$_REQUEST['cat']] as $child_board) { |
|
| 278 | + $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
| 279 | + } |
|
| 271 | 280 | } |
| 272 | 281 | |
| 273 | 282 | $prevCat = 0; |
| 274 | 283 | foreach ($cat_tree as $catid => $tree) |
| 275 | 284 | { |
| 276 | - if ($catid == $_REQUEST['cat'] && $prevCat > 0) |
|
| 277 | - $context['category_order'][$prevCat]['selected'] = true; |
|
| 278 | - elseif ($catid != $_REQUEST['cat']) |
|
| 279 | - $context['category_order'][$catid] = array( |
|
| 285 | + if ($catid == $_REQUEST['cat'] && $prevCat > 0) { |
|
| 286 | + $context['category_order'][$prevCat]['selected'] = true; |
|
| 287 | + } elseif ($catid != $_REQUEST['cat']) { |
|
| 288 | + $context['category_order'][$catid] = array( |
|
| 280 | 289 | 'id' => $catid, |
| 281 | 290 | 'name' => $txt['mboards_order_after'] . $tree['node']['name'], |
| 282 | 291 | 'selected' => false, |
| 283 | 292 | 'true_name' => $tree['node']['name'] |
| 284 | 293 | ); |
| 294 | + } |
|
| 285 | 295 | $prevCat = $catid; |
| 286 | 296 | } |
| 287 | 297 | if (!isset($_REQUEST['delete'])) |
| 288 | 298 | { |
| 289 | 299 | $context['sub_template'] = 'modify_category'; |
| 290 | 300 | $context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit']; |
| 291 | - } |
|
| 292 | - else |
|
| 301 | + } else |
|
| 293 | 302 | { |
| 294 | 303 | $context['sub_template'] = 'confirm_category_delete'; |
| 295 | 304 | $context['page_title'] = $txt['mboards_delete_cat']; |
@@ -326,8 +335,9 @@ discard block |
||
| 326 | 335 | { |
| 327 | 336 | $catOptions = array(); |
| 328 | 337 | |
| 329 | - if (isset($_POST['cat_order'])) |
|
| 330 | - $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
| 338 | + if (isset($_POST['cat_order'])) { |
|
| 339 | + $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
| 340 | + } |
|
| 331 | 341 | |
| 332 | 342 | // Change "This & That" to "This & That" but don't change "¢" to "&cent;"... |
| 333 | 343 | $catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']); |
@@ -335,10 +345,11 @@ discard block |
||
| 335 | 345 | |
| 336 | 346 | $catOptions['is_collapsible'] = isset($_POST['collapse']); |
| 337 | 347 | |
| 338 | - if (isset($_POST['add'])) |
|
| 339 | - createCategory($catOptions); |
|
| 340 | - else |
|
| 341 | - modifyCategory($_POST['cat'], $catOptions); |
|
| 348 | + if (isset($_POST['add'])) { |
|
| 349 | + createCategory($catOptions); |
|
| 350 | + } else { |
|
| 351 | + modifyCategory($_POST['cat'], $catOptions); |
|
| 352 | + } |
|
| 342 | 353 | } |
| 343 | 354 | // If they want to delete - first give them confirmation. |
| 344 | 355 | elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty'])) |
@@ -352,13 +363,14 @@ discard block |
||
| 352 | 363 | // First off - check if we are moving all the current boards first - before we start deleting! |
| 353 | 364 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
| 354 | 365 | { |
| 355 | - if (empty($_POST['cat_to'])) |
|
| 356 | - fatal_lang_error('mboards_delete_error'); |
|
| 366 | + if (empty($_POST['cat_to'])) { |
|
| 367 | + fatal_lang_error('mboards_delete_error'); |
|
| 368 | + } |
|
| 357 | 369 | |
| 358 | 370 | deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']); |
| 371 | + } else { |
|
| 372 | + deleteCategories(array($_POST['cat'])); |
|
| 359 | 373 | } |
| 360 | - else |
|
| 361 | - deleteCategories(array($_POST['cat'])); |
|
| 362 | 374 | } |
| 363 | 375 | |
| 364 | 376 | redirectexit('action=admin;area=manageboards'); |
@@ -403,8 +415,9 @@ discard block |
||
| 403 | 415 | if ($_REQUEST['sa'] == 'newboard') |
| 404 | 416 | { |
| 405 | 417 | // Category doesn't exist, man... sorry. |
| 406 | - if (empty($_REQUEST['cat'])) |
|
| 407 | - redirectexit('action=admin;area=manageboards'); |
|
| 418 | + if (empty($_REQUEST['cat'])) { |
|
| 419 | + redirectexit('action=admin;area=manageboards'); |
|
| 420 | + } |
|
| 408 | 421 | |
| 409 | 422 | // Some things that need to be setup for a new board. |
| 410 | 423 | $curBoard = array( |
@@ -428,8 +441,7 @@ discard block |
||
| 428 | 441 | 'category' => (int) $_REQUEST['cat'], |
| 429 | 442 | 'no_children' => true, |
| 430 | 443 | ); |
| 431 | - } |
|
| 432 | - else |
|
| 444 | + } else |
|
| 433 | 445 | { |
| 434 | 446 | // Just some easy shortcuts. |
| 435 | 447 | $curBoard = &$boards[$_REQUEST['boardid']]; |
@@ -477,8 +489,9 @@ discard block |
||
| 477 | 489 | ); |
| 478 | 490 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 479 | 491 | { |
| 480 | - if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) |
|
| 481 | - $curBoard['member_groups'][] = $row['id_group']; |
|
| 492 | + if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) { |
|
| 493 | + $curBoard['member_groups'][] = $row['id_group']; |
|
| 494 | + } |
|
| 482 | 495 | |
| 483 | 496 | $context['groups'][(int) $row['id_group']] = array( |
| 484 | 497 | 'id' => $row['id_group'], |
@@ -491,8 +504,9 @@ discard block |
||
| 491 | 504 | $smcFunc['db_free_result']($request); |
| 492 | 505 | |
| 493 | 506 | // Category doesn't exist, man... sorry. |
| 494 | - if (!isset($boardList[$curBoard['category']])) |
|
| 495 | - redirectexit('action=admin;area=manageboards'); |
|
| 507 | + if (!isset($boardList[$curBoard['category']])) { |
|
| 508 | + redirectexit('action=admin;area=manageboards'); |
|
| 509 | + } |
|
| 496 | 510 | |
| 497 | 511 | foreach ($boardList[$curBoard['category']] as $boardid) |
| 498 | 512 | { |
@@ -506,8 +520,7 @@ discard block |
||
| 506 | 520 | 'is_child' => false, |
| 507 | 521 | 'selected' => true |
| 508 | 522 | ); |
| 509 | - } |
|
| 510 | - else |
|
| 523 | + } else |
|
| 511 | 524 | { |
| 512 | 525 | $context['board_order'][] = array( |
| 513 | 526 | 'id' => $boardid, |
@@ -524,19 +537,21 @@ discard block |
||
| 524 | 537 | $context['can_move_children'] = false; |
| 525 | 538 | $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children']; |
| 526 | 539 | |
| 527 | - foreach ($context['board_order'] as $lBoard) |
|
| 528 | - if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
| 540 | + foreach ($context['board_order'] as $lBoard) { |
|
| 541 | + if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
| 529 | 542 | $context['can_move_children'] = true; |
| 543 | + } |
|
| 530 | 544 | } |
| 531 | 545 | |
| 532 | 546 | // Get other available categories. |
| 533 | 547 | $context['categories'] = array(); |
| 534 | - foreach ($cat_tree as $catID => $tree) |
|
| 535 | - $context['categories'][] = array( |
|
| 548 | + foreach ($cat_tree as $catID => $tree) { |
|
| 549 | + $context['categories'][] = array( |
|
| 536 | 550 | 'id' => $catID == $curBoard['category'] ? 0 : $catID, |
| 537 | 551 | 'name' => $tree['node']['name'], |
| 538 | 552 | 'selected' => $catID == $curBoard['category'] |
| 539 | 553 | ); |
| 554 | + } |
|
| 540 | 555 | |
| 541 | 556 | $request = $smcFunc['db_query']('', ' |
| 542 | 557 | SELECT mem.id_member, mem.real_name |
@@ -548,14 +563,16 @@ discard block |
||
| 548 | 563 | ) |
| 549 | 564 | ); |
| 550 | 565 | $context['board']['moderators'] = array(); |
| 551 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 552 | - $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 566 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 567 | + $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 568 | + } |
|
| 553 | 569 | $smcFunc['db_free_result']($request); |
| 554 | 570 | |
| 555 | 571 | $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"'; |
| 556 | 572 | |
| 557 | - if (!empty($context['board']['moderators'])) |
|
| 558 | - list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
| 573 | + if (!empty($context['board']['moderators'])) { |
|
| 574 | + list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
| 575 | + } |
|
| 559 | 576 | |
| 560 | 577 | // Get all the groups assigned as moderators |
| 561 | 578 | $request = $smcFunc['db_query']('', ' |
@@ -567,14 +584,16 @@ discard block |
||
| 567 | 584 | ) |
| 568 | 585 | ); |
| 569 | 586 | $context['board']['moderator_groups'] = array(); |
| 570 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 571 | - $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
| 587 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 588 | + $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
| 589 | + } |
|
| 572 | 590 | $smcFunc['db_free_result']($request); |
| 573 | 591 | |
| 574 | 592 | $context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '"' . implode('", &qout;', $context['board']['moderator_groups']) . '"'; |
| 575 | 593 | |
| 576 | - if (!empty($context['board']['moderator_groups'])) |
|
| 577 | - list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
| 594 | + if (!empty($context['board']['moderator_groups'])) { |
|
| 595 | + list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
| 596 | + } |
|
| 578 | 597 | |
| 579 | 598 | // Get all the themes... |
| 580 | 599 | $request = $smcFunc['db_query']('', ' |
@@ -586,8 +605,9 @@ discard block |
||
| 586 | 605 | ) |
| 587 | 606 | ); |
| 588 | 607 | $context['themes'] = array(); |
| 589 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 590 | - $context['themes'][] = $row; |
|
| 608 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 609 | + $context['themes'][] = $row; |
|
| 610 | + } |
|
| 591 | 611 | $smcFunc['db_free_result']($request); |
| 592 | 612 | |
| 593 | 613 | if (!isset($_REQUEST['delete'])) |
@@ -595,8 +615,7 @@ discard block |
||
| 595 | 615 | $context['sub_template'] = 'modify_board'; |
| 596 | 616 | $context['page_title'] = $txt['boardsEdit']; |
| 597 | 617 | loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); |
| 598 | - } |
|
| 599 | - else |
|
| 618 | + } else |
|
| 600 | 619 | { |
| 601 | 620 | $context['sub_template'] = 'confirm_board_delete'; |
| 602 | 621 | $context['page_title'] = $txt['mboards_delete_board']; |
@@ -640,8 +659,9 @@ discard block |
||
| 640 | 659 | // Change the boardorder of this board? |
| 641 | 660 | elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) |
| 642 | 661 | { |
| 643 | - if (!in_array($_POST['placement'], array('before', 'after', 'child'))) |
|
| 644 | - fatal_lang_error('mangled_post', false); |
|
| 662 | + if (!in_array($_POST['placement'], array('before', 'after', 'child'))) { |
|
| 663 | + fatal_lang_error('mangled_post', false); |
|
| 664 | + } |
|
| 645 | 665 | |
| 646 | 666 | $boardOptions['move_to'] = $_POST['placement']; |
| 647 | 667 | $boardOptions['target_board'] = (int) $_POST['board_order']; |
@@ -654,13 +674,14 @@ discard block |
||
| 654 | 674 | $boardOptions['access_groups'] = array(); |
| 655 | 675 | $boardOptions['deny_groups'] = array(); |
| 656 | 676 | |
| 657 | - if (!empty($_POST['groups'])) |
|
| 658 | - foreach ($_POST['groups'] as $group => $action) |
|
| 677 | + if (!empty($_POST['groups'])) { |
|
| 678 | + foreach ($_POST['groups'] as $group => $action) |
|
| 659 | 679 | { |
| 660 | 680 | if ($action == 'allow') |
| 661 | 681 | $boardOptions['access_groups'][] = (int) $group; |
| 662 | - elseif ($action == 'deny') |
|
| 663 | - $boardOptions['deny_groups'][] = (int) $group; |
|
| 682 | + } elseif ($action == 'deny') { |
|
| 683 | + $boardOptions['deny_groups'][] = (int) $group; |
|
| 684 | + } |
|
| 664 | 685 | } |
| 665 | 686 | |
| 666 | 687 | // People with manage-boards are special. |
@@ -672,8 +693,9 @@ discard block |
||
| 672 | 693 | // Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded. |
| 673 | 694 | $boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers)); |
| 674 | 695 | |
| 675 | - if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) |
|
| 676 | - fatal_lang_error('too_many_groups', false); |
|
| 696 | + if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) { |
|
| 697 | + fatal_lang_error('too_many_groups', false); |
|
| 698 | + } |
|
| 677 | 699 | |
| 678 | 700 | // Do not allow HTML tags. Parse the string. |
| 679 | 701 | $boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']); |
@@ -684,8 +706,9 @@ discard block |
||
| 684 | 706 | if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list'])) |
| 685 | 707 | { |
| 686 | 708 | $moderators = array(); |
| 687 | - foreach ($_POST['moderator_list'] as $moderator) |
|
| 688 | - $moderators[(int) $moderator] = (int) $moderator; |
|
| 709 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
| 710 | + $moderators[(int) $moderator] = (int) $moderator; |
|
| 711 | + } |
|
| 689 | 712 | $boardOptions['moderators'] = $moderators; |
| 690 | 713 | } |
| 691 | 714 | |
@@ -694,8 +717,9 @@ discard block |
||
| 694 | 717 | if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list'])) |
| 695 | 718 | { |
| 696 | 719 | $moderator_groups = array(); |
| 697 | - foreach ($_POST['moderator_group_list'] as $moderator_group) |
|
| 698 | - $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
| 720 | + foreach ($_POST['moderator_group_list'] as $moderator_group) { |
|
| 721 | + $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
| 722 | + } |
|
| 699 | 723 | $boardOptions['moderator_groups'] = $moderator_groups; |
| 700 | 724 | } |
| 701 | 725 | |
@@ -721,56 +745,62 @@ discard block |
||
| 721 | 745 | $smcFunc['db_free_result']($request); |
| 722 | 746 | |
| 723 | 747 | // If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board. |
| 724 | - if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) |
|
| 725 | - unset($boardOptions['redirect']); |
|
| 748 | + if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) { |
|
| 749 | + unset($boardOptions['redirect']); |
|
| 750 | + } |
|
| 726 | 751 | // Reset the redirection count when switching on/off. |
| 727 | - elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) |
|
| 728 | - $boardOptions['num_posts'] = 0; |
|
| 752 | + elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) { |
|
| 753 | + $boardOptions['num_posts'] = 0; |
|
| 754 | + } |
|
| 729 | 755 | // Resetting the count? |
| 730 | - elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) |
|
| 731 | - $boardOptions['num_posts'] = 0; |
|
| 756 | + elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) { |
|
| 757 | + $boardOptions['num_posts'] = 0; |
|
| 758 | + } |
|
| 732 | 759 | } |
| 733 | 760 | |
| 734 | 761 | // Create a new board... |
| 735 | 762 | if (isset($_POST['add'])) |
| 736 | 763 | { |
| 737 | 764 | // New boards by default go to the bottom of the category. |
| 738 | - if (empty($_POST['new_cat'])) |
|
| 739 | - $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
| 740 | - if (!isset($boardOptions['move_to'])) |
|
| 741 | - $boardOptions['move_to'] = 'bottom'; |
|
| 765 | + if (empty($_POST['new_cat'])) { |
|
| 766 | + $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
| 767 | + } |
|
| 768 | + if (!isset($boardOptions['move_to'])) { |
|
| 769 | + $boardOptions['move_to'] = 'bottom'; |
|
| 770 | + } |
|
| 742 | 771 | |
| 743 | 772 | createBoard($boardOptions); |
| 744 | 773 | } |
| 745 | 774 | |
| 746 | 775 | // ...or update an existing board. |
| 747 | - else |
|
| 748 | - modifyBoard($_POST['boardid'], $boardOptions); |
|
| 749 | - } |
|
| 750 | - elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
| 776 | + else { |
|
| 777 | + modifyBoard($_POST['boardid'], $boardOptions); |
|
| 778 | + } |
|
| 779 | + } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
| 751 | 780 | { |
| 752 | 781 | EditBoard(); |
| 753 | 782 | return; |
| 754 | - } |
|
| 755 | - elseif (isset($_POST['delete'])) |
|
| 783 | + } elseif (isset($_POST['delete'])) |
|
| 756 | 784 | { |
| 757 | 785 | // First off - check if we are moving all the current child boards first - before we start deleting! |
| 758 | 786 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
| 759 | 787 | { |
| 760 | - if (empty($_POST['board_to'])) |
|
| 761 | - fatal_lang_error('mboards_delete_board_error'); |
|
| 788 | + if (empty($_POST['board_to'])) { |
|
| 789 | + fatal_lang_error('mboards_delete_board_error'); |
|
| 790 | + } |
|
| 762 | 791 | |
| 763 | 792 | deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']); |
| 793 | + } else { |
|
| 794 | + deleteBoards(array($_POST['boardid']), 0); |
|
| 764 | 795 | } |
| 765 | - else |
|
| 766 | - deleteBoards(array($_POST['boardid']), 0); |
|
| 767 | 796 | } |
| 768 | 797 | |
| 769 | - if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') |
|
| 770 | - redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 771 | - else |
|
| 772 | - redirectexit('action=admin;area=manageboards'); |
|
| 773 | -} |
|
| 798 | + if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') { |
|
| 799 | + redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 800 | + } else { |
|
| 801 | + redirectexit('action=admin;area=manageboards'); |
|
| 802 | + } |
|
| 803 | + } |
|
| 774 | 804 | |
| 775 | 805 | /** |
| 776 | 806 | * Used to retrieve data for modifying a board category |
@@ -807,8 +837,9 @@ discard block |
||
| 807 | 837 | $smcFunc['db_free_result']($request); |
| 808 | 838 | |
| 809 | 839 | // This would probably never happen, but just to be sure. |
| 810 | - if ($cat .= $allowed_sa[1]) |
|
| 811 | - die(str_replace(',', ' to', $cat)); |
|
| 840 | + if ($cat .= $allowed_sa[1]) { |
|
| 841 | + die(str_replace(',', ' to', $cat)); |
|
| 842 | + } |
|
| 812 | 843 | |
| 813 | 844 | redirectexit(); |
| 814 | 845 | } |
@@ -834,8 +865,9 @@ discard block |
||
| 834 | 865 | 'empty_string' => '', |
| 835 | 866 | ) |
| 836 | 867 | ); |
| 837 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 838 | - $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
| 868 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 869 | + $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
| 870 | + } |
|
| 839 | 871 | $smcFunc['db_free_result']($request); |
| 840 | 872 | |
| 841 | 873 | if (!empty($recycle_boards)) |
@@ -843,13 +875,14 @@ discard block |
||
| 843 | 875 | require_once($sourcedir . '/Subs-Boards.php'); |
| 844 | 876 | sortBoards($recycle_boards); |
| 845 | 877 | $recycle_boards = array('') + $recycle_boards; |
| 878 | + } else { |
|
| 879 | + $recycle_boards = array(''); |
|
| 846 | 880 | } |
| 847 | - else |
|
| 848 | - $recycle_boards = array(''); |
|
| 849 | 881 | |
| 850 | 882 | // If this setting is missing, set it to 1 |
| 851 | - if (empty($modSettings['boardindex_max_depth'])) |
|
| 852 | - $modSettings['boardindex_max_depth'] = 1; |
|
| 883 | + if (empty($modSettings['boardindex_max_depth'])) { |
|
| 884 | + $modSettings['boardindex_max_depth'] = 1; |
|
| 885 | + } |
|
| 853 | 886 | |
| 854 | 887 | // Here and the board settings... |
| 855 | 888 | $config_vars = array( |
@@ -868,8 +901,9 @@ discard block |
||
| 868 | 901 | |
| 869 | 902 | call_integration_hook('integrate_modify_board_settings', array(&$config_vars)); |
| 870 | 903 | |
| 871 | - if ($return_config) |
|
| 872 | - return $config_vars; |
|
| 904 | + if ($return_config) { |
|
| 905 | + return $config_vars; |
|
| 906 | + } |
|
| 873 | 907 | |
| 874 | 908 | // Needed for the settings template. |
| 875 | 909 | require_once($sourcedir . '/ManageServer.php'); |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Fetches a list of boards and (optional) categories including |
@@ -37,15 +38,17 @@ discard block |
||
| 37 | 38 | require_once($sourcedir . '/Subs-Boards.php'); |
| 38 | 39 | |
| 39 | 40 | // For performance, track the latest post while going through the boards. |
| 40 | - if (!empty($boardIndexOptions['set_latest_post'])) |
|
| 41 | - $latest_post = array( |
|
| 41 | + if (!empty($boardIndexOptions['set_latest_post'])) { |
|
| 42 | + $latest_post = array( |
|
| 42 | 43 | 'timestamp' => 0, |
| 43 | 44 | 'ref' => 0, |
| 44 | 45 | ); |
| 46 | + } |
|
| 45 | 47 | |
| 46 | 48 | // This setting is not allowed to be empty |
| 47 | - if (empty($modSettings['boardindex_max_depth'])) |
|
| 48 | - $modSettings['boardindex_max_depth'] = 1; |
|
| 49 | + if (empty($modSettings['boardindex_max_depth'])) { |
|
| 50 | + $modSettings['boardindex_max_depth'] = 1; |
|
| 51 | + } |
|
| 49 | 52 | |
| 50 | 53 | // Find all boards and categories, as well as related information. This will be sorted by the natural order of boards and categories, which we control. |
| 51 | 54 | $result_boards = $smcFunc['db_query']('', ' |
@@ -78,16 +81,18 @@ discard block |
||
| 78 | 81 | ); |
| 79 | 82 | |
| 80 | 83 | // Start with an empty array. |
| 81 | - if ($boardIndexOptions['include_categories']) |
|
| 82 | - $categories = array(); |
|
| 83 | - else |
|
| 84 | - $this_category = array(); |
|
| 84 | + if ($boardIndexOptions['include_categories']) { |
|
| 85 | + $categories = array(); |
|
| 86 | + } else { |
|
| 87 | + $this_category = array(); |
|
| 88 | + } |
|
| 85 | 89 | $boards = array(); |
| 86 | 90 | |
| 87 | 91 | // Children can affect parents, so we need to gather all the boards first and then process them after. |
| 88 | 92 | $row_boards = array(); |
| 89 | - while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) |
|
| 90 | - $row_boards[$row_board['id_board']] = $row_board; |
|
| 93 | + while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) { |
|
| 94 | + $row_boards[$row_board['id_board']] = $row_board; |
|
| 95 | + } |
|
| 91 | 96 | $smcFunc['db_free_result']($result_boards); |
| 92 | 97 | |
| 93 | 98 | // Run through the categories and boards (or only boards).... |
@@ -100,8 +105,9 @@ discard block |
||
| 100 | 105 | $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0'; |
| 101 | 106 | |
| 102 | 107 | // Add parent boards to the $boards list later used to fetch moderators |
| 103 | - if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) |
|
| 104 | - $boards[] = $row_board['id_board']; |
|
| 108 | + if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) { |
|
| 109 | + $boards[] = $row_board['id_board']; |
|
| 110 | + } |
|
| 105 | 111 | |
| 106 | 112 | if ($boardIndexOptions['include_categories']) |
| 107 | 113 | { |
@@ -123,8 +129,9 @@ discard block |
||
| 123 | 129 | } |
| 124 | 130 | |
| 125 | 131 | // If this board has new posts in it (and isn't the recycle bin!) then the category is new. |
| 126 | - if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) |
|
| 127 | - $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']); |
|
| 132 | + if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) { |
|
| 133 | + $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']); |
|
| 134 | + } |
|
| 128 | 135 | |
| 129 | 136 | // Avoid showing category unread link where it only has redirection boards. |
| 130 | 137 | $categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect']; |
@@ -143,8 +150,9 @@ discard block |
||
| 143 | 150 | $isChild = false; |
| 144 | 151 | |
| 145 | 152 | // We might or might not have already added this board, so... |
| 146 | - if (!isset($this_category[$row_board['id_board']])) |
|
| 147 | - $this_category[$row_board['id_board']] = array(); |
|
| 153 | + if (!isset($this_category[$row_board['id_board']])) { |
|
| 154 | + $this_category[$row_board['id_board']] = array(); |
|
| 155 | + } |
|
| 148 | 156 | |
| 149 | 157 | $this_category[$row_board['id_board']] += array( |
| 150 | 158 | 'new' => empty($row_board['is_read']), |
@@ -177,14 +185,12 @@ discard block |
||
| 177 | 185 | { |
| 178 | 186 | $this_category[$row_board['id_board']]['board_class'] = 'redirect'; |
| 179 | 187 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board']; |
| 180 | - } |
|
| 181 | - elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
| 188 | + } elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
| 182 | 189 | { |
| 183 | 190 | // If we're showing to guests, we want to give them the idea that something interesting is going on! |
| 184 | 191 | $this_category[$row_board['id_board']]['board_class'] = 'on'; |
| 185 | 192 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts']; |
| 186 | - } |
|
| 187 | - else |
|
| 193 | + } else |
|
| 188 | 194 | { |
| 189 | 195 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts']; |
| 190 | 196 | } |
@@ -196,12 +202,13 @@ discard block |
||
| 196 | 202 | $isChild = true; |
| 197 | 203 | |
| 198 | 204 | // Ensure the parent has at least the most important info defined |
| 199 | - if (!isset($this_category[$row_board['id_parent']])) |
|
| 200 | - $this_category[$row_board['id_parent']] = array( |
|
| 205 | + if (!isset($this_category[$row_board['id_parent']])) { |
|
| 206 | + $this_category[$row_board['id_parent']] = array( |
|
| 201 | 207 | 'children' => array(), |
| 202 | 208 | 'children_new' => false, |
| 203 | 209 | 'board_class' => 'off', |
| 204 | 210 | ); |
| 211 | + } |
|
| 205 | 212 | |
| 206 | 213 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array( |
| 207 | 214 | 'id' => $row_board['id_board'], |
@@ -245,8 +252,9 @@ discard block |
||
| 245 | 252 | // Propagate some values to the parent board |
| 246 | 253 | if (isset($row_boards[$row_board['id_parent']])) |
| 247 | 254 | { |
| 248 | - if (empty($row_board['is_read'])) |
|
| 249 | - $row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read']; |
|
| 255 | + if (empty($row_board['is_read'])) { |
|
| 256 | + $row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read']; |
|
| 257 | + } |
|
| 250 | 258 | |
| 251 | 259 | if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect']) |
| 252 | 260 | { |
@@ -277,12 +285,13 @@ discard block |
||
| 277 | 285 | 'topic' => $row_board['id_topic'] |
| 278 | 286 | ); |
| 279 | 287 | |
| 280 | - if (!empty($settings['avatars_on_boardIndex'])) |
|
| 281 | - $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
| 288 | + if (!empty($settings['avatars_on_boardIndex'])) { |
|
| 289 | + $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
| 282 | 290 | 'avatar' => $row_board['avatar'], |
| 283 | 291 | 'email' => $row_board['email_address'], |
| 284 | 292 | 'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '', |
| 285 | 293 | )); |
| 294 | + } |
|
| 286 | 295 | |
| 287 | 296 | // Provide the href and link. |
| 288 | 297 | if ($row_board['subject'] != '') |
@@ -294,8 +303,7 @@ discard block |
||
| 294 | 303 | link, href, subject, start (where they should go for the first unread post.), |
| 295 | 304 | and member. (which has id, name, link, href, username in it.) */ |
| 296 | 305 | $this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']); |
| 297 | - } |
|
| 298 | - else |
|
| 306 | + } else |
|
| 299 | 307 | { |
| 300 | 308 | $this_last_post['href'] = ''; |
| 301 | 309 | $this_last_post['link'] = $txt['not_applicable']; |
@@ -303,18 +311,21 @@ discard block |
||
| 303 | 311 | } |
| 304 | 312 | |
| 305 | 313 | // Set the last post in the parent board. |
| 306 | - if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time']))) |
|
| 307 | - $this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post; |
|
| 314 | + if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time']))) { |
|
| 315 | + $this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post; |
|
| 316 | + } |
|
| 308 | 317 | // Just in the child...? |
| 309 | - if ($isChild) |
|
| 310 | - $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 318 | + if ($isChild) { |
|
| 319 | + $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 320 | + } |
|
| 311 | 321 | |
| 312 | 322 | // Determine a global most recent topic. |
| 313 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) |
|
| 314 | - $latest_post = array( |
|
| 323 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) { |
|
| 324 | + $latest_post = array( |
|
| 315 | 325 | 'timestamp' => $row_board['poster_time'], |
| 316 | 326 | 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'], |
| 317 | 327 | ); |
| 328 | + } |
|
| 318 | 329 | } |
| 319 | 330 | |
| 320 | 331 | // Fetch the board's moderators and moderator groups |
@@ -330,8 +341,9 @@ discard block |
||
| 330 | 341 | if (!empty($moderators[$board['id']])) |
| 331 | 342 | { |
| 332 | 343 | $categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']]; |
| 333 | - foreach ($moderators[$board['id']] as $moderator) |
|
| 334 | - $categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link']; |
|
| 344 | + foreach ($moderators[$board['id']] as $moderator) { |
|
| 345 | + $categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link']; |
|
| 346 | + } |
|
| 335 | 347 | } |
| 336 | 348 | if (!empty($groups[$board['id']])) |
| 337 | 349 | { |
@@ -344,16 +356,16 @@ discard block |
||
| 344 | 356 | } |
| 345 | 357 | } |
| 346 | 358 | } |
| 347 | - } |
|
| 348 | - else |
|
| 359 | + } else |
|
| 349 | 360 | { |
| 350 | 361 | foreach ($this_category as $k => $board) |
| 351 | 362 | { |
| 352 | 363 | if (!empty($moderators[$board['id']])) |
| 353 | 364 | { |
| 354 | 365 | $this_category[$k]['moderators'] = $moderators[$board['id']]; |
| 355 | - foreach ($moderators[$board['id']] as $moderator) |
|
| 356 | - $this_category[$k]['link_moderators'][] = $moderator['link']; |
|
| 366 | + foreach ($moderators[$board['id']] as $moderator) { |
|
| 367 | + $this_category[$k]['link_moderators'][] = $moderator['link']; |
|
| 368 | + } |
|
| 357 | 369 | } |
| 358 | 370 | if (!empty($groups[$board['id']])) |
| 359 | 371 | { |
@@ -367,20 +379,23 @@ discard block |
||
| 367 | 379 | } |
| 368 | 380 | } |
| 369 | 381 | |
| 370 | - if ($boardIndexOptions['include_categories']) |
|
| 371 | - sortCategories($categories); |
|
| 372 | - else |
|
| 373 | - sortBoards($this_category); |
|
| 382 | + if ($boardIndexOptions['include_categories']) { |
|
| 383 | + sortCategories($categories); |
|
| 384 | + } else { |
|
| 385 | + sortBoards($this_category); |
|
| 386 | + } |
|
| 374 | 387 | |
| 375 | 388 | // By now we should know the most recent post...if we wanna know it that is. |
| 376 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) |
|
| 377 | - $context['latest_post'] = $latest_post['ref']; |
|
| 389 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) { |
|
| 390 | + $context['latest_post'] = $latest_post['ref']; |
|
| 391 | + } |
|
| 378 | 392 | |
| 379 | 393 | // I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea. |
| 380 | - if ($boardIndexOptions['include_categories']) |
|
| 381 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
| 382 | - else |
|
| 383 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
| 394 | + if ($boardIndexOptions['include_categories']) { |
|
| 395 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
| 396 | + } else { |
|
| 397 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
| 398 | + } |
|
| 384 | 399 | |
| 385 | 400 | return $boardIndexOptions['include_categories'] ? $categories : $this_category; |
| 386 | 401 | } |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | * @version 2.1 Beta 4 |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | -if (!defined('SMF')) |
|
| 20 | +if (!defined('SMF')) { |
|
| 21 | 21 | die('No direct access...'); |
| 22 | +} |
|
| 22 | 23 | |
| 23 | 24 | /** |
| 24 | 25 | * Attempt to start the session, unless it already has been. |
@@ -38,8 +39,9 @@ discard block |
||
| 38 | 39 | { |
| 39 | 40 | $parsed_url = parse_url($boardurl); |
| 40 | 41 | |
| 41 | - if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
| 42 | - @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
| 42 | + if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
| 43 | + @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
| 44 | + } |
|
| 43 | 45 | } |
| 44 | 46 | // @todo Set the session cookie path? |
| 45 | 47 | |
@@ -47,8 +49,9 @@ discard block |
||
| 47 | 49 | if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') |
| 48 | 50 | { |
| 49 | 51 | // Attempt to end the already-started session. |
| 50 | - if (ini_get('session.auto_start') == 1) |
|
| 51 | - session_write_close(); |
|
| 52 | + if (ini_get('session.auto_start') == 1) { |
|
| 53 | + session_write_close(); |
|
| 54 | + } |
|
| 52 | 55 | |
| 53 | 56 | // This is here to stop people from using bad junky PHPSESSIDs. |
| 54 | 57 | if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()])) |
@@ -63,23 +66,26 @@ discard block |
||
| 63 | 66 | if (!empty($modSettings['databaseSession_enable'])) |
| 64 | 67 | { |
| 65 | 68 | @ini_set('session.serialize_handler', 'php_serialize'); |
| 66 | - if (ini_get('session.serialize_handler') != 'php_serialize') |
|
| 67 | - @ini_set('session.serialize_handler', 'php'); |
|
| 69 | + if (ini_get('session.serialize_handler') != 'php_serialize') { |
|
| 70 | + @ini_set('session.serialize_handler', 'php'); |
|
| 71 | + } |
|
| 68 | 72 | session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); |
| 69 | 73 | @ini_set('session.gc_probability', '1'); |
| 74 | + } elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) { |
|
| 75 | + @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
| 70 | 76 | } |
| 71 | - elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) |
|
| 72 | - @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
| 73 | 77 | |
| 74 | 78 | // Use cache setting sessions? |
| 75 | - if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') |
|
| 76 | - call_integration_hook('integrate_session_handlers'); |
|
| 79 | + if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') { |
|
| 80 | + call_integration_hook('integrate_session_handlers'); |
|
| 81 | + } |
|
| 77 | 82 | |
| 78 | 83 | session_start(); |
| 79 | 84 | |
| 80 | 85 | // Change it so the cache settings are a little looser than default. |
| 81 | - if (!empty($modSettings['databaseSession_loose'])) |
|
| 82 | - header('cache-control: private'); |
|
| 86 | + if (!empty($modSettings['databaseSession_loose'])) { |
|
| 87 | + header('cache-control: private'); |
|
| 88 | + } |
|
| 83 | 89 | } |
| 84 | 90 | |
| 85 | 91 | // Set the randomly generated code. |
@@ -125,8 +131,9 @@ discard block |
||
| 125 | 131 | { |
| 126 | 132 | global $smcFunc; |
| 127 | 133 | |
| 128 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
| 129 | - return ''; |
|
| 134 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
| 135 | + return ''; |
|
| 136 | + } |
|
| 130 | 137 | |
| 131 | 138 | // Look for it in the database. |
| 132 | 139 | $result = $smcFunc['db_query']('', ' |
@@ -156,8 +163,9 @@ discard block |
||
| 156 | 163 | global $smcFunc, $db_connection, $db_server, $db_name, $db_user, $db_passwd; |
| 157 | 164 | global $db_prefix, $db_persist, $db_port, $db_mb4; |
| 158 | 165 | |
| 159 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
| 160 | - return false; |
|
| 166 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 161 | 169 | |
| 162 | 170 | // php < 7.0 need this |
| 163 | 171 | if (empty($db_connection)) |
@@ -165,11 +173,13 @@ discard block |
||
| 165 | 173 | $db_options = array(); |
| 166 | 174 | |
| 167 | 175 | // Add in the port if needed |
| 168 | - if (!empty($db_port)) |
|
| 169 | - $db_options['port'] = $db_port; |
|
| 176 | + if (!empty($db_port)) { |
|
| 177 | + $db_options['port'] = $db_port; |
|
| 178 | + } |
|
| 170 | 179 | |
| 171 | - if (!empty($db_mb4)) |
|
| 172 | - $db_options['db_mb4'] = $db_mb4; |
|
| 180 | + if (!empty($db_mb4)) { |
|
| 181 | + $db_options['db_mb4'] = $db_mb4; |
|
| 182 | + } |
|
| 173 | 183 | |
| 174 | 184 | $options = array_merge($db_options, array('persist' => $db_persist, 'dont_select_db' => SMF == 'SSI')); |
| 175 | 185 | |
@@ -189,13 +199,14 @@ discard block |
||
| 189 | 199 | ); |
| 190 | 200 | |
| 191 | 201 | // If that didn't work, try inserting a new one. |
| 192 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 193 | - $smcFunc['db_insert']('ignore', |
|
| 202 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 203 | + $smcFunc['db_insert']('ignore', |
|
| 194 | 204 | '{db_prefix}sessions', |
| 195 | 205 | array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'), |
| 196 | 206 | array($session_id, $data, time()), |
| 197 | 207 | array('session_id') |
| 198 | 208 | ); |
| 209 | + } |
|
| 199 | 210 | |
| 200 | 211 | return ($smcFunc['db_affected_rows']() == 0 ? false : true); |
| 201 | 212 | } |
@@ -210,8 +221,9 @@ discard block |
||
| 210 | 221 | { |
| 211 | 222 | global $smcFunc; |
| 212 | 223 | |
| 213 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
| 214 | - return false; |
|
| 224 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 215 | 227 | |
| 216 | 228 | // Just delete the row... |
| 217 | 229 | $smcFunc['db_query']('', ' |
@@ -237,8 +249,9 @@ discard block |
||
| 237 | 249 | global $modSettings, $smcFunc; |
| 238 | 250 | |
| 239 | 251 | // Just set to the default or lower? Ignore it for a higher value. (hopefully) |
| 240 | - if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) |
|
| 241 | - $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
| 252 | + if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) { |
|
| 253 | + $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
| 254 | + } |
|
| 242 | 255 | |
| 243 | 256 | // Clean up after yerself ;). |
| 244 | 257 | $smcFunc['db_query']('', ' |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
| 33 | 34 | global $smcFunc; |
| 34 | 35 | |
| 35 | 36 | // Map some database specific functions, only do this once. |
| 36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
| 38 | + $smcFunc += array( |
|
| 38 | 39 | 'db_query' => 'smf_db_query', |
| 39 | 40 | 'db_quote' => 'smf_db_quote', |
| 40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -64,13 +65,16 @@ discard block |
||
| 64 | 65 | 'db_custom_order' => 'smf_db_custom_order', |
| 65 | 66 | 'db_native_replace' => 'smf_db_native_replace', |
| 66 | 67 | ); |
| 68 | + } |
|
| 67 | 69 | |
| 68 | - if (!empty($db_options['persist'])) |
|
| 69 | - $db_server = 'p:' . $db_server; |
|
| 70 | + if (!empty($db_options['persist'])) { |
|
| 71 | + $db_server = 'p:' . $db_server; |
|
| 72 | + } |
|
| 70 | 73 | |
| 71 | 74 | // We are not going to make it very far without these. |
| 72 | - if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) |
|
| 73 | - display_db_error(); |
|
| 75 | + if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) { |
|
| 76 | + display_db_error(); |
|
| 77 | + } |
|
| 74 | 78 | |
| 75 | 79 | $connection = mysqli_init(); |
| 76 | 80 | |
@@ -80,29 +84,33 @@ discard block |
||
| 80 | 84 | |
| 81 | 85 | if ($connection) |
| 82 | 86 | { |
| 83 | - if (!empty($db_options['port'])) |
|
| 84 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
| 85 | - else |
|
| 86 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
| 87 | + if (!empty($db_options['port'])) { |
|
| 88 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
| 89 | + } else { |
|
| 90 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
| 91 | + } |
|
| 87 | 92 | } |
| 88 | 93 | |
| 89 | 94 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 90 | 95 | if ($success === false) |
| 91 | 96 | { |
| 92 | - if (!empty($db_options['non_fatal'])) |
|
| 93 | - return null; |
|
| 94 | - else |
|
| 95 | - display_db_error(); |
|
| 97 | + if (!empty($db_options['non_fatal'])) { |
|
| 98 | + return null; |
|
| 99 | + } else { |
|
| 100 | + display_db_error(); |
|
| 101 | + } |
|
| 96 | 102 | } |
| 97 | 103 | |
| 98 | 104 | // Select the database, unless told not to |
| 99 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
| 100 | - display_db_error(); |
|
| 105 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
| 106 | + display_db_error(); |
|
| 107 | + } |
|
| 101 | 108 | |
| 102 | 109 | mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\''); |
| 103 | 110 | |
| 104 | - if (!empty($db_options['db_mb4'])) |
|
| 105 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
| 111 | + if (!empty($db_options['db_mb4'])) { |
|
| 112 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
| 113 | + } |
|
| 106 | 114 | |
| 107 | 115 | return $connection; |
| 108 | 116 | } |
@@ -173,34 +181,42 @@ discard block |
||
| 173 | 181 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
| 174 | 182 | |
| 175 | 183 | list ($values, $connection) = $db_callback; |
| 176 | - if (!is_object($connection)) |
|
| 177 | - display_db_error(); |
|
| 184 | + if (!is_object($connection)) { |
|
| 185 | + display_db_error(); |
|
| 186 | + } |
|
| 178 | 187 | |
| 179 | - if ($matches[1] === 'db_prefix') |
|
| 180 | - return $db_prefix; |
|
| 188 | + if ($matches[1] === 'db_prefix') { |
|
| 189 | + return $db_prefix; |
|
| 190 | + } |
|
| 181 | 191 | |
| 182 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
| 183 | - return $user_info[$matches[1]]; |
|
| 192 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
| 193 | + return $user_info[$matches[1]]; |
|
| 194 | + } |
|
| 184 | 195 | |
| 185 | - if ($matches[1] === 'empty') |
|
| 186 | - return '\'\''; |
|
| 196 | + if ($matches[1] === 'empty') { |
|
| 197 | + return '\'\''; |
|
| 198 | + } |
|
| 187 | 199 | |
| 188 | - if (!isset($matches[2])) |
|
| 189 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 200 | + if (!isset($matches[2])) { |
|
| 201 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 202 | + } |
|
| 190 | 203 | |
| 191 | - if ($matches[1] === 'literal') |
|
| 192 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 204 | + if ($matches[1] === 'literal') { |
|
| 205 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 206 | + } |
|
| 193 | 207 | |
| 194 | - if (!isset($values[$matches[2]])) |
|
| 195 | - 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__); |
|
| 208 | + if (!isset($values[$matches[2]])) { |
|
| 209 | + 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__); |
|
| 210 | + } |
|
| 196 | 211 | |
| 197 | 212 | $replacement = $values[$matches[2]]; |
| 198 | 213 | |
| 199 | 214 | switch ($matches[1]) |
| 200 | 215 | { |
| 201 | 216 | case 'int': |
| 202 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 203 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 217 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 218 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 219 | + } |
|
| 204 | 220 | return (string) (int) $replacement; |
| 205 | 221 | break; |
| 206 | 222 | |
@@ -212,65 +228,73 @@ discard block |
||
| 212 | 228 | case 'array_int': |
| 213 | 229 | if (is_array($replacement)) |
| 214 | 230 | { |
| 215 | - if (empty($replacement)) |
|
| 216 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 231 | + if (empty($replacement)) { |
|
| 232 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 233 | + } |
|
| 217 | 234 | |
| 218 | 235 | foreach ($replacement as $key => $value) |
| 219 | 236 | { |
| 220 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 221 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 237 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 238 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 239 | + } |
|
| 222 | 240 | |
| 223 | 241 | $replacement[$key] = (string) (int) $value; |
| 224 | 242 | } |
| 225 | 243 | |
| 226 | 244 | return implode(', ', $replacement); |
| 245 | + } else { |
|
| 246 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 227 | 247 | } |
| 228 | - else |
|
| 229 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 230 | 248 | |
| 231 | 249 | break; |
| 232 | 250 | |
| 233 | 251 | case 'array_string': |
| 234 | 252 | if (is_array($replacement)) |
| 235 | 253 | { |
| 236 | - if (empty($replacement)) |
|
| 237 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 254 | + if (empty($replacement)) { |
|
| 255 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 256 | + } |
|
| 238 | 257 | |
| 239 | - foreach ($replacement as $key => $value) |
|
| 240 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 258 | + foreach ($replacement as $key => $value) { |
|
| 259 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 260 | + } |
|
| 241 | 261 | |
| 242 | 262 | return implode(', ', $replacement); |
| 263 | + } else { |
|
| 264 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 243 | 265 | } |
| 244 | - else |
|
| 245 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 246 | 266 | break; |
| 247 | 267 | |
| 248 | 268 | case 'date': |
| 249 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 250 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 251 | - else |
|
| 252 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 269 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 270 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 271 | + } else { |
|
| 272 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 273 | + } |
|
| 253 | 274 | break; |
| 254 | 275 | |
| 255 | 276 | case 'time': |
| 256 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 257 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 258 | - else |
|
| 259 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 277 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 278 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 279 | + } else { |
|
| 280 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 281 | + } |
|
| 260 | 282 | break; |
| 261 | 283 | |
| 262 | 284 | case 'datetime': |
| 263 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
| 264 | - return 'str_to_date('. |
|
| 285 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
| 286 | + return 'str_to_date('. |
|
| 265 | 287 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
| 266 | 288 | ',\'%Y-%m-%d %h:%i:%s\')'; |
| 267 | - else |
|
| 268 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 289 | + } else { |
|
| 290 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 291 | + } |
|
| 269 | 292 | break; |
| 270 | 293 | |
| 271 | 294 | case 'float': |
| 272 | - if (!is_numeric($replacement)) |
|
| 273 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 295 | + if (!is_numeric($replacement)) { |
|
| 296 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 297 | + } |
|
| 274 | 298 | return (string) (float) $replacement; |
| 275 | 299 | break; |
| 276 | 300 | |
@@ -284,32 +308,37 @@ discard block |
||
| 284 | 308 | break; |
| 285 | 309 | |
| 286 | 310 | case 'inet': |
| 287 | - if ($replacement == 'null' || $replacement == '') |
|
| 288 | - return 'null'; |
|
| 289 | - if (!isValidIP($replacement)) |
|
| 290 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 311 | + if ($replacement == 'null' || $replacement == '') { |
|
| 312 | + return 'null'; |
|
| 313 | + } |
|
| 314 | + if (!isValidIP($replacement)) { |
|
| 315 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 316 | + } |
|
| 291 | 317 | //we don't use the native support of mysql > 5.6.2 |
| 292 | 318 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 293 | 319 | |
| 294 | 320 | case 'array_inet': |
| 295 | 321 | if (is_array($replacement)) |
| 296 | 322 | { |
| 297 | - if (empty($replacement)) |
|
| 298 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 323 | + if (empty($replacement)) { |
|
| 324 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 325 | + } |
|
| 299 | 326 | |
| 300 | 327 | foreach ($replacement as $key => $value) |
| 301 | 328 | { |
| 302 | - if ($replacement == 'null' || $replacement == '') |
|
| 303 | - $replacement[$key] = 'null'; |
|
| 304 | - if (!isValidIP($value)) |
|
| 305 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 329 | + if ($replacement == 'null' || $replacement == '') { |
|
| 330 | + $replacement[$key] = 'null'; |
|
| 331 | + } |
|
| 332 | + if (!isValidIP($value)) { |
|
| 333 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 334 | + } |
|
| 306 | 335 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 307 | 336 | } |
| 308 | 337 | |
| 309 | 338 | return implode(', ', $replacement); |
| 339 | + } else { |
|
| 340 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 310 | 341 | } |
| 311 | - else |
|
| 312 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 313 | 342 | break; |
| 314 | 343 | |
| 315 | 344 | default: |
@@ -380,18 +409,20 @@ discard block |
||
| 380 | 409 | // One more query.... |
| 381 | 410 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 382 | 411 | |
| 383 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 384 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 412 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 413 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 414 | + } |
|
| 385 | 415 | |
| 386 | 416 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 387 | 417 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 388 | 418 | { |
| 389 | 419 | // Add before LIMIT |
| 390 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 391 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 392 | - else |
|
| 393 | - // Append it. |
|
| 420 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 421 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 422 | + } else { |
|
| 423 | + // Append it. |
|
| 394 | 424 | $db_string .= "\n\t\t\tORDER BY null"; |
| 425 | + } |
|
| 395 | 426 | } |
| 396 | 427 | |
| 397 | 428 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -417,17 +448,18 @@ discard block |
||
| 417 | 448 | while (true) |
| 418 | 449 | { |
| 419 | 450 | $pos = strpos($db_string_1, '\'', $pos + 1); |
| 420 | - if ($pos === false) |
|
| 421 | - break; |
|
| 451 | + if ($pos === false) { |
|
| 452 | + break; |
|
| 453 | + } |
|
| 422 | 454 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
| 423 | 455 | |
| 424 | 456 | while (true) |
| 425 | 457 | { |
| 426 | 458 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
| 427 | 459 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
| 428 | - if ($pos1 === false) |
|
| 429 | - break; |
|
| 430 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 460 | + if ($pos1 === false) { |
|
| 461 | + break; |
|
| 462 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 431 | 463 | { |
| 432 | 464 | $pos = $pos1; |
| 433 | 465 | break; |
@@ -443,16 +475,19 @@ discard block |
||
| 443 | 475 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 444 | 476 | |
| 445 | 477 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 446 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 447 | - $fail = true; |
|
| 478 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 479 | + $fail = true; |
|
| 480 | + } |
|
| 448 | 481 | // Trying to change passwords, slow us down, or something? |
| 449 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 450 | - $fail = true; |
|
| 451 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 452 | - $fail = true; |
|
| 482 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 483 | + $fail = true; |
|
| 484 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 485 | + $fail = true; |
|
| 486 | + } |
|
| 453 | 487 | |
| 454 | - if (!empty($fail) && function_exists('log_error')) |
|
| 455 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 488 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 489 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 490 | + } |
|
| 456 | 491 | } |
| 457 | 492 | |
| 458 | 493 | // Debugging. |
@@ -462,8 +497,9 @@ discard block |
||
| 462 | 497 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 463 | 498 | |
| 464 | 499 | // Initialize $db_cache if not already initialized. |
| 465 | - if (!isset($db_cache)) |
|
| 466 | - $db_cache = array(); |
|
| 500 | + if (!isset($db_cache)) { |
|
| 501 | + $db_cache = array(); |
|
| 502 | + } |
|
| 467 | 503 | |
| 468 | 504 | if (!empty($_SESSION['debug_redirect'])) |
| 469 | 505 | { |
@@ -479,17 +515,20 @@ discard block |
||
| 479 | 515 | $db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start; |
| 480 | 516 | } |
| 481 | 517 | |
| 482 | - if (empty($db_unbuffered)) |
|
| 483 | - $ret = @mysqli_query($connection, $db_string); |
|
| 484 | - else |
|
| 485 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 518 | + if (empty($db_unbuffered)) { |
|
| 519 | + $ret = @mysqli_query($connection, $db_string); |
|
| 520 | + } else { |
|
| 521 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 522 | + } |
|
| 486 | 523 | |
| 487 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 488 | - $ret = smf_db_error($db_string, $connection); |
|
| 524 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 525 | + $ret = smf_db_error($db_string, $connection); |
|
| 526 | + } |
|
| 489 | 527 | |
| 490 | 528 | // Debugging. |
| 491 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 492 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 529 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 530 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 531 | + } |
|
| 493 | 532 | |
| 494 | 533 | return $ret; |
| 495 | 534 | } |
@@ -536,12 +575,13 @@ discard block |
||
| 536 | 575 | // Decide which connection to use |
| 537 | 576 | $connection = $connection === null ? $db_connection : $connection; |
| 538 | 577 | |
| 539 | - if ($type == 'begin') |
|
| 540 | - return @mysqli_query($connection, 'BEGIN'); |
|
| 541 | - elseif ($type == 'rollback') |
|
| 542 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
| 543 | - elseif ($type == 'commit') |
|
| 544 | - return @mysqli_query($connection, 'COMMIT'); |
|
| 578 | + if ($type == 'begin') { |
|
| 579 | + return @mysqli_query($connection, 'BEGIN'); |
|
| 580 | + } elseif ($type == 'rollback') { |
|
| 581 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
| 582 | + } elseif ($type == 'commit') { |
|
| 583 | + return @mysqli_query($connection, 'COMMIT'); |
|
| 584 | + } |
|
| 545 | 585 | |
| 546 | 586 | return false; |
| 547 | 587 | } |
@@ -579,8 +619,9 @@ discard block |
||
| 579 | 619 | // 1213: Deadlock found. |
| 580 | 620 | |
| 581 | 621 | // Log the error. |
| 582 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 583 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 622 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 623 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 624 | + } |
|
| 584 | 625 | |
| 585 | 626 | // Database error auto fixing ;). |
| 586 | 627 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -589,8 +630,9 @@ discard block |
||
| 589 | 630 | $old_cache = @$modSettings['cache_enable']; |
| 590 | 631 | $modSettings['cache_enable'] = '1'; |
| 591 | 632 | |
| 592 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 593 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 633 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 634 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 635 | + } |
|
| 594 | 636 | |
| 595 | 637 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 596 | 638 | { |
@@ -606,8 +648,9 @@ discard block |
||
| 606 | 648 | foreach ($tables as $table) |
| 607 | 649 | { |
| 608 | 650 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 609 | - if (trim($table) != '') |
|
| 610 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 651 | + if (trim($table) != '') { |
|
| 652 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 653 | + } |
|
| 611 | 654 | } |
| 612 | 655 | } |
| 613 | 656 | |
@@ -616,8 +659,9 @@ discard block |
||
| 616 | 659 | // Table crashed. Let's try to fix it. |
| 617 | 660 | elseif ($query_errno == 1016) |
| 618 | 661 | { |
| 619 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 620 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 662 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 663 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 664 | + } |
|
| 621 | 665 | } |
| 622 | 666 | // Indexes crashed. Should be easy to fix! |
| 623 | 667 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -636,13 +680,15 @@ discard block |
||
| 636 | 680 | |
| 637 | 681 | // Make a note of the REPAIR... |
| 638 | 682 | cache_put_data('db_last_error', time(), 600); |
| 639 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 640 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 683 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 684 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 685 | + } |
|
| 641 | 686 | |
| 642 | 687 | // Attempt to find and repair the broken table. |
| 643 | - foreach ($fix_tables as $table) |
|
| 644 | - $smcFunc['db_query']('', " |
|
| 688 | + foreach ($fix_tables as $table) { |
|
| 689 | + $smcFunc['db_query']('', " |
|
| 645 | 690 | REPAIR TABLE $table", false, false); |
| 691 | + } |
|
| 646 | 692 | |
| 647 | 693 | // And send off an email! |
| 648 | 694 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -651,11 +697,12 @@ discard block |
||
| 651 | 697 | |
| 652 | 698 | // Try the query again...? |
| 653 | 699 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 654 | - if ($ret !== false) |
|
| 655 | - return $ret; |
|
| 700 | + if ($ret !== false) { |
|
| 701 | + return $ret; |
|
| 702 | + } |
|
| 703 | + } else { |
|
| 704 | + $modSettings['cache_enable'] = $old_cache; |
|
| 656 | 705 | } |
| 657 | - else |
|
| 658 | - $modSettings['cache_enable'] = $old_cache; |
|
| 659 | 706 | |
| 660 | 707 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 661 | 708 | if (in_array($query_errno, array(1205, 1213))) |
@@ -668,24 +715,27 @@ discard block |
||
| 668 | 715 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 669 | 716 | |
| 670 | 717 | $new_errno = mysqli_errno($db_connection); |
| 671 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 672 | - break; |
|
| 718 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 719 | + break; |
|
| 720 | + } |
|
| 673 | 721 | } |
| 674 | 722 | |
| 675 | 723 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 676 | - if ($ret !== false) |
|
| 677 | - return $ret; |
|
| 724 | + if ($ret !== false) { |
|
| 725 | + return $ret; |
|
| 726 | + } |
|
| 678 | 727 | } |
| 679 | 728 | } |
| 680 | 729 | // Are they out of space, perhaps? |
| 681 | 730 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 682 | 731 | { |
| 683 | - if (!isset($txt)) |
|
| 684 | - $query_error .= ' - check database storage space.'; |
|
| 685 | - else |
|
| 732 | + if (!isset($txt)) { |
|
| 733 | + $query_error .= ' - check database storage space.'; |
|
| 734 | + } else |
|
| 686 | 735 | { |
| 687 | - if (!isset($txt['mysql_error_space'])) |
|
| 688 | - loadLanguage('Errors'); |
|
| 736 | + if (!isset($txt['mysql_error_space'])) { |
|
| 737 | + loadLanguage('Errors'); |
|
| 738 | + } |
|
| 689 | 739 | |
| 690 | 740 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 691 | 741 | } |
@@ -693,15 +743,17 @@ discard block |
||
| 693 | 743 | } |
| 694 | 744 | |
| 695 | 745 | // Nothing's defined yet... just die with it. |
| 696 | - if (empty($context) || empty($txt)) |
|
| 697 | - die($query_error); |
|
| 746 | + if (empty($context) || empty($txt)) { |
|
| 747 | + die($query_error); |
|
| 748 | + } |
|
| 698 | 749 | |
| 699 | 750 | // Show an error message, if possible. |
| 700 | 751 | $context['error_title'] = $txt['database_error']; |
| 701 | - if (allowedTo('admin_forum')) |
|
| 702 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 703 | - else |
|
| 704 | - $context['error_message'] = $txt['try_again']; |
|
| 752 | + if (allowedTo('admin_forum')) { |
|
| 753 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 754 | + } else { |
|
| 755 | + $context['error_message'] = $txt['try_again']; |
|
| 756 | + } |
|
| 705 | 757 | |
| 706 | 758 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 707 | 759 | { |
@@ -733,8 +785,9 @@ discard block |
||
| 733 | 785 | $return_var = null; |
| 734 | 786 | |
| 735 | 787 | // With nothing to insert, simply return. |
| 736 | - if (empty($data)) |
|
| 737 | - return; |
|
| 788 | + if (empty($data)) { |
|
| 789 | + return; |
|
| 790 | + } |
|
| 738 | 791 | |
| 739 | 792 | // Replace the prefix holder with the actual prefix. |
| 740 | 793 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -744,23 +797,26 @@ discard block |
||
| 744 | 797 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
| 745 | 798 | { |
| 746 | 799 | $with_returning = true; |
| 747 | - if ($returnmode == 2) |
|
| 748 | - $return_var = array(); |
|
| 800 | + if ($returnmode == 2) { |
|
| 801 | + $return_var = array(); |
|
| 802 | + } |
|
| 749 | 803 | } |
| 750 | 804 | |
| 751 | 805 | // Inserting data as a single row can be done as a single array. |
| 752 | - if (!is_array($data[array_rand($data)])) |
|
| 753 | - $data = array($data); |
|
| 806 | + if (!is_array($data[array_rand($data)])) { |
|
| 807 | + $data = array($data); |
|
| 808 | + } |
|
| 754 | 809 | |
| 755 | 810 | // Create the mold for a single row insert. |
| 756 | 811 | $insertData = '('; |
| 757 | 812 | foreach ($columns as $columnName => $type) |
| 758 | 813 | { |
| 759 | 814 | // Are we restricting the length? |
| 760 | - if (strpos($type, 'string-') !== false) |
|
| 761 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 762 | - else |
|
| 763 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 815 | + if (strpos($type, 'string-') !== false) { |
|
| 816 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 817 | + } else { |
|
| 818 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 819 | + } |
|
| 764 | 820 | } |
| 765 | 821 | $insertData = substr($insertData, 0, -2) . ')'; |
| 766 | 822 | |
@@ -769,8 +825,9 @@ discard block |
||
| 769 | 825 | |
| 770 | 826 | // Here's where the variables are injected to the query. |
| 771 | 827 | $insertRows = array(); |
| 772 | - foreach ($data as $dataRow) |
|
| 773 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 828 | + foreach ($data as $dataRow) { |
|
| 829 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 830 | + } |
|
| 774 | 831 | |
| 775 | 832 | // Determine the method of insertion. |
| 776 | 833 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -789,8 +846,7 @@ discard block |
||
| 789 | 846 | ), |
| 790 | 847 | $connection |
| 791 | 848 | ); |
| 792 | - } |
|
| 793 | - else //special way for ignore method with returning |
|
| 849 | + } else //special way for ignore method with returning |
|
| 794 | 850 | { |
| 795 | 851 | $count = count($insertRows); |
| 796 | 852 | $ai = 0; |
@@ -810,19 +866,21 @@ discard block |
||
| 810 | 866 | ); |
| 811 | 867 | $new_id = $smcFunc['db_insert_id'](); |
| 812 | 868 | |
| 813 | - if ($last_id != $new_id) //the inserted value was new |
|
| 869 | + if ($last_id != $new_id) { |
|
| 870 | + //the inserted value was new |
|
| 814 | 871 | { |
| 815 | 872 | $ai = $new_id; |
| 816 | 873 | } |
| 817 | - else // the inserted value already exists we need to find the pk |
|
| 874 | + } else // the inserted value already exists we need to find the pk |
|
| 818 | 875 | { |
| 819 | 876 | $where_string = ''; |
| 820 | 877 | $count2 = count($indexed_columns); |
| 821 | 878 | for ($x = 0; $x < $count2; $x++) |
| 822 | 879 | { |
| 823 | 880 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
| 824 | - if (($x + 1) < $count2) |
|
| 825 | - $where_string += ' AND '; |
|
| 881 | + if (($x + 1) < $count2) { |
|
| 882 | + $where_string += ' AND '; |
|
| 883 | + } |
|
| 826 | 884 | } |
| 827 | 885 | |
| 828 | 886 | $request = $smcFunc['db_query']('',' |
@@ -838,25 +896,27 @@ discard block |
||
| 838 | 896 | } |
| 839 | 897 | } |
| 840 | 898 | |
| 841 | - if ($returnmode == 1) |
|
| 842 | - $return_var = $ai; |
|
| 843 | - else if ($returnmode == 2) |
|
| 844 | - $return_var[] = $ai; |
|
| 899 | + if ($returnmode == 1) { |
|
| 900 | + $return_var = $ai; |
|
| 901 | + } else if ($returnmode == 2) { |
|
| 902 | + $return_var[] = $ai; |
|
| 903 | + } |
|
| 845 | 904 | } |
| 846 | 905 | } |
| 847 | 906 | |
| 848 | 907 | |
| 849 | 908 | if ($with_returning) |
| 850 | 909 | { |
| 851 | - if ($returnmode == 1 && empty($return_var)) |
|
| 852 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 853 | - else if ($returnmode == 2 && empty($return_var)) |
|
| 910 | + if ($returnmode == 1 && empty($return_var)) { |
|
| 911 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 912 | + } else if ($returnmode == 2 && empty($return_var)) |
|
| 854 | 913 | { |
| 855 | 914 | $return_var = array(); |
| 856 | 915 | $count = count($insertRows); |
| 857 | 916 | $start = smf_db_insert_id($table, $keys[0]); |
| 858 | - for ($i = 0; $i < $count; $i++ ) |
|
| 859 | - $return_var[] = $start + $i; |
|
| 917 | + for ($i = 0; $i < $count; $i++ ) { |
|
| 918 | + $return_var[] = $start + $i; |
|
| 919 | + } |
|
| 860 | 920 | } |
| 861 | 921 | return $return_var; |
| 862 | 922 | } |
@@ -874,8 +934,9 @@ discard block |
||
| 874 | 934 | */ |
| 875 | 935 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 876 | 936 | { |
| 877 | - if (empty($log_message)) |
|
| 878 | - $log_message = $error_message; |
|
| 937 | + if (empty($log_message)) { |
|
| 938 | + $log_message = $error_message; |
|
| 939 | + } |
|
| 879 | 940 | |
| 880 | 941 | foreach (debug_backtrace() as $step) |
| 881 | 942 | { |
@@ -894,12 +955,14 @@ discard block |
||
| 894 | 955 | } |
| 895 | 956 | |
| 896 | 957 | // A special case - we want the file and line numbers for debugging. |
| 897 | - if ($error_type == 'return') |
|
| 898 | - return array($file, $line); |
|
| 958 | + if ($error_type == 'return') { |
|
| 959 | + return array($file, $line); |
|
| 960 | + } |
|
| 899 | 961 | |
| 900 | 962 | // Is always a critical error. |
| 901 | - if (function_exists('log_error')) |
|
| 902 | - log_error($log_message, 'critical', $file, $line); |
|
| 963 | + if (function_exists('log_error')) { |
|
| 964 | + log_error($log_message, 'critical', $file, $line); |
|
| 965 | + } |
|
| 903 | 966 | |
| 904 | 967 | if (function_exists('fatal_error')) |
| 905 | 968 | { |
@@ -907,12 +970,12 @@ discard block |
||
| 907 | 970 | |
| 908 | 971 | // Cannot continue... |
| 909 | 972 | exit; |
| 973 | + } elseif ($error_type) { |
|
| 974 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 975 | + } else { |
|
| 976 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 977 | + } |
|
| 910 | 978 | } |
| 911 | - elseif ($error_type) |
|
| 912 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 913 | - else |
|
| 914 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 915 | -} |
|
| 916 | 979 | |
| 917 | 980 | /** |
| 918 | 981 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -929,10 +992,11 @@ discard block |
||
| 929 | 992 | '\\' => '\\\\', |
| 930 | 993 | ); |
| 931 | 994 | |
| 932 | - if ($translate_human_wildcards) |
|
| 933 | - $replacements += array( |
|
| 995 | + if ($translate_human_wildcards) { |
|
| 996 | + $replacements += array( |
|
| 934 | 997 | '*' => '%', |
| 935 | 998 | ); |
| 999 | + } |
|
| 936 | 1000 | |
| 937 | 1001 | return strtr($string, $replacements); |
| 938 | 1002 | } |
@@ -946,8 +1010,9 @@ discard block |
||
| 946 | 1010 | */ |
| 947 | 1011 | function smf_is_resource($result) |
| 948 | 1012 | { |
| 949 | - if ($result instanceof mysqli_result) |
|
| 950 | - return true; |
|
| 1013 | + if ($result instanceof mysqli_result) { |
|
| 1014 | + return true; |
|
| 1015 | + } |
|
| 951 | 1016 | |
| 952 | 1017 | return false; |
| 953 | 1018 | } |
@@ -976,19 +1041,22 @@ discard block |
||
| 976 | 1041 | static $mysql_error_data_prep; |
| 977 | 1042 | |
| 978 | 1043 | // without database we can't do anything |
| 979 | - if (empty($db_connection)) |
|
| 980 | - return; |
|
| 1044 | + if (empty($db_connection)) { |
|
| 1045 | + return; |
|
| 1046 | + } |
|
| 981 | 1047 | |
| 982 | - if (empty($mysql_error_data_prep)) |
|
| 983 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
| 1048 | + if (empty($mysql_error_data_prep)) { |
|
| 1049 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
| 984 | 1050 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
| 985 | 1051 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?, ?)' |
| 986 | 1052 | ); |
| 1053 | + } |
|
| 987 | 1054 | |
| 988 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
| 989 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
| 990 | - else |
|
| 991 | - $error_array[2] = null; |
|
| 1055 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
| 1056 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
| 1057 | + } else { |
|
| 1058 | + $error_array[2] = null; |
|
| 1059 | + } |
|
| 992 | 1060 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis', |
| 993 | 1061 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
| 994 | 1062 | $error_array[7], $error_array[8], $error_array[9]); |
@@ -1010,8 +1078,9 @@ discard block |
||
| 1010 | 1078 | $count = count($array_values); |
| 1011 | 1079 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1012 | 1080 | |
| 1013 | - for ($i = 0; $i < $count; $i++) |
|
| 1014 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1081 | + for ($i = 0; $i < $count; $i++) { |
|
| 1082 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1083 | + } |
|
| 1015 | 1084 | |
| 1016 | 1085 | $return .= 'END'; |
| 1017 | 1086 | return $return; |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
| 34 | 35 | global $smcFunc; |
| 35 | 36 | |
| 36 | 37 | // Map some database specific functions, only do this once. |
| 37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
| 38 | - $smcFunc += array( |
|
| 38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
| 39 | + $smcFunc += array( |
|
| 39 | 40 | 'db_query' => 'smf_db_query', |
| 40 | 41 | 'db_quote' => 'smf_db_quote', |
| 41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -65,15 +66,18 @@ discard block |
||
| 65 | 66 | 'db_custom_order' => 'smf_db_custom_order', |
| 66 | 67 | 'db_native_replace' => 'smf_db_native_replace', |
| 67 | 68 | ); |
| 69 | + } |
|
| 68 | 70 | |
| 69 | 71 | // We are not going to make it very far without these. |
| 70 | - if (!function_exists('pg_pconnect')) |
|
| 71 | - display_db_error(); |
|
| 72 | + if (!function_exists('pg_pconnect')) { |
|
| 73 | + display_db_error(); |
|
| 74 | + } |
|
| 72 | 75 | |
| 73 | - if (!empty($db_options['persist'])) |
|
| 74 | - $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 75 | - else |
|
| 76 | - $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 76 | + if (!empty($db_options['persist'])) { |
|
| 77 | + $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 78 | + } else { |
|
| 79 | + $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 80 | + } |
|
| 77 | 81 | |
| 78 | 82 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 79 | 83 | if (!$connection) |
@@ -81,15 +85,15 @@ discard block |
||
| 81 | 85 | if (!empty($db_options['non_fatal'])) |
| 82 | 86 | { |
| 83 | 87 | return null; |
| 84 | - } |
|
| 85 | - else |
|
| 88 | + } else |
|
| 86 | 89 | { |
| 87 | 90 | display_db_error(); |
| 88 | 91 | } |
| 89 | 92 | } |
| 90 | 93 | |
| 91 | - if (!empty($db_options['db_mb4'])) |
|
| 92 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
| 94 | + if (!empty($db_options['db_mb4'])) { |
|
| 95 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
| 96 | + } |
|
| 93 | 97 | |
| 94 | 98 | return $connection; |
| 95 | 99 | } |
@@ -136,31 +140,38 @@ discard block |
||
| 136 | 140 | |
| 137 | 141 | list ($values, $connection) = $db_callback; |
| 138 | 142 | |
| 139 | - if ($matches[1] === 'db_prefix') |
|
| 140 | - return $db_prefix; |
|
| 143 | + if ($matches[1] === 'db_prefix') { |
|
| 144 | + return $db_prefix; |
|
| 145 | + } |
|
| 141 | 146 | |
| 142 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
| 143 | - return $user_info[$matches[1]]; |
|
| 147 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
| 148 | + return $user_info[$matches[1]]; |
|
| 149 | + } |
|
| 144 | 150 | |
| 145 | - if ($matches[1] === 'empty') |
|
| 146 | - return '\'\''; |
|
| 151 | + if ($matches[1] === 'empty') { |
|
| 152 | + return '\'\''; |
|
| 153 | + } |
|
| 147 | 154 | |
| 148 | - if (!isset($matches[2])) |
|
| 149 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 155 | + if (!isset($matches[2])) { |
|
| 156 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 157 | + } |
|
| 150 | 158 | |
| 151 | - if ($matches[1] === 'literal') |
|
| 152 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 159 | + if ($matches[1] === 'literal') { |
|
| 160 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 161 | + } |
|
| 153 | 162 | |
| 154 | - if (!isset($values[$matches[2]])) |
|
| 155 | - 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__); |
|
| 163 | + if (!isset($values[$matches[2]])) { |
|
| 164 | + 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__); |
|
| 165 | + } |
|
| 156 | 166 | |
| 157 | 167 | $replacement = $values[$matches[2]]; |
| 158 | 168 | |
| 159 | 169 | switch ($matches[1]) |
| 160 | 170 | { |
| 161 | 171 | case 'int': |
| 162 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 163 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 172 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 173 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 174 | + } |
|
| 164 | 175 | return (string) (int) $replacement; |
| 165 | 176 | break; |
| 166 | 177 | |
@@ -172,65 +183,73 @@ discard block |
||
| 172 | 183 | case 'array_int': |
| 173 | 184 | if (is_array($replacement)) |
| 174 | 185 | { |
| 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__); |
|
| 186 | + if (empty($replacement)) { |
|
| 187 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 188 | + } |
|
| 177 | 189 | |
| 178 | 190 | foreach ($replacement as $key => $value) |
| 179 | 191 | { |
| 180 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 181 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 192 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 193 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 194 | + } |
|
| 182 | 195 | |
| 183 | 196 | $replacement[$key] = (string) (int) $value; |
| 184 | 197 | } |
| 185 | 198 | |
| 186 | 199 | return implode(', ', $replacement); |
| 200 | + } else { |
|
| 201 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 187 | 202 | } |
| 188 | - else |
|
| 189 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 190 | 203 | |
| 191 | 204 | break; |
| 192 | 205 | |
| 193 | 206 | case 'array_string': |
| 194 | 207 | if (is_array($replacement)) |
| 195 | 208 | { |
| 196 | - if (empty($replacement)) |
|
| 197 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 209 | + if (empty($replacement)) { |
|
| 210 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 211 | + } |
|
| 198 | 212 | |
| 199 | - foreach ($replacement as $key => $value) |
|
| 200 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 213 | + foreach ($replacement as $key => $value) { |
|
| 214 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 215 | + } |
|
| 201 | 216 | |
| 202 | 217 | return implode(', ', $replacement); |
| 218 | + } else { |
|
| 219 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 203 | 220 | } |
| 204 | - else |
|
| 205 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 206 | 221 | break; |
| 207 | 222 | |
| 208 | 223 | case 'date': |
| 209 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 210 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 211 | - else |
|
| 212 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 224 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 225 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 226 | + } else { |
|
| 227 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 228 | + } |
|
| 213 | 229 | break; |
| 214 | 230 | |
| 215 | 231 | case 'time': |
| 216 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 217 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 218 | - else |
|
| 219 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 232 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 233 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 234 | + } else { |
|
| 235 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 236 | + } |
|
| 220 | 237 | break; |
| 221 | 238 | |
| 222 | 239 | case 'datetime': |
| 223 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
| 224 | - return 'to_timestamp('. |
|
| 240 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
| 241 | + return 'to_timestamp('. |
|
| 225 | 242 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
| 226 | 243 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
| 227 | - else |
|
| 228 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 244 | + } else { |
|
| 245 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 246 | + } |
|
| 229 | 247 | break; |
| 230 | 248 | |
| 231 | 249 | case 'float': |
| 232 | - if (!is_numeric($replacement)) |
|
| 233 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 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__); |
|
| 252 | + } |
|
| 234 | 253 | return (string) (float) $replacement; |
| 235 | 254 | break; |
| 236 | 255 | |
@@ -243,31 +262,36 @@ discard block |
||
| 243 | 262 | break; |
| 244 | 263 | |
| 245 | 264 | case 'inet': |
| 246 | - if ($replacement == 'null' || $replacement == '') |
|
| 247 | - return 'null'; |
|
| 248 | - if (inet_pton($replacement) === false) |
|
| 249 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 265 | + if ($replacement == 'null' || $replacement == '') { |
|
| 266 | + return 'null'; |
|
| 267 | + } |
|
| 268 | + if (inet_pton($replacement) === false) { |
|
| 269 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 270 | + } |
|
| 250 | 271 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 251 | 272 | |
| 252 | 273 | case 'array_inet': |
| 253 | 274 | if (is_array($replacement)) |
| 254 | 275 | { |
| 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__); |
|
| 276 | + if (empty($replacement)) { |
|
| 277 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 278 | + } |
|
| 257 | 279 | |
| 258 | 280 | foreach ($replacement as $key => $value) |
| 259 | 281 | { |
| 260 | - if ($replacement == 'null' || $replacement == '') |
|
| 261 | - $replacement[$key] = 'null'; |
|
| 262 | - if (!isValidIP($value)) |
|
| 263 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 282 | + if ($replacement == 'null' || $replacement == '') { |
|
| 283 | + $replacement[$key] = 'null'; |
|
| 284 | + } |
|
| 285 | + if (!isValidIP($value)) { |
|
| 286 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 287 | + } |
|
| 264 | 288 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 265 | 289 | } |
| 266 | 290 | |
| 267 | 291 | return implode(', ', $replacement); |
| 292 | + } else { |
|
| 293 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 268 | 294 | } |
| 269 | - else |
|
| 270 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 271 | 295 | break; |
| 272 | 296 | |
| 273 | 297 | default: |
@@ -355,14 +379,16 @@ discard block |
||
| 355 | 379 | ), |
| 356 | 380 | ); |
| 357 | 381 | |
| 358 | - if (isset($replacements[$identifier])) |
|
| 359 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 382 | + if (isset($replacements[$identifier])) { |
|
| 383 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 384 | + } |
|
| 360 | 385 | |
| 361 | 386 | // Limits need to be a little different. |
| 362 | 387 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 363 | 388 | |
| 364 | - if (trim($db_string) == '') |
|
| 365 | - return false; |
|
| 389 | + if (trim($db_string) == '') { |
|
| 390 | + return false; |
|
| 391 | + } |
|
| 366 | 392 | |
| 367 | 393 | // Comments that are allowed in a query are preg_removed. |
| 368 | 394 | static $allowed_comments_from = array( |
@@ -382,8 +408,9 @@ discard block |
||
| 382 | 408 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 383 | 409 | $db_replace_result = 0; |
| 384 | 410 | |
| 385 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 386 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 411 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 412 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 413 | + } |
|
| 387 | 414 | |
| 388 | 415 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 389 | 416 | { |
@@ -408,17 +435,18 @@ discard block |
||
| 408 | 435 | while (true) |
| 409 | 436 | { |
| 410 | 437 | $pos = strpos($db_string_1, '\'', $pos + 1); |
| 411 | - if ($pos === false) |
|
| 412 | - break; |
|
| 438 | + if ($pos === false) { |
|
| 439 | + break; |
|
| 440 | + } |
|
| 413 | 441 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
| 414 | 442 | |
| 415 | 443 | while (true) |
| 416 | 444 | { |
| 417 | 445 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
| 418 | 446 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
| 419 | - if ($pos1 === false) |
|
| 420 | - break; |
|
| 421 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 447 | + if ($pos1 === false) { |
|
| 448 | + break; |
|
| 449 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 422 | 450 | { |
| 423 | 451 | $pos = $pos1; |
| 424 | 452 | break; |
@@ -434,16 +462,19 @@ discard block |
||
| 434 | 462 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 435 | 463 | |
| 436 | 464 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 437 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 438 | - $fail = true; |
|
| 465 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 466 | + $fail = true; |
|
| 467 | + } |
|
| 439 | 468 | // Trying to change passwords, slow us down, or something? |
| 440 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 441 | - $fail = true; |
|
| 442 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 443 | - $fail = true; |
|
| 469 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 470 | + $fail = true; |
|
| 471 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 472 | + $fail = true; |
|
| 473 | + } |
|
| 444 | 474 | |
| 445 | - if (!empty($fail) && function_exists('log_error')) |
|
| 446 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 475 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 476 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 477 | + } |
|
| 447 | 478 | } |
| 448 | 479 | |
| 449 | 480 | // Set optimize stuff |
@@ -470,8 +501,9 @@ discard block |
||
| 470 | 501 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 471 | 502 | |
| 472 | 503 | // Initialize $db_cache if not already initialized. |
| 473 | - if (!isset($db_cache)) |
|
| 474 | - $db_cache = array(); |
|
| 504 | + if (!isset($db_cache)) { |
|
| 505 | + $db_cache = array(); |
|
| 506 | + } |
|
| 475 | 507 | |
| 476 | 508 | if (!empty($_SESSION['debug_redirect'])) |
| 477 | 509 | { |
@@ -489,12 +521,14 @@ discard block |
||
| 489 | 521 | |
| 490 | 522 | $db_last_result = @pg_query($connection, $db_string); |
| 491 | 523 | |
| 492 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 493 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 524 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 525 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 526 | + } |
|
| 494 | 527 | |
| 495 | 528 | // 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)); |
|
| 529 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 530 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 531 | + } |
|
| 498 | 532 | |
| 499 | 533 | return $db_last_result; |
| 500 | 534 | } |
@@ -511,10 +545,11 @@ discard block |
||
| 511 | 545 | { |
| 512 | 546 | global $db_last_result, $db_replace_result; |
| 513 | 547 | |
| 514 | - if ($db_replace_result) |
|
| 515 | - return $db_replace_result; |
|
| 516 | - elseif ($result === null && !$db_last_result) |
|
| 517 | - return 0; |
|
| 548 | + if ($db_replace_result) { |
|
| 549 | + return $db_replace_result; |
|
| 550 | + } elseif ($result === null && !$db_last_result) { |
|
| 551 | + return 0; |
|
| 552 | + } |
|
| 518 | 553 | |
| 519 | 554 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 520 | 555 | } |
@@ -538,8 +573,9 @@ discard block |
||
| 538 | 573 | array( |
| 539 | 574 | ) |
| 540 | 575 | ); |
| 541 | - if (!$request) |
|
| 542 | - return false; |
|
| 576 | + if (!$request) { |
|
| 577 | + return false; |
|
| 578 | + } |
|
| 543 | 579 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 544 | 580 | $smcFunc['db_free_result']($request); |
| 545 | 581 | |
@@ -560,12 +596,13 @@ discard block |
||
| 560 | 596 | // Decide which connection to use |
| 561 | 597 | $connection = $connection === null ? $db_connection : $connection; |
| 562 | 598 | |
| 563 | - if ($type == 'begin') |
|
| 564 | - return @pg_query($connection, 'BEGIN'); |
|
| 565 | - elseif ($type == 'rollback') |
|
| 566 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 567 | - elseif ($type == 'commit') |
|
| 568 | - return @pg_query($connection, 'COMMIT'); |
|
| 599 | + if ($type == 'begin') { |
|
| 600 | + return @pg_query($connection, 'BEGIN'); |
|
| 601 | + } elseif ($type == 'rollback') { |
|
| 602 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 603 | + } elseif ($type == 'commit') { |
|
| 604 | + return @pg_query($connection, 'COMMIT'); |
|
| 605 | + } |
|
| 569 | 606 | |
| 570 | 607 | return false; |
| 571 | 608 | } |
@@ -593,19 +630,22 @@ discard block |
||
| 593 | 630 | $query_error = @pg_last_error($connection); |
| 594 | 631 | |
| 595 | 632 | // Log the error. |
| 596 | - if (function_exists('log_error')) |
|
| 597 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 633 | + if (function_exists('log_error')) { |
|
| 634 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 635 | + } |
|
| 598 | 636 | |
| 599 | 637 | // Nothing's defined yet... just die with it. |
| 600 | - if (empty($context) || empty($txt)) |
|
| 601 | - die($query_error); |
|
| 638 | + if (empty($context) || empty($txt)) { |
|
| 639 | + die($query_error); |
|
| 640 | + } |
|
| 602 | 641 | |
| 603 | 642 | // Show an error message, if possible. |
| 604 | 643 | $context['error_title'] = $txt['database_error']; |
| 605 | - if (allowedTo('admin_forum')) |
|
| 606 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 607 | - else |
|
| 608 | - $context['error_message'] = $txt['try_again']; |
|
| 644 | + if (allowedTo('admin_forum')) { |
|
| 645 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 646 | + } else { |
|
| 647 | + $context['error_message'] = $txt['try_again']; |
|
| 648 | + } |
|
| 609 | 649 | |
| 610 | 650 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 611 | 651 | { |
@@ -627,12 +667,14 @@ discard block |
||
| 627 | 667 | { |
| 628 | 668 | global $db_row_count; |
| 629 | 669 | |
| 630 | - if ($counter !== false) |
|
| 631 | - return pg_fetch_row($request, $counter); |
|
| 670 | + if ($counter !== false) { |
|
| 671 | + return pg_fetch_row($request, $counter); |
|
| 672 | + } |
|
| 632 | 673 | |
| 633 | 674 | // Reset the row counter... |
| 634 | - if (!isset($db_row_count[(int) $request])) |
|
| 635 | - $db_row_count[(int) $request] = 0; |
|
| 675 | + if (!isset($db_row_count[(int) $request])) { |
|
| 676 | + $db_row_count[(int) $request] = 0; |
|
| 677 | + } |
|
| 636 | 678 | |
| 637 | 679 | // Return the right row. |
| 638 | 680 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -649,12 +691,14 @@ discard block |
||
| 649 | 691 | { |
| 650 | 692 | global $db_row_count; |
| 651 | 693 | |
| 652 | - if ($counter !== false) |
|
| 653 | - return pg_fetch_assoc($request, $counter); |
|
| 694 | + if ($counter !== false) { |
|
| 695 | + return pg_fetch_assoc($request, $counter); |
|
| 696 | + } |
|
| 654 | 697 | |
| 655 | 698 | // Reset the row counter... |
| 656 | - if (!isset($db_row_count[(int) $request])) |
|
| 657 | - $db_row_count[(int) $request] = 0; |
|
| 699 | + if (!isset($db_row_count[(int) $request])) { |
|
| 700 | + $db_row_count[(int) $request] = 0; |
|
| 701 | + } |
|
| 658 | 702 | |
| 659 | 703 | // Return the right row. |
| 660 | 704 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -707,11 +751,13 @@ discard block |
||
| 707 | 751 | |
| 708 | 752 | $replace = ''; |
| 709 | 753 | |
| 710 | - if (empty($data)) |
|
| 711 | - return; |
|
| 754 | + if (empty($data)) { |
|
| 755 | + return; |
|
| 756 | + } |
|
| 712 | 757 | |
| 713 | - if (!is_array($data[array_rand($data)])) |
|
| 714 | - $data = array($data); |
|
| 758 | + if (!is_array($data[array_rand($data)])) { |
|
| 759 | + $data = array($data); |
|
| 760 | + } |
|
| 715 | 761 | |
| 716 | 762 | // Replace the prefix holder with the actual prefix. |
| 717 | 763 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -737,32 +783,35 @@ discard block |
||
| 737 | 783 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 738 | 784 | $key_str .= $columnName; |
| 739 | 785 | $count_pk++; |
| 740 | - } |
|
| 741 | - else if ($method == 'replace') //normal field |
|
| 786 | + } else if ($method == 'replace') { |
|
| 787 | + //normal field |
|
| 742 | 788 | { |
| 743 | 789 | $col_str .= ($count > 0 ? ',' : ''); |
| 790 | + } |
|
| 744 | 791 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
| 745 | 792 | $count++; |
| 746 | 793 | } |
| 747 | 794 | } |
| 748 | - if ($method == 'replace') |
|
| 749 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 750 | - else |
|
| 751 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
| 752 | - } |
|
| 753 | - else if ($method == 'replace') |
|
| 795 | + if ($method == 'replace') { |
|
| 796 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 797 | + } else { |
|
| 798 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
| 799 | + } |
|
| 800 | + } else if ($method == 'replace') |
|
| 754 | 801 | { |
| 755 | 802 | foreach ($columns as $columnName => $type) |
| 756 | 803 | { |
| 757 | 804 | // Are we restricting the length? |
| 758 | - if (strpos($type, 'string-') !== false) |
|
| 759 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 760 | - else |
|
| 761 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 805 | + if (strpos($type, 'string-') !== false) { |
|
| 806 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 807 | + } else { |
|
| 808 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 809 | + } |
|
| 762 | 810 | |
| 763 | 811 | // A key? That's what we were looking for. |
| 764 | - if (in_array($columnName, $keys)) |
|
| 765 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 812 | + if (in_array($columnName, $keys)) { |
|
| 813 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 814 | + } |
|
| 766 | 815 | $count++; |
| 767 | 816 | } |
| 768 | 817 | |
@@ -798,10 +847,11 @@ discard block |
||
| 798 | 847 | foreach ($columns as $columnName => $type) |
| 799 | 848 | { |
| 800 | 849 | // Are we restricting the length? |
| 801 | - if (strpos($type, 'string-') !== false) |
|
| 802 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 803 | - else |
|
| 804 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 850 | + if (strpos($type, 'string-') !== false) { |
|
| 851 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 852 | + } else { |
|
| 853 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 854 | + } |
|
| 805 | 855 | } |
| 806 | 856 | $insertData = substr($insertData, 0, -2) . ')'; |
| 807 | 857 | |
@@ -810,8 +860,9 @@ discard block |
||
| 810 | 860 | |
| 811 | 861 | // Here's where the variables are injected to the query. |
| 812 | 862 | $insertRows = array(); |
| 813 | - foreach ($data as $dataRow) |
|
| 814 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 863 | + foreach ($data as $dataRow) { |
|
| 864 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 865 | + } |
|
| 815 | 866 | |
| 816 | 867 | // Do the insert. |
| 817 | 868 | $request = $smcFunc['db_query']('', ' |
@@ -828,19 +879,21 @@ discard block |
||
| 828 | 879 | |
| 829 | 880 | if ($with_returning && $request !== false) |
| 830 | 881 | { |
| 831 | - if ($returnmode === 2) |
|
| 832 | - $return_var = array(); |
|
| 882 | + if ($returnmode === 2) { |
|
| 883 | + $return_var = array(); |
|
| 884 | + } |
|
| 833 | 885 | |
| 834 | 886 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
| 835 | 887 | { |
| 836 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
| 888 | + if (is_numeric($row[0])) { |
|
| 889 | + // try to emulate mysql limitation |
|
| 837 | 890 | { |
| 838 | 891 | if ($returnmode === 1) |
| 839 | 892 | $return_var = $row[0]; |
| 840 | - elseif ($returnmode === 2) |
|
| 841 | - $return_var[] = $row[0]; |
|
| 842 | - } |
|
| 843 | - else |
|
| 893 | + } elseif ($returnmode === 2) { |
|
| 894 | + $return_var[] = $row[0]; |
|
| 895 | + } |
|
| 896 | + } else |
|
| 844 | 897 | { |
| 845 | 898 | $with_returning = false; |
| 846 | 899 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -849,9 +902,10 @@ discard block |
||
| 849 | 902 | } |
| 850 | 903 | } |
| 851 | 904 | |
| 852 | - if ($with_returning && !empty($return_var)) |
|
| 853 | - return $return_var; |
|
| 854 | -} |
|
| 905 | + if ($with_returning && !empty($return_var)) { |
|
| 906 | + return $return_var; |
|
| 907 | + } |
|
| 908 | + } |
|
| 855 | 909 | |
| 856 | 910 | /** |
| 857 | 911 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -888,8 +942,9 @@ discard block |
||
| 888 | 942 | */ |
| 889 | 943 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 890 | 944 | { |
| 891 | - if (empty($log_message)) |
|
| 892 | - $log_message = $error_message; |
|
| 945 | + if (empty($log_message)) { |
|
| 946 | + $log_message = $error_message; |
|
| 947 | + } |
|
| 893 | 948 | |
| 894 | 949 | foreach (debug_backtrace() as $step) |
| 895 | 950 | { |
@@ -908,12 +963,14 @@ discard block |
||
| 908 | 963 | } |
| 909 | 964 | |
| 910 | 965 | // A special case - we want the file and line numbers for debugging. |
| 911 | - if ($error_type == 'return') |
|
| 912 | - return array($file, $line); |
|
| 966 | + if ($error_type == 'return') { |
|
| 967 | + return array($file, $line); |
|
| 968 | + } |
|
| 913 | 969 | |
| 914 | 970 | // Is always a critical error. |
| 915 | - if (function_exists('log_error')) |
|
| 916 | - log_error($log_message, 'critical', $file, $line); |
|
| 971 | + if (function_exists('log_error')) { |
|
| 972 | + log_error($log_message, 'critical', $file, $line); |
|
| 973 | + } |
|
| 917 | 974 | |
| 918 | 975 | if (function_exists('fatal_error')) |
| 919 | 976 | { |
@@ -921,12 +978,12 @@ discard block |
||
| 921 | 978 | |
| 922 | 979 | // Cannot continue... |
| 923 | 980 | exit; |
| 981 | + } elseif ($error_type) { |
|
| 982 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 983 | + } else { |
|
| 984 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 985 | + } |
|
| 924 | 986 | } |
| 925 | - elseif ($error_type) |
|
| 926 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 927 | - else |
|
| 928 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 929 | -} |
|
| 930 | 987 | |
| 931 | 988 | /** |
| 932 | 989 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -943,10 +1000,11 @@ discard block |
||
| 943 | 1000 | '\\' => '\\\\', |
| 944 | 1001 | ); |
| 945 | 1002 | |
| 946 | - if ($translate_human_wildcards) |
|
| 947 | - $replacements += array( |
|
| 1003 | + if ($translate_human_wildcards) { |
|
| 1004 | + $replacements += array( |
|
| 948 | 1005 | '*' => '%', |
| 949 | 1006 | ); |
| 1007 | + } |
|
| 950 | 1008 | |
| 951 | 1009 | return strtr($string, $replacements); |
| 952 | 1010 | } |
@@ -975,14 +1033,16 @@ discard block |
||
| 975 | 1033 | static $pg_error_data_prep; |
| 976 | 1034 | |
| 977 | 1035 | // without database we can't do anything |
| 978 | - if (empty($db_connection)) |
|
| 979 | - return; |
|
| 1036 | + if (empty($db_connection)) { |
|
| 1037 | + return; |
|
| 1038 | + } |
|
| 980 | 1039 | |
| 981 | - if (empty($pg_error_data_prep)) |
|
| 982 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
| 1040 | + if (empty($pg_error_data_prep)) { |
|
| 1041 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
| 983 | 1042 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
| 984 | 1043 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10)' |
| 985 | 1044 | ); |
| 1045 | + } |
|
| 986 | 1046 | |
| 987 | 1047 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
| 988 | 1048 | } |
@@ -1002,8 +1062,9 @@ discard block |
||
| 1002 | 1062 | $count = count($array_values); |
| 1003 | 1063 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1004 | 1064 | |
| 1005 | - for ($i = 0; $i < $count; $i++) |
|
| 1006 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1065 | + for ($i = 0; $i < $count; $i++) { |
|
| 1066 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1067 | + } |
|
| 1007 | 1068 | |
| 1008 | 1069 | $return .= 'END'; |
| 1009 | 1070 | return $return; |
@@ -1026,11 +1087,13 @@ discard block |
||
| 1026 | 1087 | //pg 9.5 got replace support |
| 1027 | 1088 | $pg_version = $smcFunc['db_get_version'](); |
| 1028 | 1089 | // if we got a Beta Version |
| 1029 | - if (stripos($pg_version, 'beta') !== false) |
|
| 1030 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 1090 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 1091 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 1092 | + } |
|
| 1031 | 1093 | // or RC |
| 1032 | - if (stripos($pg_version, 'rc') !== false) |
|
| 1033 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 1094 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 1095 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 1096 | + } |
|
| 1034 | 1097 | |
| 1035 | 1098 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
| 1036 | 1099 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * This function works out what to do! |
@@ -24,9 +25,9 @@ discard block |
||
| 24 | 25 | global $time_start, $smcFunc; |
| 25 | 26 | |
| 26 | 27 | // Special case for doing the mail queue. |
| 27 | - if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') |
|
| 28 | - ReduceMailQueue(); |
|
| 29 | - else |
|
| 28 | + if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') { |
|
| 29 | + ReduceMailQueue(); |
|
| 30 | + } else |
|
| 30 | 31 | { |
| 31 | 32 | $task_string = ''; |
| 32 | 33 | |
@@ -53,18 +54,20 @@ discard block |
||
| 53 | 54 | |
| 54 | 55 | // How long in seconds it the gap? |
| 55 | 56 | $duration = $row['time_regularity']; |
| 56 | - if ($row['time_unit'] == 'm') |
|
| 57 | - $duration *= 60; |
|
| 58 | - elseif ($row['time_unit'] == 'h') |
|
| 59 | - $duration *= 3600; |
|
| 60 | - elseif ($row['time_unit'] == 'd') |
|
| 61 | - $duration *= 86400; |
|
| 62 | - elseif ($row['time_unit'] == 'w') |
|
| 63 | - $duration *= 604800; |
|
| 57 | + if ($row['time_unit'] == 'm') { |
|
| 58 | + $duration *= 60; |
|
| 59 | + } elseif ($row['time_unit'] == 'h') { |
|
| 60 | + $duration *= 3600; |
|
| 61 | + } elseif ($row['time_unit'] == 'd') { |
|
| 62 | + $duration *= 86400; |
|
| 63 | + } elseif ($row['time_unit'] == 'w') { |
|
| 64 | + $duration *= 604800; |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | // If we were really late running this task actually skip the next one. |
| 66 | - if (time() + ($duration / 2) > $next_time) |
|
| 67 | - $next_time += $duration; |
|
| 68 | + if (time() + ($duration / 2) > $next_time) { |
|
| 69 | + $next_time += $duration; |
|
| 70 | + } |
|
| 68 | 71 | |
| 69 | 72 | // Update it now, so no others run this! |
| 70 | 73 | $smcFunc['db_query']('', ' |
@@ -81,16 +84,19 @@ discard block |
||
| 81 | 84 | $affected_rows = $smcFunc['db_affected_rows'](); |
| 82 | 85 | |
| 83 | 86 | // What kind of task are we handling? |
| 84 | - if (!empty($row['callable'])) |
|
| 85 | - $task_string = $row['callable']; |
|
| 87 | + if (!empty($row['callable'])) { |
|
| 88 | + $task_string = $row['callable']; |
|
| 89 | + } |
|
| 86 | 90 | |
| 87 | 91 | // Default SMF task or old mods? |
| 88 | - elseif (function_exists('scheduled_' . $row['task'])) |
|
| 89 | - $task_string = 'scheduled_' . $row['task']; |
|
| 92 | + elseif (function_exists('scheduled_' . $row['task'])) { |
|
| 93 | + $task_string = 'scheduled_' . $row['task']; |
|
| 94 | + } |
|
| 90 | 95 | |
| 91 | 96 | // One last resource, the task name. |
| 92 | - elseif (!empty($row['task'])) |
|
| 93 | - $task_string = $row['task']; |
|
| 97 | + elseif (!empty($row['task'])) { |
|
| 98 | + $task_string = $row['task']; |
|
| 99 | + } |
|
| 94 | 100 | |
| 95 | 101 | // The function must exist or we are wasting our time, plus do some timestamp checking, and database check! |
| 96 | 102 | if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows) |
@@ -101,11 +107,11 @@ discard block |
||
| 101 | 107 | $callable_task = call_helper($task_string, true); |
| 102 | 108 | |
| 103 | 109 | // Perform the task. |
| 104 | - if (!empty($callable_task)) |
|
| 105 | - $completed = call_user_func($callable_task); |
|
| 106 | - |
|
| 107 | - else |
|
| 108 | - $completed = false; |
|
| 110 | + if (!empty($callable_task)) { |
|
| 111 | + $completed = call_user_func($callable_task); |
|
| 112 | + } else { |
|
| 113 | + $completed = false; |
|
| 114 | + } |
|
| 109 | 115 | |
| 110 | 116 | // Log that we did it ;) |
| 111 | 117 | if ($completed) |
@@ -138,18 +144,20 @@ discard block |
||
| 138 | 144 | ) |
| 139 | 145 | ); |
| 140 | 146 | // No new task scheduled yet? |
| 141 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 142 | - $nextEvent = time() + 86400; |
|
| 143 | - else |
|
| 144 | - list ($nextEvent) = $smcFunc['db_fetch_row']($request); |
|
| 147 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 148 | + $nextEvent = time() + 86400; |
|
| 149 | + } else { |
|
| 150 | + list ($nextEvent) = $smcFunc['db_fetch_row']($request); |
|
| 151 | + } |
|
| 145 | 152 | $smcFunc['db_free_result']($request); |
| 146 | 153 | |
| 147 | 154 | updateSettings(array('next_task_time' => $nextEvent)); |
| 148 | 155 | } |
| 149 | 156 | |
| 150 | 157 | // Shall we return? |
| 151 | - if (!isset($_GET['scheduled'])) |
|
| 152 | - return true; |
|
| 158 | + if (!isset($_GET['scheduled'])) { |
|
| 159 | + return true; |
|
| 160 | + } |
|
| 153 | 161 | |
| 154 | 162 | // Finally, send some stuff... |
| 155 | 163 | header('expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -181,16 +189,18 @@ discard block |
||
| 181 | 189 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 182 | 190 | { |
| 183 | 191 | // If this is no longer around we'll ignore it. |
| 184 | - if (empty($row['id_topic'])) |
|
| 185 | - continue; |
|
| 192 | + if (empty($row['id_topic'])) { |
|
| 193 | + continue; |
|
| 194 | + } |
|
| 186 | 195 | |
| 187 | 196 | // What type is it? |
| 188 | - if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) |
|
| 189 | - $type = 'topic'; |
|
| 190 | - elseif ($row['id_attach']) |
|
| 191 | - $type = 'attach'; |
|
| 192 | - else |
|
| 193 | - $type = 'msg'; |
|
| 197 | + if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) { |
|
| 198 | + $type = 'topic'; |
|
| 199 | + } elseif ($row['id_attach']) { |
|
| 200 | + $type = 'attach'; |
|
| 201 | + } else { |
|
| 202 | + $type = 'msg'; |
|
| 203 | + } |
|
| 194 | 204 | |
| 195 | 205 | // Add it to the array otherwise. |
| 196 | 206 | $notices[$row['id_board']][$type][] = array( |
@@ -211,8 +221,9 @@ discard block |
||
| 211 | 221 | ); |
| 212 | 222 | |
| 213 | 223 | // If nothing quit now. |
| 214 | - if (empty($notices)) |
|
| 215 | - return true; |
|
| 224 | + if (empty($notices)) { |
|
| 225 | + return true; |
|
| 226 | + } |
|
| 216 | 227 | |
| 217 | 228 | // Now we need to think about finding out *who* can approve - this is hard! |
| 218 | 229 | |
@@ -231,14 +242,16 @@ discard block |
||
| 231 | 242 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 232 | 243 | { |
| 233 | 244 | // Sorry guys, but we have to ignore guests AND members - it would be too many otherwise. |
| 234 | - if ($row['id_group'] < 2) |
|
| 235 | - continue; |
|
| 245 | + if ($row['id_group'] < 2) { |
|
| 246 | + continue; |
|
| 247 | + } |
|
| 236 | 248 | |
| 237 | 249 | $perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group']; |
| 238 | 250 | |
| 239 | 251 | // Anyone who can access has to be considered. |
| 240 | - if ($row['add_deny']) |
|
| 241 | - $addGroups[] = $row['id_group']; |
|
| 252 | + if ($row['add_deny']) { |
|
| 253 | + $addGroups[] = $row['id_group']; |
|
| 254 | + } |
|
| 242 | 255 | } |
| 243 | 256 | $smcFunc['db_free_result']($request); |
| 244 | 257 | |
@@ -283,8 +296,9 @@ discard block |
||
| 283 | 296 | if (!empty($row['mod_prefs'])) |
| 284 | 297 | { |
| 285 | 298 | list(,, $pref_binary) = explode('|', $row['mod_prefs']); |
| 286 | - if (!($pref_binary & 4)) |
|
| 287 | - continue; |
|
| 299 | + if (!($pref_binary & 4)) { |
|
| 300 | + continue; |
|
| 301 | + } |
|
| 288 | 302 | } |
| 289 | 303 | |
| 290 | 304 | $members[$row['id_member']] = array( |
@@ -309,8 +323,9 @@ discard block |
||
| 309 | 323 | $emailbody = ''; |
| 310 | 324 | |
| 311 | 325 | // Load the language file as required. |
| 312 | - if (empty($current_language) || $current_language != $member['language']) |
|
| 313 | - $current_language = loadLanguage('EmailTemplates', $member['language'], false); |
|
| 326 | + if (empty($current_language) || $current_language != $member['language']) { |
|
| 327 | + $current_language = loadLanguage('EmailTemplates', $member['language'], false); |
|
| 328 | + } |
|
| 314 | 329 | |
| 315 | 330 | // Loop through each notice... |
| 316 | 331 | foreach ($notices as $board => $notice) |
@@ -318,29 +333,34 @@ discard block |
||
| 318 | 333 | $access = false; |
| 319 | 334 | |
| 320 | 335 | // Can they mod in this board? |
| 321 | - if (isset($mods[$id][$board])) |
|
| 322 | - $access = true; |
|
| 336 | + if (isset($mods[$id][$board])) { |
|
| 337 | + $access = true; |
|
| 338 | + } |
|
| 323 | 339 | |
| 324 | 340 | // Do the group check... |
| 325 | 341 | if (!$access && isset($perms[$profiles[$board]]['add'])) |
| 326 | 342 | { |
| 327 | 343 | // They can access?! |
| 328 | - if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) |
|
| 329 | - $access = true; |
|
| 344 | + if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) { |
|
| 345 | + $access = true; |
|
| 346 | + } |
|
| 330 | 347 | |
| 331 | 348 | // If they have deny rights don't consider them! |
| 332 | - if (isset($perms[$profiles[$board]]['deny'])) |
|
| 333 | - if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups'])) |
|
| 349 | + if (isset($perms[$profiles[$board]]['deny'])) { |
|
| 350 | + if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups'])) |
|
| 334 | 351 | $access = false; |
| 352 | + } |
|
| 335 | 353 | } |
| 336 | 354 | |
| 337 | 355 | // Finally, fix it for admins! |
| 338 | - if (in_array(1, $member['groups'])) |
|
| 339 | - $access = true; |
|
| 356 | + if (in_array(1, $member['groups'])) { |
|
| 357 | + $access = true; |
|
| 358 | + } |
|
| 340 | 359 | |
| 341 | 360 | // If they can't access it then give it a break! |
| 342 | - if (!$access) |
|
| 343 | - continue; |
|
| 361 | + if (!$access) { |
|
| 362 | + continue; |
|
| 363 | + } |
|
| 344 | 364 | |
| 345 | 365 | foreach ($notice as $type => $items) |
| 346 | 366 | { |
@@ -348,15 +368,17 @@ discard block |
||
| 348 | 368 | $emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" . |
| 349 | 369 | '------------------------------------------------------' . "\n"; |
| 350 | 370 | |
| 351 | - foreach ($items as $item) |
|
| 352 | - $emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n"; |
|
| 371 | + foreach ($items as $item) { |
|
| 372 | + $emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n"; |
|
| 373 | + } |
|
| 353 | 374 | |
| 354 | 375 | $emailbody .= "\n"; |
| 355 | 376 | } |
| 356 | 377 | } |
| 357 | 378 | |
| 358 | - if ($emailbody == '') |
|
| 359 | - continue; |
|
| 379 | + if ($emailbody == '') { |
|
| 380 | + continue; |
|
| 381 | + } |
|
| 360 | 382 | |
| 361 | 383 | $replacements = array( |
| 362 | 384 | 'REALNAME' => $member['name'], |
@@ -397,8 +419,9 @@ discard block |
||
| 397 | 419 | ) |
| 398 | 420 | ); |
| 399 | 421 | $members = array(); |
| 400 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 401 | - $members[$row['id_member']] = $row['warning']; |
|
| 422 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 423 | + $members[$row['id_member']] = $row['warning']; |
|
| 424 | + } |
|
| 402 | 425 | $smcFunc['db_free_result']($request); |
| 403 | 426 | |
| 404 | 427 | // Have some members to check? |
@@ -420,17 +443,18 @@ discard block |
||
| 420 | 443 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 421 | 444 | { |
| 422 | 445 | // More than 24 hours ago? |
| 423 | - if ($row['last_warning'] <= time() - 86400) |
|
| 424 | - $member_changes[] = array( |
|
| 446 | + if ($row['last_warning'] <= time() - 86400) { |
|
| 447 | + $member_changes[] = array( |
|
| 425 | 448 | 'id' => $row['id_recipient'], |
| 426 | 449 | 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0, |
| 427 | 450 | ); |
| 451 | + } |
|
| 428 | 452 | } |
| 429 | 453 | $smcFunc['db_free_result']($request); |
| 430 | 454 | |
| 431 | 455 | // Have some members to change? |
| 432 | - if (!empty($member_changes)) |
|
| 433 | - foreach ($member_changes as $change) |
|
| 456 | + if (!empty($member_changes)) { |
|
| 457 | + foreach ($member_changes as $change) |
|
| 434 | 458 | $smcFunc['db_query']('', ' |
| 435 | 459 | UPDATE {db_prefix}members |
| 436 | 460 | SET warning = {int:warning} |
@@ -440,6 +464,7 @@ discard block |
||
| 440 | 464 | 'id_member' => $change['id'], |
| 441 | 465 | ) |
| 442 | 466 | ); |
| 467 | + } |
|
| 443 | 468 | } |
| 444 | 469 | } |
| 445 | 470 | |
@@ -519,15 +544,17 @@ discard block |
||
| 519 | 544 | |
| 520 | 545 | // Store this useful data! |
| 521 | 546 | $boards[$row['id_board']] = $row['id_board']; |
| 522 | - if ($row['id_topic']) |
|
| 523 | - $notify['topics'][$row['id_topic']][] = $row['id_member']; |
|
| 524 | - else |
|
| 525 | - $notify['boards'][$row['id_board']][] = $row['id_member']; |
|
| 547 | + if ($row['id_topic']) { |
|
| 548 | + $notify['topics'][$row['id_topic']][] = $row['id_member']; |
|
| 549 | + } else { |
|
| 550 | + $notify['boards'][$row['id_board']][] = $row['id_member']; |
|
| 551 | + } |
|
| 526 | 552 | } |
| 527 | 553 | $smcFunc['db_free_result']($request); |
| 528 | 554 | |
| 529 | - if (empty($boards)) |
|
| 530 | - return true; |
|
| 555 | + if (empty($boards)) { |
|
| 556 | + return true; |
|
| 557 | + } |
|
| 531 | 558 | |
| 532 | 559 | // Just get the board names. |
| 533 | 560 | $request = $smcFunc['db_query']('', ' |
@@ -539,12 +566,14 @@ discard block |
||
| 539 | 566 | ) |
| 540 | 567 | ); |
| 541 | 568 | $boards = array(); |
| 542 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 543 | - $boards[$row['id_board']] = $row['name']; |
|
| 569 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 570 | + $boards[$row['id_board']] = $row['name']; |
|
| 571 | + } |
|
| 544 | 572 | $smcFunc['db_free_result']($request); |
| 545 | 573 | |
| 546 | - if (empty($boards)) |
|
| 547 | - return true; |
|
| 574 | + if (empty($boards)) { |
|
| 575 | + return true; |
|
| 576 | + } |
|
| 548 | 577 | |
| 549 | 578 | // Get the actual topics... |
| 550 | 579 | $request = $smcFunc['db_query']('', ' |
@@ -564,52 +593,57 @@ discard block |
||
| 564 | 593 | $types = array(); |
| 565 | 594 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 566 | 595 | { |
| 567 | - if (!isset($types[$row['note_type']][$row['id_board']])) |
|
| 568 | - $types[$row['note_type']][$row['id_board']] = array( |
|
| 596 | + if (!isset($types[$row['note_type']][$row['id_board']])) { |
|
| 597 | + $types[$row['note_type']][$row['id_board']] = array( |
|
| 569 | 598 | 'lines' => array(), |
| 570 | 599 | 'name' => $row['board_name'], |
| 571 | 600 | 'id' => $row['id_board'], |
| 572 | 601 | ); |
| 602 | + } |
|
| 573 | 603 | |
| 574 | 604 | if ($row['note_type'] == 'reply') |
| 575 | 605 | { |
| 576 | - if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) |
|
| 577 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++; |
|
| 578 | - else |
|
| 579 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 606 | + if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) { |
|
| 607 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++; |
|
| 608 | + } else { |
|
| 609 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 580 | 610 | 'id' => $row['id_topic'], |
| 581 | 611 | 'subject' => un_htmlspecialchars($row['subject']), |
| 582 | 612 | 'count' => 1, |
| 583 | 613 | ); |
| 584 | - } |
|
| 585 | - elseif ($row['note_type'] == 'topic') |
|
| 614 | + } |
|
| 615 | + } elseif ($row['note_type'] == 'topic') |
|
| 586 | 616 | { |
| 587 | - if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) |
|
| 588 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 617 | + if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) { |
|
| 618 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 589 | 619 | 'id' => $row['id_topic'], |
| 590 | 620 | 'subject' => un_htmlspecialchars($row['subject']), |
| 591 | 621 | ); |
| 592 | - } |
|
| 593 | - else |
|
| 622 | + } |
|
| 623 | + } else |
|
| 594 | 624 | { |
| 595 | - if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) |
|
| 596 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 625 | + if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) { |
|
| 626 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 597 | 627 | 'id' => $row['id_topic'], |
| 598 | 628 | 'subject' => un_htmlspecialchars($row['subject']), |
| 599 | 629 | 'starter' => $row['id_member_started'], |
| 600 | 630 | ); |
| 631 | + } |
|
| 601 | 632 | } |
| 602 | 633 | |
| 603 | 634 | $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array(); |
| 604 | - if (!empty($notify['topics'][$row['id_topic']])) |
|
| 605 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]); |
|
| 606 | - if (!empty($notify['boards'][$row['id_board']])) |
|
| 607 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]); |
|
| 635 | + if (!empty($notify['topics'][$row['id_topic']])) { |
|
| 636 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]); |
|
| 637 | + } |
|
| 638 | + if (!empty($notify['boards'][$row['id_board']])) { |
|
| 639 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]); |
|
| 640 | + } |
|
| 608 | 641 | } |
| 609 | 642 | $smcFunc['db_free_result']($request); |
| 610 | 643 | |
| 611 | - if (empty($types)) |
|
| 612 | - return true; |
|
| 644 | + if (empty($types)) { |
|
| 645 | + return true; |
|
| 646 | + } |
|
| 613 | 647 | |
| 614 | 648 | // Let's load all the languages into a cache thingy. |
| 615 | 649 | $langtxt = array(); |
@@ -651,8 +685,9 @@ discard block |
||
| 651 | 685 | $notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1; |
| 652 | 686 | |
| 653 | 687 | // Did they not elect to choose this? |
| 654 | - if ($frequency < 3 || $frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) |
|
| 655 | - continue; |
|
| 688 | + if ($frequency < 3 || $frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) { |
|
| 689 | + continue; |
|
| 690 | + } |
|
| 656 | 691 | |
| 657 | 692 | // Right character set! |
| 658 | 693 | $context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set']; |
@@ -668,39 +703,43 @@ discard block |
||
| 668 | 703 | if (isset($types['topic'])) |
| 669 | 704 | { |
| 670 | 705 | $titled = false; |
| 671 | - foreach ($types['topic'] as $id => $board) |
|
| 672 | - foreach ($board['lines'] as $topic) |
|
| 706 | + foreach ($types['topic'] as $id => $board) { |
|
| 707 | + foreach ($board['lines'] as $topic) |
|
| 673 | 708 | if (in_array($mid, $topic['members'])) |
| 674 | 709 | { |
| 675 | 710 | if (!$titled) |
| 676 | 711 | { |
| 677 | 712 | $email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------'; |
| 713 | + } |
|
| 678 | 714 | $titled = true; |
| 679 | 715 | } |
| 680 | 716 | $email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']); |
| 681 | 717 | } |
| 682 | - if ($titled) |
|
| 683 | - $email['body'] .= "\n"; |
|
| 718 | + if ($titled) { |
|
| 719 | + $email['body'] .= "\n"; |
|
| 720 | + } |
|
| 684 | 721 | } |
| 685 | 722 | |
| 686 | 723 | // What about replies? |
| 687 | 724 | if (isset($types['reply'])) |
| 688 | 725 | { |
| 689 | 726 | $titled = false; |
| 690 | - foreach ($types['reply'] as $id => $board) |
|
| 691 | - foreach ($board['lines'] as $topic) |
|
| 727 | + foreach ($types['reply'] as $id => $board) { |
|
| 728 | + foreach ($board['lines'] as $topic) |
|
| 692 | 729 | if (in_array($mid, $topic['members'])) |
| 693 | 730 | { |
| 694 | 731 | if (!$titled) |
| 695 | 732 | { |
| 696 | 733 | $email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------'; |
| 734 | + } |
|
| 697 | 735 | $titled = true; |
| 698 | 736 | } |
| 699 | 737 | $email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject'])); |
| 700 | 738 | } |
| 701 | 739 | |
| 702 | - if ($titled) |
|
| 703 | - $email['body'] .= "\n"; |
|
| 740 | + if ($titled) { |
|
| 741 | + $email['body'] .= "\n"; |
|
| 742 | + } |
|
| 704 | 743 | } |
| 705 | 744 | |
| 706 | 745 | // Finally, moderation actions! |
@@ -709,24 +748,27 @@ discard block |
||
| 709 | 748 | $titled = false; |
| 710 | 749 | foreach ($types as $note_type => $type) |
| 711 | 750 | { |
| 712 | - if ($note_type == 'topic' || $note_type == 'reply') |
|
| 713 | - continue; |
|
| 751 | + if ($note_type == 'topic' || $note_type == 'reply') { |
|
| 752 | + continue; |
|
| 753 | + } |
|
| 714 | 754 | |
| 715 | - foreach ($type as $id => $board) |
|
| 716 | - foreach ($board['lines'] as $topic) |
|
| 755 | + foreach ($type as $id => $board) { |
|
| 756 | + foreach ($board['lines'] as $topic) |
|
| 717 | 757 | if (in_array($mid, $topic['members'])) |
| 718 | 758 | { |
| 719 | 759 | if (!$titled) |
| 720 | 760 | { |
| 721 | 761 | $email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------'; |
| 762 | + } |
|
| 722 | 763 | $titled = true; |
| 723 | 764 | } |
| 724 | 765 | $email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']); |
| 725 | 766 | } |
| 726 | 767 | } |
| 727 | 768 | } |
| 728 | - if ($titled) |
|
| 729 | - $email['body'] .= "\n"; |
|
| 769 | + if ($titled) { |
|
| 770 | + $email['body'] .= "\n"; |
|
| 771 | + } |
|
| 730 | 772 | |
| 731 | 773 | // Then just say our goodbyes! |
| 732 | 774 | $email['body'] .= "\n\n" . $txt['regards_team']; |
@@ -756,8 +798,7 @@ discard block |
||
| 756 | 798 | 'not_daily' => 0, |
| 757 | 799 | ) |
| 758 | 800 | ); |
| 759 | - } |
|
| 760 | - else |
|
| 801 | + } else |
|
| 761 | 802 | { |
| 762 | 803 | // Clear any only weekly ones, and stop us from sending daily again. |
| 763 | 804 | $smcFunc['db_query']('', ' |
@@ -821,16 +862,19 @@ discard block |
||
| 821 | 862 | global $modSettings, $smcFunc, $sourcedir; |
| 822 | 863 | |
| 823 | 864 | // Are we intending another script to be sending out the queue? |
| 824 | - if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) |
|
| 825 | - return false; |
|
| 865 | + if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) { |
|
| 866 | + return false; |
|
| 867 | + } |
|
| 826 | 868 | |
| 827 | 869 | // By default send 5 at once. |
| 828 | - if (!$number) |
|
| 829 | - $number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity']; |
|
| 870 | + if (!$number) { |
|
| 871 | + $number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity']; |
|
| 872 | + } |
|
| 830 | 873 | |
| 831 | 874 | // If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us. |
| 832 | - if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) |
|
| 833 | - return false; |
|
| 875 | + if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) { |
|
| 876 | + return false; |
|
| 877 | + } |
|
| 834 | 878 | |
| 835 | 879 | // By default move the next sending on by 10 seconds, and require an affected row. |
| 836 | 880 | if (!$override_limit) |
@@ -847,8 +891,9 @@ discard block |
||
| 847 | 891 | 'last_send' => $modSettings['mail_next_send'], |
| 848 | 892 | ) |
| 849 | 893 | ); |
| 850 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 851 | - return false; |
|
| 894 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 895 | + return false; |
|
| 896 | + } |
|
| 852 | 897 | $modSettings['mail_next_send'] = time() + $delay; |
| 853 | 898 | } |
| 854 | 899 | |
@@ -869,8 +914,9 @@ discard block |
||
| 869 | 914 | $mn += $number; |
| 870 | 915 | } |
| 871 | 916 | // No more I'm afraid, return! |
| 872 | - else |
|
| 873 | - return false; |
|
| 917 | + else { |
|
| 918 | + return false; |
|
| 919 | + } |
|
| 874 | 920 | |
| 875 | 921 | // Reflect that we're about to send some, do it now to be safe. |
| 876 | 922 | updateSettings(array('mail_recent' => $mt . '|' . $mn)); |
@@ -905,14 +951,15 @@ discard block |
||
| 905 | 951 | $smcFunc['db_free_result']($request); |
| 906 | 952 | |
| 907 | 953 | // Delete, delete, delete!!! |
| 908 | - if (!empty($ids)) |
|
| 909 | - $smcFunc['db_query']('', ' |
|
| 954 | + if (!empty($ids)) { |
|
| 955 | + $smcFunc['db_query']('', ' |
|
| 910 | 956 | DELETE FROM {db_prefix}mail_queue |
| 911 | 957 | WHERE id_mail IN ({array_int:mail_list})', |
| 912 | 958 | array( |
| 913 | 959 | 'mail_list' => $ids, |
| 914 | 960 | ) |
| 915 | 961 | ); |
| 962 | + } |
|
| 916 | 963 | |
| 917 | 964 | // Don't believe we have any left? |
| 918 | 965 | if (count($ids) < $number) |
@@ -930,11 +977,13 @@ discard block |
||
| 930 | 977 | ); |
| 931 | 978 | } |
| 932 | 979 | |
| 933 | - if (empty($ids)) |
|
| 934 | - return false; |
|
| 980 | + if (empty($ids)) { |
|
| 981 | + return false; |
|
| 982 | + } |
|
| 935 | 983 | |
| 936 | - if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') |
|
| 937 | - require_once($sourcedir . '/Subs-Post.php'); |
|
| 984 | + if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') { |
|
| 985 | + require_once($sourcedir . '/Subs-Post.php'); |
|
| 986 | + } |
|
| 938 | 987 | |
| 939 | 988 | // Send each email, yea! |
| 940 | 989 | $failed_emails = array(); |
@@ -954,15 +1003,17 @@ discard block |
||
| 954 | 1003 | |
| 955 | 1004 | // Try to stop a timeout, this would be bad... |
| 956 | 1005 | @set_time_limit(300); |
| 957 | - if (function_exists('apache_reset_timeout')) |
|
| 958 | - @apache_reset_timeout(); |
|
| 1006 | + if (function_exists('apache_reset_timeout')) { |
|
| 1007 | + @apache_reset_timeout(); |
|
| 1008 | + } |
|
| 1009 | + } else { |
|
| 1010 | + $result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']); |
|
| 959 | 1011 | } |
| 960 | - else |
|
| 961 | - $result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']); |
|
| 962 | 1012 | |
| 963 | 1013 | // Hopefully it sent? |
| 964 | - if (!$result) |
|
| 965 | - $failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']); |
|
| 1014 | + if (!$result) { |
|
| 1015 | + $failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']); |
|
| 1016 | + } |
|
| 966 | 1017 | } |
| 967 | 1018 | |
| 968 | 1019 | // Any emails that didn't send? |
@@ -977,8 +1028,8 @@ discard block |
||
| 977 | 1028 | ); |
| 978 | 1029 | |
| 979 | 1030 | // If we have failed to many times, tell mail to wait a bit and try again. |
| 980 | - if ($modSettings['mail_failed_attempts'] > 5) |
|
| 981 | - $smcFunc['db_query']('', ' |
|
| 1031 | + if ($modSettings['mail_failed_attempts'] > 5) { |
|
| 1032 | + $smcFunc['db_query']('', ' |
|
| 982 | 1033 | UPDATE {db_prefix}settings |
| 983 | 1034 | SET value = {string:next_mail_send} |
| 984 | 1035 | WHERE variable = {literal:mail_next_send} |
@@ -987,6 +1038,7 @@ discard block |
||
| 987 | 1038 | 'next_mail_send' => time() + 60, |
| 988 | 1039 | 'last_send' => $modSettings['mail_next_send'], |
| 989 | 1040 | )); |
| 1041 | + } |
|
| 990 | 1042 | |
| 991 | 1043 | // Add our email back to the queue, manually. |
| 992 | 1044 | $smcFunc['db_insert']('insert', |
@@ -999,8 +1051,8 @@ discard block |
||
| 999 | 1051 | return false; |
| 1000 | 1052 | } |
| 1001 | 1053 | // We where unable to send the email, clear our failed attempts. |
| 1002 | - elseif (!empty($modSettings['mail_failed_attempts'])) |
|
| 1003 | - $smcFunc['db_query']('', ' |
|
| 1054 | + elseif (!empty($modSettings['mail_failed_attempts'])) { |
|
| 1055 | + $smcFunc['db_query']('', ' |
|
| 1004 | 1056 | UPDATE {db_prefix}settings |
| 1005 | 1057 | SET value = {string:zero} |
| 1006 | 1058 | WHERE variable = {string:mail_failed_attempts}', |
@@ -1008,6 +1060,7 @@ discard block |
||
| 1008 | 1060 | 'zero' => '0', |
| 1009 | 1061 | 'mail_failed_attempts' => 'mail_failed_attempts', |
| 1010 | 1062 | )); |
| 1063 | + } |
|
| 1011 | 1064 | |
| 1012 | 1065 | // Had something to send... |
| 1013 | 1066 | return true; |
@@ -1024,16 +1077,18 @@ discard block |
||
| 1024 | 1077 | global $modSettings, $smcFunc; |
| 1025 | 1078 | |
| 1026 | 1079 | $task_query = ''; |
| 1027 | - if (!is_array($tasks)) |
|
| 1028 | - $tasks = array($tasks); |
|
| 1080 | + if (!is_array($tasks)) { |
|
| 1081 | + $tasks = array($tasks); |
|
| 1082 | + } |
|
| 1029 | 1083 | |
| 1030 | 1084 | // Actually have something passed? |
| 1031 | 1085 | if (!empty($tasks)) |
| 1032 | 1086 | { |
| 1033 | - if (!isset($tasks[0]) || is_numeric($tasks[0])) |
|
| 1034 | - $task_query = ' AND id_task IN ({array_int:tasks})'; |
|
| 1035 | - else |
|
| 1036 | - $task_query = ' AND task IN ({array_string:tasks})'; |
|
| 1087 | + if (!isset($tasks[0]) || is_numeric($tasks[0])) { |
|
| 1088 | + $task_query = ' AND id_task IN ({array_int:tasks})'; |
|
| 1089 | + } else { |
|
| 1090 | + $task_query = ' AND task IN ({array_string:tasks})'; |
|
| 1091 | + } |
|
| 1037 | 1092 | } |
| 1038 | 1093 | $nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time']; |
| 1039 | 1094 | |
@@ -1054,20 +1109,22 @@ discard block |
||
| 1054 | 1109 | $next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']); |
| 1055 | 1110 | |
| 1056 | 1111 | // Only bother moving the task if it's out of place or we're forcing it! |
| 1057 | - if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) |
|
| 1058 | - $tasks[$row['id_task']] = $next_time; |
|
| 1059 | - else |
|
| 1060 | - $next_time = $row['next_time']; |
|
| 1112 | + if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) { |
|
| 1113 | + $tasks[$row['id_task']] = $next_time; |
|
| 1114 | + } else { |
|
| 1115 | + $next_time = $row['next_time']; |
|
| 1116 | + } |
|
| 1061 | 1117 | |
| 1062 | 1118 | // If this is sooner than the current next task, make this the next task. |
| 1063 | - if ($next_time < $nextTaskTime) |
|
| 1064 | - $nextTaskTime = $next_time; |
|
| 1119 | + if ($next_time < $nextTaskTime) { |
|
| 1120 | + $nextTaskTime = $next_time; |
|
| 1121 | + } |
|
| 1065 | 1122 | } |
| 1066 | 1123 | $smcFunc['db_free_result']($request); |
| 1067 | 1124 | |
| 1068 | 1125 | // Now make the changes! |
| 1069 | - foreach ($tasks as $id => $time) |
|
| 1070 | - $smcFunc['db_query']('', ' |
|
| 1126 | + foreach ($tasks as $id => $time) { |
|
| 1127 | + $smcFunc['db_query']('', ' |
|
| 1071 | 1128 | UPDATE {db_prefix}scheduled_tasks |
| 1072 | 1129 | SET next_time = {int:next_time} |
| 1073 | 1130 | WHERE id_task = {int:id_task}', |
@@ -1076,11 +1133,13 @@ discard block |
||
| 1076 | 1133 | 'id_task' => $id, |
| 1077 | 1134 | ) |
| 1078 | 1135 | ); |
| 1136 | + } |
|
| 1079 | 1137 | |
| 1080 | 1138 | // If the next task is now different update. |
| 1081 | - if ($modSettings['next_task_time'] != $nextTaskTime) |
|
| 1082 | - updateSettings(array('next_task_time' => $nextTaskTime)); |
|
| 1083 | -} |
|
| 1139 | + if ($modSettings['next_task_time'] != $nextTaskTime) { |
|
| 1140 | + updateSettings(array('next_task_time' => $nextTaskTime)); |
|
| 1141 | + } |
|
| 1142 | + } |
|
| 1084 | 1143 | |
| 1085 | 1144 | /** |
| 1086 | 1145 | * Simply returns a time stamp of the next instance of these time parameters. |
@@ -1093,8 +1152,9 @@ discard block |
||
| 1093 | 1152 | function next_time($regularity, $unit, $offset) |
| 1094 | 1153 | { |
| 1095 | 1154 | // Just in case! |
| 1096 | - if ($regularity == 0) |
|
| 1097 | - $regularity = 2; |
|
| 1155 | + if ($regularity == 0) { |
|
| 1156 | + $regularity = 2; |
|
| 1157 | + } |
|
| 1098 | 1158 | |
| 1099 | 1159 | $curMin = date('i', time()); |
| 1100 | 1160 | |
@@ -1104,15 +1164,16 @@ discard block |
||
| 1104 | 1164 | $off = date('i', $offset); |
| 1105 | 1165 | |
| 1106 | 1166 | // If it's now just pretend it ain't, |
| 1107 | - if ($off == $curMin) |
|
| 1108 | - $next_time = time() + $regularity; |
|
| 1109 | - else |
|
| 1167 | + if ($off == $curMin) { |
|
| 1168 | + $next_time = time() + $regularity; |
|
| 1169 | + } else |
|
| 1110 | 1170 | { |
| 1111 | 1171 | // Make sure that the offset is always in the past. |
| 1112 | 1172 | $off = $off > $curMin ? $off - 60 : $off; |
| 1113 | 1173 | |
| 1114 | - while ($off <= $curMin) |
|
| 1115 | - $off += $regularity; |
|
| 1174 | + while ($off <= $curMin) { |
|
| 1175 | + $off += $regularity; |
|
| 1176 | + } |
|
| 1116 | 1177 | |
| 1117 | 1178 | // Now we know when the time should be! |
| 1118 | 1179 | $next_time = time() + 60 * ($off - $curMin); |
@@ -1132,11 +1193,13 @@ discard block |
||
| 1132 | 1193 | // Default we'll jump in hours. |
| 1133 | 1194 | $applyOffset = 3600; |
| 1134 | 1195 | // 24 hours = 1 day. |
| 1135 | - if ($unit == 'd') |
|
| 1136 | - $applyOffset = 86400; |
|
| 1196 | + if ($unit == 'd') { |
|
| 1197 | + $applyOffset = 86400; |
|
| 1198 | + } |
|
| 1137 | 1199 | // Otherwise a week. |
| 1138 | - if ($unit == 'w') |
|
| 1139 | - $applyOffset = 604800; |
|
| 1200 | + if ($unit == 'w') { |
|
| 1201 | + $applyOffset = 604800; |
|
| 1202 | + } |
|
| 1140 | 1203 | |
| 1141 | 1204 | $applyOffset *= $regularity; |
| 1142 | 1205 | |
@@ -1173,8 +1236,9 @@ discard block |
||
| 1173 | 1236 | $settings[$row['variable']] = $row['value']; |
| 1174 | 1237 | |
| 1175 | 1238 | // Is this the default theme? |
| 1176 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') |
|
| 1177 | - $settings['default_' . $row['variable']] = $row['value']; |
|
| 1239 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') { |
|
| 1240 | + $settings['default_' . $row['variable']] = $row['value']; |
|
| 1241 | + } |
|
| 1178 | 1242 | } |
| 1179 | 1243 | $smcFunc['db_free_result']($result); |
| 1180 | 1244 | |
@@ -1184,12 +1248,14 @@ discard block |
||
| 1184 | 1248 | $settings['template_dirs'] = array($settings['theme_dir']); |
| 1185 | 1249 | |
| 1186 | 1250 | // Based on theme (if there is one). |
| 1187 | - if (!empty($settings['base_theme_dir'])) |
|
| 1188 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1251 | + if (!empty($settings['base_theme_dir'])) { |
|
| 1252 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1253 | + } |
|
| 1189 | 1254 | |
| 1190 | 1255 | // Lastly the default theme. |
| 1191 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
| 1192 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1256 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
| 1257 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1258 | + } |
|
| 1193 | 1259 | } |
| 1194 | 1260 | |
| 1195 | 1261 | // Assume we want this. |
@@ -1333,8 +1399,9 @@ discard block |
||
| 1333 | 1399 | // Ok should we prune the logs? |
| 1334 | 1400 | if (!empty($modSettings['pruningOptions'])) |
| 1335 | 1401 | { |
| 1336 | - if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) |
|
| 1337 | - list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 1402 | + if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) { |
|
| 1403 | + list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 1404 | + } |
|
| 1338 | 1405 | |
| 1339 | 1406 | if (!empty($modSettings['pruneErrorLog'])) |
| 1340 | 1407 | { |
@@ -1400,8 +1467,9 @@ discard block |
||
| 1400 | 1467 | ) |
| 1401 | 1468 | ); |
| 1402 | 1469 | |
| 1403 | - while ($row = $smcFunc['db_fetch_row']($result)) |
|
| 1404 | - $reports[] = $row[0]; |
|
| 1470 | + while ($row = $smcFunc['db_fetch_row']($result)) { |
|
| 1471 | + $reports[] = $row[0]; |
|
| 1472 | + } |
|
| 1405 | 1473 | |
| 1406 | 1474 | $smcFunc['db_free_result']($result); |
| 1407 | 1475 | |
@@ -1486,8 +1554,9 @@ discard block |
||
| 1486 | 1554 | ); |
| 1487 | 1555 | |
| 1488 | 1556 | // Run Cache housekeeping |
| 1489 | - if (!empty($cache_enable) && !empty($cacheAPI)) |
|
| 1490 | - $cacheAPI->housekeeping(); |
|
| 1557 | + if (!empty($cache_enable) && !empty($cacheAPI)) { |
|
| 1558 | + $cacheAPI->housekeeping(); |
|
| 1559 | + } |
|
| 1491 | 1560 | |
| 1492 | 1561 | // Prevent stale minimized CSS and JavaScript from cluttering up the theme directories |
| 1493 | 1562 | deleteAllMinified(); |
@@ -1570,8 +1639,9 @@ discard block |
||
| 1570 | 1639 | $emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']); |
| 1571 | 1640 | |
| 1572 | 1641 | // Send the actual email. |
| 1573 | - if ($notifyPrefs[$row['id_member']] & 0x02) |
|
| 1574 | - sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2); |
|
| 1642 | + if ($notifyPrefs[$row['id_member']] & 0x02) { |
|
| 1643 | + sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2); |
|
| 1644 | + } |
|
| 1575 | 1645 | |
| 1576 | 1646 | if ($notifyPrefs[$row['id_member']] & 0x01) |
| 1577 | 1647 | { |
@@ -1594,18 +1664,19 @@ discard block |
||
| 1594 | 1664 | } |
| 1595 | 1665 | |
| 1596 | 1666 | // Insert the alerts if any |
| 1597 | - if (!empty($alert_rows)) |
|
| 1598 | - $smcFunc['db_insert']('', |
|
| 1667 | + if (!empty($alert_rows)) { |
|
| 1668 | + $smcFunc['db_insert']('', |
|
| 1599 | 1669 | '{db_prefix}user_alerts', |
| 1600 | 1670 | array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string', |
| 1601 | 1671 | 'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'), |
| 1602 | 1672 | $alert_rows, |
| 1603 | 1673 | array() |
| 1604 | 1674 | ); |
| 1675 | + } |
|
| 1605 | 1676 | |
| 1606 | 1677 | // Mark the reminder as sent. |
| 1607 | - if (!empty($subs_reminded)) |
|
| 1608 | - $smcFunc['db_query']('', ' |
|
| 1678 | + if (!empty($subs_reminded)) { |
|
| 1679 | + $smcFunc['db_query']('', ' |
|
| 1609 | 1680 | UPDATE {db_prefix}log_subscribed |
| 1610 | 1681 | SET reminder_sent = {int:reminder_sent} |
| 1611 | 1682 | WHERE id_sublog IN ({array_int:subscription_list})', |
@@ -1614,6 +1685,7 @@ discard block |
||
| 1614 | 1685 | 'reminder_sent' => 1, |
| 1615 | 1686 | ) |
| 1616 | 1687 | ); |
| 1688 | + } |
|
| 1617 | 1689 | |
| 1618 | 1690 | return true; |
| 1619 | 1691 | } |
@@ -1629,13 +1701,13 @@ discard block |
||
| 1629 | 1701 | // We need to know where this thing is going. |
| 1630 | 1702 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
| 1631 | 1703 | { |
| 1632 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 1633 | - $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
| 1704 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 1705 | + $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
| 1706 | + } |
|
| 1634 | 1707 | |
| 1635 | 1708 | // Just use the current path for temp files. |
| 1636 | 1709 | $attach_dirs = $modSettings['attachmentUploadDir']; |
| 1637 | - } |
|
| 1638 | - else |
|
| 1710 | + } else |
|
| 1639 | 1711 | { |
| 1640 | 1712 | $attach_dirs = array($modSettings['attachmentUploadDir']); |
| 1641 | 1713 | } |
@@ -1654,14 +1726,16 @@ discard block |
||
| 1654 | 1726 | |
| 1655 | 1727 | while ($file = readdir($dir)) |
| 1656 | 1728 | { |
| 1657 | - if ($file == '.' || $file == '..') |
|
| 1658 | - continue; |
|
| 1729 | + if ($file == '.' || $file == '..') { |
|
| 1730 | + continue; |
|
| 1731 | + } |
|
| 1659 | 1732 | |
| 1660 | 1733 | if (strpos($file, 'post_tmp_') !== false) |
| 1661 | 1734 | { |
| 1662 | 1735 | // Temp file is more than 5 hours old! |
| 1663 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
| 1664 | - @unlink($attach_dir . '/' . $file); |
|
| 1736 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
| 1737 | + @unlink($attach_dir . '/' . $file); |
|
| 1738 | + } |
|
| 1665 | 1739 | } |
| 1666 | 1740 | } |
| 1667 | 1741 | closedir($dir); |
@@ -1694,8 +1768,9 @@ discard block |
||
| 1694 | 1768 | ) |
| 1695 | 1769 | ); |
| 1696 | 1770 | |
| 1697 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1698 | - $topics[] = $row[0]; |
|
| 1771 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1772 | + $topics[] = $row[0]; |
|
| 1773 | + } |
|
| 1699 | 1774 | $smcFunc['db_free_result']($request); |
| 1700 | 1775 | |
| 1701 | 1776 | // Zap, your gone |
@@ -1715,8 +1790,9 @@ discard block |
||
| 1715 | 1790 | { |
| 1716 | 1791 | global $smcFunc, $sourcedir, $modSettings; |
| 1717 | 1792 | |
| 1718 | - if (empty($modSettings['drafts_keep_days'])) |
|
| 1719 | - return true; |
|
| 1793 | + if (empty($modSettings['drafts_keep_days'])) { |
|
| 1794 | + return true; |
|
| 1795 | + } |
|
| 1720 | 1796 | |
| 1721 | 1797 | // init |
| 1722 | 1798 | $drafts = array(); |
@@ -1734,8 +1810,9 @@ discard block |
||
| 1734 | 1810 | ) |
| 1735 | 1811 | ); |
| 1736 | 1812 | |
| 1737 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1738 | - $drafts[] = (int) $row[0]; |
|
| 1813 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1814 | + $drafts[] = (int) $row[0]; |
|
| 1815 | + } |
|
| 1739 | 1816 | $smcFunc['db_free_result']($request); |
| 1740 | 1817 | |
| 1741 | 1818 | // If we have old one, remove them |