Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/13/2008 11:20:15 PM (16 years ago)
Author:
apeatling
Message:

Added ability for group admins to:

  • Promote users to moderators
  • Demote users to regular group members
  • Ban and kick users from a group
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-templatetags.php

    r536 r540  
    313313    if ( !$admins = &$groups_template->group->admins )
    314314        $admins = $groups_template->group->get_administrators();
    315    
     315
    316316    if ( $admins ) {
    317317        if ( $full_list ) { ?>
     
    338338}
    339339
     340function bp_group_list_mods( $full_list = true ) {
     341    global $groups_template, $group_mods;
     342   
     343    if ( $group_mods ) {
     344        if ( $full_list ) { ?>
     345            <ul id="group-mods" class="mods-list">
     346            <?php for ( $i = 0; $i < count($group_mods); $i++ ) { ?>
     347                <li>
     348                    <?php echo bp_core_get_avatar( $group_mods[$i]->user_id, 1, false, 36, 36 ) ?>
     349                    <h5><?php echo bp_core_get_userlink( $group_mods[$i]->user_id ) ?></h5>
     350                    <span class="activity"><?php _e( 'Group Mod', 'buddypress' ) ?></span>
     351                    <div class="clear"></div>
     352                </li>
     353            <?php } ?>
     354            </ul>
     355        <?php } else { ?>
     356            <?php for ( $i = 0; $i < count($admins); $i++ ) { ?>
     357                <?php echo bp_core_get_userlink( $group_mods[$i]->user_id ) . ' ' ?>
     358            <?php } ?>
     359        <?php } ?>
     360    <?php } else { ?>
     361        <span class="activity">No Admin</span>
     362    <?php } ?>
     363   
     364<?php
     365}
     366
    340367function bp_group_all_members_permalink() {
    341368    global $groups_template, $bp;
     
    457484}
    458485
     486function bp_group_admin_memberlist( $admin_list = false ) {
     487    global $groups_template;
     488   
     489    $admins = groups_get_group_admins( $groups_template->group->id );
     490?>
     491    <?php if ( $admins ) { ?>
     492        <ul id="admins-list" class="item-list<?php if ( $admin_list ) { ?> single-line<?php } ?>">
     493        <?php foreach ( $admins as $admin ) { ?>
     494            <?php if ( $admin_list ) { ?>
     495            <li>
     496                <?php echo bp_core_get_avatar( $admin->user_id, 1, false, 30, 30 ) ?>
     497                <h5><?php echo bp_core_get_userlink( $admin->user_id ) ?></h5>
     498            </li>
     499            <?php } else { ?>
     500            <li>
     501                <?php echo bp_core_get_avatar( $admin->user_id, 1 ) ?>
     502                <h5><?php echo bp_core_get_userlink( $admin->user_id ) ?></h5>
     503                <span class="activity"><?php echo bp_core_get_last_activity( strtotime( $admin->date_modified ), __( 'joined %s ago', 'buddypress') ); ?></span>
     504               
     505                <?php if ( function_exists( 'friends_install' ) ) : ?>
     506                    <div class="action">
     507                        <?php bp_add_friend_button( $admin->user_id ) ?>
     508                    </div>
     509                <?php endif; ?>
     510            </li>       
     511            <?php } ?>
     512        <?php } ?>
     513        </ul>
     514    <?php } else { ?>
     515        <div id="message" class="info">
     516            <?php _e( 'This group has no administrators', 'buddypress' ); ?>
     517        </div>
     518    <?php }
     519}
     520
     521function bp_group_mod_memberlist( $admin_list = false ) {
     522    global $groups_template, $group_mods;   
     523    ?>
     524        <?php if ( $group_mods ) { ?>
     525            <ul id="mods-list" class="item-list<?php if ( $admin_list ) { ?> single-line<?php } ?>">
     526            <?php foreach ( $group_mods as $mod ) { ?>
     527                <?php if ( $admin_list ) { ?>
     528                <li>
     529                    <?php echo bp_core_get_avatar( $mod->user_id, 1, false, 30, 30 ) ?>
     530                    <h5><?php echo bp_core_get_userlink( $mod->user_id ) ?>  <span class="small"> &mdash; <a href="<?php bp_group_member_ban_link() ?>"><?php _e( 'Kick &amp; Ban', 'buddypress' ) ?></a> | <a href="<?php bp_group_member_demote_link($mod->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a></span></h5>
     531                </li>
     532                <?php } else { ?>
     533                <li>
     534                    <?php echo bp_core_get_avatar( $mod->user_id, 1 ) ?>
     535                    <h5><?php echo bp_core_get_userlink( $mod->user_id ) ?></h5>
     536                    <span class="activity"><?php echo bp_core_get_last_activity( strtotime( $mod->date_modified ), __( 'joined %s ago', 'buddypress') ); ?></span>
     537                   
     538                    <?php if ( function_exists( 'friends_install' ) ) : ?>
     539                        <div class="action">
     540                            <?php bp_add_friend_button( $mod->user_id ) ?>
     541                        </div>
     542                    <?php endif; ?>
     543                </li>       
     544                <?php } ?>         
     545            <?php } ?>
     546            </ul>
     547        <?php } else { ?>
     548            <div id="message" class="info">
     549                <p><?php _e( 'This group has no moderators', 'buddypress' ); ?></p>
     550            </div>
     551        <?php }
     552}
     553
     554function bp_group_has_moderators() {
     555    global $group_mods, $groups_template;
     556   
     557    $group_mods = groups_get_group_mods( $groups_template->group->id );
     558    return $group_mods;
     559}
     560
     561function bp_group_member_promote_link() {
     562    global $members_template, $groups_template, $bp;
     563
     564    echo bp_group_permalink( $groups_template->group, false ) . '/admin/manage-members/promote/' . $members_template->member->user_id;
     565}
     566
     567function bp_group_member_demote_link( $user_id = false) {
     568    global $members_template, $groups_template, $bp;
     569   
     570    if ( !$user_id )
     571        $user_id = $members_template->member->user_id;
     572   
     573    echo bp_group_permalink( $groups_template->group, false ) . '/admin/manage-members/demote/' . $user_id;
     574}
     575
     576function bp_group_member_ban_link() {
     577    global $members_template, $groups_template, $bp;
     578   
     579    echo bp_group_permalink( $groups_template->group, false ) . '/admin/manage-members/ban/' . $members_template->member->user_id;
     580}
     581
     582function bp_group_member_unban_link() {
     583    global $members_template, $groups_template, $bp;
     584   
     585    echo bp_group_permalink( $groups_template->group, false ) . '/admin/manage-members/unban/' . $members_template->member->user_id;   
     586}
     587
    459588function bp_group_admin_tabs() {
    460589    global $bp, $groups_template;
     
    462591    $current_tab = $bp['action_variables'][0];
    463592?>
    464     <li<?php if ( $current_tab == 'edit-details' || $current_tab == '' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/edit-details"><?php _e('Edit Details', 'buddypress') ?></a></li>
    465     <li<?php if ( $current_tab == 'group-settings' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/group-settings"><?php _e('Group Settings', 'buddypress') ?></a></li>
    466     <li<?php if ( $current_tab == 'manage-members' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/manage-members"><?php _e('Manage Members', 'buddypress') ?></a></li>
    467    
    468     <?php if ( $groups_template->group->status == 'private' ) : ?>
     593    <?php if ( $bp['is_item_admin'] || $bp['is_item_mod'] ) { ?>
     594        <li<?php if ( $current_tab == 'edit-details' || $current_tab == '' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/edit-details"><?php _e('Edit Details', 'buddypress') ?></a></li>
     595    <?php } ?>
     596
     597    <?php if ( $bp['is_item_admin'] ) { ?> 
     598        <li<?php if ( $current_tab == 'group-settings' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/group-settings"><?php _e('Group Settings', 'buddypress') ?></a></li>
     599    <?php } ?>
     600
     601    <?php if ( $bp['is_item_admin'] ) { ?>         
     602        <li<?php if ( $current_tab == 'manage-members' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/manage-members"><?php _e('Manage Members', 'buddypress') ?></a></li>
     603    <?php } ?>
     604   
     605    <?php if ( $bp['is_item_admin'] && $groups_template->group->status == 'private' ) : ?>
    469606    <li<?php if ( $current_tab == 'membership-requests' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/membership-requests"><?php _e('Membership Requests', 'buddypress') ?></a></li>
    470607    <?php endif; ?>
    471    
    472     <li<?php if ( $current_tab == 'delete-group' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/delete-group"><?php _e('Delete Group', 'buddypress') ?></a></li>
     608
     609    <?php if ( $bp['is_item_admin'] ) { ?>     
     610        <li<?php if ( $current_tab == 'delete-group' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/delete-group"><?php _e('Delete Group', 'buddypress') ?></a></li>
     611    <?php } ?>
    473612   
    474613<?php
     
    680819}
    681820
    682 function bp_group_list_members() {
    683     global $groups_template, $bp;
    684 
    685     for ( $i = 0; $i < count($groups_template->group->user_dataset); $i++ ) {
    686         $member = new BP_Groups_Member( $groups_template->group->user_dataset[$i]->user_id, $groups_template->group->id );
    687 
    688         ?><li id="uid-<?php echo $user->id ?>">
    689             <?php echo $member->user->avatar_thumb ?>
    690             <p><?php echo $member->user->user_link ?> <?php if ( $member->user_title ) { ?><?php echo '<span class="small">- ' . $member->user_title . '</span>' ?><?php } ?></p>
    691             <span class="activity"><?php echo sprintf( __( 'joined %s ago', 'buddypress' ), bp_core_time_since( strtotime( $member->date_modified ) ) ); ?></span>
    692     <?php if ( bp_exists('friends') && function_exists('bp_add_friend_button') ) { ?>
    693             <div class="action">
    694                 <?php bp_add_friend_button( $member->user->id ) ?>
    695             </div>
    696     <?php } ?>
    697            </li>
    698         <?php
    699     }
    700 }
    701 
    702821function bp_group_accept_invite_link() {
    703822    global $groups_template, $bp;
     
    775894    global $bp, $groups_template;
    776895   
    777     if ( !is_user_logged_in() || BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $groups_template->group->id ) )
     896    if ( !is_user_logged_in() || BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $groups_template->group->id ) || groups_is_user_banned( $bp['loggedin_userid'], $groups_template->group->id ) )
    778897        return false;
    779898       
     
    852971    var $total_member_count;
    853972   
    854     function bp_groups_group_members_template( $group_id ) {
     973    function bp_groups_group_members_template( $group_id, $num_per_page, $exclude_admins_mods, $exclude_banned ) {
    855974        global $bp;
    856975       
    857976        $this->pag_page = isset( $_REQUEST['mlpage'] ) ? intval( $_REQUEST['mlpage'] ) : 1;
    858         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : 5;
    859        
    860         $members = BP_Groups_Member::get_all_for_group( $group_id, $this->pag_num, $this->pag_page );
     977        $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $num_per_page;
     978       
     979        $members = BP_Groups_Member::get_all_for_group( $group_id, $this->pag_num, $this->pag_page, $exclude_admins_mods, $exclude_banned );
    861980       
    862981        $this->total_member_count = $members['count'];
     
    9221041}
    9231042
    924 function bp_group_has_members( $group_id = false ) {
     1043function bp_group_has_members( $group_id = false, $num_per_page = 5, $exclude_admins_mods = true, $exclude_banned = true ) {
    9251044    global $members_template, $groups_template;
    9261045   
    927     if ( !$group_id )
    928         $group_id = $groups_template->group->id;
    929 
    930     $members_template = new BP_Groups_Group_Members_Template( $group_id );
     1046    if ( !$groups_template )
     1047        $groups_template->group = new BP_Groups_Group( $group_id );
     1048   
     1049
     1050    $members_template = new BP_Groups_Group_Members_Template( $groups_template->group->id, $num_per_page, $exclude_admins_mods, $exclude_banned );
    9311051
    9321052    return $members_template->has_members();
     
    9511071}
    9521072
     1073function bp_group_member_avatar_mini( $width = 30, $height = 30 ) {
     1074    global $members_template;
     1075   
     1076    echo bp_core_get_avatar( $members_template->member->user_id, 1, false, $width, $height );
     1077}
     1078
    9531079function bp_group_member_link() {
    9541080    global $members_template;
    9551081   
    9561082    echo bp_core_get_userlink( $members_template->member->user_id );
     1083}
     1084
     1085function bp_group_member_is_banned() {
     1086    global $members_template, $groups_template;
     1087
     1088    return groups_is_user_banned( $members_template->member->user_id, $groups_template->group->id );
    9571089}
    9581090
     
    9901122    global $members_template;
    9911123    echo $members_template->pag_links;
    992     wp_nonce_field( 'bp_groups_member_list' );
     1124    wp_nonce_field( 'bp_groups_member_list', '_member_pag_nonce' );
    9931125}
    9941126
     
    10001132
    10011133    echo sprintf( __( 'Viewing members %d to %d (%d total members)', 'buddypress' ), $from_num, $to_num, $members_template->total_member_count ); 
     1134}
     1135
     1136function bp_group_member_admin_pagination() {
     1137    global $members_template;
     1138    echo $members_template->pag_links;
     1139    wp_nonce_field( 'bp_groups_member_admin_list', '_member_admin_pag_nonce' );
    10021140}
    10031141
     
    10201158    var $total_request_count;
    10211159   
    1022     function bp_groups_membership_requests_template( $group_id ) {
     1160    function bp_groups_membership_requests_template( $group_id, $num_per_page ) {
    10231161        global $bp;
    10241162       
    10251163        $this->pag_page = isset( $_REQUEST['mrpage'] ) ? intval( $_REQUEST['mrpage'] ) : 1;
    1026         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : 5;
     1164        $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $num_per_page;
    10271165       
    10281166        $this->requests = BP_Groups_Group::get_membership_requests( $group_id, $this->pag_num, $this->pag_page );
     
    10881226}
    10891227
    1090 function bp_group_has_membership_requests() {
     1228function bp_group_has_membership_requests( $num_per_page = 5 ) {
    10911229    global $requests_template, $groups_template;
    10921230   
    1093     $requests_template = new BP_Groups_Membership_Requests_Template( $groups_template->group->id );
     1231    $requests_template = new BP_Groups_Membership_Requests_Template( $groups_template->group->id, $num_per_page );
    10941232
    10951233    return $requests_template->has_requests();
Note: See TracChangeset for help on using the changeset viewer.