<?php
/**
 * Querystring is set via AJAX in _inc/ajax.php - bp_dtheme_object_filter()
 */

do_action( 'bp_before_members_loop' );

if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&per_page=12&action=alphabetical' ) ) :
?>

    <div id="pag-top" class="pagination">
        
        <div class="pag-count" id="member-dir-count-top">
            <?php
            bp_members_pagination_count();
            ?>
        </div>
        
        <div class="pagination-links" id="member-dir-pag-top">
            <?php
            bp_members_pagination_links();
            ?>
        </div>
        
    </div>
    
    <?php
    do_action( 'bp_before_directory_members_list' );
    ?>
    
    <ul id="members-list" class="item-list">
        <?php
        while ( bp_members() ) : bp_the_member();
        
            $class = calculate_moodbar( bp_get_member_user_id() );
        ?>
        
            <li>
                <div class="item-avatar <?php echo $class; ?>">
                    
                    <a href="<?php bp_member_permalink() ?>" title="<?php echo bp_get_member_name(); ?>">
                        <?php bp_member_avatar() ?>
                    </a>
                    
                    <?php
                    /**
                     * Check online icon
                     * Checks users last activity and if less than 5 minute have passed, display online icon
                     */
                    global $members_template;
                    
                    $online_time = strtotime($members_template->member->last_activity);
                    
                    if ($online_time+300>=time())
                        echo '<img class="check-online" src="'. get_stylesheet_directory_uri() . '/_inc/images/user_online.png" />';
                    /*
                    else
                        echo '<img class="check-online" src="'. get_stylesheet_directory_uri() . '/_inc/images/user_offline.gif" />';
                    */
                    ?>
                
                </div>
                
                <div class="item">
                    
                    <div class="item-title">
                        
                        <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>">
                            <?php bp_member_name() ?>
                        </a>
                        <?php
                        global $bp, $members_template;
                        
                        if (friends_check_friendship(wp_get_current_user()->ID, bp_get_member_user_id()) or current_user_can( 'manage_options' )) {
                            
                            $wpnonceurl = wp_nonce_url( $bp->loggedin_user->domain . $bp->messages->slug . '/compose/?r=' . bp_core_get_username( bp_get_member_user_id(), bp_get_member_user_nicename(), bp_get_member_user_login() ) );
                            ?>
                            <div id="send-private-message" class="generic-button single-message">
                                <a class="send-message single" title="<?php _e ('Enviar un mensaje privado a este usuario.','buddypress'); ?>" href="<?php echo $wpnonceurl; ?>">
                                    <?php _e ('Enviar mensaje privado','buddypress'); ?>
                                </a>
                            </div>
                        <?php
                        }
                        ?>
                    </div>
                    
                    <?php
                    do_action( 'bp_directory_members_item' );
                    
                     /**
                      * If you want to show specific profile fields here you can,
                      * but it'll add an extra query for each member in the loop
                      * (only one regardless of the number of fields you show):
                      *
                      * bp_member_profile_data( 'field=the field name' );
                      */
                    ?>
                </div>
                
                <div class="action-mem">
                    
                    <?php
                    do_action( 'bp_directory_members_actions' );
                    ?>
                </div>
            </li>
            
        <?php
        endwhile;
        ?>
    </ul>
    
    <div class="clear"></div>
    
    <?php
    do_action( 'bp_after_directory_members_list' );
    
    bp_member_hidden_fields();
    ?>
    
    <div id="pag-bottom" class="pagination">
        
        <div class="pag-count" id="member-dir-count-bottom">
            <?php bp_members_pagination_count() ?>
        </div>
        
        <div class="pagination-links" id="member-dir-pag-bottom">
            <?php bp_members_pagination_links() ?>
        </div>
        
    </div>
    
<?php
else:
?>
    
    <div id="message" class="info">
        <p><?php _e( "Sorry, no members were found.", 'buddypress' ) ?></p>
    </div>

<?php
endif;

do_action( 'bp_after_members_loop' );
?>