| Conditions | 114 |
| Paths | 0 |
| Total Lines | 578 |
| Code Lines | 290 |
| Lines | 49 |
| Ratio | 8.48 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 624 | function EditMembergroup() |
||
| 625 | { |
||
| 626 | global $context, $txt, $sourcedir, $modSettings, $smcFunc, $settings; |
||
| 627 | |||
| 628 | $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0; |
||
| 629 | |||
| 630 | if (!empty($modSettings['deny_boards_access'])) |
||
| 631 | loadLanguage('ManagePermissions'); |
||
| 632 | |||
| 633 | // Make sure this group is editable. |
||
| 634 | if (!empty($_REQUEST['group'])) |
||
| 635 | { |
||
| 636 | $request = $smcFunc['db_query']('', ' |
||
| 637 | SELECT id_group |
||
| 638 | FROM {db_prefix}membergroups |
||
| 639 | WHERE id_group = {int:current_group}' . (allowedTo('admin_forum') ? '' : ' |
||
| 640 | AND group_type != {int:is_protected}') . ' |
||
| 641 | LIMIT {int:limit}', |
||
| 642 | array( |
||
| 643 | 'current_group' => $_REQUEST['group'], |
||
| 644 | 'is_protected' => 1, |
||
| 645 | 'limit' => 1, |
||
| 646 | ) |
||
| 647 | ); |
||
| 648 | list ($_REQUEST['group']) = $smcFunc['db_fetch_row']($request); |
||
| 649 | $smcFunc['db_free_result']($request); |
||
| 650 | } |
||
| 651 | |||
| 652 | // Now, do we have a valid id? |
||
| 653 | if (empty($_REQUEST['group'])) |
||
| 654 | fatal_lang_error('membergroup_does_not_exist', false); |
||
| 655 | |||
| 656 | // People who can manage boards are a bit special. |
||
| 657 | require_once($sourcedir . '/Subs-Members.php'); |
||
| 658 | $board_managers = groupsAllowedTo('manage_boards', null); |
||
| 659 | $context['can_manage_boards'] = in_array($_REQUEST['group'], $board_managers['allowed']); |
||
| 660 | |||
| 661 | // Can this group moderate any boards? |
||
| 662 | $request = $smcFunc['db_query']('', ' |
||
| 663 | SELECT COUNT(id_board) |
||
| 664 | FROM {db_prefix}moderator_groups |
||
| 665 | WHERE id_group = {int:current_group}', |
||
| 666 | array( |
||
| 667 | 'current_group' => $_REQUEST['group'], |
||
| 668 | ) |
||
| 669 | ); |
||
| 670 | |||
| 671 | // Why don't we have a $smcFunc['db_result'] function? |
||
| 672 | $result = $smcFunc['db_fetch_row']($request); |
||
| 673 | $context['is_moderator_group'] = ($result[0] > 0); |
||
| 674 | $smcFunc['db_free_result']($request); |
||
| 675 | |||
| 676 | // The delete this membergroup button was pressed. |
||
| 677 | if (isset($_POST['delete'])) |
||
| 678 | { |
||
| 679 | checkSession(); |
||
| 680 | validateToken('admin-mmg'); |
||
| 681 | |||
| 682 | require_once($sourcedir . '/Subs-Membergroups.php'); |
||
| 683 | $result = deleteMembergroups($_REQUEST['group']); |
||
| 684 | // 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); |
||
| 687 | |||
| 688 | redirectexit('action=admin;area=membergroups;'); |
||
| 689 | } |
||
| 690 | // A form was submitted with the new membergroup settings. |
||
| 691 | elseif (isset($_POST['save'])) |
||
| 692 | { |
||
| 693 | // Validate the session. |
||
| 694 | checkSession(); |
||
| 695 | validateToken('admin-mmg'); |
||
| 696 | |||
| 697 | // Can they really inherit from this group? |
||
| 698 | if ($_REQUEST['group'] > 1 && $_REQUEST['group'] != 3 && isset($_POST['group_inherit']) && $_POST['group_inherit'] != -2 && !allowedTo('admin_forum')) |
||
| 699 | { |
||
| 700 | $request = $smcFunc['db_query']('', ' |
||
| 701 | SELECT group_type |
||
| 702 | FROM {db_prefix}membergroups |
||
| 703 | WHERE id_group = {int:inherit_from} |
||
| 704 | LIMIT {int:limit}', |
||
| 705 | array( |
||
| 706 | 'inherit_from' => $_POST['group_inherit'], |
||
| 707 | 'limit' => 1, |
||
| 708 | ) |
||
| 709 | ); |
||
| 710 | list ($inherit_type) = $smcFunc['db_fetch_row']($request); |
||
| 711 | $smcFunc['db_free_result']($request); |
||
| 712 | } |
||
| 713 | |||
| 714 | // Set variables to their proper value. |
||
| 715 | $_POST['max_messages'] = isset($_POST['max_messages']) ? (int) $_POST['max_messages'] : 0; |
||
| 716 | $_POST['min_posts'] = isset($_POST['min_posts']) && isset($_POST['group_type']) && $_POST['group_type'] == -1 && $_REQUEST['group'] > 3 ? abs($_POST['min_posts']) : ($_REQUEST['group'] == 4 ? 0 : -1); |
||
| 717 | $_POST['icons'] = (empty($_POST['icon_count']) || $_POST['icon_count'] < 0) ? '' : min((int) $_POST['icon_count'], 99) . '#' . $_POST['icon_image']; |
||
| 718 | $_POST['group_desc'] = isset($_POST['group_desc']) && ($_REQUEST['group'] == 1 || (isset($_POST['group_type']) && $_POST['group_type'] != -1)) ? trim($_POST['group_desc']) : ''; |
||
| 719 | $_POST['group_type'] = !isset($_POST['group_type']) || $_POST['group_type'] < 0 || $_POST['group_type'] > 3 || ($_POST['group_type'] == 1 && !allowedTo('admin_forum')) ? 0 : (int) $_POST['group_type']; |
||
| 720 | $_POST['group_hidden'] = empty($_POST['group_hidden']) || $_POST['min_posts'] != -1 || $_REQUEST['group'] == 3 ? 0 : (int) $_POST['group_hidden']; |
||
| 721 | $_POST['group_inherit'] = $_REQUEST['group'] > 1 && $_REQUEST['group'] != 3 && (empty($inherit_type) || $inherit_type != 1) ? (int) $_POST['group_inherit'] : -2; |
||
| 722 | $_POST['group_tfa_force'] = (empty($modSettings['tfa_mode']) || $modSettings['tfa_mode'] != 2 || empty($_POST['group_tfa_force'])) ? 0 : 1; |
||
| 723 | |||
| 724 | //@todo Don't set online_color for the Moderators group? |
||
| 725 | |||
| 726 | // Do the update of the membergroup settings. |
||
| 727 | $smcFunc['db_query']('', ' |
||
| 728 | UPDATE {db_prefix}membergroups |
||
| 729 | SET group_name = {string:group_name}, online_color = {string:online_color}, |
||
| 730 | max_messages = {int:max_messages}, min_posts = {int:min_posts}, icons = {string:icons}, |
||
| 731 | description = {string:group_desc}, group_type = {int:group_type}, hidden = {int:group_hidden}, |
||
| 732 | id_parent = {int:group_inherit}, tfa_required = {int:tfa_required} |
||
| 733 | WHERE id_group = {int:current_group}', |
||
| 734 | array( |
||
| 735 | 'max_messages' => $_POST['max_messages'], |
||
| 736 | 'min_posts' => $_POST['min_posts'], |
||
| 737 | 'group_type' => $_POST['group_type'], |
||
| 738 | 'group_hidden' => $_POST['group_hidden'], |
||
| 739 | 'group_inherit' => $_POST['group_inherit'], |
||
| 740 | 'current_group' => (int) $_REQUEST['group'], |
||
| 741 | 'group_name' => $smcFunc['htmlspecialchars']($_POST['group_name']), |
||
| 742 | 'online_color' => $_POST['online_color'], |
||
| 743 | 'icons' => $_POST['icons'], |
||
| 744 | 'group_desc' => $_POST['group_desc'], |
||
| 745 | 'tfa_required' => $_POST['group_tfa_force'], |
||
| 746 | ) |
||
| 747 | ); |
||
| 748 | |||
| 749 | call_integration_hook('integrate_save_membergroup', array((int) $_REQUEST['group'])); |
||
| 750 | |||
| 751 | // Time to update the boards this membergroup has access to. |
||
| 752 | if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) |
||
| 753 | { |
||
| 754 | $accesses = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess']; |
||
| 755 | |||
| 756 | // If they can manage boards, the rules are a bit different. They can see everything. |
||
| 757 | if ($context['can_manage_boards']) |
||
| 758 | { |
||
| 759 | $accesses = array(); |
||
| 760 | $request = $smcFunc['db_query']('', ' |
||
| 761 | SELECT id_board |
||
| 762 | FROM {db_prefix}boards'); |
||
| 763 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 764 | $accesses[(int) $row['id_board']] = 'allow'; |
||
| 765 | $smcFunc['db_free_result']($request); |
||
| 766 | } |
||
| 767 | |||
| 768 | $changed_boards['allow'] = array(); |
||
| 769 | $changed_boards['deny'] = array(); |
||
| 770 | $changed_boards['ignore'] = array(); |
||
| 771 | foreach ($accesses as $group_id => $action) |
||
| 772 | $changed_boards[$action][] = (int) $group_id; |
||
| 773 | |||
| 774 | foreach (array('allow', 'deny') as $board_action) |
||
| 775 | { |
||
| 776 | // Find all board this group is in, but shouldn't be in. |
||
| 777 | $request = $smcFunc['db_query']('', ' |
||
| 778 | SELECT id_board, {raw:column} |
||
| 779 | FROM {db_prefix}boards |
||
| 780 | WHERE FIND_IN_SET({string:current_group}, {raw:column}) != 0' . (empty($changed_boards[$board_action]) ? '' : ' |
||
| 781 | AND id_board NOT IN ({array_int:board_access_list})'), |
||
| 782 | array( |
||
| 783 | 'current_group' => (int) $_REQUEST['group'], |
||
| 784 | 'board_access_list' => $changed_boards[$board_action], |
||
| 785 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
||
| 786 | ) |
||
| 787 | ); |
||
| 788 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 789 | $smcFunc['db_query']('', ' |
||
| 790 | UPDATE {db_prefix}boards |
||
| 791 | SET {raw:column} = {string:member_group_access} |
||
| 792 | WHERE id_board = {int:current_board}', |
||
| 793 | array( |
||
| 794 | 'current_board' => $row['id_board'], |
||
| 795 | 'member_group_access' => implode(',', array_diff(explode(',', $row['member_groups']), array($_REQUEST['group']))), |
||
| 796 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
||
| 797 | ) |
||
| 798 | ); |
||
| 799 | $smcFunc['db_free_result']($request); |
||
| 800 | |||
| 801 | // Add the membergroup to all boards that hadn't been set yet. |
||
| 802 | if (!empty($changed_boards[$board_action])) |
||
| 803 | $smcFunc['db_query']('', ' |
||
| 804 | UPDATE {db_prefix}boards |
||
| 805 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
||
| 806 | WHERE id_board IN ({array_int:board_list}) |
||
| 807 | AND FIND_IN_SET({int:current_group}, {raw:column}) = 0', |
||
| 808 | array( |
||
| 809 | 'board_list' => $changed_boards[$board_action], |
||
| 810 | 'blank_string' => '', |
||
| 811 | 'current_group' => (int) $_REQUEST['group'], |
||
| 812 | 'group_id_string' => (string) (int) $_REQUEST['group'], |
||
| 813 | 'comma_group' => ',' . $_REQUEST['group'], |
||
| 814 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
||
| 815 | ) |
||
| 816 | ); |
||
| 817 | } |
||
| 818 | } |
||
| 819 | |||
| 820 | // Remove everyone from this group! |
||
| 821 | if ($_POST['min_posts'] != -1) |
||
| 822 | { |
||
| 823 | $smcFunc['db_query']('', ' |
||
| 824 | UPDATE {db_prefix}members |
||
| 825 | SET id_group = {int:regular_member} |
||
| 826 | WHERE id_group = {int:current_group}', |
||
| 827 | array( |
||
| 828 | 'regular_member' => 0, |
||
| 829 | 'current_group' => (int) $_REQUEST['group'], |
||
| 830 | ) |
||
| 831 | ); |
||
| 832 | |||
| 833 | $request = $smcFunc['db_query']('', ' |
||
| 834 | SELECT id_member, additional_groups |
||
| 835 | FROM {db_prefix}members |
||
| 836 | WHERE FIND_IN_SET({string:current_group}, additional_groups) != 0', |
||
| 837 | array( |
||
| 838 | 'current_group' => (int) $_REQUEST['group'], |
||
| 839 | ) |
||
| 840 | ); |
||
| 841 | $updates = array(); |
||
| 842 | View Code Duplication | while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 843 | $updates[$row['additional_groups']][] = $row['id_member']; |
||
| 844 | $smcFunc['db_free_result']($request); |
||
| 845 | |||
| 846 | View Code Duplication | foreach ($updates as $additional_groups => $memberArray) |
|
| 847 | updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
||
| 848 | |||
| 849 | // Sorry, but post groups can't moderate boards |
||
| 850 | $smcFunc['db_query']('', ' |
||
| 851 | DELETE FROM {db_prefix}moderator_groups |
||
| 852 | WHERE id_group = {int:current_group}', |
||
| 853 | array( |
||
| 854 | 'current_group' => (int) $_REQUEST['group'], |
||
| 855 | ) |
||
| 856 | ); |
||
| 857 | } |
||
| 858 | elseif ($_REQUEST['group'] != 3) |
||
| 859 | { |
||
| 860 | // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional). |
||
| 861 | if ($_POST['group_hidden'] == 2) |
||
| 862 | { |
||
| 863 | $request = $smcFunc['db_query']('', ' |
||
| 864 | SELECT id_member, additional_groups |
||
| 865 | FROM {db_prefix}members |
||
| 866 | WHERE id_group = {int:current_group} |
||
| 867 | AND FIND_IN_SET({int:current_group}, additional_groups) = 0', |
||
| 868 | array( |
||
| 869 | 'current_group' => (int) $_REQUEST['group'], |
||
| 870 | ) |
||
| 871 | ); |
||
| 872 | $updates = array(); |
||
| 873 | View Code Duplication | while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 874 | $updates[$row['additional_groups']][] = $row['id_member']; |
||
| 875 | $smcFunc['db_free_result']($request); |
||
| 876 | |||
| 877 | foreach ($updates as $additional_groups => $memberArray) |
||
| 878 | { |
||
| 879 | $new_groups = (!empty($additional_groups) ? $additional_groups . ',' : '') . $_REQUEST['group']; // We already validated this a while ago. |
||
| 880 | updateMemberData($memberArray, array('additional_groups' => $new_groups)); |
||
| 881 | } |
||
| 882 | |||
| 883 | $smcFunc['db_query']('', ' |
||
| 884 | UPDATE {db_prefix}members |
||
| 885 | SET id_group = {int:regular_member} |
||
| 886 | WHERE id_group = {int:current_group}', |
||
| 887 | array( |
||
| 888 | 'regular_member' => 0, |
||
| 889 | 'current_group' => $_REQUEST['group'], |
||
| 890 | ) |
||
| 891 | ); |
||
| 892 | |||
| 893 | // Hidden groups can't moderate boards |
||
| 894 | $smcFunc['db_query']('', ' |
||
| 895 | DELETE FROM {db_prefix}moderator_groups |
||
| 896 | WHERE id_group = {int:current_group}', |
||
| 897 | array( |
||
| 898 | 'current_group' => $_REQUEST['group'], |
||
| 899 | ) |
||
| 900 | ); |
||
| 901 | } |
||
| 902 | |||
| 903 | // Either way, let's check our "show group membership" setting is correct. |
||
| 904 | $request = $smcFunc['db_query']('', ' |
||
| 905 | SELECT COUNT(*) |
||
| 906 | FROM {db_prefix}membergroups |
||
| 907 | WHERE group_type > {int:non_joinable}', |
||
| 908 | array( |
||
| 909 | 'non_joinable' => 1, |
||
| 910 | ) |
||
| 911 | ); |
||
| 912 | list ($have_joinable) = $smcFunc['db_fetch_row']($request); |
||
| 913 | $smcFunc['db_free_result']($request); |
||
| 914 | |||
| 915 | // 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)); |
||
| 918 | } |
||
| 919 | |||
| 920 | // Do we need to set inherited permissions? |
||
| 921 | if ($_POST['group_inherit'] != -2 && $_POST['group_inherit'] != $_POST['old_inherit']) |
||
| 922 | { |
||
| 923 | require_once($sourcedir . '/ManagePermissions.php'); |
||
| 924 | updateChildPermissions($_POST['group_inherit']); |
||
| 925 | } |
||
| 926 | |||
| 927 | // Finally, moderators! |
||
| 928 | $moderator_string = isset($_POST['group_moderators']) ? trim($_POST['group_moderators']) : ''; |
||
| 929 | $smcFunc['db_query']('', ' |
||
| 930 | DELETE FROM {db_prefix}group_moderators |
||
| 931 | WHERE id_group = {int:current_group}', |
||
| 932 | array( |
||
| 933 | 'current_group' => $_REQUEST['group'], |
||
| 934 | ) |
||
| 935 | ); |
||
| 936 | if ((!empty($moderator_string) || !empty($_POST['moderator_list'])) && $_POST['min_posts'] == -1 && $_REQUEST['group'] != 3) |
||
| 937 | { |
||
| 938 | $group_moderators = array(); |
||
| 939 | |||
| 940 | // Get all the usernames from the string |
||
| 941 | if (!empty($moderator_string)) |
||
| 942 | { |
||
| 943 | $moderator_string = strtr(preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($moderator_string, ENT_QUOTES)), array('"' => '"')); |
||
| 944 | preg_match_all('~"([^"]+)"~', $moderator_string, $matches); |
||
| 945 | $moderators = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $moderator_string))); |
||
| 946 | View Code Duplication | for ($k = 0, $n = count($moderators); $k < $n; $k++) |
|
| 947 | { |
||
| 948 | $moderators[$k] = trim($moderators[$k]); |
||
| 949 | |||
| 950 | if (strlen($moderators[$k]) == 0) |
||
| 951 | unset($moderators[$k]); |
||
| 952 | } |
||
| 953 | |||
| 954 | // Find all the id_member's for the member_name's in the list. |
||
| 955 | if (!empty($moderators)) |
||
| 956 | { |
||
| 957 | $request = $smcFunc['db_query']('', ' |
||
| 958 | SELECT id_member |
||
| 959 | FROM {db_prefix}members |
||
| 960 | WHERE member_name IN ({array_string:moderators}) OR real_name IN ({array_string:moderators}) |
||
| 961 | LIMIT {int:count}', |
||
| 962 | array( |
||
| 963 | 'moderators' => $moderators, |
||
| 964 | 'count' => count($moderators), |
||
| 965 | ) |
||
| 966 | ); |
||
| 967 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 968 | $group_moderators[] = $row['id_member']; |
||
| 969 | $smcFunc['db_free_result']($request); |
||
| 970 | } |
||
| 971 | } |
||
| 972 | |||
| 973 | View Code Duplication | if (!empty($_POST['moderator_list'])) |
|
| 974 | { |
||
| 975 | $moderators = array(); |
||
| 976 | foreach ($_POST['moderator_list'] as $moderator) |
||
| 977 | $moderators[] = (int) $moderator; |
||
| 978 | |||
| 979 | if (!empty($moderators)) |
||
| 980 | { |
||
| 981 | $request = $smcFunc['db_query']('', ' |
||
| 982 | SELECT id_member |
||
| 983 | FROM {db_prefix}members |
||
| 984 | WHERE id_member IN ({array_int:moderators}) |
||
| 985 | LIMIT {int:num_moderators}', |
||
| 986 | array( |
||
| 987 | 'moderators' => $moderators, |
||
| 988 | 'num_moderators' => count($moderators), |
||
| 989 | ) |
||
| 990 | ); |
||
| 991 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 992 | $group_moderators[] = $row['id_member']; |
||
| 993 | $smcFunc['db_free_result']($request); |
||
| 994 | } |
||
| 995 | } |
||
| 996 | |||
| 997 | // Make sure we don't have any duplicates first... |
||
| 998 | $group_moderators = array_unique($group_moderators); |
||
| 999 | |||
| 1000 | // Found some? |
||
| 1001 | if (!empty($group_moderators)) |
||
| 1002 | { |
||
| 1003 | $mod_insert = array(); |
||
| 1004 | foreach ($group_moderators as $moderator) |
||
| 1005 | $mod_insert[] = array($_REQUEST['group'], $moderator); |
||
| 1006 | |||
| 1007 | $smcFunc['db_insert']('insert', |
||
| 1008 | '{db_prefix}group_moderators', |
||
| 1009 | array('id_group' => 'int', 'id_member' => 'int'), |
||
| 1010 | $mod_insert, |
||
| 1011 | array('id_group', 'id_member') |
||
| 1012 | ); |
||
| 1013 | } |
||
| 1014 | } |
||
| 1015 | |||
| 1016 | // There might have been some post group changes. |
||
| 1017 | updateStats('postgroups'); |
||
| 1018 | // We've definitely changed some group stuff. |
||
| 1019 | updateSettings(array( |
||
| 1020 | 'settings_updated' => time(), |
||
| 1021 | )); |
||
| 1022 | |||
| 1023 | // Log the edit. |
||
| 1024 | logAction('edited_group', array('group' => $smcFunc['htmlspecialchars']($_POST['group_name'])), 'admin'); |
||
| 1025 | |||
| 1026 | redirectexit('action=admin;area=membergroups'); |
||
| 1027 | } |
||
| 1028 | |||
| 1029 | // Fetch the current group information. |
||
| 1030 | $request = $smcFunc['db_query']('', ' |
||
| 1031 | SELECT group_name, description, min_posts, online_color, max_messages, icons, group_type, hidden, id_parent, tfa_required |
||
| 1032 | FROM {db_prefix}membergroups |
||
| 1033 | WHERE id_group = {int:current_group} |
||
| 1034 | LIMIT 1', |
||
| 1035 | array( |
||
| 1036 | 'current_group' => (int) $_REQUEST['group'], |
||
| 1037 | ) |
||
| 1038 | ); |
||
| 1039 | if ($smcFunc['db_num_rows']($request) == 0) |
||
| 1040 | fatal_lang_error('membergroup_does_not_exist', false); |
||
| 1041 | $row = $smcFunc['db_fetch_assoc']($request); |
||
| 1042 | $smcFunc['db_free_result']($request); |
||
| 1043 | |||
| 1044 | $row['icons'] = explode('#', $row['icons']); |
||
| 1045 | |||
| 1046 | $context['group'] = array( |
||
| 1047 | 'id' => $_REQUEST['group'], |
||
| 1048 | 'name' => $row['group_name'], |
||
| 1049 | 'description' => $smcFunc['htmlspecialchars']($row['description'], ENT_QUOTES), |
||
| 1050 | 'editable_name' => $row['group_name'], |
||
| 1051 | 'color' => $row['online_color'], |
||
| 1052 | 'min_posts' => $row['min_posts'], |
||
| 1053 | 'max_messages' => $row['max_messages'], |
||
| 1054 | 'icon_count' => (int) $row['icons'][0], |
||
| 1055 | 'icon_image' => isset($row['icons'][1]) ? $row['icons'][1] : '', |
||
| 1056 | 'is_post_group' => $row['min_posts'] != -1, |
||
| 1057 | 'type' => $row['min_posts'] != -1 ? 0 : $row['group_type'], |
||
| 1058 | 'hidden' => $row['min_posts'] == -1 ? $row['hidden'] : 0, |
||
| 1059 | 'inherited_from' => $row['id_parent'], |
||
| 1060 | 'allow_post_group' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, |
||
| 1061 | 'allow_delete' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, |
||
| 1062 | 'allow_protected' => allowedTo('admin_forum'), |
||
| 1063 | 'tfa_required' => $row['tfa_required'], |
||
| 1064 | ); |
||
| 1065 | |||
| 1066 | // Get any moderators for this group |
||
| 1067 | $request = $smcFunc['db_query']('', ' |
||
| 1068 | SELECT mem.id_member, mem.real_name |
||
| 1069 | FROM {db_prefix}group_moderators AS mods |
||
| 1070 | INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member) |
||
| 1071 | WHERE mods.id_group = {int:current_group}', |
||
| 1072 | array( |
||
| 1073 | 'current_group' => $_REQUEST['group'], |
||
| 1074 | ) |
||
| 1075 | ); |
||
| 1076 | $context['group']['moderators'] = array(); |
||
| 1077 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 1078 | $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
||
| 1079 | $smcFunc['db_free_result']($request); |
||
| 1080 | |||
| 1081 | $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '"' . implode('", "', $context['group']['moderators']) . '"'; |
||
| 1082 | |||
| 1083 | View Code Duplication | if (!empty($context['group']['moderators'])) |
|
| 1084 | list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
||
| 1085 | |||
| 1086 | // Get a list of boards this membergroup is allowed to see. |
||
| 1087 | $context['boards'] = array(); |
||
| 1088 | if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) |
||
| 1089 | { |
||
| 1090 | $request = $smcFunc['db_query']('', ' |
||
| 1091 | SELECT b.id_cat, c.name as cat_name, b.id_board, b.name, b.child_level, |
||
| 1092 | FIND_IN_SET({string:current_group}, b.member_groups) != 0 AS can_access, FIND_IN_SET({string:current_group}, b.deny_member_groups) != 0 AS cannot_access |
||
| 1093 | FROM {db_prefix}boards AS b |
||
| 1094 | LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) |
||
| 1095 | ORDER BY board_order', |
||
| 1096 | array( |
||
| 1097 | 'current_group' => (int) $_REQUEST['group'], |
||
| 1098 | ) |
||
| 1099 | ); |
||
| 1100 | $context['categories'] = array(); |
||
| 1101 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 1102 | { |
||
| 1103 | // This category hasn't been set up yet.. |
||
| 1104 | if (!isset($context['categories'][$row['id_cat']])) |
||
| 1105 | $context['categories'][$row['id_cat']] = array( |
||
| 1106 | 'id' => $row['id_cat'], |
||
| 1107 | 'name' => $row['cat_name'], |
||
| 1108 | 'boards' => array() |
||
| 1109 | ); |
||
| 1110 | |||
| 1111 | // Set this board up, and let the template know when it's a child. (indent them..) |
||
| 1112 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
||
| 1113 | 'id' => $row['id_board'], |
||
| 1114 | 'name' => $row['name'], |
||
| 1115 | 'child_level' => $row['child_level'], |
||
| 1116 | 'allow' => !(empty($row['can_access']) || $row['can_access'] == 'f'), |
||
| 1117 | 'deny' => !(empty($row['cannot_access']) || $row['cannot_access'] == 'f'), |
||
| 1118 | ); |
||
| 1119 | } |
||
| 1120 | $smcFunc['db_free_result']($request); |
||
| 1121 | |||
| 1122 | // Now, let's sort the list of categories into the boards for templates that like that. |
||
| 1123 | $temp_boards = array(); |
||
| 1124 | View Code Duplication | foreach ($context['categories'] as $category) |
|
| 1125 | { |
||
| 1126 | $temp_boards[] = array( |
||
| 1127 | 'name' => $category['name'], |
||
| 1128 | 'child_ids' => array_keys($category['boards']) |
||
| 1129 | ); |
||
| 1130 | $temp_boards = array_merge($temp_boards, array_values($category['boards'])); |
||
| 1131 | |||
| 1132 | // Include a list of boards per category for easy toggling. |
||
| 1133 | $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']); |
||
| 1134 | } |
||
| 1135 | } |
||
| 1136 | |||
| 1137 | // Get a list of all the image formats we can select. |
||
| 1138 | $imageExts = array('png', 'jpg', 'jpeg', 'bmp', 'gif'); |
||
| 1139 | |||
| 1140 | // Scan the directory. |
||
| 1141 | $context['possible_icons'] = array(); |
||
| 1142 | if ($files = scandir($settings['default_theme_dir'] . '/images/membericons')) |
||
| 1143 | { |
||
| 1144 | // Loop through every file in the directory. |
||
| 1145 | foreach ($files as $value) |
||
| 1146 | { |
||
| 1147 | // Grab the image extension. |
||
| 1148 | $ext = pathinfo($settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION); |
||
| 1149 | |||
| 1150 | // If the extension is not empty, and it is valid |
||
| 1151 | if (!empty($ext) && in_array($ext, $imageExts)) |
||
| 1152 | { |
||
| 1153 | // Get the size of the image. |
||
| 1154 | $image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value); |
||
| 1155 | |||
| 1156 | // 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; |
||
| 1159 | |||
| 1160 | // Else it's valid. Add it in. |
||
| 1161 | else |
||
| 1162 | $context['possible_icons'][] = $value; |
||
| 1163 | } |
||
| 1164 | } |
||
| 1165 | } |
||
| 1166 | |||
| 1167 | // Insert our JS, if we have possible icons. |
||
| 1168 | if (!empty($context['possible_icons'])) |
||
| 1169 | loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown'); |
||
| 1170 | |||
| 1171 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
||
| 1172 | |||
| 1173 | // Finally, get all the groups this could be inherited off. |
||
| 1174 | $request = $smcFunc['db_query']('', ' |
||
| 1175 | SELECT id_group, group_name |
||
| 1176 | FROM {db_prefix}membergroups |
||
| 1177 | WHERE id_group != {int:current_group}' . |
||
| 1178 | (empty($modSettings['permission_enable_postgroups']) ? ' |
||
| 1179 | AND min_posts = {int:min_posts}' : '') . (allowedTo('admin_forum') ? '' : ' |
||
| 1180 | AND group_type != {int:is_protected}') . ' |
||
| 1181 | AND id_group NOT IN (1, 3) |
||
| 1182 | AND id_parent = {int:not_inherited}', |
||
| 1183 | array( |
||
| 1184 | 'current_group' => (int) $_REQUEST['group'], |
||
| 1185 | 'min_posts' => -1, |
||
| 1186 | 'not_inherited' => -2, |
||
| 1187 | 'is_protected' => 1, |
||
| 1188 | ) |
||
| 1189 | ); |
||
| 1190 | $context['inheritable_groups'] = array(); |
||
| 1191 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 1192 | $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
||
| 1193 | $smcFunc['db_free_result']($request); |
||
| 1194 | |||
| 1195 | call_integration_hook('integrate_view_membergroup'); |
||
| 1196 | |||
| 1197 | $context['sub_template'] = 'edit_group'; |
||
| 1198 | $context['page_title'] = $txt['membergroups_edit_group']; |
||
| 1199 | |||
| 1200 | createToken('admin-mmg'); |
||
| 1201 | } |
||
| 1202 | |||
| 1249 | ?> |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.