Skip to:
Content

BuddyPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.