Ticket #5336: group-admin-invites-panel.patch
File group-admin-invites-panel.patch, 13.2 KB (added by , 11 years ago) |
---|
-
bp-groups/admin/css/admin.css
diff --git bp-groups/admin/css/admin.css bp-groups/admin/css/admin.css index 5a122cc..adf2cf8 100644
body.toplevel_page_bp-groups table.groups th#last_active { 23 23 .bp-groups-settings-section { 24 24 margin-bottom: 15px; 25 25 } 26 .bp-group s-member-type{26 .bp-group-admin-paginated-list { 27 27 position: relative; 28 padding-bottom: 1.7em; 28 padding: 1.7em 0; 29 } 30 .bp-groups-member-type { 31 padding-top: 0; 29 32 } 30 33 .bp-groups-member-type > h4 { 31 34 margin-bottom: .5em; 32 35 } 36 33 37 ul.bp-group-delete-list { 34 38 list-style-type: disc; 35 39 margin: 4px 26px; -
bp-groups/admin/css/admin.min.css
diff --git bp-groups/admin/css/admin.min.css bp-groups/admin/css/admin.min.css index 7983663..e46ce6d 100644
1 body.toplevel_page_bp-groups table.groups th# status,body.toplevel_page_bp-groups table.groups th#members{width:10%}body.toplevel_page_bp-groups table.groups th#last_active{width:15%}#bp-groups-edit-form input{outline:medium none;padding:3px 8px}#bp-groups-edit-form input#bp-groups-name{font-size:1.7em;width:100%}#bp-groups-edit-form input#bp-groups-new-members{width:100%;max-width:90%;border:0}.bp-groups-settings-section{margin-bottom:15px}.bp-groups-member-type{position:relative;padding-bottom:1.7em}.bp-groups-member-type>h4{margin-bottom:.5em}ul.bp-group-delete-list{list-style-type:disc;margin:4px 26px}.bp-group-admin-pagination{position:absolute;text-align:right;width:100%}.bp-group-admin-pagination.table-top{top:0}.bp-group-admin-pagination.table-bottom{bottom:0}.bp-group-admin-pagination-viewing{font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;color:#777;font-size:12px;font-style:italic}.bp-group-admin-pagination-links{white-space:nowrap;padding-left:15px}2 No newline at end of file 1 body.toplevel_page_bp-groups table.groups th#members,body.toplevel_page_bp-groups table.groups th#status{width:10%}body.toplevel_page_bp-groups table.groups th#last_active{width:15%}#bp-groups-edit-form input{outline:medium none;padding:3px 8px}#bp-groups-edit-form input#bp-groups-name{font-size:1.7em;width:100%}#bp-groups-edit-form input#bp-groups-new-members{width:100%;max-width:90%;border:0}.bp-groups-settings-section{margin-bottom:15px}.bp-group-admin-paginated-list{position:relative;padding:1.7em 0}.bp-groups-member-type{padding-top:0}.bp-groups-member-type>h4{margin-bottom:.5em}ul.bp-group-delete-list{list-style-type:disc;margin:4px 26px}.bp-group-admin-pagination{position:absolute;text-align:right;width:100%}.bp-group-admin-pagination.table-top{top:0}.bp-group-admin-pagination.table-bottom{bottom:0}.bp-group-admin-pagination-viewing{font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;color:#777;font-size:12px;font-style:italic}.bp-group-admin-pagination-links{white-space:nowrap;padding-left:15px} 2 No newline at end of file -
bp-groups/bp-groups-admin.php
diff --git bp-groups/bp-groups-admin.php bp-groups/bp-groups-admin.php index 1622692..3d74300 100644
function bp_groups_admin_load() { 126 126 add_meta_box( 'bp_group_settings', _x( 'Settings', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_settings', get_current_screen()->id, 'side', 'core' ); 127 127 add_meta_box( 'bp_group_add_members', _x( 'Add New Members', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_add_new_members', get_current_screen()->id, 'normal', 'core' ); 128 128 add_meta_box( 'bp_group_members', _x( 'Manage Members', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_members', get_current_screen()->id, 'normal', 'core' ); 129 add_meta_box( 'bp_group_invitations', _x( 'Manage Invitations', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_invitations', get_current_screen()->id, 'normal', 'core' ); 129 130 130 131 do_action( 'bp_groups_admin_meta_boxes' ); 131 132 … … function bp_groups_admin_load() { 337 338 } 338 339 } 339 340 341 // Process invitation removals 342 if ( ! empty( $_POST['bp-groups-remove-invite'] ) ) { 343 344 foreach ( (array) $_POST['bp-groups-remove-invite'] as $uninvited ) { 345 346 // Remove the invitation 347 $result = groups_delete_invite( (int) $uninvited, $group_id ); 348 349 // Store the success or failure 350 if ( $result ) { 351 $success_removed_invite[] = $uninvited; 352 } else { 353 $error_removed_invite[] = $uninvited; 354 } 355 356 } 357 } 358 340 359 // Call actions for plugins to do something before we redirect 341 360 do_action( 'bp_group_admin_edit_after', $group_id ); 342 361 … … function bp_groups_admin_load() { 370 389 $redirect_to = add_query_arg( 'error_modified', $error_modified, $redirect_to ); 371 390 } 372 391 392 if ( !empty( $success_removed_invite ) ) { 393 $success_removed_invite = implode( ',', array_filter( $success_removed_invite, 'urlencode' ) ); 394 $redirect_to = add_query_arg( 'success_removed_invite', $success_removed_invite, $redirect_to ); 395 } 396 397 if ( !empty( $error_removed_invite ) ) { 398 $error_removed_invite = implode( ',', array_filter( $error_removed_invite, 'urlencode' ) ); 399 $redirect_to = add_query_arg( 'error_removed_invite', $error_removed_invite, $redirect_to ); 400 } 401 373 402 // Redirect 374 403 wp_redirect( apply_filters( 'bp_group_admin_edit_redirect', $redirect_to ) ); 375 404 exit; … … function bp_groups_admin_edit_metabox_members( $item ) { 767 796 // Loop through each member type 768 797 foreach ( $members as $member_type => $type_users ) : ?> 769 798 770 <div class="bp-groups-member-type " id="bp-groups-member-type-<?php echo esc_attr( $member_type ) ?>">799 <div class="bp-groups-member-type bp-group-admin-paginated-list" id="bp-groups-member-type-<?php echo esc_attr( $member_type ) ?>"> 771 800 772 801 <h4> 773 802 <?php switch ( $member_type ) : … … function bp_groups_admin_edit_metabox_members( $item ) { 859 888 } 860 889 861 890 /** 891 * Renders the Invitations metabox on single group pages. 892 * 893 * @since BuddyPress (2.0.0) 894 * 895 * @param BP_Groups_Group $item The BP_Groups_Group object for the current 896 * group. 897 */ 898 function bp_groups_admin_edit_metabox_invitations( $item ) { 899 global $members_template; 900 901 $current_inv_page = isset( $_GET[ 'invitations_page' ] ) ? absint( $_GET[ 'invitations_page' ] ) : 1; 902 $per_page = 10; 903 904 //Get invitations 905 $invitations = BP_Groups_Member::get_group_invites( $item->id, $per_page, $current_inv_page ); 906 $total_invites = (int) $invitations['total']; 907 908 $pagination[ 'invitations' ] = bp_groups_admin_create_invitation_pagination_links( $current_inv_page, $per_page, $total_invites ); 909 ?> 910 <div id="bp-group-invitations-list" class="bp-group-admin-paginated-list"> 911 912 <div class="bp-group-admin-pagination table-top"> 913 <?php echo $pagination[ 'invitations' ] ?> 914 </div> 915 916 917 <?php if ( !empty( $invitations['invitees'] ) ) : ?> 918 919 <table class="widefat bp-group-invitations"> 920 <thead> 921 <tr> 922 <th scope="col" class="uid-column"><?php _ex( 'ID', 'Group invitation recipient user_id in group admin', 'buddypress' ) ?></th> 923 <th scope="col" class="uname-column"><?php _ex( 'Name', 'Group invitation recipient name in group admin', 'buddypress' ) ?></th> 924 <th scope="col" class="inviter-name-column"><?php _ex( 'Invited By', 'User_id of group invitation sender in group admin', 'buddypress' ) ?></th> 925 <th scope="col" class="remove-invitation-column"><?php _ex( 'Remove Invitation', 'Remove invitation in group admin', 'buddypress' ) ?></th> 926 </tr> 927 </thead> 928 929 <tbody> 930 931 <?php foreach ( $invitations['invitees'] as $invitee ) : ?> 932 <tr> 933 <th scope="row" class="uid-column"><?php echo esc_html( $invitee->user_id ); ?></th> 934 935 <td class="uname-column"> 936 <a style="float: left;" href="<?php echo bp_core_get_user_domain( $invitee->user_id ); ?>"><?php echo bp_core_fetch_avatar( array( 937 'item_id' => $invitee->user_id, 938 'width' => '32', 939 'height' => '32' 940 ) ); ?></a> 941 942 <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $invitee->user_id ) ?></span> 943 </td> 944 945 <td class="inviter-name-column"> 946 <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $invitee->inviter_id ) ?></span> 947 </td> 948 <td class="inviter-name-column"> 949 <label style="margin: 8px; float: left;"><input type="checkbox" name="bp-groups-remove-invite[<?php echo esc_html( $invitee->user_id ); ?>]" value="<?php echo esc_html( $invitee->user_id ); ?>">Remove</label> 950 </td> 951 </tr> 952 953 <?php endforeach; ?> 954 955 </tbody> 956 </table> 957 958 <div class="bp-group-admin-pagination table-bottom"> 959 <?php echo $pagination[ 'invitations' ] ?> 960 </div> 961 962 <?php else : ?> 963 964 <p class="bp-groups-no-outstanding-invites description"><?php _e( 'No outstanding invitations', 'buddypress' ) ?></p> 965 966 <?php endif; ?> 967 968 </div><!-- #bp-group-invitations-list --> 969 970 <?php 971 } 972 973 /** 862 974 * Renders the Status metabox for the Groups admin edit screen. 863 975 * 864 976 * @since BuddyPress (1.7.0) … … function bp_groups_admin_create_pagination_links( BP_Group_Member_Query $query, 945 1057 946 1058 return $pagination; 947 1059 } 1060 /** 1061 * Create pagination links for invitations. 1062 * 1063 * This function is intended to create pagination links for use under the 1064 * Manage Invitations section of the Groups Admin Dashboard pages. It is a stopgap 1065 * measure until a more general pagination solution is in place for BuddyPress. 1066 * Plugin authors should not use this function, as it is likely to be 1067 * deprecated soon. 1068 * 1069 * @since BuddyPress (2.0.0) 1070 * 1071 * @return string Pagination links HTML. 1072 */ 1073 function bp_groups_admin_create_invitation_pagination_links( $page, $per_page, $total_invites ) { 1074 $pagination = ''; 1075 1076 // The key used to paginate this member type in the $_GET global 1077 $qs_key = 'invitations_page'; 1078 $url_base = remove_query_arg( array( $qs_key, 'updated', 'success_modified' ), $_SERVER['REQUEST_URI'] ); 1079 1080 1081 // Don't show anything if there's no pagination 1082 if ( 1 === $page && $total_invites<= $per_page ) { 1083 return $pagination; 1084 } 1085 1086 $current_page_start = ( ( $page - 1 ) * $per_page ) + 1; 1087 $current_page_end = $page * $per_page > intval( $total_invites ) ? $total_invites : $page * $per_page; 1088 1089 $pag_links = paginate_links( array( 1090 'base' => add_query_arg( $qs_key, '%#%', $url_base ), 1091 'format' => '', 1092 'prev_text' => __( '«', 'buddypress' ), 1093 'next_text' => __( '»', 'buddypress' ), 1094 'total' => ceil( $total_invites / $per_page ), 1095 'current' => $page, 1096 ) ); 1097 1098 $viewing_text = sprintf( 1099 __( 'Viewing %1$s - %2$s of %3$s', 'buddypress' ), 1100 number_format_i18n( $current_page_start ), 1101 number_format_i18n( $current_page_end ), 1102 sprintf( _n( '%s member', '%s members', $total_invites, 'buddypress' ), $total_invites ) 1103 ); 1104 1105 $pagination .= '<span class="bp-group-admin-pagination-viewing">' . $viewing_text . '</span>'; 1106 $pagination .= '<span class="bp-group-admin-pagination-links">' . $pag_links . '</span>'; 1107 1108 return $pagination; 1109 } 1110 948 1111 949 1112 /** 950 1113 * Get a set of usernames corresponding to a set of user IDs. -
bp-groups/bp-groups-classes.php
diff --git bp-groups/bp-groups-classes.php bp-groups/bp-groups-classes.php index de81785..ea879f3 100644
class BP_Groups_Member { 2168 2168 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) ); 2169 2169 } 2170 2170 } 2171 /** 2172 * Get a group's outstanding group invitations. 2173 * 2174 * @param int $group_id ID of the group. 2175 * @param int $limit Optional. Max number of results to return. 2176 * Default: false (no limit). 2177 * @param int $page Optional. Page offset of results to return. 2178 * Default: false (no limit). 2179 * @return array { 2180 * @type array $invitees Array of users returned by paginated query. 2181 * @type int $total Count of users matching query. 2182 * } 2183 */ 2184 public static function get_group_invites( $group_id, $limit = false, $page = false ) { 2185 global $wpdb, $bp; 2186 2187 $pag_sql = ( !empty( $limit ) && !empty( $page ) ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : ''; 2188 2189 // Outstanding invitations can be identified by checking for is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1 2190 // Outstanding membership requests have is_confirmed = 0 AND inviter_id = 0 AND invite_sent = 0 2191 2192 $paged_invitees = $wpdb->get_results( $wpdb->prepare( "SELECT m.*, i1.ID as invitee_id_check, i1.display_name as invitee_display_name, i2.ID as inviter_id_check, i2.display_name as inviter_display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} i1, {$wpdb->users} i2 WHERE m.user_id = i1.ID AND m.inviter_id = i2.ID AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.group_id = %d ORDER BY m.date_modified ASC {$pag_sql}", $group_id ) ); 2193 $total_invitees = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.user_id) FROM {$bp->groups->table_name_members} m WHERE m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.group_id = %d {$exclude_sql} ORDER BY date_modified ASC", $group_id ) ); 2194 2195 return array( 'invitees' => $paged_invitees, 'total' => $total_invitees ); 2196 } 2171 2197 2172 2198 /** 2173 2199 * Get a user's outstanding group invitations.