@@ -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( |
@@ -604,8 +620,9 @@ discard block |
||
| 604 | 620 | require_once($sourcedir . '/Subs-Membergroups.php'); |
| 605 | 621 | $result = deleteMembergroups((int) $_REQUEST['group']); |
| 606 | 622 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
| 607 | - if ($result === 'group_cannot_delete_sub') |
|
| 608 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 623 | + if ($result === 'group_cannot_delete_sub') { |
|
| 624 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 625 | + } |
|
| 609 | 626 | |
| 610 | 627 | // Go back to the membergroup index. |
| 611 | 628 | redirectexit('action=admin;area=membergroups;'); |
@@ -627,8 +644,9 @@ discard block |
||
| 627 | 644 | |
| 628 | 645 | $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0; |
| 629 | 646 | |
| 630 | - if (!empty($modSettings['deny_boards_access'])) |
|
| 631 | - loadLanguage('ManagePermissions'); |
|
| 647 | + if (!empty($modSettings['deny_boards_access'])) { |
|
| 648 | + loadLanguage('ManagePermissions'); |
|
| 649 | + } |
|
| 632 | 650 | |
| 633 | 651 | // Make sure this group is editable. |
| 634 | 652 | if (!empty($_REQUEST['group'])) |
@@ -650,8 +668,9 @@ discard block |
||
| 650 | 668 | } |
| 651 | 669 | |
| 652 | 670 | // Now, do we have a valid id? |
| 653 | - if (empty($_REQUEST['group'])) |
|
| 654 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
| 671 | + if (empty($_REQUEST['group'])) { |
|
| 672 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
| 673 | + } |
|
| 655 | 674 | |
| 656 | 675 | // People who can manage boards are a bit special. |
| 657 | 676 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -682,8 +701,9 @@ discard block |
||
| 682 | 701 | require_once($sourcedir . '/Subs-Membergroups.php'); |
| 683 | 702 | $result = deleteMembergroups($_REQUEST['group']); |
| 684 | 703 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
| 685 | - if ($result === 'group_cannot_delete_sub') |
|
| 686 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 704 | + if ($result === 'group_cannot_delete_sub') { |
|
| 705 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 706 | + } |
|
| 687 | 707 | |
| 688 | 708 | redirectexit('action=admin;area=membergroups;'); |
| 689 | 709 | } |
@@ -760,16 +780,18 @@ discard block |
||
| 760 | 780 | $request = $smcFunc['db_query']('', ' |
| 761 | 781 | SELECT id_board |
| 762 | 782 | FROM {db_prefix}boards'); |
| 763 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 764 | - $accesses[(int) $row['id_board']] = 'allow'; |
|
| 783 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 784 | + $accesses[(int) $row['id_board']] = 'allow'; |
|
| 785 | + } |
|
| 765 | 786 | $smcFunc['db_free_result']($request); |
| 766 | 787 | } |
| 767 | 788 | |
| 768 | 789 | $changed_boards['allow'] = array(); |
| 769 | 790 | $changed_boards['deny'] = array(); |
| 770 | 791 | $changed_boards['ignore'] = array(); |
| 771 | - foreach ($accesses as $group_id => $action) |
|
| 772 | - $changed_boards[$action][] = (int) $group_id; |
|
| 792 | + foreach ($accesses as $group_id => $action) { |
|
| 793 | + $changed_boards[$action][] = (int) $group_id; |
|
| 794 | + } |
|
| 773 | 795 | |
| 774 | 796 | foreach (array('allow', 'deny') as $board_action) |
| 775 | 797 | { |
@@ -785,8 +807,8 @@ discard block |
||
| 785 | 807 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 786 | 808 | ) |
| 787 | 809 | ); |
| 788 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 789 | - $smcFunc['db_query']('', ' |
|
| 810 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 811 | + $smcFunc['db_query']('', ' |
|
| 790 | 812 | UPDATE {db_prefix}boards |
| 791 | 813 | SET {raw:column} = {string:member_group_access} |
| 792 | 814 | WHERE id_board = {int:current_board}', |
@@ -796,11 +818,12 @@ discard block |
||
| 796 | 818 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 797 | 819 | ) |
| 798 | 820 | ); |
| 821 | + } |
|
| 799 | 822 | $smcFunc['db_free_result']($request); |
| 800 | 823 | |
| 801 | 824 | // Add the membergroup to all boards that hadn't been set yet. |
| 802 | - if (!empty($changed_boards[$board_action])) |
|
| 803 | - $smcFunc['db_query']('', ' |
|
| 825 | + if (!empty($changed_boards[$board_action])) { |
|
| 826 | + $smcFunc['db_query']('', ' |
|
| 804 | 827 | UPDATE {db_prefix}boards |
| 805 | 828 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
| 806 | 829 | WHERE id_board IN ({array_int:board_list}) |
@@ -814,6 +837,7 @@ discard block |
||
| 814 | 837 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 815 | 838 | ) |
| 816 | 839 | ); |
| 840 | + } |
|
| 817 | 841 | } |
| 818 | 842 | } |
| 819 | 843 | |
@@ -839,12 +863,14 @@ discard block |
||
| 839 | 863 | ) |
| 840 | 864 | ); |
| 841 | 865 | $updates = array(); |
| 842 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 843 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 866 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 867 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 868 | + } |
|
| 844 | 869 | $smcFunc['db_free_result']($request); |
| 845 | 870 | |
| 846 | - foreach ($updates as $additional_groups => $memberArray) |
|
| 847 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
| 871 | + foreach ($updates as $additional_groups => $memberArray) { |
|
| 872 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
| 873 | + } |
|
| 848 | 874 | |
| 849 | 875 | // Sorry, but post groups can't moderate boards |
| 850 | 876 | $smcFunc['db_query']('', ' |
@@ -854,8 +880,7 @@ discard block |
||
| 854 | 880 | 'current_group' => (int) $_REQUEST['group'], |
| 855 | 881 | ) |
| 856 | 882 | ); |
| 857 | - } |
|
| 858 | - elseif ($_REQUEST['group'] != 3) |
|
| 883 | + } elseif ($_REQUEST['group'] != 3) |
|
| 859 | 884 | { |
| 860 | 885 | // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional). |
| 861 | 886 | if ($_POST['group_hidden'] == 2) |
@@ -870,8 +895,9 @@ discard block |
||
| 870 | 895 | ) |
| 871 | 896 | ); |
| 872 | 897 | $updates = array(); |
| 873 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 874 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 898 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 899 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 900 | + } |
|
| 875 | 901 | $smcFunc['db_free_result']($request); |
| 876 | 902 | |
| 877 | 903 | foreach ($updates as $additional_groups => $memberArray) |
@@ -913,8 +939,9 @@ discard block |
||
| 913 | 939 | $smcFunc['db_free_result']($request); |
| 914 | 940 | |
| 915 | 941 | // Do we need to update the setting? |
| 916 | - if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) |
|
| 917 | - updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
| 942 | + if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) { |
|
| 943 | + updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
| 944 | + } |
|
| 918 | 945 | } |
| 919 | 946 | |
| 920 | 947 | // Do we need to set inherited permissions? |
@@ -947,8 +974,9 @@ discard block |
||
| 947 | 974 | { |
| 948 | 975 | $moderators[$k] = trim($moderators[$k]); |
| 949 | 976 | |
| 950 | - if (strlen($moderators[$k]) == 0) |
|
| 951 | - unset($moderators[$k]); |
|
| 977 | + if (strlen($moderators[$k]) == 0) { |
|
| 978 | + unset($moderators[$k]); |
|
| 979 | + } |
|
| 952 | 980 | } |
| 953 | 981 | |
| 954 | 982 | // Find all the id_member's for the member_name's in the list. |
@@ -964,8 +992,9 @@ discard block |
||
| 964 | 992 | 'count' => count($moderators), |
| 965 | 993 | ) |
| 966 | 994 | ); |
| 967 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 968 | - $group_moderators[] = $row['id_member']; |
|
| 995 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 996 | + $group_moderators[] = $row['id_member']; |
|
| 997 | + } |
|
| 969 | 998 | $smcFunc['db_free_result']($request); |
| 970 | 999 | } |
| 971 | 1000 | } |
@@ -973,8 +1002,9 @@ discard block |
||
| 973 | 1002 | if (!empty($_POST['moderator_list'])) |
| 974 | 1003 | { |
| 975 | 1004 | $moderators = array(); |
| 976 | - foreach ($_POST['moderator_list'] as $moderator) |
|
| 977 | - $moderators[] = (int) $moderator; |
|
| 1005 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
| 1006 | + $moderators[] = (int) $moderator; |
|
| 1007 | + } |
|
| 978 | 1008 | |
| 979 | 1009 | if (!empty($moderators)) |
| 980 | 1010 | { |
@@ -988,8 +1018,9 @@ discard block |
||
| 988 | 1018 | 'num_moderators' => count($moderators), |
| 989 | 1019 | ) |
| 990 | 1020 | ); |
| 991 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 992 | - $group_moderators[] = $row['id_member']; |
|
| 1021 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1022 | + $group_moderators[] = $row['id_member']; |
|
| 1023 | + } |
|
| 993 | 1024 | $smcFunc['db_free_result']($request); |
| 994 | 1025 | } |
| 995 | 1026 | } |
@@ -1001,8 +1032,9 @@ discard block |
||
| 1001 | 1032 | if (!empty($group_moderators)) |
| 1002 | 1033 | { |
| 1003 | 1034 | $mod_insert = array(); |
| 1004 | - foreach ($group_moderators as $moderator) |
|
| 1005 | - $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
| 1035 | + foreach ($group_moderators as $moderator) { |
|
| 1036 | + $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
| 1037 | + } |
|
| 1006 | 1038 | |
| 1007 | 1039 | $smcFunc['db_insert']('insert', |
| 1008 | 1040 | '{db_prefix}group_moderators', |
@@ -1036,8 +1068,9 @@ discard block |
||
| 1036 | 1068 | 'current_group' => (int) $_REQUEST['group'], |
| 1037 | 1069 | ) |
| 1038 | 1070 | ); |
| 1039 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1040 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
| 1071 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1072 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
| 1073 | + } |
|
| 1041 | 1074 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1042 | 1075 | $smcFunc['db_free_result']($request); |
| 1043 | 1076 | |
@@ -1074,14 +1107,16 @@ discard block |
||
| 1074 | 1107 | ) |
| 1075 | 1108 | ); |
| 1076 | 1109 | $context['group']['moderators'] = array(); |
| 1077 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1078 | - $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 1110 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1111 | + $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 1112 | + } |
|
| 1079 | 1113 | $smcFunc['db_free_result']($request); |
| 1080 | 1114 | |
| 1081 | 1115 | $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '"' . implode('", "', $context['group']['moderators']) . '"'; |
| 1082 | 1116 | |
| 1083 | - if (!empty($context['group']['moderators'])) |
|
| 1084 | - list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
| 1117 | + if (!empty($context['group']['moderators'])) { |
|
| 1118 | + list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
| 1119 | + } |
|
| 1085 | 1120 | |
| 1086 | 1121 | // Get a list of boards this membergroup is allowed to see. |
| 1087 | 1122 | $context['boards'] = array(); |
@@ -1101,12 +1136,13 @@ discard block |
||
| 1101 | 1136 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1102 | 1137 | { |
| 1103 | 1138 | // This category hasn't been set up yet.. |
| 1104 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 1105 | - $context['categories'][$row['id_cat']] = array( |
|
| 1139 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 1140 | + $context['categories'][$row['id_cat']] = array( |
|
| 1106 | 1141 | 'id' => $row['id_cat'], |
| 1107 | 1142 | 'name' => $row['cat_name'], |
| 1108 | 1143 | 'boards' => array() |
| 1109 | 1144 | ); |
| 1145 | + } |
|
| 1110 | 1146 | |
| 1111 | 1147 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 1112 | 1148 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -1154,19 +1190,22 @@ discard block |
||
| 1154 | 1190 | $image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value); |
| 1155 | 1191 | |
| 1156 | 1192 | // If this is bigger than 128 in width or 32 in height, skip this one. |
| 1157 | - if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) |
|
| 1158 | - continue; |
|
| 1193 | + if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) { |
|
| 1194 | + continue; |
|
| 1195 | + } |
|
| 1159 | 1196 | |
| 1160 | 1197 | // Else it's valid. Add it in. |
| 1161 | - else |
|
| 1162 | - $context['possible_icons'][] = $value; |
|
| 1198 | + else { |
|
| 1199 | + $context['possible_icons'][] = $value; |
|
| 1200 | + } |
|
| 1163 | 1201 | } |
| 1164 | 1202 | } |
| 1165 | 1203 | } |
| 1166 | 1204 | |
| 1167 | 1205 | // Insert our JS, if we have possible icons. |
| 1168 | - if (!empty($context['possible_icons'])) |
|
| 1169 | - loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown'); |
|
| 1206 | + if (!empty($context['possible_icons'])) { |
|
| 1207 | + loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown'); |
|
| 1208 | + } |
|
| 1170 | 1209 | |
| 1171 | 1210 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
| 1172 | 1211 | |
@@ -1188,8 +1227,9 @@ discard block |
||
| 1188 | 1227 | ) |
| 1189 | 1228 | ); |
| 1190 | 1229 | $context['inheritable_groups'] = array(); |
| 1191 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1192 | - $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
| 1230 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1231 | + $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
| 1232 | + } |
|
| 1193 | 1233 | $smcFunc['db_free_result']($request); |
| 1194 | 1234 | |
| 1195 | 1235 | 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 | * Class xmlArray |
@@ -65,8 +66,9 @@ discard block |
||
| 65 | 66 | } |
| 66 | 67 | |
| 67 | 68 | // Is the input an array? (ie. passed from file()?) |
| 68 | - if (is_array($data)) |
|
| 69 | - $data = implode('', $data); |
|
| 69 | + if (is_array($data)) { |
|
| 70 | + $data = implode('', $data); |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | 73 | // Remove any xml declaration or doctype, and parse out comments and CDATA. |
| 72 | 74 | $data = preg_replace('/<!--.*?-->/s', '', $this->_to_cdata(preg_replace(array('/^<\?xml.+?\?' . '>/is', '/<!DOCTYPE[^>]+?' . '>/s'), '', $data))); |
@@ -101,8 +103,9 @@ discard block |
||
| 101 | 103 | // Get the element, in array form. |
| 102 | 104 | $array = $this->path($path); |
| 103 | 105 | |
| 104 | - if ($array === false) |
|
| 105 | - return false; |
|
| 106 | + if ($array === false) { |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 106 | 109 | |
| 107 | 110 | // Getting elements into this is a bit complicated... |
| 108 | 111 | if ($get_elements && !is_string($array)) |
@@ -113,8 +116,9 @@ discard block |
||
| 113 | 116 | foreach ($array->array as $val) |
| 114 | 117 | { |
| 115 | 118 | // Skip the name and any attributes. |
| 116 | - if (is_array($val)) |
|
| 117 | - $temp .= $this->_xml($val, null); |
|
| 119 | + if (is_array($val)) { |
|
| 120 | + $temp .= $this->_xml($val, null); |
|
| 121 | + } |
|
| 118 | 122 | } |
| 119 | 123 | |
| 120 | 124 | // Just get the XML data and then take out the CDATAs. |
@@ -156,32 +160,35 @@ discard block |
||
| 156 | 160 | elseif (substr($el, 0, 1) == '@') |
| 157 | 161 | { |
| 158 | 162 | // It simplifies things if the attribute is already there ;). |
| 159 | - if (isset($array[$el])) |
|
| 160 | - return $array[$el]; |
|
| 161 | - else |
|
| 163 | + if (isset($array[$el])) { |
|
| 164 | + return $array[$el]; |
|
| 165 | + } else |
|
| 162 | 166 | { |
| 163 | 167 | $trace = debug_backtrace(); |
| 164 | 168 | $i = 0; |
| 165 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
| 166 | - $i++; |
|
| 169 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
| 170 | + $i++; |
|
| 171 | + } |
|
| 167 | 172 | $debug = ' (from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'] . ')'; |
| 168 | 173 | |
| 169 | 174 | // Cause an error. |
| 170 | - if ($this->debug_level & E_NOTICE) |
|
| 171 | - trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
| 175 | + if ($this->debug_level & E_NOTICE) { |
|
| 176 | + trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
| 177 | + } |
|
| 172 | 178 | return false; |
| 173 | 179 | } |
| 180 | + } else { |
|
| 181 | + $lvl = null; |
|
| 174 | 182 | } |
| 175 | - else |
|
| 176 | - $lvl = null; |
|
| 177 | 183 | |
| 178 | 184 | // Find this element. |
| 179 | 185 | $array = $this->_path($array, $el, $lvl); |
| 180 | 186 | } |
| 181 | 187 | |
| 182 | 188 | // Clean up after $lvl, for $return_full. |
| 183 | - if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) |
|
| 184 | - $array = array('name' => $el . '[]', $array); |
|
| 189 | + if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) { |
|
| 190 | + $array = array('name' => $el . '[]', $array); |
|
| 191 | + } |
|
| 185 | 192 | |
| 186 | 193 | // Create the right type of class... |
| 187 | 194 | $newClass = get_class($this); |
@@ -216,10 +223,11 @@ discard block |
||
| 216 | 223 | $el = substr($el, 0, strpos($el, '[')); |
| 217 | 224 | } |
| 218 | 225 | // Find an attribute. |
| 219 | - elseif (substr($el, 0, 1) == '@') |
|
| 220 | - return isset($array[$el]); |
|
| 221 | - else |
|
| 222 | - $lvl = null; |
|
| 226 | + elseif (substr($el, 0, 1) == '@') { |
|
| 227 | + return isset($array[$el]); |
|
| 228 | + } else { |
|
| 229 | + $lvl = null; |
|
| 230 | + } |
|
| 223 | 231 | |
| 224 | 232 | // Find this element. |
| 225 | 233 | $array = $this->_path($array, $el, $lvl, true); |
@@ -244,8 +252,9 @@ discard block |
||
| 244 | 252 | $i = 0; |
| 245 | 253 | foreach ($temp->array as $item) |
| 246 | 254 | { |
| 247 | - if (is_array($item)) |
|
| 248 | - $i++; |
|
| 255 | + if (is_array($item)) { |
|
| 256 | + $i++; |
|
| 257 | + } |
|
| 249 | 258 | } |
| 250 | 259 | |
| 251 | 260 | return $i; |
@@ -269,8 +278,9 @@ discard block |
||
| 269 | 278 | foreach ($xml->array as $val) |
| 270 | 279 | { |
| 271 | 280 | // Skip these, they aren't elements. |
| 272 | - if (!is_array($val) || $val['name'] == '!') |
|
| 273 | - continue; |
|
| 281 | + if (!is_array($val) || $val['name'] == '!') { |
|
| 282 | + continue; |
|
| 283 | + } |
|
| 274 | 284 | |
| 275 | 285 | // Create the right type of class... |
| 276 | 286 | $newClass = get_class($this); |
@@ -297,14 +307,16 @@ discard block |
||
| 297 | 307 | $path = $this->path($path); |
| 298 | 308 | |
| 299 | 309 | // The path was not found |
| 300 | - if ($path === false) |
|
| 301 | - return false; |
|
| 310 | + if ($path === false) { |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 302 | 313 | |
| 303 | 314 | $path = $path->array; |
| 304 | 315 | } |
| 305 | 316 | // Just use the current array. |
| 306 | - else |
|
| 307 | - $path = $this->array; |
|
| 317 | + else { |
|
| 318 | + $path = $this->array; |
|
| 319 | + } |
|
| 308 | 320 | |
| 309 | 321 | // Add the xml declaration to the front. |
| 310 | 322 | return '<?xml version="1.0"?' . '>' . $this->_xml($path, 0); |
@@ -326,14 +338,16 @@ discard block |
||
| 326 | 338 | $path = $this->path($path); |
| 327 | 339 | |
| 328 | 340 | // The path was not found |
| 329 | - if ($path === false) |
|
| 330 | - return false; |
|
| 341 | + if ($path === false) { |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 331 | 344 | |
| 332 | 345 | $path = $path->array; |
| 333 | 346 | } |
| 334 | 347 | // No, so just use the current array. |
| 335 | - else |
|
| 336 | - $path = $this->array; |
|
| 348 | + else { |
|
| 349 | + $path = $this->array; |
|
| 350 | + } |
|
| 337 | 351 | |
| 338 | 352 | return $this->_array($path); |
| 339 | 353 | } |
@@ -355,8 +369,9 @@ discard block |
||
| 355 | 369 | { |
| 356 | 370 | // Find and remove the next tag. |
| 357 | 371 | preg_match('/\A<([\w\-:]+)((?:\s+.+?)?)([\s]?\/)?' . '>/', $data, $match); |
| 358 | - if (isset($match[0])) |
|
| 359 | - $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
| 372 | + if (isset($match[0])) { |
|
| 373 | + $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
| 374 | + } |
|
| 360 | 375 | |
| 361 | 376 | // Didn't find a tag? Keep looping.... |
| 362 | 377 | if (!isset($match[1]) || $match[1] == '') |
@@ -367,11 +382,12 @@ discard block |
||
| 367 | 382 | $text_value = $this->_from_cdata($data); |
| 368 | 383 | $data = ''; |
| 369 | 384 | |
| 370 | - if ($text_value != '') |
|
| 371 | - $current[] = array( |
|
| 385 | + if ($text_value != '') { |
|
| 386 | + $current[] = array( |
|
| 372 | 387 | 'name' => '!', |
| 373 | 388 | 'value' => $text_value |
| 374 | 389 | ); |
| 390 | + } |
|
| 375 | 391 | } |
| 376 | 392 | // If the < isn't immediately next to the current position... more data. |
| 377 | 393 | elseif (strpos($data, '<') > 0) |
@@ -379,11 +395,12 @@ discard block |
||
| 379 | 395 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<'))); |
| 380 | 396 | $data = substr($data, strpos($data, '<')); |
| 381 | 397 | |
| 382 | - if ($text_value != '') |
|
| 383 | - $current[] = array( |
|
| 398 | + if ($text_value != '') { |
|
| 399 | + $current[] = array( |
|
| 384 | 400 | 'name' => '!', |
| 385 | 401 | 'value' => $text_value |
| 386 | 402 | ); |
| 403 | + } |
|
| 387 | 404 | } |
| 388 | 405 | // If we're looking at a </something> with no start, kill it. |
| 389 | 406 | elseif (strpos($data, '<') !== false && strpos($data, '<') == 0) |
@@ -393,22 +410,23 @@ discard block |
||
| 393 | 410 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<', 1))); |
| 394 | 411 | $data = substr($data, strpos($data, '<', 1)); |
| 395 | 412 | |
| 396 | - if ($text_value != '') |
|
| 397 | - $current[] = array( |
|
| 413 | + if ($text_value != '') { |
|
| 414 | + $current[] = array( |
|
| 398 | 415 | 'name' => '!', |
| 399 | 416 | 'value' => $text_value |
| 400 | 417 | ); |
| 401 | - } |
|
| 402 | - else |
|
| 418 | + } |
|
| 419 | + } else |
|
| 403 | 420 | { |
| 404 | 421 | $text_value = $this->_from_cdata($data); |
| 405 | 422 | $data = ''; |
| 406 | 423 | |
| 407 | - if ($text_value != '') |
|
| 408 | - $current[] = array( |
|
| 424 | + if ($text_value != '') { |
|
| 425 | + $current[] = array( |
|
| 409 | 426 | 'name' => '!', |
| 410 | 427 | 'value' => $text_value |
| 411 | 428 | ); |
| 429 | + } |
|
| 412 | 430 | } |
| 413 | 431 | } |
| 414 | 432 | |
@@ -425,8 +443,9 @@ discard block |
||
| 425 | 443 | { |
| 426 | 444 | // Because PHP 5.2.0+ seems to croak using regex, we'll have to do this the less fun way. |
| 427 | 445 | $last_tag_end = strpos($data, '</' . $match[1] . '>'); |
| 428 | - if ($last_tag_end === false) |
|
| 429 | - continue; |
|
| 446 | + if ($last_tag_end === false) { |
|
| 447 | + continue; |
|
| 448 | + } |
|
| 430 | 449 | |
| 431 | 450 | $offset = 0; |
| 432 | 451 | while (1 == 1) |
@@ -434,16 +453,17 @@ discard block |
||
| 434 | 453 | // Where is the next start tag? |
| 435 | 454 | $next_tag_start = strpos($data, '<' . $match[1], $offset); |
| 436 | 455 | // If the next start tag is after the last end tag then we've found the right close. |
| 437 | - if ($next_tag_start === false || $next_tag_start > $last_tag_end) |
|
| 438 | - break; |
|
| 456 | + if ($next_tag_start === false || $next_tag_start > $last_tag_end) { |
|
| 457 | + break; |
|
| 458 | + } |
|
| 439 | 459 | |
| 440 | 460 | // If not then find the next ending tag. |
| 441 | 461 | $next_tag_end = strpos($data, '</' . $match[1] . '>', $offset); |
| 442 | 462 | |
| 443 | 463 | // Didn't find one? Then just use the last and sod it. |
| 444 | - if ($next_tag_end === false) |
|
| 445 | - break; |
|
| 446 | - else |
|
| 464 | + if ($next_tag_end === false) { |
|
| 465 | + break; |
|
| 466 | + } else |
|
| 447 | 467 | { |
| 448 | 468 | $last_tag_end = $next_tag_end; |
| 449 | 469 | $offset = $next_tag_start + 1; |
@@ -457,16 +477,17 @@ discard block |
||
| 457 | 477 | if (!empty($inner_match)) |
| 458 | 478 | { |
| 459 | 479 | // Parse the inner data. |
| 460 | - if (strpos($inner_match, '<') !== false) |
|
| 461 | - $el += $this->_parse($inner_match); |
|
| 462 | - elseif (trim($inner_match) != '') |
|
| 480 | + if (strpos($inner_match, '<') !== false) { |
|
| 481 | + $el += $this->_parse($inner_match); |
|
| 482 | + } elseif (trim($inner_match) != '') |
|
| 463 | 483 | { |
| 464 | 484 | $text_value = $this->_from_cdata($inner_match); |
| 465 | - if ($text_value != '') |
|
| 466 | - $el[] = array( |
|
| 485 | + if ($text_value != '') { |
|
| 486 | + $el[] = array( |
|
| 467 | 487 | 'name' => '!', |
| 468 | 488 | 'value' => $text_value |
| 469 | 489 | ); |
| 490 | + } |
|
| 470 | 491 | } |
| 471 | 492 | } |
| 472 | 493 | } |
@@ -478,8 +499,9 @@ discard block |
||
| 478 | 499 | preg_match_all('/([\w:]+)="(.+?)"/', $match[2], $attr, PREG_SET_ORDER); |
| 479 | 500 | |
| 480 | 501 | // Set them as @attribute-name. |
| 481 | - foreach ($attr as $match_attr) |
|
| 482 | - $el['@' . $match_attr[1]] = $match_attr[2]; |
|
| 502 | + foreach ($attr as $match_attr) { |
|
| 503 | + $el['@' . $match_attr[1]] = $match_attr[2]; |
|
| 504 | + } |
|
| 483 | 505 | } |
| 484 | 506 | } |
| 485 | 507 | |
@@ -503,16 +525,18 @@ discard block |
||
| 503 | 525 | if (is_array($array) && !isset($array['name'])) |
| 504 | 526 | { |
| 505 | 527 | $temp = ''; |
| 506 | - foreach ($array as $val) |
|
| 507 | - $temp .= $this->_xml($val, $indent); |
|
| 528 | + foreach ($array as $val) { |
|
| 529 | + $temp .= $this->_xml($val, $indent); |
|
| 530 | + } |
|
| 508 | 531 | return $temp; |
| 509 | 532 | } |
| 510 | 533 | |
| 511 | 534 | // This is just text! |
| 512 | - if ($array['name'] == '!') |
|
| 513 | - return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
| 514 | - elseif (substr($array['name'], -2) == '[]') |
|
| 515 | - $array['name'] = substr($array['name'], 0, -2); |
|
| 535 | + if ($array['name'] == '!') { |
|
| 536 | + return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
| 537 | + } elseif (substr($array['name'], -2) == '[]') { |
|
| 538 | + $array['name'] = substr($array['name'], 0, -2); |
|
| 539 | + } |
|
| 516 | 540 | |
| 517 | 541 | // Start the element. |
| 518 | 542 | $output = $indentation . '<' . $array['name']; |
@@ -523,9 +547,9 @@ discard block |
||
| 523 | 547 | // Run through and recursively output all the elements or attrbutes inside this. |
| 524 | 548 | foreach ($array as $k => $v) |
| 525 | 549 | { |
| 526 | - if (substr($k, 0, 1) == '@') |
|
| 527 | - $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
| 528 | - elseif (is_array($v)) |
|
| 550 | + if (substr($k, 0, 1) == '@') { |
|
| 551 | + $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
| 552 | + } elseif (is_array($v)) |
|
| 529 | 553 | { |
| 530 | 554 | $output_el .= $this->_xml($v, $indent === null ? null : $indent + 1); |
| 531 | 555 | $inside_elements = true; |
@@ -533,10 +557,11 @@ discard block |
||
| 533 | 557 | } |
| 534 | 558 | |
| 535 | 559 | // Indent, if necessary.... then close the tag. |
| 536 | - if ($inside_elements) |
|
| 537 | - $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
| 538 | - else |
|
| 539 | - $output .= ' />'; |
|
| 560 | + if ($inside_elements) { |
|
| 561 | + $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
| 562 | + } else { |
|
| 563 | + $output .= ' />'; |
|
| 564 | + } |
|
| 540 | 565 | |
| 541 | 566 | return $output; |
| 542 | 567 | } |
@@ -553,19 +578,22 @@ discard block |
||
| 553 | 578 | $text = ''; |
| 554 | 579 | foreach ($array as $value) |
| 555 | 580 | { |
| 556 | - if (!is_array($value) || !isset($value['name'])) |
|
| 557 | - continue; |
|
| 581 | + if (!is_array($value) || !isset($value['name'])) { |
|
| 582 | + continue; |
|
| 583 | + } |
|
| 558 | 584 | |
| 559 | - if ($value['name'] == '!') |
|
| 560 | - $text .= $value['value']; |
|
| 561 | - else |
|
| 562 | - $return[$value['name']] = $this->_array($value); |
|
| 585 | + if ($value['name'] == '!') { |
|
| 586 | + $text .= $value['value']; |
|
| 587 | + } else { |
|
| 588 | + $return[$value['name']] = $this->_array($value); |
|
| 589 | + } |
|
| 563 | 590 | } |
| 564 | 591 | |
| 565 | - if (empty($return)) |
|
| 566 | - return $text; |
|
| 567 | - else |
|
| 568 | - return $return; |
|
| 592 | + if (empty($return)) { |
|
| 593 | + return $text; |
|
| 594 | + } else { |
|
| 595 | + return $return; |
|
| 596 | + } |
|
| 569 | 597 | } |
| 570 | 598 | |
| 571 | 599 | /** |
@@ -583,24 +611,28 @@ discard block |
||
| 583 | 611 | foreach ($parts as $part) |
| 584 | 612 | { |
| 585 | 613 | // Handle XML comments. |
| 586 | - if (!$inCdata && $part === '<!--') |
|
| 587 | - $inComment = true; |
|
| 588 | - if ($inComment && $part === '-->') |
|
| 589 | - $inComment = false; |
|
| 590 | - elseif ($inComment) |
|
| 591 | - continue; |
|
| 614 | + if (!$inCdata && $part === '<!--') { |
|
| 615 | + $inComment = true; |
|
| 616 | + } |
|
| 617 | + if ($inComment && $part === '-->') { |
|
| 618 | + $inComment = false; |
|
| 619 | + } elseif ($inComment) { |
|
| 620 | + continue; |
|
| 621 | + } |
|
| 592 | 622 | |
| 593 | 623 | // Handle Cdata blocks. |
| 594 | - elseif (!$inComment && $part === '<![CDATA[') |
|
| 595 | - $inCdata = true; |
|
| 596 | - elseif ($inCdata && $part === ']]>') |
|
| 597 | - $inCdata = false; |
|
| 598 | - elseif ($inCdata) |
|
| 599 | - $output .= htmlentities($part, ENT_QUOTES); |
|
| 624 | + elseif (!$inComment && $part === '<![CDATA[') { |
|
| 625 | + $inCdata = true; |
|
| 626 | + } elseif ($inCdata && $part === ']]>') { |
|
| 627 | + $inCdata = false; |
|
| 628 | + } elseif ($inCdata) { |
|
| 629 | + $output .= htmlentities($part, ENT_QUOTES); |
|
| 630 | + } |
|
| 600 | 631 | |
| 601 | 632 | // Everything else is kept as is. |
| 602 | - else |
|
| 603 | - $output .= $part; |
|
| 633 | + else { |
|
| 634 | + $output .= $part; |
|
| 635 | + } |
|
| 604 | 636 | } |
| 605 | 637 | |
| 606 | 638 | return $output; |
@@ -635,22 +667,26 @@ discard block |
||
| 635 | 667 | protected function _fetch($array) |
| 636 | 668 | { |
| 637 | 669 | // Don't return anything if this is just a string. |
| 638 | - if (is_string($array)) |
|
| 639 | - return ''; |
|
| 670 | + if (is_string($array)) { |
|
| 671 | + return ''; |
|
| 672 | + } |
|
| 640 | 673 | |
| 641 | 674 | $temp = ''; |
| 642 | 675 | foreach ($array as $text) |
| 643 | 676 | { |
| 644 | 677 | // This means it's most likely an attribute or the name itself. |
| 645 | - if (!isset($text['name'])) |
|
| 646 | - continue; |
|
| 678 | + if (!isset($text['name'])) { |
|
| 679 | + continue; |
|
| 680 | + } |
|
| 647 | 681 | |
| 648 | 682 | // This is text! |
| 649 | - if ($text['name'] == '!') |
|
| 650 | - $temp .= $text['value']; |
|
| 683 | + if ($text['name'] == '!') { |
|
| 684 | + $temp .= $text['value']; |
|
| 685 | + } |
|
| 651 | 686 | // Another element - dive in ;). |
| 652 | - else |
|
| 653 | - $temp .= $this->_fetch($text); |
|
| 687 | + else { |
|
| 688 | + $temp .= $this->_fetch($text); |
|
| 689 | + } |
|
| 654 | 690 | } |
| 655 | 691 | |
| 656 | 692 | // Return all the bits and pieces we've put together. |
@@ -669,12 +705,14 @@ discard block |
||
| 669 | 705 | protected function _path($array, $path, $level, $no_error = false) |
| 670 | 706 | { |
| 671 | 707 | // Is $array even an array? It might be false! |
| 672 | - if (!is_array($array)) |
|
| 673 | - return false; |
|
| 708 | + if (!is_array($array)) { |
|
| 709 | + return false; |
|
| 710 | + } |
|
| 674 | 711 | |
| 675 | 712 | // Asking for *no* path? |
| 676 | - if ($path == '' || $path == '.') |
|
| 677 | - return $array; |
|
| 713 | + if ($path == '' || $path == '.') { |
|
| 714 | + return $array; |
|
| 715 | + } |
|
| 678 | 716 | $paths = explode('|', $path); |
| 679 | 717 | |
| 680 | 718 | // A * means all elements of any name. |
@@ -685,16 +723,18 @@ discard block |
||
| 685 | 723 | // Check each element. |
| 686 | 724 | foreach ($array as $value) |
| 687 | 725 | { |
| 688 | - if (!is_array($value) || $value['name'] === '!') |
|
| 689 | - continue; |
|
| 726 | + if (!is_array($value) || $value['name'] === '!') { |
|
| 727 | + continue; |
|
| 728 | + } |
|
| 690 | 729 | |
| 691 | 730 | if ($show_all || in_array($value['name'], $paths)) |
| 692 | 731 | { |
| 693 | 732 | // Skip elements before "the one". |
| 694 | - if ($level !== null && $level > 0) |
|
| 695 | - $level--; |
|
| 696 | - else |
|
| 697 | - $results[] = $value; |
|
| 733 | + if ($level !== null && $level > 0) { |
|
| 734 | + $level--; |
|
| 735 | + } else { |
|
| 736 | + $results[] = $value; |
|
| 737 | + } |
|
| 698 | 738 | } |
| 699 | 739 | } |
| 700 | 740 | |
@@ -703,21 +743,25 @@ discard block |
||
| 703 | 743 | { |
| 704 | 744 | $trace = debug_backtrace(); |
| 705 | 745 | $i = 0; |
| 706 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
| 707 | - $i++; |
|
| 746 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
| 747 | + $i++; |
|
| 748 | + } |
|
| 708 | 749 | $debug = ' from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line']; |
| 709 | 750 | |
| 710 | 751 | // Cause an error. |
| 711 | - if ($this->debug_level & E_NOTICE && !$no_error) |
|
| 712 | - trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
| 752 | + if ($this->debug_level & E_NOTICE && !$no_error) { |
|
| 753 | + trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
| 754 | + } |
|
| 713 | 755 | return false; |
| 714 | 756 | } |
| 715 | 757 | // Only one result. |
| 716 | - elseif (count($results) == 1 || $level !== null) |
|
| 717 | - return $results[0]; |
|
| 758 | + elseif (count($results) == 1 || $level !== null) { |
|
| 759 | + return $results[0]; |
|
| 760 | + } |
|
| 718 | 761 | // Return the result set. |
| 719 | - else |
|
| 720 | - return $results + array('name' => $path . '[]'); |
|
| 762 | + else { |
|
| 763 | + return $results + array('name' => $path . '[]'); |
|
| 764 | + } |
|
| 721 | 765 | } |
| 722 | 766 | } |
| 723 | 767 | |
@@ -764,8 +808,9 @@ discard block |
||
| 764 | 808 | $this->error = false; |
| 765 | 809 | $this->pasv = array(); |
| 766 | 810 | |
| 767 | - if ($ftp_server !== null) |
|
| 768 | - $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 811 | + if ($ftp_server !== null) { |
|
| 812 | + $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 813 | + } |
|
| 769 | 814 | } |
| 770 | 815 | |
| 771 | 816 | /** |
@@ -778,14 +823,16 @@ discard block |
||
| 778 | 823 | */ |
| 779 | 824 | public function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]') |
| 780 | 825 | { |
| 781 | - if (strpos($ftp_server, 'ftp://') === 0) |
|
| 782 | - $ftp_server = substr($ftp_server, 6); |
|
| 783 | - elseif (strpos($ftp_server, 'ftps://') === 0) |
|
| 784 | - $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 785 | - if (strpos($ftp_server, 'http://') === 0) |
|
| 786 | - $ftp_server = substr($ftp_server, 7); |
|
| 787 | - elseif (strpos($ftp_server, 'https://') === 0) |
|
| 788 | - $ftp_server = substr($ftp_server, 8); |
|
| 826 | + if (strpos($ftp_server, 'ftp://') === 0) { |
|
| 827 | + $ftp_server = substr($ftp_server, 6); |
|
| 828 | + } elseif (strpos($ftp_server, 'ftps://') === 0) { |
|
| 829 | + $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 830 | + } |
|
| 831 | + if (strpos($ftp_server, 'http://') === 0) { |
|
| 832 | + $ftp_server = substr($ftp_server, 7); |
|
| 833 | + } elseif (strpos($ftp_server, 'https://') === 0) { |
|
| 834 | + $ftp_server = substr($ftp_server, 8); |
|
| 835 | + } |
|
| 789 | 836 | $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); |
| 790 | 837 | |
| 791 | 838 | // Connect to the FTP server. |
@@ -834,12 +881,14 @@ discard block |
||
| 834 | 881 | */ |
| 835 | 882 | public function chdir($ftp_path) |
| 836 | 883 | { |
| 837 | - if (!is_resource($this->connection)) |
|
| 838 | - return false; |
|
| 884 | + if (!is_resource($this->connection)) { |
|
| 885 | + return false; |
|
| 886 | + } |
|
| 839 | 887 | |
| 840 | 888 | // No slash on the end, please... |
| 841 | - if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') |
|
| 842 | - $ftp_path = substr($ftp_path, 0, -1); |
|
| 889 | + if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') { |
|
| 890 | + $ftp_path = substr($ftp_path, 0, -1); |
|
| 891 | + } |
|
| 843 | 892 | |
| 844 | 893 | fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n"); |
| 845 | 894 | if (!$this->check_response(250)) |
@@ -860,11 +909,13 @@ discard block |
||
| 860 | 909 | */ |
| 861 | 910 | public function chmod($ftp_file, $chmod) |
| 862 | 911 | { |
| 863 | - if (!is_resource($this->connection)) |
|
| 864 | - return false; |
|
| 912 | + if (!is_resource($this->connection)) { |
|
| 913 | + return false; |
|
| 914 | + } |
|
| 865 | 915 | |
| 866 | - if ($ftp_file == '') |
|
| 867 | - $ftp_file = '.'; |
|
| 916 | + if ($ftp_file == '') { |
|
| 917 | + $ftp_file = '.'; |
|
| 918 | + } |
|
| 868 | 919 | |
| 869 | 920 | // Do we have a file or a dir? |
| 870 | 921 | $is_dir = is_dir($ftp_file); |
@@ -880,9 +931,7 @@ discard block |
||
| 880 | 931 | { |
| 881 | 932 | $is_writable = true; |
| 882 | 933 | break; |
| 883 | - } |
|
| 884 | - |
|
| 885 | - else |
|
| 934 | + } else |
|
| 886 | 935 | { |
| 887 | 936 | // Convert the chmod value from octal (0777) to text ("777"). |
| 888 | 937 | fwrite($this->connection, 'SITE CHMOD ' . decoct($val) . ' ' . $ftp_file . "\r\n"); |
@@ -905,8 +954,9 @@ discard block |
||
| 905 | 954 | public function unlink($ftp_file) |
| 906 | 955 | { |
| 907 | 956 | // We are actually connected, right? |
| 908 | - if (!is_resource($this->connection)) |
|
| 909 | - return false; |
|
| 957 | + if (!is_resource($this->connection)) { |
|
| 958 | + return false; |
|
| 959 | + } |
|
| 910 | 960 | |
| 911 | 961 | // Delete file X. |
| 912 | 962 | fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n"); |
@@ -935,9 +985,9 @@ discard block |
||
| 935 | 985 | { |
| 936 | 986 | // Wait for a response that isn't continued with -, but don't wait too long. |
| 937 | 987 | $time = time(); |
| 938 | - do |
|
| 939 | - $this->last_message = fgets($this->connection, 1024); |
|
| 940 | - while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
| 988 | + do { |
|
| 989 | + $this->last_message = fgets($this->connection, 1024); |
|
| 990 | + } while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
| 941 | 991 | |
| 942 | 992 | // Was the desired response returned? |
| 943 | 993 | return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; |
@@ -951,15 +1001,16 @@ discard block |
||
| 951 | 1001 | public function passive() |
| 952 | 1002 | { |
| 953 | 1003 | // We can't create a passive data connection without a primary one first being there. |
| 954 | - if (!is_resource($this->connection)) |
|
| 955 | - return false; |
|
| 1004 | + if (!is_resource($this->connection)) { |
|
| 1005 | + return false; |
|
| 1006 | + } |
|
| 956 | 1007 | |
| 957 | 1008 | // Request a passive connection - this means, we'll talk to you, you don't talk to us. |
| 958 | 1009 | @fwrite($this->connection, 'PASV' . "\r\n"); |
| 959 | 1010 | $time = time(); |
| 960 | - do |
|
| 961 | - $response = fgets($this->connection, 1024); |
|
| 962 | - while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
| 1011 | + do { |
|
| 1012 | + $response = fgets($this->connection, 1024); |
|
| 1013 | + } while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
| 963 | 1014 | |
| 964 | 1015 | // If it's not 227, we weren't given an IP and port, which means it failed. |
| 965 | 1016 | if (strpos($response, '227 ') !== 0) |
@@ -990,12 +1041,14 @@ discard block |
||
| 990 | 1041 | public function create_file($ftp_file) |
| 991 | 1042 | { |
| 992 | 1043 | // First, we have to be connected... very important. |
| 993 | - if (!is_resource($this->connection)) |
|
| 994 | - return false; |
|
| 1044 | + if (!is_resource($this->connection)) { |
|
| 1045 | + return false; |
|
| 1046 | + } |
|
| 995 | 1047 | |
| 996 | 1048 | // I'd like one passive mode, please! |
| 997 | - if (!$this->passive()) |
|
| 998 | - return false; |
|
| 1049 | + if (!$this->passive()) { |
|
| 1050 | + return false; |
|
| 1051 | + } |
|
| 999 | 1052 | |
| 1000 | 1053 | // Seems logical enough, so far... |
| 1001 | 1054 | fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n"); |
@@ -1030,12 +1083,14 @@ discard block |
||
| 1030 | 1083 | public function list_dir($ftp_path = '', $search = false) |
| 1031 | 1084 | { |
| 1032 | 1085 | // Are we even connected...? |
| 1033 | - if (!is_resource($this->connection)) |
|
| 1034 | - return false; |
|
| 1086 | + if (!is_resource($this->connection)) { |
|
| 1087 | + return false; |
|
| 1088 | + } |
|
| 1035 | 1089 | |
| 1036 | 1090 | // Passive... non-agressive... |
| 1037 | - if (!$this->passive()) |
|
| 1038 | - return false; |
|
| 1091 | + if (!$this->passive()) { |
|
| 1092 | + return false; |
|
| 1093 | + } |
|
| 1039 | 1094 | |
| 1040 | 1095 | // Get the listing! |
| 1041 | 1096 | fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n"); |
@@ -1051,8 +1106,9 @@ discard block |
||
| 1051 | 1106 | |
| 1052 | 1107 | // Read in the file listing. |
| 1053 | 1108 | $data = ''; |
| 1054 | - while (!feof($fp)) |
|
| 1055 | - $data .= fread($fp, 4096); |
|
| 1109 | + while (!feof($fp)) { |
|
| 1110 | + $data .= fread($fp, 4096); |
|
| 1111 | + } |
|
| 1056 | 1112 | fclose($fp); |
| 1057 | 1113 | |
| 1058 | 1114 | // Everything go okay? |
@@ -1074,21 +1130,23 @@ discard block |
||
| 1074 | 1130 | */ |
| 1075 | 1131 | public function locate($file, $listing = null) |
| 1076 | 1132 | { |
| 1077 | - if ($listing === null) |
|
| 1078 | - $listing = $this->list_dir('', true); |
|
| 1133 | + if ($listing === null) { |
|
| 1134 | + $listing = $this->list_dir('', true); |
|
| 1135 | + } |
|
| 1079 | 1136 | $listing = explode("\n", $listing); |
| 1080 | 1137 | |
| 1081 | 1138 | @fwrite($this->connection, 'PWD' . "\r\n"); |
| 1082 | 1139 | $time = time(); |
| 1083 | - do |
|
| 1084 | - $response = fgets($this->connection, 1024); |
|
| 1085 | - while ($response[3] != ' ' && time() - $time < 5); |
|
| 1140 | + do { |
|
| 1141 | + $response = fgets($this->connection, 1024); |
|
| 1142 | + } while ($response[3] != ' ' && time() - $time < 5); |
|
| 1086 | 1143 | |
| 1087 | 1144 | // Check for 257! |
| 1088 | - if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) |
|
| 1089 | - $current_dir = strtr($match[1], array('""' => '"')); |
|
| 1090 | - else |
|
| 1091 | - $current_dir = ''; |
|
| 1145 | + if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) { |
|
| 1146 | + $current_dir = strtr($match[1], array('""' => '"')); |
|
| 1147 | + } else { |
|
| 1148 | + $current_dir = ''; |
|
| 1149 | + } |
|
| 1092 | 1150 | |
| 1093 | 1151 | for ($i = 0, $n = count($listing); $i < $n; $i++) |
| 1094 | 1152 | { |
@@ -1101,12 +1159,15 @@ discard block |
||
| 1101 | 1159 | // Okay, this file's name is: |
| 1102 | 1160 | $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]); |
| 1103 | 1161 | |
| 1104 | - if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) |
|
| 1105 | - return $listing[$i]; |
|
| 1106 | - if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) |
|
| 1107 | - return $listing[$i]; |
|
| 1108 | - if (basename($listing[$i]) == $file || $listing[$i] == $file) |
|
| 1109 | - return $listing[$i]; |
|
| 1162 | + if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) { |
|
| 1163 | + return $listing[$i]; |
|
| 1164 | + } |
|
| 1165 | + if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) { |
|
| 1166 | + return $listing[$i]; |
|
| 1167 | + } |
|
| 1168 | + if (basename($listing[$i]) == $file || $listing[$i] == $file) { |
|
| 1169 | + return $listing[$i]; |
|
| 1170 | + } |
|
| 1110 | 1171 | } |
| 1111 | 1172 | |
| 1112 | 1173 | return false; |
@@ -1121,8 +1182,9 @@ discard block |
||
| 1121 | 1182 | public function create_dir($ftp_dir) |
| 1122 | 1183 | { |
| 1123 | 1184 | // We must be connected to the server to do something. |
| 1124 | - if (!is_resource($this->connection)) |
|
| 1125 | - return false; |
|
| 1185 | + if (!is_resource($this->connection)) { |
|
| 1186 | + return false; |
|
| 1187 | + } |
|
| 1126 | 1188 | |
| 1127 | 1189 | // Make this new beautiful directory! |
| 1128 | 1190 | fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n"); |
@@ -1154,35 +1216,40 @@ discard block |
||
| 1154 | 1216 | |
| 1155 | 1217 | $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => '')); |
| 1156 | 1218 | |
| 1157 | - if (substr($path, -1) == '/') |
|
| 1158 | - $path = substr($path, 0, -1); |
|
| 1219 | + if (substr($path, -1) == '/') { |
|
| 1220 | + $path = substr($path, 0, -1); |
|
| 1221 | + } |
|
| 1159 | 1222 | |
| 1160 | - if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) |
|
| 1161 | - $path .= dirname($_SERVER['PHP_SELF']); |
|
| 1223 | + if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) { |
|
| 1224 | + $path .= dirname($_SERVER['PHP_SELF']); |
|
| 1225 | + } |
|
| 1226 | + } elseif (strpos($filesystem_path, '/var/www/') === 0) { |
|
| 1227 | + $path = substr($filesystem_path, 8); |
|
| 1228 | + } else { |
|
| 1229 | + $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
| 1162 | 1230 | } |
| 1163 | - elseif (strpos($filesystem_path, '/var/www/') === 0) |
|
| 1164 | - $path = substr($filesystem_path, 8); |
|
| 1165 | - else |
|
| 1166 | - $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
| 1231 | + } else { |
|
| 1232 | + $path = ''; |
|
| 1167 | 1233 | } |
| 1168 | - else |
|
| 1169 | - $path = ''; |
|
| 1170 | 1234 | |
| 1171 | 1235 | if (is_resource($this->connection) && $this->list_dir($path) == '') |
| 1172 | 1236 | { |
| 1173 | 1237 | $data = $this->list_dir('', true); |
| 1174 | 1238 | |
| 1175 | - if ($lookup_file === null) |
|
| 1176 | - $lookup_file = $_SERVER['PHP_SELF']; |
|
| 1239 | + if ($lookup_file === null) { |
|
| 1240 | + $lookup_file = $_SERVER['PHP_SELF']; |
|
| 1241 | + } |
|
| 1177 | 1242 | |
| 1178 | 1243 | $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data)); |
| 1179 | - if ($found_path == false) |
|
| 1180 | - $found_path = dirname($this->locate(basename($lookup_file))); |
|
| 1181 | - if ($found_path != false) |
|
| 1182 | - $path = $found_path; |
|
| 1244 | + if ($found_path == false) { |
|
| 1245 | + $found_path = dirname($this->locate(basename($lookup_file))); |
|
| 1246 | + } |
|
| 1247 | + if ($found_path != false) { |
|
| 1248 | + $path = $found_path; |
|
| 1249 | + } |
|
| 1250 | + } elseif (is_resource($this->connection)) { |
|
| 1251 | + $found_path = true; |
|
| 1183 | 1252 | } |
| 1184 | - elseif (is_resource($this->connection)) |
|
| 1185 | - $found_path = true; |
|
| 1186 | 1253 | |
| 1187 | 1254 | return array($username, $path, isset($found_path)); |
| 1188 | 1255 | } |
@@ -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 | * Check if the current directory is still valid or not. |
@@ -28,22 +29,24 @@ discard block |
||
| 28 | 29 | global $smcFunc, $boarddir, $modSettings, $context; |
| 29 | 30 | |
| 30 | 31 | // Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found. |
| 31 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') |
|
| 32 | - $doit = true; |
|
| 33 | - elseif (empty($modSettings['automanage_attachments'])) |
|
| 34 | - return; |
|
| 35 | - elseif (!isset($_FILES)) |
|
| 36 | - return; |
|
| 37 | - elseif (isset($_FILES['attachment'])) |
|
| 38 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
| 32 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') { |
|
| 33 | + $doit = true; |
|
| 34 | + } elseif (empty($modSettings['automanage_attachments'])) { |
|
| 35 | + return; |
|
| 36 | + } elseif (!isset($_FILES)) { |
|
| 37 | + return; |
|
| 38 | + } elseif (isset($_FILES['attachment'])) { |
|
| 39 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
| 39 | 40 | if (!empty($dummy)) |
| 40 | 41 | { |
| 41 | 42 | $doit = true; |
| 43 | + } |
|
| 42 | 44 | break; |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | - if (!isset($doit)) |
|
| 46 | - return; |
|
| 47 | + if (!isset($doit)) { |
|
| 48 | + return; |
|
| 49 | + } |
|
| 47 | 50 | |
| 48 | 51 | $year = date('Y'); |
| 49 | 52 | $month = date('m'); |
@@ -54,21 +57,25 @@ discard block |
||
| 54 | 57 | |
| 55 | 58 | if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments'])) |
| 56 | 59 | { |
| 57 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
| 58 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
| 60 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 61 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
| 62 | + } |
|
| 59 | 63 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
| 64 | + } else { |
|
| 65 | + $base_dir = 0; |
|
| 60 | 66 | } |
| 61 | - else |
|
| 62 | - $base_dir = 0; |
|
| 63 | 67 | |
| 64 | 68 | if ($modSettings['automanage_attachments'] == 1) |
| 65 | 69 | { |
| 66 | - if (!isset($modSettings['last_attachments_directory'])) |
|
| 67 | - $modSettings['last_attachments_directory'] = array(); |
|
| 68 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
| 69 | - $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
| 70 | - if (!isset($modSettings['last_attachments_directory'][$base_dir])) |
|
| 71 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 70 | + if (!isset($modSettings['last_attachments_directory'])) { |
|
| 71 | + $modSettings['last_attachments_directory'] = array(); |
|
| 72 | + } |
|
| 73 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
| 74 | + $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
| 75 | + } |
|
| 76 | + if (!isset($modSettings['last_attachments_directory'][$base_dir])) { |
|
| 77 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 78 | + } |
|
| 72 | 79 | } |
| 73 | 80 | |
| 74 | 81 | $basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
@@ -97,12 +104,14 @@ discard block |
||
| 97 | 104 | $updir = ''; |
| 98 | 105 | } |
| 99 | 106 | |
| 100 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 101 | - $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
| 102 | - if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) |
|
| 103 | - $outputCreation = automanage_attachments_create_directory($updir); |
|
| 104 | - elseif (in_array($updir, $modSettings['attachmentUploadDir'])) |
|
| 105 | - $outputCreation = true; |
|
| 107 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 108 | + $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
| 109 | + } |
|
| 110 | + if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) { |
|
| 111 | + $outputCreation = automanage_attachments_create_directory($updir); |
|
| 112 | + } elseif (in_array($updir, $modSettings['attachmentUploadDir'])) { |
|
| 113 | + $outputCreation = true; |
|
| 114 | + } |
|
| 106 | 115 | |
| 107 | 116 | if ($outputCreation) |
| 108 | 117 | { |
@@ -139,8 +148,9 @@ discard block |
||
| 139 | 148 | $count = count($tree); |
| 140 | 149 | |
| 141 | 150 | $directory = attachments_init_dir($tree, $count); |
| 142 | - if ($directory === false) |
|
| 143 | - return false; |
|
| 151 | + if ($directory === false) { |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 144 | 154 | } |
| 145 | 155 | |
| 146 | 156 | $directory .= DIRECTORY_SEPARATOR . array_shift($tree); |
@@ -168,8 +178,9 @@ discard block |
||
| 168 | 178 | } |
| 169 | 179 | |
| 170 | 180 | // Everything seems fine...let's create the .htaccess |
| 171 | - if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) |
|
| 172 | - secureDirectory($updir, true); |
|
| 181 | + if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) { |
|
| 182 | + secureDirectory($updir, true); |
|
| 183 | + } |
|
| 173 | 184 | |
| 174 | 185 | $sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR; |
| 175 | 186 | $updir = rtrim($updir, $sep); |
@@ -201,8 +212,9 @@ discard block |
||
| 201 | 212 | { |
| 202 | 213 | global $smcFunc, $modSettings, $boarddir; |
| 203 | 214 | |
| 204 | - if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) |
|
| 205 | - return; |
|
| 215 | + if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 206 | 218 | |
| 207 | 219 | $basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir; |
| 208 | 220 | // Just to be sure: I don't want directory separators at the end |
@@ -214,13 +226,14 @@ discard block |
||
| 214 | 226 | { |
| 215 | 227 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
| 216 | 228 | $base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0; |
| 229 | + } else { |
|
| 230 | + $base_dir = 0; |
|
| 217 | 231 | } |
| 218 | - else |
|
| 219 | - $base_dir = 0; |
|
| 220 | 232 | |
| 221 | 233 | // Get the last attachment directory for that base directory |
| 222 | - if (empty($modSettings['last_attachments_directory'][$base_dir])) |
|
| 223 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 234 | + if (empty($modSettings['last_attachments_directory'][$base_dir])) { |
|
| 235 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 236 | + } |
|
| 224 | 237 | // And increment it. |
| 225 | 238 | $modSettings['last_attachments_directory'][$base_dir]++; |
| 226 | 239 | |
@@ -235,10 +248,10 @@ discard block |
||
| 235 | 248 | $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
| 236 | 249 | |
| 237 | 250 | return true; |
| 251 | + } else { |
|
| 252 | + return false; |
|
| 253 | + } |
|
| 238 | 254 | } |
| 239 | - else |
|
| 240 | - return false; |
|
| 241 | -} |
|
| 242 | 255 | |
| 243 | 256 | /** |
| 244 | 257 | * Split a path into a list of all directories and subdirectories |
@@ -256,12 +269,13 @@ discard block |
||
| 256 | 269 | * in Windows we need to explode for both \ and / |
| 257 | 270 | * while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR) |
| 258 | 271 | */ |
| 259 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
| 260 | - $tree = preg_split('#[\\\/]#', $directory); |
|
| 261 | - else |
|
| 272 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
| 273 | + $tree = preg_split('#[\\\/]#', $directory); |
|
| 274 | + } else |
|
| 262 | 275 | { |
| 263 | - if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) |
|
| 264 | - return false; |
|
| 276 | + if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { |
|
| 277 | + return false; |
|
| 278 | + } |
|
| 265 | 279 | |
| 266 | 280 | $tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR)); |
| 267 | 281 | } |
@@ -285,10 +299,11 @@ discard block |
||
| 285 | 299 | //Better be sure that the first part of the path is actually a drive letter... |
| 286 | 300 | //...even if, I should check this in the admin page...isn't it? |
| 287 | 301 | //...NHAAA Let's leave space for users' complains! :P |
| 288 | - if (preg_match('/^[a-z]:$/i', $tree[0])) |
|
| 289 | - $directory = array_shift($tree); |
|
| 290 | - else |
|
| 291 | - return false; |
|
| 302 | + if (preg_match('/^[a-z]:$/i', $tree[0])) { |
|
| 303 | + $directory = array_shift($tree); |
|
| 304 | + } else { |
|
| 305 | + return false; |
|
| 306 | + } |
|
| 292 | 307 | |
| 293 | 308 | $count--; |
| 294 | 309 | } |
@@ -303,18 +318,20 @@ discard block |
||
| 303 | 318 | global $context, $modSettings, $smcFunc, $txt, $user_info; |
| 304 | 319 | |
| 305 | 320 | // Make sure we're uploading to the right place. |
| 306 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 307 | - automanage_attachments_check_directory(); |
|
| 321 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 322 | + automanage_attachments_check_directory(); |
|
| 323 | + } |
|
| 308 | 324 | |
| 309 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 310 | - $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
| 325 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 326 | + $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
| 327 | + } |
|
| 311 | 328 | |
| 312 | 329 | $context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
| 313 | 330 | |
| 314 | 331 | // Is the attachments folder actualy there? |
| 315 | - if (!empty($context['dir_creation_error'])) |
|
| 316 | - $initial_error = $context['dir_creation_error']; |
|
| 317 | - elseif (!is_dir($context['attach_dir'])) |
|
| 332 | + if (!empty($context['dir_creation_error'])) { |
|
| 333 | + $initial_error = $context['dir_creation_error']; |
|
| 334 | + } elseif (!is_dir($context['attach_dir'])) |
|
| 318 | 335 | { |
| 319 | 336 | $initial_error = 'attach_folder_warning'; |
| 320 | 337 | log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical'); |
@@ -337,12 +354,12 @@ discard block |
||
| 337 | 354 | ); |
| 338 | 355 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
| 339 | 356 | $smcFunc['db_free_result']($request); |
| 340 | - } |
|
| 341 | - else |
|
| 342 | - $context['attachments'] = array( |
|
| 357 | + } else { |
|
| 358 | + $context['attachments'] = array( |
|
| 343 | 359 | 'quantity' => 0, |
| 344 | 360 | 'total_size' => 0, |
| 345 | 361 | ); |
| 362 | + } |
|
| 346 | 363 | } |
| 347 | 364 | |
| 348 | 365 | // Hmm. There are still files in session. |
@@ -352,39 +369,44 @@ discard block |
||
| 352 | 369 | // Let's try to keep them. But... |
| 353 | 370 | $ignore_temp = true; |
| 354 | 371 | // If new files are being added. We can't ignore those |
| 355 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
| 356 | - if (!empty($dummy)) |
|
| 372 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) { |
|
| 373 | + if (!empty($dummy)) |
|
| 357 | 374 | { |
| 358 | 375 | $ignore_temp = false; |
| 376 | + } |
|
| 359 | 377 | break; |
| 360 | 378 | } |
| 361 | 379 | |
| 362 | 380 | // Need to make space for the new files. So, bye bye. |
| 363 | 381 | if (!$ignore_temp) |
| 364 | 382 | { |
| 365 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 366 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 383 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
| 384 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 367 | 385 | unlink($attachment['tmp_name']); |
| 386 | + } |
|
| 368 | 387 | |
| 369 | 388 | $context['we_are_history'] = $txt['error_temp_attachments_flushed']; |
| 370 | 389 | $_SESSION['temp_attachments'] = array(); |
| 371 | 390 | } |
| 372 | 391 | } |
| 373 | 392 | |
| 374 | - if (!isset($_FILES['attachment']['name'])) |
|
| 375 | - $_FILES['attachment']['tmp_name'] = array(); |
|
| 393 | + if (!isset($_FILES['attachment']['name'])) { |
|
| 394 | + $_FILES['attachment']['tmp_name'] = array(); |
|
| 395 | + } |
|
| 376 | 396 | |
| 377 | - if (!isset($_SESSION['temp_attachments'])) |
|
| 378 | - $_SESSION['temp_attachments'] = array(); |
|
| 397 | + if (!isset($_SESSION['temp_attachments'])) { |
|
| 398 | + $_SESSION['temp_attachments'] = array(); |
|
| 399 | + } |
|
| 379 | 400 | |
| 380 | 401 | // Remember where we are at. If it's anywhere at all. |
| 381 | - if (!$ignore_temp) |
|
| 382 | - $_SESSION['temp_attachments']['post'] = array( |
|
| 402 | + if (!$ignore_temp) { |
|
| 403 | + $_SESSION['temp_attachments']['post'] = array( |
|
| 383 | 404 | 'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0, |
| 384 | 405 | 'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0, |
| 385 | 406 | 'topic' => !empty($topic) ? $topic : 0, |
| 386 | 407 | 'board' => !empty($board) ? $board : 0, |
| 387 | 408 | ); |
| 409 | + } |
|
| 388 | 410 | |
| 389 | 411 | // If we have an initial error, lets just display it. |
| 390 | 412 | if (!empty($initial_error)) |
@@ -392,9 +414,10 @@ discard block |
||
| 392 | 414 | $_SESSION['temp_attachments']['initial_error'] = $initial_error; |
| 393 | 415 | |
| 394 | 416 | // And delete the files 'cos they ain't going nowhere. |
| 395 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
| 396 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 417 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
| 418 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 397 | 419 | unlink($_FILES['attachment']['tmp_name'][$n]); |
| 420 | + } |
|
| 398 | 421 | |
| 399 | 422 | $_FILES['attachment']['tmp_name'] = array(); |
| 400 | 423 | } |
@@ -402,21 +425,24 @@ discard block |
||
| 402 | 425 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
| 403 | 426 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
| 404 | 427 | { |
| 405 | - if ($_FILES['attachment']['name'][$n] == '') |
|
| 406 | - continue; |
|
| 428 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
| 429 | + continue; |
|
| 430 | + } |
|
| 407 | 431 | |
| 408 | 432 | // First, let's first check for PHP upload errors. |
| 409 | 433 | $errors = array(); |
| 410 | 434 | if (!empty($_FILES['attachment']['error'][$n])) |
| 411 | 435 | { |
| 412 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
| 413 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 414 | - elseif ($_FILES['attachment']['error'][$n] == 6) |
|
| 415 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 416 | - else |
|
| 417 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 418 | - if (empty($errors)) |
|
| 419 | - $errors[] = 'attach_php_error'; |
|
| 436 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
| 437 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 438 | + } elseif ($_FILES['attachment']['error'][$n] == 6) { |
|
| 439 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 440 | + } else { |
|
| 441 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 442 | + } |
|
| 443 | + if (empty($errors)) { |
|
| 444 | + $errors[] = 'attach_php_error'; |
|
| 445 | + } |
|
| 420 | 446 | } |
| 421 | 447 | |
| 422 | 448 | // Try to move and rename the file before doing any more checks on it. |
@@ -426,8 +452,9 @@ discard block |
||
| 426 | 452 | { |
| 427 | 453 | // The reported MIME type of the attachment might not be reliable. |
| 428 | 454 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
| 429 | - if (function_exists('mime_content_type')) |
|
| 430 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 455 | + if (function_exists('mime_content_type')) { |
|
| 456 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 457 | + } |
|
| 431 | 458 | |
| 432 | 459 | $_SESSION['temp_attachments'][$attachID] = array( |
| 433 | 460 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -439,16 +466,16 @@ discard block |
||
| 439 | 466 | ); |
| 440 | 467 | |
| 441 | 468 | // Move the file to the attachments folder with a temp name for now. |
| 442 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
| 443 | - smf_chmod($destName, 0644); |
|
| 444 | - else |
|
| 469 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
| 470 | + smf_chmod($destName, 0644); |
|
| 471 | + } else |
|
| 445 | 472 | { |
| 446 | 473 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
| 447 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 448 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 474 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 475 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 476 | + } |
|
| 449 | 477 | } |
| 450 | - } |
|
| 451 | - else |
|
| 478 | + } else |
|
| 452 | 479 | { |
| 453 | 480 | $_SESSION['temp_attachments'][$attachID] = array( |
| 454 | 481 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -456,12 +483,14 @@ discard block |
||
| 456 | 483 | 'errors' => $errors, |
| 457 | 484 | ); |
| 458 | 485 | |
| 459 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 460 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 486 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 487 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 488 | + } |
|
| 461 | 489 | } |
| 462 | 490 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
| 463 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
| 464 | - attachmentChecks($attachID); |
|
| 491 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
| 492 | + attachmentChecks($attachID); |
|
| 493 | + } |
|
| 465 | 494 | } |
| 466 | 495 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
| 467 | 496 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
@@ -488,21 +517,20 @@ discard block |
||
| 488 | 517 | global $modSettings, $context, $sourcedir, $smcFunc; |
| 489 | 518 | |
| 490 | 519 | // No data or missing data .... Not necessarily needed, but in case a mod author missed something. |
| 491 | - if (empty($_SESSION['temp_attachments'][$attachID])) |
|
| 492 | - $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
| 493 | - |
|
| 494 | - elseif (empty($attachID)) |
|
| 495 | - $error = '$attachID'; |
|
| 496 | - |
|
| 497 | - elseif (empty($context['attachments'])) |
|
| 498 | - $error = '$context[\'attachments\']'; |
|
| 499 | - |
|
| 500 | - elseif (empty($context['attach_dir'])) |
|
| 501 | - $error = '$context[\'attach_dir\']'; |
|
| 520 | + if (empty($_SESSION['temp_attachments'][$attachID])) { |
|
| 521 | + $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
| 522 | + } elseif (empty($attachID)) { |
|
| 523 | + $error = '$attachID'; |
|
| 524 | + } elseif (empty($context['attachments'])) { |
|
| 525 | + $error = '$context[\'attachments\']'; |
|
| 526 | + } elseif (empty($context['attach_dir'])) { |
|
| 527 | + $error = '$context[\'attach_dir\']'; |
|
| 528 | + } |
|
| 502 | 529 | |
| 503 | 530 | // Let's get their attention. |
| 504 | - if (!empty($error)) |
|
| 505 | - fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
| 531 | + if (!empty($error)) { |
|
| 532 | + fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
| 533 | + } |
|
| 506 | 534 | |
| 507 | 535 | // Just in case this slipped by the first checks, we stop it here and now |
| 508 | 536 | if ($_SESSION['temp_attachments'][$attachID]['size'] == 0) |
@@ -531,8 +559,9 @@ discard block |
||
| 531 | 559 | $size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']); |
| 532 | 560 | if (!(empty($size)) && ($size[2] != $old_format)) |
| 533 | 561 | { |
| 534 | - if (isset($context['validImageTypes'][$size[2]])) |
|
| 535 | - $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 562 | + if (isset($context['validImageTypes'][$size[2]])) { |
|
| 563 | + $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 564 | + } |
|
| 536 | 565 | } |
| 537 | 566 | } |
| 538 | 567 | } |
@@ -586,42 +615,48 @@ discard block |
||
| 586 | 615 | // Or, let the user know that it ain't gonna happen. |
| 587 | 616 | else |
| 588 | 617 | { |
| 589 | - if (isset($context['dir_creation_error'])) |
|
| 590 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
| 591 | - else |
|
| 592 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 618 | + if (isset($context['dir_creation_error'])) { |
|
| 619 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
| 620 | + } else { |
|
| 621 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 622 | + } |
|
| 593 | 623 | } |
| 624 | + } else { |
|
| 625 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 594 | 626 | } |
| 595 | - else |
|
| 596 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 597 | 627 | } |
| 598 | 628 | } |
| 599 | 629 | |
| 600 | 630 | // Is the file too big? |
| 601 | 631 | $context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size']; |
| 602 | - if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) |
|
| 603 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
| 632 | + if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) { |
|
| 633 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
| 634 | + } |
|
| 604 | 635 | |
| 605 | 636 | // Check the total upload size for this post... |
| 606 | - if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) |
|
| 607 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
| 637 | + if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) { |
|
| 638 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
| 639 | + } |
|
| 608 | 640 | |
| 609 | 641 | // Have we reached the maximum number of files we are allowed? |
| 610 | 642 | $context['attachments']['quantity']++; |
| 611 | 643 | |
| 612 | 644 | // Set a max limit if none exists |
| 613 | - if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) |
|
| 614 | - $modSettings['attachmentNumPerPostLimit'] = 50; |
|
| 645 | + if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) { |
|
| 646 | + $modSettings['attachmentNumPerPostLimit'] = 50; |
|
| 647 | + } |
|
| 615 | 648 | |
| 616 | - if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) |
|
| 617 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
| 649 | + if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) { |
|
| 650 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
| 651 | + } |
|
| 618 | 652 | |
| 619 | 653 | // File extension check |
| 620 | 654 | if (!empty($modSettings['attachmentCheckExtensions'])) |
| 621 | 655 | { |
| 622 | 656 | $allowed = explode(',', strtolower($modSettings['attachmentExtensions'])); |
| 623 | - foreach ($allowed as $k => $dummy) |
|
| 624 | - $allowed[$k] = trim($dummy); |
|
| 657 | + foreach ($allowed as $k => $dummy) { |
|
| 658 | + $allowed[$k] = trim($dummy); |
|
| 659 | + } |
|
| 625 | 660 | |
| 626 | 661 | if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) |
| 627 | 662 | { |
@@ -633,10 +668,12 @@ discard block |
||
| 633 | 668 | // Undo the math if there's an error |
| 634 | 669 | if (!empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
| 635 | 670 | { |
| 636 | - if (isset($context['dir_size'])) |
|
| 637 | - $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
| 638 | - if (isset($context['dir_files'])) |
|
| 639 | - $context['dir_files']--; |
|
| 671 | + if (isset($context['dir_size'])) { |
|
| 672 | + $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
| 673 | + } |
|
| 674 | + if (isset($context['dir_files'])) { |
|
| 675 | + $context['dir_files']--; |
|
| 676 | + } |
|
| 640 | 677 | $context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
| 641 | 678 | $context['attachments']['quantity']--; |
| 642 | 679 | return false; |
@@ -668,12 +705,14 @@ discard block |
||
| 668 | 705 | if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) |
| 669 | 706 | { |
| 670 | 707 | // Got a proper mime type? |
| 671 | - if (!empty($size['mime'])) |
|
| 672 | - $attachmentOptions['mime_type'] = $size['mime']; |
|
| 708 | + if (!empty($size['mime'])) { |
|
| 709 | + $attachmentOptions['mime_type'] = $size['mime']; |
|
| 710 | + } |
|
| 673 | 711 | |
| 674 | 712 | // Otherwise a valid one? |
| 675 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
| 676 | - $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 713 | + elseif (isset($context['validImageTypes'][$size[2]])) { |
|
| 714 | + $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 715 | + } |
|
| 677 | 716 | } |
| 678 | 717 | |
| 679 | 718 | // It is possible we might have a MIME type that isn't actually an image but still have a size. |
@@ -685,15 +724,17 @@ discard block |
||
| 685 | 724 | } |
| 686 | 725 | |
| 687 | 726 | // Get the hash if no hash has been given yet. |
| 688 | - if (empty($attachmentOptions['file_hash'])) |
|
| 689 | - $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
| 727 | + if (empty($attachmentOptions['file_hash'])) { |
|
| 728 | + $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
| 729 | + } |
|
| 690 | 730 | |
| 691 | 731 | // Assuming no-one set the extension let's take a look at it. |
| 692 | 732 | if (empty($attachmentOptions['fileext'])) |
| 693 | 733 | { |
| 694 | 734 | $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : ''); |
| 695 | - if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) |
|
| 696 | - $attachmentOptions['fileext'] = ''; |
|
| 735 | + if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) { |
|
| 736 | + $attachmentOptions['fileext'] = ''; |
|
| 737 | + } |
|
| 697 | 738 | } |
| 698 | 739 | |
| 699 | 740 | // Last chance to change stuff! |
@@ -702,8 +743,9 @@ discard block |
||
| 702 | 743 | // Make sure the folder is valid... |
| 703 | 744 | $tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
| 704 | 745 | $folders = array_keys($tmp); |
| 705 | - if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) |
|
| 706 | - $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
| 746 | + if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) { |
|
| 747 | + $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
| 748 | + } |
|
| 707 | 749 | |
| 708 | 750 | $attachmentOptions['id'] = $smcFunc['db_insert']('', |
| 709 | 751 | '{db_prefix}attachments', |
@@ -734,8 +776,8 @@ discard block |
||
| 734 | 776 | rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']); |
| 735 | 777 | |
| 736 | 778 | // If it's not approved then add to the approval queue. |
| 737 | - if (!$attachmentOptions['approved']) |
|
| 738 | - $smcFunc['db_insert']('', |
|
| 779 | + if (!$attachmentOptions['approved']) { |
|
| 780 | + $smcFunc['db_insert']('', |
|
| 739 | 781 | '{db_prefix}approval_queue', |
| 740 | 782 | array( |
| 741 | 783 | 'id_attach' => 'int', 'id_msg' => 'int', |
@@ -745,9 +787,11 @@ discard block |
||
| 745 | 787 | ), |
| 746 | 788 | array() |
| 747 | 789 | ); |
| 790 | + } |
|
| 748 | 791 | |
| 749 | - if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) |
|
| 750 | - return true; |
|
| 792 | + if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) { |
|
| 793 | + return true; |
|
| 794 | + } |
|
| 751 | 795 | |
| 752 | 796 | // Like thumbnails, do we? |
| 753 | 797 | if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) |
@@ -758,13 +802,15 @@ discard block |
||
| 758 | 802 | $size = @getimagesize($attachmentOptions['destination'] . '_thumb'); |
| 759 | 803 | list ($thumb_width, $thumb_height) = $size; |
| 760 | 804 | |
| 761 | - if (!empty($size['mime'])) |
|
| 762 | - $thumb_mime = $size['mime']; |
|
| 763 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
| 764 | - $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 805 | + if (!empty($size['mime'])) { |
|
| 806 | + $thumb_mime = $size['mime']; |
|
| 807 | + } elseif (isset($context['validImageTypes'][$size[2]])) { |
|
| 808 | + $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 809 | + } |
|
| 765 | 810 | // Lord only knows how this happened... |
| 766 | - else |
|
| 767 | - $thumb_mime = ''; |
|
| 811 | + else { |
|
| 812 | + $thumb_mime = ''; |
|
| 813 | + } |
|
| 768 | 814 | |
| 769 | 815 | $thumb_filename = $attachmentOptions['name'] . '_thumb'; |
| 770 | 816 | $thumb_size = filesize($attachmentOptions['destination'] . '_thumb'); |
@@ -844,15 +890,17 @@ discard block |
||
| 844 | 890 | global $smcFunc; |
| 845 | 891 | |
| 846 | 892 | // Oh, come on! |
| 847 | - if (empty($attachIDs) || empty($msgID)) |
|
| 848 | - return false; |
|
| 893 | + if (empty($attachIDs) || empty($msgID)) { |
|
| 894 | + return false; |
|
| 895 | + } |
|
| 849 | 896 | |
| 850 | 897 | // "I see what is right and approve, but I do what is wrong." |
| 851 | 898 | call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID)); |
| 852 | 899 | |
| 853 | 900 | // One last check |
| 854 | - if (empty($attachIDs)) |
|
| 855 | - return false; |
|
| 901 | + if (empty($attachIDs)) { |
|
| 902 | + return false; |
|
| 903 | + } |
|
| 856 | 904 | |
| 857 | 905 | // Perform. |
| 858 | 906 | $smcFunc['db_query']('', ' |
@@ -880,8 +928,9 @@ discard block |
||
| 880 | 928 | global $board, $modSettings, $context, $scripturl, $smcFunc; |
| 881 | 929 | |
| 882 | 930 | // Meh... |
| 883 | - if (empty($attachID)) |
|
| 884 | - return 'attachments_no_data_loaded'; |
|
| 931 | + if (empty($attachID)) { |
|
| 932 | + return 'attachments_no_data_loaded'; |
|
| 933 | + } |
|
| 885 | 934 | |
| 886 | 935 | // Make it easy. |
| 887 | 936 | $msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0; |
@@ -890,20 +939,23 @@ discard block |
||
| 890 | 939 | $externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID)); |
| 891 | 940 | |
| 892 | 941 | // "I am innocent of the blood of this just person: see ye to it." |
| 893 | - if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) |
|
| 894 | - return $externalParse; |
|
| 942 | + if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) { |
|
| 943 | + return $externalParse; |
|
| 944 | + } |
|
| 895 | 945 | |
| 896 | 946 | //Are attachments enable? |
| 897 | - if (empty($modSettings['attachmentEnable'])) |
|
| 898 | - return 'attachments_not_enable'; |
|
| 947 | + if (empty($modSettings['attachmentEnable'])) { |
|
| 948 | + return 'attachments_not_enable'; |
|
| 949 | + } |
|
| 899 | 950 | |
| 900 | 951 | // Previewing much? no msg ID has been set yet. |
| 901 | 952 | if (!empty($context['preview_message'])) |
| 902 | 953 | { |
| 903 | 954 | $allAttachments = getAttachsByMsg(0); |
| 904 | 955 | |
| 905 | - if (empty($allAttachments[0][$attachID])) |
|
| 906 | - return 'attachments_no_data_loaded'; |
|
| 956 | + if (empty($allAttachments[0][$attachID])) { |
|
| 957 | + return 'attachments_no_data_loaded'; |
|
| 958 | + } |
|
| 907 | 959 | |
| 908 | 960 | $attachLoaded = loadAttachmentContext(0, $allAttachments); |
| 909 | 961 | |
@@ -915,57 +967,66 @@ discard block |
||
| 915 | 967 | $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
| 916 | 968 | |
| 917 | 969 | // Fix the thumbnail too, if the image has one. |
| 918 | - if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) |
|
| 919 | - $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
| 970 | + if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) { |
|
| 971 | + $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
| 972 | + } |
|
| 920 | 973 | |
| 921 | 974 | return $attachContext; |
| 922 | 975 | } |
| 923 | 976 | |
| 924 | 977 | // There is always the chance someone else has already done our dirty work... |
| 925 | 978 | // If so, all pertinent checks were already done. Hopefully... |
| 926 | - if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) |
|
| 927 | - return $context['current_attachments'][$attachID]; |
|
| 979 | + if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) { |
|
| 980 | + return $context['current_attachments'][$attachID]; |
|
| 981 | + } |
|
| 928 | 982 | |
| 929 | 983 | // If we are lucky enough to be in $board's scope then check it! |
| 930 | - if (!empty($board) && !allowedTo('view_attachments', $board)) |
|
| 931 | - return 'attachments_not_allowed_to_see'; |
|
| 984 | + if (!empty($board) && !allowedTo('view_attachments', $board)) { |
|
| 985 | + return 'attachments_not_allowed_to_see'; |
|
| 986 | + } |
|
| 932 | 987 | |
| 933 | 988 | // Get the message info associated with this particular attach ID. |
| 934 | 989 | $attachInfo = getAttachMsgInfo($attachID); |
| 935 | 990 | |
| 936 | 991 | // There is always the chance this attachment no longer exists or isn't associated to a message anymore... |
| 937 | - if (empty($attachInfo) || empty($attachInfo['msg'])) |
|
| 938 | - return 'attachments_no_msg_associated'; |
|
| 992 | + if (empty($attachInfo) || empty($attachInfo['msg'])) { |
|
| 993 | + return 'attachments_no_msg_associated'; |
|
| 994 | + } |
|
| 939 | 995 | |
| 940 | 996 | // Hold it! got the info now check if you can see this attachment. |
| 941 | - if (!allowedTo('view_attachments', $attachInfo['board'])) |
|
| 942 | - return 'attachments_not_allowed_to_see'; |
|
| 997 | + if (!allowedTo('view_attachments', $attachInfo['board'])) { |
|
| 998 | + return 'attachments_not_allowed_to_see'; |
|
| 999 | + } |
|
| 943 | 1000 | |
| 944 | 1001 | $allAttachments = getAttachsByMsg($attachInfo['msg']); |
| 945 | 1002 | $attachContext = $allAttachments[$attachInfo['msg']][$attachID]; |
| 946 | 1003 | |
| 947 | 1004 | // No point in keep going further. |
| 948 | - if (!allowedTo('view_attachments', $attachContext['board'])) |
|
| 949 | - return 'attachments_not_allowed_to_see'; |
|
| 1005 | + if (!allowedTo('view_attachments', $attachContext['board'])) { |
|
| 1006 | + return 'attachments_not_allowed_to_see'; |
|
| 1007 | + } |
|
| 950 | 1008 | |
| 951 | 1009 | // Load this particular attach's context. |
| 952 | - if (!empty($attachContext)) |
|
| 953 | - $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
| 1010 | + if (!empty($attachContext)) { |
|
| 1011 | + $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
| 1012 | + } |
|
| 954 | 1013 | |
| 955 | 1014 | // One last check, you know, gotta be paranoid... |
| 956 | - else |
|
| 957 | - return 'attachments_no_data_loaded'; |
|
| 1015 | + else { |
|
| 1016 | + return 'attachments_no_data_loaded'; |
|
| 1017 | + } |
|
| 958 | 1018 | |
| 959 | 1019 | // This is the last "if" I promise! |
| 960 | - if (empty($attachLoaded)) |
|
| 961 | - return 'attachments_no_data_loaded'; |
|
| 962 | - |
|
| 963 | - else |
|
| 964 | - $attachContext = $attachLoaded[$attachID]; |
|
| 1020 | + if (empty($attachLoaded)) { |
|
| 1021 | + return 'attachments_no_data_loaded'; |
|
| 1022 | + } else { |
|
| 1023 | + $attachContext = $attachLoaded[$attachID]; |
|
| 1024 | + } |
|
| 965 | 1025 | |
| 966 | 1026 | // You may or may not want to show this under the post. |
| 967 | - if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) |
|
| 968 | - $context['show_attach_under_post'][$attachID] = $attachID; |
|
| 1027 | + if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) { |
|
| 1028 | + $context['show_attach_under_post'][$attachID] = $attachID; |
|
| 1029 | + } |
|
| 969 | 1030 | |
| 970 | 1031 | // Last minute changes? |
| 971 | 1032 | call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext)); |
@@ -985,8 +1046,9 @@ discard block |
||
| 985 | 1046 | { |
| 986 | 1047 | global $smcFunc, $modSettings; |
| 987 | 1048 | |
| 988 | - if (empty($attachIDs)) |
|
| 989 | - return array(); |
|
| 1049 | + if (empty($attachIDs)) { |
|
| 1050 | + return array(); |
|
| 1051 | + } |
|
| 990 | 1052 | |
| 991 | 1053 | $return = array(); |
| 992 | 1054 | |
@@ -1002,11 +1064,12 @@ discard block |
||
| 1002 | 1064 | ) |
| 1003 | 1065 | ); |
| 1004 | 1066 | |
| 1005 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1006 | - return array(); |
|
| 1067 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1068 | + return array(); |
|
| 1069 | + } |
|
| 1007 | 1070 | |
| 1008 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1009 | - $return[$row['id_attach']] = array( |
|
| 1071 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1072 | + $return[$row['id_attach']] = array( |
|
| 1010 | 1073 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
| 1011 | 1074 | 'size' => $row['size'], |
| 1012 | 1075 | 'attachID' => $row['id_attach'], |
@@ -1015,6 +1078,7 @@ discard block |
||
| 1015 | 1078 | 'mime_type' => $row['mime_type'], |
| 1016 | 1079 | 'thumb' => $row['id_thumb'], |
| 1017 | 1080 | ); |
| 1081 | + } |
|
| 1018 | 1082 | $smcFunc['db_free_result']($request); |
| 1019 | 1083 | |
| 1020 | 1084 | return $return; |
@@ -1031,8 +1095,9 @@ discard block |
||
| 1031 | 1095 | { |
| 1032 | 1096 | global $smcFunc; |
| 1033 | 1097 | |
| 1034 | - if (empty($attachID)) |
|
| 1035 | - return array(); |
|
| 1098 | + if (empty($attachID)) { |
|
| 1099 | + return array(); |
|
| 1100 | + } |
|
| 1036 | 1101 | |
| 1037 | 1102 | $request = $smcFunc['db_query']('', ' |
| 1038 | 1103 | SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board |
@@ -1045,8 +1110,9 @@ discard block |
||
| 1045 | 1110 | ) |
| 1046 | 1111 | ); |
| 1047 | 1112 | |
| 1048 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1049 | - return array(); |
|
| 1113 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1114 | + return array(); |
|
| 1115 | + } |
|
| 1050 | 1116 | |
| 1051 | 1117 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1052 | 1118 | $smcFunc['db_free_result']($request); |
@@ -1087,8 +1153,9 @@ discard block |
||
| 1087 | 1153 | $temp = array(); |
| 1088 | 1154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1089 | 1155 | { |
| 1090 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
| 1091 | - continue; |
|
| 1156 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
| 1157 | + continue; |
|
| 1158 | + } |
|
| 1092 | 1159 | |
| 1093 | 1160 | $temp[$row['id_attach']] = $row; |
| 1094 | 1161 | } |
@@ -1117,8 +1184,9 @@ discard block |
||
| 1117 | 1184 | { |
| 1118 | 1185 | global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc; |
| 1119 | 1186 | |
| 1120 | - if (empty($attachments) || empty($attachments[$id_msg])) |
|
| 1121 | - return array(); |
|
| 1187 | + if (empty($attachments) || empty($attachments[$id_msg])) { |
|
| 1188 | + return array(); |
|
| 1189 | + } |
|
| 1122 | 1190 | |
| 1123 | 1191 | // Set up the attachment info - based on code by Meriadoc. |
| 1124 | 1192 | $attachmentData = array(); |
@@ -1142,11 +1210,13 @@ discard block |
||
| 1142 | 1210 | ); |
| 1143 | 1211 | |
| 1144 | 1212 | // If something is unapproved we'll note it so we can sort them. |
| 1145 | - if (!$attachment['approved']) |
|
| 1146 | - $have_unapproved = true; |
|
| 1213 | + if (!$attachment['approved']) { |
|
| 1214 | + $have_unapproved = true; |
|
| 1215 | + } |
|
| 1147 | 1216 | |
| 1148 | - if (!$attachmentData[$i]['is_image']) |
|
| 1149 | - continue; |
|
| 1217 | + if (!$attachmentData[$i]['is_image']) { |
|
| 1218 | + continue; |
|
| 1219 | + } |
|
| 1150 | 1220 | |
| 1151 | 1221 | $attachmentData[$i]['real_width'] = $attachment['width']; |
| 1152 | 1222 | $attachmentData[$i]['width'] = $attachment['width']; |
@@ -1167,11 +1237,11 @@ discard block |
||
| 1167 | 1237 | // So what folder are we putting this image in? |
| 1168 | 1238 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
| 1169 | 1239 | { |
| 1170 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 1171 | - $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
| 1240 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 1241 | + $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
| 1242 | + } |
|
| 1172 | 1243 | $id_folder_thumb = $modSettings['currentAttachmentUploadDir']; |
| 1173 | - } |
|
| 1174 | - else |
|
| 1244 | + } else |
|
| 1175 | 1245 | { |
| 1176 | 1246 | $id_folder_thumb = 1; |
| 1177 | 1247 | } |
@@ -1185,10 +1255,11 @@ discard block |
||
| 1185 | 1255 | $thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : ''; |
| 1186 | 1256 | |
| 1187 | 1257 | // Figure out the mime type. |
| 1188 | - if (!empty($size['mime'])) |
|
| 1189 | - $thumb_mime = $size['mime']; |
|
| 1190 | - else |
|
| 1191 | - $thumb_mime = 'image/' . $thumb_ext; |
|
| 1258 | + if (!empty($size['mime'])) { |
|
| 1259 | + $thumb_mime = $size['mime']; |
|
| 1260 | + } else { |
|
| 1261 | + $thumb_mime = 'image/' . $thumb_ext; |
|
| 1262 | + } |
|
| 1192 | 1263 | |
| 1193 | 1264 | $thumb_filename = $attachment['filename'] . '_thumb'; |
| 1194 | 1265 | $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true); |
@@ -1235,11 +1306,12 @@ discard block |
||
| 1235 | 1306 | } |
| 1236 | 1307 | } |
| 1237 | 1308 | |
| 1238 | - if (!empty($attachment['id_thumb'])) |
|
| 1239 | - $attachmentData[$i]['thumbnail'] = array( |
|
| 1309 | + if (!empty($attachment['id_thumb'])) { |
|
| 1310 | + $attachmentData[$i]['thumbnail'] = array( |
|
| 1240 | 1311 | 'id' => $attachment['id_thumb'], |
| 1241 | 1312 | 'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image', |
| 1242 | 1313 | ); |
| 1314 | + } |
|
| 1243 | 1315 | $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']); |
| 1244 | 1316 | |
| 1245 | 1317 | // If thumbnails are disabled, check the maximum size of the image. |
@@ -1249,30 +1321,31 @@ discard block |
||
| 1249 | 1321 | { |
| 1250 | 1322 | $attachmentData[$i]['width'] = $modSettings['max_image_width']; |
| 1251 | 1323 | $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']); |
| 1252 | - } |
|
| 1253 | - elseif (!empty($modSettings['max_image_width'])) |
|
| 1324 | + } elseif (!empty($modSettings['max_image_width'])) |
|
| 1254 | 1325 | { |
| 1255 | 1326 | $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']); |
| 1256 | 1327 | $attachmentData[$i]['height'] = $modSettings['max_image_height']; |
| 1257 | 1328 | } |
| 1258 | - } |
|
| 1259 | - elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
| 1329 | + } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
| 1260 | 1330 | { |
| 1261 | 1331 | // If the image is too large to show inline, make it a popup. |
| 1262 | - if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) |
|
| 1263 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
| 1264 | - else |
|
| 1265 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
| 1332 | + if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) { |
|
| 1333 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
| 1334 | + } else { |
|
| 1335 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
| 1336 | + } |
|
| 1266 | 1337 | } |
| 1267 | 1338 | |
| 1268 | - if (!$attachmentData[$i]['thumbnail']['has_thumb']) |
|
| 1269 | - $attachmentData[$i]['downloads']++; |
|
| 1339 | + if (!$attachmentData[$i]['thumbnail']['has_thumb']) { |
|
| 1340 | + $attachmentData[$i]['downloads']++; |
|
| 1341 | + } |
|
| 1270 | 1342 | } |
| 1271 | 1343 | } |
| 1272 | 1344 | |
| 1273 | 1345 | // Do we need to instigate a sort? |
| 1274 | - if ($have_unapproved) |
|
| 1275 | - usort($attachmentData, 'approved_attach_sort'); |
|
| 1346 | + if ($have_unapproved) { |
|
| 1347 | + usort($attachmentData, 'approved_attach_sort'); |
|
| 1348 | + } |
|
| 1276 | 1349 | |
| 1277 | 1350 | return $attachmentData; |
| 1278 | 1351 | } |
@@ -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,34 +173,39 @@ 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 | 195 | } |
| 190 | - if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
| 191 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
| 192 | - elseif (!empty($stack)) |
|
| 193 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
| 196 | + if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
| 197 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
| 198 | + } elseif (!empty($stack)) { |
|
| 199 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
| 200 | + } |
|
| 194 | 201 | |
| 195 | - if (empty($boardList[$catid])) |
|
| 196 | - $context['categories'][$catid]['move_link'] = array( |
|
| 202 | + if (empty($boardList[$catid])) { |
|
| 203 | + $context['categories'][$catid]['move_link'] = array( |
|
| 197 | 204 | 'child_level' => 0, |
| 198 | 205 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'', |
| 199 | 206 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security, |
| 200 | 207 | ); |
| 208 | + } |
|
| 201 | 209 | } |
| 202 | 210 | } |
| 203 | 211 | |
@@ -253,9 +261,9 @@ discard block |
||
| 253 | 261 | ); |
| 254 | 262 | } |
| 255 | 263 | // Category doesn't exist, man... sorry. |
| 256 | - elseif (!isset($cat_tree[$_REQUEST['cat']])) |
|
| 257 | - redirectexit('action=admin;area=manageboards'); |
|
| 258 | - else |
|
| 264 | + elseif (!isset($cat_tree[$_REQUEST['cat']])) { |
|
| 265 | + redirectexit('action=admin;area=manageboards'); |
|
| 266 | + } else |
|
| 259 | 267 | { |
| 260 | 268 | $context['category'] = array( |
| 261 | 269 | 'id' => $_REQUEST['cat'], |
@@ -267,30 +275,31 @@ discard block |
||
| 267 | 275 | 'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children']) |
| 268 | 276 | ); |
| 269 | 277 | |
| 270 | - foreach ($boardList[$_REQUEST['cat']] as $child_board) |
|
| 271 | - $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
| 278 | + foreach ($boardList[$_REQUEST['cat']] as $child_board) { |
|
| 279 | + $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
| 280 | + } |
|
| 272 | 281 | } |
| 273 | 282 | |
| 274 | 283 | $prevCat = 0; |
| 275 | 284 | foreach ($cat_tree as $catid => $tree) |
| 276 | 285 | { |
| 277 | - if ($catid == $_REQUEST['cat'] && $prevCat > 0) |
|
| 278 | - $context['category_order'][$prevCat]['selected'] = true; |
|
| 279 | - elseif ($catid != $_REQUEST['cat']) |
|
| 280 | - $context['category_order'][$catid] = array( |
|
| 286 | + if ($catid == $_REQUEST['cat'] && $prevCat > 0) { |
|
| 287 | + $context['category_order'][$prevCat]['selected'] = true; |
|
| 288 | + } elseif ($catid != $_REQUEST['cat']) { |
|
| 289 | + $context['category_order'][$catid] = array( |
|
| 281 | 290 | 'id' => $catid, |
| 282 | 291 | 'name' => $txt['mboards_order_after'] . $tree['node']['name'], |
| 283 | 292 | 'selected' => false, |
| 284 | 293 | 'true_name' => $tree['node']['name'] |
| 285 | 294 | ); |
| 295 | + } |
|
| 286 | 296 | $prevCat = $catid; |
| 287 | 297 | } |
| 288 | 298 | if (!isset($_REQUEST['delete'])) |
| 289 | 299 | { |
| 290 | 300 | $context['sub_template'] = 'modify_category'; |
| 291 | 301 | $context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit']; |
| 292 | - } |
|
| 293 | - else |
|
| 302 | + } else |
|
| 294 | 303 | { |
| 295 | 304 | $context['sub_template'] = 'confirm_category_delete'; |
| 296 | 305 | $context['page_title'] = $txt['mboards_delete_cat']; |
@@ -327,8 +336,9 @@ discard block |
||
| 327 | 336 | { |
| 328 | 337 | $catOptions = array(); |
| 329 | 338 | |
| 330 | - if (isset($_POST['cat_order'])) |
|
| 331 | - $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
| 339 | + if (isset($_POST['cat_order'])) { |
|
| 340 | + $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
| 341 | + } |
|
| 332 | 342 | |
| 333 | 343 | // Change "This & That" to "This & That" but don't change "¢" to "&cent;"... |
| 334 | 344 | $catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']); |
@@ -336,10 +346,11 @@ discard block |
||
| 336 | 346 | |
| 337 | 347 | $catOptions['is_collapsible'] = isset($_POST['collapse']); |
| 338 | 348 | |
| 339 | - if (isset($_POST['add'])) |
|
| 340 | - createCategory($catOptions); |
|
| 341 | - else |
|
| 342 | - modifyCategory($_POST['cat'], $catOptions); |
|
| 349 | + if (isset($_POST['add'])) { |
|
| 350 | + createCategory($catOptions); |
|
| 351 | + } else { |
|
| 352 | + modifyCategory($_POST['cat'], $catOptions); |
|
| 353 | + } |
|
| 343 | 354 | } |
| 344 | 355 | // If they want to delete - first give them confirmation. |
| 345 | 356 | elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty'])) |
@@ -353,13 +364,14 @@ discard block |
||
| 353 | 364 | // First off - check if we are moving all the current boards first - before we start deleting! |
| 354 | 365 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
| 355 | 366 | { |
| 356 | - if (empty($_POST['cat_to'])) |
|
| 357 | - fatal_lang_error('mboards_delete_error'); |
|
| 367 | + if (empty($_POST['cat_to'])) { |
|
| 368 | + fatal_lang_error('mboards_delete_error'); |
|
| 369 | + } |
|
| 358 | 370 | |
| 359 | 371 | deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']); |
| 372 | + } else { |
|
| 373 | + deleteCategories(array($_POST['cat'])); |
|
| 360 | 374 | } |
| 361 | - else |
|
| 362 | - deleteCategories(array($_POST['cat'])); |
|
| 363 | 375 | } |
| 364 | 376 | |
| 365 | 377 | redirectexit('action=admin;area=manageboards'); |
@@ -404,8 +416,9 @@ discard block |
||
| 404 | 416 | if ($_REQUEST['sa'] == 'newboard') |
| 405 | 417 | { |
| 406 | 418 | // Category doesn't exist, man... sorry. |
| 407 | - if (empty($_REQUEST['cat'])) |
|
| 408 | - redirectexit('action=admin;area=manageboards'); |
|
| 419 | + if (empty($_REQUEST['cat'])) { |
|
| 420 | + redirectexit('action=admin;area=manageboards'); |
|
| 421 | + } |
|
| 409 | 422 | |
| 410 | 423 | // Some things that need to be setup for a new board. |
| 411 | 424 | $curBoard = array( |
@@ -429,8 +442,7 @@ discard block |
||
| 429 | 442 | 'category' => (int) $_REQUEST['cat'], |
| 430 | 443 | 'no_children' => true, |
| 431 | 444 | ); |
| 432 | - } |
|
| 433 | - else |
|
| 445 | + } else |
|
| 434 | 446 | { |
| 435 | 447 | // Just some easy shortcuts. |
| 436 | 448 | $curBoard = &$boards[$_REQUEST['boardid']]; |
@@ -478,8 +490,9 @@ discard block |
||
| 478 | 490 | ); |
| 479 | 491 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 480 | 492 | { |
| 481 | - if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) |
|
| 482 | - $curBoard['member_groups'][] = $row['id_group']; |
|
| 493 | + if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) { |
|
| 494 | + $curBoard['member_groups'][] = $row['id_group']; |
|
| 495 | + } |
|
| 483 | 496 | |
| 484 | 497 | $context['groups'][(int) $row['id_group']] = array( |
| 485 | 498 | 'id' => $row['id_group'], |
@@ -492,8 +505,9 @@ discard block |
||
| 492 | 505 | $smcFunc['db_free_result']($request); |
| 493 | 506 | |
| 494 | 507 | // Category doesn't exist, man... sorry. |
| 495 | - if (!isset($boardList[$curBoard['category']])) |
|
| 496 | - redirectexit('action=admin;area=manageboards'); |
|
| 508 | + if (!isset($boardList[$curBoard['category']])) { |
|
| 509 | + redirectexit('action=admin;area=manageboards'); |
|
| 510 | + } |
|
| 497 | 511 | |
| 498 | 512 | foreach ($boardList[$curBoard['category']] as $boardid) |
| 499 | 513 | { |
@@ -507,8 +521,7 @@ discard block |
||
| 507 | 521 | 'is_child' => false, |
| 508 | 522 | 'selected' => true |
| 509 | 523 | ); |
| 510 | - } |
|
| 511 | - else |
|
| 524 | + } else |
|
| 512 | 525 | { |
| 513 | 526 | $context['board_order'][] = array( |
| 514 | 527 | 'id' => $boardid, |
@@ -525,19 +538,21 @@ discard block |
||
| 525 | 538 | $context['can_move_children'] = false; |
| 526 | 539 | $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children']; |
| 527 | 540 | |
| 528 | - foreach ($context['board_order'] as $lBoard) |
|
| 529 | - if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
| 541 | + foreach ($context['board_order'] as $lBoard) { |
|
| 542 | + if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
| 530 | 543 | $context['can_move_children'] = true; |
| 544 | + } |
|
| 531 | 545 | } |
| 532 | 546 | |
| 533 | 547 | // Get other available categories. |
| 534 | 548 | $context['categories'] = array(); |
| 535 | - foreach ($cat_tree as $catID => $tree) |
|
| 536 | - $context['categories'][] = array( |
|
| 549 | + foreach ($cat_tree as $catID => $tree) { |
|
| 550 | + $context['categories'][] = array( |
|
| 537 | 551 | 'id' => $catID == $curBoard['category'] ? 0 : $catID, |
| 538 | 552 | 'name' => $tree['node']['name'], |
| 539 | 553 | 'selected' => $catID == $curBoard['category'] |
| 540 | 554 | ); |
| 555 | + } |
|
| 541 | 556 | |
| 542 | 557 | $request = $smcFunc['db_query']('', ' |
| 543 | 558 | SELECT mem.id_member, mem.real_name |
@@ -549,14 +564,16 @@ discard block |
||
| 549 | 564 | ) |
| 550 | 565 | ); |
| 551 | 566 | $context['board']['moderators'] = array(); |
| 552 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 553 | - $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 567 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 568 | + $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 569 | + } |
|
| 554 | 570 | $smcFunc['db_free_result']($request); |
| 555 | 571 | |
| 556 | 572 | $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"'; |
| 557 | 573 | |
| 558 | - if (!empty($context['board']['moderators'])) |
|
| 559 | - list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
| 574 | + if (!empty($context['board']['moderators'])) { |
|
| 575 | + list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
| 576 | + } |
|
| 560 | 577 | |
| 561 | 578 | // Get all the groups assigned as moderators |
| 562 | 579 | $request = $smcFunc['db_query']('', ' |
@@ -568,14 +585,16 @@ discard block |
||
| 568 | 585 | ) |
| 569 | 586 | ); |
| 570 | 587 | $context['board']['moderator_groups'] = array(); |
| 571 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 572 | - $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
| 588 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 589 | + $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
| 590 | + } |
|
| 573 | 591 | $smcFunc['db_free_result']($request); |
| 574 | 592 | |
| 575 | 593 | $context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '"' . implode('", &qout;', $context['board']['moderator_groups']) . '"'; |
| 576 | 594 | |
| 577 | - if (!empty($context['board']['moderator_groups'])) |
|
| 578 | - list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
| 595 | + if (!empty($context['board']['moderator_groups'])) { |
|
| 596 | + list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
| 597 | + } |
|
| 579 | 598 | |
| 580 | 599 | // Get all the themes... |
| 581 | 600 | $request = $smcFunc['db_query']('', ' |
@@ -587,8 +606,9 @@ discard block |
||
| 587 | 606 | ) |
| 588 | 607 | ); |
| 589 | 608 | $context['themes'] = array(); |
| 590 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 591 | - $context['themes'][] = $row; |
|
| 609 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 610 | + $context['themes'][] = $row; |
|
| 611 | + } |
|
| 592 | 612 | $smcFunc['db_free_result']($request); |
| 593 | 613 | |
| 594 | 614 | if (!isset($_REQUEST['delete'])) |
@@ -596,8 +616,7 @@ discard block |
||
| 596 | 616 | $context['sub_template'] = 'modify_board'; |
| 597 | 617 | $context['page_title'] = $txt['boardsEdit']; |
| 598 | 618 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
| 599 | - } |
|
| 600 | - else |
|
| 619 | + } else |
|
| 601 | 620 | { |
| 602 | 621 | $context['sub_template'] = 'confirm_board_delete'; |
| 603 | 622 | $context['page_title'] = $txt['mboards_delete_board']; |
@@ -641,8 +660,9 @@ discard block |
||
| 641 | 660 | // Change the boardorder of this board? |
| 642 | 661 | elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) |
| 643 | 662 | { |
| 644 | - if (!in_array($_POST['placement'], array('before', 'after', 'child'))) |
|
| 645 | - fatal_lang_error('mangled_post', false); |
|
| 663 | + if (!in_array($_POST['placement'], array('before', 'after', 'child'))) { |
|
| 664 | + fatal_lang_error('mangled_post', false); |
|
| 665 | + } |
|
| 646 | 666 | |
| 647 | 667 | $boardOptions['move_to'] = $_POST['placement']; |
| 648 | 668 | $boardOptions['target_board'] = (int) $_POST['board_order']; |
@@ -655,13 +675,14 @@ discard block |
||
| 655 | 675 | $boardOptions['access_groups'] = array(); |
| 656 | 676 | $boardOptions['deny_groups'] = array(); |
| 657 | 677 | |
| 658 | - if (!empty($_POST['groups'])) |
|
| 659 | - foreach ($_POST['groups'] as $group => $action) |
|
| 678 | + if (!empty($_POST['groups'])) { |
|
| 679 | + foreach ($_POST['groups'] as $group => $action) |
|
| 660 | 680 | { |
| 661 | 681 | if ($action == 'allow') |
| 662 | 682 | $boardOptions['access_groups'][] = (int) $group; |
| 663 | - elseif ($action == 'deny') |
|
| 664 | - $boardOptions['deny_groups'][] = (int) $group; |
|
| 683 | + } elseif ($action == 'deny') { |
|
| 684 | + $boardOptions['deny_groups'][] = (int) $group; |
|
| 685 | + } |
|
| 665 | 686 | } |
| 666 | 687 | |
| 667 | 688 | // People with manage-boards are special. |
@@ -673,8 +694,9 @@ discard block |
||
| 673 | 694 | // Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded. |
| 674 | 695 | $boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers)); |
| 675 | 696 | |
| 676 | - if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) |
|
| 677 | - fatal_lang_error('too_many_groups', false); |
|
| 697 | + if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) { |
|
| 698 | + fatal_lang_error('too_many_groups', false); |
|
| 699 | + } |
|
| 678 | 700 | |
| 679 | 701 | // Do not allow HTML tags. Parse the string. |
| 680 | 702 | $boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']); |
@@ -685,8 +707,9 @@ discard block |
||
| 685 | 707 | if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list'])) |
| 686 | 708 | { |
| 687 | 709 | $moderators = array(); |
| 688 | - foreach ($_POST['moderator_list'] as $moderator) |
|
| 689 | - $moderators[(int) $moderator] = (int) $moderator; |
|
| 710 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
| 711 | + $moderators[(int) $moderator] = (int) $moderator; |
|
| 712 | + } |
|
| 690 | 713 | $boardOptions['moderators'] = $moderators; |
| 691 | 714 | } |
| 692 | 715 | |
@@ -695,8 +718,9 @@ discard block |
||
| 695 | 718 | if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list'])) |
| 696 | 719 | { |
| 697 | 720 | $moderator_groups = array(); |
| 698 | - foreach ($_POST['moderator_group_list'] as $moderator_group) |
|
| 699 | - $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
| 721 | + foreach ($_POST['moderator_group_list'] as $moderator_group) { |
|
| 722 | + $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
| 723 | + } |
|
| 700 | 724 | $boardOptions['moderator_groups'] = $moderator_groups; |
| 701 | 725 | } |
| 702 | 726 | |
@@ -722,56 +746,62 @@ discard block |
||
| 722 | 746 | $smcFunc['db_free_result']($request); |
| 723 | 747 | |
| 724 | 748 | // 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. |
| 725 | - if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) |
|
| 726 | - unset($boardOptions['redirect']); |
|
| 749 | + if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) { |
|
| 750 | + unset($boardOptions['redirect']); |
|
| 751 | + } |
|
| 727 | 752 | // Reset the redirection count when switching on/off. |
| 728 | - elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) |
|
| 729 | - $boardOptions['num_posts'] = 0; |
|
| 753 | + elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) { |
|
| 754 | + $boardOptions['num_posts'] = 0; |
|
| 755 | + } |
|
| 730 | 756 | // Resetting the count? |
| 731 | - elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) |
|
| 732 | - $boardOptions['num_posts'] = 0; |
|
| 757 | + elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) { |
|
| 758 | + $boardOptions['num_posts'] = 0; |
|
| 759 | + } |
|
| 733 | 760 | } |
| 734 | 761 | |
| 735 | 762 | // Create a new board... |
| 736 | 763 | if (isset($_POST['add'])) |
| 737 | 764 | { |
| 738 | 765 | // New boards by default go to the bottom of the category. |
| 739 | - if (empty($_POST['new_cat'])) |
|
| 740 | - $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
| 741 | - if (!isset($boardOptions['move_to'])) |
|
| 742 | - $boardOptions['move_to'] = 'bottom'; |
|
| 766 | + if (empty($_POST['new_cat'])) { |
|
| 767 | + $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
| 768 | + } |
|
| 769 | + if (!isset($boardOptions['move_to'])) { |
|
| 770 | + $boardOptions['move_to'] = 'bottom'; |
|
| 771 | + } |
|
| 743 | 772 | |
| 744 | 773 | createBoard($boardOptions); |
| 745 | 774 | } |
| 746 | 775 | |
| 747 | 776 | // ...or update an existing board. |
| 748 | - else |
|
| 749 | - modifyBoard($_POST['boardid'], $boardOptions); |
|
| 750 | - } |
|
| 751 | - elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
| 777 | + else { |
|
| 778 | + modifyBoard($_POST['boardid'], $boardOptions); |
|
| 779 | + } |
|
| 780 | + } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
| 752 | 781 | { |
| 753 | 782 | EditBoard(); |
| 754 | 783 | return; |
| 755 | - } |
|
| 756 | - elseif (isset($_POST['delete'])) |
|
| 784 | + } elseif (isset($_POST['delete'])) |
|
| 757 | 785 | { |
| 758 | 786 | // First off - check if we are moving all the current child boards first - before we start deleting! |
| 759 | 787 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
| 760 | 788 | { |
| 761 | - if (empty($_POST['board_to'])) |
|
| 762 | - fatal_lang_error('mboards_delete_board_error'); |
|
| 789 | + if (empty($_POST['board_to'])) { |
|
| 790 | + fatal_lang_error('mboards_delete_board_error'); |
|
| 791 | + } |
|
| 763 | 792 | |
| 764 | 793 | deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']); |
| 794 | + } else { |
|
| 795 | + deleteBoards(array($_POST['boardid']), 0); |
|
| 765 | 796 | } |
| 766 | - else |
|
| 767 | - deleteBoards(array($_POST['boardid']), 0); |
|
| 768 | 797 | } |
| 769 | 798 | |
| 770 | - if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') |
|
| 771 | - redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 772 | - else |
|
| 773 | - redirectexit('action=admin;area=manageboards'); |
|
| 774 | -} |
|
| 799 | + if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') { |
|
| 800 | + redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 801 | + } else { |
|
| 802 | + redirectexit('action=admin;area=manageboards'); |
|
| 803 | + } |
|
| 804 | + } |
|
| 775 | 805 | |
| 776 | 806 | /** |
| 777 | 807 | * Used to retrieve data for modifying a board category |
@@ -808,8 +838,9 @@ discard block |
||
| 808 | 838 | $smcFunc['db_free_result']($request); |
| 809 | 839 | |
| 810 | 840 | // This would probably never happen, but just to be sure. |
| 811 | - if ($cat .= $allowed_sa[1]) |
|
| 812 | - die(str_replace(',', ' to', $cat)); |
|
| 841 | + if ($cat .= $allowed_sa[1]) { |
|
| 842 | + die(str_replace(',', ' to', $cat)); |
|
| 843 | + } |
|
| 813 | 844 | |
| 814 | 845 | redirectexit(); |
| 815 | 846 | } |
@@ -835,8 +866,9 @@ discard block |
||
| 835 | 866 | 'empty_string' => '', |
| 836 | 867 | ) |
| 837 | 868 | ); |
| 838 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 839 | - $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
| 869 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 870 | + $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
| 871 | + } |
|
| 840 | 872 | $smcFunc['db_free_result']($request); |
| 841 | 873 | |
| 842 | 874 | if (!empty($recycle_boards)) |
@@ -844,9 +876,9 @@ discard block |
||
| 844 | 876 | require_once($sourcedir . '/Subs-Boards.php'); |
| 845 | 877 | sortBoards($recycle_boards); |
| 846 | 878 | $recycle_boards = array('') + $recycle_boards; |
| 879 | + } else { |
|
| 880 | + $recycle_boards = array(''); |
|
| 847 | 881 | } |
| 848 | - else |
|
| 849 | - $recycle_boards = array(''); |
|
| 850 | 882 | |
| 851 | 883 | // Here and the board settings... |
| 852 | 884 | $config_vars = array( |
@@ -864,8 +896,9 @@ discard block |
||
| 864 | 896 | |
| 865 | 897 | call_integration_hook('integrate_modify_board_settings', array(&$config_vars)); |
| 866 | 898 | |
| 867 | - if ($return_config) |
|
| 868 | - return $config_vars; |
|
| 899 | + if ($return_config) { |
|
| 900 | + return $config_vars; |
|
| 901 | + } |
|
| 869 | 902 | |
| 870 | 903 | // Needed for the settings template. |
| 871 | 904 | require_once($sourcedir . '/ManageServer.php'); |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 4 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * This defines every profile field known to man. |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | global $sourcedir, $profile_vars; |
| 30 | 31 | |
| 31 | 32 | // Don't load this twice! |
| 32 | - if (!empty($profile_fields) && !$force_reload) |
|
| 33 | - return; |
|
| 33 | + if (!empty($profile_fields) && !$force_reload) { |
|
| 34 | + return; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | /* This horrific array defines all the profile fields in the whole world! |
| 36 | 38 | In general each "field" has one array - the key of which is the database column name associated with said field. Each item |
@@ -103,13 +105,14 @@ discard block |
||
| 103 | 105 | if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0) |
| 104 | 106 | { |
| 105 | 107 | // Set to blank? |
| 106 | - if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) |
|
| 107 | - $value = '1004-01-01'; |
|
| 108 | - else |
|
| 109 | - $value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01'; |
|
| 108 | + if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) { |
|
| 109 | + $value = '1004-01-01'; |
|
| 110 | + } else { |
|
| 111 | + $value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01'; |
|
| 112 | + } |
|
| 113 | + } else { |
|
| 114 | + $value = '1004-01-01'; |
|
| 110 | 115 | } |
| 111 | - else |
|
| 112 | - $value = '1004-01-01'; |
|
| 113 | 116 | |
| 114 | 117 | $profile_vars['birthdate'] = $value; |
| 115 | 118 | $cur_profile['birthdate'] = $value; |
@@ -127,8 +130,7 @@ discard block |
||
| 127 | 130 | { |
| 128 | 131 | $value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '1004-01-01'; |
| 129 | 132 | return true; |
| 130 | - } |
|
| 131 | - else |
|
| 133 | + } else |
|
| 132 | 134 | { |
| 133 | 135 | $value = empty($cur_profile['birthdate']) ? '1004-01-01' : $cur_profile['birthdate']; |
| 134 | 136 | return false; |
@@ -150,10 +152,11 @@ discard block |
||
| 150 | 152 | return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false)); |
| 151 | 153 | } |
| 152 | 154 | // As long as it doesn't equal "N/A"... |
| 153 | - elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) |
|
| 154 | - $value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 155 | - else |
|
| 156 | - $value = $cur_profile['date_registered']; |
|
| 155 | + elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) { |
|
| 156 | + $value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 157 | + } else { |
|
| 158 | + $value = $cur_profile['date_registered']; |
|
| 159 | + } |
|
| 157 | 160 | |
| 158 | 161 | return true; |
| 159 | 162 | }, |
@@ -177,8 +180,9 @@ discard block |
||
| 177 | 180 | { |
| 178 | 181 | global $context, $old_profile, $profile_vars, $sourcedir, $modSettings; |
| 179 | 182 | |
| 180 | - if (strtolower($value) == strtolower($old_profile['email_address'])) |
|
| 181 | - return false; |
|
| 183 | + if (strtolower($value) == strtolower($old_profile['email_address'])) { |
|
| 184 | + return false; |
|
| 185 | + } |
|
| 182 | 186 | |
| 183 | 187 | $isValid = profileValidateEmail($value, $context['id_member']); |
| 184 | 188 | |
@@ -254,11 +258,11 @@ discard block |
||
| 254 | 258 | |
| 255 | 259 | if (isset($context['profile_languages'][$value])) |
| 256 | 260 | { |
| 257 | - if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) |
|
| 258 | - $_SESSION['language'] = $value; |
|
| 261 | + if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) { |
|
| 262 | + $_SESSION['language'] = $value; |
|
| 263 | + } |
|
| 259 | 264 | return true; |
| 260 | - } |
|
| 261 | - else |
|
| 265 | + } else |
|
| 262 | 266 | { |
| 263 | 267 | $value = $cur_profile['lngfile']; |
| 264 | 268 | return false; |
@@ -282,13 +286,14 @@ discard block |
||
| 282 | 286 | |
| 283 | 287 | // Maybe they are trying to change their password as well? |
| 284 | 288 | $resetPassword = true; |
| 285 | - if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) |
|
| 286 | - $resetPassword = false; |
|
| 289 | + if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) { |
|
| 290 | + $resetPassword = false; |
|
| 291 | + } |
|
| 287 | 292 | |
| 288 | 293 | // Do the reset... this will send them an email too. |
| 289 | - if ($resetPassword) |
|
| 290 | - resetPassword($context['id_member'], $value); |
|
| 291 | - elseif ($value !== null) |
|
| 294 | + if ($resetPassword) { |
|
| 295 | + resetPassword($context['id_member'], $value); |
|
| 296 | + } elseif ($value !== null) |
|
| 292 | 297 | { |
| 293 | 298 | validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value))); |
| 294 | 299 | updateMemberData($context['id_member'], array('member_name' => $value)); |
@@ -312,20 +317,23 @@ discard block |
||
| 312 | 317 | 'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile) |
| 313 | 318 | { |
| 314 | 319 | // If we didn't try it then ignore it! |
| 315 | - if ($value == '') |
|
| 316 | - return false; |
|
| 320 | + if ($value == '') { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 317 | 323 | |
| 318 | 324 | // Do the two entries for the password even match? |
| 319 | - if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) |
|
| 320 | - return 'bad_new_password'; |
|
| 325 | + if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) { |
|
| 326 | + return 'bad_new_password'; |
|
| 327 | + } |
|
| 321 | 328 | |
| 322 | 329 | // Let's get the validation function into play... |
| 323 | 330 | require_once($sourcedir . '/Subs-Auth.php'); |
| 324 | 331 | $passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])); |
| 325 | 332 | |
| 326 | 333 | // Were there errors? |
| 327 | - if ($passwordErrors != null) |
|
| 328 | - return 'password_' . $passwordErrors; |
|
| 334 | + if ($passwordErrors != null) { |
|
| 335 | + return 'password_' . $passwordErrors; |
|
| 336 | + } |
|
| 329 | 337 | |
| 330 | 338 | // Set up the new password variable... ready for storage. |
| 331 | 339 | $value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value)); |
@@ -350,8 +358,9 @@ discard block |
||
| 350 | 358 | 'permission' => 'profile_blurb', |
| 351 | 359 | 'input_validate' => function(&$value) use ($smcFunc) |
| 352 | 360 | { |
| 353 | - if ($smcFunc['strlen']($value) > 50) |
|
| 354 | - return 'personal_text_too_long'; |
|
| 361 | + if ($smcFunc['strlen']($value) > 50) { |
|
| 362 | + return 'personal_text_too_long'; |
|
| 363 | + } |
|
| 355 | 364 | |
| 356 | 365 | return true; |
| 357 | 366 | }, |
@@ -386,10 +395,11 @@ discard block |
||
| 386 | 395 | 'permission' => 'moderate_forum', |
| 387 | 396 | 'input_validate' => function(&$value) |
| 388 | 397 | { |
| 389 | - if (!is_numeric($value)) |
|
| 390 | - return 'digits_only'; |
|
| 391 | - else |
|
| 392 | - $value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0; |
|
| 398 | + if (!is_numeric($value)) { |
|
| 399 | + return 'digits_only'; |
|
| 400 | + } else { |
|
| 401 | + $value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0; |
|
| 402 | + } |
|
| 393 | 403 | return true; |
| 394 | 404 | }, |
| 395 | 405 | ), |
@@ -405,15 +415,16 @@ discard block |
||
| 405 | 415 | { |
| 406 | 416 | $value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)); |
| 407 | 417 | |
| 408 | - if (trim($value) == '') |
|
| 409 | - return 'no_name'; |
|
| 410 | - elseif ($smcFunc['strlen']($value) > 60) |
|
| 411 | - return 'name_too_long'; |
|
| 412 | - elseif ($cur_profile['real_name'] != $value) |
|
| 418 | + if (trim($value) == '') { |
|
| 419 | + return 'no_name'; |
|
| 420 | + } elseif ($smcFunc['strlen']($value) > 60) { |
|
| 421 | + return 'name_too_long'; |
|
| 422 | + } elseif ($cur_profile['real_name'] != $value) |
|
| 413 | 423 | { |
| 414 | 424 | require_once($sourcedir . '/Subs-Members.php'); |
| 415 | - if (isReservedName($value, $context['id_member'])) |
|
| 416 | - return 'name_taken'; |
|
| 425 | + if (isReservedName($value, $context['id_member'])) { |
|
| 426 | + return 'name_taken'; |
|
| 427 | + } |
|
| 417 | 428 | } |
| 418 | 429 | return true; |
| 419 | 430 | }, |
@@ -471,8 +482,9 @@ discard block |
||
| 471 | 482 | 'selected' => $set == $context['member']['smiley_set']['id'] |
| 472 | 483 | ); |
| 473 | 484 | |
| 474 | - if ($context['smiley_sets'][$i]['selected']) |
|
| 475 | - $context['member']['smiley_set']['name'] = $set_names[$i]; |
|
| 485 | + if ($context['smiley_sets'][$i]['selected']) { |
|
| 486 | + $context['member']['smiley_set']['name'] = $set_names[$i]; |
|
| 487 | + } |
|
| 476 | 488 | } |
| 477 | 489 | return true; |
| 478 | 490 | }, |
@@ -481,8 +493,9 @@ discard block |
||
| 481 | 493 | global $modSettings; |
| 482 | 494 | |
| 483 | 495 | $smiley_sets = explode(',', $modSettings['smiley_sets_known']); |
| 484 | - if (!in_array($value, $smiley_sets) && $value != 'none') |
|
| 485 | - $value = ''; |
|
| 496 | + if (!in_array($value, $smiley_sets) && $value != 'none') { |
|
| 497 | + $value = ''; |
|
| 498 | + } |
|
| 486 | 499 | return true; |
| 487 | 500 | }, |
| 488 | 501 | ), |
@@ -497,8 +510,9 @@ discard block |
||
| 497 | 510 | loadLanguage('Settings'); |
| 498 | 511 | |
| 499 | 512 | $context['allow_no_censored'] = false; |
| 500 | - if ($user_info['is_admin'] || $context['user']['is_owner']) |
|
| 501 | - $context['allow_no_censored'] = !empty($modSettings['allow_no_censored']); |
|
| 513 | + if ($user_info['is_admin'] || $context['user']['is_owner']) { |
|
| 514 | + $context['allow_no_censored'] = !empty($modSettings['allow_no_censored']); |
|
| 515 | + } |
|
| 502 | 516 | |
| 503 | 517 | return true; |
| 504 | 518 | }, |
@@ -545,8 +559,9 @@ discard block |
||
| 545 | 559 | 'input_validate' => function($value) |
| 546 | 560 | { |
| 547 | 561 | $tz = smf_list_timezones(); |
| 548 | - if (!isset($tz[$value])) |
|
| 549 | - return 'bad_timezone'; |
|
| 562 | + if (!isset($tz[$value])) { |
|
| 563 | + return 'bad_timezone'; |
|
| 564 | + } |
|
| 550 | 565 | |
| 551 | 566 | return true; |
| 552 | 567 | }, |
@@ -561,8 +576,9 @@ discard block |
||
| 561 | 576 | 'enabled' => !empty($modSettings['titlesEnable']), |
| 562 | 577 | 'input_validate' => function(&$value) use ($smcFunc) |
| 563 | 578 | { |
| 564 | - if ($smcFunc['strlen']($value) > 50) |
|
| 565 | - return 'user_title_too_long'; |
|
| 579 | + if ($smcFunc['strlen']($value) > 50) { |
|
| 580 | + return 'user_title_too_long'; |
|
| 581 | + } |
|
| 566 | 582 | |
| 567 | 583 | return true; |
| 568 | 584 | }, |
@@ -584,10 +600,12 @@ discard block |
||
| 584 | 600 | // Fix the URL... |
| 585 | 601 | 'input_validate' => function(&$value) |
| 586 | 602 | { |
| 587 | - if (strlen(trim($value)) > 0 && strpos($value, '://') === false) |
|
| 588 | - $value = 'http://' . $value; |
|
| 589 | - if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) |
|
| 590 | - $value = ''; |
|
| 603 | + if (strlen(trim($value)) > 0 && strpos($value, '://') === false) { |
|
| 604 | + $value = 'http://' . $value; |
|
| 605 | + } |
|
| 606 | + if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) { |
|
| 607 | + $value = ''; |
|
| 608 | + } |
|
| 591 | 609 | return true; |
| 592 | 610 | }, |
| 593 | 611 | 'link_with' => 'website', |
@@ -601,16 +619,19 @@ discard block |
||
| 601 | 619 | foreach ($profile_fields as $key => $field) |
| 602 | 620 | { |
| 603 | 621 | // Do we have permission to do this? |
| 604 | - if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) |
|
| 605 | - unset($profile_fields[$key]); |
|
| 622 | + if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) { |
|
| 623 | + unset($profile_fields[$key]); |
|
| 624 | + } |
|
| 606 | 625 | |
| 607 | 626 | // Is it enabled? |
| 608 | - if (isset($field['enabled']) && !$field['enabled']) |
|
| 609 | - unset($profile_fields[$key]); |
|
| 627 | + if (isset($field['enabled']) && !$field['enabled']) { |
|
| 628 | + unset($profile_fields[$key]); |
|
| 629 | + } |
|
| 610 | 630 | |
| 611 | 631 | // Is it specifically disabled? |
| 612 | - if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) |
|
| 613 | - unset($profile_fields[$key]); |
|
| 632 | + if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) { |
|
| 633 | + unset($profile_fields[$key]); |
|
| 634 | + } |
|
| 614 | 635 | } |
| 615 | 636 | } |
| 616 | 637 | |
@@ -635,9 +656,10 @@ discard block |
||
| 635 | 656 | loadProfileFields(true); |
| 636 | 657 | |
| 637 | 658 | // First check for any linked sets. |
| 638 | - foreach ($profile_fields as $key => $field) |
|
| 639 | - if (isset($field['link_with']) && in_array($field['link_with'], $fields)) |
|
| 659 | + foreach ($profile_fields as $key => $field) { |
|
| 660 | + if (isset($field['link_with']) && in_array($field['link_with'], $fields)) |
|
| 640 | 661 | $fields[] = $key; |
| 662 | + } |
|
| 641 | 663 | |
| 642 | 664 | $i = 0; |
| 643 | 665 | $last_type = ''; |
@@ -649,38 +671,46 @@ discard block |
||
| 649 | 671 | $cur_field = &$profile_fields[$field]; |
| 650 | 672 | |
| 651 | 673 | // Does it have a preload and does that preload succeed? |
| 652 | - if (isset($cur_field['preload']) && !$cur_field['preload']()) |
|
| 653 | - continue; |
|
| 674 | + if (isset($cur_field['preload']) && !$cur_field['preload']()) { |
|
| 675 | + continue; |
|
| 676 | + } |
|
| 654 | 677 | |
| 655 | 678 | // If this is anything but complex we need to do more cleaning! |
| 656 | 679 | if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden') |
| 657 | 680 | { |
| 658 | - if (!isset($cur_field['label'])) |
|
| 659 | - $cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field; |
|
| 681 | + if (!isset($cur_field['label'])) { |
|
| 682 | + $cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field; |
|
| 683 | + } |
|
| 660 | 684 | |
| 661 | 685 | // Everything has a value! |
| 662 | - if (!isset($cur_field['value'])) |
|
| 663 | - $cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : ''; |
|
| 686 | + if (!isset($cur_field['value'])) { |
|
| 687 | + $cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : ''; |
|
| 688 | + } |
|
| 664 | 689 | |
| 665 | 690 | // Any input attributes? |
| 666 | 691 | $cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : ''; |
| 667 | 692 | } |
| 668 | 693 | |
| 669 | 694 | // Was there an error with this field on posting? |
| 670 | - if (isset($context['profile_errors'][$field])) |
|
| 671 | - $cur_field['is_error'] = true; |
|
| 695 | + if (isset($context['profile_errors'][$field])) { |
|
| 696 | + $cur_field['is_error'] = true; |
|
| 697 | + } |
|
| 672 | 698 | |
| 673 | 699 | // Any javascript stuff? |
| 674 | - if (!empty($cur_field['js_submit'])) |
|
| 675 | - $context['profile_onsubmit_javascript'] .= $cur_field['js_submit']; |
|
| 676 | - if (!empty($cur_field['js'])) |
|
| 677 | - $context['profile_javascript'] .= $cur_field['js']; |
|
| 700 | + if (!empty($cur_field['js_submit'])) { |
|
| 701 | + $context['profile_onsubmit_javascript'] .= $cur_field['js_submit']; |
|
| 702 | + } |
|
| 703 | + if (!empty($cur_field['js'])) { |
|
| 704 | + $context['profile_javascript'] .= $cur_field['js']; |
|
| 705 | + } |
|
| 678 | 706 | |
| 679 | 707 | // Any template stuff? |
| 680 | - if (!empty($cur_field['prehtml'])) |
|
| 681 | - $context['profile_prehtml'] .= $cur_field['prehtml']; |
|
| 682 | - if (!empty($cur_field['posthtml'])) |
|
| 683 | - $context['profile_posthtml'] .= $cur_field['posthtml']; |
|
| 708 | + if (!empty($cur_field['prehtml'])) { |
|
| 709 | + $context['profile_prehtml'] .= $cur_field['prehtml']; |
|
| 710 | + } |
|
| 711 | + if (!empty($cur_field['posthtml'])) { |
|
| 712 | + $context['profile_posthtml'] .= $cur_field['posthtml']; |
|
| 713 | + } |
|
| 684 | 714 | |
| 685 | 715 | // Finally put it into context? |
| 686 | 716 | if ($cur_field['type'] != 'hidden') |
@@ -713,12 +743,14 @@ discard block |
||
| 713 | 743 | }, false);' : ''), true); |
| 714 | 744 | |
| 715 | 745 | // Any onsubmit javascript? |
| 716 | - if (!empty($context['profile_onsubmit_javascript'])) |
|
| 717 | - addInlineJavaScript($context['profile_onsubmit_javascript'], true); |
|
| 746 | + if (!empty($context['profile_onsubmit_javascript'])) { |
|
| 747 | + addInlineJavaScript($context['profile_onsubmit_javascript'], true); |
|
| 748 | + } |
|
| 718 | 749 | |
| 719 | 750 | // Any totally custom stuff? |
| 720 | - if (!empty($context['profile_javascript'])) |
|
| 721 | - addInlineJavaScript($context['profile_javascript'], true); |
|
| 751 | + if (!empty($context['profile_javascript'])) { |
|
| 752 | + addInlineJavaScript($context['profile_javascript'], true); |
|
| 753 | + } |
|
| 722 | 754 | |
| 723 | 755 | // Free up some memory. |
| 724 | 756 | unset($profile_fields); |
@@ -739,8 +771,9 @@ discard block |
||
| 739 | 771 | |
| 740 | 772 | // This allows variables to call activities when they save - by default just to reload their settings |
| 741 | 773 | $context['profile_execute_on_save'] = array(); |
| 742 | - if ($context['user']['is_owner']) |
|
| 743 | - $context['profile_execute_on_save']['reload_user'] = 'profileReloadUser'; |
|
| 774 | + if ($context['user']['is_owner']) { |
|
| 775 | + $context['profile_execute_on_save']['reload_user'] = 'profileReloadUser'; |
|
| 776 | + } |
|
| 744 | 777 | |
| 745 | 778 | // Assume we log nothing. |
| 746 | 779 | $context['log_changes'] = array(); |
@@ -748,8 +781,9 @@ discard block |
||
| 748 | 781 | // Cycle through the profile fields working out what to do! |
| 749 | 782 | foreach ($profile_fields as $key => $field) |
| 750 | 783 | { |
| 751 | - if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) |
|
| 752 | - continue; |
|
| 784 | + if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) { |
|
| 785 | + continue; |
|
| 786 | + } |
|
| 753 | 787 | |
| 754 | 788 | // What gets updated? |
| 755 | 789 | $db_key = isset($field['save_key']) ? $field['save_key'] : $key; |
@@ -777,12 +811,13 @@ discard block |
||
| 777 | 811 | $field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type']; |
| 778 | 812 | |
| 779 | 813 | // Finally, clean up certain types. |
| 780 | - if ($field['cast_type'] == 'int') |
|
| 781 | - $_POST[$key] = (int) $_POST[$key]; |
|
| 782 | - elseif ($field['cast_type'] == 'float') |
|
| 783 | - $_POST[$key] = (float) $_POST[$key]; |
|
| 784 | - elseif ($field['cast_type'] == 'check') |
|
| 785 | - $_POST[$key] = !empty($_POST[$key]) ? 1 : 0; |
|
| 814 | + if ($field['cast_type'] == 'int') { |
|
| 815 | + $_POST[$key] = (int) $_POST[$key]; |
|
| 816 | + } elseif ($field['cast_type'] == 'float') { |
|
| 817 | + $_POST[$key] = (float) $_POST[$key]; |
|
| 818 | + } elseif ($field['cast_type'] == 'check') { |
|
| 819 | + $_POST[$key] = !empty($_POST[$key]) ? 1 : 0; |
|
| 820 | + } |
|
| 786 | 821 | |
| 787 | 822 | // If we got here we're doing OK. |
| 788 | 823 | if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key])) |
@@ -793,11 +828,12 @@ discard block |
||
| 793 | 828 | $cur_profile[$key] = $_POST[$key]; |
| 794 | 829 | |
| 795 | 830 | // Are we logging it? |
| 796 | - if (!empty($field['log_change']) && isset($old_profile[$key])) |
|
| 797 | - $context['log_changes'][$key] = array( |
|
| 831 | + if (!empty($field['log_change']) && isset($old_profile[$key])) { |
|
| 832 | + $context['log_changes'][$key] = array( |
|
| 798 | 833 | 'previous' => $old_profile[$key], |
| 799 | 834 | 'new' => $_POST[$key], |
| 800 | 835 | ); |
| 836 | + } |
|
| 801 | 837 | } |
| 802 | 838 | |
| 803 | 839 | // Logging group changes are a bit different... |
@@ -830,10 +866,11 @@ discard block |
||
| 830 | 866 | { |
| 831 | 867 | foreach ($groups as $id => $group) |
| 832 | 868 | { |
| 833 | - if (isset($context['member_groups'][$group])) |
|
| 834 | - $additional_groups[$type][$id] = $context['member_groups'][$group]['name']; |
|
| 835 | - else |
|
| 836 | - unset($additional_groups[$type][$id]); |
|
| 869 | + if (isset($context['member_groups'][$group])) { |
|
| 870 | + $additional_groups[$type][$id] = $context['member_groups'][$group]['name']; |
|
| 871 | + } else { |
|
| 872 | + unset($additional_groups[$type][$id]); |
|
| 873 | + } |
|
| 837 | 874 | } |
| 838 | 875 | $additional_groups[$type] = implode(', ', $additional_groups[$type]); |
| 839 | 876 | } |
@@ -844,10 +881,11 @@ discard block |
||
| 844 | 881 | } |
| 845 | 882 | |
| 846 | 883 | // @todo Temporary |
| 847 | - if ($context['user']['is_owner']) |
|
| 848 | - $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own')); |
|
| 849 | - else |
|
| 850 | - $changeOther = allowedTo('profile_extra_any'); |
|
| 884 | + if ($context['user']['is_owner']) { |
|
| 885 | + $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own')); |
|
| 886 | + } else { |
|
| 887 | + $changeOther = allowedTo('profile_extra_any'); |
|
| 888 | + } |
|
| 851 | 889 | if ($changeOther && empty($post_errors)) |
| 852 | 890 | { |
| 853 | 891 | makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']); |
@@ -855,8 +893,9 @@ discard block |
||
| 855 | 893 | { |
| 856 | 894 | $custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true); |
| 857 | 895 | |
| 858 | - if (!empty($custom_fields_errors)) |
|
| 859 | - $post_errors = array_merge($post_errors, $custom_fields_errors); |
|
| 896 | + if (!empty($custom_fields_errors)) { |
|
| 897 | + $post_errors = array_merge($post_errors, $custom_fields_errors); |
|
| 898 | + } |
|
| 860 | 899 | } |
| 861 | 900 | } |
| 862 | 901 | |
@@ -882,9 +921,9 @@ discard block |
||
| 882 | 921 | if ($context['user']['is_owner']) |
| 883 | 922 | { |
| 884 | 923 | $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own')); |
| 924 | + } else { |
|
| 925 | + $changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any')); |
|
| 885 | 926 | } |
| 886 | - else |
|
| 887 | - $changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any')); |
|
| 888 | 927 | |
| 889 | 928 | // Arrays of all the changes - makes things easier. |
| 890 | 929 | $profile_bools = array(); |
@@ -895,22 +934,25 @@ discard block |
||
| 895 | 934 | 'ignore_boards', |
| 896 | 935 | ); |
| 897 | 936 | |
| 898 | - if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) |
|
| 899 | - $_POST['ignore_brd'] = array(); |
|
| 937 | + if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) { |
|
| 938 | + $_POST['ignore_brd'] = array(); |
|
| 939 | + } |
|
| 900 | 940 | |
| 901 | 941 | unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing. Kinda like our minds. |
| 902 | 942 | if (isset($_POST['ignore_brd'])) |
| 903 | 943 | { |
| 904 | - if (!is_array($_POST['ignore_brd'])) |
|
| 905 | - $_POST['ignore_brd'] = array($_POST['ignore_brd']); |
|
| 944 | + if (!is_array($_POST['ignore_brd'])) { |
|
| 945 | + $_POST['ignore_brd'] = array($_POST['ignore_brd']); |
|
| 946 | + } |
|
| 906 | 947 | |
| 907 | 948 | foreach ($_POST['ignore_brd'] as $k => $d) |
| 908 | 949 | { |
| 909 | 950 | $d = (int) $d; |
| 910 | - if ($d != 0) |
|
| 911 | - $_POST['ignore_brd'][$k] = $d; |
|
| 912 | - else |
|
| 913 | - unset($_POST['ignore_brd'][$k]); |
|
| 951 | + if ($d != 0) { |
|
| 952 | + $_POST['ignore_brd'][$k] = $d; |
|
| 953 | + } else { |
|
| 954 | + unset($_POST['ignore_brd'][$k]); |
|
| 955 | + } |
|
| 914 | 956 | } |
| 915 | 957 | $_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']); |
| 916 | 958 | unset($_POST['ignore_brd']); |
@@ -923,21 +965,26 @@ discard block |
||
| 923 | 965 | makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']); |
| 924 | 966 | //makeAvatarChanges($memID, $post_errors); |
| 925 | 967 | |
| 926 | - if (!empty($_REQUEST['sa'])) |
|
| 927 | - makeCustomFieldChanges($memID, $_REQUEST['sa'], false); |
|
| 968 | + if (!empty($_REQUEST['sa'])) { |
|
| 969 | + makeCustomFieldChanges($memID, $_REQUEST['sa'], false); |
|
| 970 | + } |
|
| 928 | 971 | |
| 929 | - foreach ($profile_bools as $var) |
|
| 930 | - if (isset($_POST[$var])) |
|
| 972 | + foreach ($profile_bools as $var) { |
|
| 973 | + if (isset($_POST[$var])) |
|
| 931 | 974 | $profile_vars[$var] = empty($_POST[$var]) ? '0' : '1'; |
| 932 | - foreach ($profile_ints as $var) |
|
| 933 | - if (isset($_POST[$var])) |
|
| 975 | + } |
|
| 976 | + foreach ($profile_ints as $var) { |
|
| 977 | + if (isset($_POST[$var])) |
|
| 934 | 978 | $profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : ''; |
| 935 | - foreach ($profile_floats as $var) |
|
| 936 | - if (isset($_POST[$var])) |
|
| 979 | + } |
|
| 980 | + foreach ($profile_floats as $var) { |
|
| 981 | + if (isset($_POST[$var])) |
|
| 937 | 982 | $profile_vars[$var] = (float) $_POST[$var]; |
| 938 | - foreach ($profile_strings as $var) |
|
| 939 | - if (isset($_POST[$var])) |
|
| 983 | + } |
|
| 984 | + foreach ($profile_strings as $var) { |
|
| 985 | + if (isset($_POST[$var])) |
|
| 940 | 986 | $profile_vars[$var] = $_POST[$var]; |
| 987 | + } |
|
| 941 | 988 | } |
| 942 | 989 | } |
| 943 | 990 | |
@@ -971,8 +1018,9 @@ discard block |
||
| 971 | 1018 | ); |
| 972 | 1019 | |
| 973 | 1020 | // Can't change reserved vars. |
| 974 | - if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) |
|
| 975 | - fatal_lang_error('no_access', false); |
|
| 1021 | + if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) { |
|
| 1022 | + fatal_lang_error('no_access', false); |
|
| 1023 | + } |
|
| 976 | 1024 | |
| 977 | 1025 | // Don't allow any overriding of custom fields with default or non-default options. |
| 978 | 1026 | $request = $smcFunc['db_query']('', ' |
@@ -984,8 +1032,9 @@ discard block |
||
| 984 | 1032 | ) |
| 985 | 1033 | ); |
| 986 | 1034 | $custom_fields = array(); |
| 987 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 988 | - $custom_fields[] = $row['col_name']; |
|
| 1035 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1036 | + $custom_fields[] = $row['col_name']; |
|
| 1037 | + } |
|
| 989 | 1038 | $smcFunc['db_free_result']($request); |
| 990 | 1039 | |
| 991 | 1040 | // These are the theme changes... |
@@ -994,33 +1043,39 @@ discard block |
||
| 994 | 1043 | { |
| 995 | 1044 | foreach ($_POST['options'] as $opt => $val) |
| 996 | 1045 | { |
| 997 | - if (in_array($opt, $custom_fields)) |
|
| 998 | - continue; |
|
| 1046 | + if (in_array($opt, $custom_fields)) { |
|
| 1047 | + continue; |
|
| 1048 | + } |
|
| 999 | 1049 | |
| 1000 | 1050 | // These need to be controlled. |
| 1001 | - if ($opt == 'topics_per_page' || $opt == 'messages_per_page') |
|
| 1002 | - $val = max(0, min($val, 50)); |
|
| 1051 | + if ($opt == 'topics_per_page' || $opt == 'messages_per_page') { |
|
| 1052 | + $val = max(0, min($val, 50)); |
|
| 1053 | + } |
|
| 1003 | 1054 | // We don't set this per theme anymore. |
| 1004 | - elseif ($opt == 'allow_no_censored') |
|
| 1005 | - continue; |
|
| 1055 | + elseif ($opt == 'allow_no_censored') { |
|
| 1056 | + continue; |
|
| 1057 | + } |
|
| 1006 | 1058 | |
| 1007 | 1059 | $themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val); |
| 1008 | 1060 | } |
| 1009 | 1061 | } |
| 1010 | 1062 | |
| 1011 | 1063 | $erase_options = array(); |
| 1012 | - if (isset($_POST['default_options']) && is_array($_POST['default_options'])) |
|
| 1013 | - foreach ($_POST['default_options'] as $opt => $val) |
|
| 1064 | + if (isset($_POST['default_options']) && is_array($_POST['default_options'])) { |
|
| 1065 | + foreach ($_POST['default_options'] as $opt => $val) |
|
| 1014 | 1066 | { |
| 1015 | 1067 | if (in_array($opt, $custom_fields)) |
| 1016 | 1068 | continue; |
| 1069 | + } |
|
| 1017 | 1070 | |
| 1018 | 1071 | // These need to be controlled. |
| 1019 | - if ($opt == 'topics_per_page' || $opt == 'messages_per_page') |
|
| 1020 | - $val = max(0, min($val, 50)); |
|
| 1072 | + if ($opt == 'topics_per_page' || $opt == 'messages_per_page') { |
|
| 1073 | + $val = max(0, min($val, 50)); |
|
| 1074 | + } |
|
| 1021 | 1075 | // Only let admins and owners change the censor. |
| 1022 | - elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) |
|
| 1023 | - continue; |
|
| 1076 | + elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) { |
|
| 1077 | + continue; |
|
| 1078 | + } |
|
| 1024 | 1079 | |
| 1025 | 1080 | $themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val); |
| 1026 | 1081 | $erase_options[] = $opt; |
@@ -1056,8 +1111,9 @@ discard block |
||
| 1056 | 1111 | |
| 1057 | 1112 | // Admins can choose any theme, even if it's not enabled... |
| 1058 | 1113 | $themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']); |
| 1059 | - foreach ($themes as $t) |
|
| 1060 | - cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60); |
|
| 1114 | + foreach ($themes as $t) { |
|
| 1115 | + cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60); |
|
| 1116 | + } |
|
| 1061 | 1117 | } |
| 1062 | 1118 | } |
| 1063 | 1119 | |
@@ -1076,8 +1132,9 @@ discard block |
||
| 1076 | 1132 | if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards'])) |
| 1077 | 1133 | { |
| 1078 | 1134 | // Make sure only integers are deleted. |
| 1079 | - foreach ($_POST['notify_boards'] as $index => $id) |
|
| 1080 | - $_POST['notify_boards'][$index] = (int) $id; |
|
| 1135 | + foreach ($_POST['notify_boards'] as $index => $id) { |
|
| 1136 | + $_POST['notify_boards'][$index] = (int) $id; |
|
| 1137 | + } |
|
| 1081 | 1138 | |
| 1082 | 1139 | // id_board = 0 is reserved for topic notifications. |
| 1083 | 1140 | $_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0)); |
@@ -1096,8 +1153,9 @@ discard block |
||
| 1096 | 1153 | // We are editing topic notifications...... |
| 1097 | 1154 | elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics'])) |
| 1098 | 1155 | { |
| 1099 | - foreach ($_POST['notify_topics'] as $index => $id) |
|
| 1100 | - $_POST['notify_topics'][$index] = (int) $id; |
|
| 1156 | + foreach ($_POST['notify_topics'] as $index => $id) { |
|
| 1157 | + $_POST['notify_topics'][$index] = (int) $id; |
|
| 1158 | + } |
|
| 1101 | 1159 | |
| 1102 | 1160 | // Make sure there are no zeros left. |
| 1103 | 1161 | $_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0)); |
@@ -1111,16 +1169,18 @@ discard block |
||
| 1111 | 1169 | 'selected_member' => $memID, |
| 1112 | 1170 | ) |
| 1113 | 1171 | ); |
| 1114 | - foreach ($_POST['notify_topics'] as $topic) |
|
| 1115 | - setNotifyPrefs($memID, array('topic_notify_' . $topic => 0)); |
|
| 1172 | + foreach ($_POST['notify_topics'] as $topic) { |
|
| 1173 | + setNotifyPrefs($memID, array('topic_notify_' . $topic => 0)); |
|
| 1174 | + } |
|
| 1116 | 1175 | } |
| 1117 | 1176 | |
| 1118 | 1177 | // We are removing topic preferences |
| 1119 | 1178 | elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics'])) |
| 1120 | 1179 | { |
| 1121 | 1180 | $prefs = array(); |
| 1122 | - foreach ($_POST['notify_topics'] as $topic) |
|
| 1123 | - $prefs[] = 'topic_notify_' . $topic; |
|
| 1181 | + foreach ($_POST['notify_topics'] as $topic) { |
|
| 1182 | + $prefs[] = 'topic_notify_' . $topic; |
|
| 1183 | + } |
|
| 1124 | 1184 | deleteNotifyPrefs($memID, $prefs); |
| 1125 | 1185 | } |
| 1126 | 1186 | |
@@ -1128,8 +1188,9 @@ discard block |
||
| 1128 | 1188 | elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards'])) |
| 1129 | 1189 | { |
| 1130 | 1190 | $prefs = array(); |
| 1131 | - foreach ($_POST['notify_boards'] as $board) |
|
| 1132 | - $prefs[] = 'board_notify_' . $board; |
|
| 1191 | + foreach ($_POST['notify_boards'] as $board) { |
|
| 1192 | + $prefs[] = 'board_notify_' . $board; |
|
| 1193 | + } |
|
| 1133 | 1194 | deleteNotifyPrefs($memID, $prefs); |
| 1134 | 1195 | } |
| 1135 | 1196 | } |
@@ -1150,8 +1211,9 @@ discard block |
||
| 1150 | 1211 | |
| 1151 | 1212 | $errors = array(); |
| 1152 | 1213 | |
| 1153 | - if ($sanitize && isset($_POST['customfield'])) |
|
| 1154 | - $_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']); |
|
| 1214 | + if ($sanitize && isset($_POST['customfield'])) { |
|
| 1215 | + $_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']); |
|
| 1216 | + } |
|
| 1155 | 1217 | |
| 1156 | 1218 | $where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}'; |
| 1157 | 1219 | |
@@ -1176,48 +1238,49 @@ discard block |
||
| 1176 | 1238 | - The data is not invisible to users but editable by the owner (or if it is the user is not the owner) |
| 1177 | 1239 | - The area isn't registration, and if it is that the field is not supposed to be shown there. |
| 1178 | 1240 | */ |
| 1179 | - if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) |
|
| 1180 | - continue; |
|
| 1241 | + if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) { |
|
| 1242 | + continue; |
|
| 1243 | + } |
|
| 1181 | 1244 | |
| 1182 | 1245 | // Validate the user data. |
| 1183 | - if ($row['field_type'] == 'check') |
|
| 1184 | - $value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0; |
|
| 1185 | - elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio') |
|
| 1246 | + if ($row['field_type'] == 'check') { |
|
| 1247 | + $value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0; |
|
| 1248 | + } elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio') |
|
| 1186 | 1249 | { |
| 1187 | 1250 | $value = $row['default_value']; |
| 1188 | - foreach (explode(',', $row['field_options']) as $k => $v) |
|
| 1189 | - if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k) |
|
| 1251 | + foreach (explode(',', $row['field_options']) as $k => $v) { |
|
| 1252 | + if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k) |
|
| 1190 | 1253 | $value = $v; |
| 1254 | + } |
|
| 1191 | 1255 | } |
| 1192 | 1256 | // Otherwise some form of text! |
| 1193 | 1257 | else |
| 1194 | 1258 | { |
| 1195 | 1259 | $value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : ''; |
| 1196 | - if ($row['field_length']) |
|
| 1197 | - $value = $smcFunc['substr']($value, 0, $row['field_length']); |
|
| 1260 | + if ($row['field_length']) { |
|
| 1261 | + $value = $smcFunc['substr']($value, 0, $row['field_length']); |
|
| 1262 | + } |
|
| 1198 | 1263 | |
| 1199 | 1264 | // Any masks? |
| 1200 | 1265 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
| 1201 | 1266 | { |
| 1202 | 1267 | if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
| 1203 | 1268 | { |
| 1204 | - if ($returnErrors) |
|
| 1205 | - $errors[] = 'custom_field_mail_fail'; |
|
| 1206 | - |
|
| 1207 | - else |
|
| 1208 | - $value = ''; |
|
| 1209 | - } |
|
| 1210 | - elseif ($row['mask'] == 'number') |
|
| 1269 | + if ($returnErrors) { |
|
| 1270 | + $errors[] = 'custom_field_mail_fail'; |
|
| 1271 | + } else { |
|
| 1272 | + $value = ''; |
|
| 1273 | + } |
|
| 1274 | + } elseif ($row['mask'] == 'number') |
|
| 1211 | 1275 | { |
| 1212 | 1276 | $value = (int) $value; |
| 1213 | - } |
|
| 1214 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
| 1277 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
| 1215 | 1278 | { |
| 1216 | - if ($returnErrors) |
|
| 1217 | - $errors[] = 'custom_field_regex_fail'; |
|
| 1218 | - |
|
| 1219 | - else |
|
| 1220 | - $value = ''; |
|
| 1279 | + if ($returnErrors) { |
|
| 1280 | + $errors[] = 'custom_field_regex_fail'; |
|
| 1281 | + } else { |
|
| 1282 | + $value = ''; |
|
| 1283 | + } |
|
| 1221 | 1284 | } |
| 1222 | 1285 | } |
| 1223 | 1286 | } |
@@ -1243,8 +1306,9 @@ discard block |
||
| 1243 | 1306 | |
| 1244 | 1307 | $hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize)); |
| 1245 | 1308 | |
| 1246 | - if (!empty($hook_errors) && is_array($hook_errors)) |
|
| 1247 | - $errors = array_merge($errors, $hook_errors); |
|
| 1309 | + if (!empty($hook_errors) && is_array($hook_errors)) { |
|
| 1310 | + $errors = array_merge($errors, $hook_errors); |
|
| 1311 | + } |
|
| 1248 | 1312 | |
| 1249 | 1313 | // Make those changes! |
| 1250 | 1314 | if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors)) |
@@ -1262,9 +1326,10 @@ discard block |
||
| 1262 | 1326 | } |
| 1263 | 1327 | } |
| 1264 | 1328 | |
| 1265 | - if ($returnErrors) |
|
| 1266 | - return $errors; |
|
| 1267 | -} |
|
| 1329 | + if ($returnErrors) { |
|
| 1330 | + return $errors; |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1268 | 1333 | |
| 1269 | 1334 | /** |
| 1270 | 1335 | * Show all the users buddies, as well as a add/delete interface. |
@@ -1276,8 +1341,9 @@ discard block |
||
| 1276 | 1341 | global $context, $txt, $modSettings; |
| 1277 | 1342 | |
| 1278 | 1343 | // Do a quick check to ensure people aren't getting here illegally! |
| 1279 | - if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) |
|
| 1280 | - fatal_lang_error('no_access', false); |
|
| 1344 | + if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) { |
|
| 1345 | + fatal_lang_error('no_access', false); |
|
| 1346 | + } |
|
| 1281 | 1347 | |
| 1282 | 1348 | // Can we email the user direct? |
| 1283 | 1349 | $context['can_moderate_forum'] = allowedTo('moderate_forum'); |
@@ -1307,9 +1373,10 @@ discard block |
||
| 1307 | 1373 | $context['sub_template'] = $subActions[$context['list_area']][0]; |
| 1308 | 1374 | $call = call_helper($subActions[$context['list_area']][0], true); |
| 1309 | 1375 | |
| 1310 | - if (!empty($call)) |
|
| 1311 | - call_user_func($call, $memID); |
|
| 1312 | -} |
|
| 1376 | + if (!empty($call)) { |
|
| 1377 | + call_user_func($call, $memID); |
|
| 1378 | + } |
|
| 1379 | + } |
|
| 1313 | 1380 | |
| 1314 | 1381 | /** |
| 1315 | 1382 | * Show all the users buddies, as well as a add/delete interface. |
@@ -1323,9 +1390,10 @@ discard block |
||
| 1323 | 1390 | |
| 1324 | 1391 | // For making changes! |
| 1325 | 1392 | $buddiesArray = explode(',', $user_profile[$memID]['buddy_list']); |
| 1326 | - foreach ($buddiesArray as $k => $dummy) |
|
| 1327 | - if ($dummy == '') |
|
| 1393 | + foreach ($buddiesArray as $k => $dummy) { |
|
| 1394 | + if ($dummy == '') |
|
| 1328 | 1395 | unset($buddiesArray[$k]); |
| 1396 | + } |
|
| 1329 | 1397 | |
| 1330 | 1398 | // Removing a buddy? |
| 1331 | 1399 | if (isset($_GET['remove'])) |
@@ -1337,10 +1405,11 @@ discard block |
||
| 1337 | 1405 | $_SESSION['prf-save'] = $txt['could_not_remove_person']; |
| 1338 | 1406 | |
| 1339 | 1407 | // Heh, I'm lazy, do it the easy way... |
| 1340 | - foreach ($buddiesArray as $key => $buddy) |
|
| 1341 | - if ($buddy == (int) $_GET['remove']) |
|
| 1408 | + foreach ($buddiesArray as $key => $buddy) { |
|
| 1409 | + if ($buddy == (int) $_GET['remove']) |
|
| 1342 | 1410 | { |
| 1343 | 1411 | unset($buddiesArray[$key]); |
| 1412 | + } |
|
| 1344 | 1413 | $_SESSION['prf-save'] = true; |
| 1345 | 1414 | } |
| 1346 | 1415 | |
@@ -1350,8 +1419,7 @@ discard block |
||
| 1350 | 1419 | |
| 1351 | 1420 | // Redirect off the page because we don't like all this ugly query stuff to stick in the history. |
| 1352 | 1421 | redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID); |
| 1353 | - } |
|
| 1354 | - elseif (isset($_POST['new_buddy'])) |
|
| 1422 | + } elseif (isset($_POST['new_buddy'])) |
|
| 1355 | 1423 | { |
| 1356 | 1424 | checkSession(); |
| 1357 | 1425 | |
@@ -1364,8 +1432,9 @@ discard block |
||
| 1364 | 1432 | { |
| 1365 | 1433 | $new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => ''')); |
| 1366 | 1434 | |
| 1367 | - if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) |
|
| 1368 | - unset($new_buddies[$k]); |
|
| 1435 | + if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) { |
|
| 1436 | + unset($new_buddies[$k]); |
|
| 1437 | + } |
|
| 1369 | 1438 | } |
| 1370 | 1439 | |
| 1371 | 1440 | call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies)); |
@@ -1385,16 +1454,18 @@ discard block |
||
| 1385 | 1454 | ) |
| 1386 | 1455 | ); |
| 1387 | 1456 | |
| 1388 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1389 | - $_SESSION['prf-save'] = true; |
|
| 1457 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1458 | + $_SESSION['prf-save'] = true; |
|
| 1459 | + } |
|
| 1390 | 1460 | |
| 1391 | 1461 | // Add the new member to the buddies array. |
| 1392 | 1462 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1393 | 1463 | { |
| 1394 | - if (in_array($row['id_member'], $buddiesArray)) |
|
| 1395 | - continue; |
|
| 1396 | - else |
|
| 1397 | - $buddiesArray[] = (int) $row['id_member']; |
|
| 1464 | + if (in_array($row['id_member'], $buddiesArray)) { |
|
| 1465 | + continue; |
|
| 1466 | + } else { |
|
| 1467 | + $buddiesArray[] = (int) $row['id_member']; |
|
| 1468 | + } |
|
| 1398 | 1469 | } |
| 1399 | 1470 | $smcFunc['db_free_result']($request); |
| 1400 | 1471 | |
@@ -1424,18 +1495,20 @@ discard block |
||
| 1424 | 1495 | |
| 1425 | 1496 | $context['custom_pf'] = array(); |
| 1426 | 1497 | $disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
| 1427 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1428 | - if (!isset($disabled_fields[$row['col_name']])) |
|
| 1498 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1499 | + if (!isset($disabled_fields[$row['col_name']])) |
|
| 1429 | 1500 | $context['custom_pf'][$row['col_name']] = array( |
| 1430 | 1501 | 'label' => $row['field_name'], |
| 1431 | 1502 | 'type' => $row['field_type'], |
| 1432 | 1503 | 'bbc' => !empty($row['bbc']), |
| 1433 | 1504 | 'enclose' => $row['enclose'], |
| 1434 | 1505 | ); |
| 1506 | + } |
|
| 1435 | 1507 | |
| 1436 | 1508 | // Gotta disable the gender option. |
| 1437 | - if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') |
|
| 1438 | - unset($context['custom_pf']['cust_gender']); |
|
| 1509 | + if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') { |
|
| 1510 | + unset($context['custom_pf']['cust_gender']); |
|
| 1511 | + } |
|
| 1439 | 1512 | |
| 1440 | 1513 | $smcFunc['db_free_result']($request); |
| 1441 | 1514 | |
@@ -1452,8 +1525,9 @@ discard block |
||
| 1452 | 1525 | 'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1, |
| 1453 | 1526 | ) |
| 1454 | 1527 | ); |
| 1455 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1456 | - $buddies[] = $row['id_member']; |
|
| 1528 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1529 | + $buddies[] = $row['id_member']; |
|
| 1530 | + } |
|
| 1457 | 1531 | $smcFunc['db_free_result']($result); |
| 1458 | 1532 | } |
| 1459 | 1533 | |
@@ -1481,30 +1555,32 @@ discard block |
||
| 1481 | 1555 | continue; |
| 1482 | 1556 | } |
| 1483 | 1557 | |
| 1484 | - if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) |
|
| 1485 | - $context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key])); |
|
| 1486 | - |
|
| 1487 | - elseif ($column['type'] == 'check') |
|
| 1488 | - $context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 1558 | + if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) { |
|
| 1559 | + $context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key])); |
|
| 1560 | + } elseif ($column['type'] == 'check') { |
|
| 1561 | + $context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 1562 | + } |
|
| 1489 | 1563 | |
| 1490 | 1564 | // Enclosing the user input within some other text? |
| 1491 | - if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) |
|
| 1492 | - $context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array( |
|
| 1565 | + if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) { |
|
| 1566 | + $context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array( |
|
| 1493 | 1567 | '{SCRIPTURL}' => $scripturl, |
| 1494 | 1568 | '{IMAGES_URL}' => $settings['images_url'], |
| 1495 | 1569 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1496 | 1570 | '{INPUT}' => $context['buddies'][$buddy]['options'][$key], |
| 1497 | 1571 | )); |
| 1572 | + } |
|
| 1498 | 1573 | } |
| 1499 | 1574 | } |
| 1500 | 1575 | } |
| 1501 | 1576 | |
| 1502 | 1577 | if (isset($_SESSION['prf-save'])) |
| 1503 | 1578 | { |
| 1504 | - if ($_SESSION['prf-save'] === true) |
|
| 1505 | - $context['saved_successful'] = true; |
|
| 1506 | - else |
|
| 1507 | - $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1579 | + if ($_SESSION['prf-save'] === true) { |
|
| 1580 | + $context['saved_successful'] = true; |
|
| 1581 | + } else { |
|
| 1582 | + $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1583 | + } |
|
| 1508 | 1584 | |
| 1509 | 1585 | unset($_SESSION['prf-save']); |
| 1510 | 1586 | } |
@@ -1524,9 +1600,10 @@ discard block |
||
| 1524 | 1600 | |
| 1525 | 1601 | // For making changes! |
| 1526 | 1602 | $ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']); |
| 1527 | - foreach ($ignoreArray as $k => $dummy) |
|
| 1528 | - if ($dummy == '') |
|
| 1603 | + foreach ($ignoreArray as $k => $dummy) { |
|
| 1604 | + if ($dummy == '') |
|
| 1529 | 1605 | unset($ignoreArray[$k]); |
| 1606 | + } |
|
| 1530 | 1607 | |
| 1531 | 1608 | // Removing a member from the ignore list? |
| 1532 | 1609 | if (isset($_GET['remove'])) |
@@ -1536,10 +1613,11 @@ discard block |
||
| 1536 | 1613 | $_SESSION['prf-save'] = $txt['could_not_remove_person']; |
| 1537 | 1614 | |
| 1538 | 1615 | // Heh, I'm lazy, do it the easy way... |
| 1539 | - foreach ($ignoreArray as $key => $id_remove) |
|
| 1540 | - if ($id_remove == (int) $_GET['remove']) |
|
| 1616 | + foreach ($ignoreArray as $key => $id_remove) { |
|
| 1617 | + if ($id_remove == (int) $_GET['remove']) |
|
| 1541 | 1618 | { |
| 1542 | 1619 | unset($ignoreArray[$key]); |
| 1620 | + } |
|
| 1543 | 1621 | $_SESSION['prf-save'] = true; |
| 1544 | 1622 | } |
| 1545 | 1623 | |
@@ -1549,8 +1627,7 @@ discard block |
||
| 1549 | 1627 | |
| 1550 | 1628 | // Redirect off the page because we don't like all this ugly query stuff to stick in the history. |
| 1551 | 1629 | redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID); |
| 1552 | - } |
|
| 1553 | - elseif (isset($_POST['new_ignore'])) |
|
| 1630 | + } elseif (isset($_POST['new_ignore'])) |
|
| 1554 | 1631 | { |
| 1555 | 1632 | checkSession(); |
| 1556 | 1633 | // Prepare the string for extraction... |
@@ -1562,8 +1639,9 @@ discard block |
||
| 1562 | 1639 | { |
| 1563 | 1640 | $new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => ''')); |
| 1564 | 1641 | |
| 1565 | - if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) |
|
| 1566 | - unset($new_entries[$k]); |
|
| 1642 | + if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) { |
|
| 1643 | + unset($new_entries[$k]); |
|
| 1644 | + } |
|
| 1567 | 1645 | } |
| 1568 | 1646 | |
| 1569 | 1647 | $_SESSION['prf-save'] = $txt['could_not_add_person']; |
@@ -1581,16 +1659,18 @@ discard block |
||
| 1581 | 1659 | ) |
| 1582 | 1660 | ); |
| 1583 | 1661 | |
| 1584 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1585 | - $_SESSION['prf-save'] = true; |
|
| 1662 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1663 | + $_SESSION['prf-save'] = true; |
|
| 1664 | + } |
|
| 1586 | 1665 | |
| 1587 | 1666 | // Add the new member to the buddies array. |
| 1588 | 1667 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1589 | 1668 | { |
| 1590 | - if (in_array($row['id_member'], $ignoreArray)) |
|
| 1591 | - continue; |
|
| 1592 | - else |
|
| 1593 | - $ignoreArray[] = (int) $row['id_member']; |
|
| 1669 | + if (in_array($row['id_member'], $ignoreArray)) { |
|
| 1670 | + continue; |
|
| 1671 | + } else { |
|
| 1672 | + $ignoreArray[] = (int) $row['id_member']; |
|
| 1673 | + } |
|
| 1594 | 1674 | } |
| 1595 | 1675 | $smcFunc['db_free_result']($request); |
| 1596 | 1676 | |
@@ -1619,8 +1699,9 @@ discard block |
||
| 1619 | 1699 | 'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1, |
| 1620 | 1700 | ) |
| 1621 | 1701 | ); |
| 1622 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1623 | - $ignored[] = $row['id_member']; |
|
| 1702 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1703 | + $ignored[] = $row['id_member']; |
|
| 1704 | + } |
|
| 1624 | 1705 | $smcFunc['db_free_result']($result); |
| 1625 | 1706 | } |
| 1626 | 1707 | |
@@ -1639,10 +1720,11 @@ discard block |
||
| 1639 | 1720 | |
| 1640 | 1721 | if (isset($_SESSION['prf-save'])) |
| 1641 | 1722 | { |
| 1642 | - if ($_SESSION['prf-save'] === true) |
|
| 1643 | - $context['saved_successful'] = true; |
|
| 1644 | - else |
|
| 1645 | - $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1723 | + if ($_SESSION['prf-save'] === true) { |
|
| 1724 | + $context['saved_successful'] = true; |
|
| 1725 | + } else { |
|
| 1726 | + $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1727 | + } |
|
| 1646 | 1728 | |
| 1647 | 1729 | unset($_SESSION['prf-save']); |
| 1648 | 1730 | } |
@@ -1658,8 +1740,9 @@ discard block |
||
| 1658 | 1740 | global $context, $txt; |
| 1659 | 1741 | |
| 1660 | 1742 | loadThemeOptions($memID); |
| 1661 | - if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) |
|
| 1662 | - loadCustomFields($memID, 'account'); |
|
| 1743 | + if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) { |
|
| 1744 | + loadCustomFields($memID, 'account'); |
|
| 1745 | + } |
|
| 1663 | 1746 | |
| 1664 | 1747 | $context['sub_template'] = 'edit_options'; |
| 1665 | 1748 | $context['page_desc'] = $txt['account_info']; |
@@ -1686,8 +1769,9 @@ discard block |
||
| 1686 | 1769 | global $context, $txt; |
| 1687 | 1770 | |
| 1688 | 1771 | loadThemeOptions($memID); |
| 1689 | - if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) |
|
| 1690 | - loadCustomFields($memID, 'forumprofile'); |
|
| 1772 | + if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) { |
|
| 1773 | + loadCustomFields($memID, 'forumprofile'); |
|
| 1774 | + } |
|
| 1691 | 1775 | |
| 1692 | 1776 | $context['sub_template'] = 'edit_options'; |
| 1693 | 1777 | $context['page_desc'] = $txt['forumProfile_info']; |
@@ -1720,18 +1804,21 @@ discard block |
||
| 1720 | 1804 | $dirs = array(); |
| 1721 | 1805 | $files = array(); |
| 1722 | 1806 | |
| 1723 | - if (!$dir) |
|
| 1724 | - return array(); |
|
| 1807 | + if (!$dir) { |
|
| 1808 | + return array(); |
|
| 1809 | + } |
|
| 1725 | 1810 | |
| 1726 | 1811 | while ($line = $dir->read()) |
| 1727 | 1812 | { |
| 1728 | - if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) |
|
| 1729 | - continue; |
|
| 1813 | + if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) { |
|
| 1814 | + continue; |
|
| 1815 | + } |
|
| 1730 | 1816 | |
| 1731 | - if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) |
|
| 1732 | - $dirs[] = $line; |
|
| 1733 | - else |
|
| 1734 | - $files[] = $line; |
|
| 1817 | + if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) { |
|
| 1818 | + $dirs[] = $line; |
|
| 1819 | + } else { |
|
| 1820 | + $files[] = $line; |
|
| 1821 | + } |
|
| 1735 | 1822 | } |
| 1736 | 1823 | $dir->close(); |
| 1737 | 1824 | |
@@ -1752,14 +1839,15 @@ discard block |
||
| 1752 | 1839 | foreach ($dirs as $line) |
| 1753 | 1840 | { |
| 1754 | 1841 | $tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1); |
| 1755 | - if (!empty($tmp)) |
|
| 1756 | - $result[] = array( |
|
| 1842 | + if (!empty($tmp)) { |
|
| 1843 | + $result[] = array( |
|
| 1757 | 1844 | 'filename' => $smcFunc['htmlspecialchars']($line), |
| 1758 | 1845 | 'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false, |
| 1759 | 1846 | 'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']', |
| 1760 | 1847 | 'is_dir' => true, |
| 1761 | 1848 | 'files' => $tmp |
| 1762 | 1849 | ); |
| 1850 | + } |
|
| 1763 | 1851 | unset($tmp); |
| 1764 | 1852 | } |
| 1765 | 1853 | |
@@ -1769,8 +1857,9 @@ discard block |
||
| 1769 | 1857 | $extension = substr(strrchr($line, '.'), 1); |
| 1770 | 1858 | |
| 1771 | 1859 | // Make sure it is an image. |
| 1772 | - if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) |
|
| 1773 | - continue; |
|
| 1860 | + if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) { |
|
| 1861 | + continue; |
|
| 1862 | + } |
|
| 1774 | 1863 | |
| 1775 | 1864 | $result[] = array( |
| 1776 | 1865 | 'filename' => $smcFunc['htmlspecialchars']($line), |
@@ -1778,8 +1867,9 @@ discard block |
||
| 1778 | 1867 | 'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)), |
| 1779 | 1868 | 'is_dir' => false |
| 1780 | 1869 | ); |
| 1781 | - if ($level == 1) |
|
| 1782 | - $context['avatar_list'][] = $directory . '/' . $line; |
|
| 1870 | + if ($level == 1) { |
|
| 1871 | + $context['avatar_list'][] = $directory . '/' . $line; |
|
| 1872 | + } |
|
| 1783 | 1873 | } |
| 1784 | 1874 | |
| 1785 | 1875 | return $result; |
@@ -1798,8 +1888,9 @@ discard block |
||
| 1798 | 1888 | loadSubTemplate('options'); |
| 1799 | 1889 | |
| 1800 | 1890 | loadThemeOptions($memID); |
| 1801 | - if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) |
|
| 1802 | - loadCustomFields($memID, 'theme'); |
|
| 1891 | + if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) { |
|
| 1892 | + loadCustomFields($memID, 'theme'); |
|
| 1893 | + } |
|
| 1803 | 1894 | |
| 1804 | 1895 | $context['sub_template'] = 'edit_options'; |
| 1805 | 1896 | $context['page_desc'] = $txt['theme_info']; |
@@ -1853,16 +1944,19 @@ discard block |
||
| 1853 | 1944 | { |
| 1854 | 1945 | global $txt, $context, $modSettings, $smcFunc, $sourcedir; |
| 1855 | 1946 | |
| 1856 | - if (!isset($context['token_check'])) |
|
| 1857 | - $context['token_check'] = 'profile-nt' . $memID; |
|
| 1947 | + if (!isset($context['token_check'])) { |
|
| 1948 | + $context['token_check'] = 'profile-nt' . $memID; |
|
| 1949 | + } |
|
| 1858 | 1950 | |
| 1859 | 1951 | is_not_guest(); |
| 1860 | - if (!$context['user']['is_owner']) |
|
| 1861 | - isAllowedTo('profile_extra_any'); |
|
| 1952 | + if (!$context['user']['is_owner']) { |
|
| 1953 | + isAllowedTo('profile_extra_any'); |
|
| 1954 | + } |
|
| 1862 | 1955 | |
| 1863 | 1956 | // Set the post action if we're coming from the profile... |
| 1864 | - if (!isset($context['action'])) |
|
| 1865 | - $context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID; |
|
| 1957 | + if (!isset($context['action'])) { |
|
| 1958 | + $context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID; |
|
| 1959 | + } |
|
| 1866 | 1960 | |
| 1867 | 1961 | // What options are set |
| 1868 | 1962 | loadThemeOptions($memID); |
@@ -1949,28 +2043,34 @@ discard block |
||
| 1949 | 2043 | ); |
| 1950 | 2044 | |
| 1951 | 2045 | // There are certain things that are disabled at the group level. |
| 1952 | - if (empty($modSettings['cal_enabled'])) |
|
| 1953 | - unset($alert_types['calendar']); |
|
| 2046 | + if (empty($modSettings['cal_enabled'])) { |
|
| 2047 | + unset($alert_types['calendar']); |
|
| 2048 | + } |
|
| 1954 | 2049 | |
| 1955 | 2050 | // Disable paid subscriptions at group level if they're disabled |
| 1956 | - if (empty($modSettings['paid_enabled'])) |
|
| 1957 | - unset($alert_types['paidsubs']); |
|
| 2051 | + if (empty($modSettings['paid_enabled'])) { |
|
| 2052 | + unset($alert_types['paidsubs']); |
|
| 2053 | + } |
|
| 1958 | 2054 | |
| 1959 | 2055 | // Disable membergroup requests at group level if they're disabled |
| 1960 | - if (empty($modSettings['show_group_membership'])) |
|
| 1961 | - unset($alert_types['groupr'], $alert_types['members']['request_group']); |
|
| 2056 | + if (empty($modSettings['show_group_membership'])) { |
|
| 2057 | + unset($alert_types['groupr'], $alert_types['members']['request_group']); |
|
| 2058 | + } |
|
| 1962 | 2059 | |
| 1963 | 2060 | // Disable mentions if they're disabled |
| 1964 | - if (empty($modSettings['enable_mentions'])) |
|
| 1965 | - unset($alert_types['msg']['msg_mention']); |
|
| 2061 | + if (empty($modSettings['enable_mentions'])) { |
|
| 2062 | + unset($alert_types['msg']['msg_mention']); |
|
| 2063 | + } |
|
| 1966 | 2064 | |
| 1967 | 2065 | // Disable likes if they're disabled |
| 1968 | - if (empty($modSettings['enable_likes'])) |
|
| 1969 | - unset($alert_types['msg']['msg_like']); |
|
| 2066 | + if (empty($modSettings['enable_likes'])) { |
|
| 2067 | + unset($alert_types['msg']['msg_like']); |
|
| 2068 | + } |
|
| 1970 | 2069 | |
| 1971 | 2070 | // Disable buddy requests if they're disabled |
| 1972 | - if (empty($modSettings['enable_buddylist'])) |
|
| 1973 | - unset($alert_types['members']['buddy_request']); |
|
| 2071 | + if (empty($modSettings['enable_buddylist'])) { |
|
| 2072 | + unset($alert_types['members']['buddy_request']); |
|
| 2073 | + } |
|
| 1974 | 2074 | |
| 1975 | 2075 | // Now, now, we could pass this through global but we should really get into the habit of |
| 1976 | 2076 | // passing content to hooks, not expecting hooks to splatter everything everywhere. |
@@ -1998,15 +2098,17 @@ discard block |
||
| 1998 | 2098 | $perms_cache['manage_membergroups'] = in_array($memID, $members); |
| 1999 | 2099 | } |
| 2000 | 2100 | |
| 2001 | - if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) |
|
| 2002 | - unset($alert_types['members']['request_group']); |
|
| 2101 | + if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) { |
|
| 2102 | + unset($alert_types['members']['request_group']); |
|
| 2103 | + } |
|
| 2003 | 2104 | |
| 2004 | 2105 | foreach ($alert_types as $group => $items) |
| 2005 | 2106 | { |
| 2006 | 2107 | foreach ($items as $alert_key => $alert_value) |
| 2007 | 2108 | { |
| 2008 | - if (!isset($alert_value['permission'])) |
|
| 2009 | - continue; |
|
| 2109 | + if (!isset($alert_value['permission'])) { |
|
| 2110 | + continue; |
|
| 2111 | + } |
|
| 2010 | 2112 | if (!isset($perms_cache[$alert_value['permission']['name']])) |
| 2011 | 2113 | { |
| 2012 | 2114 | $in_board = !empty($alert_value['permission']['is_board']) ? 0 : null; |
@@ -2014,12 +2116,14 @@ discard block |
||
| 2014 | 2116 | $perms_cache[$alert_value['permission']['name']] = in_array($memID, $members); |
| 2015 | 2117 | } |
| 2016 | 2118 | |
| 2017 | - if (!$perms_cache[$alert_value['permission']['name']]) |
|
| 2018 | - unset ($alert_types[$group][$alert_key]); |
|
| 2119 | + if (!$perms_cache[$alert_value['permission']['name']]) { |
|
| 2120 | + unset ($alert_types[$group][$alert_key]); |
|
| 2121 | + } |
|
| 2019 | 2122 | } |
| 2020 | 2123 | |
| 2021 | - if (empty($alert_types[$group])) |
|
| 2022 | - unset ($alert_types[$group]); |
|
| 2124 | + if (empty($alert_types[$group])) { |
|
| 2125 | + unset ($alert_types[$group]); |
|
| 2126 | + } |
|
| 2023 | 2127 | } |
| 2024 | 2128 | } |
| 2025 | 2129 | |
@@ -2051,9 +2155,9 @@ discard block |
||
| 2051 | 2155 | $update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0; |
| 2052 | 2156 | break; |
| 2053 | 2157 | case 'select': |
| 2054 | - if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) |
|
| 2055 | - $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]]; |
|
| 2056 | - else |
|
| 2158 | + if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) { |
|
| 2159 | + $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]]; |
|
| 2160 | + } else |
|
| 2057 | 2161 | { |
| 2058 | 2162 | // We didn't have a sane value. Let's grab the first item from the possibles. |
| 2059 | 2163 | $keys = array_keys($this_option['opts']); |
@@ -2073,23 +2177,28 @@ discard block |
||
| 2073 | 2177 | $this_value = 0; |
| 2074 | 2178 | foreach ($context['alert_bits'] as $type => $bitvalue) |
| 2075 | 2179 | { |
| 2076 | - if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') |
|
| 2077 | - $this_value |= $bitvalue; |
|
| 2180 | + if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') { |
|
| 2181 | + $this_value |= $bitvalue; |
|
| 2182 | + } |
|
| 2183 | + } |
|
| 2184 | + if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) { |
|
| 2185 | + $update_prefs[$item_key] = $this_value; |
|
| 2078 | 2186 | } |
| 2079 | - if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) |
|
| 2080 | - $update_prefs[$item_key] = $this_value; |
|
| 2081 | 2187 | } |
| 2082 | 2188 | } |
| 2083 | 2189 | |
| 2084 | - if (!empty($_POST['opt_alert_timeout'])) |
|
| 2085 | - $update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout']; |
|
| 2190 | + if (!empty($_POST['opt_alert_timeout'])) { |
|
| 2191 | + $update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout']; |
|
| 2192 | + } |
|
| 2086 | 2193 | |
| 2087 | - if (!empty($_POST['notify_announcements'])) |
|
| 2088 | - $update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements']; |
|
| 2194 | + if (!empty($_POST['notify_announcements'])) { |
|
| 2195 | + $update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements']; |
|
| 2196 | + } |
|
| 2089 | 2197 | |
| 2090 | 2198 | setNotifyPrefs((int) $memID, $update_prefs); |
| 2091 | - foreach ($update_prefs as $pref => $value) |
|
| 2092 | - $context['alert_prefs'][$pref] = $value; |
|
| 2199 | + foreach ($update_prefs as $pref => $value) { |
|
| 2200 | + $context['alert_prefs'][$pref] = $value; |
|
| 2201 | + } |
|
| 2093 | 2202 | |
| 2094 | 2203 | makeNotificationChanges($memID); |
| 2095 | 2204 | |
@@ -2119,8 +2228,9 @@ discard block |
||
| 2119 | 2228 | |
| 2120 | 2229 | // Now we're all set up. |
| 2121 | 2230 | is_not_guest(); |
| 2122 | - if (!$context['user']['is_owner']) |
|
| 2123 | - fatal_error('no_access'); |
|
| 2231 | + if (!$context['user']['is_owner']) { |
|
| 2232 | + fatal_error('no_access'); |
|
| 2233 | + } |
|
| 2124 | 2234 | |
| 2125 | 2235 | checkSession('get'); |
| 2126 | 2236 | |
@@ -2152,8 +2262,9 @@ discard block |
||
| 2152 | 2262 | { |
| 2153 | 2263 | global $smcFunc; |
| 2154 | 2264 | |
| 2155 | - if (empty($toMark) || empty($memID)) |
|
| 2156 | - return false; |
|
| 2265 | + if (empty($toMark) || empty($memID)) { |
|
| 2266 | + return false; |
|
| 2267 | + } |
|
| 2157 | 2268 | |
| 2158 | 2269 | $toMark = (array) $toMark; |
| 2159 | 2270 | |
@@ -2187,8 +2298,9 @@ discard block |
||
| 2187 | 2298 | { |
| 2188 | 2299 | global $smcFunc; |
| 2189 | 2300 | |
| 2190 | - if (empty($toDelete)) |
|
| 2191 | - return false; |
|
| 2301 | + if (empty($toDelete)) { |
|
| 2302 | + return false; |
|
| 2303 | + } |
|
| 2192 | 2304 | |
| 2193 | 2305 | $toDelete = (array) $toDelete; |
| 2194 | 2306 | |
@@ -2223,8 +2335,9 @@ discard block |
||
| 2223 | 2335 | { |
| 2224 | 2336 | global $smcFunc; |
| 2225 | 2337 | |
| 2226 | - if (empty($memID)) |
|
| 2227 | - return false; |
|
| 2338 | + if (empty($memID)) { |
|
| 2339 | + return false; |
|
| 2340 | + } |
|
| 2228 | 2341 | |
| 2229 | 2342 | $request = $smcFunc['db_query']('', ' |
| 2230 | 2343 | SELECT id_alert |
@@ -2301,8 +2414,9 @@ discard block |
||
| 2301 | 2414 | { |
| 2302 | 2415 | $link = $topic['link']; |
| 2303 | 2416 | |
| 2304 | - if ($topic['new']) |
|
| 2305 | - $link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2417 | + if ($topic['new']) { |
|
| 2418 | + $link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2419 | + } |
|
| 2306 | 2420 | |
| 2307 | 2421 | $link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>'; |
| 2308 | 2422 | |
@@ -2453,8 +2567,9 @@ discard block |
||
| 2453 | 2567 | { |
| 2454 | 2568 | $link = $board['link']; |
| 2455 | 2569 | |
| 2456 | - if ($board['new']) |
|
| 2457 | - $link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2570 | + if ($board['new']) { |
|
| 2571 | + $link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2572 | + } |
|
| 2458 | 2573 | |
| 2459 | 2574 | return $link; |
| 2460 | 2575 | }, |
@@ -2654,8 +2769,8 @@ discard block |
||
| 2654 | 2769 | ) |
| 2655 | 2770 | ); |
| 2656 | 2771 | $notification_boards = array(); |
| 2657 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2658 | - $notification_boards[] = array( |
|
| 2772 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2773 | + $notification_boards[] = array( |
|
| 2659 | 2774 | 'id' => $row['id_board'], |
| 2660 | 2775 | 'name' => $row['name'], |
| 2661 | 2776 | 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', |
@@ -2663,6 +2778,7 @@ discard block |
||
| 2663 | 2778 | 'new' => $row['board_read'] < $row['id_msg_updated'], |
| 2664 | 2779 | 'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0), |
| 2665 | 2780 | ); |
| 2781 | + } |
|
| 2666 | 2782 | $smcFunc['db_free_result']($request); |
| 2667 | 2783 | |
| 2668 | 2784 | return $notification_boards; |
@@ -2677,17 +2793,18 @@ discard block |
||
| 2677 | 2793 | { |
| 2678 | 2794 | global $context, $options, $cur_profile, $smcFunc; |
| 2679 | 2795 | |
| 2680 | - if (isset($_POST['default_options'])) |
|
| 2681 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 2796 | + if (isset($_POST['default_options'])) { |
|
| 2797 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 2798 | + } |
|
| 2682 | 2799 | |
| 2683 | 2800 | if ($context['user']['is_owner']) |
| 2684 | 2801 | { |
| 2685 | 2802 | $context['member']['options'] = $options; |
| 2686 | - if (isset($_POST['options']) && is_array($_POST['options'])) |
|
| 2687 | - foreach ($_POST['options'] as $k => $v) |
|
| 2803 | + if (isset($_POST['options']) && is_array($_POST['options'])) { |
|
| 2804 | + foreach ($_POST['options'] as $k => $v) |
|
| 2688 | 2805 | $context['member']['options'][$k] = $v; |
| 2689 | - } |
|
| 2690 | - else |
|
| 2806 | + } |
|
| 2807 | + } else |
|
| 2691 | 2808 | { |
| 2692 | 2809 | $request = $smcFunc['db_query']('', ' |
| 2693 | 2810 | SELECT id_member, variable, value |
@@ -2708,8 +2825,9 @@ discard block |
||
| 2708 | 2825 | continue; |
| 2709 | 2826 | } |
| 2710 | 2827 | |
| 2711 | - if (isset($_POST['options'][$row['variable']])) |
|
| 2712 | - $row['value'] = $_POST['options'][$row['variable']]; |
|
| 2828 | + if (isset($_POST['options'][$row['variable']])) { |
|
| 2829 | + $row['value'] = $_POST['options'][$row['variable']]; |
|
| 2830 | + } |
|
| 2713 | 2831 | $context['member']['options'][$row['variable']] = $row['value']; |
| 2714 | 2832 | } |
| 2715 | 2833 | $smcFunc['db_free_result']($request); |
@@ -2717,8 +2835,9 @@ discard block |
||
| 2717 | 2835 | // Load up the default theme options for any missing. |
| 2718 | 2836 | foreach ($temp as $k => $v) |
| 2719 | 2837 | { |
| 2720 | - if (!isset($context['member']['options'][$k])) |
|
| 2721 | - $context['member']['options'][$k] = $v; |
|
| 2838 | + if (!isset($context['member']['options'][$k])) { |
|
| 2839 | + $context['member']['options'][$k] = $v; |
|
| 2840 | + } |
|
| 2722 | 2841 | } |
| 2723 | 2842 | } |
| 2724 | 2843 | } |
@@ -2733,8 +2852,9 @@ discard block |
||
| 2733 | 2852 | global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir; |
| 2734 | 2853 | |
| 2735 | 2854 | // Have the admins enabled this option? |
| 2736 | - if (empty($modSettings['allow_ignore_boards'])) |
|
| 2737 | - fatal_lang_error('ignoreboards_disallowed', 'user'); |
|
| 2855 | + if (empty($modSettings['allow_ignore_boards'])) { |
|
| 2856 | + fatal_lang_error('ignoreboards_disallowed', 'user'); |
|
| 2857 | + } |
|
| 2738 | 2858 | |
| 2739 | 2859 | // Find all the boards this user is allowed to see. |
| 2740 | 2860 | $request = $smcFunc['db_query']('order_by_board_order', ' |
@@ -2754,12 +2874,13 @@ discard block |
||
| 2754 | 2874 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2755 | 2875 | { |
| 2756 | 2876 | // This category hasn't been set up yet.. |
| 2757 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 2758 | - $context['categories'][$row['id_cat']] = array( |
|
| 2877 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 2878 | + $context['categories'][$row['id_cat']] = array( |
|
| 2759 | 2879 | 'id' => $row['id_cat'], |
| 2760 | 2880 | 'name' => $row['cat_name'], |
| 2761 | 2881 | 'boards' => array() |
| 2762 | 2882 | ); |
| 2883 | + } |
|
| 2763 | 2884 | |
| 2764 | 2885 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 2765 | 2886 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -2789,18 +2910,20 @@ discard block |
||
| 2789 | 2910 | } |
| 2790 | 2911 | |
| 2791 | 2912 | $max_boards = ceil(count($temp_boards) / 2); |
| 2792 | - if ($max_boards == 1) |
|
| 2793 | - $max_boards = 2; |
|
| 2913 | + if ($max_boards == 1) { |
|
| 2914 | + $max_boards = 2; |
|
| 2915 | + } |
|
| 2794 | 2916 | |
| 2795 | 2917 | // Now, alternate them so they can be shown left and right ;). |
| 2796 | 2918 | $context['board_columns'] = array(); |
| 2797 | 2919 | for ($i = 0; $i < $max_boards; $i++) |
| 2798 | 2920 | { |
| 2799 | 2921 | $context['board_columns'][] = $temp_boards[$i]; |
| 2800 | - if (isset($temp_boards[$i + $max_boards])) |
|
| 2801 | - $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 2802 | - else |
|
| 2803 | - $context['board_columns'][] = array(); |
|
| 2922 | + if (isset($temp_boards[$i + $max_boards])) { |
|
| 2923 | + $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 2924 | + } else { |
|
| 2925 | + $context['board_columns'][] = array(); |
|
| 2926 | + } |
|
| 2804 | 2927 | } |
| 2805 | 2928 | |
| 2806 | 2929 | loadThemeOptions($memID); |
@@ -2869,8 +2992,9 @@ discard block |
||
| 2869 | 2992 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2870 | 2993 | { |
| 2871 | 2994 | // We should skip the administrator group if they don't have the admin_forum permission! |
| 2872 | - if ($row['id_group'] == 1 && !allowedTo('admin_forum')) |
|
| 2873 | - continue; |
|
| 2995 | + if ($row['id_group'] == 1 && !allowedTo('admin_forum')) { |
|
| 2996 | + continue; |
|
| 2997 | + } |
|
| 2874 | 2998 | |
| 2875 | 2999 | $context['member_groups'][$row['id_group']] = array( |
| 2876 | 3000 | 'id' => $row['id_group'], |
@@ -2916,16 +3040,17 @@ discard block |
||
| 2916 | 3040 | $context['max_signature_length'] = $context['signature_limits']['max_length']; |
| 2917 | 3041 | // Warning message for signature image limits? |
| 2918 | 3042 | $context['signature_warning'] = ''; |
| 2919 | - if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) |
|
| 2920 | - $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']); |
|
| 2921 | - elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) |
|
| 2922 | - $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']); |
|
| 3043 | + if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) { |
|
| 3044 | + $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']); |
|
| 3045 | + } elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) { |
|
| 3046 | + $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']); |
|
| 3047 | + } |
|
| 2923 | 3048 | |
| 2924 | 3049 | $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))); |
| 2925 | 3050 | |
| 2926 | - if (empty($context['do_preview'])) |
|
| 2927 | - $context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '<', '>', '"', '''), $cur_profile['signature']); |
|
| 2928 | - else |
|
| 3051 | + if (empty($context['do_preview'])) { |
|
| 3052 | + $context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '<', '>', '"', '''), $cur_profile['signature']); |
|
| 3053 | + } else |
|
| 2929 | 3054 | { |
| 2930 | 3055 | $signature = !empty($_POST['signature']) ? $_POST['signature'] : ''; |
| 2931 | 3056 | $validation = profileValidateSignature($signature); |
@@ -2935,8 +3060,9 @@ discard block |
||
| 2935 | 3060 | $context['post_errors'] = array(); |
| 2936 | 3061 | } |
| 2937 | 3062 | $context['post_errors'][] = 'signature_not_yet_saved'; |
| 2938 | - if ($validation !== true && $validation !== false) |
|
| 2939 | - $context['post_errors'][] = $validation; |
|
| 3063 | + if ($validation !== true && $validation !== false) { |
|
| 3064 | + $context['post_errors'][] = $validation; |
|
| 3065 | + } |
|
| 2940 | 3066 | |
| 2941 | 3067 | censorText($context['member']['signature']); |
| 2942 | 3068 | $context['member']['current_signature'] = $context['member']['signature']; |
@@ -2946,8 +3072,9 @@ discard block |
||
| 2946 | 3072 | } |
| 2947 | 3073 | |
| 2948 | 3074 | // Load the spell checker? |
| 2949 | - if ($context['show_spellchecking']) |
|
| 2950 | - loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
| 3075 | + if ($context['show_spellchecking']) { |
|
| 3076 | + loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
| 3077 | + } |
|
| 2951 | 3078 | |
| 2952 | 3079 | return true; |
| 2953 | 3080 | } |
@@ -2981,8 +3108,7 @@ discard block |
||
| 2981 | 3108 | 'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11) |
| 2982 | 3109 | ); |
| 2983 | 3110 | $context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']); |
| 2984 | - } |
|
| 2985 | - elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload']) |
|
| 3111 | + } elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload']) |
|
| 2986 | 3112 | { |
| 2987 | 3113 | $context['member']['avatar'] += array( |
| 2988 | 3114 | 'choice' => 'upload', |
@@ -2992,33 +3118,34 @@ discard block |
||
| 2992 | 3118 | $context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename']; |
| 2993 | 3119 | } |
| 2994 | 3120 | // Use "avatar_original" here so we show what the user entered even if the image proxy is enabled |
| 2995 | - elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) |
|
| 2996 | - $context['member']['avatar'] += array( |
|
| 3121 | + elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) { |
|
| 3122 | + $context['member']['avatar'] += array( |
|
| 2997 | 3123 | 'choice' => 'external', |
| 2998 | 3124 | 'server_pic' => 'blank.png', |
| 2999 | 3125 | 'external' => $cur_profile['avatar_original'] |
| 3000 | 3126 | ); |
| 3001 | - elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) |
|
| 3002 | - $context['member']['avatar'] += array( |
|
| 3127 | + } elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) { |
|
| 3128 | + $context['member']['avatar'] += array( |
|
| 3003 | 3129 | 'choice' => 'server_stored', |
| 3004 | 3130 | 'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'], |
| 3005 | 3131 | 'external' => 'http://' |
| 3006 | 3132 | ); |
| 3007 | - else |
|
| 3008 | - $context['member']['avatar'] += array( |
|
| 3133 | + } else { |
|
| 3134 | + $context['member']['avatar'] += array( |
|
| 3009 | 3135 | 'choice' => 'none', |
| 3010 | 3136 | 'server_pic' => 'blank.png', |
| 3011 | 3137 | 'external' => 'http://' |
| 3012 | 3138 | ); |
| 3139 | + } |
|
| 3013 | 3140 | |
| 3014 | 3141 | // Get a list of all the avatars. |
| 3015 | 3142 | if ($context['member']['avatar']['allow_server_stored']) |
| 3016 | 3143 | { |
| 3017 | 3144 | $context['avatar_list'] = array(); |
| 3018 | 3145 | $context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array(); |
| 3146 | + } else { |
|
| 3147 | + $context['avatars'] = array(); |
|
| 3019 | 3148 | } |
| 3020 | - else |
|
| 3021 | - $context['avatars'] = array(); |
|
| 3022 | 3149 | |
| 3023 | 3150 | // Second level selected avatar... |
| 3024 | 3151 | $context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1); |
@@ -3047,19 +3174,22 @@ discard block |
||
| 3047 | 3174 | ) |
| 3048 | 3175 | ); |
| 3049 | 3176 | $protected_groups = array(1); |
| 3050 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3051 | - $protected_groups[] = $row['id_group']; |
|
| 3177 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3178 | + $protected_groups[] = $row['id_group']; |
|
| 3179 | + } |
|
| 3052 | 3180 | $smcFunc['db_free_result']($request); |
| 3053 | 3181 | |
| 3054 | 3182 | $protected_groups = array_unique($protected_groups); |
| 3055 | 3183 | } |
| 3056 | 3184 | |
| 3057 | 3185 | // The account page allows the change of your id_group - but not to a protected group! |
| 3058 | - if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) |
|
| 3059 | - $value = (int) $value; |
|
| 3186 | + if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) { |
|
| 3187 | + $value = (int) $value; |
|
| 3188 | + } |
|
| 3060 | 3189 | // ... otherwise it's the old group sir. |
| 3061 | - else |
|
| 3062 | - $value = $old_profile['id_group']; |
|
| 3190 | + else { |
|
| 3191 | + $value = $old_profile['id_group']; |
|
| 3192 | + } |
|
| 3063 | 3193 | |
| 3064 | 3194 | // Find the additional membergroups (if any) |
| 3065 | 3195 | if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups'])) |
@@ -3068,16 +3198,18 @@ discard block |
||
| 3068 | 3198 | foreach ($_POST['additional_groups'] as $group_id) |
| 3069 | 3199 | { |
| 3070 | 3200 | $group_id = (int) $group_id; |
| 3071 | - if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) |
|
| 3072 | - $additional_groups[] = $group_id; |
|
| 3201 | + if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) { |
|
| 3202 | + $additional_groups[] = $group_id; |
|
| 3203 | + } |
|
| 3073 | 3204 | } |
| 3074 | 3205 | |
| 3075 | 3206 | // Put the protected groups back in there if you don't have permission to take them away. |
| 3076 | 3207 | $old_additional_groups = explode(',', $old_profile['additional_groups']); |
| 3077 | 3208 | foreach ($old_additional_groups as $group_id) |
| 3078 | 3209 | { |
| 3079 | - if (!empty($protected_groups) && in_array($group_id, $protected_groups)) |
|
| 3080 | - $additional_groups[] = $group_id; |
|
| 3210 | + if (!empty($protected_groups) && in_array($group_id, $protected_groups)) { |
|
| 3211 | + $additional_groups[] = $group_id; |
|
| 3212 | + } |
|
| 3081 | 3213 | } |
| 3082 | 3214 | |
| 3083 | 3215 | if (implode(',', $additional_groups) !== $old_profile['additional_groups']) |
@@ -3109,18 +3241,20 @@ discard block |
||
| 3109 | 3241 | list ($another) = $smcFunc['db_fetch_row']($request); |
| 3110 | 3242 | $smcFunc['db_free_result']($request); |
| 3111 | 3243 | |
| 3112 | - if (empty($another)) |
|
| 3113 | - fatal_lang_error('at_least_one_admin', 'critical'); |
|
| 3244 | + if (empty($another)) { |
|
| 3245 | + fatal_lang_error('at_least_one_admin', 'critical'); |
|
| 3246 | + } |
|
| 3114 | 3247 | } |
| 3115 | 3248 | } |
| 3116 | 3249 | |
| 3117 | 3250 | // If we are changing group status, update permission cache as necessary. |
| 3118 | 3251 | if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups'])) |
| 3119 | 3252 | { |
| 3120 | - if ($context['user']['is_owner']) |
|
| 3121 | - $_SESSION['mc']['time'] = 0; |
|
| 3122 | - else |
|
| 3123 | - updateSettings(array('settings_updated' => time())); |
|
| 3253 | + if ($context['user']['is_owner']) { |
|
| 3254 | + $_SESSION['mc']['time'] = 0; |
|
| 3255 | + } else { |
|
| 3256 | + updateSettings(array('settings_updated' => time())); |
|
| 3257 | + } |
|
| 3124 | 3258 | } |
| 3125 | 3259 | |
| 3126 | 3260 | // Announce to any hooks that we have changed groups, but don't allow them to change it. |
@@ -3141,8 +3275,9 @@ discard block |
||
| 3141 | 3275 | global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context; |
| 3142 | 3276 | |
| 3143 | 3277 | $memID = $context['id_member']; |
| 3144 | - if (empty($memID) && !empty($context['password_auth_failed'])) |
|
| 3145 | - return false; |
|
| 3278 | + if (empty($memID) && !empty($context['password_auth_failed'])) { |
|
| 3279 | + return false; |
|
| 3280 | + } |
|
| 3146 | 3281 | |
| 3147 | 3282 | require_once($sourcedir . '/ManageAttachments.php'); |
| 3148 | 3283 | |
@@ -3153,8 +3288,9 @@ discard block |
||
| 3153 | 3288 | $downloadedExternalAvatar = false; |
| 3154 | 3289 | if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external'])) |
| 3155 | 3290 | { |
| 3156 | - if (!is_writable($uploadDir)) |
|
| 3157 | - fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3291 | + if (!is_writable($uploadDir)) { |
|
| 3292 | + fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3293 | + } |
|
| 3158 | 3294 | |
| 3159 | 3295 | require_once($sourcedir . '/Subs-Package.php'); |
| 3160 | 3296 | |
@@ -3198,19 +3334,18 @@ discard block |
||
| 3198 | 3334 | |
| 3199 | 3335 | // Get rid of their old avatar. (if uploaded.) |
| 3200 | 3336 | removeAttachments(array('id_member' => $memID)); |
| 3201 | - } |
|
| 3202 | - elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled'])) |
|
| 3337 | + } elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled'])) |
|
| 3203 | 3338 | { |
| 3204 | 3339 | // One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar. |
| 3205 | - if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) |
|
| 3206 | - $profile_vars['avatar'] = 'gravatar://'; |
|
| 3207 | - else |
|
| 3208 | - $profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : ''); |
|
| 3340 | + if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) { |
|
| 3341 | + $profile_vars['avatar'] = 'gravatar://'; |
|
| 3342 | + } else { |
|
| 3343 | + $profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : ''); |
|
| 3344 | + } |
|
| 3209 | 3345 | |
| 3210 | 3346 | // Get rid of their old avatar. (if uploaded.) |
| 3211 | 3347 | removeAttachments(array('id_member' => $memID)); |
| 3212 | - } |
|
| 3213 | - elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external'])) |
|
| 3348 | + } elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external'])) |
|
| 3214 | 3349 | { |
| 3215 | 3350 | // We need these clean... |
| 3216 | 3351 | $cur_profile['id_attach'] = 0; |
@@ -3222,11 +3357,13 @@ discard block |
||
| 3222 | 3357 | |
| 3223 | 3358 | $profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal'])); |
| 3224 | 3359 | |
| 3225 | - if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') |
|
| 3226 | - $profile_vars['avatar'] = ''; |
|
| 3360 | + if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') { |
|
| 3361 | + $profile_vars['avatar'] = ''; |
|
| 3362 | + } |
|
| 3227 | 3363 | // Trying to make us do something we'll regret? |
| 3228 | - elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') |
|
| 3229 | - return 'bad_avatar_invalid_url'; |
|
| 3364 | + elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') { |
|
| 3365 | + return 'bad_avatar_invalid_url'; |
|
| 3366 | + } |
|
| 3230 | 3367 | // Should we check dimensions? |
| 3231 | 3368 | elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external'])) |
| 3232 | 3369 | { |
@@ -3236,9 +3373,9 @@ discard block |
||
| 3236 | 3373 | if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external'])))) |
| 3237 | 3374 | { |
| 3238 | 3375 | // Houston, we have a problem. The avatar is too large!! |
| 3239 | - if ($modSettings['avatar_action_too_large'] == 'option_refuse') |
|
| 3240 | - return 'bad_avatar_too_large'; |
|
| 3241 | - elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') |
|
| 3376 | + if ($modSettings['avatar_action_too_large'] == 'option_refuse') { |
|
| 3377 | + return 'bad_avatar_too_large'; |
|
| 3378 | + } elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') |
|
| 3242 | 3379 | { |
| 3243 | 3380 | // @todo remove this if appropriate |
| 3244 | 3381 | require_once($sourcedir . '/Subs-Graphics.php'); |
@@ -3248,26 +3385,27 @@ discard block |
||
| 3248 | 3385 | $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id']; |
| 3249 | 3386 | $cur_profile['filename'] = $modSettings['new_avatar_data']['filename']; |
| 3250 | 3387 | $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type']; |
| 3388 | + } else { |
|
| 3389 | + return 'bad_avatar'; |
|
| 3251 | 3390 | } |
| 3252 | - else |
|
| 3253 | - return 'bad_avatar'; |
|
| 3254 | 3391 | } |
| 3255 | 3392 | } |
| 3256 | 3393 | } |
| 3257 | - } |
|
| 3258 | - elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar) |
|
| 3394 | + } elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar) |
|
| 3259 | 3395 | { |
| 3260 | 3396 | if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar) |
| 3261 | 3397 | { |
| 3262 | 3398 | // Get the dimensions of the image. |
| 3263 | 3399 | if (!$downloadedExternalAvatar) |
| 3264 | 3400 | { |
| 3265 | - if (!is_writable($uploadDir)) |
|
| 3266 | - fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3401 | + if (!is_writable($uploadDir)) { |
|
| 3402 | + fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3403 | + } |
|
| 3267 | 3404 | |
| 3268 | 3405 | $new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true); |
| 3269 | - if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) |
|
| 3270 | - fatal_lang_error('attach_timeout', 'critical'); |
|
| 3406 | + if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) { |
|
| 3407 | + fatal_lang_error('attach_timeout', 'critical'); |
|
| 3408 | + } |
|
| 3271 | 3409 | |
| 3272 | 3410 | $_FILES['attachment']['tmp_name'] = $new_filename; |
| 3273 | 3411 | } |
@@ -3380,17 +3518,19 @@ discard block |
||
| 3380 | 3518 | $profile_vars['avatar'] = ''; |
| 3381 | 3519 | |
| 3382 | 3520 | // Delete any temporary file. |
| 3383 | - if (file_exists($_FILES['attachment']['tmp_name'])) |
|
| 3384 | - @unlink($_FILES['attachment']['tmp_name']); |
|
| 3521 | + if (file_exists($_FILES['attachment']['tmp_name'])) { |
|
| 3522 | + @unlink($_FILES['attachment']['tmp_name']); |
|
| 3523 | + } |
|
| 3385 | 3524 | } |
| 3386 | 3525 | // Selected the upload avatar option and had one already uploaded before or didn't upload one. |
| 3387 | - else |
|
| 3526 | + else { |
|
| 3527 | + $profile_vars['avatar'] = ''; |
|
| 3528 | + } |
|
| 3529 | + } elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) { |
|
| 3530 | + $profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address']))); |
|
| 3531 | + } else { |
|
| 3388 | 3532 | $profile_vars['avatar'] = ''; |
| 3389 | 3533 | } |
| 3390 | - elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) |
|
| 3391 | - $profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address']))); |
|
| 3392 | - else |
|
| 3393 | - $profile_vars['avatar'] = ''; |
|
| 3394 | 3534 | |
| 3395 | 3535 | // Setup the profile variables so it shows things right on display! |
| 3396 | 3536 | $cur_profile['avatar'] = $profile_vars['avatar']; |
@@ -3438,9 +3578,9 @@ discard block |
||
| 3438 | 3578 | $smiley_parsed = $unparsed_signature; |
| 3439 | 3579 | parsesmileys($smiley_parsed); |
| 3440 | 3580 | $smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img'); |
| 3441 | - if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) |
|
| 3442 | - return 'signature_allow_smileys'; |
|
| 3443 | - elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4]) |
|
| 3581 | + if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) { |
|
| 3582 | + return 'signature_allow_smileys'; |
|
| 3583 | + } elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4]) |
|
| 3444 | 3584 | { |
| 3445 | 3585 | $txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]); |
| 3446 | 3586 | return 'signature_max_smileys'; |
@@ -3453,14 +3593,15 @@ discard block |
||
| 3453 | 3593 | { |
| 3454 | 3594 | $limit_broke = 0; |
| 3455 | 3595 | // Attempt to allow all sizes of abuse, so to speak. |
| 3456 | - if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) |
|
| 3457 | - $limit_broke = $sig_limits[7] . 'px'; |
|
| 3458 | - elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) |
|
| 3459 | - $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 3460 | - elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) |
|
| 3461 | - $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 3462 | - elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) |
|
| 3463 | - $limit_broke = 'large'; |
|
| 3596 | + if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) { |
|
| 3597 | + $limit_broke = $sig_limits[7] . 'px'; |
|
| 3598 | + } elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) { |
|
| 3599 | + $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 3600 | + } elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) { |
|
| 3601 | + $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 3602 | + } elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) { |
|
| 3603 | + $limit_broke = 'large'; |
|
| 3604 | + } |
|
| 3464 | 3605 | |
| 3465 | 3606 | if ($limit_broke) |
| 3466 | 3607 | { |
@@ -3502,24 +3643,26 @@ discard block |
||
| 3502 | 3643 | $width = -1; $height = -1; |
| 3503 | 3644 | |
| 3504 | 3645 | // Does it have predefined restraints? Width first. |
| 3505 | - if ($matches[6][$key]) |
|
| 3506 | - $matches[2][$key] = $matches[6][$key]; |
|
| 3646 | + if ($matches[6][$key]) { |
|
| 3647 | + $matches[2][$key] = $matches[6][$key]; |
|
| 3648 | + } |
|
| 3507 | 3649 | if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) |
| 3508 | 3650 | { |
| 3509 | 3651 | $width = $sig_limits[5]; |
| 3510 | 3652 | $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]); |
| 3653 | + } elseif ($matches[2][$key]) { |
|
| 3654 | + $width = $matches[2][$key]; |
|
| 3511 | 3655 | } |
| 3512 | - elseif ($matches[2][$key]) |
|
| 3513 | - $width = $matches[2][$key]; |
|
| 3514 | 3656 | // ... and height. |
| 3515 | 3657 | if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) |
| 3516 | 3658 | { |
| 3517 | 3659 | $height = $sig_limits[6]; |
| 3518 | - if ($width != -1) |
|
| 3519 | - $width = $width * ($height / $matches[4][$key]); |
|
| 3660 | + if ($width != -1) { |
|
| 3661 | + $width = $width * ($height / $matches[4][$key]); |
|
| 3662 | + } |
|
| 3663 | + } elseif ($matches[4][$key]) { |
|
| 3664 | + $height = $matches[4][$key]; |
|
| 3520 | 3665 | } |
| 3521 | - elseif ($matches[4][$key]) |
|
| 3522 | - $height = $matches[4][$key]; |
|
| 3523 | 3666 | |
| 3524 | 3667 | // If the dimensions are still not fixed - we need to check the actual image. |
| 3525 | 3668 | if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) |
@@ -3537,21 +3680,24 @@ discard block |
||
| 3537 | 3680 | if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) |
| 3538 | 3681 | { |
| 3539 | 3682 | $height = $sig_limits[6]; |
| 3540 | - if ($width == -1) |
|
| 3541 | - $width = $sizes[0]; |
|
| 3683 | + if ($width == -1) { |
|
| 3684 | + $width = $sizes[0]; |
|
| 3685 | + } |
|
| 3542 | 3686 | $width = $width * ($height / $sizes[1]); |
| 3687 | + } elseif ($width != -1) { |
|
| 3688 | + $height = $sizes[1]; |
|
| 3543 | 3689 | } |
| 3544 | - elseif ($width != -1) |
|
| 3545 | - $height = $sizes[1]; |
|
| 3546 | 3690 | } |
| 3547 | 3691 | } |
| 3548 | 3692 | |
| 3549 | 3693 | // Did we come up with some changes? If so remake the string. |
| 3550 | - if ($width != -1 || $height != -1) |
|
| 3551 | - $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]'; |
|
| 3694 | + if ($width != -1 || $height != -1) { |
|
| 3695 | + $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]'; |
|
| 3696 | + } |
|
| 3697 | + } |
|
| 3698 | + if (!empty($replaces)) { |
|
| 3699 | + $value = str_replace(array_keys($replaces), array_values($replaces), $value); |
|
| 3552 | 3700 | } |
| 3553 | - if (!empty($replaces)) |
|
| 3554 | - $value = str_replace(array_keys($replaces), array_values($replaces), $value); |
|
| 3555 | 3701 | } |
| 3556 | 3702 | } |
| 3557 | 3703 | |
@@ -3595,10 +3741,12 @@ discard block |
||
| 3595 | 3741 | $email = strtr($email, array(''' => '\'')); |
| 3596 | 3742 | |
| 3597 | 3743 | // Check the name and email for validity. |
| 3598 | - if (trim($email) == '') |
|
| 3599 | - return 'no_email'; |
|
| 3600 | - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) |
|
| 3601 | - return 'bad_email'; |
|
| 3744 | + if (trim($email) == '') { |
|
| 3745 | + return 'no_email'; |
|
| 3746 | + } |
|
| 3747 | + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
| 3748 | + return 'bad_email'; |
|
| 3749 | + } |
|
| 3602 | 3750 | |
| 3603 | 3751 | // Email addresses should be and stay unique. |
| 3604 | 3752 | $request = $smcFunc['db_query']('', ' |
@@ -3613,8 +3761,9 @@ discard block |
||
| 3613 | 3761 | ) |
| 3614 | 3762 | ); |
| 3615 | 3763 | |
| 3616 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 3617 | - return 'email_taken'; |
|
| 3764 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 3765 | + return 'email_taken'; |
|
| 3766 | + } |
|
| 3618 | 3767 | $smcFunc['db_free_result']($request); |
| 3619 | 3768 | |
| 3620 | 3769 | return true; |
@@ -3627,8 +3776,9 @@ discard block |
||
| 3627 | 3776 | { |
| 3628 | 3777 | global $modSettings, $context, $cur_profile; |
| 3629 | 3778 | |
| 3630 | - if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') |
|
| 3631 | - setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt'])); |
|
| 3779 | + if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') { |
|
| 3780 | + setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt'])); |
|
| 3781 | + } |
|
| 3632 | 3782 | |
| 3633 | 3783 | loadUserSettings(); |
| 3634 | 3784 | writeLog(); |
@@ -3644,8 +3794,9 @@ discard block |
||
| 3644 | 3794 | require_once($sourcedir . '/Subs-Post.php'); |
| 3645 | 3795 | |
| 3646 | 3796 | // Shouldn't happen but just in case. |
| 3647 | - if (empty($profile_vars['email_address'])) |
|
| 3648 | - return; |
|
| 3797 | + if (empty($profile_vars['email_address'])) { |
|
| 3798 | + return; |
|
| 3799 | + } |
|
| 3649 | 3800 | |
| 3650 | 3801 | $replacements = array( |
| 3651 | 3802 | 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'], |
@@ -3668,8 +3819,9 @@ discard block |
||
| 3668 | 3819 | $_SESSION['log_time'] = 0; |
| 3669 | 3820 | $_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0)); |
| 3670 | 3821 | |
| 3671 | - if (isset($_COOKIE[$cookiename])) |
|
| 3672 | - $_COOKIE[$cookiename] = ''; |
|
| 3822 | + if (isset($_COOKIE[$cookiename])) { |
|
| 3823 | + $_COOKIE[$cookiename] = ''; |
|
| 3824 | + } |
|
| 3673 | 3825 | |
| 3674 | 3826 | loadUserSettings(); |
| 3675 | 3827 | |
@@ -3702,11 +3854,13 @@ discard block |
||
| 3702 | 3854 | $groups[] = $curMember['id_group']; |
| 3703 | 3855 | |
| 3704 | 3856 | // Ensure the query doesn't croak! |
| 3705 | - if (empty($groups)) |
|
| 3706 | - $groups = array(0); |
|
| 3857 | + if (empty($groups)) { |
|
| 3858 | + $groups = array(0); |
|
| 3859 | + } |
|
| 3707 | 3860 | // Just to be sure... |
| 3708 | - foreach ($groups as $k => $v) |
|
| 3709 | - $groups[$k] = (int) $v; |
|
| 3861 | + foreach ($groups as $k => $v) { |
|
| 3862 | + $groups[$k] = (int) $v; |
|
| 3863 | + } |
|
| 3710 | 3864 | |
| 3711 | 3865 | // Get all the membergroups they can join. |
| 3712 | 3866 | $request = $smcFunc['db_query']('', ' |
@@ -3736,12 +3890,14 @@ discard block |
||
| 3736 | 3890 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 3737 | 3891 | { |
| 3738 | 3892 | // Can they edit their primary group? |
| 3739 | - if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) |
|
| 3740 | - $context['can_edit_primary'] = true; |
|
| 3893 | + if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) { |
|
| 3894 | + $context['can_edit_primary'] = true; |
|
| 3895 | + } |
|
| 3741 | 3896 | |
| 3742 | 3897 | // If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it. |
| 3743 | - if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) |
|
| 3744 | - continue; |
|
| 3898 | + if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) { |
|
| 3899 | + continue; |
|
| 3900 | + } |
|
| 3745 | 3901 | |
| 3746 | 3902 | $context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array( |
| 3747 | 3903 | 'id' => $row['id_group'], |
@@ -3770,13 +3926,15 @@ discard block |
||
| 3770 | 3926 | ); |
| 3771 | 3927 | |
| 3772 | 3928 | // No changing primary one unless you have enough groups! |
| 3773 | - if (count($context['groups']['member']) < 2) |
|
| 3774 | - $context['can_edit_primary'] = false; |
|
| 3929 | + if (count($context['groups']['member']) < 2) { |
|
| 3930 | + $context['can_edit_primary'] = false; |
|
| 3931 | + } |
|
| 3775 | 3932 | |
| 3776 | 3933 | // In the special case that someone is requesting membership of a group, setup some special context vars. |
| 3777 | - if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) |
|
| 3778 | - $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; |
|
| 3779 | -} |
|
| 3934 | + if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) { |
|
| 3935 | + $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; |
|
| 3936 | + } |
|
| 3937 | + } |
|
| 3780 | 3938 | |
| 3781 | 3939 | /** |
| 3782 | 3940 | * This function actually makes all the group changes |
@@ -3791,10 +3949,12 @@ discard block |
||
| 3791 | 3949 | global $user_info, $context, $user_profile, $modSettings, $smcFunc; |
| 3792 | 3950 | |
| 3793 | 3951 | // Let's be extra cautious... |
| 3794 | - if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) |
|
| 3795 | - isAllowedTo('manage_membergroups'); |
|
| 3796 | - if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) |
|
| 3797 | - fatal_lang_error('no_access', false); |
|
| 3952 | + if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) { |
|
| 3953 | + isAllowedTo('manage_membergroups'); |
|
| 3954 | + } |
|
| 3955 | + if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) { |
|
| 3956 | + fatal_lang_error('no_access', false); |
|
| 3957 | + } |
|
| 3798 | 3958 | |
| 3799 | 3959 | checkSession(isset($_GET['gid']) ? 'get' : 'post'); |
| 3800 | 3960 | |
@@ -3813,8 +3973,9 @@ discard block |
||
| 3813 | 3973 | $foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false; |
| 3814 | 3974 | |
| 3815 | 3975 | // Sanity check!! |
| 3816 | - if ($group_id == 1) |
|
| 3817 | - isAllowedTo('admin_forum'); |
|
| 3976 | + if ($group_id == 1) { |
|
| 3977 | + isAllowedTo('admin_forum'); |
|
| 3978 | + } |
|
| 3818 | 3979 | // Protected groups too! |
| 3819 | 3980 | else |
| 3820 | 3981 | { |
@@ -3831,8 +3992,9 @@ discard block |
||
| 3831 | 3992 | list ($is_protected) = $smcFunc['db_fetch_row']($request); |
| 3832 | 3993 | $smcFunc['db_free_result']($request); |
| 3833 | 3994 | |
| 3834 | - if ($is_protected == 1) |
|
| 3835 | - isAllowedTo('admin_forum'); |
|
| 3995 | + if ($is_protected == 1) { |
|
| 3996 | + isAllowedTo('admin_forum'); |
|
| 3997 | + } |
|
| 3836 | 3998 | } |
| 3837 | 3999 | |
| 3838 | 4000 | // What ever we are doing, we need to determine if changing primary is possible! |
@@ -3854,36 +4016,43 @@ discard block |
||
| 3854 | 4016 | $group_name = $row['group_name']; |
| 3855 | 4017 | |
| 3856 | 4018 | // Does the group type match what we're doing - are we trying to request a non-requestable group? |
| 3857 | - if ($changeType == 'request' && $row['group_type'] != 2) |
|
| 3858 | - fatal_lang_error('no_access', false); |
|
| 4019 | + if ($changeType == 'request' && $row['group_type'] != 2) { |
|
| 4020 | + fatal_lang_error('no_access', false); |
|
| 4021 | + } |
|
| 3859 | 4022 | // What about leaving a requestable group we are not a member of? |
| 3860 | - elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) |
|
| 3861 | - fatal_lang_error('no_access', false); |
|
| 3862 | - elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) |
|
| 3863 | - fatal_lang_error('no_access', false); |
|
| 4023 | + elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) { |
|
| 4024 | + fatal_lang_error('no_access', false); |
|
| 4025 | + } elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) { |
|
| 4026 | + fatal_lang_error('no_access', false); |
|
| 4027 | + } |
|
| 3864 | 4028 | |
| 3865 | 4029 | // We can't change the primary group if this is hidden! |
| 3866 | - if ($row['hidden'] == 2) |
|
| 3867 | - $canChangePrimary = false; |
|
| 4030 | + if ($row['hidden'] == 2) { |
|
| 4031 | + $canChangePrimary = false; |
|
| 4032 | + } |
|
| 3868 | 4033 | } |
| 3869 | 4034 | |
| 3870 | 4035 | // If this is their old primary, can we change it? |
| 3871 | - if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) |
|
| 3872 | - $canChangePrimary = 1; |
|
| 4036 | + if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) { |
|
| 4037 | + $canChangePrimary = 1; |
|
| 4038 | + } |
|
| 3873 | 4039 | |
| 3874 | 4040 | // If we are not doing a force primary move, don't do it automatically if current primary is not 0. |
| 3875 | - if ($changeType != 'primary' && $old_profile['id_group'] != 0) |
|
| 3876 | - $canChangePrimary = false; |
|
| 4041 | + if ($changeType != 'primary' && $old_profile['id_group'] != 0) { |
|
| 4042 | + $canChangePrimary = false; |
|
| 4043 | + } |
|
| 3877 | 4044 | |
| 3878 | 4045 | // If this is the one we are acting on, can we even act? |
| 3879 | - if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) |
|
| 3880 | - $canChangePrimary = false; |
|
| 4046 | + if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) { |
|
| 4047 | + $canChangePrimary = false; |
|
| 4048 | + } |
|
| 3881 | 4049 | } |
| 3882 | 4050 | $smcFunc['db_free_result']($request); |
| 3883 | 4051 | |
| 3884 | 4052 | // Didn't find the target? |
| 3885 | - if (!$foundTarget) |
|
| 3886 | - fatal_lang_error('no_access', false); |
|
| 4053 | + if (!$foundTarget) { |
|
| 4054 | + fatal_lang_error('no_access', false); |
|
| 4055 | + } |
|
| 3887 | 4056 | |
| 3888 | 4057 | // Final security check, don't allow users to promote themselves to admin. |
| 3889 | 4058 | if ($context['can_manage_membergroups'] && !allowedTo('admin_forum')) |
@@ -3903,8 +4072,9 @@ discard block |
||
| 3903 | 4072 | list ($disallow) = $smcFunc['db_fetch_row']($request); |
| 3904 | 4073 | $smcFunc['db_free_result']($request); |
| 3905 | 4074 | |
| 3906 | - if ($disallow) |
|
| 3907 | - isAllowedTo('admin_forum'); |
|
| 4075 | + if ($disallow) { |
|
| 4076 | + isAllowedTo('admin_forum'); |
|
| 4077 | + } |
|
| 3908 | 4078 | } |
| 3909 | 4079 | |
| 3910 | 4080 | // If we're requesting, add the note then return. |
@@ -3922,8 +4092,9 @@ discard block |
||
| 3922 | 4092 | 'status_open' => 0, |
| 3923 | 4093 | ) |
| 3924 | 4094 | ); |
| 3925 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 3926 | - fatal_lang_error('profile_error_already_requested_group'); |
|
| 4095 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 4096 | + fatal_lang_error('profile_error_already_requested_group'); |
|
| 4097 | + } |
|
| 3927 | 4098 | $smcFunc['db_free_result']($request); |
| 3928 | 4099 | |
| 3929 | 4100 | // Log the request. |
@@ -3957,10 +4128,11 @@ discard block |
||
| 3957 | 4128 | // Are we leaving? |
| 3958 | 4129 | if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id])) |
| 3959 | 4130 | { |
| 3960 | - if ($old_profile['id_group'] == $group_id) |
|
| 3961 | - $newPrimary = 0; |
|
| 3962 | - else |
|
| 3963 | - unset($addGroups[$group_id]); |
|
| 4131 | + if ($old_profile['id_group'] == $group_id) { |
|
| 4132 | + $newPrimary = 0; |
|
| 4133 | + } else { |
|
| 4134 | + unset($addGroups[$group_id]); |
|
| 4135 | + } |
|
| 3964 | 4136 | } |
| 3965 | 4137 | // ... if not, must be joining. |
| 3966 | 4138 | else |
@@ -3968,36 +4140,42 @@ discard block |
||
| 3968 | 4140 | // Can we change the primary, and do we want to? |
| 3969 | 4141 | if ($canChangePrimary) |
| 3970 | 4142 | { |
| 3971 | - if ($old_profile['id_group'] != 0) |
|
| 3972 | - $addGroups[$old_profile['id_group']] = -1; |
|
| 4143 | + if ($old_profile['id_group'] != 0) { |
|
| 4144 | + $addGroups[$old_profile['id_group']] = -1; |
|
| 4145 | + } |
|
| 3973 | 4146 | $newPrimary = $group_id; |
| 3974 | 4147 | } |
| 3975 | 4148 | // Otherwise it's an additional group... |
| 3976 | - else |
|
| 3977 | - $addGroups[$group_id] = -1; |
|
| 4149 | + else { |
|
| 4150 | + $addGroups[$group_id] = -1; |
|
| 4151 | + } |
|
| 3978 | 4152 | } |
| 3979 | 4153 | } |
| 3980 | 4154 | // Finally, we must be setting the primary. |
| 3981 | 4155 | elseif ($canChangePrimary) |
| 3982 | 4156 | { |
| 3983 | - if ($old_profile['id_group'] != 0) |
|
| 3984 | - $addGroups[$old_profile['id_group']] = -1; |
|
| 3985 | - if (isset($addGroups[$group_id])) |
|
| 3986 | - unset($addGroups[$group_id]); |
|
| 4157 | + if ($old_profile['id_group'] != 0) { |
|
| 4158 | + $addGroups[$old_profile['id_group']] = -1; |
|
| 4159 | + } |
|
| 4160 | + if (isset($addGroups[$group_id])) { |
|
| 4161 | + unset($addGroups[$group_id]); |
|
| 4162 | + } |
|
| 3987 | 4163 | $newPrimary = $group_id; |
| 3988 | 4164 | } |
| 3989 | 4165 | |
| 3990 | 4166 | // Finally, we can make the changes! |
| 3991 | - foreach ($addGroups as $id => $dummy) |
|
| 3992 | - if (empty($id)) |
|
| 4167 | + foreach ($addGroups as $id => $dummy) { |
|
| 4168 | + if (empty($id)) |
|
| 3993 | 4169 | unset($addGroups[$id]); |
| 4170 | + } |
|
| 3994 | 4171 | $addGroups = implode(',', array_flip($addGroups)); |
| 3995 | 4172 | |
| 3996 | 4173 | // Ensure that we don't cache permissions if the group is changing. |
| 3997 | - if ($context['user']['is_owner']) |
|
| 3998 | - $_SESSION['mc']['time'] = 0; |
|
| 3999 | - else |
|
| 4000 | - updateSettings(array('settings_updated' => time())); |
|
| 4174 | + if ($context['user']['is_owner']) { |
|
| 4175 | + $_SESSION['mc']['time'] = 0; |
|
| 4176 | + } else { |
|
| 4177 | + updateSettings(array('settings_updated' => time())); |
|
| 4178 | + } |
|
| 4001 | 4179 | |
| 4002 | 4180 | updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups)); |
| 4003 | 4181 | |
@@ -4020,8 +4198,9 @@ discard block |
||
| 4020 | 4198 | if (empty($user_settings['tfa_secret']) && $context['user']['is_owner']) |
| 4021 | 4199 | { |
| 4022 | 4200 | // Check to ensure we're forcing SSL for authentication |
| 4023 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 4024 | - fatal_lang_error('login_ssl_required'); |
|
| 4201 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 4202 | + fatal_lang_error('login_ssl_required'); |
|
| 4203 | + } |
|
| 4025 | 4204 | |
| 4026 | 4205 | // In some cases (forced 2FA or backup code) they would be forced to be redirected here, |
| 4027 | 4206 | // we do not want too much AJAX to confuse them. |
@@ -4058,8 +4237,7 @@ discard block |
||
| 4058 | 4237 | $context['sub_template'] = 'tfasetup_backup'; |
| 4059 | 4238 | |
| 4060 | 4239 | return; |
| 4061 | - } |
|
| 4062 | - else |
|
| 4240 | + } else |
|
| 4063 | 4241 | { |
| 4064 | 4242 | $context['tfa_secret'] = $_SESSION['tfa_secret']; |
| 4065 | 4243 | $context['tfa_error'] = !$valid_code; |
@@ -4067,8 +4245,7 @@ discard block |
||
| 4067 | 4245 | $context['tfa_pass_value'] = $_POST['passwd']; |
| 4068 | 4246 | $context['tfa_value'] = $_POST['tfa_code']; |
| 4069 | 4247 | } |
| 4070 | - } |
|
| 4071 | - else |
|
| 4248 | + } else |
|
| 4072 | 4249 | { |
| 4073 | 4250 | $totp = new \TOTP\Auth(); |
| 4074 | 4251 | $secret = $totp->generateCode(); |
@@ -4078,17 +4255,16 @@ discard block |
||
| 4078 | 4255 | } |
| 4079 | 4256 | |
| 4080 | 4257 | $context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']); |
| 4081 | - } |
|
| 4082 | - elseif (isset($_REQUEST['disable'])) |
|
| 4258 | + } elseif (isset($_REQUEST['disable'])) |
|
| 4083 | 4259 | { |
| 4084 | 4260 | updateMemberData($memID, array( |
| 4085 | 4261 | 'tfa_secret' => '', |
| 4086 | 4262 | 'tfa_backup' => '', |
| 4087 | 4263 | )); |
| 4088 | 4264 | redirectexit('action=profile;area=account;u=' . $memID); |
| 4265 | + } else { |
|
| 4266 | + redirectexit('action=profile;area=account;u=' . $memID); |
|
| 4267 | + } |
|
| 4089 | 4268 | } |
| 4090 | - else |
|
| 4091 | - redirectexit('action=profile;area=account;u=' . $memID); |
|
| 4092 | -} |
|
| 4093 | 4269 | |
| 4094 | 4270 | ?> |
| 4095 | 4271 | \ 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 | * Updates a report with the given parameters. Logs each action via logAction() |
@@ -28,19 +29,20 @@ discard block |
||
| 28 | 29 | global $smcFunc, $user_info, $context; |
| 29 | 30 | |
| 30 | 31 | // Don't bother. |
| 31 | - if (empty($action) || empty($report_id)) |
|
| 32 | - return false; |
|
| 32 | + if (empty($action) || empty($report_id)) { |
|
| 33 | + return false; |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | // Add the "_all" thingy. |
| 35 | - if ($action == 'ignore') |
|
| 36 | - $action = 'ignore_all'; |
|
| 37 | + if ($action == 'ignore') { |
|
| 38 | + $action = 'ignore_all'; |
|
| 39 | + } |
|
| 37 | 40 | |
| 38 | 41 | // We don't need the board query for reported members |
| 39 | 42 | if ($context['report_type'] == 'members') |
| 40 | 43 | { |
| 41 | 44 | $board_query = ''; |
| 42 | - } |
|
| 43 | - else |
|
| 45 | + } else |
|
| 44 | 46 | { |
| 45 | 47 | $board_query = ' AND ' . $user_info['mod_cache']['bq']; |
| 46 | 48 | } |
@@ -76,17 +78,17 @@ discard block |
||
| 76 | 78 | ) |
| 77 | 79 | ); |
| 78 | 80 | |
| 79 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 80 | - $extra[$row['id_report']] = array( |
|
| 81 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 82 | + $extra[$row['id_report']] = array( |
|
| 81 | 83 | 'report' => $row['id_report'], |
| 82 | 84 | 'board' => $row['id_board'], |
| 83 | 85 | 'message' => $row['id_msg'], |
| 84 | 86 | 'topic' => $row['id_topic'], |
| 85 | 87 | ); |
| 88 | + } |
|
| 86 | 89 | |
| 87 | 90 | $smcFunc['db_free_result']($request); |
| 88 | - } |
|
| 89 | - else |
|
| 91 | + } else |
|
| 90 | 92 | { |
| 91 | 93 | $request = $smcFunc['db_query']('', ' |
| 92 | 94 | SELECT id_report, id_member, membername |
@@ -97,28 +99,32 @@ discard block |
||
| 97 | 99 | ) |
| 98 | 100 | ); |
| 99 | 101 | |
| 100 | - while($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 101 | - $extra[$row['id_report']] = array( |
|
| 102 | + while($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 103 | + $extra[$row['id_report']] = array( |
|
| 102 | 104 | 'report' => $row['id_report'], |
| 103 | 105 | 'member' => $row['id_member'], |
| 104 | 106 | ); |
| 107 | + } |
|
| 105 | 108 | |
| 106 | 109 | $smcFunc['db_free_result']($request); |
| 107 | 110 | } |
| 108 | 111 | |
| 109 | 112 | // Back to "ignore". |
| 110 | - if ($action == 'ignore_all') |
|
| 111 | - $action = 'ignore'; |
|
| 113 | + if ($action == 'ignore_all') { |
|
| 114 | + $action = 'ignore'; |
|
| 115 | + } |
|
| 112 | 116 | |
| 113 | 117 | $log_report = $action == 'ignore' ? (!empty($value) ? 'ignore' : 'unignore') : (!empty($value) ? 'close' : 'open'); |
| 114 | 118 | |
| 115 | - if ($context['report_type'] == 'members') |
|
| 116 | - $log_report .= '_user'; |
|
| 119 | + if ($context['report_type'] == 'members') { |
|
| 120 | + $log_report .= '_user'; |
|
| 121 | + } |
|
| 117 | 122 | |
| 118 | 123 | // Log this action. |
| 119 | - if (!empty($extra)) |
|
| 120 | - foreach ($extra as $report) |
|
| 124 | + if (!empty($extra)) { |
|
| 125 | + foreach ($extra as $report) |
|
| 121 | 126 | logAction($log_report . '_report', $report); |
| 127 | + } |
|
| 122 | 128 | |
| 123 | 129 | // Time to update. |
| 124 | 130 | updateSettings(array('last_mod_report_action' => time())); |
@@ -140,14 +146,12 @@ discard block |
||
| 140 | 146 | if ($context['report_type'] == 'members') |
| 141 | 147 | { |
| 142 | 148 | $and = 'lr.id_board = 0'; |
| 143 | - } |
|
| 144 | - else |
|
| 149 | + } else |
|
| 145 | 150 | { |
| 146 | 151 | if ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1') |
| 147 | 152 | { |
| 148 | 153 | $bq = $user_info['mod_cache']['bq']; |
| 149 | - } |
|
| 150 | - else |
|
| 154 | + } else |
|
| 151 | 155 | { |
| 152 | 156 | $bq = 'lr.' . $user_info['mod_cache']['bq']; |
| 153 | 157 | } |
@@ -203,8 +207,7 @@ discard block |
||
| 203 | 207 | 'max' => 10, |
| 204 | 208 | ) |
| 205 | 209 | ); |
| 206 | - } |
|
| 207 | - else |
|
| 210 | + } else |
|
| 208 | 211 | { |
| 209 | 212 | $request = $smcFunc['db_query']('', ' |
| 210 | 213 | SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body, |
@@ -252,8 +255,7 @@ discard block |
||
| 252 | 255 | 'href' => $scripturl . '?action=profile;u=' . $row['id_user'], |
| 253 | 256 | ), |
| 254 | 257 | ); |
| 255 | - } |
|
| 256 | - else |
|
| 258 | + } else |
|
| 257 | 259 | { |
| 258 | 260 | $report_boards_ids[] = $row['id_board']; |
| 259 | 261 | $extraDetails = array( |
@@ -293,14 +295,16 @@ discard block |
||
| 293 | 295 | ) |
| 294 | 296 | ); |
| 295 | 297 | |
| 296 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 297 | - $board_names[$row['id_board']] = $row['name']; |
|
| 298 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 299 | + $board_names[$row['id_board']] = $row['name']; |
|
| 300 | + } |
|
| 298 | 301 | |
| 299 | 302 | $smcFunc['db_free_result']($request); |
| 300 | 303 | |
| 301 | - foreach ($reports as $id_report => $report) |
|
| 302 | - if (!empty($board_names[$report['topic']['id_board']])) |
|
| 304 | + foreach ($reports as $id_report => $report) { |
|
| 305 | + if (!empty($board_names[$report['topic']['id_board']])) |
|
| 303 | 306 | $reports[$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']]; |
| 307 | + } |
|
| 304 | 308 | } |
| 305 | 309 | |
| 306 | 310 | // Now get all the people who reported it. |
@@ -350,10 +354,11 @@ discard block |
||
| 350 | 354 | { |
| 351 | 355 | global $user_info, $smcFunc; |
| 352 | 356 | |
| 353 | - if ($type == 'members') |
|
| 354 | - $bq = ''; |
|
| 355 | - else |
|
| 356 | - $bq = ' AND ' . $user_info['mod_cache']['bq']; |
|
| 357 | + if ($type == 'members') { |
|
| 358 | + $bq = ''; |
|
| 359 | + } else { |
|
| 360 | + $bq = ' AND ' . $user_info['mod_cache']['bq']; |
|
| 361 | + } |
|
| 357 | 362 | |
| 358 | 363 | $request = $smcFunc['db_query']('', ' |
| 359 | 364 | SELECT COUNT(*) |
@@ -392,8 +397,9 @@ discard block |
||
| 392 | 397 | { |
| 393 | 398 | global $smcFunc, $user_info, $context; |
| 394 | 399 | |
| 395 | - if (empty($report_id)) |
|
| 396 | - return false; |
|
| 400 | + if (empty($report_id)) { |
|
| 401 | + return false; |
|
| 402 | + } |
|
| 397 | 403 | |
| 398 | 404 | // We don't need all this info if we're only getting user info |
| 399 | 405 | if ($context['report_type'] == 'members') |
@@ -411,8 +417,7 @@ discard block |
||
| 411 | 417 | 'id_report' => $report_id, |
| 412 | 418 | ) |
| 413 | 419 | ); |
| 414 | - } |
|
| 415 | - else |
|
| 420 | + } else |
|
| 416 | 421 | { |
| 417 | 422 | // Get the report details, need this so we can limit access to a particular board. |
| 418 | 423 | $request = $smcFunc['db_query']('', ' |
@@ -431,8 +436,9 @@ discard block |
||
| 431 | 436 | } |
| 432 | 437 | |
| 433 | 438 | // So did we find anything? |
| 434 | - if (!$smcFunc['db_num_rows']($request)) |
|
| 435 | - return false; |
|
| 439 | + if (!$smcFunc['db_num_rows']($request)) { |
|
| 440 | + return false; |
|
| 441 | + } |
|
| 436 | 442 | |
| 437 | 443 | // Woohoo we found a report and they can see it! |
| 438 | 444 | $row = $smcFunc['db_fetch_assoc']($request); |
@@ -451,8 +457,9 @@ discard block |
||
| 451 | 457 | { |
| 452 | 458 | global $smcFunc, $scripturl, $user_info, $txt; |
| 453 | 459 | |
| 454 | - if (empty($report_id)) |
|
| 455 | - return false; |
|
| 460 | + if (empty($report_id)) { |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 456 | 463 | |
| 457 | 464 | $report = array( |
| 458 | 465 | 'comments' => array(), |
@@ -533,8 +540,9 @@ discard block |
||
| 533 | 540 | { |
| 534 | 541 | global $smcFunc, $user_info; |
| 535 | 542 | |
| 536 | - if (empty($comment_id)) |
|
| 537 | - return false; |
|
| 543 | + if (empty($comment_id)) { |
|
| 544 | + return false; |
|
| 545 | + } |
|
| 538 | 546 | |
| 539 | 547 | $request = $smcFunc['db_query']('', ' |
| 540 | 548 | SELECT id_comment, id_notice, log_time, body, id_member |
@@ -551,8 +559,9 @@ discard block |
||
| 551 | 559 | $smcFunc['db_free_result']($request); |
| 552 | 560 | |
| 553 | 561 | // Add the permission |
| 554 | - if (!empty($comment)) |
|
| 555 | - $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
|
| 562 | + if (!empty($comment)) { |
|
| 563 | + $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
|
| 564 | + } |
|
| 556 | 565 | |
| 557 | 566 | return $comment; |
| 558 | 567 | } |
@@ -568,8 +577,9 @@ discard block |
||
| 568 | 577 | { |
| 569 | 578 | global $smcFunc, $user_info, $context; |
| 570 | 579 | |
| 571 | - if (empty($data)) |
|
| 572 | - return false; |
|
| 580 | + if (empty($data)) { |
|
| 581 | + return false; |
|
| 582 | + } |
|
| 573 | 583 | |
| 574 | 584 | $data = array_merge(array($user_info['id'], $user_info['name'], 'reportc', ''), $data); |
| 575 | 585 | |
@@ -598,8 +608,7 @@ discard block |
||
| 598 | 608 | 'comment_id' => $last_comment, |
| 599 | 609 | 'time' => time(), |
| 600 | 610 | ); |
| 601 | - } |
|
| 602 | - else |
|
| 611 | + } else |
|
| 603 | 612 | { |
| 604 | 613 | $prefix = 'Msg'; |
| 605 | 614 | $data = array( |
@@ -615,14 +624,15 @@ discard block |
||
| 615 | 624 | } |
| 616 | 625 | |
| 617 | 626 | // And get ready to notify people. |
| 618 | - if (!empty($report)) |
|
| 619 | - $smcFunc['db_insert']('insert', |
|
| 627 | + if (!empty($report)) { |
|
| 628 | + $smcFunc['db_insert']('insert', |
|
| 620 | 629 | '{db_prefix}background_tasks', |
| 621 | 630 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 622 | 631 | array('$sourcedir/tasks/' . $prefix . 'ReportReply-Notify.php', $prefix . 'ReportReply_Notify_Background', $smcFunc['json_encode']($data), 0), |
| 623 | 632 | array('id_task') |
| 624 | 633 | ); |
| 625 | -} |
|
| 634 | + } |
|
| 635 | + } |
|
| 626 | 636 | |
| 627 | 637 | /** |
| 628 | 638 | * Saves the new information whenever a moderator comment is edited. |
@@ -635,8 +645,9 @@ discard block |
||
| 635 | 645 | { |
| 636 | 646 | global $smcFunc; |
| 637 | 647 | |
| 638 | - if (empty($comment_id) || empty($edited_comment)) |
|
| 639 | - return false; |
|
| 648 | + if (empty($comment_id) || empty($edited_comment)) { |
|
| 649 | + return false; |
|
| 650 | + } |
|
| 640 | 651 | |
| 641 | 652 | $smcFunc['db_query']('', ' |
| 642 | 653 | UPDATE {db_prefix}log_comments |
@@ -659,8 +670,9 @@ discard block |
||
| 659 | 670 | { |
| 660 | 671 | global $smcFunc; |
| 661 | 672 | |
| 662 | - if (empty($comment_id)) |
|
| 663 | - return false; |
|
| 673 | + if (empty($comment_id)) { |
|
| 674 | + return false; |
|
| 675 | + } |
|
| 664 | 676 | |
| 665 | 677 | $smcFunc['db_query']('', ' |
| 666 | 678 | DELETE FROM {db_prefix}log_comments |
@@ -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 a list of versions that are currently installed on the server. |
@@ -45,8 +46,7 @@ discard block |
||
| 45 | 46 | $temp2 = $temp->getVersion(); |
| 46 | 47 | $im_version = $temp2['versionString']; |
| 47 | 48 | $extension_version = 'Imagick ' . phpversion('Imagick'); |
| 48 | - } |
|
| 49 | - else |
|
| 49 | + } else |
|
| 50 | 50 | { |
| 51 | 51 | $im_version = MagickGetVersionString(); |
| 52 | 52 | $extension_version = 'MagickWand ' . phpversion('MagickWand'); |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | if (in_array('db_server', $checkFor)) |
| 62 | 62 | { |
| 63 | 63 | db_extend(); |
| 64 | - if (!isset($db_connection) || $db_connection === false) |
|
| 65 | - trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE); |
|
| 66 | - else |
|
| 64 | + if (!isset($db_connection) || $db_connection === false) { |
|
| 65 | + trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE); |
|
| 66 | + } else |
|
| 67 | 67 | { |
| 68 | 68 | $versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => ''); |
| 69 | 69 | $versions['db_engine']['version'] = $smcFunc['db_get_engine'](); |
@@ -74,24 +74,31 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // If we're using memcache we need the server info. |
| 77 | - if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') |
|
| 78 | - get_memcached_server(); |
|
| 77 | + if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') { |
|
| 78 | + get_memcached_server(); |
|
| 79 | + } |
|
| 79 | 80 | |
| 80 | 81 | // Check to see if we have any accelerators installed... |
| 81 | - if (in_array('phpa', $checkFor) && isset($_PHPA)) |
|
| 82 | - $versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']); |
|
| 83 | - if (in_array('apc', $checkFor) && extension_loaded('apc')) |
|
| 84 | - $versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc')); |
|
| 85 | - if (in_array('memcache', $checkFor) && function_exists('memcache_set')) |
|
| 86 | - $versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached)); |
|
| 87 | - if (in_array('xcache', $checkFor) && function_exists('xcache_set')) |
|
| 88 | - $versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION); |
|
| 82 | + if (in_array('phpa', $checkFor) && isset($_PHPA)) { |
|
| 83 | + $versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']); |
|
| 84 | + } |
|
| 85 | + if (in_array('apc', $checkFor) && extension_loaded('apc')) { |
|
| 86 | + $versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc')); |
|
| 87 | + } |
|
| 88 | + if (in_array('memcache', $checkFor) && function_exists('memcache_set')) { |
|
| 89 | + $versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached)); |
|
| 90 | + } |
|
| 91 | + if (in_array('xcache', $checkFor) && function_exists('xcache_set')) { |
|
| 92 | + $versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION); |
|
| 93 | + } |
|
| 89 | 94 | |
| 90 | - if (in_array('php', $checkFor)) |
|
| 91 | - $versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo'); |
|
| 95 | + if (in_array('php', $checkFor)) { |
|
| 96 | + $versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo'); |
|
| 97 | + } |
|
| 92 | 98 | |
| 93 | - if (in_array('server', $checkFor)) |
|
| 94 | - $versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']); |
|
| 99 | + if (in_array('server', $checkFor)) { |
|
| 100 | + $versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']); |
|
| 101 | + } |
|
| 95 | 102 | |
| 96 | 103 | return $versions; |
| 97 | 104 | } |
@@ -131,11 +138,13 @@ discard block |
||
| 131 | 138 | fclose($fp); |
| 132 | 139 | |
| 133 | 140 | // The comment looks rougly like... that. |
| 134 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 135 | - $version_info['file_versions']['SSI.php'] = $match[1]; |
|
| 141 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 142 | + $version_info['file_versions']['SSI.php'] = $match[1]; |
|
| 143 | + } |
|
| 136 | 144 | // Not found! This is bad. |
| 137 | - else |
|
| 138 | - $version_info['file_versions']['SSI.php'] = '??'; |
|
| 145 | + else { |
|
| 146 | + $version_info['file_versions']['SSI.php'] = '??'; |
|
| 147 | + } |
|
| 139 | 148 | } |
| 140 | 149 | |
| 141 | 150 | // Do the paid subscriptions handler? |
@@ -146,11 +155,13 @@ discard block |
||
| 146 | 155 | fclose($fp); |
| 147 | 156 | |
| 148 | 157 | // Found it? |
| 149 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 150 | - $version_info['file_versions']['subscriptions.php'] = $match[1]; |
|
| 158 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 159 | + $version_info['file_versions']['subscriptions.php'] = $match[1]; |
|
| 160 | + } |
|
| 151 | 161 | // If we haven't how do we all get paid? |
| 152 | - else |
|
| 153 | - $version_info['file_versions']['subscriptions.php'] = '??'; |
|
| 162 | + else { |
|
| 163 | + $version_info['file_versions']['subscriptions.php'] = '??'; |
|
| 164 | + } |
|
| 154 | 165 | } |
| 155 | 166 | |
| 156 | 167 | // Load all the files in the Sources directory, except this file and the redirect. |
@@ -165,11 +176,13 @@ discard block |
||
| 165 | 176 | fclose($fp); |
| 166 | 177 | |
| 167 | 178 | // Look for the version comment in the file header. |
| 168 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 169 | - $version_info['file_versions'][$entry] = $match[1]; |
|
| 179 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 180 | + $version_info['file_versions'][$entry] = $match[1]; |
|
| 181 | + } |
|
| 170 | 182 | // It wasn't found, but the file was... show a '??'. |
| 171 | - else |
|
| 172 | - $version_info['file_versions'][$entry] = '??'; |
|
| 183 | + else { |
|
| 184 | + $version_info['file_versions'][$entry] = '??'; |
|
| 185 | + } |
|
| 173 | 186 | } |
| 174 | 187 | } |
| 175 | 188 | $sources_dir->close(); |
@@ -188,11 +201,13 @@ discard block |
||
| 188 | 201 | fclose($fp); |
| 189 | 202 | |
| 190 | 203 | // Look for the version comment in the file header. |
| 191 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 192 | - $version_info['tasks_versions'][$entry] = $match[1]; |
|
| 204 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 205 | + $version_info['tasks_versions'][$entry] = $match[1]; |
|
| 206 | + } |
|
| 193 | 207 | // It wasn't found, but the file was... show a '??'. |
| 194 | - else |
|
| 195 | - $version_info['tasks_versions'][$entry] = '??'; |
|
| 208 | + else { |
|
| 209 | + $version_info['tasks_versions'][$entry] = '??'; |
|
| 210 | + } |
|
| 196 | 211 | } |
| 197 | 212 | } |
| 198 | 213 | $tasks_dir->close(); |
@@ -200,8 +215,9 @@ discard block |
||
| 200 | 215 | |
| 201 | 216 | // Load all the files in the default template directory - and the current theme if applicable. |
| 202 | 217 | $directories = array('default_template_versions' => $settings['default_theme_dir']); |
| 203 | - if ($settings['theme_id'] != 1) |
|
| 204 | - $directories += array('template_versions' => $settings['theme_dir']); |
|
| 218 | + if ($settings['theme_id'] != 1) { |
|
| 219 | + $directories += array('template_versions' => $settings['theme_dir']); |
|
| 220 | + } |
|
| 205 | 221 | |
| 206 | 222 | foreach ($directories as $type => $dirname) |
| 207 | 223 | { |
@@ -216,11 +232,13 @@ discard block |
||
| 216 | 232 | fclose($fp); |
| 217 | 233 | |
| 218 | 234 | // Look for the version comment in the file header. |
| 219 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 220 | - $version_info[$type][$entry] = $match[1]; |
|
| 235 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 236 | + $version_info[$type][$entry] = $match[1]; |
|
| 237 | + } |
|
| 221 | 238 | // It wasn't found, but the file was... show a '??'. |
| 222 | - else |
|
| 223 | - $version_info[$type][$entry] = '??'; |
|
| 239 | + else { |
|
| 240 | + $version_info[$type][$entry] = '??'; |
|
| 241 | + } |
|
| 224 | 242 | } |
| 225 | 243 | } |
| 226 | 244 | $this_dir->close(); |
@@ -241,11 +259,13 @@ discard block |
||
| 241 | 259 | list ($name, $language) = explode('.', $entry); |
| 242 | 260 | |
| 243 | 261 | // Look for the version comment in the file header. |
| 244 | - if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) |
|
| 245 | - $version_info['default_language_versions'][$language][$name] = $match[1]; |
|
| 262 | + if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) { |
|
| 263 | + $version_info['default_language_versions'][$language][$name] = $match[1]; |
|
| 264 | + } |
|
| 246 | 265 | // It wasn't found, but the file was... show a '??'. |
| 247 | - else |
|
| 248 | - $version_info['default_language_versions'][$language][$name] = '??'; |
|
| 266 | + else { |
|
| 267 | + $version_info['default_language_versions'][$language][$name] = '??'; |
|
| 268 | + } |
|
| 249 | 269 | } |
| 250 | 270 | } |
| 251 | 271 | $this_dir->close(); |
@@ -260,8 +280,9 @@ discard block |
||
| 260 | 280 | ksort($version_info['tasks_versions']); |
| 261 | 281 | |
| 262 | 282 | // For languages sort each language too. |
| 263 | - foreach ($version_info['default_language_versions'] as $language => $dummy) |
|
| 264 | - ksort($version_info['default_language_versions'][$language]); |
|
| 283 | + foreach ($version_info['default_language_versions'] as $language => $dummy) { |
|
| 284 | + ksort($version_info['default_language_versions'][$language]); |
|
| 285 | + } |
|
| 265 | 286 | } |
| 266 | 287 | return $version_info; |
| 267 | 288 | } |
@@ -303,27 +324,31 @@ discard block |
||
| 303 | 324 | $settingsArray = trim(file_get_contents($boarddir . '/Settings.php')); |
| 304 | 325 | |
| 305 | 326 | // Break it up based on \r or \n, and then clean out extra characters. |
| 306 | - if (strpos($settingsArray, "\n") !== false) |
|
| 307 | - $settingsArray = explode("\n", $settingsArray); |
|
| 308 | - elseif (strpos($settingsArray, "\r") !== false) |
|
| 309 | - $settingsArray = explode("\r", $settingsArray); |
|
| 310 | - else |
|
| 311 | - return; |
|
| 327 | + if (strpos($settingsArray, "\n") !== false) { |
|
| 328 | + $settingsArray = explode("\n", $settingsArray); |
|
| 329 | + } elseif (strpos($settingsArray, "\r") !== false) { |
|
| 330 | + $settingsArray = explode("\r", $settingsArray); |
|
| 331 | + } else { |
|
| 332 | + return; |
|
| 333 | + } |
|
| 312 | 334 | |
| 313 | 335 | // Presumably, the file has to have stuff in it for this function to be called :P. |
| 314 | - if (count($settingsArray) < 10) |
|
| 315 | - return; |
|
| 336 | + if (count($settingsArray) < 10) { |
|
| 337 | + return; |
|
| 338 | + } |
|
| 316 | 339 | |
| 317 | 340 | // remove any /r's that made there way in here |
| 318 | - foreach ($settingsArray as $k => $dummy) |
|
| 319 | - $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
| 341 | + foreach ($settingsArray as $k => $dummy) { |
|
| 342 | + $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
| 343 | + } |
|
| 320 | 344 | |
| 321 | 345 | // go line by line and see whats changing |
| 322 | 346 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
| 323 | 347 | { |
| 324 | 348 | // Don't trim or bother with it if it's not a variable. |
| 325 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
| 326 | - continue; |
|
| 349 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
| 350 | + continue; |
|
| 351 | + } |
|
| 327 | 352 | |
| 328 | 353 | $settingsArray[$i] = trim($settingsArray[$i]) . "\n"; |
| 329 | 354 | |
@@ -335,8 +360,7 @@ discard block |
||
| 335 | 360 | { |
| 336 | 361 | updateDbLastError($val); |
| 337 | 362 | unset($config_vars[$var]); |
| 338 | - } |
|
| 339 | - elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 363 | + } elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 340 | 364 | { |
| 341 | 365 | $comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#'); |
| 342 | 366 | $settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n"; |
@@ -347,34 +371,39 @@ discard block |
||
| 347 | 371 | } |
| 348 | 372 | |
| 349 | 373 | // End of the file ... maybe |
| 350 | - if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') |
|
| 351 | - $end = $i; |
|
| 374 | + if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') { |
|
| 375 | + $end = $i; |
|
| 376 | + } |
|
| 352 | 377 | } |
| 353 | 378 | |
| 354 | 379 | // This should never happen, but apparently it is happening. |
| 355 | - if (empty($end) || $end < 10) |
|
| 356 | - $end = count($settingsArray) - 1; |
|
| 380 | + if (empty($end) || $end < 10) { |
|
| 381 | + $end = count($settingsArray) - 1; |
|
| 382 | + } |
|
| 357 | 383 | |
| 358 | 384 | // Still more variables to go? Then lets add them at the end. |
| 359 | 385 | if (!empty($config_vars)) |
| 360 | 386 | { |
| 361 | - if (trim($settingsArray[$end]) == '?' . '>') |
|
| 362 | - $settingsArray[$end++] = ''; |
|
| 363 | - else |
|
| 364 | - $end++; |
|
| 387 | + if (trim($settingsArray[$end]) == '?' . '>') { |
|
| 388 | + $settingsArray[$end++] = ''; |
|
| 389 | + } else { |
|
| 390 | + $end++; |
|
| 391 | + } |
|
| 365 | 392 | |
| 366 | 393 | // Add in any newly defined vars that were passed |
| 367 | - foreach ($config_vars as $var => $val) |
|
| 368 | - $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
| 394 | + foreach ($config_vars as $var => $val) { |
|
| 395 | + $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
| 396 | + } |
|
| 369 | 397 | |
| 370 | 398 | $settingsArray[$end] = '?' . '>'; |
| 399 | + } else { |
|
| 400 | + $settingsArray[$end] = trim($settingsArray[$end]); |
|
| 371 | 401 | } |
| 372 | - else |
|
| 373 | - $settingsArray[$end] = trim($settingsArray[$end]); |
|
| 374 | 402 | |
| 375 | 403 | // Sanity error checking: the file needs to be at least 12 lines. |
| 376 | - if (count($settingsArray) < 12) |
|
| 377 | - return; |
|
| 404 | + if (count($settingsArray) < 12) { |
|
| 405 | + return; |
|
| 406 | + } |
|
| 378 | 407 | |
| 379 | 408 | // Try to avoid a few pitfalls: |
| 380 | 409 | // - like a possible race condition, |
@@ -382,8 +411,9 @@ discard block |
||
| 382 | 411 | // |
| 383 | 412 | // Check before you act: if cache is enabled, we can do a simple write test |
| 384 | 413 | // to validate that we even write things on this filesystem. |
| 385 | - if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 386 | - $cachedir = $boarddir . '/cache'; |
|
| 414 | + if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 415 | + $cachedir = $boarddir . '/cache'; |
|
| 416 | + } |
|
| 387 | 417 | |
| 388 | 418 | $test_fp = @fopen($cachedir . '/settings_update.tmp', "w+"); |
| 389 | 419 | if ($test_fp) |
@@ -418,16 +448,18 @@ discard block |
||
| 418 | 448 | // Well this is not good at all, lets see if we can save this |
| 419 | 449 | $context['settings_message'] = 'settings_error'; |
| 420 | 450 | |
| 421 | - if (file_exists($boarddir . '/Settings_bak.php')) |
|
| 422 | - @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
| 451 | + if (file_exists($boarddir . '/Settings_bak.php')) { |
|
| 452 | + @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
| 453 | + } |
|
| 423 | 454 | } |
| 424 | 455 | } |
| 425 | 456 | |
| 426 | 457 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
| 427 | 458 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
| 428 | - if (function_exists('opcache_invalidate')) |
|
| 429 | - opcache_invalidate($boarddir . '/Settings.php', true); |
|
| 430 | -} |
|
| 459 | + if (function_exists('opcache_invalidate')) { |
|
| 460 | + opcache_invalidate($boarddir . '/Settings.php', true); |
|
| 461 | + } |
|
| 462 | + } |
|
| 431 | 463 | |
| 432 | 464 | /** |
| 433 | 465 | * Saves the time of the last db error for the error log |
@@ -453,8 +485,9 @@ discard block |
||
| 453 | 485 | global $options, $context, $smcFunc, $settings, $user_info; |
| 454 | 486 | |
| 455 | 487 | // This must exist! |
| 456 | - if (!isset($context['admin_preferences'])) |
|
| 457 | - return false; |
|
| 488 | + if (!isset($context['admin_preferences'])) { |
|
| 489 | + return false; |
|
| 490 | + } |
|
| 458 | 491 | |
| 459 | 492 | // This is what we'll be saving. |
| 460 | 493 | $options['admin_preferences'] = $smcFunc['json_encode']($context['admin_preferences']); |
@@ -518,8 +551,9 @@ discard block |
||
| 518 | 551 | $emails_sent = array(); |
| 519 | 552 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 520 | 553 | { |
| 521 | - if (empty($prefs[$row['id_member']]['announcements'])) |
|
| 522 | - continue; |
|
| 554 | + if (empty($prefs[$row['id_member']]['announcements'])) { |
|
| 555 | + continue; |
|
| 556 | + } |
|
| 523 | 557 | |
| 524 | 558 | // Stick their particulars in the replacement data. |
| 525 | 559 | $replacements['IDMEMBER'] = $row['id_member']; |
@@ -538,11 +572,12 @@ discard block |
||
| 538 | 572 | $smcFunc['db_free_result']($request); |
| 539 | 573 | |
| 540 | 574 | // Any additional users we must email this to? |
| 541 | - if (!empty($additional_recipients)) |
|
| 542 | - foreach ($additional_recipients as $recipient) |
|
| 575 | + if (!empty($additional_recipients)) { |
|
| 576 | + foreach ($additional_recipients as $recipient) |
|
| 543 | 577 | { |
| 544 | 578 | if (in_array($recipient['email'], $emails_sent)) |
| 545 | 579 | continue; |
| 580 | + } |
|
| 546 | 581 | |
| 547 | 582 | $replacements['IDMEMBER'] = $recipient['id']; |
| 548 | 583 | $replacements['REALNAME'] = $recipient['name']; |
@@ -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', |
@@ -61,9 +62,11 @@ discard block |
||
| 61 | 62 | 'db_ping' => 'mysqli_ping', |
| 62 | 63 | 'db_fetch_all' => 'smf_db_fetch_all', |
| 63 | 64 | ); |
| 65 | + } |
|
| 64 | 66 | |
| 65 | - if (!empty($db_options['persist'])) |
|
| 66 | - $db_server = 'p:' . $db_server; |
|
| 67 | + if (!empty($db_options['persist'])) { |
|
| 68 | + $db_server = 'p:' . $db_server; |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | $connection = mysqli_init(); |
| 69 | 72 | |
@@ -72,24 +75,27 @@ discard block |
||
| 72 | 75 | $success = false; |
| 73 | 76 | |
| 74 | 77 | if ($connection) { |
| 75 | - if (!empty($db_options['port'])) |
|
| 76 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
| 77 | - else |
|
| 78 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
| 78 | + if (!empty($db_options['port'])) { |
|
| 79 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
| 80 | + } else { |
|
| 81 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
| 82 | + } |
|
| 79 | 83 | } |
| 80 | 84 | |
| 81 | 85 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 82 | 86 | if ($success === false) |
| 83 | 87 | { |
| 84 | - if (!empty($db_options['non_fatal'])) |
|
| 85 | - return null; |
|
| 86 | - else |
|
| 87 | - display_db_error(); |
|
| 88 | + if (!empty($db_options['non_fatal'])) { |
|
| 89 | + return null; |
|
| 90 | + } else { |
|
| 91 | + display_db_error(); |
|
| 92 | + } |
|
| 88 | 93 | } |
| 89 | 94 | |
| 90 | 95 | // Select the database, unless told not to |
| 91 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
| 92 | - display_db_error(); |
|
| 96 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
| 97 | + display_db_error(); |
|
| 98 | + } |
|
| 93 | 99 | |
| 94 | 100 | $smcFunc['db_query']('', '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\'', |
| 95 | 101 | array(), |
@@ -165,34 +171,42 @@ discard block |
||
| 165 | 171 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
| 166 | 172 | |
| 167 | 173 | list ($values, $connection) = $db_callback; |
| 168 | - if (!is_object($connection)) |
|
| 169 | - display_db_error(); |
|
| 174 | + if (!is_object($connection)) { |
|
| 175 | + display_db_error(); |
|
| 176 | + } |
|
| 170 | 177 | |
| 171 | - if ($matches[1] === 'db_prefix') |
|
| 172 | - return $db_prefix; |
|
| 178 | + if ($matches[1] === 'db_prefix') { |
|
| 179 | + return $db_prefix; |
|
| 180 | + } |
|
| 173 | 181 | |
| 174 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
| 175 | - return $user_info[$matches[1]]; |
|
| 182 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
| 183 | + return $user_info[$matches[1]]; |
|
| 184 | + } |
|
| 176 | 185 | |
| 177 | - if ($matches[1] === 'empty') |
|
| 178 | - return '\'\''; |
|
| 186 | + if ($matches[1] === 'empty') { |
|
| 187 | + return '\'\''; |
|
| 188 | + } |
|
| 179 | 189 | |
| 180 | - if (!isset($matches[2])) |
|
| 181 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 190 | + if (!isset($matches[2])) { |
|
| 191 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 192 | + } |
|
| 182 | 193 | |
| 183 | - if ($matches[1] === 'literal') |
|
| 184 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 194 | + if ($matches[1] === 'literal') { |
|
| 195 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 196 | + } |
|
| 185 | 197 | |
| 186 | - if (!isset($values[$matches[2]])) |
|
| 187 | - 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__); |
|
| 198 | + if (!isset($values[$matches[2]])) { |
|
| 199 | + 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__); |
|
| 200 | + } |
|
| 188 | 201 | |
| 189 | 202 | $replacement = $values[$matches[2]]; |
| 190 | 203 | |
| 191 | 204 | switch ($matches[1]) |
| 192 | 205 | { |
| 193 | 206 | case 'int': |
| 194 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 195 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 207 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 208 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 209 | + } |
|
| 196 | 210 | return (string) (int) $replacement; |
| 197 | 211 | break; |
| 198 | 212 | |
@@ -204,65 +218,73 @@ discard block |
||
| 204 | 218 | case 'array_int': |
| 205 | 219 | if (is_array($replacement)) |
| 206 | 220 | { |
| 207 | - if (empty($replacement)) |
|
| 208 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | + if (empty($replacement)) { |
|
| 222 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 223 | + } |
|
| 209 | 224 | |
| 210 | 225 | foreach ($replacement as $key => $value) |
| 211 | 226 | { |
| 212 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 213 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 227 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 228 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 229 | + } |
|
| 214 | 230 | |
| 215 | 231 | $replacement[$key] = (string) (int) $value; |
| 216 | 232 | } |
| 217 | 233 | |
| 218 | 234 | return implode(', ', $replacement); |
| 235 | + } else { |
|
| 236 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 219 | 237 | } |
| 220 | - else |
|
| 221 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 222 | 238 | |
| 223 | 239 | break; |
| 224 | 240 | |
| 225 | 241 | case 'array_string': |
| 226 | 242 | if (is_array($replacement)) |
| 227 | 243 | { |
| 228 | - if (empty($replacement)) |
|
| 229 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 244 | + if (empty($replacement)) { |
|
| 245 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 246 | + } |
|
| 230 | 247 | |
| 231 | - foreach ($replacement as $key => $value) |
|
| 232 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 248 | + foreach ($replacement as $key => $value) { |
|
| 249 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 250 | + } |
|
| 233 | 251 | |
| 234 | 252 | return implode(', ', $replacement); |
| 253 | + } else { |
|
| 254 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 235 | 255 | } |
| 236 | - else |
|
| 237 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 238 | 256 | break; |
| 239 | 257 | |
| 240 | 258 | case 'date': |
| 241 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 242 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 243 | - else |
|
| 244 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 259 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 260 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 261 | + } else { |
|
| 262 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 263 | + } |
|
| 245 | 264 | break; |
| 246 | 265 | |
| 247 | 266 | case 'time': |
| 248 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 249 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 250 | - else |
|
| 251 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 267 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 268 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 269 | + } else { |
|
| 270 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 271 | + } |
|
| 252 | 272 | break; |
| 253 | 273 | |
| 254 | 274 | case 'datetime': |
| 255 | - 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) |
|
| 256 | - return 'str_to_date('. |
|
| 275 | + 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) { |
|
| 276 | + return 'str_to_date('. |
|
| 257 | 277 | 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]). |
| 258 | 278 | ',\'%Y-%m-%d %h:%i:%s\')'; |
| 259 | - else |
|
| 260 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 279 | + } else { |
|
| 280 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 281 | + } |
|
| 261 | 282 | break; |
| 262 | 283 | |
| 263 | 284 | case 'float': |
| 264 | - if (!is_numeric($replacement)) |
|
| 265 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 285 | + if (!is_numeric($replacement)) { |
|
| 286 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 287 | + } |
|
| 266 | 288 | return (string) (float) $replacement; |
| 267 | 289 | break; |
| 268 | 290 | |
@@ -276,32 +298,37 @@ discard block |
||
| 276 | 298 | break; |
| 277 | 299 | |
| 278 | 300 | case 'inet': |
| 279 | - if ($replacement == 'null' || $replacement == '') |
|
| 280 | - return 'null'; |
|
| 281 | - if (!isValidIP($replacement)) |
|
| 282 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 301 | + if ($replacement == 'null' || $replacement == '') { |
|
| 302 | + return 'null'; |
|
| 303 | + } |
|
| 304 | + if (!isValidIP($replacement)) { |
|
| 305 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 306 | + } |
|
| 283 | 307 | //we don't use the native support of mysql > 5.6.2 |
| 284 | 308 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 285 | 309 | |
| 286 | 310 | case 'array_inet': |
| 287 | 311 | if (is_array($replacement)) |
| 288 | 312 | { |
| 289 | - if (empty($replacement)) |
|
| 290 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 313 | + if (empty($replacement)) { |
|
| 314 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 315 | + } |
|
| 291 | 316 | |
| 292 | 317 | foreach ($replacement as $key => $value) |
| 293 | 318 | { |
| 294 | - if ($replacement == 'null' || $replacement == '') |
|
| 295 | - $replacement[$key] = 'null'; |
|
| 296 | - if (!isValidIP($value)) |
|
| 297 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 319 | + if ($replacement == 'null' || $replacement == '') { |
|
| 320 | + $replacement[$key] = 'null'; |
|
| 321 | + } |
|
| 322 | + if (!isValidIP($value)) { |
|
| 323 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 324 | + } |
|
| 298 | 325 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 299 | 326 | } |
| 300 | 327 | |
| 301 | 328 | return implode(', ', $replacement); |
| 329 | + } else { |
|
| 330 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 302 | 331 | } |
| 303 | - else |
|
| 304 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 305 | 332 | break; |
| 306 | 333 | |
| 307 | 334 | default: |
@@ -377,22 +404,25 @@ discard block |
||
| 377 | 404 | // Are we in SSI mode? If so try that username and password first |
| 378 | 405 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 379 | 406 | { |
| 380 | - if (empty($db_persist)) |
|
| 381 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 382 | - else |
|
| 383 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 407 | + if (empty($db_persist)) { |
|
| 408 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 409 | + } else { |
|
| 410 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 411 | + } |
|
| 384 | 412 | } |
| 385 | 413 | // Fall back to the regular username and password if need be |
| 386 | 414 | if (!$db_connection) |
| 387 | 415 | { |
| 388 | - if (empty($db_persist)) |
|
| 389 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 390 | - else |
|
| 391 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 416 | + if (empty($db_persist)) { |
|
| 417 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 418 | + } else { |
|
| 419 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 420 | + } |
|
| 392 | 421 | } |
| 393 | 422 | |
| 394 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 395 | - $db_connection = false; |
|
| 423 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 424 | + $db_connection = false; |
|
| 425 | + } |
|
| 396 | 426 | |
| 397 | 427 | $connection = $db_connection; |
| 398 | 428 | } |
@@ -400,18 +430,20 @@ discard block |
||
| 400 | 430 | // One more query.... |
| 401 | 431 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 402 | 432 | |
| 403 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 404 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 433 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 434 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 435 | + } |
|
| 405 | 436 | |
| 406 | 437 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 407 | 438 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 408 | 439 | { |
| 409 | 440 | // Add before LIMIT |
| 410 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 411 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 412 | - else |
|
| 413 | - // Append it. |
|
| 441 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 442 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 443 | + } else { |
|
| 444 | + // Append it. |
|
| 414 | 445 | $db_string .= "\n\t\t\tORDER BY null"; |
| 446 | + } |
|
| 415 | 447 | } |
| 416 | 448 | |
| 417 | 449 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -433,8 +465,9 @@ discard block |
||
| 433 | 465 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 434 | 466 | |
| 435 | 467 | // Initialize $db_cache if not already initialized. |
| 436 | - if (!isset($db_cache)) |
|
| 437 | - $db_cache = array(); |
|
| 468 | + if (!isset($db_cache)) { |
|
| 469 | + $db_cache = array(); |
|
| 470 | + } |
|
| 438 | 471 | |
| 439 | 472 | if (!empty($_SESSION['debug_redirect'])) |
| 440 | 473 | { |
@@ -460,17 +493,18 @@ discard block |
||
| 460 | 493 | while (true) |
| 461 | 494 | { |
| 462 | 495 | $pos = strpos($db_string, '\'', $pos + 1); |
| 463 | - if ($pos === false) |
|
| 464 | - break; |
|
| 496 | + if ($pos === false) { |
|
| 497 | + break; |
|
| 498 | + } |
|
| 465 | 499 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 466 | 500 | |
| 467 | 501 | while (true) |
| 468 | 502 | { |
| 469 | 503 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 470 | 504 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 471 | - if ($pos1 === false) |
|
| 472 | - break; |
|
| 473 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 505 | + if ($pos1 === false) { |
|
| 506 | + break; |
|
| 507 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 474 | 508 | { |
| 475 | 509 | $pos = $pos1; |
| 476 | 510 | break; |
@@ -486,29 +520,35 @@ discard block |
||
| 486 | 520 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 487 | 521 | |
| 488 | 522 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 489 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 490 | - $fail = true; |
|
| 523 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 524 | + $fail = true; |
|
| 525 | + } |
|
| 491 | 526 | // Trying to change passwords, slow us down, or something? |
| 492 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 493 | - $fail = true; |
|
| 494 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 495 | - $fail = true; |
|
| 527 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 528 | + $fail = true; |
|
| 529 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 530 | + $fail = true; |
|
| 531 | + } |
|
| 496 | 532 | |
| 497 | - if (!empty($fail) && function_exists('log_error')) |
|
| 498 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 533 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 534 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 535 | + } |
|
| 499 | 536 | } |
| 500 | 537 | |
| 501 | - if (empty($db_unbuffered)) |
|
| 502 | - $ret = @mysqli_query($connection, $db_string); |
|
| 503 | - else |
|
| 504 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 538 | + if (empty($db_unbuffered)) { |
|
| 539 | + $ret = @mysqli_query($connection, $db_string); |
|
| 540 | + } else { |
|
| 541 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 542 | + } |
|
| 505 | 543 | |
| 506 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 507 | - $ret = smf_db_error($db_string, $connection); |
|
| 544 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 545 | + $ret = smf_db_error($db_string, $connection); |
|
| 546 | + } |
|
| 508 | 547 | |
| 509 | 548 | // Debugging. |
| 510 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 511 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 549 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 550 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 551 | + } |
|
| 512 | 552 | |
| 513 | 553 | return $ret; |
| 514 | 554 | } |
@@ -555,12 +595,13 @@ discard block |
||
| 555 | 595 | // Decide which connection to use |
| 556 | 596 | $connection = $connection === null ? $db_connection : $connection; |
| 557 | 597 | |
| 558 | - if ($type == 'begin') |
|
| 559 | - return @mysqli_query($connection, 'BEGIN'); |
|
| 560 | - elseif ($type == 'rollback') |
|
| 561 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
| 562 | - elseif ($type == 'commit') |
|
| 563 | - return @mysqli_query($connection, 'COMMIT'); |
|
| 598 | + if ($type == 'begin') { |
|
| 599 | + return @mysqli_query($connection, 'BEGIN'); |
|
| 600 | + } elseif ($type == 'rollback') { |
|
| 601 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
| 602 | + } elseif ($type == 'commit') { |
|
| 603 | + return @mysqli_query($connection, 'COMMIT'); |
|
| 604 | + } |
|
| 564 | 605 | |
| 565 | 606 | return false; |
| 566 | 607 | } |
@@ -600,8 +641,9 @@ discard block |
||
| 600 | 641 | // 2013: Lost connection to server during query. |
| 601 | 642 | |
| 602 | 643 | // Log the error. |
| 603 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 604 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 644 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 645 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 646 | + } |
|
| 605 | 647 | |
| 606 | 648 | // Database error auto fixing ;). |
| 607 | 649 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -610,8 +652,9 @@ discard block |
||
| 610 | 652 | $old_cache = @$modSettings['cache_enable']; |
| 611 | 653 | $modSettings['cache_enable'] = '1'; |
| 612 | 654 | |
| 613 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 614 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 655 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 656 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 657 | + } |
|
| 615 | 658 | |
| 616 | 659 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 617 | 660 | { |
@@ -627,8 +670,9 @@ discard block |
||
| 627 | 670 | foreach ($tables as $table) |
| 628 | 671 | { |
| 629 | 672 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 630 | - if (trim($table) != '') |
|
| 631 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 673 | + if (trim($table) != '') { |
|
| 674 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 675 | + } |
|
| 632 | 676 | } |
| 633 | 677 | } |
| 634 | 678 | |
@@ -637,8 +681,9 @@ discard block |
||
| 637 | 681 | // Table crashed. Let's try to fix it. |
| 638 | 682 | elseif ($query_errno == 1016) |
| 639 | 683 | { |
| 640 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 641 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 684 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 685 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 686 | + } |
|
| 642 | 687 | } |
| 643 | 688 | // Indexes crashed. Should be easy to fix! |
| 644 | 689 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -657,13 +702,15 @@ discard block |
||
| 657 | 702 | |
| 658 | 703 | // Make a note of the REPAIR... |
| 659 | 704 | cache_put_data('db_last_error', time(), 600); |
| 660 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 661 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 705 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 706 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 707 | + } |
|
| 662 | 708 | |
| 663 | 709 | // Attempt to find and repair the broken table. |
| 664 | - foreach ($fix_tables as $table) |
|
| 665 | - $smcFunc['db_query']('', " |
|
| 710 | + foreach ($fix_tables as $table) { |
|
| 711 | + $smcFunc['db_query']('', " |
|
| 666 | 712 | REPAIR TABLE $table", false, false); |
| 713 | + } |
|
| 667 | 714 | |
| 668 | 715 | // And send off an email! |
| 669 | 716 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -672,11 +719,12 @@ discard block |
||
| 672 | 719 | |
| 673 | 720 | // Try the query again...? |
| 674 | 721 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 675 | - if ($ret !== false) |
|
| 676 | - return $ret; |
|
| 722 | + if ($ret !== false) { |
|
| 723 | + return $ret; |
|
| 724 | + } |
|
| 725 | + } else { |
|
| 726 | + $modSettings['cache_enable'] = $old_cache; |
|
| 677 | 727 | } |
| 678 | - else |
|
| 679 | - $modSettings['cache_enable'] = $old_cache; |
|
| 680 | 728 | |
| 681 | 729 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 682 | 730 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -686,22 +734,25 @@ discard block |
||
| 686 | 734 | // Are we in SSI mode? If so try that username and password first |
| 687 | 735 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 688 | 736 | { |
| 689 | - if (empty($db_persist)) |
|
| 690 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 691 | - else |
|
| 692 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 737 | + if (empty($db_persist)) { |
|
| 738 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 739 | + } else { |
|
| 740 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 741 | + } |
|
| 693 | 742 | } |
| 694 | 743 | // Fall back to the regular username and password if need be |
| 695 | 744 | if (!$db_connection) |
| 696 | 745 | { |
| 697 | - if (empty($db_persist)) |
|
| 698 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 699 | - else |
|
| 700 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 746 | + if (empty($db_persist)) { |
|
| 747 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 748 | + } else { |
|
| 749 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 750 | + } |
|
| 701 | 751 | } |
| 702 | 752 | |
| 703 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 704 | - $db_connection = false; |
|
| 753 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 754 | + $db_connection = false; |
|
| 755 | + } |
|
| 705 | 756 | } |
| 706 | 757 | |
| 707 | 758 | if ($db_connection) |
@@ -712,24 +763,27 @@ discard block |
||
| 712 | 763 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 713 | 764 | |
| 714 | 765 | $new_errno = mysqli_errno($db_connection); |
| 715 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 716 | - break; |
|
| 766 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 767 | + break; |
|
| 768 | + } |
|
| 717 | 769 | } |
| 718 | 770 | |
| 719 | 771 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 720 | - if ($ret !== false) |
|
| 721 | - return $ret; |
|
| 772 | + if ($ret !== false) { |
|
| 773 | + return $ret; |
|
| 774 | + } |
|
| 722 | 775 | } |
| 723 | 776 | } |
| 724 | 777 | // Are they out of space, perhaps? |
| 725 | 778 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 726 | 779 | { |
| 727 | - if (!isset($txt)) |
|
| 728 | - $query_error .= ' - check database storage space.'; |
|
| 729 | - else |
|
| 780 | + if (!isset($txt)) { |
|
| 781 | + $query_error .= ' - check database storage space.'; |
|
| 782 | + } else |
|
| 730 | 783 | { |
| 731 | - if (!isset($txt['mysql_error_space'])) |
|
| 732 | - loadLanguage('Errors'); |
|
| 784 | + if (!isset($txt['mysql_error_space'])) { |
|
| 785 | + loadLanguage('Errors'); |
|
| 786 | + } |
|
| 733 | 787 | |
| 734 | 788 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 735 | 789 | } |
@@ -737,15 +791,17 @@ discard block |
||
| 737 | 791 | } |
| 738 | 792 | |
| 739 | 793 | // Nothing's defined yet... just die with it. |
| 740 | - if (empty($context) || empty($txt)) |
|
| 741 | - die($query_error); |
|
| 794 | + if (empty($context) || empty($txt)) { |
|
| 795 | + die($query_error); |
|
| 796 | + } |
|
| 742 | 797 | |
| 743 | 798 | // Show an error message, if possible. |
| 744 | 799 | $context['error_title'] = $txt['database_error']; |
| 745 | - if (allowedTo('admin_forum')) |
|
| 746 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 747 | - else |
|
| 748 | - $context['error_message'] = $txt['try_again']; |
|
| 800 | + if (allowedTo('admin_forum')) { |
|
| 801 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 802 | + } else { |
|
| 803 | + $context['error_message'] = $txt['try_again']; |
|
| 804 | + } |
|
| 749 | 805 | |
| 750 | 806 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 751 | 807 | { |
@@ -777,8 +833,9 @@ discard block |
||
| 777 | 833 | $return_var = null; |
| 778 | 834 | |
| 779 | 835 | // With nothing to insert, simply return. |
| 780 | - if (empty($data)) |
|
| 781 | - return; |
|
| 836 | + if (empty($data)) { |
|
| 837 | + return; |
|
| 838 | + } |
|
| 782 | 839 | |
| 783 | 840 | // Replace the prefix holder with the actual prefix. |
| 784 | 841 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -788,23 +845,26 @@ discard block |
||
| 788 | 845 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
| 789 | 846 | { |
| 790 | 847 | $with_returning = true; |
| 791 | - if ($returnmode == 2) |
|
| 792 | - $return_var = array(); |
|
| 848 | + if ($returnmode == 2) { |
|
| 849 | + $return_var = array(); |
|
| 850 | + } |
|
| 793 | 851 | } |
| 794 | 852 | |
| 795 | 853 | // Inserting data as a single row can be done as a single array. |
| 796 | - if (!is_array($data[array_rand($data)])) |
|
| 797 | - $data = array($data); |
|
| 854 | + if (!is_array($data[array_rand($data)])) { |
|
| 855 | + $data = array($data); |
|
| 856 | + } |
|
| 798 | 857 | |
| 799 | 858 | // Create the mold for a single row insert. |
| 800 | 859 | $insertData = '('; |
| 801 | 860 | foreach ($columns as $columnName => $type) |
| 802 | 861 | { |
| 803 | 862 | // Are we restricting the length? |
| 804 | - if (strpos($type, 'string-') !== false) |
|
| 805 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 806 | - else |
|
| 807 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 863 | + if (strpos($type, 'string-') !== false) { |
|
| 864 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 865 | + } else { |
|
| 866 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 867 | + } |
|
| 808 | 868 | } |
| 809 | 869 | $insertData = substr($insertData, 0, -2) . ')'; |
| 810 | 870 | |
@@ -813,8 +873,9 @@ discard block |
||
| 813 | 873 | |
| 814 | 874 | // Here's where the variables are injected to the query. |
| 815 | 875 | $insertRows = array(); |
| 816 | - foreach ($data as $dataRow) |
|
| 817 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 876 | + foreach ($data as $dataRow) { |
|
| 877 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 878 | + } |
|
| 818 | 879 | |
| 819 | 880 | // Determine the method of insertion. |
| 820 | 881 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -833,8 +894,7 @@ discard block |
||
| 833 | 894 | ), |
| 834 | 895 | $connection |
| 835 | 896 | ); |
| 836 | - } |
|
| 837 | - else //special way for ignore method with returning |
|
| 897 | + } else //special way for ignore method with returning |
|
| 838 | 898 | { |
| 839 | 899 | $count = count($insertRows); |
| 840 | 900 | $ai = 0; |
@@ -854,19 +914,21 @@ discard block |
||
| 854 | 914 | ); |
| 855 | 915 | $new_id = $smcFunc['db_insert_id'](); |
| 856 | 916 | |
| 857 | - if ($last_id != $new_id) //the inserted value was new |
|
| 917 | + if ($last_id != $new_id) { |
|
| 918 | + //the inserted value was new |
|
| 858 | 919 | { |
| 859 | 920 | $ai = $new_id; |
| 860 | 921 | } |
| 861 | - else // the inserted value already exists we need to find the pk |
|
| 922 | + } else // the inserted value already exists we need to find the pk |
|
| 862 | 923 | { |
| 863 | 924 | $where_string = ''; |
| 864 | 925 | $count2 = count($indexed_columns); |
| 865 | 926 | for ($x = 0; $x < $count2; $x++) |
| 866 | 927 | { |
| 867 | 928 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
| 868 | - if (($x + 1) < $count2) |
|
| 869 | - $where_string += ' AND '; |
|
| 929 | + if (($x + 1) < $count2) { |
|
| 930 | + $where_string += ' AND '; |
|
| 931 | + } |
|
| 870 | 932 | } |
| 871 | 933 | |
| 872 | 934 | $request = $smcFunc['db_query']('',' |
@@ -882,25 +944,27 @@ discard block |
||
| 882 | 944 | } |
| 883 | 945 | } |
| 884 | 946 | |
| 885 | - if ($returnmode == 1) |
|
| 886 | - $return_var = $ai; |
|
| 887 | - else if ($returnmode == 2) |
|
| 888 | - $return_var[] = $ai; |
|
| 947 | + if ($returnmode == 1) { |
|
| 948 | + $return_var = $ai; |
|
| 949 | + } else if ($returnmode == 2) { |
|
| 950 | + $return_var[] = $ai; |
|
| 951 | + } |
|
| 889 | 952 | } |
| 890 | 953 | } |
| 891 | 954 | |
| 892 | 955 | |
| 893 | 956 | if ($with_returning) |
| 894 | 957 | { |
| 895 | - if ($returnmode == 1 && empty($return_var)) |
|
| 896 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 897 | - else if ($returnmode == 2 && empty($return_var)) |
|
| 958 | + if ($returnmode == 1 && empty($return_var)) { |
|
| 959 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 960 | + } else if ($returnmode == 2 && empty($return_var)) |
|
| 898 | 961 | { |
| 899 | 962 | $return_var = array(); |
| 900 | 963 | $count = count($insertRows); |
| 901 | 964 | $start = smf_db_insert_id($table, $keys[0]); |
| 902 | - for ($i = 0; $i < $count; $i++ ) |
|
| 903 | - $return_var[] = $start + $i; |
|
| 965 | + for ($i = 0; $i < $count; $i++ ) { |
|
| 966 | + $return_var[] = $start + $i; |
|
| 967 | + } |
|
| 904 | 968 | } |
| 905 | 969 | return $return_var; |
| 906 | 970 | } |
@@ -918,8 +982,9 @@ discard block |
||
| 918 | 982 | */ |
| 919 | 983 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 920 | 984 | { |
| 921 | - if (empty($log_message)) |
|
| 922 | - $log_message = $error_message; |
|
| 985 | + if (empty($log_message)) { |
|
| 986 | + $log_message = $error_message; |
|
| 987 | + } |
|
| 923 | 988 | |
| 924 | 989 | foreach (debug_backtrace() as $step) |
| 925 | 990 | { |
@@ -938,12 +1003,14 @@ discard block |
||
| 938 | 1003 | } |
| 939 | 1004 | |
| 940 | 1005 | // A special case - we want the file and line numbers for debugging. |
| 941 | - if ($error_type == 'return') |
|
| 942 | - return array($file, $line); |
|
| 1006 | + if ($error_type == 'return') { |
|
| 1007 | + return array($file, $line); |
|
| 1008 | + } |
|
| 943 | 1009 | |
| 944 | 1010 | // Is always a critical error. |
| 945 | - if (function_exists('log_error')) |
|
| 946 | - log_error($log_message, 'critical', $file, $line); |
|
| 1011 | + if (function_exists('log_error')) { |
|
| 1012 | + log_error($log_message, 'critical', $file, $line); |
|
| 1013 | + } |
|
| 947 | 1014 | |
| 948 | 1015 | if (function_exists('fatal_error')) |
| 949 | 1016 | { |
@@ -951,12 +1018,12 @@ discard block |
||
| 951 | 1018 | |
| 952 | 1019 | // Cannot continue... |
| 953 | 1020 | exit; |
| 1021 | + } elseif ($error_type) { |
|
| 1022 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 1023 | + } else { |
|
| 1024 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 1025 | + } |
|
| 954 | 1026 | } |
| 955 | - elseif ($error_type) |
|
| 956 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 957 | - else |
|
| 958 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 959 | -} |
|
| 960 | 1027 | |
| 961 | 1028 | /** |
| 962 | 1029 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -973,10 +1040,11 @@ discard block |
||
| 973 | 1040 | '\\' => '\\\\', |
| 974 | 1041 | ); |
| 975 | 1042 | |
| 976 | - if ($translate_human_wildcards) |
|
| 977 | - $replacements += array( |
|
| 1043 | + if ($translate_human_wildcards) { |
|
| 1044 | + $replacements += array( |
|
| 978 | 1045 | '*' => '%', |
| 979 | 1046 | ); |
| 1047 | + } |
|
| 980 | 1048 | |
| 981 | 1049 | return strtr($string, $replacements); |
| 982 | 1050 | } |
@@ -990,8 +1058,9 @@ discard block |
||
| 990 | 1058 | */ |
| 991 | 1059 | function smf_is_resource($result) |
| 992 | 1060 | { |
| 993 | - if ($result instanceof mysqli_result) |
|
| 994 | - return true; |
|
| 1061 | + if ($result instanceof mysqli_result) { |
|
| 1062 | + return true; |
|
| 1063 | + } |
|
| 995 | 1064 | |
| 996 | 1065 | return false; |
| 997 | 1066 | } |
@@ -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 | * Retrieve a list and several other statistics of the users currently online. |
@@ -45,8 +46,9 @@ discard block |
||
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | // Not allowed sort method? Bang! Error! |
| 48 | - elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) |
|
| 49 | - trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE); |
|
| 49 | + elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) { |
|
| 50 | + trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE); |
|
| 51 | + } |
|
| 50 | 52 | |
| 51 | 53 | // Initialize the array that'll be returned later on. |
| 52 | 54 | $membersOnlineStats = array( |
@@ -63,8 +65,9 @@ discard block |
||
| 63 | 65 | // Get any spiders if enabled. |
| 64 | 66 | $spiders = array(); |
| 65 | 67 | $spider_finds = array(); |
| 66 | - if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) |
|
| 67 | - $spiders = $smcFunc['json_decode']($modSettings['spider_name_cache'], true); |
|
| 68 | + if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) { |
|
| 69 | + $spiders = $smcFunc['json_decode']($modSettings['spider_name_cache'], true); |
|
| 70 | + } |
|
| 68 | 71 | |
| 69 | 72 | // Load the users online right now. |
| 70 | 73 | $request = $smcFunc['db_query']('', ' |
@@ -92,9 +95,7 @@ discard block |
||
| 92 | 95 | $membersOnlineStats['num_guests']++; |
| 93 | 96 | |
| 94 | 97 | continue; |
| 95 | - } |
|
| 96 | - |
|
| 97 | - elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden'])) |
|
| 98 | + } elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden'])) |
|
| 98 | 99 | { |
| 99 | 100 | // Just increase the stats and don't add this hidden user to any list. |
| 100 | 101 | $membersOnlineStats['num_users_hidden']++; |
@@ -102,10 +103,11 @@ discard block |
||
| 102 | 103 | } |
| 103 | 104 | |
| 104 | 105 | // Some basic color coding... |
| 105 | - if (!empty($row['online_color'])) |
|
| 106 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 107 | - else |
|
| 108 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 106 | + if (!empty($row['online_color'])) { |
|
| 107 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 108 | + } else { |
|
| 109 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 110 | + } |
|
| 109 | 111 | |
| 110 | 112 | // Buddies get counted and highlighted. |
| 111 | 113 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
@@ -132,12 +134,13 @@ discard block |
||
| 132 | 134 | $membersOnlineStats['list_users_online'][$row[$membersOnlineOptions['sort']] . '_' . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
| 133 | 135 | |
| 134 | 136 | // Store all distinct (primary) membergroups that are shown. |
| 135 | - if (!isset($membersOnlineStats['online_groups'][$row['id_group']])) |
|
| 136 | - $membersOnlineStats['online_groups'][$row['id_group']] = array( |
|
| 137 | + if (!isset($membersOnlineStats['online_groups'][$row['id_group']])) { |
|
| 138 | + $membersOnlineStats['online_groups'][$row['id_group']] = array( |
|
| 137 | 139 | 'id' => $row['id_group'], |
| 138 | 140 | 'name' => $row['group_name'], |
| 139 | 141 | 'color' => $row['online_color'] |
| 140 | 142 | ); |
| 143 | + } |
|
| 141 | 144 | } |
| 142 | 145 | $smcFunc['db_free_result']($request); |
| 143 | 146 | |
@@ -198,11 +201,12 @@ discard block |
||
| 198 | 201 | $settingsToUpdate = array(); |
| 199 | 202 | |
| 200 | 203 | // More members on now than ever were? Update it! |
| 201 | - if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline']) |
|
| 202 | - $settingsToUpdate = array( |
|
| 204 | + if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline']) { |
|
| 205 | + $settingsToUpdate = array( |
|
| 203 | 206 | 'mostOnline' => $total_users_online, |
| 204 | 207 | 'mostDate' => time() |
| 205 | 208 | ); |
| 209 | + } |
|
| 206 | 210 | |
| 207 | 211 | $date = strftime('%Y-%m-%d', forum_time(false)); |
| 208 | 212 | |
@@ -234,8 +238,9 @@ discard block |
||
| 234 | 238 | { |
| 235 | 239 | list ($modSettings['mostOnlineToday']) = $smcFunc['db_fetch_row']($request); |
| 236 | 240 | |
| 237 | - if ($total_users_online > $modSettings['mostOnlineToday']) |
|
| 238 | - trackStats(array('most_on' => $total_users_online)); |
|
| 241 | + if ($total_users_online > $modSettings['mostOnlineToday']) { |
|
| 242 | + trackStats(array('most_on' => $total_users_online)); |
|
| 243 | + } |
|
| 239 | 244 | |
| 240 | 245 | $total_users_online = max($total_users_online, $modSettings['mostOnlineToday']); |
| 241 | 246 | } |
@@ -252,8 +257,9 @@ discard block |
||
| 252 | 257 | $settingsToUpdate['mostOnlineToday'] = $total_users_online; |
| 253 | 258 | } |
| 254 | 259 | |
| 255 | - if (!empty($settingsToUpdate)) |
|
| 256 | - updateSettings($settingsToUpdate); |
|
| 257 | -} |
|
| 260 | + if (!empty($settingsToUpdate)) { |
|
| 261 | + updateSettings($settingsToUpdate); |
|
| 262 | + } |
|
| 263 | + } |
|
| 258 | 264 | |
| 259 | 265 | ?> |
| 260 | 266 | \ No newline at end of file |