WordPress.org

Plugin Directory

Changeset 120577


Ignore:
Timestamp:
05/26/09 14:14:51 (5 years ago)
Author:
bforchhammer
Message:

Added feature to sort by recent user activity. Requires BuddyPress or WP-UserOnline.

Location:
author-avatars/trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • author-avatars/trunk/lib/AuthorAvatarsForm.class.php

    r118924 r120577  
    330330            'user_id' => __('User Id'), 
    331331        ); 
     332        if (AA_is_bp() || function_exists('get_memberlastvisit') ) { 
     333            $order_options['recent_activity'] = __('Recent Activity'); 
     334        } 
    332335         
    333336        $attributes = array( 
  • author-avatars/trunk/lib/UserList.class.php

    r119226 r120577  
    394394            case 'date_registered': 
    395395                usort($users, array($this, '_user_cmp_regdate')); 
     396                break; 
     397            case 'recent_activity': 
     398                usort($users, array($this, '_user_cmp_activity')); 
     399                break; 
    396400        } 
    397401    } 
     
    488492    function _user_cmp_regdate($a, $b) { 
    489493        return $this->_sort_direction() * strcasecmp($a->user_registered, $b->user_registered); 
     494    } 
     495     
     496    /** 
     497     * Given two users, this function compares the time of last user activity on the page. 
     498     * 
     499     * @access private 
     500     * @param WP_User $a 
     501     * @param WP_User $b 
     502     * @return int result of a string compare of the user's recent activity. 
     503     */ 
     504    function _user_cmp_activity($a, $b) { 
     505        $a_activity = $this->get_user_last_activity($a->user_id); 
     506        $b_activity = $this->get_user_last_activity($b->user_id); 
     507         
     508        return $this->_sort_direction() * strcasecmp($a_activity, $b_activity); 
     509    } 
     510     
     511    /** 
     512     * Returns the time of last activity for a given user.  
     513     * 
     514     * This requires that either BuddyPress or the WP-UserOnline plugin is installed. 
     515     * If neither is available the function returns an empty string. 
     516     * 
     517     * @param int $user_id 
     518     * @return string last activity date 
     519     */ 
     520    function get_user_last_activity($user_id) { 
     521        if (AA_is_bp()) { 
     522            return gmdate( 'Y-m-d H:i:s', (int)get_usermeta( $user_id, 'last_activity' ) ); 
     523        } 
     524        if (function_exists('get_memberlastvisit') ) { 
     525            return gmdate( 'Y-m-d H:i:s', (int)get_user_option( 'member_last_login', $user_id )); 
     526        } 
     527        return ""; 
    490528    } 
    491529     
  • author-avatars/trunk/lib/helper.functions.php

    r111030 r120577  
    1010    global $wpmu_version, $wp_version; 
    1111    return (bool) ( (isset($wpmu_version)) || (strpos($wp_version, 'wordpress-mu')) ); 
     12} 
     13endif; 
     14 
     15/** 
     16 * Helper function which checks whether we are running wpmu 
     17 * 
     18 * @return bool true if we are on a wordpress mu system, false otherwise. 
     19 */ 
     20if (!function_exists('AA_is_bp')): 
     21function AA_is_bp() { 
     22    return defined('BP_CORE_VERSION'); 
    1223} 
    1324endif; 
Note: See TracChangeset for help on using the changeset viewer.