Skip to:
Content

BuddyPress.org

Changeset 2088


Ignore:
Timestamp:
11/13/2009 01:01:37 AM (17 years ago)
Author:
apeatling
Message:

Initial support for threaded activity stream commenting. Some major performance improvements around fetching profile and group data.

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2077 r2088  
    11<?php
    22
    3 define ( 'BP_ACTIVITY_DB_VERSION', '1800' );
     3define ( 'BP_ACTIVITY_DB_VERSION', '1900' );
    44
    55/* Define the slug for the component */
    … …  
    3333                                date_recorded datetime NOT NULL,
    3434                                hide_sitewide bool DEFAULT 0,
     35                                mptt_left int(11) NOT NULL,
     36                                mptt_right int(11) NOT NULL,
    3537                                KEY date_recorded (date_recorded),
    3638                                KEY user_id (user_id),
    … …  
    224226 */
    225227
     228function bp_activity_get_sitewide( $args = '' ) {
     229        $defaults = array(
     230                'max' => false, // Maximum number of results to return
     231                'page' => 1, // page 1 without a per_page will result in no pagination.
     232                'per_page' => false, // results per page
     233                'sort' => 'DESC', // sort ASC or DESC
     234                'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
     235
     236                'search_terms' => false, // Pass search terms as a string
     237
     238                /**
     239                 * Pass filters as an array:
     240                 * array(
     241                 *      'user_id' => false, // user_id to filter on
     242                 *      'object' => false, // object to filter on e.g. groups, profile, status, friends
     243                 *      'action' => false, // action to filter on e.g. new_wire_post, new_forum_post, profile_updated
     244                 *      'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
     245                 *      'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
     246                 * );
     247                 */
     248                'filter' => array()
     249        );
     250
     251        $r = wp_parse_args( $args, $defaults );
     252        extract( $r, EXTR_SKIP );
     253
     254        return apply_filters( 'bp_activity_get_sitewide', BP_Activity_Activity::get_sitewide_activity( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments ), &$r );
     255}
     256
     257function bp_activity_get_for_user( $args = '' ) {
     258        global $bp;
     259
     260        $defaults = array(
     261                'user_id' => $bp->displayed_user->id,
     262                'max' => false, // Maximum number of results to return
     263                'page' => 1, // page 1 without a per_page will result in no pagination.
     264                'per_page' => false, // results per page
     265                'sort' => 'DESC', // sort ASC or DESC
     266                'display_comments' => 'stream', // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
     267
     268                'search_terms' => false, // Pass search terms as a string
     269                'filter' => array()
     270        );
     271
     272        $r = wp_parse_args( $args, $defaults );
     273        extract( $r, EXTR_SKIP );
     274
     275        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 ), &$r );
     276}
     277
     278function bp_activity_get_friends_activity( $user_id, $max = 30, $max_items_per_friend = false, $pag_num = false, $pag_page = false, $filter = false ) {
     279        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 );
     280}
     281
     282function bp_activity_get_specific( $args = '' ) {
     283        $defaults = array(
     284                'activity_ids' => false, // A single activity_id or array of IDs.
     285                'max' => false, // Maximum number of results to return
     286                'page' => 1, // page 1 without a per_page will result in no pagination.
     287                'per_page' => false, // results per page
     288                'sort' => 'DESC', // sort ASC or DESC
     289                'display_comments' => false // true or false to display threaded comments for these specific activity items
     290        );
     291
     292        $r = wp_parse_args( $args, $defaults );
     293        extract( $r, EXTR_SKIP );
     294
     295        return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get_specific( $activity_ids, $max, $page, $per_page, $sort, $display_comments ) );
     296}
     297
    226298function bp_activity_add( $args = '' ) {
    227299        global $bp, $wpdb;
    … …  
    247319                $content = bp_activity_add_timesince_placeholder( $content );
    248320
    249         $activity = new BP_Activity_Activity;
     321        /* Pass certain values so we can update an activity item if it already exists */
     322        $activity = new BP_Activity_Activity();
     323
    250324        $activity->user_id = $user_id;
    251325        $activity->content = $content;
    … …  
    261335                return false;
    262336
    263         do_action( 'bp_activity_add', $args );
    264 
    265         return true;
     337        /* If this is an activity comment, rebuild the tree */
     338        if ( 'activity_comment' == $activity->component_action )
     339                BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
     340
     341        do_action( 'bp_activity_add', $r );
     342
     343        return $activity->id;
    266344}
    267345
    … …  
    374452}
    375453
    376 function bp_activity_get_sitewide_activity( $max_items = 30, $pag_num = false, $pag_page = false, $filter = false ) {
    377         return apply_filters( 'bp_activity_get_sitewide_activity', BP_Activity_Activity::get_sitewide_activity( $max_items, $pag_num, $pag_page, $filter ), $max_items, $pag_num, $pag_page, $filter );
    378 }
    379 
    380 function bp_activity_get_user_activity( $user_id, $max_items = 30, $pag_num = false, $pag_page = false, $filter = false ) {
    381         return apply_filters( 'bp_activity_get_user_activity', BP_Activity_Activity::get_activity_for_user( $user_id, $max_items, $pag_num, $pag_page, $filter ), $user_id, $max_items, $pag_num, $pag_page, $filter );
    382 }
    383 
    384 function bp_activity_get_friends_activity( $user_id, $max_items = 30, $max_items_per_friend = false, $pag_num = false, $pag_page = false, $filter = false ) {
    385         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 );
    386 }
    387 
    388454function bp_activity_remove_data( $user_id ) {
    389455        // Clear the user's activity from the sitewide stream and clear their activity tables
  • trunk/bp-activity/bp-activity-classes.php

    r2077 r2088  
    2626                $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
    2727
    28                 $this->id = $activity->id;
    29                 $this->item_id = $activity->item_id;
    30                 $this->secondary_item_id = $activity->secondary_item_id;
    31                 $this->user_id = $activity->user_id;
    32                 $this->content = $activity->content;
    33                 $this->primary_link = $activity->primary_link;
    34                 $this->component_name = $activity->component_name;
    35                 $this->component_action = $activity->component_action;
    36                 $this->date_recorded = $activity->date_recorded;
    37                 $this->hide_sitewide = $activity->hide_sitewide;
     28                if ( $activity ) {
     29                        $this->id = $activity->id;
     30                        $this->item_id = $activity->item_id;
     31                        $this->secondary_item_id = $activity->secondary_item_id;
     32                        $this->user_id = $activity->user_id;
     33                        $this->content = $activity->content;
     34                        $this->primary_link = $activity->primary_link;
     35                        $this->component_name = $activity->component_name;
     36                        $this->component_action = $activity->component_action;
     37                        $this->date_recorded = $activity->date_recorded;
     38                        $this->hide_sitewide = $activity->hide_sitewide;
     39                }
    3840        }
    3941
    … …  
    6365                        $this->primary_link = $bp->loggedin_user->domain;
    6466
    65                 if ( $existing_activity_id = $this->exists() )
    66                         BP_Activity_Activity::delete_by_activity_id( $existing_activity_id );
    67 
    6867                /* If we have an existing ID, update the activity item, otherwise insert it. */
    69                 if ( $this->id ) {
    70                         if ( $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component_name = %s, component_action = %s, content = %s, primary_link = %s, date_recorded = FROM_UNIXTIME(%d), item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id ) ) ) {
    71                                 do_action( 'bp_activity_after_save', $this );
    72                                 return true;
    73                         }
    74                 } else {
    75                         if ( $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component_name, component_action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s, %s, %d )", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide ) ) ) {
    76                                 do_action( 'bp_activity_after_save', $this );
    77                                 return true;
    78                         }
    79                 }
    80 
    81                 return false;
    82         }
    83 
    84         function exists() {
    85                 global $wpdb, $bp;
    86 
    87                 /* This doesn't seem to be working correctly at the moment, so it is disabled [TODO] */
    88                 return false;
    89 
    90                 /* If we have an item id, try and match on that, if not do a content match */
    91                 if ( $this->item_id ) {
    92                         if ( $this->secondary_item_id )
    93                                 $secondary_sql = $wpdb->prepare( " AND secondary_item_id = %s", $secondary_item_id );
    94 
    95                         return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) );
    96                 } else {
    97                         return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) );
    98                 }
     68                if ( $this->id )
     69                        $q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component_name = %s, component_action = %s, content = %s, primary_link = %s, date_recorded = FROM_UNIXTIME(%d), item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id );
     70                else
     71                        $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component_name, component_action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s, %s, %d )", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );
     72
     73                if ( !$wpdb->query( $q ) )
     74                        return false;
     75
     76                $this->id = $wpdb->insert_id;
     77
     78                do_action( 'bp_activity_after_save', $this );
     79                return true;
    9980        }
    10081
    … …  
    144125        }
    145126
    146         function get_activity_for_user( $user_id, $max_items, $limit, $page, $filter ) {
    147                 global $wpdb, $bp;
     127        function get_activity_for_user( $user_id, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false ) {
     128                global $wpdb, $bp;
     129
     130                if ( $limit && $page )
     131                        $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     132
     133                if ( $max )
     134                        $max_sql = $wpdb->prepare( "LIMIT %d", $max );
     135
     136                /* Searching */
     137                if ( $search_terms ) {
     138                        $search_terms = $wpdb->escape( $search_terms );
     139                        $search_sql = "AND content LIKE '%%" . like_escape( $search_terms ) . "%%'";
     140                }
     141
     142                /* Filtering */
     143                if ( $filter )
     144                        $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
     145
     146                /* Sorting */
     147                if ( $sort != 'ASC' && $sort != 'DESC' )
     148                        $sort = 'DESC';
     149
     150                /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
     151                if ( !$display_comments || 'threaded' == $display_comments ) {
     152                        if ( $per_page && $page && $max )
     153                                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
     154                        else
     155                                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
     156
     157                        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
     158
     159                        if ( $activities && $display_comments )
     160                                $activities = BP_Activity_Activity::append_comments( &$activities );
     161                } else {
     162                        if ( $per_page && $page && $max )
     163                                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
     164                        else
     165                                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
     166
     167                        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
     168
     169                        if ( $activities )
     170                                $activities = BP_Activity_Activity::append_comments( &$activities );
     171                }
     172
     173                return array( 'activities' => $activities, 'total' => (int)$total_activities );
     174        }
     175
     176        function get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $limit, $page, $filter ) {
     177                global $wpdb, $bp;
     178
     179                // TODO: Max items per friend not yet implemented.
     180
     181                if ( !function_exists('friends_get_friend_user_ids') )
     182                        return false;
    148183
    149184                if ( $limit && $page )
    … …  
    157192                        $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
    158193
    159                 if ( $limit && $page && $max_items )
    160                         $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql", $user_id ) );
    161                 else
    162                         $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql", $user_id ) );
    163 
    164                 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $max_sql", $user_id ) );
    165 
    166                 return array( 'activities' => $activities, 'total' => (int)$total_activities );
    167         }
    168 
    169         function get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $limit, $page, $filter ) {
    170                 global $wpdb, $bp;
    171 
    172                 // TODO: Max items per friend not yet implemented.
    173 
    174                 if ( !function_exists('friends_get_friend_user_ids') )
    175                         return false;
    176 
    177                 if ( $limit && $page )
    178                         $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    179 
    180                 if ( $max_items )
    181                         $max_sql = $wpdb->prepare( "LIMIT %d", $max_items );
    182 
    183                 /* Sort out filtering */
    184                 if ( $filter )
    185                         $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
    186 
    187194                $friend_ids = friends_get_friend_user_ids( $user_id );
    188195
    … …  
    190197                        return false;
    191198
    192                 $friend_ids = implode( ',', $friend_ids );
     199                $friend_ids = $wpdb->escape( implode( ',', $friend_ids ) );
    193200
    194201                if ( $limit && $page && $max_items )
    … …  
    202209        }
    203210
    204         function get_sitewide_activity( $max, $limit, $page, $filter ) {
    205                 global $wpdb, $bp;
    206 
    207                 if ( $limit && $page )
    208                         $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     211        function get_sitewide_activity( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false ) {
     212                global $wpdb, $bp;
     213
     214                if ( $per_page && $page )
     215                        $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
    209216
    210217                if ( $max )
    211218                        $max_sql = $wpdb->prepare( "LIMIT %d", $max );
    212219
    213                 /* Sort out filtering */
     220                /* Searching */
     221                if ( $search_terms ) {
     222                        $search_terms = $wpdb->escape( $search_terms );
     223                        $search_sql = "AND content LIKE '%%" . like_escape( $search_terms ) . "%%'";
     224                }
     225
     226                /* Filtering */
    214227                if ( $filter )
    215228                        $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
    216229
    217                 if ( $limit && $page && $max )
    218                         $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 $filter_sql ORDER BY date_recorded DESC $pag_sql" ) );
     230                /* Sorting */
     231                if ( $sort != 'ASC' && $sort != 'DESC' )
     232                        $sort = 'DESC';
     233
     234                /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
     235                if ( !$display_comments || 'threaded' == $display_comments ) {
     236                        if ( $per_page && $page && $max )
     237                                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql}" ) );
     238                        else
     239                                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}" ) );
     240
     241                        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$max_sql}" ) );
     242
     243                        if ( $activities && $display_comments )
     244                                $activities = BP_Activity_Activity::append_comments( &$activities );
     245                } else {
     246                        if ( $per_page && $page && $max )
     247                                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$pag_sql}" ) );
     248                        else
     249                                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}" ) );
     250
     251                        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
     252
     253                        if ( $activities )
     254                                $activities = BP_Activity_Activity::append_comments( &$activities );
     255                }
     256
     257                return array( 'activities' => $activities, 'total' => (int)$total_activities );
     258        }
     259
     260        function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
     261                global $wpdb, $bp;
     262
     263                if ( is_array( $activity_ids ) )
     264                        $activity_ids = implode( ',', $activity_ids );
     265
     266                $activity_ids = $wpdb->escape( $activity_ids );
     267
     268                if ( $per_page && $page )
     269                        $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
     270
     271                if ( $max )
     272                        $max_sql = $wpdb->prepare( "LIMIT %d", $max );
     273
     274                if ( $sort != 'ASC' && $sort != 'DESC' )
     275                        $sort = 'DESC';
     276
     277                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) ORDER BY date_recorded {$sort} $pag_sql $max_sql" ) );
     278                $total_activities = $wpdb->get_results( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) ORDER BY date_recorded {$sort}" ) );
     279
     280                if ( $display_comments )
     281                        $activities = BP_Activity_Activity::append_comments( $activities );
     282
     283                return array( 'activities' => $activities, 'total' => (int)$total_activities );
     284        }
     285
     286        function append_comments( $activities ) {
     287                global $bp, $wpdb;
     288
     289                /* Now fetch the activity comments and parse them into the correct position in the activities array. */
     290                foreach( $activities as $activity ) {
     291                        if ( 'activity_comment' != $activity->component_action )
     292                                $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
     293                }
     294
     295                /* Merge the comments with the activity items */
     296                foreach( $activities as $key => $activity )
     297                        $activities[$key]->children = $activity_comments[$activity->id];
     298
     299                return $activities;
     300        }
     301
     302        function get_activity_comments( $activity_id, $left, $right ) {
     303                global $wpdb, $bp;
     304
     305                /* Start with an empty $stack */
     306                $stack = array();
     307
     308                /* Retrieve all descendants of the $root node */
     309                $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE component_action = 'activity_comment' AND item_id = %d AND mptt_left BETWEEN %d AND %d", $activity_id, $left, $right ) );
     310
     311                /* Loop descendants and build an assoc array */
     312                foreach ( $descendants as $d ) {
     313                    $d->children = array();
     314
     315                        /* We have a reference on its parent */
     316                    if ( isset( $ref[ $d->secondary_item_id ] ) ) {
     317                        $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
     318                        $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
     319
     320                        /* We don't have a reference on its parent, put it a root level */
     321                    } else {
     322                        $menu[ $d->id ] = $d;
     323                        $ref[ $d->id ] =& $menu[ $d->id ];
     324                    }
     325                }
     326
     327                return $menu;
     328        }
     329
     330        function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
     331                global $wpdb, $bp;
     332
     333                /* The right value of this node is the left value + 1 */
     334                $right = $left + 1;
     335
     336                /* Get all descendants of this node */
     337                $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE component_action = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
     338
     339                /* Loop the descendants and recalculate the left and right values */
     340                foreach ( $descendants as $descendant )
     341                        $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
     342
     343                /* We've got the left value, and now that we've processed the children of this node we also know the right value */
     344                if ( 1 == $left )
     345                        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
    219346                else
    220                         $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql" ) );
    221 
    222                 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 $filter_sql ORDER BY date_recorded DESC $max_sql" ) );
    223 
    224                 return array( 'activities' => $activities, 'total' => (int)$total_activities );
     347                        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE component_action = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );
     348
     349                /* Return the right value of this node + 1 */
     350                return $right + 1;
    225351        }
    226352
    … …  
    234360                global $wpdb, $bp;
    235361
    236                 $activities = bp_activity_get_sitewide_activity( $limit );
     362                $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
     363
    237364                for ( $i = 0; $i < count($activities); $i++ ) {
    238365                                $title = explode( '<span', $activities[$i]['content'] );
  • trunk/bp-activity/bp-activity-filters.php

    r2077 r2088  
    1919        $activity_allowedtags['span'] = array();
    2020        $activity_allowedtags['span']['class'] = array();
     21        $activity_allowedtags['div'] = array();
     22        $activity_allowedtags['div']['class'] = array();
     23        $activity_allowedtags['div']['id'] = array();
    2124        $activity_allowedtags['a']['class'] = array();
    2225        $activity_allowedtags['img'] = array();
  • trunk/bp-activity/bp-activity-templatetags.php

    r2077 r2088  
    1717        var $full_name;
    1818
    19         function bp_activity_template( $type, $user_id, $per_page, $max, $filter ) {
     19        function bp_activity_template( $type, $user_id, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments ) {
    2020                global $bp;
    2121
    … …  
    2424                $this->activity_type = $type;
    2525
    26                 if ( $type == 'sitewide' )
    27                         $this->activities = bp_activity_get_sitewide_activity( $max, $this->pag_num, $this->pag_page, $filter );
    28 
    29                 if ( $type == 'personal' )
    30                         $this->activities = bp_activity_get_user_activity( $user_id, $max, $this->pag_num, $this->pag_page, $filter );
    31 
    32                 if ( $type == 'friends' && ( bp_is_home() || is_site_admin() || $bp->loggedin_user->id == $user_id ) )
    33                         $this->activities = bp_activity_get_friends_activity( $user_id, $max, false, $this->pag_num, $this->pag_page, $filter );
     26                if ( !empty( $include ) ) {
     27                        /* 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 ) );
     29                } 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 ) );
     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 ) );
     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 );
     38                }
    3439
    3540                if ( !$max || $max >= (int)$this->activities['total'] )
    … …  
    119124        $defaults = array(
    120125                'type' => 'sitewide',
    121                 'per_page' => 25,
    122                 'max' => false,
     126                'display_comments' => false, // false for none, stream/threaded - show comments in the stream or threaded under items
     127                'include' => false, // pass an activity_id or string of ID's comma separated
     128                'sort' => 'DESC', // sort DESC or ASC
     129                'per_page' => 25, // number of items per page
     130                'max' => false, // max number to return
     131
     132                /* Filtering */
    123133                'user_id' => false, // user_id to filter on
    124134                'object' => false, // object to filter on e.g. groups, profile, status, friends
    … …  
    126136                'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
    127137                'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
     138
     139                /* Searching */
     140                'search_terms' => false // specify terms to search on
    128141        );
    129142
    … …  
    144157                $filter = array( 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
    145158
    146         $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $filter );
     159        $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments );
     160
    147161        return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template );
    148162}
    … …  
    197211
    198212                return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
     213        }
     214
     215function bp_activity_id() {
     216        echo bp_get_activity_id();
     217}
     218        function bp_get_activity_id() {
     219                global $activities_template;
     220                return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
     221        }
     222
     223function bp_activity_item_id() {
     224        echo bp_get_activity_item_id();
     225}
     226        function bp_get_activity_item_id() {
     227                global $activities_template;
     228                return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
     229        }
     230
     231function bp_activity_secondary_item_id() {
     232        echo bp_get_activity_secondary_item_id();
     233}
     234        function bp_get_activity_secondary_item_id() {
     235                global $activities_template;
     236                return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
     237        }
     238
     239function bp_activity_date_recorded() {
     240        echo bp_get_activity_date_recorded();
     241}
     242        function bp_get_activity_date_recorded() {
     243                global $activities_template;
     244                return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
     245        }
     246
     247function bp_activity_object_name() {
     248        echo bp_get_activity_object_name();
     249}
     250        function bp_get_activity_object_name() {
     251                global $activities_template;
     252                return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component_name );
     253        }
     254
     255function bp_activity_action_name() {
     256        echo bp_get_activity_action_name();
     257}
     258        function bp_get_activity_action_name() {
     259                global $activities_template;
     260                return apply_filters( 'bp_get_activity_action_name', $activities_template->activity->component_action );
    199261        }
    200262
    … …  
    255317                $content = apply_filters( 'the_content', $content );
    256318
    257                 return apply_filters( 'bp_get_activity_content', $content );
     319                return apply_filters( 'bp_get_activity_content', $content, $activities_template->activity->component_name, $activities_template->activity->component_action );
    258320        }
    259321
    … …  
    299361        return apply_filters( 'bp_activity_content_filter', $content_new );
    300362}
     363
     364function bp_activity_comments( $args = '' ) {
     365        echo bp_activity_get_comments( $args );
     366}
     367        function bp_activity_get_comments( $args = '' ) {
     368                global $activities_template, $bp;
     369
     370                if ( !$activities_template->activity->children )
     371                        return false;
     372
     373                $comments_html = bp_activity_recurse_comments( $activities_template->activity );
     374
     375                return apply_filters( 'bp_activity_get_comments', $comments_html );
     376        }
     377                /* The HTML in this function is temporary, it will be move to template tags once comments are working. */
     378                function bp_activity_recurse_comments( $comment ) {
     379                        global $activities_template, $bp;
     380
     381                        if ( !$comment->children )
     382                                return false;
     383
     384                        $content .= '<ul>';
     385                        foreach ( $comment->children as $comment ) {
     386                                $content .= '<li id="acomment-' . $comment->id . '">';
     387
     388                                $content .= '<div class="acomment-avatar">' . bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => 25, 'height' => 25 ) ) . '</div>';
     389
     390                                $content .= '<div class="acomment-meta">' . bp_core_get_userlink( $comment->user_id ) . ' &middot; ' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( strtotime( $comment->date_recorded ) ) );
     391
     392                                /* Reply link */
     393                                if ( is_user_logged_in() )
     394                                        $content .= ' &middot; <a href="#acomment-' . $comment->id . '" class="acomment-reply" id="acomment-reply-' . $activities_template->activity->id . '">' . __( 'Reply', 'buddypress' ) . '</a>';
     395
     396                                /* Delete link */
     397                                if ( is_site_admin() || $bp->loggedin_user->id == $comment->user_id )
     398                                        $content .= ' &middot; <a href="' . wp_nonce_url( $bp->activity->id . '/delete/?cid=' . $comment->id, 'delete_activity_comment' ) . '" class="delete acomment-delete">' . __( 'Delete', 'buddypress' ) . '</a>';
     399
     400                                $content .= '</div>';
     401                                $content .= '<div class="acomment-content">' . apply_filters( 'bp_get_activity_content', $comment->content ) . '</div>';
     402
     403                                $content .= bp_activity_recurse_comments( $comment );
     404                                $content .= '</li>';
     405                        }
     406                        $content .= '</ul>';
     407
     408                        return $content;
     409                }
    301410
    302411function bp_activity_insert_time_since( $content, $date ) {
    … …  
    391500                        $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . attribute_escape( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
    392501
    393                 return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
     502                return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
    394503        }
    395504
  • trunk/bp-activity/deprecated/bp-activity-deprecated.php

    r2077 r2088  
    9393add_action( 'bp_styles', 'bp_activity_add_structure_css' );
    9494
     95/* DEPRECATED - use bp_activity_get_sitewide( $args ) */
     96function bp_activity_get_sitewide_activity( $max_items = 30, $pag_num = false, $pag_page = false, $filter = false ) {
     97        return apply_filters( 'bp_activity_get_sitewide_activity', bp_activity_get_sitewide( array( 'max' => $max_items, 'limit' => $pag_num, 'page' => $pag_page, 'filter' => $filter ) ), $max_items, $pag_num, $pag_page, $filter );
     98}
     99
     100/* DEPRECATED - use bp_activity_get_for_user( $args ) */
     101function bp_activity_get_user_activity( $user_id, $max = 30, $pag_num = false, $pag_page = false, $filter = false ) {
     102        return apply_filters( 'bp_activity_get_user_activity', BP_Activity_Activity::get_activity_for_user( $user_id, $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments ), $user_id, $max_items, $pag_num, $pag_page, $filter );
     103}
     104
     105
    95106?>
  • trunk/bp-blogs/bp-blogs-templatetags.php

    r1949 r2088  
    55function bp_blog_signup_enabled() {
    66        $active_signup = get_site_option( 'registration' );
    7        
     7
    88        if ( !$active_signup )
    99                $active_signup = 'all';
    10                
     10
    1111        $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
    12        
     12
    1313        if ( 'none' == $active_signup || 'user' == $active_signup )
    1414                return false;
    15        
     15
    1616        return true;
    1717}
    … …  
    2020        global $current_user, $current_site;
    2121        global $bp;
    22                
     22
    2323        require_once( ABSPATH . WPINC . '/registration.php' );
    2424
    … …  
    4848                        <input type="hidden" name="stage" value="gimmeanotherblog" />
    4949                        <?php do_action( "signup_hidden_fields" ); ?>
    50                        
     50
    5151                        <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
    5252                        <p>
    5353                                <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog &raquo;', 'buddypress') ?>" />
    5454                        </p>
    55                        
     55
    5656                        <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
    5757                </form>
    … …  
    6262function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
    6363        global $current_site;
    64        
     64
    6565        // Blog name
    6666        if( 'no' == constant( "VHOST" ) )
    … …  
    9090        // Blog Title
    9191        ?>
    92         <label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label>       
     92        <label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label>
    9393        <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
    9494                <p class="error"><?php echo $errmsg ?></p>
    … …  
    9999        <p>
    100100                <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'); ?> 
     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'); ?>
    102102
    103103
    … …  
    119119        global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;
    120120
    121         if ( !check_admin_referer( 'bp_blog_signup_form' ) ) 
     121        if ( !check_admin_referer( 'bp_blog_signup_form' ) )
    122122                return false;
    123123
    124124        $current_user = wp_get_current_user();
    125        
     125
    126126        if( !is_user_logged_in() )
    127127                die();
    … …  
    137137
    138138        $public = (int) $_POST['blog_public'];
    139        
     139
    140140        $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
    141141        $meta = apply_filters( 'add_signup_meta', $meta );
    142        
     142
    143143        /* If this is a VHOST install, remove the username from the domain as we are setting this blog
    144144           up inside a user domain, not the root domain. */
    145        
     145
    146146        wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
    147147        bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
    … …  
    169169function bp_create_blog_link() {
    170170        global $bp;
    171        
     171
    172172        if ( bp_is_home() )     {
    173173                echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog">' . __('Create a Blog', 'buddypress') . '</a>' );
    … …  
    177177function bp_blogs_blog_tabs() {
    178178        global $bp, $groups_template;
    179        
     179
    180180        // Don't show these tabs on a user's own profile
    181181        if ( bp_is_home() )
    182182                return false;
    183        
     183
    184184        $current_tab = $bp->current_action
    185185?>
    … …  
    187187                <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>
    188188                <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>     
     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>
    190190        </ul>
    191191<?php
    … …  
    202202        var $blogs;
    203203        var $blog;
    204        
     204
    205205        var $in_the_loop;
    206        
     206
    207207        var $pag_page;
    208208        var $pag_num;
    209209        var $pag_links;
    210210        var $total_blog_count;
    211        
     211
    212212        function bp_blogs_user_blogs_template( $user_id, $per_page, $max ) {
    213213                global $bp;
    214                
     214
    215215                if ( !$user_id )
    216216                        $user_id = $bp->displayed_user->id;
    … …  
    223223                        wp_cache_set( 'bp_blogs_for_user_' . $user_id, $this->blogs, 'bp' );
    224224                }
    225                
     225
    226226                if ( !$max || $max >= (int)$this->blogs['count'] )
    227227                        $this->total_blog_count = (int)$this->blogs['count'];
    228228                else
    229229                        $this->total_blog_count = (int)$max;
    230                
     230
    231231                $this->blogs = array_slice( (array)$this->blogs['blogs'], intval( ( $this->pag_page - 1 ) * $this->pag_num), intval( $this->pag_num ) );
    232                
     232
    233233                if ( $max ) {
    234234                        if ( $max >= count($this->blogs) )
    … …  
    239239                        $this->blog_count = count($this->blogs);
    240240                }
    241                
     241
    242242                $this->pag_links = paginate_links( array(
    243243                        'base' => add_query_arg( 'fpage', '%#%' ),
    … …  
    250250                ));
    251251        }
    252        
     252
    253253        function has_blogs() {
    254254                if ( $this->blog_count )
    255255                        return true;
    256                
     256
    257257                return false;
    258258        }
    259        
     259
    260260        function next_blog() {
    261261                $this->current_blog++;
    262262                $this->blog = $this->blogs[$this->current_blog];
    263                
     263
    264264                return $this->blog;
    265265        }
    266        
     266
    267267        function rewind_blogs() {
    268268                $this->current_blog = -1;
    … …  
    271271                }
    272272        }
    273        
    274         function user_blogs() { 
     273
     274        function user_blogs() {
    275275                if ( $this->current_blog + 1 < $this->blog_count ) {
    276276                        return true;
    … …  
    284284                return false;
    285285        }
    286        
     286
    287287        function the_blog() {
    288288                global $blog;
    … …  
    290290                $this->in_the_loop = true;
    291291                $blog = $this->next_blog();
    292                
     292
    293293                if ( 0 == $this->current_blog ) // loop has just started
    294294                        do_action('loop_start');
    … …  
    324324function bp_blogs_pagination_count() {
    325325        global $bp, $blogs_template;
    326        
     326
    327327        $from_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
    328328        $to_num = ( $from_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $from_num + ( $blogs_template->pag_num - 1 ) ;
    … …  
    346346        function bp_get_blog_title() {
    347347                global $blogs_template;
    348                        
    349                 return apply_filters( 'bp_get_blog_title', $blogs_template->blog['title'] );
     348
     349                return apply_filters( 'bp_get_blog_title', $blogs_template->blog->name );
    350350        }
    351351
    … …  
    355355        function bp_get_blog_description() {
    356356                global $blogs_template;
    357                
    358                 return apply_filters( 'bp_get_blog_description', $blogs_template->blog['description'] );
     357
     358                return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
    359359        }
    360360
    … …  
    363363}
    364364        function bp_get_blog_permalink() {
    365                 global $blogs_template; 
    366                
    367                 return apply_filters( 'bp_get_blog_permalink', $blogs_template->blog['siteurl'] );
     365                global $blogs_template;
     366
     367                return apply_filters( 'bp_get_blog_permalink', $blogs_template->blog->siteurl );
    368368        }
    369369
    … …  
    378378        var $posts;
    379379        var $post;
    380        
     380
    381381        var $in_the_loop;
    382        
     382
    383383        var $pag_page;
    384384        var $pag_num;
    385385        var $pag_links;
    386386        var $total_post_count;
    387        
     387
    388388        function bp_blogs_blog_post_template( $user_id, $per_page, $max ) {
    389389                global $bp;
    390                
     390
    391391                if ( !$user_id )
    392392                        $user_id = $bp->displayed_user->id;
    … …  
    394394                $this->pag_page = isset( $_GET['fpage'] ) ? intval( $_GET['fpage'] ) : 1;
    395395                $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page;
    396                
     396
    397397                if ( !$this->posts = wp_cache_get( 'bp_user_posts_' . $user_id, 'bp' ) ) {
    398398                        $this->posts = bp_blogs_get_posts_for_user( $user_id );
    399399                        wp_cache_set( 'bp_user_posts_' . $user_id, $this->posts, 'bp' );
    400400                }
    401                
     401
    402402                if ( !$max || $max >= (int)$this->posts['count'] )
    403403                        $this->total_post_count = (int)$this->posts['count'];
    404404                else
    405405                        $this->total_post_count = (int)$max;
    406                
     406
    407407                $this->posts = array_slice( (array)$this->posts['posts'], intval( ( $this->pag_page - 1 ) * $this->pag_num), intval( $this->pag_num ) );
    408408
    … …  
    415415                        $this->post_count = count($this->posts);
    416416                }
    417                
     417
    418418                $this->pag_links = paginate_links( array(
    419419                        'base' => add_query_arg( 'fpage', '%#%' ),
    … …  
    424424                        'next_text' => '&raquo;',
    425425                        'mid_size' => 1
    426                 ));     
    427         }
    428        
     426                ));
     427        }
     428
    429429        function has_posts() {
    430430                if ( $this->post_count )
    431431                        return true;
    432                
     432
    433433                return false;
    434434        }
    435        
     435
    436436        function next_post() {
    437437                $this->current_post++;
    438438                $this->post = $this->posts[$this->current_post];
    439                
     439
    440440                return $this->post;
    441441        }
    442        
     442
    443443        function rewind_posts() {
    444444                $this->current_post = -1;
    … …  
    447447                }
    448448        }
    449        
    450         function user_posts() { 
     449
     450        function user_posts() {
    451451                if ( $this->current_post + 1 < $this->post_count ) {
    452452                        return true;
    … …  
    460460                return false;
    461461        }
    462        
     462
    463463        function the_post() {
    464464                global $post;
    … …  
    466466                $this->in_the_loop = true;
    467467                $post = $this->next_post();
    468                
     468
    469469                if ( 0 == $this->current_post ) // loop has just started
    470470                        do_action('loop_start');
    … …  
    484484        extract( $r, EXTR_SKIP );
    485485
    486         $posts_template = new BP_Blogs_Blog_Post_Template( $user_id, $per_page, $max ); 
     486        $posts_template = new BP_Blogs_Blog_Post_Template( $user_id, $per_page, $max );
    487487        return apply_filters( 'bp_has_posts', $posts_template->has_posts(), &$posts_template );
    488488}
    … …  
    500500function bp_post_pagination_count() {
    501501        global $bp, $posts_template;
    502        
     502
    503503        $from_num = intval( ( $posts_template->pag_page - 1 ) * $posts_template->pag_num ) + 1;
    504504        $to_num = ( $from_num + ( $posts_template->pag_num - 1 ) > $posts_template->total_post_count ) ? $posts_template->total_post_count : $from_num + ( $posts_template->pag_num - 1 ) ;
    … …  
    522522        function bp_get_post_id() {
    523523                global $posts_template;
    524                 return apply_filters( 'bp_get_post_id', $posts_template->post->ID );   
    525         }
    526        
     524                return apply_filters( 'bp_get_post_id', $posts_template->post->ID );
     525        }
     526
    527527function bp_post_title( $deprecated = true ) {
    528528        if ( !$deprecated )
    … …  
    533533        function bp_get_post_title() {
    534534                global $posts_template;
    535                
     535
    536536                return apply_filters( 'bp_get_post_title', $posts_template->post->post_title );
    537537        }
    … …  
    539539function bp_post_permalink() {
    540540        global $posts_template;
    541        
    542         echo bp_post_get_permalink();   
     541
     542        echo bp_post_get_permalink();
    543543}
    544544
    545545function bp_post_excerpt() {
    546         echo bp_get_post_excerpt();     
     546        echo bp_get_post_excerpt();
    547547}
    548548        function bp_get_post_excerpt() {
    549549                global $posts_template;
    550                 echo apply_filters( 'bp_get_post_excerpt', $posts_template->post->post_excerpt );       
     550                echo apply_filters( 'bp_get_post_excerpt', $posts_template->post->post_excerpt );
    551551        }
    552552
    … …  
    567567        function bp_get_post_status() {
    568568                global $posts_template;
    569                 return apply_filters( 'bp_get_post_status', $posts_template->post->post_status );       
    570         }
    571        
     569                return apply_filters( 'bp_get_post_status', $posts_template->post->post_status );
     570        }
     571
    572572function bp_post_date( $date_format = null, $deprecated = true ) {
    573573        if ( !$date_format )
    574574                $date_format = get_option('date_format');
    575                
     575
    576576        if ( !$deprecated )
    577577                return bp_get_post_date( $date_format );
    … …  
    593593        function bp_get_post_comment_count() {
    594594                global $posts_template;
    595                 return apply_filters( 'bp_get_post_comment_count', $posts_template->post->comment_count );     
     595                return apply_filters( 'bp_get_post_comment_count', $posts_template->post->comment_count );
    596596        }
    597597
    598598function bp_post_comments( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $css_class = '', $none = 'Comments Off' ) {
    599599        global $posts_template, $wpdb;
    600        
     600
    601601        $number = (int)$posts_template->post->comment_count;
    602        
     602
    603603        if ( 0 == $number && 'closed' == $posts_template->postcomment_status && 'closed' == $posts_template->postping_status ) {
    604604                echo '<span' . ((!empty($css_class)) ? ' class="' . $css_class . '"' : '') . '>' . $none . '</span>';
    … …  
    614614
    615615        echo '<a href="';
    616        
     616
    617617        if ( 0 == $number )
    618618                echo bp_post_get_permalink() . '#respond';
    … …  
    620620                echo bp_post_get_permalink() . '#comments';
    621621        echo '"';
    622        
     622
    623623        if ( !empty( $css_class ) ) {
    624624                echo ' class="'.$css_class.'" ';
    … …  
    629629
    630630        echo ' title="' . sprintf( __('Comment on %s', 'buddypress'), $title ) . '">';
    631        
     631
    632632        if ( 1 == $number )
    633633                printf( __( '%d Comment', 'buddypress' ), $number );
    634634        else
    635635                printf( __( '%d Comments', 'buddypress' ), $number );
    636                
     636
    637637        echo '</a>';
    638638}
    … …  
    646646        function bp_get_post_author() {
    647647                global $posts_template;
    648                
     648
    649649                return apply_filters( 'bp_get_post_author', bp_core_get_userlink( $posts_template->post->post_author ) );
    650650        }
    … …  
    664664                        $post_id = $posts_template->post->ID;
    665665
    666                 return apply_filters( 'bp_get_post_category', get_the_category_list( $separator, $parents, $post_id ) );       
     666                return apply_filters( 'bp_get_post_category', get_the_category_list( $separator, $parents, $post_id ) );
    667667        }
    668668
    669669function bp_post_tags( $before = '', $sep = ', ', $after = '' ) {
    670670        global $posts_template, $wpdb;
    671        
     671
    672672        /* Disabling this for now as it's too expensive and there is no global tags directory */
    673673        return false;
    674        
     674
    675675        switch_to_blog( $posts_template->post->blog_id );
    676676        $terms = bp_post_get_term_list( $before, $sep, $after );
    … …  
    692692        function bp_get_post_blog_name() {
    693693                global $posts_template;
    694                 return apply_filters( 'bp_get_post_blog_name', get_blog_option( $posts_template->post->blog_id, 'blogname' ) ); 
     694                return apply_filters( 'bp_get_post_blog_name', get_blog_option( $posts_template->post->blog_id, 'blogname' ) );
    695695        }
    696696
    697697function bp_post_blog_permalink() {
    698         echo bp_get_post_blog_permalink();     
     698        echo bp_get_post_blog_permalink();
    699699}
    700700        function bp_get_post_blog_permalink() {
    701701                global $posts_template;
    702                 return apply_filters( 'bp_get_post_blog_permalink', get_blog_option( $posts_template->post->blog_id, 'siteurl' ) );     
    703         }
    704        
     702                return apply_filters( 'bp_get_post_blog_permalink', get_blog_option( $posts_template->post->blog_id, 'siteurl' ) );
     703        }
     704
    705705function bp_post_get_permalink( $post = null, $blog_id = null ) {
    706706        global $current_blog, $posts_template;
    707        
     707
    708708        if ( !$post )
    709                 $post = $posts_template->post; 
    710                
     709                $post = $posts_template->post;
     710
    711711        if ( !$blog_id )
    712712                $blog_id = $posts_template->post->blog_id;
    713                
     713
    714714        if ( !$post || !$blog_id )
    715715                return false;
    716                
     716
    717717        $rewritecode = array(
    718718                '%year%',
    … …  
    735735
    736736        $permalink = get_blog_option( $blog_id, 'permalink_structure' );
    737         $site_url = get_blog_option( $blog_id, 'siteurl' ); 
     737        $site_url = get_blog_option( $blog_id, 'siteurl' );
    738738
    739739        if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
    … …  
    753753                        if ( empty($category) ) {
    754754                                $default_category = get_category( get_option( 'default_category' ) );
    755                                 $category = is_wp_error( $default_category ) ? '' : $default_category->slug; 
     755                                $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
    756756                        }
    757757                }
    … …  
    789789function bp_post_get_term_list( $before = '', $sep = '', $after = '' ) {
    790790        global $posts_template;
    791        
     791
    792792        $terms = get_the_terms( $posts_template->post->ID, 'post_tag' );
    793793
    … …  
    801801                $link = get_blog_option( BP_ROOT_BLOG, 'siteurl') . '/tag/' . $term->slug;
    802802                $link = apply_filters('term_link', $link);
    803                
     803
    804804                $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>';
    805805        }
    … …  
    820820        var $comments;
    821821        var $comment;
    822        
     822
    823823        var $in_the_loop;
    824        
     824
    825825        var $pag_page;
    826826        var $pag_num;
    827827        var $pag_links;
    828828        var $total_comment_count;
    829        
     829
    830830        function bp_blogs_post_comment_template( $user_id, $per_page, $max ) {
    831831                global $bp;
    832                
     832
    833833                if ( !$user_id )
    834834                        $user_id = $bp->displayed_user->id;
    … …  
    836836                $this->pag_page = isset( $_GET['compage'] ) ? intval( $_GET['compage'] ) : 1;
    837837                $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page;
    838                
     838
    839839                if ( !$this->comments = wp_cache_get( 'bp_user_comments_' . $user_id, 'bp' ) ) {
    840840                        $this->comments = bp_blogs_get_comments_for_user( $user_id );
    841841                        wp_cache_set( 'bp_user_comments_' . $user_id, $this->comments, 'bp' );
    842842                }
    843                
     843
    844844                if ( !$max || $max >= (int)$this->comments['count'] )
    845845                        $this->total_comment_count = (int)$this->comments['count'];
    846846                else
    847847                        $this->total_comment_count = (int)$max;
    848                
     848
    849849                $this->comments = array_slice( (array)$this->comments['comments'], intval( ( $this->pag_page - 1 ) * $this->pag_num), intval( $this->pag_num ) );
    850850
    … …  
    857857                        $this->comment_count = count($this->comments);
    858858                }
    859                
     859
    860860                $this->pag_links = paginate_links( array(
    861861                        'base' => add_query_arg( 'compage', '%#%' ),
    … …  
    867867                        'mid_size' => 1
    868868                ));
    869                                
    870         }
    871        
     869
     870        }
     871
    872872        function has_comments() {
    873873                if ( $this->comment_count )
    874874                        return true;
    875                
     875
    876876                return false;
    877877        }
    878        
     878
    879879        function next_comment() {
    880880                $this->current_comment++;
    881881                $this->comment = $this->comments[$this->current_comment];
    882                
     882
    883883                return $this->comment;
    884884        }
    885        
     885
    886886        function rewind_comments() {
    887887                $this->current_comment = -1;
    … …  
    890890                }
    891891        }
    892        
    893         function user_comments() { 
     892
     893        function user_comments() {
    894894                if ( $this->current_comment + 1 < $this->comment_count ) {
    895895                        return true;
    … …  
    903903                return false;
    904904        }
    905        
     905
    906906        function the_comment() {
    907907                global $comment;
    … …  
    909909                $this->in_the_loop = true;
    910910                $comment = $this->next_comment();
    911                
     911
    912912                if ( 0 == $this->current_comment ) // loop has just started
    913913                        do_action('loop_start');
    … …  
    926926        $r = wp_parse_args( $args, $defaults );
    927927        extract( $r, EXTR_SKIP );
    928        
     928
    929929        $comments_template = new BP_Blogs_Post_Comment_Template( $user_id, $per_page, $max );
    930930        return apply_filters( 'bp_has_comments', $comments_template->has_comments(), &$comments_template );
    … …  
    946946        function bp_get_comments_pagination() {
    947947                global $comments_template;
    948                
     948
    949949                return apply_filters( 'bp_get_comments_pagination', $comments_template->pag_links );
    950950        }
    … …  
    966966        function bp_get_comment_post_permalink() {
    967967                global $comments_template;
    968                
     968
    969969                return apply_filters( 'bp_get_comment_post_permalink', bp_post_get_permalink( $comments_template->comment->post, $comments_template->comment->blog_id ) . '#comment-' . $comments_template->comment->comment_ID );
    970970        }
    … …  
    978978        function bp_get_comment_post_title( $deprecated = true ) {
    979979                global $comments_template;
    980                
     980
    981981                return apply_filters( 'bp_get_comment_post_title', $comments_template->comment->post->post_title );
    982982        }
    … …  
    984984function bp_comment_author( $deprecated = true ) {
    985985        global $comments_template;
    986        
     986
    987987        if ( !$deprecated )
    988988                return bp_get_comment_author();
    … …  
    10101010        if ( !$date_format )
    10111011                $date_format = get_option('date_format');
    1012                
     1012
    10131013        if ( !$deprecated )
    10141014                return bp_get_comment_date( $date_format );
    1015         else 
     1015        else
    10161016                echo bp_get_comment_date( $date_format );
    10171017}
    … …  
    10271027function bp_comment_blog_permalink( $deprecated = true ) {
    10281028        if ( !$deprecated )
    1029                 return bp_get_comment_blog_permalink(); 
     1029                return bp_get_comment_blog_permalink();
    10301030        else
    10311031                echo bp_get_comment_blog_permalink();
    … …  
    10391039function bp_comment_blog_name( $deprecated = true ) {
    10401040        global $comments_template;
    1041        
     1041
    10421042        if ( !$deprecated )
    1043                 return bp_get_comment_blog_permalink(); 
     1043                return bp_get_comment_blog_permalink();
    10441044        else
    1045                 echo bp_get_comment_blog_permalink();   
     1045                echo bp_get_comment_blog_permalink();
    10461046}
    10471047        function bp_get_comment_blog_name( $deprecated = true ) {
    … …  
    10601060        var $blogs;
    10611061        var $blog;
    1062        
     1062
    10631063        var $in_the_loop;
    1064        
     1064
    10651065        var $pag_page;
    10661066        var $pag_num;
    10671067        var $pag_links;
    10681068        var $total_blog_count;
    1069        
     1069
    10701070        function bp_blogs_site_blogs_template( $type, $per_page, $max ) {
    10711071                global $bp;
    … …  
    10731073                $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : 1;
    10741074                $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    1075                                
     1075
    10761076                if ( isset( $_REQUEST['s'] ) && '' != $_REQUEST['s'] && $type != 'random' ) {
    10771077                        $this->blogs = BP_Blogs_Blog::search_blogs( $_REQUEST['s'], $this->pag_num, $this->pag_page );
    … …  
    10831083                                        $this->blogs = BP_Blogs_Blog::get_random( $this->pag_num, $this->pag_page );
    10841084                                        break;
    1085                                
     1085
    10861086                                case 'newest':
    10871087                                        $this->blogs = BP_Blogs_Blog::get_newest( $this->pag_num, $this->pag_page );
    1088                                         break; 
    1089                                
     1088                                        break;
     1089
    10901090                                case 'active': default:
    10911091                                        $this->blogs = BP_Blogs_Blog::get_active( $this->pag_num, $this->pag_page );
    1092                                         break;                                 
     1092                                        break;
    10931093                        }
    10941094                }
    1095                
     1095
    10961096                if ( !$max || $max >= (int)$this->blogs['total'] )
    10971097                        $this->total_blog_count = (int)$this->blogs['total'];
    … …  
    11091109                        $this->blog_count = count($this->blogs);
    11101110                }
    1111                
     1111
    11121112                $this->pag_links = paginate_links( array(
    11131113                        'base' => add_query_arg( 'bpage', '%#%' ),
    … …  
    11181118                        'next_text' => '&raquo;',
    11191119                        'mid_size' => 1
    1120                 ));             
    1121         }
    1122        
     1120                ));
     1121        }
     1122
    11231123        function has_blogs() {
    11241124                if ( $this->blog_count )
    11251125                        return true;
    1126                
     1126
    11271127                return false;
    11281128        }
    1129        
     1129
    11301130        function next_blog() {
    11311131                $this->current_blog++;
    11321132                $this->blog = $this->blogs[$this->current_blog];
    1133                
     1133
    11341134                return $this->blog;
    11351135        }
    1136        
     1136
    11371137        function rewind_blogs() {
    11381138                $this->current_blog = -1;
    … …  
    11411141                }
    11421142        }
    1143        
    1144         function blogs() { 
     1143
     1144        function blogs() {
    11451145                if ( $this->current_blog + 1 < $this->blog_count ) {
    11461146                        return true;
    … …  
    11541154                return false;
    11551155        }
    1156        
     1156
    11571157        function the_blog() {
    11581158                global $blog;
    … …  
    11601160                $this->in_the_loop = true;
    11611161                $this->blog = $this->next_blog();
    1162                
     1162
    11631163                if ( 0 == $this->current_blog ) // loop has just started
    11641164                        do_action('loop_start');
    … …  
    11681168function bp_rewind_site_blogs() {
    11691169        global $site_blogs_template;
    1170        
    1171         $site_blogs_template->rewind_blogs();   
     1170
     1171        $site_blogs_template->rewind_blogs();
    11721172}
    11731173
    … …  
    11831183        $r = wp_parse_args( $args, $defaults );
    11841184        extract( $r, EXTR_SKIP );
    1185        
     1185
    11861186        // type: active ( default ) | random | newest | popular
    1187        
     1187
    11881188        if ( $max ) {
    11891189                if ( $per_page > $max )
    11901190                        $per_page = $max;
    11911191        }
    1192                
     1192
    11931193        $site_blogs_template = new BP_Blogs_Site_Blogs_Template( $type, $per_page, $max );
    11941194
    … …  
    11981198function bp_site_blogs() {
    11991199        global $site_blogs_template;
    1200        
     1200
    12011201        return $site_blogs_template->blogs();
    12021202}
    … …  
    12041204function bp_the_site_blog() {
    12051205        global $site_blogs_template;
    1206        
     1206
    12071207        return $site_blogs_template->the_blog();
    12081208}
    … …  
    12101210function bp_site_blogs_pagination_count() {
    12111211        global $bp, $site_blogs_template;
    1212        
     1212
    12131213        $from_num = intval( ( $site_blogs_template->pag_page - 1 ) * $site_blogs_template->pag_num ) + 1;
    12141214        $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 ) ;
    … …  
    12261226                return apply_filters( 'bp_get_site_blogs_pagination_links', $site_blogs_template->pag_links );
    12271227        }
    1228        
     1228
    12291229function bp_the_site_blog_avatar() {
    12301230        echo bp_get_the_site_blog_avatar();
    … …  
    12321232        function bp_get_the_site_blog_avatar() {
    12331233                global $site_blogs_template, $bp;
    1234                
     1234
    12351235                /***
    12361236                 * In future BuddyPress versions you will be able to set the avatar for a blog.
    … …  
    13091309                echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ). '" name="search_terms" />';
    13101310        }
    1311        
     1311
    13121312        if ( isset( $_REQUEST['letter'] ) ) {
    13131313                echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    13141314        }
    1315        
     1315
    13161316        if ( isset( $_REQUEST['blogs_search'] ) ) {
    13171317                echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
  • trunk/bp-core.php

    r2077 r2088  
    533533 * @uses get_usermeta() WordPress function to get the usermeta for a user.
    534534 */
    535 function bp_core_get_user_domain( $user_id ) {
     535function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) {
    536536        global $bp;
    537537
    538538        if ( !$user_id ) return;
    539539
    540         $ud = get_userdata($user_id);
     540        if ( $domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) )
     541                return apply_filters( 'bp_core_get_user_domain', $domain );
     542
     543        if ( !$user_nicename && !$user_login ) {
     544                $ud = get_userdata($user_id);
     545                $user_nicename = $ud->user_nicename;
     546                $user_login = $ud->user_login;
     547        }
    541548
    542549        if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
    543                 $username = $ud->user_login;
     550                $username = $user_login;
    544551        else
    545                 $username = $ud->user_nicename;
     552                $username = $user_nicename;
    546553
    547554        /* If we are using a members slug, include it. */
    548555        if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
    549                 return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/' );
     556                $domain = $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
    550557        else
    551                 return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . $username . '/' );
     558                $domain = $bp->root_domain . '/' . $username . '/';
     559
     560        /* Cache the link */
     561        wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
     562
     563        return apply_filters( 'bp_core_get_user_domain', $domain );
    552564}
    553565
    … …  
    721733}
    722734add_action( 'wp_head', 'bp_core_sort_nav_items' );
    723 
    724 /**
    725  * bp_core_remove_nav_item()
    726  *
    727  * Removes a navigation item from the main navigation array.
    728  *
    729  * @package BuddyPress Core
    730  * @param $slug The slug of the sub navigation item.
    731  */
    732 function bp_core_remove_nav_item( $slug ) {
    733         global $bp;
    734 
    735         unset( $bp->bp_nav[$slug] );
    736 }
    737735
    738736/**
    … …  
    820818
    821819/**
    822  * bp_core_remove_subnav_item()
     820 * bp_core_remove_nav_item()
    823821 *
    824822 * Removes a navigation item from the sub navigation array used in BuddyPress themes.
    … …  
    828826 * @param $slug The slug of the sub navigation item.
    829827 */
     828function bp_core_remove_nav_item( $parent_id ) {
     829        global $bp;
     830
     831        /* Unset subnav items for this nav item */
     832        foreach( $bp->bp_options_nav[$parent_id] as $subnav_item ) {
     833                bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );
     834        }
     835
     836        unset( $bp->bp_nav[$parent_id] );
     837}
     838
     839/**
     840 * bp_core_remove_subnav_item()
     841 *
     842 * Removes a navigation item from the sub navigation array used in BuddyPress themes.
     843 *
     844 * @package BuddyPress Core
     845 * @param $parent_id The id of the parent navigation item.
     846 * @param $slug The slug of the sub navigation item.
     847 */
    830848function bp_core_remove_subnav_item( $parent_id, $slug ) {
    831849        global $bp;
    832850
     851        $function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'];
     852
     853        if ( $function ) {
     854                if ( !is_object( $screen_function[0] ) )
     855                        remove_action( 'wp', $screen_function, 3 );
     856                else
     857                        remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
     858        }
     859
    833860        unset( $bp->bp_options_nav[$parent_id][$slug] );
     861
     862        if ( !count( $bp->bp_options_nav[$parent_id] ) )
     863                unset($bp->bp_options_nav[$parent_id]);
    834864}
    835865
    … …  
    9791009        global $bp;
    9801010
    981         if ( !is_numeric($uid) )
    982                 return false;
    983 
    984         return apply_filters( 'bp_core_get_userurl', bp_core_get_user_domain( $uid ) );
     1011        if ( !$url = wp_cache_get( 'bp_user_url_' . $uid, 'bp' ) ) {
     1012                $url = bp_core_get_user_domain( $uid );
     1013        }
     1014
     1015        return apply_filters( 'bp_core_get_userurl', $url );
    9851016}
    9861017
    … …  
    9971028 */
    9981029function bp_core_get_user_email( $uid ) {
    999         $ud = get_userdata($uid);
    1000         return apply_filters( 'bp_core_get_user_email', $ud->user_email );
     1030        if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {
     1031                $ud = get_userdata($uid);
     1032                $email = $ud->user_email;
     1033        }
     1034        return apply_filters( 'bp_core_get_user_email', $email );
    10011035}
    10021036
    … …  
    10311065                return false;
    10321066
    1033         if ( function_exists('bp_fetch_user_fullname') ) {
     1067        if ( function_exists( 'bp_core_get_user_displayname' ) ) {
    10341068                $display_name = bp_core_get_user_displayname( $user_id );
    10351069
    … …  
    10501084                return $url;
    10511085
    1052         return '<a href="' . $url . '">' . $display_name . '</a>';
     1086        return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '">' . $display_name . '</a>', $user_id );
    10531087}
    10541088
    … …  
    16661700        global $wpdb;
    16671701        ?>
    1668 <!-- Generated in <?php timer_stop(1); ?> seconds. -->
     1702<!-- Generated in <?php timer_stop(1); ?> seconds. <?php echo get_num_queries(); ?> -->
    16691703        <?php
    16701704}
  • trunk/bp-core/bp-core-avatars.php

    r2077 r2088  
    130130
    131131                if ( 'user' == $object ) {
    132                         $ud = get_userdata( $item_id );
    133                         $grav_email = $ud->user_email;
     132                        $grav_email = bp_core_get_user_email( $item_id );
    134133                } else if ( 'group' == $object || 'blog' == $object ) {
    135134                        $grav_email = "{$item_id}-{$object}@{$bp->root_domain}";
    … …  
    140139
    141140                return apply_filters( 'bp_core_fetch_avatar', "<img src='{$gravatar}' alt='{$alt}' id='{$css_id}' class='{$class}'{$html_width}{$html_height} />", $params );
     141
    142142        } else if ( !file_exists( $avatar_url ) && $no_grav )
    143143                return false;
  • trunk/bp-core/bp-core-catchuri.php

    r2077 r2088  
    254254                bp_core_redirect( $bp->root_domain );
    255255
     256        // If the template file doesn't exist, redirect to the root domain.
     257        if ( !bp_is_blog_page() && !file_exists( locate_template( array( $bp_path . '.php' ), false ) ) )
     258                bp_core_redirect( $bp->root_domain );
     259
    256260        if ( !$bp_path && !bp_is_blog_page() ) {
    257261                if ( is_user_logged_in() ) {
  • trunk/bp-core/bp-core-classes.php

    r2077 r2088  
    5757         */
    5858        function populate() {
    59                 $this->user_url = bp_core_get_userurl( $this->id );
    60                 $this->user_link = bp_core_get_userlink( $this->id );
    61 
    62                 $this->fullname = attribute_escape( bp_core_get_user_displayname( $this->id ) );
    63                 $this->email = attribute_escape( bp_core_get_user_email( $this->id ) );
    64                 $this->last_active = attribute_escape( bp_core_get_last_activity( get_usermeta( $this->id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) ) );
     59                if ( function_exists( 'xprofile_install' ) )
     60                        $this->profile_data = $this->get_profile_data();
     61
     62                if ( $this->profile_data ) {
     63                        $this->user_url = bp_core_get_user_domain( $this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login'] );
     64                        $this->fullname = attribute_escape( $this->profile_data[BP_XPROFILE_FULLNAME_FIELD_NAME]['field_data'] );
     65                        $this->user_link = "<a href='{$this->user_url}'>{$this->fullname}</a>";
     66                        $this->email = attribute_escape( $this->profile_data['user_email'] );
     67                } else {
     68                        $this->user_url = bp_core_get_userurl( $this->id );
     69                        $this->user_link = bp_core_get_userlink( $this->id );
     70                        $this->fullname = attribute_escape( bp_core_get_user_displayname( $this->id ) );
     71                        $this->email = attribute_escape( bp_core_get_user_email( $this->id ) );
     72                }
     73
     74                /* Cache a few things that are fetched often */
     75                wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' );
     76                wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' );
     77                wp_cache_set( 'bp_user_url_' . $this->id, $this->user_url, 'bp' );
    6578
    6679                $this->avatar = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'full' ) );
    … …  
    7285                global $bp;
    7386
    74                 if ( function_exists('friends_install') ) {
     87                if ( function_exists('friends_install') )
    7588                        $this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );
    7689
    77                         if ( $this->total_friends ) {
    78                                 if ( 1 == $this->total_friends )
    79                                         $this->total_friends .= ' ' . __( 'friend', 'buddypress' );
    80                                 else
    81                                         $this->total_friends .= ' ' . __( 'friends', 'buddypress' );
    82 
    83                                 $this->total_friends = '<a href="' . $this->user_url . $bp->friends->slug . '" title="' . sprintf( __( "%s's friend list", 'buddypress' ), $this->fullname ) . '">' . $this->total_friends . '</a>';
    84                         }
    85                 }
    86 
    87                 if ( function_exists('bp_blogs_install') ) {
    88                         if ( $this->total_blogs ) {
    89                                 if ( 1 == $this->total_blogs )
    90                                         $this->total_blogs .= ' ' . __( 'blog', 'buddypress' );
    91                                 else
    92                                         $this->total_blogs .= ' ' . __( 'blogs', 'buddypress' );
    93 
    94                                 $this->total_blogs = '<a href="' . $this->user_url . $bp->blogs->slug . '" title="' . sprintf( __( "%s's blog list", 'buddypress' ), $this->fullname ) . '">' . $this->total_blogs . '</a>';
    95                         }
    96                 }
    97 
    98                 if ( function_exists('groups_install') ) {
     90                if ( function_exists('groups_install') )
    9991                        $this->total_groups = BP_Groups_Member::total_group_count( $this->id );
    100 
    101                         if ( $this->total_groups ) {
    102                                 if ( 1 == $this->total_groups )
    103                                         $this->total_groups .= ' ' . __( 'group', 'buddypress' );
    104                                 else
    105                                         $this->total_groups .= ' ' . __( 'groups', 'buddypress' );
    106 
    107                                 $this->total_groups = '<a href="' . $this->user_url . $bp->groups->slug . '" title="' . sprintf( __( "%s's group list", 'buddypress' ), $this->fullname ) . '">' . $this->total_groups . '</a>';
    108                         }
    109                 }
     92        }
     93
     94        function get_profile_data() {
     95                return BP_XProfile_ProfileData::get_all_for_user( $this->id );
    11096        }
    11197
  • trunk/bp-core/bp-core-templatetags.php

    r2077 r2088  
    10541054        }
    10551055
    1056 function bp_the_site_member_avatar() {
    1057         echo apply_filters( 'bp_the_site_member_avatar', bp_get_the_site_member_avatar() );
    1058 }
    1059         function bp_get_the_site_member_avatar() {
    1060                 global $site_members_template;
    1061 
    1062                 return apply_filters( 'bp_get_the_site_member_avatar', $site_members_template->member->avatar_thumb );
     1056function bp_the_site_member_avatar( $args = '' ) {
     1057        echo apply_filters( 'bp_the_site_member_avatar', bp_get_the_site_member_avatar( $args ) );
     1058}
     1059        function bp_get_the_site_member_avatar( $args = '' ) {
     1060                global $bp, $site_members_template;
     1061
     1062                $defaults = array(
     1063                        'type' => 'thumb',
     1064                        'width' => false,
     1065                        'height' => false,
     1066                        'class' => 'avatar',
     1067                        'id' => false,
     1068                        'alt' => __( 'Member avatar', 'buddypress' )
     1069                );
     1070
     1071                $r = wp_parse_args( $args, $defaults );
     1072                extract( $r, EXTR_SKIP );
     1073
     1074                /* Fetch the avatar from the folder, if not provide backwards compat. */
     1075                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 ) ) )
     1076                        $avatar = '<img src="' . attribute_escape( $site_members_template->member->avatar_thumb ) . '" class="avatar" alt="' . __( 'Member avatar', 'buddypress' ) . '" />';
     1077
     1078                return apply_filters( 'bp_get_the_site_member_avatar', $avatar );
    10631079        }
    10641080
    … …  
    10891105                global $site_members_template;
    10901106
    1091                 return apply_filters( 'bp_the_site_member_last_active', $site_members_template->member->last_active );
     1107                $last_activity = attribute_escape( bp_core_get_last_activity( get_usermeta( $site_members_template->member->id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) ) );
     1108
     1109                return apply_filters( 'bp_the_site_member_last_active', $last_activity );
     1110        }
     1111
     1112function bp_the_site_member_profile_data( $field_name = false ) {
     1113        echo bp_get_the_site_member_profile_data( $field_name );
     1114}
     1115        function bp_get_the_site_member_profile_data( $field_name = false ) {
     1116                global $site_members_template;
     1117
     1118                if ( !$field_name || !function_exists( 'xprofile_install' ) )
     1119                        return false;
     1120
     1121                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'] );
    10921122        }
    10931123
    … …  
    12081238}
    12091239        function bp_displayed_user_fullname() {
    1210                 return bp_user_fullname();
     1240                global $bp;
     1241
     1242                return apply_filters( 'bp_displayed_user_fullname', $bp->displayed_user->fullname );
    12111243        }
    12121244
  • trunk/bp-core/deprecated/bp-core-deprecated.php

    r2077 r2088  
    332332        $blog_title = $filtered_results['blog_title'];
    333333        $errors = $filtered_results['errors'];
    334 
     334       
    335335        if ( empty($blogname) )
    336336                $blogname = $user_name;
  • trunk/bp-groups.php

    r2077 r2088  
    110110                        item_id bigint(20) NOT NULL,
    111111                        user_id bigint(20) NOT NULL,
     112                        parent_id bigint(20) NOT NULL,
    112113                        content longtext NOT NULL,
    113114                        date_posted datetime NOT NULL,
    114115                        KEY item_id (item_id),
    115                         KEY user_id (user_id)
     116                        KEY user_id (user_id),
     117                        KEY parent_id (parent_id)
    116118                   ) {$charset_collate};";
    117119
  • trunk/bp-groups/bp-groups-classes.php

    r2077 r2088  
    706706                        $hidden_sql = " AND g.status != 'hidden'";
    707707
    708                 $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_confirmed = 1 ORDER BY m.date_modified DESC {$pag_sql}", $user_id ) );
     708                $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}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 ORDER BY m.date_modified DESC {$pag_sql}", $user_id ) );
    709709                $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_confirmed = 1 ORDER BY m.date_modified DESC", $user_id ) );
    710710
    … …  
    726726                        $hidden_sql = " AND g.status != 'hidden'";
    727727
    728                 $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_confirmed = 1 LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id AND gm.meta_key = 'total_member_count' ORDER BY CONVERT( gm.meta_value, SIGNED ) DESC {$pag_sql}", $user_id ) );
     728                $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}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 ORDER BY CONVERT( total_member_count, SIGNED ) DESC {$pag_sql}", $user_id ) );
    729729                $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM {$bp->groups->table_name_members} m INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_confirmed = 1 LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id AND gm.meta_key = 'total_member_count' ORDER BY CONVERT( gm.meta_value, SIGNED ) DESC", $user_id ) );
    730730
    … …  
    746746                        $hidden_sql = " AND g.status != 'hidden'";
    747747
    748                 $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT 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}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 ORDER BY gm.meta_value DESC {$pag_sql}", $user_id ) );
     748                $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}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 ORDER BY last_activity DESC {$pag_sql}", $user_id ) );
    749749                $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(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}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 ORDER BY gm.meta_value DESC", $user_id ) );
    750750
    … …  
    766766                        $hidden_sql = " AND g.status != 'hidden'";
    767767
    768                 $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 ORDER BY g.name ASC {$pag_sql}", $user_id ) );
     768                $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}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 ORDER BY g.name ASC {$pag_sql}", $user_id ) );
    769769                $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 ORDER BY g.name ASC", $user_id ) );
    770770
    … …  
    786786                        $hidden_sql = " AND g.status != 'hidden'";
    787787
    788                 $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_admin = 1 ORDER BY date_modified ASC {$pag_sql}", $user_id ) );
     788                $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}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_admin = 1 ORDER BY m.date_modified ASC {$pag_sql}", $user_id ) );
    789789                $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_admin = 1 ORDER BY date_modified ASC", $user_id ) );
    790790
    … …  
    806806                        $hidden_sql = " AND g.status != 'hidden'";
    807807
    808                 $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY date_modified ASC {$pag_sql}", $user_id ) );
     808                $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}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY m.date_modified ASC {$pag_sql}", $user_id ) );
    809809                $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY date_modified ASC", $user_id ) );
    810810
  • trunk/bp-groups/bp-groups-templatetags.php

    r2077 r2088  
    247247                $this->group = $this->next_group();
    248248
    249                 // If this is a single group then instantiate group meta when creating the object.
    250                 if ( $this->single_group ) {
    251                         if ( !$group = wp_cache_get( 'groups_group_' . $this->group->group_id, 'bp' ) ) {
    252                                 $group = new BP_Groups_Group( $this->group->group_id, true );
    253                                 wp_cache_set( 'groups_group_' . $this->group->group_id, $group, 'bp' );
    254                         }
    255                 } else {
    256                         if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $this->group->group_id, 'bp' ) ) {
    257                                 $group = new BP_Groups_Group( $this->group->group_id, false, false );
    258                                 wp_cache_set( 'groups_group_nouserdata_' . $this->group->group_id, $group, 'bp' );
    259                         }
    260                 }
    261 
    262                 $this->group = $group;
     249                if ( $this->single_group )
     250                        $this->group = new BP_Groups_Group( $this->group->group_id, true, true );
    263251
    264252                if ( 0 == $this->current_group ) // loop has just started
    … …  
    282270        extract( $r, EXTR_SKIP );
    283271
    284         /* The following code will auto set parameters based on the page being viewed.
    285          * for example on example.com/members/andy/groups/my-groups/most-popular/
    286          * $type = 'most-popular'
    287          */
    288         if ( 'my-groups' == $bp->current_action ) {
    289                 $order = $bp->action_variables[0];
    290                 if ( 'recently-joined' == $order )
    291                         $type = 'recently-joined';
    292                 else if ( 'most-popular' == $order )
    293                         $type = 'popular';
    294                 else if ( 'admin-of' == $order )
    295                         $type = 'admin-of';
    296                 else if ( 'mod-of' == $order )
    297                         $type = 'mod-of';
    298                 else if ( 'alphabetically' == $order )
    299                         $type = 'alphabetical';
    300         } else if ( 'invites' == $bp->current_action ) {
    301                 $type = 'invites';
    302         } else if ( $bp->groups->current_group->slug ) {
    303                 $type = 'single-group';
    304                 $slug = $bp->groups->current_group->slug;
     272        if ( '' == $args ) {
     273                /* The following code will auto set parameters based on the page being viewed.
     274                 * for example on example.com/members/andy/groups/my-groups/most-popular/
     275                 * $type = 'most-popular'
     276                 */
     277                if ( 'my-groups' == $bp->current_action ) {
     278                        $order = $bp->action_variables[0];
     279                        if ( 'recently-joined' == $order )
     280                                $type = 'recently-joined';
     281                        else if ( 'most-popular' == $order )
     282                                $type = 'popular';
     283                        else if ( 'admin-of' == $order )
     284                                $type = 'admin-of';
     285                        else if ( 'mod-of' == $order )
     286                                $type = 'mod-of';
     287                        else if ( 'alphabetically' == $order )
     288                                $type = 'alphabetical';
     289                } else if ( 'invites' == $bp->current_action ) {
     290                        $type = 'invites';
     291                } else if ( $bp->groups->current_group->slug ) {
     292                        $type = 'single-group';
     293                        $slug = $bp->groups->current_group->slug;
     294                }
    305295        }
    306296
    … …  
    470460                        $group =& $groups_template->group;
    471461
    472                 $last_active = groups_get_groupmeta( $group->id, 'last_activity' );
     462                $last_active = $group->last_activity;
     463
     464                if ( !$last_active )
     465                        $last_active = groups_get_groupmeta( $group->id, 'last_activity' );
    473466
    474467                if ( empty( $last_active ) ) {
    … …  
    19971990        }
    19981991
    1999 function bp_the_site_group_avatar() {
    2000         echo bp_get_the_site_group_avatar();
    2001 }
    2002         function bp_get_the_site_group_avatar() {
     1992function bp_the_site_group_avatar( $args = '' ) {
     1993        echo bp_get_the_site_group_avatar( $args );
     1994}
     1995        function bp_get_the_site_group_avatar( $args = '' ) {
    20031996                global $site_groups_template;
    20041997
    2005                 return apply_filters( 'bp_the_site_group_avatar', bp_core_fetch_avatar( array( 'item_id' => $site_groups_template->group->id, 'object' => 'group', 'type' => 'full', 'avatar_dir' => 'group-avatars', 'alt' => __( 'Group Avatar', 'buddypress' ) ) ) );
     1998                $defaults = array(
     1999                        'type' => 'full',
     2000                        'width' => false,
     2001                        'height' => false,
     2002                        'class' => 'avatar',
     2003                        'id' => false,
     2004                        'alt' => __( 'Group avatar', 'buddypress' )
     2005                );
     2006
     2007                $r = wp_parse_args( $args, $defaults );
     2008                extract( $r, EXTR_SKIP );
     2009
     2010                return apply_filters( 'bp_the_site_group_avatar', bp_core_fetch_avatar( array( 'item_id' => $site_groups_template->group->id, 'object' => 'group', 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height ) ) );
    20062011        }
    20072012
  • trunk/bp-xprofile.php

    r2077 r2088  
    11<?php
    2 define ( 'BP_XPROFILE_DB_VERSION', '1800' );
     2define ( 'BP_XPROFILE_DB_VERSION', '1850' );
    33
    44/* Define the slug for the component */
    … …  
    110110                           item_id bigint(20) NOT NULL,
    111111                           user_id bigint(20) NOT NULL,
     112                           parent_id bigint(20) NOT NULL,
    112113                           content longtext NOT NULL,
    113114                           date_posted datetime NOT NULL,
    114115                           KEY item_id (item_id),
    115                        KEY user_id (user_id)
     116                       KEY user_id (user_id),
     117                       KEY parent_id (parent_id)
    116118                       ) {$charset_collate};";
    117119
    … …  
    530532                return false;
    531533
    532         if ( !$wire_post = bp_wire_new_post( $bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->slug, false, $bp->profile->table_name_wire ) ) {
     534        if ( !$wire_post = bp_wire_new_post( $bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->id ) ) {
    533535                bp_core_add_message( __( 'Wire message could not be posted. Please try again.', 'buddypress' ), 'error' );
    534536        } else {
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r2077 r2088  
    719719        /** Static Functions **/
    720720
     721        /**
     722         * BP_XProfile_ProfileData::get_all_for_user()
     723         *
     724         * Get all of the profile information for a specific user.
     725         */
     726        function get_all_for_user( $user_id ) {
     727                global $wpdb, $bp;
     728
     729                $results = $wpdb->get_results( $wpdb->prepare( "SELECT g.name as field_group_name, f.name as field_name, f.type as field_type, d.value as field_data, u.user_login, u.user_nicename, u.user_email FROM {$bp->profile->table_name_groups} g LEFT JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id INNER JOIN {$bp->profile->table_name_data} d ON f.id = d.field_id LEFT JOIN {$wpdb->users} u ON d.user_id = u.ID WHERE d.user_id = %d AND d.value != ''", $user_id ) );
     730
     731                if ( $results ) {
     732                        $profile_data['user_login'] = $results[0]->user_login;
     733                        $profile_data['user_nicename'] = $results[0]->user_nicename;
     734                        $profile_data['user_email'] = $results[0]->user_email;
     735
     736                        foreach( (array) $results as $field ) {
     737                                $profile_data[$field->field_name] = array( 'field_group' => $field->field_group_name, 'field_type' => $field->field_type, 'field_data' => $field->field_data );
     738                        }
     739                }
     740
     741                return $profile_data;
     742        }
     743
    721744        function get_value_byid( $field_id, $user_id = null ) {
    722745                global $wpdb, $bp;
  • trunk/bp-xprofile/bp-xprofile-filters.php

    r2077 r2088  
    33/* Apply WordPress defined filters */
    44add_filter( 'bp_get_the_profile_field_value', 'wp_filter_kses', 1 );
     5add_filter( 'bp_get_the_site_member_profile_data', 'wp_filter_kses', 1 );
    56add_filter( 'xprofile_get_field_data', 'wp_filter_kses', 1 );
    67add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses', 1 );
    … …  
    2021add_filter( 'bp_get_the_profile_field_value', 'force_balance_tags' );
    2122
     23add_filter( 'bp_get_the_site_member_profile_data', 'wptexturize' );
     24add_filter( 'bp_get_the_site_member_profile_data', 'convert_smilies', 2 );
     25add_filter( 'bp_get_the_site_member_profile_data', 'convert_chars' );
     26add_filter( 'bp_get_the_site_member_profile_data', 'make_clickable' );
     27add_filter( 'bp_get_the_site_member_profile_data', 'force_balance_tags' );
     28
    2229add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value', 1, 2 );
     30add_filter( 'bp_get_the_site_member_profile_data', 'xprofile_filter_format_field_value', 1, 2 );
    2331add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 2, 2 );
    2432
    … …  
    2735add_filter( 'xprofile_get_field_data', 'stripslashes' );
    2836add_filter( 'bp_get_the_profile_field_description', 'stripslashes' );
     37add_filter( 'bp_get_the_site_member_profile_data', 'stripslashes' );
    2938
    3039/* Custom BuddyPress filters */
Note: See TracChangeset for help on using the changeset viewer.