Skip to:
Content

BuddyPress.org

Changeset 2168


Ignore:
Timestamp:
12/14/2009 03:24:05 PM (15 years ago)
Author:
apeatling
Message:

Committing core code support for new default theme.

Removed all deprecated code since it will be released as a separate plugin for backwards compatibility if people need it.

Removed the wire and status updates components since there is no support in the theme for these. If people still want this functionality then I'm sure there is someone in the community that could spend a bit of time and release them as plugins. I'm happy to guide.

Removed a lot of template loop duplication. There are no longer site loops and user loops (e.g. bp_has_site_groups() / bp_has_groups() ). There are now bp_has_members(), bp_has_groups(), bp_has_blogs() and you can pass a "user_id" parameter into these loops to limit results to only that user or users.

Merged activity stream functions. There are no longer functions for bp_activity_get_sitewide() / bp_activity_get_for_user() / bp_activity_get_friends_activity() instead there is simply one function: bp_activity_get() and you can pass in parameters to filter on just friends, for a single user, or anything your heart desires. Actually, filtering is extremely fine grained, so I encourage devs to check out the filter functions.

Lots of other code cleanup.

The new default theme will be committed straight after this. The original default folder will be renamed to bp-classic.

Location:
trunk
Files:
10 deleted
49 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2158 r2168  
    99require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-classes.php' );
    1010require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-templatetags.php' );
    11 require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-widgets.php' );
    1211require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-filters.php' );
    13 
    14 /* Include deprecated functions if settings allow */
    15 if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
    16     require ( BP_PLUGIN_DIR . '/bp-activity/deprecated/bp-activity-deprecated.php' );
    1712
    1813function bp_activity_install() {
     
    122117function bp_activity_screen_my_activity() {
    123118    do_action( 'bp_activity_screen_my_activity' );
    124     bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'activity/just-me' ) );
     119    bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/activity' ) );
    125120}
    126121
     
    173168    }
    174169
    175     bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'activity/single' ) );
     170    bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
    176171}
    177172/* This screen is not attached to a nav item, so we need to add an action for it. */
     
    307302 */
    308303
    309 function bp_activity_get_sitewide( $args = '' ) {
     304function bp_activity_get( $args = '' ) {
    310305    $defaults = array(
    311306        'max' => false, // Maximum number of results to return
     
    319314
    320315        /**
    321          * Pass filters as an array:
     316         * Pass filters as an array -- all filter items can be multiple values comma separated:
    322317         * array(
    323318         *  'user_id' => false, // user_id to filter on
     
    334329    extract( $r, EXTR_SKIP );
    335330
    336     return apply_filters( 'bp_activity_get_sitewide', BP_Activity_Activity::get_sitewide_activity( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden ), &$r );
    337 }
    338 
    339 function bp_activity_get_for_user( $args = '' ) {
    340     global $bp;
    341 
    342     $defaults = array(
    343         'user_id' => $bp->displayed_user->id,
    344         'max' => false, // Maximum number of results to return
    345         'page' => 1, // page 1 without a per_page will result in no pagination.
    346         'per_page' => false, // results per page
    347         'sort' => 'DESC', // sort ASC or DESC
    348         'display_comments' => 'stream', // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
    349 
    350         'search_terms' => false, // Pass search terms as a string
    351         'show_hidden' => false, // Show activity items that are hidden site-wide?
    352 
    353         /* See bp_activity_get_sitewide() for filters */
    354         'filter' => array()
    355     );
    356 
    357     $r = wp_parse_args( $args, $defaults );
    358     extract( $r, EXTR_SKIP );
    359 
    360     return apply_filters( 'bp_activity_get_for_user', BP_Activity_Activity::get_activity_for_user( $user_id, $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden ), &$r );
    361 }
    362 
    363 function bp_activity_get_friends_activity( $user_id, $max = 30, $max_items_per_friend = false, $pag_num = false, $pag_page = false, $filter = false ) {
    364     return apply_filters( 'bp_activity_get_friends_activity', BP_Activity_Activity::get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $pag_num, $pag_page, $filter ), $user_id, $max_items, $max_items_per_friend, $pag_num, $pag_page, $filter );
     331    return apply_filters( 'bp_activity_get', BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden ), &$r );
    365332}
    366333
     
    537504}
    538505
     506/**
     507 * bp_activity_filter_template_paths()
     508 *
     509 * Add fallback for the bp-sn-parent theme template locations used in BuddyPress versions
     510 * older than 1.2.
     511 *
     512 * @package BuddyPress Core
     513 */
     514function bp_activity_filter_template_paths() {
     515    if ( 'bp-sn-parent' != basename( TEMPLATEPATH ) && !defined( 'BP_CLASSIC_TEMPLATE_STRUCTURE' ) )
     516        return false;
     517
     518    add_filter( 'bp_activity_template_my_activity', create_function( '', 'return "activity/just-me";' ) );
     519    add_filter( 'bp_activity_template_friends_activity', create_function( '', 'return "activity/my-friends";' ) );
     520    add_filter( 'bp_activity_template_profile_activity_permalink', create_function( '', 'return "activity/single";' ) );
     521
     522    /* Activity widget should only be available to older themes since the new default has it all in the template */
     523    require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-widgets.php' );
     524}
     525add_action( 'widgets_init', 'bp_activity_filter_template_paths' );
     526
    539527function bp_activity_remove_data( $user_id ) {
    540528    // Clear the user's activity from the sitewide stream and clear their activity tables
     
    547535add_action( 'make_spam_user', 'bp_activity_remove_data' );
    548536
    549 /* Ordering function - don't call this directly */
    550 function bp_activity_order_by_date( $a, $b ) {
    551     return apply_filters( 'bp_activity_order_by_date', strcasecmp( $b['date_recorded'], $a['date_recorded'] ) );
    552 }
    553 
    554537?>
  • trunk/bp-activity/bp-activity-classes.php

    r2158 r2168  
    163163    }
    164164
    165     function get_activity_for_user( $user_id, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
    166         global $wpdb, $bp;
    167 
    168         if ( $limit && $page )
    169             $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    170 
    171         if ( $max )
    172             $max_sql = $wpdb->prepare( "LIMIT %d", $max );
    173 
    174         /* Searching */
    175         if ( $search_terms ) {
    176             $search_terms = $wpdb->escape( $search_terms );
    177             $search_sql = "AND content LIKE '%%" . like_escape( $search_terms ) . "%%'";
    178         }
    179 
    180         /* Filtering */
    181         if ( $filter ) {
    182             unset($filter['user_id']); // Unset duplicate user_id filter - TODO: merge all to sitewide.
    183             $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
    184         }
    185 
    186         /* Sorting */
    187         if ( $sort != 'ASC' && $sort != 'DESC' )
    188             $sort = 'DESC';
    189 
    190         /* Hide Hidden Items? */
    191         if ( !$show_hidden )
    192             $hidden_sql = "AND hide_sitewide = 0";
    193 
    194         /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
    195         if ( !$display_comments || 'threaded' == $display_comments ) {
    196             if ( $per_page && $page && $max )
    197                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
    198             else
    199                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
    200 
    201             $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
    202 
    203             if ( $activities && $display_comments )
    204                 $activities = BP_Activity_Activity::append_comments( &$activities );
    205         } else {
    206             if ( $per_page && $page && $max )
    207                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
    208             else
    209                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
    210 
    211             $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
    212 
    213             if ( $activities )
    214                 $activities = BP_Activity_Activity::append_comments( &$activities );
    215         }
    216 
    217         return array( 'activities' => $activities, 'total' => (int)$total_activities );
    218     }
    219 
    220     function get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $limit, $page, $filter ) {
    221         global $wpdb, $bp;
    222 
    223         // TODO: Max items per friend not yet implemented.
    224 
    225         if ( !function_exists('friends_get_friend_user_ids') )
    226             return false;
    227 
    228         if ( $limit && $page )
    229             $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    230 
    231         if ( $max_items )
    232             $max_sql = $wpdb->prepare( "LIMIT %d", $max_items );
    233 
    234         /* Sort out filtering */
    235         if ( $filter )
    236             $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
    237 
    238         $friend_ids = friends_get_friend_user_ids( $user_id );
    239 
    240         if ( !$friend_ids )
    241             return false;
    242 
    243         $friend_ids = $wpdb->escape( implode( ',', $friend_ids ) );
    244 
    245         if ( $limit && $page && $max_items )
    246             $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql"  ) );
    247         else
    248             $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql" ) );
    249 
    250         $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) );
    251 
    252         return array( 'activities' => $activities, 'total' => (int)$total_activities );
    253     }
    254 
    255     function get_sitewide_activity( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
     165    function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
    256166        global $wpdb, $bp;
    257167
     
    285195        if ( !$display_comments || 'threaded' == $display_comments ) {
    286196            $where_conditions[] = "component_action != 'activity_comment'";
    287             $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
    288 
    289             if ( $per_page && $page && $max )
    290                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql}" ) );
    291             else
    292                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}" ) );
    293 
    294             $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
    295 
    296             if ( $activities && $display_comments )
    297                 $activities = BP_Activity_Activity::append_comments( &$activities );
    298         } else {
    299             /***
    300              * If we are filtering, this is going to stop activity comments showing in the stream,
    301              * we will need to do things slightly differently.
    302              */
    303             if ( !empty( $where_conditions ) )
    304                 $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
    305 
    306              if ( !empty( $filter_sql ) ) {
    307                 $all_activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY id {$sort}" ) );
    308 
    309                 foreach ( (array)$all_activities as $activity ) {
    310                     $tmp_activities[$activity->id] = $activity;
    311                     $a_ids[] = $activity->id;
    312                 }
    313                 $activity_ids = $wpdb->escape( implode( ',', $a_ids ) );
    314 
    315                 /* Fetch the comments for the activity items */
    316                 $search_sql = $where_conditions['search_sql'];
    317                 $all_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE item_id IN ({$activity_ids}) {$search_sql} ORDER BY id {$sort}" ) );
    318 
    319                 foreach ( (array)$all_comments as $comment ) {
    320                     $tmp_comments[$comment->id] = $comment;
    321                 }
    322 
    323                 /* Merge, sort and splice the activities and comments */
    324                 $activities = $tmp_comments + $tmp_activities;
    325                 ksort( $activities );
    326                 $activities = array_reverse( array_merge( array(), (array)$activities ) );
    327                 $activities = array_slice( (array)$activities, intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
    328 
    329                 /* Fetch the totals */
    330                 $total_activities = count($all_activities) + count($all_comments);
    331 
    332              } else {
    333                 if ( $per_page && $page && $max )
    334                     $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY id {$sort} {$pag_sql}" ) );
    335                 else
    336                     $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY id {$sort} {$pag_sql} {$max_sql}" ) );
    337 
    338                 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
    339              }
    340 
    341             /* Append threaded comments to those activites that have them */
    342             if ( $activities )
    343                 $activities = BP_Activity_Activity::append_comments( &$activities );
    344         }
     197        }
     198
     199        $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
     200
     201        if ( $per_page && $page && $max )
     202            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql}" ) );
     203        else
     204            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}" ) );
     205
     206        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
     207
     208        if ( $activities && $display_comments )
     209            $activities = BP_Activity_Activity::append_comments( &$activities );
    345210
    346211        return array( 'activities' => $activities, 'total' => (int)$total_activities );
  • trunk/bp-activity/bp-activity-filters.php

    r2138 r2168  
    44add_filter( 'bp_get_activity_content', 'bp_activity_filter_kses', 1 );
    55add_filter( 'bp_get_activity_parent_content', 'bp_activity_filter_kses', 1 );
     6add_filter( 'bp_get_activity_latest_update', 'bp_activity_filter_kses', 1 );
    67
    78add_filter( 'bp_get_activity_content', 'force_balance_tags' );
     9add_filter( 'bp_get_activity_latest_update', 'force_balance_tags' );
    810
    911add_filter( 'bp_get_activity_content', 'wptexturize' );
    1012add_filter( 'bp_get_activity_parent_content', 'wptexturize' );
     13add_filter( 'bp_get_activity_latest_update', 'wptexturize' );
    1114
    1215add_filter( 'bp_get_activity_content', 'convert_smilies' );
    1316add_filter( 'bp_get_activity_parent_content', 'convert_smilies' );
     17add_filter( 'bp_get_activity_latest_update', 'convert_smilies' );
    1418
    1519add_filter( 'bp_get_activity_content', 'convert_chars' );
    1620add_filter( 'bp_get_activity_parent_content', 'convert_chars' );
     21add_filter( 'bp_get_activity_latest_update', 'convert_chars' );
    1722
    1823add_filter( 'bp_get_activity_content', 'wpautop' );
     
    2025add_filter( 'bp_get_activity_content', 'make_clickable' );
    2126add_filter( 'bp_get_activity_parent_content', 'make_clickable' );
     27add_filter( 'bp_get_activity_latest_update', 'make_clickable' );
    2228
    2329add_filter( 'bp_get_activity_content', 'stripslashes_deep' );
    2430add_filter( 'bp_get_activity_parent_content', 'stripslashes_deep' );
     31add_filter( 'bp_get_activity_latest_update', 'stripslashes_deep' );
    2532
    2633add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
  • trunk/bp-activity/bp-activity-templatetags.php

    r2158 r2168  
    77    var $activities;
    88    var $activity;
    9     var $activity_type;
    109
    1110    var $in_the_loop;
     
    1716    var $full_name;
    1817
    19     function bp_activity_template( $type, $user_id, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden ) {
     18    function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden ) {
    2019        global $bp;
    2120
    22         $this->pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : 1;
     21        $this->pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : $page;
    2322        $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    24         $this->activity_type = $type;
    2523
    2624        if ( !empty( $include ) ) {
    2725            /* Fetch specific activity items based on ID's */
    28             $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $page, 'per_page' => $per_page, 'sort' => $sort, 'display_comments' => $display_comments ) );
     26            $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments ) );
    2927        } else {
    30             if ( $type == 'sitewide' )
    31                 $this->activities = bp_activity_get_sitewide( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) );
    32 
    33             if ( $type == 'personal' )
    34                 $this->activities = bp_activity_get_for_user( array( 'user_id' => $user_id, 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) );
    35 
    36             if ( $type == 'friends' && ( bp_is_home() || is_site_admin() || $bp->loggedin_user->id == $user_id ) )
    37                 $this->activities = bp_activity_get_friends_activity( $user_id, $max, false, $this->pag_num, $this->pag_page, $filter );
     28            $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) );
    3829        }
    3930
     
    123114
    124115    $defaults = array(
    125         'type' => 'sitewide',
    126116        'display_comments' => false, // false for none, stream/threaded - show comments in the stream or threaded under items
    127117        'include' => false, // pass an activity_id or string of ID's comma separated
    128118        'sort' => 'DESC', // sort DESC or ASC
     119        'page' => 1, // which page to load
    129120        'per_page' => 25, // number of items per page
    130121        'max' => false, // max number to return
     
    162153        $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
    163154
    164     $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
     155    $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
    165156
    166157    return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template );
     
    352343    }
    353344
    354     if ( 'activity_comment' == $activities_template->activity->component_action )
    355         $meta = '</span> <span class="activity-header-meta"> &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activities_template->activity->item_id . '">' . __( 'View Thread', 'buddypress' ) . '</a>';
    356     else
    357         $meta = '</span> <span class="activity-header-meta"> &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activities_template->activity->id . '">' . __( 'Permalink', 'buddypress' ) . '</a>';
     345    if ( !bp_is_activity_permalink() ) {
     346        if ( 'activity_comment' == $activities_template->activity->component_action )
     347            $meta = '</span> <span class="activity-header-meta"> &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activities_template->activity->item_id . '">' . __( 'View Thread', 'buddypress' ) . '</a>';
     348        else
     349            $meta = '</span> <span class="activity-header-meta"> &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activities_template->activity->id . '">' . __( 'View Thread', 'buddypress' ) . '</a>';
     350    }
    358351
    359352    /* Add the delete link if the user has permission on this item */
    360353    if ( ( $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || is_site_admin() )
    361          $meta .= ' &middot;' . bp_get_activity_delete_link();
     354         $meta .= ' &middot; ' . bp_get_activity_delete_link();
    362355
    363356    $content[1] = $meta . '</span>' . $content[1];
     
    535528
    536529        return apply_filters( 'bp_get_activity_delete_link', '<a href="' . wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/' . $activities_template->activity->id, 'bp_activity_delete_link' ) . '" class="item-button delete-activity confirm">' . __( 'Delete', 'buddypress' ) . '</a>' );
     530    }
     531
     532function bp_activity_latest_update( $user_id = false ) {
     533    echo bp_get_activity_latest_update( $user_id );
     534}
     535    function bp_get_activity_latest_update( $user_id = false ) {
     536        global $bp;
     537
     538        if ( !$user_id )
     539            $user_id = $bp->displayed_user->id;
     540
     541        if ( !$update = get_usermeta( $user_id, 'bp_latest_update' ) )
     542            return false;
     543
     544        $latest_update = '&quot;' . strip_tags( bp_create_excerpt( $update['content'], 40 ) ) . '&quot;';
     545        $latest_update .= ' &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '/"> ' . __( 'View Thread', 'buddypress' ) . '</a>';
     546
     547        return apply_filters( 'bp_get_activity_latest_update', $latest_update  );
    537548    }
    538549
  • trunk/bp-activity/bp-activity-widgets.php

    r2158 r2168  
    11<?php
    2 
    3 /* Register widgets for blogs component */
    4 function bp_activity_register_widgets() {
    5     add_action('widgets_init', create_function('', 'return register_widget("BP_Activity_Widget");') );
    6 }
    7 add_action( 'plugins_loaded', 'bp_activity_register_widgets' );
    82
    93class BP_Activity_Widget extends WP_Widget {
     
    9690        </div>
    9791
    98 
    9992        <div class="activity">
    10093            <?php // The loop will be loaded here via AJAX on page load to retain settings. ?>
     
    130123    }
    131124}
     125register_widget( "BP_Activity_Widget" );
    132126
    133127function bp_activity_widget_loop( $type = 'all', $filter = false, $query_string = false, $per_page = 20 ) {
     
    166160
    167161        <?php if ( !$_POST['acpage'] || 1 == $_POST['acpage'] ) : ?>
    168             <ul id="site-wide-stream" class="activity-list">
     162            <ul id="site-wide-stream" class="activity-list item-list">
    169163        <?php endif; ?>
    170164
     
    172166            <li class="<?php bp_activity_css_class() ?>" id="activity-<?php bp_activity_id() ?>">
    173167                <div class="activity-avatar">
    174                     <?php bp_activity_avatar('width=40&height=40') ?>
     168                    <?php bp_activity_avatar('type=full&width=40&height=40') ?>
    175169                </div>
    176170
  • trunk/bp-blogs.php

    r2120 r2168  
    1010require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-templatetags.php' );
    1111require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-widgets.php' );
    12 
    13 /* Include deprecated functions if settings allow */
    14 if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
    15     require ( BP_PLUGIN_DIR . '/bp-blogs/deprecated/bp-blogs-deprecated.php' );
    1612
    1713function bp_blogs_install() {
     
    145141
    146142    /* Add 'Blogs' to the main navigation */
    147     bp_core_new_nav_item( array( 'name' => __( 'Blogs', 'buddypress' ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
     143    bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs (%d)', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
    148144
    149145    $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
     
    153149    bp_core_new_subnav_item( array( 'name' => __( 'Recent Posts', 'buddypress' ), 'slug' => 'recent-posts', 'parent_url' => $blogs_link, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_recent_posts', 'position' => 20 ) );
    154150    bp_core_new_subnav_item( array( 'name' => __( 'Recent Comments', 'buddypress' ), 'slug' => 'recent-comments', 'parent_url' => $blogs_link, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_recent_comments', 'position' => 30 ) );
    155     bp_core_new_subnav_item( array( 'name' => __( 'Create a Blog', 'buddypress' ), 'slug' => 'create-a-blog', 'parent_url' => $blogs_link, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_create_a_blog', 'position' => 40 ) );
    156151
    157152    /* Set up the component options navigation for Blog */
     
    180175
    181176        do_action( 'bp_blogs_directory_blogs_setup' );
    182         bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'directories/blogs/index' ) );
     177        bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'blogs/index' ) );
    183178    }
    184179}
     
    196191function bp_blogs_screen_my_blogs() {
    197192    do_action( 'bp_blogs_screen_my_blogs' );
    198     bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'blogs/my-blogs' ) );
     193    bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/blogs' ) );
    199194}
    200195
    201196function bp_blogs_screen_recent_posts() {
    202197    do_action( 'bp_blogs_screen_recent_posts' );
    203     bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'blogs/recent-posts' ) );
     198    bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/blogs' ) );
    204199}
    205200
    206201function bp_blogs_screen_recent_comments() {
    207202    do_action( 'bp_blogs_screen_recent_comments' );
    208     bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'blogs/recent-comments' ) );
     203    bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/blogs' ) );
    209204}
    210205
    211206function bp_blogs_screen_create_a_blog() {
     207    global $bp;
     208
     209    if ( $bp->current_component != $bp->blogs->slug || 'create' != $bp->current_action )
     210        return false;
     211
     212    if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
     213        return false;
     214
    212215    do_action( 'bp_blogs_screen_create_a_blog' );
    213216    bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
    214217}
     218/* The create screen is not attached to a nav item, so we need to attach it to an action */
     219add_action( 'wp', 'bp_blogs_screen_create_a_blog', 3 );
    215220
    216221
     
    599604add_action( 'delete_comment', 'bp_blogs_remove_comment' );
    600605
     606function bp_blogs_total_blogs() {
     607    $blogs = BP_Blogs_Blog::get_all();
     608    return $blogs['total'];
     609}
     610
     611function bp_blogs_total_blogs_for_user( $user_id = false ) {
     612    global $bp;
     613
     614    if ( !$user_id )
     615        $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
     616
     617    return BP_Blogs_Blog::total_blog_count_for_user( $user_id );
     618}
     619
    601620function bp_blogs_remove_data_for_blog( $blog_id ) {
    602621    global $bp;
     
    775794    return true;
    776795}
     796
     797/**
     798 * bp_blogs_filter_template_paths()
     799 *
     800 * Add fallback for the bp-sn-parent theme template locations used in BuddyPress versions
     801 * older than 1.2.
     802 *
     803 * @package BuddyPress Core
     804 */
     805function bp_blogs_filter_template_paths() {
     806    if ( 'bp-sn-parent' != basename( TEMPLATEPATH ) && !defined( 'BP_CLASSIC_TEMPLATE_STRUCTURE' ) )
     807        return false;
     808
     809    add_filter( 'bp_blogs_template_directory_blogs_setup', create_function( '', 'return "directories/blogs/index";' ) );
     810    add_filter( 'bp_blogs_template_my_blogs', create_function( '', 'return "blogs/my-blogs";' ) );
     811    add_filter( 'bp_blogs_template_recent_posts', create_function( '', 'return "blogs/recent-posts";' ) );
     812    add_filter( 'bp_blogs_template_recent_comments', create_function( '', 'return "blogs/recent-comments";' ) );
     813    add_filter( 'bp_blogs_template_create_a_blog', create_function( '', 'return "blogs/create";' ) );
     814}
     815add_action( 'init', 'bp_blogs_filter_template_paths' );
    777816
    778817function bp_blogs_remove_data( $user_id ) {
  • trunk/bp-blogs/bp-blogs-classes.php

    r2114 r2168  
    105105    }
    106106
    107     function get_blogs_for_user( $user_id = null ) {
     107    function get_blogs_for_user( $user_id = false ) {
    108108        global $bp, $wpdb;
    109109
     
    120120            $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.id, bm1.meta_value as name, bm2.meta_value as description, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1, {$bp->blogs->table_name_blogmeta} bm2 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND b.blog_id = bm2.blog_id AND bm1.meta_key = 'name' AND bm2.meta_key = 'description' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) );
    121121
    122         $total_blog_count = BP_Blogs_Blog::total_blog_count( $user_id );
     122        $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
    123123
    124124        foreach ( (array)$blogs as $blog ) {
     
    133133    }
    134134
     135    function get_blog_ids_for_user( $user_id = false ) {
     136        global $bp, $wpdb;
     137
     138        if ( !$bp->blogs )
     139            bp_blogs_setup_globals();
     140
     141        if ( !$user_id )
     142            $user_id = $bp->displayed_user->id;
     143
     144        return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
     145    }
     146
    135147    function is_recorded( $blog_id ) {
    136148        global $bp, $wpdb;
     
    142154    }
    143155
    144     function total_blog_count( $user_id = null ) {
     156    function total_blog_count_for_user( $user_id = null ) {
    145157        global $bp, $wpdb;
    146158
     
    152164
    153165        // If the user is logged in return the blog count including their hidden blogs.
    154         if ( !bp_is_home() )
     166        if ( !is_user_logged_in() || $user_id != $bp->loggedin_user->id )
    155167            return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
    156168        else
     
    164176            bp_blogs_setup_globals();
    165177
    166         if ( $limit && $page ) {
     178        if ( $limit && $page )
    167179            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    168             $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' ORDER BY CONVERT(bm.meta_value, SIGNED) DESC" ) );
    169         }
    170 
    171         $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' ORDER BY CONVERT(bm.meta_value, SIGNED) DESC {$pag_sql}" ) );
     180
     181        $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$pag_sql}" ) );
     182        $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0" ) );
    172183
    173184        return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     
    182193        $letter = like_escape( $wpdb->escape( $letter ) );
    183194
    184         if ( $limit && $page ) {
     195        if ( $limit && $page )
    185196            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    186             $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' AND wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" ) );
    187         }
    188197
    189198        $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' AND wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" ) );
     199        $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' AND wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" ) );
    190200
    191201        return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     
    200210        $filter = like_escape( $wpdb->escape( $filter ) );
    201211
    202         if ( $limit && $page ) {
     212        if ( $limit && $page )
    203213            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    204             $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) AND wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" ) );
    205         }
    206214
    207215        $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) AND wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" ) );
     216        $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) AND wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" ) );
    208217
    209218        return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
    210219    }
    211220
    212     function get_random( $limit = null, $page = null ) {
    213         global $bp, $wpdb;
    214 
    215         if ( !$bp->blogs )
    216             bp_blogs_setup_globals();
    217 
    218         if ( $limit && $page ) {
     221    function get_random( $limit = null, $page = null, $user_id = false, $search_terms = false ) {
     222        global $bp, $wpdb;
     223
     224        if ( !$bp->blogs )
     225            bp_blogs_setup_globals();
     226
     227        if ( $limit && $page )
    219228            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    220             $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY rand()" ) );
    221         }
    222 
    223         $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0  ORDER BY rand() {$pag_sql}" ) );
     229
     230        if ( $user_id ) {
     231            $blog_ids = $wpdb->escape( implode( ',', (array)BP_Blogs_Blog::get_blog_ids_for_user( $user_id) ) );
     232            $user_sql = $wpdb->prepare( " AND b.blog_id IN ( {$blog_ids} ) ");
     233        }
     234
     235        $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$user_sql} ORDER BY rand() {$pag_sql}" ) );
     236        $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$user_sql} ORDER BY rand()" ) );
    224237
    225238        return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
    226239    }
    227240
    228     function get_active( $limit = null, $page = null ) {
    229         global $bp, $wpdb;
    230 
    231         if ( !$bp->blogs )
    232             bp_blogs_setup_globals();
    233 
    234         if ( $limit && $page ) {
     241    function get_active( $limit = null, $page = null, $user_id = false, $search_terms = false ) {
     242        global $bp, $wpdb;
     243
     244        if ( !$bp->blogs )
     245            bp_blogs_setup_globals();
     246
     247        if ( $limit && $page )
    235248            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    236             $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' ORDER BY CONVERT(bm.meta_value, SIGNED) DESC" ) );
    237         }
    238 
    239         $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' ORDER BY CONVERT(bm.meta_value, SIGNED) DESC {$pag_sql}" ) );
     249
     250        if ( $user_id ) {
     251            $blog_ids = $wpdb->escape( implode( ',', (array)BP_Blogs_Blog::get_blog_ids_for_user( $user_id ) ) );
     252
     253            if ( empty( $blog_ids ) )
     254                return false;
     255            else
     256                $user_sql = $wpdb->prepare( " AND b.blog_id IN ( {$blog_ids} ) " );
     257        }
     258
     259        if ( !empty( $search_terms ) ) {
     260            $filter = like_escape( $wpdb->escape( $search_terms ) );
     261            $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' AND ( ( bm2.meta_key = 'name' OR bm2.meta_key = 'description' ) AND bm2.meta_value LIKE '%%$filter%%' ) {$user_sql} ORDER BY CONVERT(bm.meta_value, SIGNED) DESC {$pag_sql}" ) );
     262            $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' AND ( ( bm2.meta_key = 'name' OR bm2.meta_key = 'description' ) AND bm2.meta_value LIKE '%%$filter%%' ) {$user_sql} ORDER BY CONVERT(bm.meta_value, SIGNED) DESC" ) );
     263        } else {
     264            $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' {$user_sql} ORDER BY CONVERT(bm.meta_value, SIGNED) DESC {$pag_sql}" ) );
     265            $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' {$user_sql} ORDER BY CONVERT(bm.meta_value, SIGNED) DESC" ) );
     266        }
    240267
    241268        return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
    242269    }
    243270
    244     function get_newest( $limit = null, $page = null ) {
    245         global $bp, $wpdb;
    246 
    247         if ( !$bp->blogs )
    248             bp_blogs_setup_globals();
    249 
    250         if ( $limit && $page ) {
     271    function get_alphabetical( $limit = null, $page = null, $user_id = false, $search_terms = false ) {
     272        global $bp, $wpdb;
     273
     274        if ( !$bp->blogs )
     275            bp_blogs_setup_globals();
     276
     277        if ( $limit && $page )
    251278            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    252             $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT wb.blog_id) FROM {$wpdb->base_prefix}blogs wb WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 ORDER BY wb.registered DESC" ) );
    253         }
    254 
    255         $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT wb.blog_id FROM {$wpdb->base_prefix}blogs wb WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 ORDER BY wb.registered DESC {$pag_sql}" ) );
     279
     280        if ( $user_id ) {
     281            $blog_ids = $wpdb->escape( implode( ',', (array)BP_Blogs_Blog::get_blog_ids_for_user( $user_id ) ) );
     282
     283            if ( empty( $blog_ids ) )
     284                return false;
     285            else
     286                $user_sql = $wpdb->prepare( " AND b.blog_id IN ( {$blog_ids} ) " );
     287        }
     288
     289        if ( !empty( $search_terms ) ) {
     290            $filter = like_escape( $wpdb->escape( $search_terms ) );
     291            $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$bp->blogs->table_name_blogmeta} bm3, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND b.blog_id = bm3.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' AND ( ( bm3.meta_key = 'name' OR bm3.meta_key = 'description' ) AND bm3.meta_value LIKE '%%$filter%%' ) {$user_sql} ORDER BY bm2.meta_value ASC {$pag_sql}" ) );
     292            $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$bp->blogs->table_name_blogmeta} bm3, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND b.blog_id = bm3.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' AND ( ( bm3.meta_key = 'name' OR bm3.meta_key = 'description' ) AND bm3.meta_value LIKE '%%$filter%%' ) {$user_sql}" ) );
     293        } else {
     294            $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' {$user_sql} ORDER BY bm2.meta_value ASC {$pag_sql}" ) );
     295            $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' {$user_sql}" ) );
     296        }
     297
     298        return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     299    }
     300
     301    function get_newest( $limit = null, $page = null, $user_id = false, $search_terms = false ) {
     302        global $bp, $wpdb;
     303
     304        if ( !$bp->blogs )
     305            bp_blogs_setup_globals();
     306
     307        if ( $limit && $page )
     308            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     309
     310        if ( $user_id ) {
     311            $blog_ids = $wpdb->escape( implode( ',', (array)BP_Blogs_Blog::get_blog_ids_for_user( $bp->loggedin_user->id ) ) );
     312
     313            if ( empty( $blog_ids ) )
     314                return false;
     315            else
     316                $user_sql = $wpdb->prepare( " AND b.blog_id IN ( {$blog_ids} ) " );
     317        }
     318
     319        if ( !empty( $search_terms ) ) {
     320            $filter = like_escape( $wpdb->escape( $search_terms ) );
     321            $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$user_sql} ORDER BY wb.registered DESC {$pag_sql}" ) );
     322            $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm WHERE b.blog_id = wb.blog_id AND b.blog_id = bm.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$user_sql} ORDER BY wb.registered DESC" ) );
     323        } else {
     324            $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT wb.blog_id FROM {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name} b WHERE wb.blog_id = b.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$user_sql} ORDER BY wb.registered DESC {$pag_sql}" ) );
     325            $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT wb.blog_id) FROM {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name} b WHERE wb.blog_id = b.blog_id AND wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$user_sql} ORDER BY wb.registered DESC" ) );
     326        }
    256327
    257328        return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
  • trunk/bp-blogs/bp-blogs-templatetags.php

    r2088 r2168  
    11<?php
    22
    3 /* Blog registration template tags */
    4 
    5 function bp_blog_signup_enabled() {
    6     $active_signup = get_site_option( 'registration' );
    7 
    8     if ( !$active_signup )
    9         $active_signup = 'all';
    10 
    11     $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
    12 
    13     if ( 'none' == $active_signup || 'user' == $active_signup )
    14         return false;
    15 
    16     return true;
    17 }
    18 
    19 function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
    20     global $current_user, $current_site;
    21     global $bp;
    22 
    23     require_once( ABSPATH . WPINC . '/registration.php' );
    24 
    25     if ( isset($_POST['submit']) ) {
    26         bp_blogs_validate_blog_signup();
    27     } else {
    28         if ( ! is_wp_error($errors) ) {
    29             $errors = new WP_Error();
    30         }
    31 
    32         // allow definition of default variables
    33         $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
    34         $blogname = $filtered_results['blogname'];
    35         $blog_title = $filtered_results['blog_title'];
    36         $errors = $filtered_results['errors'];
    37 
    38         if ( $errors->get_error_code() ) {
    39             echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";
    40         }
    41         ?>
    42         <p><?php printf(__("By filling out the form below, you can <strong>add a blog to your account</strong>. There is no limit to the number of blogs you can have, so create to your heart's content, but blog responsibly.", 'buddypress'), $current_user->display_name) ?></p>
    43 
    44         <p><?php _e("If you&#8217;re not going to use a great blog domain, leave it for a new user. Now have at it!", 'buddypress') ?></p>
    45 
    46         <form class="standard-form" id="setupform" method="post" action="<?php echo $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog' ?>">
    47 
    48             <input type="hidden" name="stage" value="gimmeanotherblog" />
    49             <?php do_action( "signup_hidden_fields" ); ?>
    50 
    51             <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
    52             <p>
    53                 <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog &raquo;', 'buddypress') ?>" />
    54             </p>
    55 
    56             <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
    57         </form>
    58         <?php
    59     }
    60 }
    61 
    62 function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
    63     global $current_site;
    64 
    65     // Blog name
    66     if( 'no' == constant( "VHOST" ) )
    67         echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';
    68     else
    69         echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>';
    70 
    71     if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
    72         <p class="error"><?php echo $errmsg ?></p>
    73     <?php }
    74 
    75     if( 'no' == constant( "VHOST" ) ) {
    76         echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
    77     } else {
    78         echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
    79     }
    80     if ( !is_user_logged_in() ) {
    81         print '(<strong>' . __( 'Your address will be ' , 'buddypress');
    82         if( 'no' == constant( "VHOST" ) ) {
    83             print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');
    84         } else {
    85             print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;
    86         }
    87         echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';
    88     }
    89 
    90     // Blog Title
    91     ?>
    92     <label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label>
    93     <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
    94         <p class="error"><?php echo $errmsg ?></p>
    95     <?php }
    96     echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></p>';
    97     ?>
    98 
    99     <p>
    100         <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
    101         <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress'); ?>
    102 
    103 
    104         <label class="checkbox" for="blog_public_on">
    105             <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if( !isset( $_POST['blog_public'] ) || '1' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
    106             <strong><?php _e( 'Yes' , 'buddypress'); ?></strong>
    107         </label>
    108         <label class="checkbox" for="blog_public_off">
    109             <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if( isset( $_POST['blog_public'] ) && '0' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
    110             <strong><?php _e( 'No' , 'buddypress'); ?></strong>
    111         </label>
    112     </p>
    113 
    114     <?php
    115     do_action('signup_blogform', $errors);
    116 }
    117 
    118 function bp_blogs_validate_blog_signup() {
    119     global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;
    120 
    121     if ( !check_admin_referer( 'bp_blog_signup_form' ) )
    122         return false;
    123 
    124     $current_user = wp_get_current_user();
    125 
    126     if( !is_user_logged_in() )
    127         die();
    128 
    129     $result = bp_blogs_validate_blog_form();
    130     extract($result);
    131 
    132     if ( $errors->get_error_code() ) {
    133         unset($_POST['submit']);
    134         bp_show_blog_signup_form( $blogname, $blog_title, $errors );
    135         return false;
    136     }
    137 
    138     $public = (int) $_POST['blog_public'];
    139 
    140     $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
    141     $meta = apply_filters( 'add_signup_meta', $meta );
    142 
    143     /* If this is a VHOST install, remove the username from the domain as we are setting this blog
    144        up inside a user domain, not the root domain. */
    145 
    146     wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
    147     bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
    148     return true;
    149 }
    150 
    151 function bp_blogs_validate_blog_form() {
    152     $user = '';
    153     if ( is_user_logged_in() )
    154         $user = wp_get_current_user();
    155 
    156     return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
    157 }
    158 
    159 function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
    160     ?>
    161     <p><?php _e('Congratulations! You have successfully registered a new blog.', 'buddypress') ?></p>
    162     <p>
    163         <?php printf(__('<a href="http://%1$s">http://%2$s</a> is your new blog.  <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress'), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name) ?>
    164     </p>
    165     <?php
    166     do_action('signup_finished');
    167 }
    168 
    169 function bp_create_blog_link() {
    170     global $bp;
    171 
    172     if ( bp_is_home() ) {
    173         echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog">' . __('Create a Blog', 'buddypress') . '</a>' );
    174     }
    175 }
    176 
    177 function bp_blogs_blog_tabs() {
    178     global $bp, $groups_template;
    179 
    180     // Don't show these tabs on a user's own profile
    181     if ( bp_is_home() )
    182         return false;
    183 
    184     $current_tab = $bp->current_action
    185 ?>
    186     <ul class="content-header-nav">
    187         <li<?php if ( 'my-blogs' == $current_tab || empty( $current_tab ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/my-blogs"><?php printf( __( "%s's Blogs", 'buddypress' ), $bp->displayed_user->fullname )  ?></a></li>
    188         <li<?php if ( 'recent-posts' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-posts"><?php printf( __( "%s's Recent Posts", 'buddypress' ), $bp->displayed_user->fullname )  ?></a></li>
    189         <li<?php if ( 'recent-comments' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-comments"><?php printf( __( "%s's Recent Comments", 'buddypress' ), $bp->displayed_user->fullname )  ?></a></li>
    190     </ul>
    191 <?php
    192     do_action( 'bp_blogs_blog_tabs', $current_tab );
    193 }
    194 
    1953/**********************************************************************
    196  * User Blog listing template class
     4 * Blog listing template class.
    1975 */
    1986
    199 class BP_Blogs_User_Blogs_Template {
     7class BP_Blogs_Template {
    2008    var $current_blog = -1;
    2019    var $blog_count;
     
    21018    var $total_blog_count;
    21119
    212     function bp_blogs_user_blogs_template( $user_id, $per_page, $max ) {
     20    function bp_blogs_template( $type, $page, $per_page, $max, $user_id, $search_terms ) {
    21321        global $bp;
    21422
    215         if ( !$user_id )
    216             $user_id = $bp->displayed_user->id;
    217 
    218         $this->pag_page = isset( $_GET['fpage'] ) ? intval( $_GET['fpage'] ) : 1;
    219         $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page;
    220 
    221         if ( !$this->blogs = wp_cache_get( 'bp_blogs_for_user_' . $user_id, 'bp' ) ) {
    222             $this->blogs = bp_blogs_get_blogs_for_user( $user_id );
    223             wp_cache_set( 'bp_blogs_for_user_' . $user_id, $this->blogs, 'bp' );
    224         }
    225 
    226         if ( !$max || $max >= (int)$this->blogs['count'] )
    227             $this->total_blog_count = (int)$this->blogs['count'];
     23        $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page;
     24        $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     25
     26        if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
     27            $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
     28        } else {
     29            switch ( $type ) {
     30                case 'random':
     31                    $this->blogs = BP_Blogs_Blog::get_random( $this->pag_num, $this->pag_page, $user_id, $search_terms );
     32                    break;
     33
     34                case 'alphabetical':
     35                    $this->blogs = BP_Blogs_Blog::get_alphabetical( $this->pag_num, $this->pag_page, $user_id, $search_terms );
     36                    break;
     37
     38                case 'newest':
     39                    $this->blogs = BP_Blogs_Blog::get_newest( $this->pag_num, $this->pag_page, $user_id, $search_terms );
     40                    break;
     41
     42                case 'active': default:
     43                    $this->blogs = BP_Blogs_Blog::get_active( $this->pag_num, $this->pag_page, $user_id, $search_terms );
     44                    break;
     45            }
     46        }
     47
     48        if ( !$max || $max >= (int)$this->blogs['total'] )
     49            $this->total_blog_count = (int)$this->blogs['total'];
    22850        else
    22951            $this->total_blog_count = (int)$max;
    23052
    231         $this->blogs = array_slice( (array)$this->blogs['blogs'], intval( ( $this->pag_page - 1 ) * $this->pag_num), intval( $this->pag_num ) );
     53        $this->blogs = $this->blogs['blogs'];
    23254
    23355        if ( $max ) {
     
    24163
    24264        $this->pag_links = paginate_links( array(
    243             'base' => add_query_arg( 'fpage', '%#%' ),
     65            'base' => add_query_arg( 'bpage', '%#%' ),
    24466            'format' => '',
    245             'total' => ceil($this->total_blog_count / $this->pag_num),
    246             'current' => $this->pag_page,
    247             'prev_text' => '&laquo;',
    248             'next_text' => '&raquo;',
     67            'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
     68            'current' => (int) $this->pag_page,
     69            'prev_text' => '&larr;',
     70            'next_text' => '&rarr;',
    24971            'mid_size' => 1
    25072        ));
     
    27294    }
    27395
    274     function user_blogs() {
     96    function blogs() {
    27597        if ( $this->current_blog + 1 < $this->blog_count ) {
    27698            return true;
     
    289111
    290112        $this->in_the_loop = true;
    291         $blog = $this->next_blog();
     113        $this->blog = $this->next_blog();
    292114
    293115        if ( 0 == $this->current_blog ) // loop has just started
     
    296118}
    297119
     120function bp_rewind_blogs() {
     121    global $blogs_template;
     122
     123    $blogs_template->rewind_blogs();
     124}
     125
    298126function bp_has_blogs( $args = '' ) {
    299127    global $blogs_template;
    300128
    301129    $defaults = array(
    302         'user_id' => false,
    303         'per_page' => 10,
    304         'max' => false
     130        'type' => 'active',
     131        'page' => 1,
     132        'per_page' => 20,
     133        'max' => false,
     134
     135        'user_id' => false, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
     136        'search_terms' => false // Pass search terms to filter on the blog title or description.
    305137    );
    306138
     
    308140    extract( $r, EXTR_SKIP );
    309141
    310     $blogs_template = new BP_Blogs_User_Blogs_Template( $user_id, $per_page, $max );
    311     return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
     142    // type: active ( default ) | random | newest | alphabetical
     143
     144    if ( !empty( $_REQUEST['s'] ) )
     145        $search_terms = $_REQUEST['s'];
     146
     147    if ( $max ) {
     148        if ( $per_page > $max )
     149            $per_page = $max;
     150    }
     151
     152    $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
     153
     154    return $blogs_template->has_blogs();
    312155}
    313156
    314157function bp_blogs() {
    315158    global $blogs_template;
    316     return $blogs_template->user_blogs();
     159
     160    return $blogs_template->blogs();
    317161}
    318162
    319163function bp_the_blog() {
    320164    global $blogs_template;
     165
    321166    return $blogs_template->the_blog();
    322167}
     
    341186    }
    342187
    343 function bp_blog_title() {
    344     echo bp_get_blog_title();
    345 }
    346     function bp_get_blog_title() {
     188function bp_blog_avatar() {
     189    echo bp_get_blog_avatar();
     190}
     191    function bp_get_blog_avatar() {
     192        global $blogs_template, $bp;
     193
     194        /***
     195         * In future BuddyPress versions you will be able to set the avatar for a blog.
     196         * Right now you can use a filter with the ID of the blog to change it if you wish.
     197         */
     198        return apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&amp;s=150" class="avatar blog-avatar" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $blogs_template->blog->blog_id );
     199    }
     200
     201function bp_blog_avatar_thumb() {
     202    echo bp_get_blog_avatar_thumb();
     203}
     204    function bp_get_blog_avatar_thumb() {
     205        global $blogs_template, $bp;
     206
     207        return apply_filters( 'bp_get_blog_avatar_thumb_' . $blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&amp;s=50" class="avatar blog-avatar thumb" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $blogs_template->blog->blog_id );
     208    }
     209
     210function bp_blog_avatar_mini() {
     211    echo bp_get_blog_avatar_mini();
     212}
     213    function bp_get_blog_avatar_mini() {
     214        global $blogs_template, $bp;
     215
     216        return apply_filters( 'bp_get_blog_avatar_mini_' . $blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&amp;s=25" class="avatar blog-avatar mini" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $blogs_template->blog->blog_id );
     217    }
     218
     219function bp_blog_permalink() {
     220    echo bp_get_blog_permalink();
     221}
     222    function bp_get_blog_permalink() {
    347223        global $blogs_template;
    348224
    349         return apply_filters( 'bp_get_blog_title', $blogs_template->blog->name );
     225        return apply_filters( 'bp_get_blog_permalink', get_blog_option( $blogs_template->blog->blog_id, 'siteurl' ) );
     226    }
     227
     228function bp_blog_name() {
     229    echo bp_get_blog_name();
     230}
     231    function bp_get_blog_name() {
     232        global $blogs_template;
     233
     234        return apply_filters( 'bp_get_blog_name', get_blog_option( $blogs_template->blog->blog_id, 'blogname' ) );
    350235    }
    351236
    352237function bp_blog_description() {
    353     echo bp_get_blog_description();
     238    echo apply_filters( 'bp_blog_description', bp_get_blog_description() );
    354239}
    355240    function bp_get_blog_description() {
    356241        global $blogs_template;
    357242
    358         return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
    359     }
    360 
    361 function bp_blog_permalink() {
    362     echo bp_get_blog_permalink();
    363 }
    364     function bp_get_blog_permalink() {
     243        return apply_filters( 'bp_get_blog_description', get_blog_option( $blogs_template->blog->blog_id, 'blogdescription' ) );
     244    }
     245
     246function bp_blog_last_active() {
     247    echo bp_get_blog_last_active();
     248}
     249    function bp_get_blog_last_active() {
    365250        global $blogs_template;
    366251
    367         return apply_filters( 'bp_get_blog_permalink', $blogs_template->blog->siteurl );
    368     }
    369 
     252        return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( bp_blogs_get_blogmeta( $blogs_template->blog->blog_id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) ) );
     253    }
     254
     255function bp_blog_latest_post() {
     256    echo bp_get_blog_latest_post();
     257}
     258    function bp_get_blog_latest_post() {
     259        global $blogs_template;
     260
     261        if ( $post = bp_blogs_get_latest_posts( $blogs_template->blog->blog_id, 1 ) ) {
     262            return apply_filters( 'bp_get_blog_latest_post', sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . bp_post_get_permalink( $post[0], $blogs_template->blog->blog_id ) . '">' . apply_filters( 'the_title', $post[0]->post_title ) . '</a>' ) );
     263        }
     264    }
     265
     266function bp_blog_hidden_fields() {
     267    if ( isset( $_REQUEST['s'] ) ) {
     268        echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ). '" name="search_terms" />';
     269    }
     270
     271    if ( isset( $_REQUEST['letter'] ) ) {
     272        echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
     273    }
     274
     275    if ( isset( $_REQUEST['blogs_search'] ) ) {
     276        echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
     277    }
     278}
     279
     280/***
     281 * Technically the template loops for blog posts and comments are deprecated.
     282 * Instead you should be using the activity stream template loop and filtering
     283 * on blog posts and blog comments either with or without a user_id.
     284 *
     285 * They remain here because they are used in the bp-sn-parent theme, but they
     286 * are running on thin ice.
     287 */
    370288
    371289/**********************************************************************
     
    1051969    }
    1052970
    1053 /**********************************************************************
    1054  * Site Wide Blog listing template class
    1055  */
    1056 
    1057 class BP_Blogs_Site_Blogs_Template {
    1058     var $current_blog = -1;
    1059     var $blog_count;
    1060     var $blogs;
    1061     var $blog;
    1062 
    1063     var $in_the_loop;
    1064 
    1065     var $pag_page;
    1066     var $pag_num;
    1067     var $pag_links;
    1068     var $total_blog_count;
    1069 
    1070     function bp_blogs_site_blogs_template( $type, $per_page, $max ) {
    1071         global $bp;
    1072 
    1073         $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : 1;
    1074         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    1075 
    1076         if ( isset( $_REQUEST['s'] ) && '' != $_REQUEST['s'] && $type != 'random' ) {
    1077             $this->blogs = BP_Blogs_Blog::search_blogs( $_REQUEST['s'], $this->pag_num, $this->pag_page );
    1078         } else if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
    1079             $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
     971
     972/* Blog registration template tags */
     973
     974function bp_blog_signup_enabled() {
     975    $active_signup = get_site_option( 'registration' );
     976
     977    if ( !$active_signup )
     978        $active_signup = 'all';
     979
     980    $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
     981
     982    if ( 'none' == $active_signup || 'user' == $active_signup )
     983        return false;
     984
     985    return true;
     986}
     987
     988function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
     989    global $current_user, $current_site;
     990    global $bp;
     991
     992    require_once( ABSPATH . WPINC . '/registration.php' );
     993
     994    if ( isset($_POST['submit']) ) {
     995        bp_blogs_validate_blog_signup();
     996    } else {
     997        if ( ! is_wp_error($errors) ) {
     998            $errors = new WP_Error();
     999        }
     1000
     1001        // allow definition of default variables
     1002        $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
     1003        $blogname = $filtered_results['blogname'];
     1004        $blog_title = $filtered_results['blog_title'];
     1005        $errors = $filtered_results['errors'];
     1006
     1007        if ( $errors->get_error_code() ) {
     1008            echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";
     1009        }
     1010        ?>
     1011        <p><?php printf(__("By filling out the form below, you can <strong>add a blog to your account</strong>. There is no limit to the number of blogs you can have, so create to your heart's content, but blog responsibly.", 'buddypress'), $current_user->display_name) ?></p>
     1012
     1013        <p><?php _e("If you&#8217;re not going to use a great blog domain, leave it for a new user. Now have at it!", 'buddypress') ?></p>
     1014
     1015        <form class="standard-form" id="setupform" method="post" action="">
     1016
     1017            <input type="hidden" name="stage" value="gimmeanotherblog" />
     1018            <?php do_action( "signup_hidden_fields" ); ?>
     1019
     1020            <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
     1021            <p>
     1022                <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog &raquo;', 'buddypress') ?>" />
     1023            </p>
     1024
     1025            <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
     1026        </form>
     1027        <?php
     1028    }
     1029}
     1030
     1031function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
     1032    global $current_site;
     1033
     1034    // Blog name
     1035    if( 'no' == constant( "VHOST" ) )
     1036        echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';
     1037    else
     1038        echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>';
     1039
     1040    if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
     1041        <p class="error"><?php echo $errmsg ?></p>
     1042    <?php }
     1043
     1044    if( 'no' == constant( "VHOST" ) ) {
     1045        echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
     1046    } else {
     1047        echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /> <span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
     1048    }
     1049    if ( !is_user_logged_in() ) {
     1050        print '(<strong>' . __( 'Your address will be ' , 'buddypress');
     1051        if( 'no' == constant( "VHOST" ) ) {
     1052            print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');
    10801053        } else {
    1081             switch ( $type ) {
    1082                 case 'random':
    1083                     $this->blogs = BP_Blogs_Blog::get_random( $this->pag_num, $this->pag_page );
    1084                     break;
    1085 
    1086                 case 'newest':
    1087                     $this->blogs = BP_Blogs_Blog::get_newest( $this->pag_num, $this->pag_page );
    1088                     break;
    1089 
    1090                 case 'active': default:
    1091                     $this->blogs = BP_Blogs_Blog::get_active( $this->pag_num, $this->pag_page );
    1092                     break;
    1093             }
    1094         }
    1095 
    1096         if ( !$max || $max >= (int)$this->blogs['total'] )
    1097             $this->total_blog_count = (int)$this->blogs['total'];
    1098         else
    1099             $this->total_blog_count = (int)$max;
    1100 
    1101         $this->blogs = $this->blogs['blogs'];
    1102 
    1103         if ( $max ) {
    1104             if ( $max >= count($this->blogs) )
    1105                 $this->blog_count = count($this->blogs);
    1106             else
    1107                 $this->blog_count = (int)$max;
    1108         } else {
    1109             $this->blog_count = count($this->blogs);
    1110         }
    1111 
    1112         $this->pag_links = paginate_links( array(
    1113             'base' => add_query_arg( 'bpage', '%#%' ),
    1114             'format' => '',
    1115             'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
    1116             'current' => (int) $this->pag_page,
    1117             'prev_text' => '&laquo;',
    1118             'next_text' => '&raquo;',
    1119             'mid_size' => 1
    1120         ));
    1121     }
    1122 
    1123     function has_blogs() {
    1124         if ( $this->blog_count )
    1125             return true;
    1126 
     1054            print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;
     1055        }
     1056        echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';
     1057    }
     1058
     1059    // Blog Title
     1060    ?>
     1061    <label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label>
     1062    <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
     1063        <p class="error"><?php echo $errmsg ?></p>
     1064    <?php }
     1065    echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></p>';
     1066    ?>
     1067
     1068    <p>
     1069        <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
     1070        <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress'); ?>
     1071
     1072
     1073        <label class="checkbox" for="blog_public_on">
     1074            <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if( !isset( $_POST['blog_public'] ) || '1' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
     1075            <strong><?php _e( 'Yes' , 'buddypress'); ?></strong>
     1076        </label>
     1077        <label class="checkbox" for="blog_public_off">
     1078            <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if( isset( $_POST['blog_public'] ) && '0' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
     1079            <strong><?php _e( 'No' , 'buddypress'); ?></strong>
     1080        </label>
     1081    </p>
     1082
     1083    <?php
     1084    do_action('signup_blogform', $errors);
     1085}
     1086
     1087function bp_blogs_validate_blog_signup() {
     1088    global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;
     1089
     1090    if ( !check_admin_referer( 'bp_blog_signup_form' ) )
    11271091        return false;
    1128     }
    1129 
    1130     function next_blog() {
    1131         $this->current_blog++;
    1132         $this->blog = $this->blogs[$this->current_blog];
    1133 
    1134         return $this->blog;
    1135     }
    1136 
    1137     function rewind_blogs() {
    1138         $this->current_blog = -1;
    1139         if ( $this->blog_count > 0 ) {
    1140             $this->blog = $this->blogs[0];
    1141         }
    1142     }
    1143 
    1144     function blogs() {
    1145         if ( $this->current_blog + 1 < $this->blog_count ) {
    1146             return true;
    1147         } elseif ( $this->current_blog + 1 == $this->blog_count ) {
    1148             do_action('loop_end');
    1149             // Do some cleaning up after the loop
    1150             $this->rewind_blogs();
    1151         }
    1152 
    1153         $this->in_the_loop = false;
     1092
     1093    $current_user = wp_get_current_user();
     1094
     1095    if( !is_user_logged_in() )
     1096        die();
     1097
     1098    $result = bp_blogs_validate_blog_form();
     1099    extract($result);
     1100
     1101    if ( $errors->get_error_code() ) {
     1102        unset($_POST['submit']);
     1103        bp_show_blog_signup_form( $blogname, $blog_title, $errors );
    11541104        return false;
    11551105    }
    11561106
    1157     function the_blog() {
    1158         global $blog;
    1159 
    1160         $this->in_the_loop = true;
    1161         $this->blog = $this->next_blog();
    1162 
    1163         if ( 0 == $this->current_blog ) // loop has just started
    1164             do_action('loop_start');
    1165     }
    1166 }
    1167 
    1168 function bp_rewind_site_blogs() {
    1169     global $site_blogs_template;
    1170 
    1171     $site_blogs_template->rewind_blogs();
    1172 }
    1173 
    1174 function bp_has_site_blogs( $args = '' ) {
    1175     global $site_blogs_template;
    1176 
    1177     $defaults = array(
    1178         'type' => 'active',
    1179         'per_page' => 10,
    1180         'max' => false
    1181     );
    1182 
    1183     $r = wp_parse_args( $args, $defaults );
    1184     extract( $r, EXTR_SKIP );
    1185 
    1186     // type: active ( default ) | random | newest | popular
    1187 
    1188     if ( $max ) {
    1189         if ( $per_page > $max )
    1190             $per_page = $max;
    1191     }
    1192 
    1193     $site_blogs_template = new BP_Blogs_Site_Blogs_Template( $type, $per_page, $max );
    1194 
    1195     return $site_blogs_template->has_blogs();
    1196 }
    1197 
    1198 function bp_site_blogs() {
    1199     global $site_blogs_template;
    1200 
    1201     return $site_blogs_template->blogs();
    1202 }
    1203 
    1204 function bp_the_site_blog() {
    1205     global $site_blogs_template;
    1206 
    1207     return $site_blogs_template->the_blog();
    1208 }
    1209 
    1210 function bp_site_blogs_pagination_count() {
    1211     global $bp, $site_blogs_template;
    1212 
    1213     $from_num = intval( ( $site_blogs_template->pag_page - 1 ) * $site_blogs_template->pag_num ) + 1;
    1214     $to_num = ( $from_num + ( $site_blogs_template->pag_num - 1 ) > $site_blogs_template->total_blog_count ) ? $site_blogs_template->total_blog_count : $from_num + ( $site_blogs_template->pag_num - 1 ) ;
    1215 
    1216     echo sprintf( __( 'Viewing blog %d to %d (of %d blogs)', 'buddypress' ), $from_num, $to_num, $site_blogs_template->total_blog_count ); ?> &nbsp;
    1217     <span class="ajax-loader"></span><?php
    1218 }
    1219 
    1220 function bp_site_blogs_pagination_links() {
    1221     echo bp_get_site_blogs_pagination_links();
    1222 }
    1223     function bp_get_site_blogs_pagination_links() {
    1224         global $site_blogs_template;
    1225 
    1226         return apply_filters( 'bp_get_site_blogs_pagination_links', $site_blogs_template->pag_links );
    1227     }
    1228 
    1229 function bp_the_site_blog_avatar() {
    1230     echo bp_get_the_site_blog_avatar();
    1231 }
    1232     function bp_get_the_site_blog_avatar() {
    1233         global $site_blogs_template, $bp;
    1234 
    1235         /***
    1236          * In future BuddyPress versions you will be able to set the avatar for a blog.
    1237          * Right now you can use a filter with the ID of the blog to change it if you wish.
    1238          */
    1239         return apply_filters( 'bp_get_blogs_blog_avatar_' . $site_blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $site_blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&amp;s=150" class="avatar blog-avatar" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $site_blogs_template->blog->blog_id );
    1240     }
    1241 
    1242 function bp_the_site_blog_avatar_thumb() {
    1243     echo bp_get_the_site_blog_avatar_thumb();
    1244 }
    1245     function bp_get_the_site_blog_avatar_thumb() {
    1246         global $site_blogs_template, $bp;
    1247 
    1248         return apply_filters( 'bp_get_blogs_blog_avatar_thumb_' . $site_blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $site_blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&amp;s=50" class="avatar blog-avatar thumb" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $site_blogs_template->blog->blog_id );
    1249     }
    1250 
    1251 function bp_the_site_blog_avatar_mini() {
    1252     echo bp_get_the_site_blog_avatar_mini();
    1253 }
    1254     function bp_get_the_site_blog_avatar_mini() {
    1255         global $site_blogs_template, $bp;
    1256 
    1257         return apply_filters( 'bp_get_blogs_blog_avatar_mini_' . $site_blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $site_blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&amp;s=25" class="avatar blog-avatar mini" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $site_blogs_template->blog->blog_id );
    1258     }
    1259 
    1260 function bp_the_site_blog_link() {
    1261     echo bp_get_the_site_blog_link();
    1262 }
    1263     function bp_get_the_site_blog_link() {
    1264         global $site_blogs_template;
    1265 
    1266         return apply_filters( 'bp_get_the_site_blog_link', get_blog_option( $site_blogs_template->blog->blog_id, 'siteurl' ) );
    1267     }
    1268 
    1269 function bp_the_site_blog_name() {
    1270     echo bp_get_the_site_blog_name();
    1271 }
    1272     function bp_get_the_site_blog_name() {
    1273         global $site_blogs_template;
    1274 
    1275         return apply_filters( 'bp_get_the_site_blog_name', get_blog_option( $site_blogs_template->blog->blog_id, 'blogname' ) );
    1276     }
    1277 
    1278 function bp_the_site_blog_description() {
    1279     echo apply_filters( 'bp_the_site_blog_description', bp_get_the_site_blog_description() );
    1280 }
    1281     function bp_get_the_site_blog_description() {
    1282         global $site_blogs_template;
    1283 
    1284         return apply_filters( 'bp_get_the_site_blog_description', get_blog_option( $site_blogs_template->blog->blog_id, 'blogdescription' ) );
    1285     }
    1286 
    1287 function bp_the_site_blog_last_active() {
    1288     echo bp_get_the_site_blog_last_active();
    1289 }
    1290     function bp_get_the_site_blog_last_active() {
    1291         global $site_blogs_template;
    1292 
    1293         return apply_filters( 'bp_the_site_blog_last_active', bp_core_get_last_activity( bp_blogs_get_blogmeta( $site_blogs_template->blog->blog_id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) ) );
    1294     }
    1295 
    1296 function bp_the_site_blog_latest_post() {
    1297     echo bp_get_the_site_blog_latest_post();
    1298 }
    1299     function bp_get_the_site_blog_latest_post() {
    1300         global $site_blogs_template;
    1301 
    1302         if ( $post = bp_blogs_get_latest_posts( $site_blogs_template->blog->blog_id, 1 ) ) {
    1303             return apply_filters( 'bp_get_the_site_blog_latest_post', sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . bp_post_get_permalink( $post[0], $site_blogs_template->blog->blog_id ) . '">' . apply_filters( 'the_title', $post[0]->post_title ) . '</a>' ) );
    1304         }
    1305     }
    1306 
    1307 function bp_the_site_blog_hidden_fields() {
    1308     if ( isset( $_REQUEST['s'] ) ) {
    1309         echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ). '" name="search_terms" />';
    1310     }
    1311 
    1312     if ( isset( $_REQUEST['letter'] ) ) {
    1313         echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    1314     }
    1315 
    1316     if ( isset( $_REQUEST['blogs_search'] ) ) {
    1317         echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
    1318     }
     1107    $public = (int) $_POST['blog_public'];
     1108
     1109    $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
     1110    $meta = apply_filters( 'add_signup_meta', $meta );
     1111
     1112    /* If this is a VHOST install, remove the username from the domain as we are setting this blog
     1113       up inside a user domain, not the root domain. */
     1114
     1115    wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
     1116    bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
     1117    return true;
     1118}
     1119
     1120function bp_blogs_validate_blog_form() {
     1121    $user = '';
     1122    if ( is_user_logged_in() )
     1123        $user = wp_get_current_user();
     1124
     1125    return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
     1126}
     1127
     1128function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
     1129    ?>
     1130    <p><?php _e('Congratulations! You have successfully registered a new blog.', 'buddypress') ?></p>
     1131    <p>
     1132        <?php printf(__('<a href="http://%1$s">http://%2$s</a> is your new blog.  <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress'), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name) ?>
     1133    </p>
     1134    <?php
     1135    do_action('signup_finished');
     1136}
     1137
     1138function bp_create_blog_link() {
     1139    global $bp;
     1140
     1141    if ( bp_is_home() ) {
     1142        echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog">' . __('Create a Blog', 'buddypress') . '</a>' );
     1143    }
     1144}
     1145
     1146function bp_blogs_blog_tabs() {
     1147    global $bp, $groups_template;
     1148
     1149    // Don't show these tabs on a user's own profile
     1150    if ( bp_is_home() )
     1151        return false;
     1152
     1153    $current_tab = $bp->current_action
     1154?>
     1155    <ul class="content-header-nav">
     1156        <li<?php if ( 'my-blogs' == $current_tab || empty( $current_tab ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/my-blogs"><?php printf( __( "%s's Blogs", 'buddypress' ), $bp->displayed_user->fullname )  ?></a></li>
     1157        <li<?php if ( 'recent-posts' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-posts"><?php printf( __( "%s's Recent Posts", 'buddypress' ), $bp->displayed_user->fullname )  ?></a></li>
     1158        <li<?php if ( 'recent-comments' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-comments"><?php printf( __( "%s's Recent Comments", 'buddypress' ), $bp->displayed_user->fullname )  ?></a></li>
     1159    </ul>
     1160<?php
     1161    do_action( 'bp_blogs_blog_tabs', $current_tab );
    13191162}
    13201163
     
    13281171}
    13291172
     1173function bp_total_blogs_for_user( $user_id = false ) {
     1174    global $bp;
     1175
     1176    if ( !$user_id )
     1177        $user_id = $bp->displayed_user->id;
     1178
     1179    return apply_filters( 'bp_total_blogs_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
     1180}
     1181
     1182function bp_get_total_blog_count() {
     1183    return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );
     1184}
    13301185
    13311186?>
  • trunk/bp-blogs/bp-blogs-widgets.php

    r1926 r2168  
    55    add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");') );
    66}
    7 add_action( 'plugins_loaded', 'bp_blogs_register_widgets' );
     7add_action( 'template_redirect', 'bp_blogs_register_widgets' );
    88
    99class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
     
    1414    function widget($args, $instance) {
    1515        global $bp;
    16        
     16
    1717        extract( $args );
    18        
     18
    1919        echo $before_widget;
    2020        echo $before_title
    21            . $widget_name 
     21           . $widget_name
    2222           . $after_title; ?>
    23    
     23
    2424        <?php
    2525        if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
    2626            $instance['max_posts'] = 10; ?>
    27        
     27
    2828        <?php $posts = bp_blogs_get_latest_posts( null, $instance['max_posts'] ) ?>
    2929        <?php $counter = 0; ?>
    30        
     30
    3131        <?php if ( $posts ) : ?>
    3232            <div class="item-options" id="recent-posts-options">
     
    4848                        </div>
    4949                    </li>
    50                     <?php $counter++; ?>   
     50                    <?php $counter++; ?>
    5151                <?php endforeach; ?>
    5252            </ul>
     
    5656            </div>
    5757        <?php endif; ?>
    58            
     58
    5959        <?php echo $after_widget; ?>
    6060    <?php
  • trunk/bp-core.php

    r2128 r2168  
    4343    require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
    4444
    45 /* If BP_IGNORE_DEPRECATED is defined, do not load any deprecated functions for backwards support */
    46 if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
    47     require ( BP_PLUGIN_DIR . '/bp-core/deprecated/bp-core-deprecated.php' );
    48 
    4945/* Define the slug for member pages and the members directory (e.g. domain.com/[members] ) */
    5046if ( !defined( 'BP_MEMBERS_SLUG' ) )
     
    6662if ( !defined( 'BP_HOME_BLOG_SLUG' ) )
    6763    define( 'BP_HOME_BLOG_SLUG', 'blog' );
    68 
    69 /* Register BuddyPress themes contained within the theme folder */
    70 if ( function_exists( 'register_theme_folder' ) )
    71     register_theme_folder( 'buddypress/bp-themes' );
    7264
    7365/* Register BuddyPress themes contained within the theme folder */
     
    381373
    382374/********************************************************************************
    383  * Screen Functions
    384  *
    385  * Screen functions are the controllers of BuddyPress. They will execute when their
    386  * specific URL is caught. They will first save or manipulate data using business
    387  * functions, then pass on the user to a template file.
    388  */
    389 
    390 
    391 /********************************************************************************
    392375 * Action Functions
    393376 *
     
    397380 */
    398381
    399 
    400382/**
    401383 * bp_core_action_directory_members()
     
    416398
    417399        do_action( 'bp_core_action_directory_members' );
    418         bp_core_load_template( apply_filters( 'bp_core_template_directory_members', 'directories/members/index' ) );
     400        bp_core_load_template( apply_filters( 'bp_core_template_directory_members', 'members/index' ) );
    419401    }
    420402}
     
    653635     * looking at their own profile, don't create the nav item.
    654636     */
    655     if ( !$show_for_displayed_user && !bp_is_home() )
     637    if ( !$show_for_displayed_user && !bp_is_my_profile() )
    656638        return false;
    657639
     
    11761158    $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) );
    11771159    return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) );
     1160}
     1161
     1162/**
     1163 * bp_core_get_total_member_count()
     1164 *
     1165 * Returns the total number of members for the installation.
     1166 *
     1167 * @package BuddyPress Core
     1168 * @return int The total number of members.
     1169 */
     1170function bp_core_get_total_member_count() {
     1171    global $wpdb;
     1172
     1173    $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0" ) );
     1174    return apply_filters( 'bp_core_get_total_member_count', (int)$count );
    11781175}
    11791176
     
    17601757 * bp_core_boot_spammer()
    17611758 *
    1762  * When a user logs in, check if they have been marked as a spammer. If then simply
     1759 * When a user logs in, check if they have been marked as a spammer. If yes then simply
    17631760 * redirect them to the home page and stop them from logging in.
    17641761 *
     
    18311828}
    18321829add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
     1830
     1831/**
     1832 * bp_core_filter_template_paths()
     1833 *
     1834 * Add fallback for the bp-sn-parent theme template locations used in BuddyPress versions
     1835 * older than 1.2.
     1836 *
     1837 * @package BuddyPress Core
     1838 */
     1839function bp_core_filter_template_paths() {
     1840    if ( 'bp-sn-parent' != basename( TEMPLATEPATH ) && !defined( 'BP_CLASSIC_TEMPLATE_STRUCTURE' ) )
     1841        return false;
     1842
     1843    add_filter( 'bp_core_template_directory_members', create_function( '', 'return "directories/members/index";' ) );
     1844    add_filter( 'bp_core_template_plugin', create_function( '', 'return "plugin-template";' ) );
     1845}
     1846add_action( 'init', 'bp_core_filter_template_paths' );
    18331847
    18341848/**
  • trunk/bp-core/bp-core-admin.php

    r2077 r2168  
    7777                    </td>
    7878                </tr>
    79                 <?php if ( function_exists('bp_wire_install') ) { ?>
    80                 <tr>
    81                     <th scope="row"><?php _e( 'Allow non-friends to post on profile wires?', 'buddypress' ) ?>:</th>
    82                     <td>
    83                         <input type="radio" name="bp-admin[non-friend-wire-posting]"<?php if ( (int)get_site_option( 'non-friend-wire-posting' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-non-friend-wire-post" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    84                         <input type="radio" name="bp-admin[non-friend-wire-posting]"<?php if ( !(int)get_site_option( 'non-friend-wire-posting' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-non-friend-wire-post" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    85                     </td>
    86                 </tr>
    87                 <?php } ?>
    8879                <tr>
    8980                    <th scope="row"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</th>
     
    10192                    </td>
    10293                </tr>
    103                 <?php endif; ?>
    104 
    105                 <?php $themes = bp_core_get_buddypress_themes() ?>
    106                 <?php if ( $themes ) : ?>
    107                     <tr>
    108                         <th scope="row"><?php _e('Select theme to use for BuddyPress generated pages', 'buddypress' ) ?>:</th>
    109                         <td>
    110                                 <select name="bp-admin[active-member-theme]" id="active-member-theme">
    111                                 <?php
    112                                 for ( $i = 0; $i < count($themes); $i++ ) {
    113                                     if ( $themes[$i]['template'] == get_site_option( 'active-member-theme' ) ) {
    114                                         $selected = ' selected="selected"';
    115                                     } else {
    116                                         $selected = '';
    117                                     }
    118                                 ?>
    119                                 <option<?php echo $selected ?> value="<?php echo $themes[$i]['template'] ?>"><?php echo $themes[$i]['name'] ?> (<?php echo $themes[$i]['version'] ?>)</option>
    120                                 <?php } ?>
    121                             </select>
    122                         </td>
    123                     </tr>
    124                 <?php else : ?>
    125                     <?php if ( '' == locate_template( array( 'registration/register.php' ), false ) && $current_blog->blog_id == BP_ROOT_BLOG ) : ?>
    126                         <div class="error">
    127                             <p><?php _e( '<strong>Your currently active theme is not BuddyPress enabled.</strong><p style="margin: 2px 0">Visit <a href="http://buddypress.org/extend/themes/">http://buddypress.org/extend/themes/</a> to browse themes that include support for BuddyPress features.</p>', 'buddypress' ) ?></p>
    128                         </div>
    129                     <?php endif; ?>
    13094                <?php endif; ?>
    13195
     
    206170                <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-activity.php') ) : ?>
    207171                <tr>
    208                     <td><h3><?php _e( 'Activity Streams', 'buddypress' ) ?></h3><p><?php _e( 'Tracks user activity across the entire site.', 'buddypress' ) ?></p></td>
     172                    <td><h3><?php _e( 'Activity Streams', 'buddypress' ) ?></h3><p><?php _e( 'Allow users to post activity updates and track all activity across the entire site.', 'buddypress' ) ?></p></td>
    209173                    <td>
    210174                        <input type="radio" name="bp_components[bp-activity.php]" value="1"<?php if ( !isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
     
    255219                        <input type="radio" name="bp_components[bp-messages.php]" value="1"<?php if ( !isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>  &nbsp;
    256220                        <input type="radio" name="bp_components[bp-messages.php]" value="0"<?php if ( isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    257                     </td>
    258                 </tr>
    259                 <?php endif; ?>
    260                 <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-wire.php') ) : ?>
    261                 <tr>
    262                     <td><h3><?php _e( 'Comment Wire', 'buddypress' ) ?></h3><p><?php _e( 'Let users leave a comment on groups, profiles and custom components.', 'buddypress' ) ?></p></td>
    263                     <td>
    264                         <input type="radio" name="bp_components[bp-wire.php]" value="1"<?php if ( !isset( $disabled_components['bp-wire.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>  &nbsp;
    265                         <input type="radio" name="bp_components[bp-wire.php]" value="0"<?php if ( isset( $disabled_components['bp-wire.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    266221                    </td>
    267222                </tr>
     
    276231                </tr>
    277232                <?php endif; ?>
    278                 <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-status.php') ) : ?>
    279                 <tr>
    280                     <td><h3><?php _e( 'Status Updates', 'buddypress' ) ?></h3><p><?php _e( 'Allow users to post status updates.', 'buddypress' ) ?></p></td>
    281                     <td width="45%">
    282                         <input type="radio" name="bp_components[bp-status.php]" value="1"<?php if ( !isset( $disabled_components['bp-status.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>  &nbsp;
    283                         <input type="radio" name="bp_components[bp-status.php]" value="0"<?php if ( isset( $disabled_components['bp-status.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
    284                     </td>
    285                 </tr>
    286                 <?php endif; ?>
    287233            </tbody>
    288234            </table>
  • trunk/bp-core/bp-core-adminbar.php

    r2114 r2168  
    1212        return false;
    1313
    14     echo '<div id="wp-admin-bar">';
     14    echo '<div id="wp-admin-bar"><div class="padder">';
    1515
    1616    // **** Do bp-adminbar-logo Actions ********
     
    2323
    2424    echo '</ul>';
    25     echo '</div>';
     25    echo '</div></div>';
    2626}
    2727
     
    275275add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
    276276add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
    277 add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
     277
     278if ( function_exists('bp_blogs_install') )
     279    add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
     280
    278281add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
    279 add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
     282
     283if ( function_exists('bp_blogs_install') )
     284    add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
     285
    280286add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
    281287
  • trunk/bp-core/bp-core-avatars.php

    r2120 r2168  
    4646        'css_id' => false,
    4747        'alt' => __( 'Avatar Image', 'buddypress' ),
     48        'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
    4849        'no_grav' => false // If there is no avatar found, return false instead of a grav?
    4950    );
     
    9495        $html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"';
    9596
    96     $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', get_blog_option( BP_ROOT_BLOG, 'siteurl' ) . '/' . basename( WP_CONTENT_DIR ) . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
     97    $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', $bp->root_domain . '/' . basename( WP_CONTENT_DIR ) . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
    9798    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
    9899
     
    133134
    134135        if ( 'user' == $object ) {
    135             $grav_email = bp_core_get_user_email( $item_id );
     136            if ( empty( $email ) )
     137                $email = bp_core_get_user_email( $item_id );
    136138        } else if ( 'group' == $object || 'blog' == $object ) {
    137             $grav_email = "{$item_id}-{$object}@{$bp->root_domain}";
     139            $email = "{$item_id}-{$object}@{$bp->root_domain}";
    138140        }
    139141
    140         $grav_email = apply_filters( 'bp_core_gravatar_email', $grav_email, $item_id, $object );
    141         $gravatar = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $grav_email ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
     142        $email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
     143        $gravatar = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $email ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
    142144
    143145        return apply_filters( 'bp_core_fetch_avatar', "<img src='{$gravatar}' alt='{$alt}' class='{$class}'{$css_id}{$html_width}{$html_height} />", $params );
  • trunk/bp-core/bp-core-classes.php

    r2114 r2168  
    2525
    2626    var $last_active;
    27     var $profile_last_updated;
    2827
    2928    /* Extras */
     
    8079        $this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb' ) );
    8180        $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) );
     81
     82        $this->last_active = bp_core_get_last_activity( get_usermeta( $this->id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) );
    8283    }
    8384
     
    106107    /* Static Functions */
    107108
    108     function get_newest_users( $limit = null, $page = 1 ) {
    109         global $wpdb;
     109    function get_users( $type, $limit = null, $page = 1, $user_id = false, $search_terms = false ) {
     110        global $wpdb, $bp;
     111
     112        $sql = array();
     113
     114        $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email";
     115
     116        if ( 'active' == $type || 'online' == $type )
     117            $sql['select_active'] = ", um.meta_value as last_activity";
     118
     119        if ( 'popular' == $type )
     120            $sql['select_popular'] = ", um.meta_value as total_friend_count";
     121
     122        if ( 'alphabetical' == $type )
     123            $sql['select_alpha'] = ", pd.value as fullname";
     124
     125        $sql['from'] = "FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN " . CUSTOM_USER_META_TABLE . " um ON um.user_id = u.ID";
     126
     127        if ( $search_terms && function_exists( 'xprofile_install' ) || 'alphabetical' == $type )
     128            $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
     129
     130        $sql['where'] = "WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0";
     131
     132        if ( 'active' == $type || 'online' == $type )
     133            $sql['where_active'] = "AND um.meta_key = 'last_activity'";
     134
     135        if ( 'popular' == $type )
     136            $sql['where_popular'] = "AND um.meta_key = 'total_friend_count'";
     137
     138        if ( 'online' == $type )
     139            $sql['where_online'] = "AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 5 MINUTE ) >= NOW()";
     140
     141        if ( 'alphabetical' == $type )
     142            $sql['where_alpha'] = "AND pd.field_id = 1";
     143
     144        if ( $user_id && function_exists( 'friends_install' ) ) {
     145            $friend_ids = friends_get_friend_user_ids( $user_id );
     146            $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
     147
     148            $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
     149        }
     150
     151        if ( $search_terms && function_exists( 'xprofile_install' ) ) {
     152            $search_terms = like_escape( $wpdb->escape( $search_terms ) );
     153            $sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'";
     154        }
     155
     156        switch ( $type ) {
     157            case 'active': default:
     158                $sql[] = "ORDER BY um.meta_value DESC";
     159                break;
     160            case 'newest':
     161                $sql[] = "ORDER BY u.user_registered DESC";
     162                break;
     163            case 'alphabetical':
     164                $sql[] = "ORDER BY pd.value ASC";
     165                break;
     166            case 'random':
     167                $sql[] = "ORDER BY rand()";
     168                break;
     169            case 'online':
     170                $sql[] = "ORDER BY FROM_UNIXTIME(um.meta_value) DESC";
     171                break;
     172            case 'popular':
     173                $sql[] = "ORDER BY CONVERT(um.meta_value, SIGNED) DESC";
     174                break;
     175        }
     176
     177        if ( $limit && $page )
     178            $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     179
     180        /* Get paginated results */
     181        $paged_users = $wpdb->get_results( $wpdb->prepare( join( ' ', (array)$sql ) ) );
     182
     183    //  var_dump( join( ' ', $sql ) );
     184
     185        /* Re-jig the SQL so we can get the total user count */
     186        unset( $sql['select_main'] );
     187
     188        if ( !empty( $sql['select_active'] ) )
     189            unset( $sql['select_active'] );
     190
     191        if ( !empty( $sql['select_popular'] ) )
     192            unset( $sql['select_popular'] );
     193
     194        if ( !empty( $sql['select_alpha'] ) )
     195            unset( $sql['select_alpha'] );
     196
     197        if ( !empty( $sql['pagination'] ) )
     198            unset( $sql['pagination'] );
     199
     200        array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
     201
     202        /* Get total user results */
     203        $total_users = $wpdb->get_var( $wpdb->prepare( join( ' ', (array)$sql ) ) );
     204
     205        /***
     206         * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
     207         * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     208         */
     209        foreach ( $paged_users as $user )
     210            $user_ids[] = $user->id;
     211
     212        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     213
     214        /* Add additional data to the returned results */
     215        $paged_users = BP_Core_User::get_user_extras( &$paged_users, $user_ids, $type );
     216
     217        return array( 'users' => $paged_users, 'total' => $total_users );
     218    }
     219
     220    function get_users_by_letter( $letter, $limit = null, $page = 1 ) {
     221        global $wpdb, $bp;
    110222
    111223        if ( $limit && $page )
    112224            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    113225
    114         $total_users_sql = apply_filters( 'bp_core_newest_users_count_sql', "SELECT COUNT(DISTINCT ID) FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 ORDER BY user_registered DESC" );
    115         $paged_users_sql = apply_filters( 'bp_core_newest_users_sql', "SELECT DISTINCT ID as user_id, DATE_ADD( user_registered, INTERVAL " . get_option('gmt_offset') . " HOUR ) as user_registered FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 ORDER BY user_registered DESC{$pag_sql}", $pag_sql );
     226        if ( strlen($letter) > 1 || is_numeric($letter) || !$letter )
     227            return false;
     228
     229        $letter = like_escape( $wpdb->escape( $letter ) );
     230
     231        $total_users_sql = apply_filters( 'bp_core_users_by_letter_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT u.ID) FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter );
     232        $paged_users_sql = apply_filters( 'bp_core_users_by_letter_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC{$pag_sql}", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter, $pag_sql );
    116233
    117234        $total_users = $wpdb->get_var( $total_users_sql );
    118235        $paged_users = $wpdb->get_results( $paged_users_sql );
    119236
     237        /***
     238         * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
     239         * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     240         */
     241        foreach ( $paged_users as $user )
     242            $user_ids[] = $user->id;
     243
     244        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     245
     246        /* Add additional data to the returned results */
     247        $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
     248
    120249        return array( 'users' => $paged_users, 'total' => $total_users );
    121250    }
    122251
    123     function get_active_users( $limit = null, $page = 1 ) {
    124         global $wpdb;
     252    function get_specific_users( $user_ids, $limit = null, $page = 1 ) {
     253        global $wpdb, $bp;
    125254
    126255        if ( $limit && $page )
    127256            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    128257
    129         $total_users_sql = apply_filters( 'bp_core_active_users_count_sql', "SELECT COUNT(DISTINCT um.user_id) FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'last_activity' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY FROM_UNIXTIME(um.meta_value) DESC" );
    130         $paged_users_sql = apply_filters( 'bp_core_active_users_sql', "SELECT DISTINCT user_id FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'last_activity' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY FROM_UNIXTIME(um.meta_value) DESC{$pag_sql}", $pag_sql );
     258        $user_sql = " AND user_id IN ( " . $wpdb->escape( $user_ids ) . " ) ";
     259
     260        $total_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT ID) FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 AND ID IN ( " . $wpdb->escape( $user_ids ) . " ) " ), $wpdb->escape( $user_ids ) );
     261        $paged_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', $wpdb->prepare( "SELECT DISTINCT ID as id, user_registered, user_nicename, user_login, user_email FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 AND ID IN ( " . $wpdb->escape( $user_ids ) . " ) {$pag_sql}" ), $wpdb->escape( $user_ids ) );
    131262
    132263        $total_users = $wpdb->get_var( $total_users_sql );
    133264        $paged_users = $wpdb->get_results( $paged_users_sql );
    134265
     266        /***
     267         * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
     268         * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     269         */
     270        foreach ( $paged_users as $user )
     271            $user_ids[] = $user->id;
     272
     273        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     274
     275        /* Add additional data to the returned results */
     276        $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
     277
    135278        return array( 'users' => $paged_users, 'total' => $total_users );
    136279    }
    137280
    138     function get_popular_users( $limit = null, $page = 1 ) {
    139         global $wpdb;
    140 
    141         if ( !function_exists('friends_install') )
    142             return false;
     281    function search_users( $search_terms, $limit = null, $page = 1 ) {
     282        global $wpdb, $bp;
    143283
    144284        if ( $limit && $page )
    145285            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    146286
    147         $total_users_sql = apply_filters( 'bp_core_popular_users_count_sql', "SELECT COUNT(DISTINCT um.user_id) FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'total_friend_count' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY CONVERT(um.meta_value, SIGNED) DESC" );
    148         $paged_users_sql = apply_filters( 'bp_core_popular_users_sql', "SELECT DISTINCT um.user_id FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'total_friend_count' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY CONVERT(um.meta_value, SIGNED) DESC{$pag_sql}", $pag_sql );
     287        $search_terms = like_escape( $wpdb->escape( $search_terms ) );
     288
     289        $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT u.ID) as id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms );
     290        $paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql );
    149291
    150292        $total_users = $wpdb->get_var( $total_users_sql );
    151293        $paged_users = $wpdb->get_results( $paged_users_sql );
    152294
     295        /***
     296         * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
     297         * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     298         */
     299        foreach ( $paged_users as $user )
     300            $user_ids[] = $user->id;
     301
     302        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     303
     304        /* Add additional data to the returned results */
     305        $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
     306
    153307        return array( 'users' => $paged_users, 'total' => $total_users );
    154308    }
    155309
    156     function get_random_users( $limit = null, $page = 1 ) {
    157         global $wpdb, $bp;
    158 
    159         if ( $limit && $page )
    160             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    161 
    162         $total_users_sql = apply_filters( 'bp_core_random_users_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT um.user_id) FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND u.ID != %d ORDER BY RAND() DESC", $bp->loggedin_user->id ) );
    163         $paged_users_sql = apply_filters( 'bp_core_random_users_sql', $wpdb->prepare( "SELECT DISTINCT um.user_id FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND u.ID != %d ORDER BY RAND(){$pag_sql}", $bp->loggedin_user->id ), $pag_sql );
    164 
    165         $total_users = $wpdb->get_var( $total_users_sql );
    166         $paged_users = $wpdb->get_results( $paged_users_sql );
    167 
    168         return array( 'users' => $paged_users, 'total' => $total_users );
    169     }
    170 
    171     function get_online_users( $limit = null, $page = 1 ) {
    172         global $wpdb;
    173 
    174         if ( $limit && $page )
    175             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    176 
    177         $total_users_sql = apply_filters( 'bp_core_online_users_count_sql', "SELECT COUNT(DISTINCT um.user_id) FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'last_activity' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 5 MINUTE ) >= NOW() ORDER BY FROM_UNIXTIME(um.meta_value) DESC" );
    178         $paged_users_sql = apply_filters( 'bp_core_online_users_sql', "SELECT DISTINCT um.user_id FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'last_activity' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 5 MINUTE ) >= NOW() ORDER BY FROM_UNIXTIME(um.meta_value) DESC{$pag_sql}", $pag_sql );
    179 
    180         $total_users = $wpdb->get_var( $total_users_sql );
    181         $paged_users = $wpdb->get_results( $paged_users_sql );
    182 
    183         return array( 'users' => $paged_users, 'total' => $total_users );
    184     }
    185 
    186     function get_alphabetical_users( $limit = null, $page = 1 ) {
    187         global $wpdb, $bp;
    188 
    189         if ( !function_exists( 'xprofile_install' ) )
    190             return BP_Core_User::get_active_users( $limit, $page );
    191 
    192         if ( $limit && $page )
    193             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    194 
    195         $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT DISTINCT u.ID as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms );
    196         $paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql );
    197 
    198         $total_users = $wpdb->get_var( $total_users_sql );
    199         $paged_users = $wpdb->get_results( $paged_users_sql );
    200 
    201         return array( 'users' => $paged_users, 'total' => $total_users );
    202     }
    203 
    204     function get_users_by_letter( $letter, $limit = null, $page = 1 ) {
    205         global $wpdb, $bp;
    206 
    207         if ( !function_exists('xprofile_install') )
    208             return BP_Core_User::get_active_users( $limit, $page );
    209 
    210         if ( $limit && $page )
    211             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    212 
    213         if ( strlen($letter) > 1 || is_numeric($letter) || !$letter )
    214             return false;
    215 
    216         $letter = like_escape( $wpdb->escape( $letter ) );
    217 
    218         $total_users_sql = apply_filters( 'bp_core_users_by_letter_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT u.ID) FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter );
    219         $paged_users_sql = apply_filters( 'bp_core_users_by_letter_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC{$pag_sql}", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter, $pag_sql );
    220 
    221         $total_users = $wpdb->get_var( $total_users_sql );
    222         $paged_users = $wpdb->get_results( $paged_users_sql );
    223 
    224         return array( 'users' => $paged_users, 'total' => $total_users );
    225     }
    226 
    227     function search_users( $search_terms, $limit = null, $page = 1 ) {
    228         global $wpdb, $bp;
    229 
    230         if ( !function_exists('xprofile_install') )
    231             return BP_Core_User::get_active_users( $limit, $page );
    232 
    233         if ( $limit && $page )
    234             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    235 
    236         $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    237 
    238         $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT u.ID) as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms );
    239         $paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql );
    240 
    241         $total_users = $wpdb->get_var( $total_users_sql );
    242         $paged_users = $wpdb->get_results( $paged_users_sql );
    243 
    244         return array( 'users' => $paged_users, 'total' => $total_users );
     310    function get_user_extras( $paged_users, $user_ids, $type = false ) {
     311        global $bp, $wpdb;
     312
     313        if ( empty( $user_ids ) )
     314            return $paged_users;
     315
     316        /* Fetch the user's full name */
     317        if ( function_exists( 'xprofile_install' ) && 'alphabetical' != $type ) {
     318            $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", BP_XPROFILE_FULLNAME_FIELD_NAME ) );
     319            for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     320                foreach ( $names as $name ) {
     321                    if ( $name->id == $paged_users[$i]->id )
     322                        $paged_users[$i]->fullname = $name->fullname;
     323                }
     324            }
     325        }
     326
     327        /* Fetch the user's total friend count */
     328        if ( 'popular' != $type ) {
     329            $friend_count = $wpdb->get_results( "SELECT user_id as id, meta_value as total_friend_count FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'total_friend_count' AND user_id IN ( {$user_ids} )" );
     330            for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     331                foreach ( $friend_count as $count ) {
     332                    if ( $count->id == $paged_users[$i]->id )
     333                        $paged_users[$i]->total_friend_count = (int)$count->total_friend_count;
     334                }
     335            }
     336        }
     337
     338        /* Fetch the user's last_activity */
     339        if ( 'active' != $type ) {
     340            $user_activity = $wpdb->get_results( "SELECT user_id as id, meta_value as last_activity FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'last_activity' AND user_id IN ( {$user_ids} )" );
     341            for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     342                foreach ( $user_activity as $activity ) {
     343                    if ( $activity->id == $paged_users[$i]->id )
     344                        $paged_users[$i]->last_activity = (int)$activity->last_activity;
     345                }
     346            }
     347        }
     348
     349        return $paged_users;
    245350    }
    246351}
  • trunk/bp-core/bp-core-settings.php

    r2114 r2168  
    6464    add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' );
    6565
    66     bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) );
     66    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    6767}
    6868
     
    9494        <input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'Repeat New Password', 'buddypress' ) ?>
    9595
    96         <p class="submit"><input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p>
     96        <div class="submit">
     97            <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p>
     98        </div>
     99
    97100        <?php wp_nonce_field('bp_settings_general') ?>
    98101    </form>
     
    122125    add_action( 'bp_template_content', 'bp_core_screen_notification_settings_content' );
    123126
    124     bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) );
     127    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    125128}
    126129
     
    144147        <?php do_action( 'bp_notification_settings' ) ?>
    145148
    146         <p class="submit"><input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p>
     149        <div class="submit">
     150            <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p>
     151        </div>
    147152
    148153        <?php wp_nonce_field('bp_settings_notifications') ?>
     
    166171    add_action( 'bp_template_content', 'bp_core_screen_delete_account_content' );
    167172
    168     bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) );
     173    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    169174}
    170175
     
    183188
    184189        <input type="checkbox" name="delete-account-understand" id="delete-account-understand" value="1" onclick="if(this.checked) { document.getElementById('delete-account-button').disabled = ''; } else { document.getElementById('delete-account-button').disabled = 'disabled'; }" /> <?php _e( 'I understand the consequences of deleting my account.', 'buddypress' ); ?>
    185         <p><input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> &raquo;" id="delete-account-button" name="delete-account-button" /></p>
     190
     191        <div class="submit">
     192            <input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> &raquo;" id="delete-account-button" name="delete-account-button" /></p>
     193        </div>
     194
    186195        <?php wp_nonce_field('delete-account') ?>
    187196    </form>
  • trunk/bp-core/bp-core-templatetags.php

    r2145 r2168  
    11<?php
     2
     3/***
     4 * Members template loop that will allow you to loop all members or friends of a member
     5 * if you pass a user_id.
     6 */
     7
     8class BP_Core_Members_Template {
     9    var $current_member = -1;
     10    var $member_count;
     11    var $members;
     12    var $member;
     13
     14    var $in_the_loop;
     15
     16    var $pag_page;
     17    var $pag_num;
     18    var $pag_links;
     19    var $total_member_count;
     20
     21    function bp_core_members_template( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include ) {
     22        global $bp, $bp_the_member_query;
     23
     24        $this->pag_page = isset( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : $page_number;
     25        $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     26        $this->type = $type;
     27
     28        if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
     29            $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
     30        }
     31        else if ( false !== $include ) {
     32            $this->members = BP_Core_User::get_specific_users( $include, $this->pag_num, $this->pag_page );
     33        }
     34        else {
     35            $this->members = BP_Core_User::get_users( $this->type, $this->pag_num, $this->pag_page, $user_id, $search_terms );
     36        }
     37
     38        if ( !$max || $max >= (int)$this->members['total'] )
     39            $this->total_member_count = (int)$this->members['total'];
     40        else
     41            $this->total_member_count = (int)$max;
     42
     43        $this->members = $this->members['users'];
     44
     45        if ( $max ) {
     46            if ( $max >= count($this->members) )
     47                $this->member_count = count($this->members);
     48            else
     49                $this->member_count = (int)$max;
     50        } else {
     51            $this->member_count = count($this->members);
     52        }
     53
     54        if ( (int) $this->total_member_count && (int) $this->pag_num ) {
     55            $this->pag_links = paginate_links( array(
     56                'base' => add_query_arg( 'upage', '%#%' ),
     57                'format' => '',
     58                'total' => ceil( (int) $this->total_member_count / (int) $this->pag_num ),
     59                'current' => (int) $this->pag_page,
     60                'prev_text' => '&larr;',
     61                'next_text' => '&rarr;',
     62                'mid_size' => 1
     63            ));
     64        }
     65    }
     66
     67    function has_members() {
     68        if ( $this->member_count )
     69            return true;
     70
     71        return false;
     72    }
     73
     74    function next_member() {
     75        $this->current_member++;
     76        $this->member = $this->members[$this->current_member];
     77
     78        return $this->member;
     79    }
     80
     81    function rewind_members() {
     82        $this->current_member = -1;
     83        if ( $this->member_count > 0 ) {
     84            $this->member = $this->members[0];
     85        }
     86    }
     87
     88    function members() {
     89        if ( $this->current_member + 1 < $this->member_count ) {
     90            return true;
     91        } elseif ( $this->current_member + 1 == $this->member_count ) {
     92            do_action('loop_end');
     93            // Do some cleaning up after the loop
     94            $this->rewind_members();
     95        }
     96
     97        $this->in_the_loop = false;
     98        return false;
     99    }
     100
     101    function the_member() {
     102        global $member, $bp;
     103
     104        $this->in_the_loop = true;
     105        $this->member = $this->next_member();
     106
     107        if ( 0 == $this->current_member ) // loop has just started
     108            do_action('loop_start');
     109    }
     110}
     111
     112function bp_rewind_members() {
     113    global $members_template;
     114
     115    return $members_template->rewind_members();
     116}
     117
     118function bp_has_members( $args = '' ) {
     119    global $bp, $members_template;
     120
     121    // type: active ( default ) | random | newest | popular | online | alphabetical
     122    $defaults = array(
     123        'type' => 'active',
     124        'page' => 1,
     125        'per_page' => 10,
     126        'max' => false,
     127
     128        'include' => false, // Pass a user_id or comma separated list of user_ids to only show these users
     129
     130        'user_id' => false, // Pass a user_id to only show friends of this user
     131        'search_terms' => false // Pass search_terms to filter users by their profile data
     132    );
     133
     134    $r = wp_parse_args( $args, $defaults );
     135    extract( $r, EXTR_SKIP );
     136
     137    if ( $max ) {
     138        if ( $per_page > $max )
     139            $per_page = $max;
     140    }
     141
     142    /* Pass a filter if ?s= is set. */
     143    if ( $_REQUEST['s'] )
     144        $search_terms = $_REQUEST['s'];
     145
     146    $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include );
     147
     148    return $members_template->has_members();
     149}
     150
     151function bp_the_member() {
     152    global $members_template;
     153    return $members_template->the_member();
     154}
     155
     156function bp_members() {
     157    global $members_template;
     158    return $members_template->members();
     159}
     160
     161function bp_members_pagination_count() {
     162    global $bp, $members_template;
     163
     164    $from_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
     165    $to_num = ( $from_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $from_num + ( $members_template->pag_num - 1) ;
     166
     167    if ( 'active' == $members_template->type )
     168        echo sprintf( __( 'Viewing member %d to %d (of %d active members)', 'buddypress' ), $from_num, $to_num, $members_template->total_member_count );
     169    else if ( 'popular' == $members_template->type )
     170        echo sprintf( __( 'Viewing member %d to %d (of %d members with friends)', 'buddypress' ), $from_num, $to_num, $members_template->total_member_count );
     171    else if ( 'online' == $members_template->type )
     172        echo sprintf( __( 'Viewing member %d to %d (of %d members online)', 'buddypress' ), $from_num, $to_num, $members_template->total_member_count );
     173    else
     174        echo sprintf( __( 'Viewing member %d to %d (of %d members)', 'buddypress' ), $from_num, $to_num, $members_template->total_member_count );
     175
     176    ?><span class="ajax-loader"></span><?php
     177}
     178
     179function bp_members_pagination_links() {
     180    echo bp_get_members_pagination_links();
     181}
     182    function bp_get_members_pagination_links() {
     183        global $members_template;
     184
     185        return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links );
     186    }
     187
     188function bp_member_user_id() {
     189    echo bp_get_member_user_id();
     190}
     191    function bp_get_member_user_id() {
     192        global $members_template;
     193
     194        return apply_filters( 'bp_get_member_user_id', $members_template->member->id );
     195    }
     196
     197function bp_member_avatar( $args = '' ) {
     198    echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
     199}
     200    function bp_get_member_avatar( $args = '' ) {
     201        global $bp, $members_template;
     202
     203        $defaults = array(
     204            'type' => 'thumb',
     205            'width' => false,
     206            'height' => false,
     207            'class' => 'avatar',
     208            'id' => false,
     209            'alt' => __( 'Member avatar', 'buddypress' )
     210        );
     211
     212        $r = wp_parse_args( $args, $defaults );
     213        extract( $r, EXTR_SKIP );
     214
     215        return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) );
     216    }
     217
     218function bp_member_permalink() {
     219    echo bp_get_member_permalink();
     220}
     221    function bp_get_member_permalink() {
     222        global $members_template;
     223
     224        echo apply_filters( 'bp_get_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) );
     225    }
     226    function bp_member_link() { echo bp_get_member_permalink(); }
     227    function bp_get_member_link() { return bp_get_member_permalink(); }
     228
     229function bp_member_name() {
     230    echo apply_filters( 'bp_member_name', bp_get_member_name() );
     231}
     232    function bp_get_member_name() {
     233        global $members_template;
     234
     235        return apply_filters( 'bp_get_member_name', $members_template->member->fullname );
     236    }
     237    add_filter( 'bp_get_member_name', 'wp_filter_kses' );
     238    add_filter( 'bp_get_member_name', 'stripslashes' );
     239
     240function bp_member_last_active() {
     241    echo bp_get_member_last_active();
     242}
     243    function bp_get_member_last_active() {
     244        global $members_template;
     245
     246        $last_activity = attribute_escape( bp_core_get_last_activity( $members_template->member->last_activity, __( 'active %s ago', 'buddypress' ) ) );
     247
     248        return apply_filters( 'bp_member_last_active', $last_activity );
     249    }
     250
     251function bp_member_profile_data( $field_name = false ) {
     252    echo bp_get_member_profile_data( $field_name );
     253}
     254    function bp_get_member_profile_data( $field_name = false ) {
     255        global $members_template;
     256
     257        if ( !$field_name || !function_exists( 'xprofile_install' ) )
     258            return false;
     259
     260        // Populate the user if it hasn't been already.
     261        if ( empty( $members_template->member->profile_data ) )
     262            $members_template->member = new BP_Core_User( $members_template->member->id );
     263
     264        return apply_filters( 'bp_get_member_profile_data', $members_template->member->profile_data[$field_name]['field_data'], $members_template->member->profile_data[$field_name]['field_type'] );
     265    }
     266
     267function bp_member_registered() {
     268    echo bp_get_member_registered();
     269}
     270    function bp_get_member_registered() {
     271        global $members_template;
     272
     273        $registered = attribute_escape( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s ago', 'buddypress' ) ) );
     274
     275        return apply_filters( 'bp_member_last_active', $registered );
     276    }
     277
     278function bp_member_add_friend_button() {
     279    global $members_template;
     280
     281    if ( function_exists( 'bp_add_friend_button' ) ) {
     282        echo bp_add_friend_button( $members_template->member->id );
     283    }
     284}
     285
     286function bp_member_total_friend_count() {
     287    global $members_template;
     288
     289    echo bp_get_member_total_friend_count();
     290}
     291    function bp_get_member_total_friend_count() {
     292        global $members_template;
     293
     294        if ( 1 == (int) $members_template->member->total_friend_count )
     295            return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friend', 'buddypress' ), (int) $members_template->member->total_friend_count ) );
     296        else
     297            return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friends', 'buddypress' ), (int) $members_template->member->total_friend_count ) );
     298    }
     299
     300function bp_member_random_profile_data() {
     301    global $members_template;
     302
     303    if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
     304        <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
     305            <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
     306            <?php echo wp_filter_kses( $random_data[0]->value ) ?>
     307    <?php }
     308}
     309
     310function bp_member_hidden_fields() {
     311    if ( isset( $_REQUEST['s'] ) ) {
     312        echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ) . '" name="search_terms" />';
     313    }
     314
     315    if ( isset( $_REQUEST['letter'] ) ) {
     316        echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
     317    }
     318
     319    if ( isset( $_REQUEST['members_search'] ) ) {
     320        echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['members_search'] ) . '" name="search_terms" />';
     321    }
     322}
     323
     324function bp_directory_members_search_form() {
     325    global $bp;
     326
     327    $search_value = __( 'Search anything...', 'buddypress' );
     328    if ( !empty( $_GET['s'] ) )
     329        $search_value = $_GET['s'];
     330
     331    else if ( !empty( $_COOKIE['bp-members-search-terms'] ) && 'false' != $_COOKIE['bp-members-search-terms'] )
     332        $search_value = $_COOKIE['bp-members-search-terms'];
     333
     334    ?>
     335    <form action="" method="get" id="search-members-form">
     336        <label><input type="text" name="s" id="members_search" value="<?php echo attribute_escape( $search_value ) ?>"  onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
     337        <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
     338        <?php wp_nonce_field( 'directory_members', '_wpnonce-member-filter' ) ?>
     339    </form>
     340<?php
     341}
     342
     343function bp_home_blog_url() {
     344    global $bp, $current_blog;
     345
     346    if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
     347        $blog_id = $current_blog->blog_id;
     348    } else {
     349        $blog_id = BP_ROOT_BLOG;
     350    }
     351
     352    if ( 'bphome' == get_blog_option( $blog_id, 'template' ) )
     353        echo $bp->root_domain . '/' . BP_HOME_BLOG_SLUG;
     354    else
     355        echo $bp->root_domain;
     356}
     357
     358function bp_total_site_member_count() {
     359    echo bp_get_total_site_member_count();
     360}
     361    function bp_get_total_site_member_count() {
     362        return apply_filters( 'bp_get_total_site_member_count', bp_core_get_total_member_count() );
     363    }
     364
     365
     366/** Navigation and other misc template tags **/
     367
    2368/**
    3369 * bp_get_nav()
     
    31397           then check to see if the two users are friends. if they are, add a highlight CSS class
    32398           to the friends nav item if it exists. */
    33         if ( !bp_is_home() && $bp->displayed_user->id ) {
     399        if ( !bp_is_my_profile() && $bp->displayed_user->id ) {
    34400            $selected = '';
    35401
     
    72438
    73439    foreach ( $bp->bp_nav as $user_nav_item ) {
    74         if ( !$user_nav_item['show_for_displayed_user'] )
     440        if ( !$user_nav_item['show_for_displayed_user'] && !bp_is_my_profile() )
    75441            continue;
    76442
     
    270636}
    271637
    272 function bp_is_home() {
     638function bp_is_my_profile() {
    273639    global $bp;
    274640
     
    278644    return false;
    279645}
     646function bp_is_home() { return bp_is_my_profile(); }
    280647
    281648function bp_last_activity( $user_id = false, $echo = true ) {
     
    8551222/*** CUSTOM LOOP TEMPLATE CLASSES *******************/
    8561223
    857 class BP_Core_Members_Template {
    858     var $current_member = -1;
    859     var $member_count;
    860     var $members;
    861     var $member;
    862 
    863     var $in_the_loop;
    864 
    865     var $pag_page;
    866     var $pag_num;
    867     var $pag_links;
    868     var $total_member_count;
    869 
    870     function bp_core_members_template( $type, $per_page, $max ) {
    871         global $bp, $bp_the_member_query;
    872 
    873         $this->pag_page = isset( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : 1;
    874         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    875 
    876         if ( isset( $_REQUEST['s'] ) && '' != $_REQUEST['s'] && $type != 'random' ) {
    877             $this->members = BP_Core_User::search_users( $_REQUEST['s'], $this->pag_num, $this->pag_page );
    878         } else if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
    879             $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
    880         } else {
    881             switch ( $type ) {
    882                 case 'random':
    883                     $this->members = BP_Core_User::get_random_users( $this->pag_num, $this->pag_page );
    884                     break;
    885 
    886                 case 'newest':
    887                     $this->members = BP_Core_User::get_newest_users( $this->pag_num, $this->pag_page );
    888                     break;
    889 
    890                 case 'popular':
    891                     $this->members = BP_Core_User::get_popular_users( $this->pag_num, $this->pag_page );
    892                     break;
    893 
    894                 case 'online':
    895                     $this->members = BP_Core_User::get_online_users( $this->pag_num, $this->pag_page );
    896                     break;
    897 
    898                 case 'alphabetical':
    899                     $this->members = BP_Core_User::get_alphabetical_users( $this->pag_num, $this->pag_page );
    900                     break;
    901 
    902                 case 'active': default:
    903                     $this->members = BP_Core_User::get_active_users( $this->pag_num, $this->pag_page );
    904                     break;
    905             }
    906         }
    907 
    908         if ( !$max || $max >= (int)$this->members['total'] )
    909             $this->total_member_count = (int)$this->members['total'];
    910         else
    911             $this->total_member_count = (int)$max;
    912 
    913         $this->members = $this->members['users'];
    914 
    915         if ( $max ) {
    916             if ( $max >= count($this->members) )
    917                 $this->member_count = count($this->members);
    918             else
    919                 $this->member_count = (int)$max;
    920         } else {
    921             $this->member_count = count($this->members);
    922         }
    923 
    924         if ( (int) $this->total_member_count && (int) $this->pag_num ) {
    925             $this->pag_links = paginate_links( array(
    926                 'base' => add_query_arg( 'upage', '%#%' ),
    927                 'format' => '',
    928                 'total' => ceil( (int) $this->total_member_count / (int) $this->pag_num ),
    929                 'current' => (int) $this->pag_page,
    930                 'prev_text' => '&laquo;',
    931                 'next_text' => '&raquo;',
    932                 'mid_size' => 1
    933             ));
    934         }
    935     }
    936 
    937     function has_members() {
    938         if ( $this->member_count )
    939             return true;
    940 
    941         return false;
    942     }
    943 
    944     function next_member() {
    945         $this->current_member++;
    946         $this->member = $this->members[$this->current_member];
    947 
    948         return $this->member;
    949     }
    950 
    951     function rewind_members() {
    952         $this->current_member = -1;
    953         if ( $this->member_count > 0 ) {
    954             $this->member = $this->members[0];
    955         }
    956     }
    957 
    958     function site_members() {
    959         if ( $this->current_member + 1 < $this->member_count ) {
    960             return true;
    961         } elseif ( $this->current_member + 1 == $this->member_count ) {
    962             do_action('loop_end');
    963             // Do some cleaning up after the loop
    964             $this->rewind_members();
    965         }
    966 
    967         $this->in_the_loop = false;
    968         return false;
    969     }
    970 
    971     function the_member() {
    972         global $member, $bp;
    973 
    974         $this->in_the_loop = true;
    975         $this->member = $this->next_member();
    976         $user_id = $this->member->user_id;
    977         $user_registered = $this->member->user_registered;
    978 
    979         if ( !$this->member = wp_cache_get( 'bp_user_' . $user_id, 'bp' ) ) {
    980             $this->member = new BP_Core_User( $user_id );
    981             wp_cache_set( 'bp_user_' . $user_id, $this->member, 'bp' );
    982         }
    983 
    984         if ( $user_registered )
    985             $this->member->user_registered = $user_registered;
    986 
    987         if ( 0 == $this->current_member ) // loop has just started
    988             do_action('loop_start');
    989     }
    990 }
    991 
    992 function bp_rewind_site_members() {
    993     global $site_members_template;
    994 
    995     return $site_members_template->rewind_members();
    996 }
    997 
    998 function bp_has_site_members( $args = '' ) {
    999     global $bp, $site_members_template;
    1000 
    1001     $defaults = array(
    1002         'type' => 'active',
    1003         'per_page' => 10,
    1004         'max' => false
    1005     );
    1006 
    1007     $r = wp_parse_args( $args, $defaults );
    1008     extract( $r, EXTR_SKIP );
    1009 
    1010     // type: active ( default ) | random | newest | popular | online | alphabetical
    1011 
    1012     if ( $max ) {
    1013         if ( $per_page > $max )
    1014             $per_page = $max;
    1015     }
    1016 
    1017     $site_members_template = new BP_Core_Members_Template( $type, $per_page, $max );
    1018 
    1019     return $site_members_template->has_members();
    1020 }
    1021 
    1022 function bp_the_site_member() {
    1023     global $site_members_template;
    1024     return $site_members_template->the_member();
    1025 }
    1026 
    1027 function bp_site_members() {
    1028     global $site_members_template;
    1029     return $site_members_template->site_members();
    1030 }
    1031 
    1032 function bp_site_members_pagination_count() {
    1033     global $bp, $site_members_template;
    1034 
    1035     $from_num = intval( ( $site_members_template->pag_page - 1 ) * $site_members_template->pag_num ) + 1;
    1036     $to_num = ( $from_num + ( $site_members_template->pag_num - 1 ) > $site_members_template->total_member_count ) ? $site_members_template->total_member_count : $from_num + ( $site_members_template->pag_num - 1) ;
    1037 
    1038     echo sprintf( __( 'Viewing member %d to %d (of %d members)', 'buddypress' ), $from_num, $to_num, $site_members_template->total_member_count ); ?> &nbsp;
    1039     <span class="ajax-loader"></span><?php
    1040 }
    1041 
    1042 function bp_site_members_pagination_links() {
    1043     echo bp_get_site_members_pagination_links();
    1044 }
    1045     function bp_get_site_members_pagination_links() {
    1046         global $site_members_template;
    1047 
    1048         return apply_filters( 'bp_get_site_members_pagination_links', $site_members_template->pag_links );
    1049     }
    1050 
    1051 function bp_the_site_member_user_id() {
    1052     echo bp_get_the_site_member_user_id();
    1053 }
    1054     function bp_get_the_site_member_user_id() {
    1055         global $site_members_template;
    1056 
    1057         return apply_filters( 'bp_get_the_site_member_user_id', $site_members_template->member->id );
    1058     }
    1059 
    1060 function bp_the_site_member_avatar( $args = '' ) {
    1061     echo apply_filters( 'bp_the_site_member_avatar', bp_get_the_site_member_avatar( $args ) );
    1062 }
    1063 
    1064     function bp_get_the_site_member_avatar( $args = '' ) {
    1065         global $bp, $site_members_template;
    1066 
    1067         $defaults = array(
    1068             'type' => 'thumb',
    1069             'width' => false,
    1070             'height' => false,
    1071             'class' => 'avatar',
    1072             'id' => false,
    1073             'alt' => __( 'Member avatar', 'buddypress' )
    1074         );
    1075 
    1076         $r = wp_parse_args( $args, $defaults );
    1077         extract( $r, EXTR_SKIP );
    1078 
    1079         /* Fetch the avatar from the folder, if not provide backwards compat. */
    1080         if ( !$avatar = bp_core_fetch_avatar( array( 'item_id' => $site_members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height ) ) )
    1081             $avatar = '<img src="' . attribute_escape( $site_members_template->member->avatar_thumb ) . '" class="avatar" alt="' . __( 'Member avatar', 'buddypress' ) . '" />';
    1082 
    1083         return apply_filters( 'bp_get_the_site_member_avatar', $avatar );
    1084     }
    1085 
    1086 function bp_the_site_member_link() {
    1087     echo bp_get_the_site_member_link();
    1088 }
    1089     function bp_get_the_site_member_link() {
    1090         global $site_members_template;
    1091 
    1092         echo apply_filters( 'bp_get_the_site_member_link', $site_members_template->member->user_url );
    1093     }
    1094 
    1095 function bp_the_site_member_name() {
    1096     echo apply_filters( 'bp_the_site_member_name', bp_get_the_site_member_name() );
    1097 }
    1098     function bp_get_the_site_member_name() {
    1099         global $site_members_template;
    1100 
    1101         return apply_filters( 'bp_get_the_site_member_name', $site_members_template->member->fullname );
    1102     }
    1103     add_filter( 'bp_get_the_site_member_name', 'wp_filter_kses' );
    1104     add_filter( 'bp_get_the_site_member_name', 'stripslashes' );
    1105 
    1106 function bp_the_site_member_last_active() {
    1107     echo bp_get_the_site_member_last_active();
    1108 }
    1109     function bp_get_the_site_member_last_active() {
    1110         global $site_members_template;
    1111 
    1112         $last_activity = attribute_escape( bp_core_get_last_activity( get_usermeta( $site_members_template->member->id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) ) );
    1113 
    1114         return apply_filters( 'bp_the_site_member_last_active', $last_activity );
    1115     }
    1116 
    1117 function bp_the_site_member_profile_data( $field_name = false ) {
    1118     echo bp_get_the_site_member_profile_data( $field_name );
    1119 }
    1120     function bp_get_the_site_member_profile_data( $field_name = false ) {
    1121         global $site_members_template;
    1122 
    1123         if ( !$field_name || !function_exists( 'xprofile_install' ) )
    1124             return false;
    1125 
    1126         return apply_filters( 'bp_get_the_site_member_profile_data', $site_members_template->member->profile_data[$field_name]['field_data'], $site_members_template->member->profile_data[$field_name]['field_type'] );
    1127     }
    1128 
    1129 function bp_the_site_member_registered() {
    1130     echo bp_get_the_site_member_registered();
    1131 }
    1132     function bp_get_the_site_member_registered() {
    1133         global $site_members_template;
    1134 
    1135         return apply_filters( 'bp_the_site_member_last_active', strtotime( $site_members_template->member->user_registered ) );
    1136     }
    1137 
    1138 function bp_the_site_member_add_friend_button() {
    1139     global $site_members_template;
    1140 
    1141     if ( function_exists( 'bp_add_friend_button' ) ) {
    1142         echo bp_add_friend_button( $site_members_template->member->id );
    1143     }
    1144 }
    1145 
    1146 function bp_the_site_member_total_friend_count() {
    1147     global $site_members_template;
    1148 
    1149     if ( !(int) $site_members_template->member->total_friends )
    1150         return false;
    1151 
    1152     echo bp_get_the_site_member_total_friend_count();
    1153 }
    1154     function bp_get_the_site_member_total_friend_count() {
    1155         global $site_members_template;
    1156 
    1157         if ( !(int) $site_members_template->member->total_friends )
    1158             return false;
    1159 
    1160         if ( 1 == (int) $site_members_template->member->total_friends )
    1161             return apply_filters( 'bp_get_the_site_member_total_friend_count', sprintf( __( '%d friend', 'buddypress' ), (int) $site_members_template->member->total_friends ) );
    1162         else
    1163             return apply_filters( 'bp_get_the_site_member_total_friend_count', sprintf( __( '%d friends', 'buddypress' ), (int) $site_members_template->member->total_friends ) );
    1164     }
    1165 
    1166 function bp_the_site_member_random_profile_data() {
    1167     global $site_members_template;
    1168 
    1169     if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
    1170         <?php $random_data = xprofile_get_random_profile_data( $site_members_template->member->id, true ); ?>
    1171             <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
    1172             <?php echo wp_filter_kses( $random_data[0]->value ) ?>
    1173     <?php }
    1174 }
    1175 
    1176 function bp_the_site_member_hidden_fields() {
    1177     if ( isset( $_REQUEST['s'] ) ) {
    1178         echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ) . '" name="search_terms" />';
    1179     }
    1180 
    1181     if ( isset( $_REQUEST['letter'] ) ) {
    1182         echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    1183     }
    1184 
    1185     if ( isset( $_REQUEST['members_search'] ) ) {
    1186         echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['members_search'] ) . '" name="search_terms" />';
    1187     }
    1188 }
    1189 
    1190 function bp_directory_members_search_form() {
    1191     global $bp; ?>
    1192     <form action="" method="get" id="search-members-form">
    1193         <label><input type="text" name="s" id="members_search" value="<?php if ( isset( $_GET['s'] ) ) { echo attribute_escape( $_GET['s'] ); } else { _e( 'Search anything...', 'buddypress' ); } ?>"  onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
    1194         <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
    1195         <?php wp_nonce_field( 'directory_members', '_wpnonce-member-filter' ) ?>
    1196     </form>
    1197 <?php
    1198 }
    1199 
    1200 function bp_home_blog_url() {
    1201     global $bp, $current_blog;
    1202 
    1203     if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
    1204         $blog_id = $current_blog->blog_id;
    1205     } else {
    1206         $blog_id = BP_ROOT_BLOG;
    1207     }
    1208 
    1209     if ( 'bphome' == get_blog_option( $blog_id, 'template' ) )
    1210         echo $bp->root_domain . '/' . BP_HOME_BLOG_SLUG;
    1211     else
    1212         echo $bp->root_domain;
    1213 }
    1214 
    12151224
    12161225/* Template functions for fetching globals, without querying the DB again
     
    12381247}
    12391248
    1240 function bp_user_fullname() {
    1241     global $bp;
    1242     echo apply_filters( 'bp_user_fullname', $bp->displayed_user->fullname );
    1243 }
    1244     function bp_displayed_user_fullname() {
     1249
     1250function bp_displayed_user_fullname() {
     1251    echo bp_get_displayed_user_fullname();
     1252}
     1253    function bp_get_displayed_user_fullname() {
    12451254        global $bp;
    12461255
    12471256        return apply_filters( 'bp_displayed_user_fullname', $bp->displayed_user->fullname );
    12481257    }
     1258    function bp_user_fullname() { echo bp_get_displayed_user_fullname(); }
     1259
    12491260
    12501261function bp_loggedin_user_fullname() {
     
    12851296    }
    12861297
     1298/* This function will pass a AJAX built querystring to a loop in the template */
     1299function bp_ajax_querystring() {
     1300    global $bp;
     1301
     1302    return apply_filters( 'bp_ajax_querystring', $bp->ajax_querystring );
     1303}
     1304
    12871305/* Template is_() functions to determine the current page */
    12881306
     
    13721390
    13731391    if ( BP_ACTIVITY_SLUG == $bp->current_component && 'my-friends' == $bp->current_action )
     1392        return true;
     1393
     1394    return false;
     1395}
     1396
     1397function bp_is_activity_permalink() {
     1398    global $bp;
     1399
     1400    if ( BP_ACTIVITY_SLUG == $bp->current_component && is_numeric( $bp->current_action ) )
    13741401        return true;
    13751402
     
    17531780        if ( bp_is_user_activity() )
    17541781            $bp_classes[] = 'my-activity';
     1782
     1783        if ( bp_is_activity_permalink() )
     1784            $bp_classes[] = 'activity-permalink';
    17551785
    17561786        if ( bp_is_register_page() )
  • trunk/bp-core/bp-core-widgets.php

    r2077 r2168  
    8787           . $after_title; ?>
    8888
    89         <?php if ( bp_has_site_members( 'type=newest&max=' . $instance['max_members'] ) ) : ?>
     89        <?php if ( bp_has_members( 'type=newest&max=' . $instance['max_members'] ) ) : ?>
    9090            <div class="item-options" id="members-list-options">
    9191                <span class="ajax-loader" id="ajax-loader-members"></span>
     
    9696
    9797            <ul id="members-list" class="item-list">
    98                 <?php while ( bp_site_members() ) : bp_the_site_member(); ?>
     98                <?php while ( bp_members() ) : bp_the_member(); ?>
    9999                    <li class="vcard">
    100100                        <div class="item-avatar">
    101                             <a href="<?php bp_the_site_member_link() ?>"><?php bp_the_site_member_avatar() ?></a>
     101                            <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
    102102                        </div>
    103103
    104104                        <div class="item">
    105                             <div class="item-title fn"><a href="<?php bp_the_site_member_link() ?>" title="<?php bp_the_site_member_name() ?>"><?php bp_the_site_member_name() ?></a></div>
    106                             <div class="item-meta"><span class="activity"><?php echo bp_core_get_last_activity( bp_get_the_site_member_registered(), __( 'registered %s ago', 'buddypress' ) ) ?></span></div>
     105                            <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
     106                            <div class="item-meta"><span class="activity"><?php bp_member_registered() ?></span></div>
    107107                        </div>
    108108                    </li>
     
    159159           . $after_title; ?>
    160160
    161         <?php if ( bp_has_site_members( 'type=online&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] ) ) : ?>
     161        <?php if ( bp_has_members( 'type=online&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] ) ) : ?>
    162162            <div class="avatar-block">
    163                 <?php while ( bp_site_members() ) : bp_the_site_member(); ?>
     163                <?php while ( bp_members() ) : bp_the_site_member(); ?>
    164164                    <div class="item-avatar">
    165165                        <a href="<?php bp_the_site_member_link() ?>" title="<?php bp_the_site_member_name() ?>"><?php bp_the_site_member_avatar() ?></a>
     
    259259    switch ( $_POST['filter'] ) {
    260260        case 'newest-members':
    261             if ( !$users = wp_cache_get( 'newest_users', 'bp' ) ) {
    262                 $users = BP_Core_User::get_newest_users( $_POST['max-members'], 1 );
    263                 wp_cache_set( 'newest_users', $users, 'bp' );
    264             }
     261            $type = 'newest';
    265262        break;
    266263        case 'recently-active-members':
    267             if ( !$users = wp_cache_get( 'active_users', 'bp' ) ) {
    268                 $users = BP_Core_User::get_active_users( $_POST['max-members'], 1 );
    269                 wp_cache_set( 'active_users', $users, 'bp' );
    270             }
     264            $type = 'active';
    271265        break;
    272266        case 'popular-members':
    273             if ( !$users = wp_cache_get( 'popular_users', 'bp' ) ) {
    274                 $users = BP_Core_User::get_popular_users( $_POST['max-members'], 1 );
    275                 wp_cache_set( 'popular_users', $users, 'bp' );
    276             }
     267            $type = 'popular';
    277268        break;
    278     }
    279 
    280     if ( $users['users'] ) {
    281         echo '0[[SPLIT]]'; // return valid result.
    282 
    283         foreach ( (array) $users['users'] as $user ) {
    284         ?>
    285             <li class="vcard">
    286                 <div class="item-avatar">
    287                     <a href="<?php echo bp_core_get_userlink( $user->user_id, false, true ) ?>"><?php echo bp_core_get_avatar( $user->user_id, 1 ) ?></a>
    288                 </div>
    289 
    290                 <div class="item">
    291                     <div class="item-title"><?php echo bp_core_get_userlink( $user->user_id ) ?></div>
    292                     <div class="item-meta">
    293                         <span class="activity">
    294                             <?php
    295                             if ( 'newest-members' == $_POST['filter'] ) {
    296                                 echo bp_core_get_last_activity( $user->user_registered, __( 'registered %s ago', 'buddypress' ) );
    297                             } else if ( 'recently-active-members' == $_POST['filter'] ) {
    298                                 echo bp_core_get_last_activity( get_usermeta( $user->user_id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) );
    299                             } else if ( 'popular-members' == $_POST['filter'] ) {
    300                                 if ( 1 == get_usermeta( $user->user_id, 'total_friend_count' ) )
    301                                     echo get_usermeta( $user->user_id, 'total_friend_count' ) . __(' friend', 'buddypress');
    302                                 else
    303                                     echo get_usermeta( $user->user_id, 'total_friend_count' ) . __(' friends', 'buddypress');
    304                             }
    305                             ?>
    306                         </span>
     269    } ?>
     270    <?php if ( bp_has_members( 'type=' . $type . '&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] ) ) : ?>
     271        <?php echo '0[[SPLIT]]'; // return valid result. TODO: remove this because it's dumb. ?>
     272        <div class="avatar-block">
     273            <?php while ( bp_members() ) : bp_the_member(); ?>
     274                <li class="vcard">
     275                    <div class="item-avatar">
     276                        <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
    307277                    </div>
    308                 </div>
    309             </li>
    310             <?php
    311         }
    312     } else {
    313         echo "-1[[SPLIT]]<li>" . __("No members matched the current filter.", 'buddypress');
    314     }
     278
     279                    <div class="item">
     280                        <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
     281                        <?php if ( 'active' == $type ) : ?>
     282                            <div class="item-meta"><span class="activity"><?php bp_member_last_active() ?></span></div>
     283                        <?php else : ?>
     284                            <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count() ?></span></div>
     285                        <?php endif; ?>
     286                    </div>
     287                </li>
     288
     289            <?php endwhile; ?>
     290        </div>
     291    <?php else: ?>
     292        <?php echo "-1[[SPLIT]]<li>"; ?>
     293        <?php _e( 'There were no members found, please try another filter.', 'buddypress' ) ?>
     294        <?php echo "</li>"; ?>
     295    <?php endif;
    315296}
    316297add_action( 'wp_ajax_widget_members', 'bp_core_ajax_widget_members' );
  • trunk/bp-core/js/widget-members.js

    r1838 r2168  
    11jQuery(document).ready( function() {
    2     jQuery("div#members-list-options a").livequery('click',
    3         function() { 
     2    jQuery("div#members-list-options a").live('click',
     3        function() {
    44            jQuery('#ajax-loader-members').toggle();
    55
     
    1515            },
    1616            function(response)
    17             {   
     17            {
    1818                jQuery('#ajax-loader-members').toggle();
    1919                member_wiget_response(response);
    2020            });
    21        
     21
    2222            return false;
    2323        }
     
    3030
    3131    if ( response[0] != "-1" ) {
    32         jQuery("ul#members-list").fadeOut(200, 
     32        jQuery("ul#members-list").fadeOut(200,
    3333            function() {
    3434                jQuery("ul#members-list").html(response[1]);
     
    3737        );
    3838
    39     } else {                   
    40         jQuery("ul#members-list").fadeOut(200, 
     39    } else {
     40        jQuery("ul#members-list").fadeOut(200,
    4141            function() {
    4242                var message = '<p>' + response[1] + '</p>';
  • trunk/bp-forums.php

    r2077 r2168  
    6262
    6363        do_action( 'bbpress_init' );
     64
     65        /* Check to see if the user has posted a new topic from the forums page. */
     66        if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) {
     67            /* Check the nonce */
     68            check_admin_referer( 'bp_forums_new_topic' );
     69
     70            if ( $group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
     71                /* Auto join this user if they are not yet a member of this group */
     72                if ( !is_site_admin() && 'public' == $group->status && !groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
     73                    groups_join_group( $group->id, $group->id );
     74
     75                if ( $forum_id = groups_get_groupmeta( $group->id, 'forum_id' ) ) {
     76                    if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
     77                        bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
     78                    else
     79                        bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
     80
     81                    bp_core_redirect( bp_get_group_permalink( $group ) . '/forum/topic/' . $topic->topic_slug . '/' );
     82                }
     83            }
     84        }
     85
    6486        do_action( 'bp_forums_directory_forums_setup' );
    65         bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'directories/forums/index' ) );
     87
     88        bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
    6689    }
    6790}
     
    391414}
    392415add_filter( 'user_has_cap', 'bp_forums_filter_caps' );
     416
     417/**
     418 * bp_forums_filter_template_paths()
     419 *
     420 * Add fallback for the bp-sn-parent theme template locations used in BuddyPress versions
     421 * older than 1.2.
     422 *
     423 * @package BuddyPress Core
     424 */
     425function bp_forums_filter_template_paths() {
     426    if ( 'bp-sn-parent' != basename( TEMPLATEPATH ) && !defined( 'BP_CLASSIC_TEMPLATE_STRUCTURE' ) )
     427        return false;
     428
     429    add_filter( 'bp_forums_template_directory_forums_setup', create_function( '', 'return "directories/forums/index";' ) );
     430}
     431add_action( 'init', 'bp_forums_filter_template_paths' );
     432
    393433?>
  • trunk/bp-forums/bp-forums-templatetags.php

    r2077 r2168  
    1919    var $order;
    2020
    21     function BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter ) {
     21    function BP_Forums_Template_Forum( $type, $forum_id, $page, $per_page, $max, $no_stickies, $filter ) {
    2222        global $bp;
    2323
    24         $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 1;
     24        $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : $page;
    2525        $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page;
    2626
     
    100100            'total' => ceil($this->total_topic_count / $this->pag_num),
    101101            'current' => $this->pag_page,
    102             'prev_text' => '&laquo;',
    103             'next_text' => '&raquo;',
     102            'prev_text' => '&larr;',
     103            'next_text' => '&rarr;',
    104104            'mid_size' => 1
    105105        ));
     
    158158        'type' => 'newest',
    159159        'forum_id' => false,
     160        'page' => 1,
    160161        'per_page' => 15,
    161162        'max' => false,
     
    184185        $filter = $_GET['fs'];
    185186
    186     $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter );
     187    $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $page, $per_page, $max, $no_stickies, $filter );
    187188
    188189    return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template );
     
    532533        extract( $r, EXTR_SKIP );
    533534
    534         $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit', 'buddypress' ) . '</a>';
     535        $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit Topic', 'buddypress' ) . '</a>';
    535536
    536537        if ( $bp->is_item_admin || $bp->is_item_mod || is_site_admin() ) {
    537538            if ( 0 == (int)$forum_template->topic->topic_sticky )
    538                 $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky', 'buddypress' ) . '</a>';
     539                $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky Topic', 'buddypress' ) . '</a>';
    539540            else
    540                 $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick', 'buddypress' ) . '</a>';
     541                $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick Topic', 'buddypress' ) . '</a>';
    541542
    542543            if ( 0 == (int)$forum_template->topic->topic_open )
    543                 $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open', 'buddypress' ) . '</a>';
     544                $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open Topic', 'buddypress' ) . '</a>';
    544545            else
    545                 $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close', 'buddypress' ) . '</a>';
    546 
    547             $links[] = '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>';
     546                $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close Topic', 'buddypress' ) . '</a>';
     547
     548            $links[] = '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete Topic', 'buddypress' ) . '</a>';
    548549        }
    549550
     
    896897        extract( $r, EXTR_SKIP );
    897898
    898         $links  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . $topic_template->post->id . 'edit/post/' . $topic_template->post->post_id, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
    899         $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete/post/' . $topic_template->post->post_id, 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>';
     899        $links  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . $topic_template->post->id . 'edit/post/' . $topic_template->post->post_id, 'bp_forums_edit_post' ) . '">' . __( 'Edit Post', 'buddypress' ) . '</a> ' . $seperator . ' ';
     900        $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete/post/' . $topic_template->post->post_id, 'bp_forums_delete_post' ) . '">' . __( 'Delete Post', 'buddypress' ) . '</a>';
    900901
    901902        return $links;
  • trunk/bp-friends.php

    r2120 r2168  
    99require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-classes.php' );
    1010require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-templatetags.php' );
    11 
    12 /* Include deprecated functions if settings allow */
    13 if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
    14     require ( BP_PLUGIN_DIR . '/bp-friends/deprecated/bp-friends-deprecated.php' );
    1511
    1612function friends_install() {
     
    7167
    7268    /* Add 'Friends' to the main navigation */
    73     bp_core_new_nav_item( array( 'name' => __('Friends', 'buddypress'), 'slug' => $bp->friends->slug, 'position' => 60, 'screen_function' => 'friends_screen_my_friends', 'default_subnav_slug' => 'my-friends', 'item_css_id' => $bp->friends->id ) );
     69    bp_core_new_nav_item( array( 'name' => sprintf( __( 'Friends (%d)', 'buddypress' ), friends_get_total_friend_count() ), 'slug' => $bp->friends->slug, 'position' => 60, 'screen_function' => 'friends_screen_my_friends', 'default_subnav_slug' => 'my-friends', 'item_css_id' => $bp->friends->id ) );
    7470
    7571    $friends_link = $bp->loggedin_user->domain . $bp->friends->slug . '/';
     
    110106    do_action( 'friends_screen_my_friends' );
    111107
    112     bp_core_load_template( apply_filters( 'friends_template_my_friends', 'friends/index' ) );
     108    bp_core_load_template( apply_filters( 'friends_template_my_friends', 'members/single/friends' ) );
    113109}
    114110
     
    131127        check_admin_referer( 'friends_reject_friendship' );
    132128
    133 
    134129        if ( friends_reject_friendship( $bp->action_variables[1] ) ) {
    135130            bp_core_add_message( __( 'Friendship rejected', 'buddypress' ) );
     
    142137    do_action( 'friends_screen_requests' );
    143138
    144     bp_core_load_template( apply_filters( 'friends_template_requests', 'friends/requests' ) );
    145 }
    146 
    147 function friends_screen_friend_finder() {
    148     do_action( 'friends_screen_friend_finder' );
    149     bp_core_load_template( apply_filters( 'friends_template_friend_finder', 'friends/friend-finder' ) );
     139    bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/friends' ) );
    150140}
    151141
     
    354344 */
    355345
    356 function friends_check_user_has_friends( $user_id ) {
    357     $friend_count = get_usermeta( $user_id, 'total_friend_count');
    358 
    359     if ( empty( $friend_count ) )
    360         return false;
    361 
    362     if ( !(int)$friend_count )
    363         return false;
    364 
    365     return true;
    366 }
    367 
    368 function friends_get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false, $filter = false ) {
    369     return BP_Friends_Friendship::get_friend_user_ids( $user_id, $friend_requests_only, $assoc_arr, $filter );
    370 }
    371 
    372 function friends_get_friendship_ids( $user_id, $friend_requests_only = false ) {
    373     return BP_Friends_Friendship::get_friendship_ids( $user_id, $friend_requests_only );
    374 }
    375 
    376 function friends_search_friends( $search_terms, $user_id, $pag_num = 10, $pag_page = 1 ) {
    377     return BP_Friends_Friendship::search_friends( $search_terms, $user_id, $pag_num, $pag_page );
    378 }
    379 
    380 function friends_get_friendship_requests( $user_id ) {
    381     $fship_ids = friends_get_friendship_ids( $user_id, true );
    382 
    383     return array( 'requests' => $fship_ids, 'total' => count($fship_ids) );
    384 }
    385 
    386 function friends_get_recently_active( $user_id, $pag_num = false, $pag_page = false, $filter = false ) {
    387     if ( $filter )
    388         $friend_ids = friends_search_friends( $filter, $user_id, false );
    389     else
    390         $friend_ids = friends_get_friend_user_ids( $user_id );
    391 
    392     if ( !$friend_ids )
    393         return false;
    394 
    395     if ( $filter )
    396         $friend_ids = $friend_ids['friends'];
    397 
    398     $ids_and_activity = friends_get_bulk_last_active( implode( ',', (array)$friend_ids ) );
    399 
    400     if ( !$ids_and_activity )
    401         return false;
    402 
    403     $total_friends = count( $ids_and_activity );
    404 
    405     if ( $pag_num && $pag_page )
    406         return array( 'friends' => array_slice( $ids_and_activity, intval( ( $pag_page - 1 ) * $pag_num), intval( $pag_num ) ), 'total' => $total_friends );
    407     else
    408         return array( 'friends' => $ids_and_activity, 'total' => $total_friends );
    409 }
    410 
    411 function friends_get_alphabetically( $user_id, $pag_num = false, $pag_page = false, $filter = false ) {
    412     if ( $filter )
    413         $friend_ids = friends_search_friends( $filter, $user_id, false );
    414     else
    415         $friend_ids = friends_get_friend_user_ids( $user_id );
    416 
    417     if ( !$friend_ids )
    418         return false;
    419 
    420     if ( $filter )
    421         $friend_ids = $friend_ids['friends'];
    422 
    423     $sorted_ids = BP_Friends_Friendship::sort_by_name( implode( ',', $friend_ids ) );
    424 
    425     if ( !$sorted_ids )
    426         return false;
    427 
    428     $total_friends = count( $sorted_ids );
    429 
    430     if ( $pag_num && $pag_page )
    431         return array( 'friends' => array_slice( $sorted_ids, intval( ( $pag_page - 1 ) * $pag_num), intval( $pag_num ) ), 'total' => $total_friends );
    432     else
    433         return array( 'friends' => $sorted_ids, 'total' => $total_friends );
    434 }
    435 
    436 function friends_get_newest( $user_id, $pag_num = false, $pag_page = false, $filter = false ) {
    437     if ( $filter )
    438         $friend_ids = friends_search_friends( $filter, $user_id, false );
    439     else
    440         $friend_ids = friends_get_friend_user_ids( $user_id );
    441 
    442     if ( !$friend_ids )
    443         return false;
    444 
    445     if ( $filter )
    446         $friend_ids = $friend_ids['friends'];
    447 
    448     $total_friends = count( $friend_ids );
    449 
    450     if ( $pag_num && $pag_page )
    451         return array( 'friends' => array_slice( $friend_ids, intval( ( $pag_page - 1 ) * $pag_num), intval( $pag_num ) ), 'total' => $total_friends );
    452     else
    453         return array( 'friends' => $friend_ids, 'total' => $total_friends );
    454 }
    455 
    456 function friends_get_bulk_last_active( $friend_ids ) {
    457     return BP_Friends_Friendship::get_bulk_last_active( $friend_ids );
    458 }
    459 
    460 function friends_get_friends_list( $user_id ) {
    461     global $bp;
    462 
    463     $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );
    464 
    465     if ( !$friend_ids )
    466         return false;
    467 
    468     for ( $i = 0; $i < count($friend_ids); $i++ ) {
    469         if ( function_exists('bp_user_fullname') )
    470             $display_name = bp_core_get_user_displayname( $friend_ids[$i] );
    471 
    472         if ( $display_name != ' ' ) {
    473             $friends[] = array(
    474                 'id' => $friend_ids[$i],
    475                 'full_name' => $display_name
    476             );
    477         }
    478     }
    479 
    480     if ( $friends && is_array($friends) )
    481         usort($friends, 'friends_sort_by_name');
    482 
    483     if ( !$friends )
    484         return false;
    485 
    486     return $friends;
    487 }
    488 
    489     function friends_sort_by_name($a, $b) {
    490         return strcasecmp($a['full_name'], $b['full_name']);
    491     }
    492 
    493 function friends_get_friends_invite_list( $user_id = false, $group_id ) {
    494     global $bp;
    495 
    496     if ( !$user_id )
    497         $user_id = $bp->loggedin_user->id;
    498 
    499     $friend_ids = friends_get_alphabetically( $user_id );
    500 
    501     if ( (int) $friend_ids['total'] < 1 )
    502         return false;
    503 
    504     for ( $i = 0; $i < count($friend_ids['friends']); $i++ ) {
    505         if ( groups_check_user_has_invite( $friend_ids['friends'][$i]->user_id, $group_id ) || groups_is_user_member( $friend_ids['friends'][$i]->user_id, $group_id ) )
    506             continue;
    507 
    508         $display_name = bp_core_get_user_displayname( $friend_ids['friends'][$i]->user_id );
    509 
    510         if ( $display_name != ' ' ) {
    511             $friends[] = array(
    512                 'id' => $friend_ids['friends'][$i]->user_id,
    513                 'full_name' => $display_name
    514             );
    515         }
    516     }
    517 
    518     if ( !$friends )
    519         return false;
    520 
    521     return $friends;
    522 }
    523 
    524 function friends_count_invitable_friends( $user_id, $group_id ) {
    525     return BP_Friends_Friendship::get_invitable_friend_count( $user_id, $group_id );
    526 }
    527 
    528 function friends_get_friend_count_for_user( $user_id ) {
    529     return BP_Friends_Friendship::total_friend_count( $user_id );
    530 }
    531 
    532 function friends_search_users( $search_terms, $user_id, $pag_num = false, $pag_page = false ) {
    533     global $bp;
    534 
    535     $user_ids = BP_Friends_Friendship::search_users( $search_terms, $user_id, $pag_num, $pag_page );
    536 
    537     if ( !$user_ids )
    538         return false;
    539 
    540     for ( $i = 0; $i < count($user_ids); $i++ ) {
    541         $users[] = new BP_Core_User($user_ids[$i]);
    542     }
    543 
    544     return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count($search_terms) );
    545 }
    546 
    547 function friends_check_friendship( $user_id, $possible_friend_id ) {
    548     global $bp;
    549 
    550     if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) )
    551         return true;
    552 
    553     return false;
    554 }
    555 
    556346function friends_add_friend( $initiator_userid, $friend_userid, $force_accept = false ) {
    557347    global $bp;
     
    676466}
    677467
     468function friends_check_friendship( $user_id, $possible_friend_id ) {
     469    global $bp;
     470
     471    if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) )
     472        return true;
     473
     474    return false;
     475}
     476
     477function friends_get_total_friend_count( $user_id = false ) {
     478    global $bp;
     479
     480    if ( !$user_id )
     481        $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
     482
     483    return apply_filters( 'friends_get_total_friend_count', get_usermeta( $user_id, 'total_friend_count' ) );
     484}
     485
     486function friends_check_user_has_friends( $user_id ) {
     487    $friend_count = friends_get_total_friend_count( $user_id );
     488
     489    if ( empty( $friend_count ) )
     490        return false;
     491
     492    if ( !(int)$friend_count )
     493        return false;
     494
     495    return true;
     496}
     497
     498function friends_get_friendship_id( $initiator_user_id, $friend_user_id ) {
     499    return BP_Friends_Friendship::get_friendship_id( $initiator_user_id, $friend_user_id );
     500}
     501
     502function friends_get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false, $filter = false ) {
     503    return BP_Friends_Friendship::get_friend_user_ids( $user_id, $friend_requests_only, $assoc_arr, $filter );
     504}
     505
     506function friends_search_friends( $search_terms, $user_id, $pag_num = 10, $pag_page = 1 ) {
     507    return BP_Friends_Friendship::search_friends( $search_terms, $user_id, $pag_num, $pag_page );
     508}
     509
     510function friends_get_friendship_request_user_ids( $user_id ) {
     511    return BP_Friends_Friendship::get_friendship_request_user_ids( $user_id );
     512}
     513
     514function friends_get_recently_active( $user_id, $per_page = false, $page = false, $filter = false ) {
     515    return apply_filters( 'friends_get_recently_active', BP_Core_User::get_users( 'active', $per_page, $page, $user_id, $filter ) );
     516}
     517
     518function friends_get_alphabetically( $user_id, $per_page = false, $page = false, $filter = false ) {
     519    return apply_filters( 'friends_get_alphabetically', BP_Core_User::get_users( 'alphabetical', $per_page, $page, $user_id, $filter ) );
     520}
     521
     522function friends_get_newest( $user_id, $per_page = false, $page = false, $filter = false ) {
     523    return apply_filters( 'friends_get_newest', BP_Core_User::get_users( 'newest', $per_page, $page, $user_id, $filter ) );
     524}
     525
     526function friends_get_bulk_last_active( $friend_ids ) {
     527    return BP_Friends_Friendship::get_bulk_last_active( $friend_ids );
     528}
     529
     530function friends_get_friends_list( $user_id ) {
     531    global $bp;
     532
     533    $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );
     534
     535    if ( !$friend_ids )
     536        return false;
     537
     538    for ( $i = 0; $i < count($friend_ids); $i++ ) {
     539        if ( function_exists('bp_user_fullname') )
     540            $display_name = bp_core_get_user_displayname( $friend_ids[$i] );
     541
     542        if ( $display_name != ' ' ) {
     543            $friends[] = array(
     544                'id' => $friend_ids[$i],
     545                'full_name' => $display_name
     546            );
     547        }
     548    }
     549
     550    if ( $friends && is_array($friends) )
     551        usort($friends, 'friends_sort_by_name');
     552
     553    if ( !$friends )
     554        return false;
     555
     556    return $friends;
     557}
     558
     559    function friends_sort_by_name($a, $b) {
     560        return strcasecmp($a['full_name'], $b['full_name']);
     561    }
     562
     563function friends_get_friends_invite_list( $user_id = false, $group_id ) {
     564    global $bp;
     565
     566    if ( !$user_id )
     567        $user_id = $bp->loggedin_user->id;
     568
     569    $friend_ids = friends_get_alphabetically( $user_id );
     570
     571    if ( (int) $friend_ids['total'] < 1 )
     572        return false;
     573
     574    for ( $i = 0; $i < count($friend_ids['friends']); $i++ ) {
     575        if ( groups_check_user_has_invite( $friend_ids['friends'][$i]->user_id, $group_id ) || groups_is_user_member( $friend_ids['friends'][$i]->user_id, $group_id ) )
     576            continue;
     577
     578        $display_name = bp_core_get_user_displayname( $friend_ids['friends'][$i]->user_id );
     579
     580        if ( $display_name != ' ' ) {
     581            $friends[] = array(
     582                'id' => $friend_ids['friends'][$i]->user_id,
     583                'full_name' => $display_name
     584            );
     585        }
     586    }
     587
     588    if ( !$friends )
     589        return false;
     590
     591    return $friends;
     592}
     593
     594function friends_count_invitable_friends( $user_id, $group_id ) {
     595    return BP_Friends_Friendship::get_invitable_friend_count( $user_id, $group_id );
     596}
     597
     598function friends_get_friend_count_for_user( $user_id ) {
     599    return BP_Friends_Friendship::total_friend_count( $user_id );
     600}
     601
     602function friends_search_users( $search_terms, $user_id, $pag_num = false, $pag_page = false ) {
     603    global $bp;
     604
     605    $user_ids = BP_Friends_Friendship::search_users( $search_terms, $user_id, $pag_num, $pag_page );
     606
     607    if ( !$user_ids )
     608        return false;
     609
     610    for ( $i = 0; $i < count($user_ids); $i++ ) {
     611        $users[] = new BP_Core_User($user_ids[$i]);
     612    }
     613
     614    return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count($search_terms) );
     615}
     616
    678617function friends_is_friendship_confirmed( $friendship_id ) {
    679618    $friendship = new BP_Friends_Friendship( $friendship_id );
     
    691630}
    692631
     632/**
     633 * friends_filter_template_paths()
     634 *
     635 * Add fallback for the bp-sn-parent theme template locations used in BuddyPress versions
     636 * older than 1.2.
     637 *
     638 * @package BuddyPress Core
     639 */
     640function friends_filter_template_paths() {
     641    if ( 'bp-sn-parent' != basename( TEMPLATEPATH ) && !defined( 'BP_CLASSIC_TEMPLATE_STRUCTURE' ) )
     642        return false;
     643
     644    add_filter( 'friends_template_my_friends', create_function( '', 'return "friends/index";' ) );
     645    add_filter( 'friends_template_requests', create_function( '', 'return "friends/requests";' ) );
     646}
     647add_action( 'init', 'friends_filter_template_paths' );
     648
    693649function friends_remove_data( $user_id ) {
    694650    BP_Friends_Friendship::delete_all_for_user($user_id);
  • trunk/bp-friends/bp-friends-classes.php

    r2114 r2168  
    104104    }
    105105
    106     function get_friendship_ids( $user_id, $friend_requests_only = false ) {
    107         global $wpdb, $bp;
    108 
    109         if ( $friend_requests_only ) {
    110             $oc_sql = $wpdb->prepare( "AND is_confirmed = 0" );
    111             $friend_sql = $wpdb->prepare ( " WHERE friend_user_id = %d", $user_id );
    112         } else {
    113             $oc_sql = $wpdb->prepare( "AND is_confirmed = 1" );
    114             $friend_sql = $wpdb->prepare ( " WHERE (initiator_user_id = %d OR friend_user_id = %d)", $user_id, $user_id );
    115         }
    116 
    117         return $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->friends->table_name} $friend_sql $oc_sql" ) );
    118     }
    119 
    120106    function get_friendship_id( $user_id, $friend_id ) {
    121107        global $wpdb, $bp;
     
    124110    }
    125111
    126     function total_friend_count( $user_id = false) {
     112    function get_friendship_request_user_ids( $user_id ) {
     113        global $wpdb, $bp;
     114
     115        return $wpdb->get_col( $wpdb->prepare( "SELECT initiator_user_id FROM {$bp->friends->table_name} WHERE friend_user_id = %d AND is_confirmed = 0", $user_id ) );
     116    }
     117
     118    function total_friend_count( $user_id = false ) {
    127119        global $wpdb, $bp;
    128120
    129121        if ( !$user_id )
    130             $user_id = $bp->displayed_user->id;
     122            $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
    131123
    132124        /* This is stored in 'total_friend_count' usermeta.
  • trunk/bp-friends/bp-friends-templatetags.php

    r2128 r2168  
    11<?php
    22
    3 class BP_Friendship_Template {
    4     var $current_friendship = -1;
    5     var $friendship_count;
    6     var $friendships;
    7     var $friendship;
    8 
    9     var $in_the_loop;
    10 
    11     var $pag_page;
    12     var $pag_num;
    13     var $pag_links;
    14     var $total_friend_count;
    15 
    16     function bp_friendship_template( $user_id, $type, $per_page, $max, $filter ) {
    17         global $bp;
    18 
    19         if ( !$user_id )
    20             $user_id = $bp->displayed_user->id;
    21 
    22         $this->pag_page = isset( $_REQUEST['frpage'] ) ? intval( $_REQUEST['frpage'] ) : 1;
    23         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    24         $this->type = $type;
    25 
    26         switch ( $type ) {
    27             case 'newest':
    28                 $this->friendships = friends_get_newest( $user_id, $this->pag_num, $this->pag_page, $filter );
    29                 break;
    30 
    31             case 'alphabetical':
    32                 $this->friendships = friends_get_alphabetically( $user_id, $this->pag_num, $this->pag_page, $filter );
    33                 break;
    34 
    35             case 'requests':
    36                 $this->friendships = friends_get_friendship_requests( $user_id );
    37                 break;
    38 
    39             case 'active': default:
    40                 $this->friendships = friends_get_recently_active( $user_id, $this->pag_num, $this->pag_page, $filter );
    41                 break;
    42         }
    43 
    44         if ( 'requests' == $type ) {
    45             $this->total_friend_count = $this->friendships['total'];
    46             $this->friendships = $this->friendships['requests'];
    47             $this->friendship_count = count($this->friendships);
    48         } else {
    49             if ( !$max || $max >= (int)$this->friendships['total'] )
    50                 $this->total_friend_count = (int)$this->friendships['total'];
    51             else
    52                 $this->total_friend_count = (int)$max;
    53 
    54             $this->friendships = $this->friendships['friends'];
    55 
    56             if ( $max ) {
    57                 if ( $max >= count($this->friendships) )
    58                     $this->friendship_count = count($this->friendships);
    59                 else
    60                     $this->friendship_count = (int)$max;
    61             } else {
    62                 $this->friendship_count = count($this->friendships);
    63             }
    64         }
    65 
    66         $this->pag_links = paginate_links( array(
    67             'base' => add_query_arg( 'frpage', '%#%' ),
    68             'format' => '',
    69             'total' => ceil($this->total_friend_count / $this->pag_num),
    70             'current' => $this->pag_page,
    71             'prev_text' => '&laquo;',
    72             'next_text' => '&raquo;',
    73             'mid_size' => 1
    74         ));
    75     }
    76 
    77     function has_friendships() {
    78         if ( $this->friendship_count )
    79             return true;
    80 
    81         return false;
    82     }
    83 
    84     function next_friendship() {
    85         $this->current_friendship++;
    86         $this->friendship = $this->friendships[$this->current_friendship];
    87 
    88         return $this->friendship;
    89     }
    90 
    91     function rewind_friendships() {
    92         $this->current_friendship = -1;
    93         if ( $this->friendship_count > 0 ) {
    94             $this->friendship = $this->friendships[0];
    95         }
    96     }
    97 
    98     function user_friendships() {
    99         if ( $this->current_friendship + 1 < $this->friendship_count ) {
    100             return true;
    101         } elseif ( $this->current_friendship + 1 == $this->friendship_count ) {
    102             do_action('loop_end');
    103             // Do some cleaning up after the loop
    104             $this->rewind_friendships();
    105         }
    106 
    107         $this->in_the_loop = false;
    108         return false;
    109     }
    110 
    111     function the_friendship() {
    112         global $friendship, $bp;
    113 
    114         $this->in_the_loop = true;
    115         $this->friendship = $this->next_friendship();
    116 
    117         if ( 'requests' == $this->type ) {
    118             $this->friendship = new BP_Friends_Friendship( $this->friendship );
    119             $this->friendship->user_id = ( $this->friendship->friend_user_id == $bp->loggedin_user->id ) ?  $this->friendship->initiator_user_id : $this->friendship->friend_user_id;
    120         } else {
    121             if ( 'newest' == $this->type )
    122                 $user_id = $this->friendship;
    123             else
    124                 $user_id = $this->friendship->user_id;
    125 
    126             $this->friendship = new stdClass;
    127 
    128             if ( !$this->friendship->friend = wp_cache_get( 'bp_user_' . $user_id, 'bp' ) ) {
    129                 $this->friendship->friend = new BP_Core_User( $user_id );
    130                 wp_cache_set( 'bp_user_' . $user_id, $this->friendship->friend, 'bp' );
    131             }
    132 
    133             /* Make sure the user_id is available in the friend object. */
    134             $this->friendship->friend->user_id = $user_id;
    135         }
    136 
    137         if ( 0 == $this->current_friendship ) // loop has just started
    138             do_action('loop_start');
    139     }
    140 }
    141 
    142 function bp_has_friendships( $args = '' ) {
    143     global $bp, $friends_template;
    144 
    145     $defaults = array(
    146         'type' => 'active',
    147         'user_id' => false,
    148         'per_page' => 10,
    149         'max' => false,
    150         'filter' => false
    151     );
    152 
    153     $r = wp_parse_args( $args, $defaults );
    154     extract( $r, EXTR_SKIP );
    155 
    156     /* The following code will auto set parameters based on the page being viewed.
    157      * for example on example.com/members/andy/friends/my-friends/newest/
    158      * $type = 'newest'
    159      */
    160     if ( 'my-friends' == $bp->current_action ) {
    161         $order = $bp->action_variables[0];
    162         if ( 'newest' == $order )
    163             $type = 'newest';
    164         else if ( 'alphabetically' == $order )
    165             $type = 'alphabetical';
    166     } else if ( 'requests' == $bp->current_action ) {
    167         $type = 'requests';
    168     }
    169 
    170     if ( isset( $_REQUEST['friend-search-box'] ) )
    171         $filter = $_REQUEST['friend-search-box'];
    172 
    173     $friends_template = new BP_Friendship_Template( $user_id, $type, $per_page, $max, $filter );
    174     return apply_filters( 'bp_has_friendships', $friends_template->has_friendships(), &$friends_template );
    175 }
    176 
    177 function bp_the_friendship() {
    178     global $friends_template;
    179     return $friends_template->the_friendship();
    180 }
    181 
    182 function bp_user_friendships() {
    183     global $friends_template;
    184     return $friends_template->user_friendships();
    185 }
    186 
    187 function bp_friend_id() {
    188     echo bp_get_friend_id();
    189 }
    190     function bp_get_friend_id() {
    191         global $friends_template;
    192 
    193         return apply_filters( 'bp_get_friend_id', $friends_template->friendship->friend->user_id );
    194     }
    195 
    196 function bp_friend_avatar_thumb( $args = '' ) {
    197     echo bp_get_friend_avatar_thumb( $args );
    198 }
    199     function bp_get_friend_avatar_thumb( $args = '' ) {
    200         global $bp, $friends_template;
    201 
    202         $defaults = array(
    203             'type' => 'thumb',
    204             'width' => false,
    205             'height' => false,
    206             'class' => 'avatar',
    207             'id' => false,
    208             'alt' => __( 'Group avatar', 'buddypress' )
    209         );
    210 
    211         $r = wp_parse_args( $args, $defaults );
    212         extract( $r, EXTR_SKIP );
    213 
    214         return apply_filters( 'bp_get_friend_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $friends_template->friendship->friend->id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class ) ) );
    215     }
    216 
    217 function bp_friend_name() {
    218     echo bp_get_friend_name();
    219 }
    220     function bp_get_friend_name() {
    221         global $friends_template;
    222 
    223         return apply_filters( 'bp_get_friend_name', strip_tags( $friends_template->friendship->friend->user_link ) );
    224     }
    225 
    226 function bp_friend_link() {
    227     echo bp_get_friend_link();
    228 }
    229     function bp_get_friend_link() {
    230         global $friends_template;
    231 
    232         return apply_filters( 'bp_get_friend_link', $friends_template->friendship->friend->user_link );
    233     }
    234 
    235 function bp_friend_url() {
    236     echo bp_get_friend_url();
    237 }
    238     function bp_get_friend_url() {
    239         global $friends_template;
    240 
    241         return apply_filters( 'bp_get_friend_url', $friends_template->friendship->friend->user_url );
    242     }
    243 
    244 function bp_friend_last_active() {
    245     echo bp_get_friend_last_active();
    246 }
    247     function bp_get_friend_last_active() {
    248         global $friends_template;
    249 
    250         return apply_filters( 'bp_get_friend_last_active', $friends_template->friendship->friend->last_active );
    251     }
    252 
    253 function bp_friend_time_since_requested() {
    254     echo bp_get_friend_time_since_requested();
    255 }
    256     function bp_get_friend_time_since_requested() {
    257         global $friends_template;
    258 
    259         if ( $friends_template->friendship->date_created != "0000-00-00 00:00:00" ) {
    260             return apply_filters( 'bp_friend_time_since_requested', sprintf( __( 'requested %s ago', 'buddypress' ), bp_core_time_since( strtotime( $friends_template->friendship->date_created ) ) ) );
    261         }
    262 
    263         return false;
    264     }
    265 
    266 function bp_friend_accept_request_link() {
    267     echo bp_get_friend_accept_request_link();
    268 }
    269     function bp_get_friend_accept_request_link() {
    270         global $friends_template, $bp;
    271 
    272         return apply_filters( 'bp_get_friend_accept_request_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/requests/accept/' . $friends_template->friendship->id, 'friends_accept_friendship' ) );
    273     }
    274 
    275 function bp_friend_reject_request_link() {
    276     echo bp_get_friend_reject_request_link();
    277 }
    278     function bp_get_friend_reject_request_link() {
    279         global $friends_template, $bp;
    280 
    281         return apply_filters( 'bp_get_friend_reject_request_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/requests/reject/' . $friends_template->friendship->id, 'friends_reject_friendship' ) );
    282     }
    283 
    284 function bp_friend_pagination() {
    285     echo bp_get_friend_pagination();
    286 }
    287     function bp_get_friend_pagination() {
    288         global $friends_template;
    289 
    290         return apply_filters( 'bp_friend_pagination', $friends_template->pag_links );
    291     }
    292 
    293 function bp_friend_pagination_count() {
    294     global $bp, $friends_template;
    295 
    296     $from_num = intval( ( $friends_template->pag_page - 1 ) * $friends_template->pag_num ) + 1;
    297     $to_num = ( $from_num + ( $friends_template->pag_num - 1 ) > $friends_template->total_friend_count ) ? $friends_template->total_friend_count : $from_num + ( $friends_template->pag_num - 1) ;
    298 
    299     echo sprintf( __( 'Viewing friend %d to %d (of %d friends)', 'buddypress' ), $from_num, $to_num, $friends_template->total_friend_count ); ?> &nbsp;
    300     <span class="ajax-loader"></span><?php
    301 }
    302 
    303 function bp_friend_total_for_member() {
    304     echo bp_get_friend_total_for_member();
    305 }
    306     function bp_get_friend_total_for_member() {
    307         return apply_filters( 'bp_get_friend_total_for_member', BP_Friends_Friendship::total_friend_count() );
    308     }
    309 
    310 function bp_friend_search_form() {
    311     global $friends_template, $bp;
    312 
    313     $action = $bp->displayed_user->domain . $bp->friends->slug . '/my-friends/search/';
    314     $label = __( 'Filter Friends', 'buddypress' );
    315 ?>
    316     <form action="<?php echo $action ?>" id="friend-search-form" method="post">
    317 
    318         <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label>
    319         <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />
    320 
    321         <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>
    322         <input type="hidden" name="initiator" id="initiator" value="<?php echo attribute_escape( $bp->displayed_user->id ) ?>" />
    323 
    324     </form>
    325 <?php
    326 }
    327 
    328 function bp_friends_is_filtered() {
    329     if ( isset( $_POST['friend-search-box'] ) )
    330         return true;
    331 
    332     return false;
    333 }
    334 
    335 function bp_friend_all_friends_link() {
     3function bp_friends_header_tabs() {
    3364    global $bp;
    337     echo apply_filters( 'bp_friend_all_friends_link', $bp->displayed_user->domain . 'my-friends/all-friends' );
    338 }
    339 
    340 function bp_friend_latest_update_link() {
    341     global $bp;
    342     echo apply_filters( 'bp_friend_latest_update_link', $bp->displayed_user->domain . 'my-friends/last-updated' );
    343 }
    344 
    345 function bp_friend_recent_activity_link() {
    346     global $bp;
    347     echo apply_filters( 'bp_friend_recent_activity_link', $bp->displayed_user->domain . 'my-friends/recently-active' );
    348 }
    349 
    350 function bp_friend_recent_status_link() {
    351     global $bp;
    352     echo apply_filters( 'bp_friend_recent_status_link', $bp->displayed_user->domain . 'my-friends/status-updates' );
    353 }
    354 
    355 function bp_add_friend_button( $potential_friend_id = false ) {
    356     echo bp_get_add_friend_button( $potential_friend_id );
    357 }
    358     function bp_get_add_friend_button( $potential_friend_id = false ) {
    359         global $bp, $friends_template;
    360 
    361         $button = false;
    362 
    363         if ( is_user_logged_in() ) {
    364 
    365             if ( !$potential_friend_id && $friends_template->friendship->friend )
    366                 $potential_friend_id = $friends_template->friendship->friend->id;
    367             else if ( !$potential_friend_id && !$friends_template->friendship->friend )
    368                 $potential_friend_id = $bp->displayed_user->id;
    369 
    370             if ( $bp->loggedin_user->id == $potential_friend_id )
    371                 return false;
    372 
    373             $friend_status = BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $potential_friend_id );
    374 
    375             $button = '<div class="generic-button friendship-button ' . $friend_status . '" id="friendship-button-' . $potential_friend_id . '">';
    376             if ( 'pending' == $friend_status ) {
    377                 $button .= '<a class="requested" href="' . $bp->loggedin_user->domain . $bp->friends->slug . '">' . __( 'Friendship Requested', 'buddypress' ) . '</a>';
    378             } else if ( 'is_friend' == $friend_status ) {
    379                 $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/remove-friend/' . $potential_friend_id, 'friends_remove_friend' ) . '" title="' . __('Cancel Friendship', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="remove" class="remove">' . __('Cancel Friendship', 'buddypress') . '</a>';
    380             } else {
    381                 $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/add-friend/' . $potential_friend_id, 'friends_add_friend' ) . '" title="' . __('Add Friend', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="add" class="add">' . __('Add Friend', 'buddypress') . '</a>';
    382             }
    383             $button .= '</div>';
    384         }
    385 
    386         return apply_filters( 'bp_get_add_friend_button', $button );
    387     }
    388 
    389 function bp_friends_header_tabs() {
    390     global $bp, $create_group_step, $completed_to_step;
    3915?>
    3926    <li<?php if ( !isset($bp->action_variables[0]) || 'recently-active' == $bp->action_variables[0] ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->friends->slug ?>/my-friends/recently-active"><?php _e( 'Recently Active', 'buddypress' ) ?></a></li>
     
    48397}
    48498
     99function bp_friend_search_form() {
     100    global $friends_template, $bp;
     101
     102    $action = $bp->displayed_user->domain . $bp->friends->slug . '/my-friends/search/';
     103    $label = __( 'Filter Friends', 'buddypress' );
     104    ?>
     105        <form action="<?php echo $action ?>" id="friend-search-form" method="post">
     106
     107        <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label>
     108        <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />
     109
     110        <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>
     111        <input type="hidden" name="initiator" id="initiator" value="<?php echo attribute_escape( $bp->displayed_user->id ) ?>" />
     112
     113        </form>
     114    <?php
     115}
     116
     117function bp_add_friend_button( $potential_friend_id = false ) {
     118    echo bp_get_add_friend_button( $potential_friend_id );
     119}
     120    function bp_get_add_friend_button( $potential_friend_id = false ) {
     121        global $bp, $friends_template;
     122
     123        $button = false;
     124
     125        if ( is_user_logged_in() ) {
     126
     127            if ( !$potential_friend_id && $friends_template->friendship->friend )
     128                $potential_friend_id = $friends_template->friendship->friend->id;
     129            else if ( !$potential_friend_id && !$friends_template->friendship->friend )
     130                $potential_friend_id = $bp->displayed_user->id;
     131
     132            if ( $bp->loggedin_user->id == $potential_friend_id )
     133                return false;
     134
     135            $friend_status = BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $potential_friend_id );
     136
     137            $button = '<div class="generic-button friendship-button ' . $friend_status . '" id="friendship-button-' . $potential_friend_id . '">';
     138            if ( 'pending' == $friend_status ) {
     139                $button .= '<a class="requested" href="' . $bp->loggedin_user->domain . $bp->friends->slug . '">' . __( 'Friendship Requested', 'buddypress' ) . '</a>';
     140            } else if ( 'is_friend' == $friend_status ) {
     141                $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/remove-friend/' . $potential_friend_id, 'friends_remove_friend' ) . '" title="' . __('Cancel Friendship', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="remove" class="remove">' . __('Cancel Friendship', 'buddypress') . '</a>';
     142            } else {
     143                $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/add-friend/' . $potential_friend_id, 'friends_add_friend' ) . '" title="' . __('Add Friend', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="add" class="add">' . __('Add Friend', 'buddypress') . '</a>';
     144            }
     145            $button .= '</div>';
     146        }
     147
     148        return apply_filters( 'bp_get_add_friend_button', $button );
     149    }
     150
     151function bp_get_friend_ids( $user_id = false ) {
     152    global $bp;
     153
     154    if ( !$user_id )
     155        $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
     156
     157    return implode( ',', friends_get_friend_user_ids( $user_id ) );
     158}
     159function bp_get_friendship_requests() {
     160    global $bp;
     161
     162    return apply_filters( 'bp_get_friendship_requests', implode( ',', (array) friends_get_friendship_request_user_ids( $bp->loggedin_user->id ) ) );
     163}
     164
     165function bp_friend_accept_request_link() {
     166    echo bp_get_friend_accept_request_link();
     167}
     168    // You only have the user ID but you need the friendship ID !!
     169
     170    function bp_get_friend_accept_request_link() {
     171        global $members_template, $bp;
     172
     173        if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id ) ) {
     174            $friendship_id = friends_get_friendship_id( $members_template->member->id, $bp->loggedin_user->id );
     175            wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp' );
     176        }
     177
     178        return apply_filters( 'bp_get_friend_accept_request_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/requests/accept/' . $friendship_id, 'friends_accept_friendship' ) );
     179    }
     180
     181function bp_friend_reject_request_link() {
     182    echo bp_get_friend_reject_request_link();
     183}
     184    function bp_get_friend_reject_request_link() {
     185        global $members_template, $bp;
     186
     187        if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id ) ) {
     188            $friendship_id = friends_get_friendship_id( $members_template->member->id, $bp->loggedin_user->id );
     189            wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp' );
     190        }
     191
     192        return apply_filters( 'bp_get_friend_reject_request_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/requests/reject/' . $friendship_id, 'friends_reject_friendship' ) );
     193    }
     194
    485195?>
  • trunk/bp-groups.php

    r2158 r2168  
    1111require ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-widgets.php' );
    1212require ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-filters.php' );
    13 
    14 /* Include deprecated functions if settings allow */
    15 if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
    16     require ( BP_PLUGIN_DIR . '/bp-groups/deprecated/bp-groups-deprecated.php' );
    1713
    1814function groups_install() {
     
    143139
    144140    $bp->groups->group_creation_steps = apply_filters( 'groups_create_group_steps', array(
    145         'group-details' => array( 'name' => __( 'Group Details', 'buddypress' ), 'position' => 0 ),
    146         'group-settings' => array( 'name' => __( 'Group Settings', 'buddypress' ), 'position' => 10 ),
    147         'group-avatar' => array( 'name' => __( 'Group Avatar', 'buddypress' ), 'position' => 20 ),
    148         'group-invites' => array( 'name' => __( 'Group Invites', 'buddypress' ), 'position' => 30 )
     141        'group-details' => array( 'name' => __( 'Details', 'buddypress' ), 'position' => 0 ),
     142        'group-settings' => array( 'name' => __( 'Settings', 'buddypress' ), 'position' => 10 ),
     143        'group-avatar' => array( 'name' => __( 'Avatar', 'buddypress' ), 'position' => 20 ),
     144        'group-invites' => array( 'name' => __( 'Invites', 'buddypress' ), 'position' => 30 )
    149145    ) );
    150146
     
    214210
    215211    /* Add 'Groups' to the main navigation */
    216     bp_core_new_nav_item( array( 'name' => __('Groups', 'buddypress'), 'slug' => $bp->groups->slug, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $bp->groups->id ) );
     212    bp_core_new_nav_item( array( 'name' => sprintf( __( 'Groups (%d)', 'buddypress' ), groups_total_groups_for_user() ), 'slug' => $bp->groups->slug, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $bp->groups->id ) );
    217213
    218214    $groups_link = $bp->loggedin_user->domain . $bp->groups->slug . '/';
     
    220216    /* Add the subnav items to the groups nav item */
    221217    bp_core_new_subnav_item( array( 'name' => __( 'My Groups', 'buddypress' ), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_my_groups', 'position' => 10, 'item_css_id' => 'groups-my-groups' ) );
    222     bp_core_new_subnav_item( array( 'name' => __( 'Create a Group', 'buddypress' ), 'slug' => 'create', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_create_group', 'position' => 20, 'user_has_access' => bp_is_home() ) );
    223218    bp_core_new_subnav_item( array( 'name' => __( 'Invites', 'buddypress' ), 'slug' => 'invites', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_invites', 'position' => 30, 'user_has_access' => bp_is_home() ) );
    224219
     
    290285                    bp_core_new_subnav_item( array( 'name' => __( 'Send Invites', 'buddypress' ), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'group-invite', 'position' => 70, 'user_has_access' => $bp->groups->current_group->user_has_access ) );
    291286
    292                 bp_core_new_subnav_item( array( 'name' => __( 'Leave Group', 'buddypress' ), 'slug' => 'leave-group', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_leave', 'item_css_id' => 'group-leave', 'position' => 110, 'user_has_access' => $bp->groups->current_group->user_has_access ) );
     287                //bp_core_new_subnav_item( array( 'name' => __( 'Leave Group', 'buddypress' ), 'slug' => 'leave-group', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_leave', 'item_css_id' => 'group-leave', 'position' => 110, 'user_has_access' => $bp->groups->current_group->user_has_access ) );
    293288            }
    294289        }
     
    307302
    308303        do_action( 'groups_directory_groups_setup' );
    309         bp_core_load_template( apply_filters( 'groups_template_directory_groups', 'directories/groups/index' ) );
     304        bp_core_load_template( apply_filters( 'groups_template_directory_groups', 'groups/index' ) );
    310305    }
    311306}
     
    352347    do_action( 'groups_screen_my_groups' );
    353348
    354     bp_core_load_template( apply_filters( 'groups_template_my_groups', 'groups/index' ) );
     349    bp_core_load_template( apply_filters( 'groups_template_my_groups', 'members/single/groups' ) );
    355350}
    356351
     
    402397    do_action( 'groups_screen_group_invites', $group_id );
    403398
    404     if ( '' != locate_template( array( 'groups/invites.php' ), false ) )
    405         bp_core_load_template( apply_filters( 'groups_template_group_invites', 'groups/invites' ) );
    406     else
    407         bp_core_load_template( apply_filters( 'groups_template_group_invites', 'groups/list-invites' ) );
    408 }
    409 
    410 function groups_screen_create_group() {
    411     global $bp;
    412 
    413     /* If no current step is set, reset everything so we can start a fresh group creation */
    414     if ( !$bp->groups->current_create_step = $bp->action_variables[1] ) {
    415 
    416         unset( $bp->groups->current_create_step );
    417         unset( $bp->groups->completed_create_steps );
    418 
    419         setcookie( 'bp_new_group_id', false, time() - 1000, COOKIEPATH );
    420         setcookie( 'bp_completed_create_steps', false, time() - 1000, COOKIEPATH );
    421 
    422         $reset_steps = true;
    423         bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . array_shift( array_keys( $bp->groups->group_creation_steps )  ) );
    424     }
    425 
    426     /* If this is a creation step that is not recognized, just redirect them back to the first screen */
    427     if ( $bp->action_variables[1] && !$bp->groups->group_creation_steps[$bp->action_variables[1]] ) {
    428         bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
    429         bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create' );
    430     }
    431 
    432     /* Fetch the currently completed steps variable */
    433     if ( isset( $_COOKIE['bp_completed_create_steps'] ) && !$reset_steps )
    434         $bp->groups->completed_create_steps = unserialize( stripslashes( $_COOKIE['bp_completed_create_steps'] ) );
    435 
    436     /* Set the ID of the new group, if it has already been created in a previous step */
    437     if ( isset( $_COOKIE['bp_new_group_id'] ) ) {
    438         $bp->groups->new_group_id = $_COOKIE['bp_new_group_id'];
    439         $bp->groups->current_group = new BP_Groups_Group( $bp->groups->new_group_id, false, false );
    440     }
    441 
    442     /* If the save, upload or skip button is hit, lets calculate what we need to save */
    443     if ( isset( $_POST['save'] ) ) {
    444 
    445         /* Check the nonce */
    446         check_admin_referer( 'groups_create_save_' . $bp->groups->current_create_step );
    447 
    448         if ( 'group-details' == $bp->groups->current_create_step ) {
    449             if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) ) {
    450                 bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' );
    451                 bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step );
    452             }
    453 
    454             if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'news' => $_POST['group-news'], 'slug' => groups_check_slug( sanitize_title($_POST['group-name']) ), 'date_created' => time() ) ) ) {
    455                 bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
    456                 bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step );
    457             }
    458 
    459             groups_update_groupmeta( $bp->groups->new_group_id, 'total_member_count', 1 );
    460             groups_update_groupmeta( $bp->groups->new_group_id, 'last_activity', time() );
    461             groups_update_groupmeta( $bp->groups->new_group_id, 'theme', 'buddypress' );
    462             groups_update_groupmeta( $bp->groups->new_group_id, 'stylesheet', 'buddypress' );
    463         }
    464 
    465         if ( 'group-settings' == $bp->groups->current_create_step ) {
    466             $group_status = 'public';
    467             $group_enable_wire = 1;
    468             $group_enable_forum = 1;
    469 
    470             if ( !isset($_POST['group-show-wire']) )
    471                 $group_enable_wire = 0;
    472 
    473             if ( !isset($_POST['group-show-forum']) ) {
    474                 $group_enable_forum = 0;
    475             } else {
    476                 /* Create the forum if enable_forum = 1 */
    477                 if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) {
    478                     groups_new_group_forum();
    479                 }
    480             }
    481 
    482             if ( 'private' == $_POST['group-status'] )
    483                 $group_status = 'private';
    484             else if ( 'hidden' == $_POST['group-status'] )
    485                 $group_status = 'hidden';
    486 
    487             if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_wire' => $group_enable_wire, 'enable_forum' => $group_enable_forum ) ) ) {
    488                 bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
    489                 bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step );
    490             }
    491         }
    492 
    493         if ( 'group-invites' == $bp->groups->current_create_step ) {
    494             groups_send_invites( $bp->groups->new_group_id, $bp->loggedin_user->id );
    495         }
    496 
    497         do_action( 'groups_create_group_step_save_' . $bp->groups->current_create_step );
    498         do_action( 'groups_create_group_step_complete' ); // Mostly for clearing cache on a generic action name
    499 
    500         /**
    501          * Once we have successfully saved the details for this step of the creation process
    502          * we need to add the current step to the array of completed steps, then update the cookies
    503          * holding the information
    504          */
    505         if ( !in_array( $bp->groups->current_create_step, (array)$bp->groups->completed_create_steps ) )
    506             $bp->groups->completed_create_steps[] = $bp->groups->current_create_step;
    507 
    508         /* Reset cookie info */
    509         setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH );
    510         setcookie( 'bp_completed_create_steps', serialize( $bp->groups->completed_create_steps ), time()+60*60*24, COOKIEPATH );
    511 
    512         /* If we have completed all steps and hit done on the final step we can redirect to the completed group */
    513         if ( count( $bp->groups->completed_create_steps ) == count( $bp->groups->group_creation_steps ) && $bp->groups->current_create_step == array_pop( array_keys( $bp->groups->group_creation_steps ) ) ) {
    514             unset( $bp->groups->current_create_step );
    515             unset( $bp->groups->completed_create_steps );
    516 
    517             /* Once we compelete all steps, record the group creation in the activity stream. */
    518             groups_record_activity( array(
    519                 'content' => apply_filters( 'groups_activity_created_group', sprintf( __( '%s created the group %s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' ) ),
    520                 'primary_link' => apply_filters( 'groups_activity_created_group_primary_link', bp_get_group_permalink( $bp->groups->current_group ) ),
    521                 'component_action' => 'created_group',
    522                 'item_id' => $bp->groups->new_group_id
    523             ) );
    524 
    525             do_action( 'groups_group_create_complete', $bp->groups->new_group_id );
    526 
    527             bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
    528         } else {
    529             /**
    530              * Since we don't know what the next step is going to be (any plugin can insert steps)
    531              * we need to loop the step array and fetch the next step that way.
    532              */
    533             foreach ( $bp->groups->group_creation_steps as $key => $value ) {
    534                 if ( $key == $bp->groups->current_create_step ) {
    535                     $next = 1;
    536                     continue;
    537                 }
    538 
    539                 if ( $next ) {
    540                     $next_step = $key;
    541                     break;
    542                 }
    543             }
    544 
    545             bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . $next_step );
    546         }
    547     }
    548 
    549     /* Group avatar is handled separately */
    550     if ( 'group-avatar' == $bp->groups->current_create_step && isset( $_POST['upload'] ) ) {
    551         if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) {
    552             /* Normally we would check a nonce here, but the group save nonce is used instead */
    553 
    554             /* Pass the file to the avatar upload handler */
    555             if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) {
    556                 $bp->avatar_admin->step = 'crop-image';
    557 
    558                 /* Make sure we include the jQuery jCrop file for image cropping */
    559                 add_action( 'wp', 'bp_core_add_jquery_cropper' );
    560             }
    561         }
    562 
    563         /* If the image cropping is done, crop the image and save a full/thumb version */
    564         if ( isset( $_POST['avatar-crop-submit'] ) && isset( $_POST['upload'] ) ) {
    565             /* Normally we would check a nonce here, but the group save nonce is used instead */
    566 
    567             if ( !bp_core_avatar_handle_crop( array( 'object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
    568                 bp_core_add_message( __( 'There was an error saving the group avatar, please try uploading again.', 'buddypress' ), 'error' );
    569             else
    570                 bp_core_add_message( __( 'The group avatar was uploaded successfully!', 'buddypress' ) );
    571         }
    572     }
    573 
    574     bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) );
     399    bp_core_load_template( apply_filters( 'groups_template_group_invites', 'members/single/groups' ) );
    575400}
    576401
     
    589414        do_action( 'groups_screen_group_home' );
    590415
    591         if ( '' != locate_template( array( 'groups/single/home.php' ), false ) )
    592             bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    593         else
    594             bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/group-home' ) );
     416        bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    595417    }
    596418}
     
    727549                }
    728550
    729                 bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/forum/edit' ) );
     551                bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) );
    730552            }
    731553
     
    773595                }
    774596
    775                 bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/forum/edit' ) );
     597                bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) );
    776598            }
    777599
    778600            /* Standard topic display */
    779601            else {
    780                 if ( '' != locate_template( array( 'groups/single/forum/topic.php' ), false ) )
    781                     bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/single/forum/topic' ) );
    782                 else
    783                     bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/forum/topic' ) );
     602                bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/single/home' ) );
    784603            }
    785604
     
    805624            do_action( 'groups_screen_group_forum', $topic_id, $forum_id );
    806625
    807             if ( '' != locate_template( array( 'groups/single/forum/index.php' ), false ) )
    808                 bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/single/forum/index' ) );
    809             else
    810                 bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/forum/index' ) );
     626            bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/single/home' ) );
    811627        }
    812628    }
     
    852668
    853669        } else if ( ( !$wire_action || 'latest' == $bp->action_variables[1] ) ) {
    854             if ( '' != locate_template( array( 'groups/single/wire.php' ), false ) )
    855                 bp_core_load_template( apply_filters( 'groups_template_group_wire', 'groups/single/wire' ) );
    856             else
    857                 bp_core_load_template( apply_filters( 'groups_template_group_wire', 'groups/wire' ) );
     670            bp_core_load_template( apply_filters( 'groups_template_group_wire', 'groups/single/wire' ) );
    858671        } else {
    859             if ( '' != locate_template( array( 'groups/single/home.php' ), false ) )
    860                 bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    861             else
    862                 bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/group-home' ) );
     672            bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    863673        }
    864674    }
     
    870680    if ( $bp->is_single_item ) {
    871681        do_action( 'groups_screen_group_members', $bp->groups->current_group->id );
    872 
    873         if ( '' != locate_template( array( 'groups/single/members.php' ), false ) )
    874             bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/single/members' ) );
    875         else
    876             bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/list-members' ) );
     682        bp_core_load_template( apply_filters( 'groups_screen_group_members', 'groups/single/home' ) );
    877683    }
    878684}
     
    897703        } else {
    898704            // Show send invite page
    899             if ( '' != locate_template( array( 'groups/single/send-invite.php' ), false ) )
    900                 bp_core_load_template( apply_filters( 'groups_template_group_invite', 'groups/single/send-invite' ) );
    901             else
    902                 bp_core_load_template( apply_filters( 'groups_template_group_invite', 'groups/send-invite' ) );
     705            bp_core_load_template( apply_filters( 'groups_template_group_invite', 'groups/single/home' ) );
    903706        }
    904707    }
     
    936739
    937740            // Show leave group page
    938             if ( '' != locate_template( array( 'groups/single/leave-confirm.php' ), false ) )
    939                 bp_core_load_template( apply_filters( 'groups_template_group_leave', 'groups/single/leave-confirm' ) );
    940             else
    941                 bp_core_load_template( apply_filters( 'groups_template_group_leave', 'groups/leave-group-confirm' ) );
     741            bp_core_load_template( apply_filters( 'groups_template_group_leave', 'groups/single/home' ) );
    942742        }
    943743    }
     
    967767        do_action( 'groups_screen_group_request_membership', $bp->groups->current_group->id );
    968768
    969         if ( '' != locate_template( array( 'groups/single/request-membership.php' ), false ) )
    970             bp_core_load_template( apply_filters( 'groups_template_group_request_membership', 'groups/single/request-membership' ) );
    971         else
    972             bp_core_load_template( apply_filters( 'groups_template_group_request_membership', 'groups/request-membership' ) );
     769        bp_core_load_template( apply_filters( 'groups_template_group_request_membership', 'groups/single/home' ) );
    973770    }
    974771}
     
    980777        return false;
    981778
    982     if ( '' != locate_template( array( 'groups/single/home.php' ), false ) )
    983         bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    984     else
    985         bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/group-home' ) );
     779    bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    986780}
    987781add_action( 'wp', 'groups_screen_group_activity_permalink', 3 );
     
    1025819            do_action( 'groups_screen_group_admin_edit_details', $bp->groups->current_group->id );
    1026820
    1027             if ( '' != locate_template( array( 'groups/single/admin.php' ), false ) )
    1028                 bp_core_load_template( apply_filters( 'groups_template_group_admin', 'groups/single/admin' ) );
    1029             else
    1030                 bp_core_load_template( apply_filters( 'groups_template_group_admin', 'groups/admin/edit-details' ) );
     821            bp_core_load_template( apply_filters( 'groups_template_group_admin', 'groups/single/home' ) );
    1031822        }
    1032823    }
     
    1069860        do_action( 'groups_screen_group_admin_settings', $bp->groups->current_group->id );
    1070861
    1071         if ( '' != locate_template( array( 'groups/single/admin.php' ), false ) )
    1072             bp_core_load_template( apply_filters( 'groups_template_group_admin_settings', 'groups/single/admin' ) );
    1073         else
    1074             bp_core_load_template( apply_filters( 'groups_template_group_admin_settings', 'groups/admin/group-settings' ) );
     862        bp_core_load_template( apply_filters( 'groups_template_group_admin_settings', 'groups/single/home' ) );
    1075863    }
    1076864}
     
    1130918        do_action( 'groups_screen_group_admin_avatar', $bp->groups->current_group->id );
    1131919
    1132         if ( '' != locate_template( array( 'groups/single/admin.php' ), false ) )
    1133             bp_core_load_template( apply_filters( 'groups_template_group_admin_avatar', 'groups/single/admin' ) );
    1134         else
    1135             bp_core_load_template( apply_filters( 'groups_template_group_admin_avatar', 'groups/admin/group-avatar' ) );
     920        bp_core_load_template( apply_filters( 'groups_template_group_admin_avatar', 'groups/single/home' ) );
    1136921    }
    1137922}
     
    12371022        do_action( 'groups_screen_group_admin_manage_members', $bp->groups->current_group->id );
    12381023
    1239         if ( '' != locate_template( array( 'groups/single/admin.php' ), false ) )
    1240             bp_core_load_template( apply_filters( 'groups_template_group_admin_manage_members', 'groups/single/admin' ) );
    1241         else
    1242             bp_core_load_template( apply_filters( 'groups_template_group_admin_manage_members', 'groups/admin/manage-members' ) );
     1024        bp_core_load_template( apply_filters( 'groups_template_group_admin_manage_members', 'groups/single/home' ) );
    12431025    }
    12441026}
     
    12941076        do_action( 'groups_screen_group_admin_requests', $bp->groups->current_group->id );
    12951077
    1296         if ( '' != locate_template( array( 'groups/single/admin.php' ), false ) )
    1297             bp_core_load_template( apply_filters( 'groups_template_group_admin_requests', 'groups/single/admin' ) );
    1298         else
    1299             bp_core_load_template( apply_filters( 'groups_template_group_admin_requests', 'groups/admin/membership-requests' ) );
     1078        bp_core_load_template( apply_filters( 'groups_template_group_admin_requests', 'groups/single/home' ) );
    13001079    }
    13011080}
     
    13311110        do_action( 'groups_screen_group_admin_delete_group', $bp->groups->current_group->id );
    13321111
    1333         if ( '' != locate_template( array( 'groups/single/admin.php' ), false ) )
    1334             bp_core_load_template( apply_filters( 'groups_template_group_admin_delete_group', 'groups/single/admin' ) );
    1335         else
    1336             bp_core_load_template( apply_filters( 'groups_template_group_admin_delete_group', 'groups/admin/delete-group' ) );
     1112        bp_core_load_template( apply_filters( 'groups_template_group_admin_delete_group', 'groups/single/home' ) );
    13371113    }
    13381114}
     
    13961172 */
    13971173
     1174function groups_action_create_group() {
     1175    global $bp;
     1176
     1177    /* If we're not at domain.org/groups/create/ then return false */
     1178    if ( $bp->current_component != $bp->groups->slug || 'create' != $bp->current_action )
     1179        return false;
     1180
     1181    if ( !is_user_logged_in() )
     1182        return false;
     1183
     1184    /* Make sure creation steps are in the right order */
     1185    groups_action_sort_creation_steps();
     1186
     1187    /* If no current step is set, reset everything so we can start a fresh group creation */
     1188    if ( !$bp->groups->current_create_step = $bp->action_variables[1] ) {
     1189
     1190        unset( $bp->groups->current_create_step );
     1191        unset( $bp->groups->completed_create_steps );
     1192
     1193        setcookie( 'bp_new_group_id', false, time() - 1000, COOKIEPATH );
     1194        setcookie( 'bp_completed_create_steps', false, time() - 1000, COOKIEPATH );
     1195
     1196        $reset_steps = true;
     1197        bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . array_shift( array_keys( $bp->groups->group_creation_steps ) ) . '/' );
     1198    }
     1199
     1200    /* If this is a creation step that is not recognized, just redirect them back to the first screen */
     1201    if ( $bp->action_variables[1] && !$bp->groups->group_creation_steps[$bp->action_variables[1]] ) {
     1202        bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
     1203        bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/' );
     1204    }
     1205
     1206    /* Fetch the currently completed steps variable */
     1207    if ( isset( $_COOKIE['bp_completed_create_steps'] ) && !$reset_steps )
     1208        $bp->groups->completed_create_steps = unserialize( stripslashes( $_COOKIE['bp_completed_create_steps'] ) );
     1209
     1210    /* Set the ID of the new group, if it has already been created in a previous step */
     1211    if ( isset( $_COOKIE['bp_new_group_id'] ) ) {
     1212        $bp->groups->new_group_id = $_COOKIE['bp_new_group_id'];
     1213        $bp->groups->current_group = new BP_Groups_Group( $bp->groups->new_group_id, false, false );
     1214    }
     1215
     1216    /* If the save, upload or skip button is hit, lets calculate what we need to save */
     1217    if ( isset( $_POST['save'] ) ) {
     1218
     1219        /* Check the nonce */
     1220        check_admin_referer( 'groups_create_save_' . $bp->groups->current_create_step );
     1221
     1222        if ( 'group-details' == $bp->groups->current_create_step ) {
     1223            if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) ) {
     1224                bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' );
     1225                bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
     1226            }
     1227
     1228            if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'news' => $_POST['group-news'], 'slug' => groups_check_slug( sanitize_title($_POST['group-name']) ), 'date_created' => time() ) ) ) {
     1229                bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
     1230                bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
     1231            }
     1232
     1233            groups_update_groupmeta( $bp->groups->new_group_id, 'total_member_count', 1 );
     1234            groups_update_groupmeta( $bp->groups->new_group_id, 'last_activity', time() );
     1235        }
     1236
     1237        if ( 'group-settings' == $bp->groups->current_create_step ) {
     1238            $group_status = 'public';
     1239            $group_enable_wire = 1;
     1240            $group_enable_forum = 1;
     1241
     1242            if ( !isset($_POST['group-show-wire']) )
     1243                $group_enable_wire = 0;
     1244
     1245            if ( !isset($_POST['group-show-forum']) ) {
     1246                $group_enable_forum = 0;
     1247            } else {
     1248                /* Create the forum if enable_forum = 1 */
     1249                if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) {
     1250                    groups_new_group_forum();
     1251                }
     1252            }
     1253
     1254            if ( 'private' == $_POST['group-status'] )
     1255                $group_status = 'private';
     1256            else if ( 'hidden' == $_POST['group-status'] )
     1257                $group_status = 'hidden';
     1258
     1259            if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_wire' => $group_enable_wire, 'enable_forum' => $group_enable_forum ) ) ) {
     1260                bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
     1261                bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
     1262            }
     1263        }
     1264
     1265        if ( 'group-invites' == $bp->groups->current_create_step ) {
     1266            groups_send_invites( $bp->groups->new_group_id, $bp->loggedin_user->id );
     1267        }
     1268
     1269        do_action( 'groups_create_group_step_save_' . $bp->groups->current_create_step );
     1270        do_action( 'groups_create_group_step_complete' ); // Mostly for clearing cache on a generic action name
     1271
     1272        /**
     1273         * Once we have successfully saved the details for this step of the creation process
     1274         * we need to add the current step to the array of completed steps, then update the cookies
     1275         * holding the information
     1276         */
     1277        if ( !in_array( $bp->groups->current_create_step, (array)$bp->groups->completed_create_steps ) )
     1278            $bp->groups->completed_create_steps[] = $bp->groups->current_create_step;
     1279
     1280        /* Reset cookie info */
     1281        setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH );
     1282        setcookie( 'bp_completed_create_steps', serialize( $bp->groups->completed_create_steps ), time()+60*60*24, COOKIEPATH );
     1283
     1284        /* If we have completed all steps and hit done on the final step we can redirect to the completed group */
     1285        if ( count( $bp->groups->completed_create_steps ) == count( $bp->groups->group_creation_steps ) && $bp->groups->current_create_step == array_pop( array_keys( $bp->groups->group_creation_steps ) ) ) {
     1286            unset( $bp->groups->current_create_step );
     1287            unset( $bp->groups->completed_create_steps );
     1288
     1289            /* Once we compelete all steps, record the group creation in the activity stream. */
     1290            groups_record_activity( array(
     1291                'content' => apply_filters( 'groups_activity_created_group', sprintf( __( '%s created the group %s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' ) ),
     1292                'primary_link' => apply_filters( 'groups_activity_created_group_primary_link', bp_get_group_permalink( $bp->groups->current_group ) ),
     1293                'component_action' => 'created_group',
     1294                'item_id' => $bp->groups->new_group_id
     1295            ) );
     1296
     1297            do_action( 'groups_group_create_complete', $bp->groups->new_group_id );
     1298
     1299            bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
     1300        } else {
     1301            /**
     1302             * Since we don't know what the next step is going to be (any plugin can insert steps)
     1303             * we need to loop the step array and fetch the next step that way.
     1304             */
     1305            foreach ( $bp->groups->group_creation_steps as $key => $value ) {
     1306                if ( $key == $bp->groups->current_create_step ) {
     1307                    $next = 1;
     1308                    continue;
     1309                }
     1310
     1311                if ( $next ) {
     1312                    $next_step = $key;
     1313                    break;
     1314                }
     1315            }
     1316
     1317            bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $next_step . '/' );
     1318        }
     1319    }
     1320
     1321    /* Group avatar is handled separately */
     1322    if ( 'group-avatar' == $bp->groups->current_create_step && isset( $_POST['upload'] ) ) {
     1323        if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) {
     1324            /* Normally we would check a nonce here, but the group save nonce is used instead */
     1325
     1326            /* Pass the file to the avatar upload handler */
     1327            if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) {
     1328                $bp->avatar_admin->step = 'crop-image';
     1329
     1330                /* Make sure we include the jQuery jCrop file for image cropping */
     1331                add_action( 'wp', 'bp_core_add_jquery_cropper' );
     1332            }
     1333        }
     1334
     1335        /* If the image cropping is done, crop the image and save a full/thumb version */
     1336        if ( isset( $_POST['avatar-crop-submit'] ) && isset( $_POST['upload'] ) ) {
     1337            /* Normally we would check a nonce here, but the group save nonce is used instead */
     1338
     1339            if ( !bp_core_avatar_handle_crop( array( 'object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
     1340                bp_core_add_message( __( 'There was an error saving the group avatar, please try uploading again.', 'buddypress' ), 'error' );
     1341            else
     1342                bp_core_add_message( __( 'The group avatar was uploaded successfully!', 'buddypress' ) );
     1343        }
     1344    }
     1345
     1346    bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) );
     1347}
     1348add_action( 'wp', 'groups_action_create_group', 3 );
     1349
    13981350function groups_action_join_group() {
    13991351    global $bp;
     
    14121364    }
    14131365
    1414     if ( '' != locate_template( array( 'groups/single/admin.php' ), false ) )
    1415         bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    1416     else
    1417         bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/group-home' ) );
     1366    bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    14181367}
    14191368add_action( 'wp', 'groups_action_join_group', 3 );
     
    14381387        $bp->groups->group_creation_steps[$step['slug']] = array( 'name' => $step['name'], 'position' => $position );
    14391388}
    1440 add_action( 'wp', 'groups_action_sort_creation_steps', 3 );
    1441 
    1442 function groups_aciton_redirect_to_random_group() {
     1389
     1390function groups_action_redirect_to_random_group() {
    14431391    global $bp, $wpdb;
    14441392
     
    14491397    }
    14501398}
    1451 add_action( 'wp', 'groups_aciton_redirect_to_random_group', 6 );
     1399add_action( 'wp', 'groups_action_redirect_to_random_group', 6 );
    14521400
    14531401
     
    19131861}
    19141862
    1915 function groups_get_newest( $limit = null, $page = 1 ) {
    1916     return BP_Groups_Group::get_newest( $limit, $page );
    1917 }
    1918 
    1919 function groups_get_active( $limit = null, $page = 1 ) {
    1920     return BP_Groups_Group::get_active( $limit, $page );
    1921 }
    1922 
    1923 function groups_get_popular( $limit = null, $page = 1 ) {
    1924     return BP_Groups_Group::get_popular( $limit, $page );
    1925 }
    1926 
    1927 function groups_get_random_groups( $limit = null, $page = 1 ) {
    1928     return BP_Groups_Group::get_random( $limit, $page );
    1929 }
    1930 
    1931 function groups_get_alphabetically( $limit = null, $page = 1 ) {
    1932     return BP_Groups_Group::get_alphabetically( $limit, $page );
    1933 }
    1934 
    1935 function groups_get_by_most_forum_topics( $limit = null, $page = 1 ) {
    1936     return BP_Groups_Group::get_by_most_forum_topics( $limit, $page );
    1937 }
    1938 
    1939 function groups_get_by_most_forum_posts( $limit = null, $page = 1 ) {
    1940     return BP_Groups_Group::get_by_most_forum_posts( $limit, $page );
    1941 }
    1942 
    1943 /* TODO: These user group functions could be merged with the above with an optional user ID param */
     1863/***
     1864 * All of the following get_() functions will return groups for the site globally.
     1865 * If you pass a $user_id then the groups will be restricted to only those that the
     1866 * user has joined.
     1867 */
     1868function groups_get_newest( $limit = null, $page = 1, $user_id = false, $search_terms = false ) {
     1869    return BP_Groups_Group::get_newest( $limit, $page, $user_id, $search_terms );
     1870}
     1871
     1872function groups_get_active( $limit = null, $page = 1, $user_id = false, $search_terms = false ) {
     1873    return BP_Groups_Group::get_active( $limit, $page, $user_id, $search_terms );
     1874}
     1875
     1876function groups_get_popular( $limit = null, $page = 1, $user_id = false, $search_terms = false ) {
     1877    return BP_Groups_Group::get_popular( $limit, $page, $user_id, $search_terms );
     1878}
     1879
     1880function groups_get_random_groups( $limit = null, $page = 1, $user_id = false, $search_terms = false ) {
     1881    return BP_Groups_Group::get_random( $limit, $page, $user_id, $search_terms );
     1882}
     1883
     1884function groups_get_alphabetically( $limit = null, $page = 1, $user_id = false, $search_terms = false ) {
     1885    return BP_Groups_Group::get_alphabetically( $limit, $page, $user_id, $search_terms );
     1886}
     1887
     1888function groups_get_by_most_forum_topics( $limit = null, $page = 1, $user_id = false, $search_terms = false ) {
     1889    return BP_Groups_Group::get_by_most_forum_topics( $limit, $page, $user_id, $search_terms );
     1890}
     1891
     1892function groups_get_by_most_forum_posts( $limit = null, $page = 1, $user_id = false, $search_terms = false ) {
     1893    return BP_Groups_Group::get_by_most_forum_posts( $limit, $page, $user_id, $search_terms );
     1894}
     1895
     1896function groups_get_total_group_count() {
     1897    return BP_Groups_Group::get_total_group_count();
     1898}
    19441899
    19451900function groups_get_user_groups( $user_id = false, $pag_num = false, $pag_page = false ) {
     
    19611916}
    19621917
    1963 function groups_get_most_popular_for_user( $user_id = false, $pag_num = false, $pag_page = false, $filter = false ) {
     1918function groups_get_user_is_admin_of( $user_id = false, $pag_num = false, $pag_page = false, $filter = false ) {
    19641919    global $bp;
    19651920
     
    19671922        $user_id = $bp->displayed_user->id;
    19681923
    1969     return BP_Groups_Member::get_most_popular( $user_id, $pag_num, $pag_page, $filter );
    1970 }
    1971 
    1972 function groups_get_recently_active_for_user( $user_id = false, $pag_num = false, $pag_page = false, $filter = false ) {
     1924    return BP_Groups_Member::get_is_admin_of( $user_id, $pag_num, $pag_page, $filter );
     1925}
     1926
     1927function groups_get_user_is_mod_of( $user_id = false, $pag_num = false, $pag_page = false, $filter = false ) {
    19731928    global $bp;
    19741929
     
    19761931        $user_id = $bp->displayed_user->id;
    19771932
    1978     return BP_Groups_Member::get_recently_active( $user_id, $pag_num, $pag_page, $filter );
    1979 }
    1980 
    1981 function groups_get_alphabetically_for_user( $user_id = false, $pag_num = false, $pag_page = false, $filter = false ) {
     1933    return BP_Groups_Member::get_is_mod_of( $user_id, $pag_num, $pag_page, $filter );
     1934}
     1935
     1936function groups_total_groups_for_user( $user_id = false ) {
    19821937    global $bp;
    19831938
    19841939    if ( !$user_id )
    1985         $user_id = $bp->displayed_user->id;
    1986 
    1987     return BP_Groups_Member::get_alphabetically( $user_id, $pag_num, $pag_page, $filter );
    1988 }
    1989 
    1990 function groups_get_user_is_admin_of( $user_id = false, $pag_num = false, $pag_page = false, $filter = false ) {
    1991     global $bp;
    1992 
    1993     if ( !$user_id )
    1994         $user_id = $bp->displayed_user->id;
    1995 
    1996     return BP_Groups_Member::get_is_admin_of( $user_id, $pag_num, $pag_page, $filter );
    1997 }
    1998 
    1999 function groups_get_user_is_mod_of( $user_id = false, $pag_num = false, $pag_page = false, $filter = false ) {
    2000     global $bp;
    2001 
    2002     if ( !$user_id )
    2003         $user_id = $bp->displayed_user->id;
    2004 
    2005     return BP_Groups_Member::get_is_mod_of( $user_id, $pag_num, $pag_page, $filter );
    2006 }
    2007 
    2008 function groups_total_groups_for_user( $user_id = false ) {
    2009     global $bp;
    2010 
    2011     if ( !$user_id )
    2012         $user_id = $bp->displayed_user->id;
     1940        $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
    20131941
    20141942    return BP_Groups_Member::total_group_count( $user_id );
    2015 }
    2016 
    2017 function groups_get_random_groups_for_user( $user_id = false, $total_groups = 5 ) {
    2018     global $bp;
    2019 
    2020     if ( !$user_id )
    2021         $user_id = $bp->displayed_user->id;
    2022 
    2023     return BP_Groups_Member::get_random_groups( $user_id, $total_groups );
    20241943}
    20251944
     
    26912610
    26922611/*** Group Cleanup Functions ****************************************************/
     2612
     2613/**
     2614 * groups_filter_template_paths()
     2615 *
     2616 * Add fallback for the bp-sn-parent theme template locations used in BuddyPress versions
     2617 * older than 1.2.
     2618 *
     2619 * @package BuddyPress Core
     2620 */
     2621function groups_filter_template_paths() {
     2622    if ( 'bp-sn-parent' != basename( TEMPLATEPATH ) && !defined( 'BP_CLASSIC_TEMPLATE_STRUCTURE' ) )
     2623        return false;
     2624
     2625    add_filter( 'groups_template_directory_groups', create_function( '', 'return "directories/groups/index";' ) );
     2626    add_filter( 'groups_template_my_groups', create_function( '', 'return "groups/index";' ) );
     2627    add_filter( 'groups_template_group_invites', create_function( '', 'return "groups/invites";' ) );
     2628    add_filter( 'groups_template_group_admin', create_function( '', 'return "groups/single/admin";' ) );
     2629    add_filter( 'groups_template_group_forum_topic_edit', create_function( '', 'return "groups/single/forum/edit";' ) );
     2630    add_filter( 'groups_template_group_forum_topic', create_function( '', 'return "groups/single/forum/topic";' ) );
     2631    add_filter( 'groups_template_group_forum', create_function( '', 'return "groups/single/forum/index";' ) );
     2632    add_filter( 'groups_template_group_leave', create_function( '', 'return "groups/single/leave-confirm";' ) );
     2633    add_filter( 'groups_template_group_request_membership', create_function( '', 'return "groups/single/request-membership";' ) );
     2634    add_filter( 'groups_template_group_invite', create_function( '', 'return "groups/single/send-invite";' ) );
     2635    add_filter( 'groups_screen_group_members', create_function( '', 'return "groups/single/members";' ) );
     2636    add_filter( 'groups_template_group_admin_settings', create_function( '', 'return "groups/single/admin";' ) );
     2637    add_filter( 'groups_template_group_admin_avatar', create_function( '', 'return "groups/single/admin";' ) );
     2638    add_filter( 'groups_template_group_admin_manage_members', create_function( '', 'return "groups/single/admin";' ) );
     2639    add_filter( 'groups_template_group_admin_requests', create_function( '', 'return "groups/single/admin";' ) );
     2640    add_filter( 'groups_template_group_admin_delete_group', create_function( '', 'return "groups/single/admin";' ) );
     2641}
     2642add_action( 'init', 'groups_filter_template_paths' );
    26932643
    26942644function groups_remove_data_for_user( $user_id ) {
  • trunk/bp-groups/bp-groups-classes.php

    r2120 r2168  
    217217    }
    218218
    219 
    220219    /* Static Functions */
    221220
     
    331330    }
    332331
    333     function get_newest( $limit = null, $page = null ) {
     332    function get_newest( $limit = null, $page = null, $user_id = false, $search_terms = false ) {
    334333        global $wpdb, $bp;
    335334
     
    340339            $hidden_sql = "WHERE status != 'hidden'";
    341340
    342         $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT id as group_id FROM {$bp->groups->table_name} {$hidden_sql} ORDER BY date_created DESC {$pag_sql}" ) );
    343         $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name} {$hidden_sql} ORDER BY date_created DESC", $limit ) );
    344 
    345         return array( 'groups' => $paged_groups, 'total' => $total_groups );
    346     }
    347 
    348     function get_active( $limit = null, $page = null ) {
     341        if ( $search_terms ) {
     342            $search_terms = like_escape( $wpdb->escape( $search_terms ) );
     343            $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
     344        }
     345
     346        if ( $user_id ) {
     347            $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 ORDER BY g.date_created DESC {$pag_sql}", $user_id ) );
     348            $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0", $user_id ) );
     349        } else {
     350            $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} ORDER BY g.date_created DESC {$pag_sql}" ) );
     351            $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm INNER JOIN {$bp->groups->table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}" ) );
     352        }
     353
     354        return array( 'groups' => $paged_groups, 'total' => $total_groups );
     355    }
     356
     357    function get_active( $limit = null, $page = null, $user_id = false, $search_terms = false ) {
    349358        global $wpdb, $bp;
    350359