Changeset 7144 for trunk/bp-groups/bp-groups-classes.php
- Timestamp:
- 06/04/2013 03:04:23 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r7143 r7144 1031 1031 1032 1032 // Role information is stored as follows: admins have 1033 // is_admin = 1, mods have is_mod = 1, and members have both1034 // set to 0.1033 // is_admin = 1, mods have is_mod = 1, banned have is_banned = 1034 // 1, and members have all three set to 0. 1035 1035 $roles = !empty( $this->query_vars['group_role'] ) ? $this->query_vars['group_role'] : array(); 1036 1036 if ( is_string( $roles ) ) { … … 1038 1038 } 1039 1039 1040 // Sanitize: Only 'admin', 'mod', and 'member' are valid 1040 // Sanitize: Only 'admin', 'mod', 'member', and 'banned' are valid 1041 $allowed_roles = array( 'admin', 'mod', 'member', 'banned' ); 1041 1042 foreach ( $roles as $role_key => $role_value ) { 1042 if ( ! in_array( $role_value, array( 'admin', 'mod', 'member' )) ) {1043 if ( ! in_array( $role_value, $allowed_roles ) ) { 1043 1044 unset( $roles[ $role_key ] ); 1044 1045 } 1045 1046 } 1046 1047 1047 // Remove dupes to make the count accurate, and flip for faster 1048 // isset() lookups 1049 $roles = array_flip( array_unique( $roles ) ); 1050 1051 switch ( count( $roles ) ) { 1052 1053 // All three roles means we don't limit results 1054 case 3 : 1055 default : 1056 $roles_sql = ''; 1057 break; 1058 1059 case 2 : 1060 // member + mod = no admins 1061 // member + admin = no mods 1062 if ( isset( $roles['member'] ) ) { 1063 $roles_sql = isset( $roles['admin'] ) ? "is_mod = 0" : "is_admin = 0"; 1064 1065 // Two non-member roles are 'admin' and 'mod' 1066 } else { 1067 $roles_sql = "(is_admin = 1 OR is_mod = 1)"; 1068 } 1069 break; 1070 1071 case 1 : 1072 // member only means no admins or mods 1073 if ( isset( $roles['member'] ) ) { 1074 $roles_sql = "is_admin = 0 AND is_mod = 0"; 1075 1076 // Filter by that role only 1077 } else { 1078 $roles_sql = isset( $roles['admin'] ) ? "is_admin = 1" : "is_mod = 1"; 1079 } 1080 break; 1081 1082 // No roles means no users should be returned 1083 case 0 : 1084 $roles_sql = $this->no_results['where']; 1085 break; 1048 $roles = array_unique( $roles ); 1049 1050 // When querying for a set of roles containing 'member' (for 1051 // which there is no dedicated is_ column), figure out a list 1052 // of columns *not* to match 1053 if ( in_array( 'member', $roles ) ) { 1054 $role_columns = array(); 1055 foreach ( array_diff( $allowed_roles, $roles ) as $excluded_role ) { 1056 $role_columns[] = 'is_' . $excluded_role . ' = 0'; 1057 } 1058 $roles_sql = '(' . implode( ' AND ', $role_columns ) . ')'; 1059 1060 // When querying for a set of roles *not* containing 'member', 1061 // simply construct a list of is_* = 1 clauses 1062 } else { 1063 $role_columns = array(); 1064 foreach ( $roles as $role ) { 1065 $role_columns[] = 'is_' . $role . ' = 1'; 1066 } 1067 $roles_sql = '(' . implode( ' OR ', $role_columns ) . ')'; 1086 1068 } 1087 1069
Note: See TracChangeset
for help on using the changeset viewer.