Skip to:
Content

BuddyPress.org

Ticket #4871: bp-activity-template.php

File bp-activity-template.php, 86.5 KB (added by chroniko, 11 years ago)
Line 
1<?php
2
3/**
4 * BuddyPress Activity Template Functions
5 *
6 * @package BuddyPress
7 * @subpackage ActivityTemplate
8 */
9
10// Exit if accessed directly
11if ( !defined( 'ABSPATH' ) ) exit;
12
13/**
14 * Output the activity component slug
15 *
16 * @since BuddyPress (1.5)
17 *
18 * @uses bp_get_activity_slug()
19 */
20function bp_activity_slug() {
21        echo bp_get_activity_slug();
22}
23        /**
24         * Return the activity component slug
25         *
26         * @since BuddyPress (1.5)
27         *
28         * @global object $bp BuddyPress global settings
29         * @uses apply_filters() To call the 'bp_get_activity_slug' hook
30         */
31        function bp_get_activity_slug() {
32                global $bp;
33                return apply_filters( 'bp_get_activity_slug', $bp->activity->slug );
34        }
35
36/**
37 * Output the activity component root slug
38 *
39 * @since BuddyPress (1.5)
40 *
41 * @uses bp_get_activity_root_slug()
42 */
43function bp_activity_root_slug() {
44        echo bp_get_activity_root_slug();
45}
46        /**
47         * Return the activity component root slug
48         *
49         * @since BuddyPress (1.5)
50         *
51         * @global object $bp BuddyPress global settings
52         * @uses apply_filters() To call the 'bp_get_activity_root_slug' hook
53         */
54        function bp_get_activity_root_slug() {
55                global $bp;
56                return apply_filters( 'bp_get_activity_root_slug', $bp->activity->root_slug );
57        }
58
59/**
60 * Output member directory permalink
61 *
62 * @since BuddyPress (1.5)
63 *
64 * @uses bp_get_activity_directory_permalink()
65 */
66function bp_activity_directory_permalink() {
67        echo bp_get_activity_directory_permalink();
68}
69        /**
70         * Return member directory permalink
71         *
72         * @since BuddyPress (1.5)
73         *
74         * @uses traisingslashit()
75         * @uses bp_get_root_domain()
76         * @uses bp_get_activity_root_slug()
77         * @uses apply_filters() To call the 'bp_get_activity_directory_permalink' hook
78         *
79         * @return string Activity directory permalink
80         */
81        function bp_get_activity_directory_permalink() {
82                return apply_filters( 'bp_get_activity_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() ) );
83        }
84
85/**
86 * The main activity template loop
87 *
88 * This is responsible for loading a group of activity items and displaying them
89 *
90 * @since BuddyPress (1.0)
91 */
92class BP_Activity_Template {
93        var $current_activity = -1;
94        var $activity_count;
95        var $total_activity_count;
96        var $activities;
97        var $activity;
98
99        var $in_the_loop;
100
101        var $pag_page;
102        var $pag_num;
103        var $pag_links;
104
105        var $full_name;
106
107        /**
108         * Constructor method
109         *
110         * See definition of $defaults below, as well as $defaults in bp_has_activities(), for
111         * description of $args array
112         *
113         * @param array $args
114         */
115        function __construct( $args ) {
116                global $bp;
117
118                // Backward compatibility with old method of passing arguments
119                if ( !is_array( $args ) || func_num_args() > 1 ) {
120                        _deprecated_argument( __METHOD__, '1.6', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
121
122                        $old_args_keys = array(
123                                0 => 'page',
124                                1 => 'per_page',
125                                2 => 'max',
126                                3 => 'include',
127                                4 => 'sort',
128                                5 => 'filter',
129                                6 => 'search_terms',
130                                7 => 'display_comments',
131                                8 => 'show_hidden',
132                                9 => 'exclude',
133                                10 => 'in',
134                                11 => 'spam',
135                                12 => 'page_arg'
136                        );
137
138                        $func_args = func_get_args();
139                        $args = bp_core_parse_args_array( $old_args_keys, $func_args );
140                }
141
142                $defaults = array(
143                        'page'             => 1,
144                        'per_page'         => 20,
145                        'page_arg'         => 'acpage',
146                        'max'              => false,
147                        'sort'             => false,
148                        'include'          => false,
149                        'exclude'          => false,
150                        'in'               => false,
151                        'filter'           => false,
152                        'search_terms'     => false,
153                        'display_comments' => 'threaded',
154                        'show_hidden'      => false,
155                        'spam'             => 'ham_only',
156                );
157                $r = wp_parse_args( $args, $defaults );
158                extract( $r );
159
160                $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
161                $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
162
163                // Check if blog/forum replies are disabled
164                $this->disable_blogforum_replies = isset( $bp->site_options['bp-disable-blogforum-comments'] ) ? $bp->site_options['bp-disable-blogforum-comments'] : false;
165
166                // Get an array of the logged in user's favorite activities
167                $this->my_favs = maybe_unserialize( bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ) );
168
169                // Fetch specific activity items based on ID's
170                if ( !empty( $include ) )
171                        $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden, 'spam' => $spam ) );
172
173                // Fetch all activity items
174                else
175                        $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'spam' => $spam ) );
176
177                if ( !$max || $max >= (int) $this->activities['total'] )
178                        $this->total_activity_count = (int) $this->activities['total'];
179                else
180                        $this->total_activity_count = (int) $max;
181
182                $this->activities = $this->activities['activities'];
183
184                if ( $max ) {
185                        if ( $max >= count($this->activities) ) {
186                                $this->activity_count = count( $this->activities );
187                        } else {
188                                $this->activity_count = (int) $max;
189                        }
190                } else {
191                        $this->activity_count = count( $this->activities );
192                }
193
194                $this->full_name = bp_get_displayed_user_fullname();
195
196                // Fetch parent content for activity comments so we do not have to query in the loop
197                foreach ( (array) $this->activities as $activity ) {
198                        if ( 'activity_comment' != $activity->type )
199                                continue;
200
201                        $parent_ids[] = $activity->item_id;
202                }
203
204                if ( !empty( $parent_ids ) )
205                        $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) );
206
207                if ( !empty( $activity_parents['activities'] ) ) {
208                        foreach( $activity_parents['activities'] as $parent )
209                                $this->activity_parents[$parent->id] = $parent;
210
211                        unset( $activity_parents );
212                }
213
214                if ( (int) $this->total_activity_count && (int) $this->pag_num ) {
215                        $this->pag_links = paginate_links( array(
216                                'base'      => add_query_arg( $page_arg, '%#%' ),
217                                'format'    => '',
218                                'total'     => ceil( (int) $this->total_activity_count / (int) $this->pag_num ),
219                                'current'   => (int) $this->pag_page,
220                                'prev_text' => _x( '&larr;', 'Activity pagination previous text', 'buddypress' ),
221                                'next_text' => _x( '&rarr;', 'Activity pagination next text', 'buddypress' ),
222                                'mid_size'  => 1
223                        ) );
224                }
225        }
226
227        function has_activities() {
228                if ( $this->activity_count )
229                        return true;
230
231                return false;
232        }
233
234        function next_activity() {
235                $this->current_activity++;
236                $this->activity = $this->activities[$this->current_activity];
237
238                return $this->activity;
239        }
240
241        function rewind_activities() {
242                $this->current_activity = -1;
243                if ( $this->activity_count > 0 ) {
244                        $this->activity = $this->activities[0];
245                }
246        }
247
248        function user_activities() {
249                if ( $this->current_activity + 1 < $this->activity_count ) {
250                        return true;
251                } elseif ( $this->current_activity + 1 == $this->activity_count ) {
252                        do_action('activity_loop_end');
253                        // Do some cleaning up after the loop
254                        $this->rewind_activities();
255                }
256
257                $this->in_the_loop = false;
258                return false;
259        }
260
261        function the_activity() {
262
263                $this->in_the_loop = true;
264                $this->activity    = $this->next_activity();
265
266                if ( is_array( $this->activity ) )
267                        $this->activity = (object) $this->activity;
268
269                if ( $this->current_activity == 0 ) // loop has just started
270                        do_action('activity_loop_start');
271        }
272}
273
274/**
275 * Initializes the activity loop.
276 *
277 * Based on the $args passed, bp_has_activities() populates the $activities_template global.
278 *
279 * @since BuddyPress (1.0)
280 *
281 * @param array $args Arguments for limiting the contents of the activity loop. Can be passed as an associative array or as a URL argument string
282 *
283 * @global object $activities_template {@link BP_Activity_Template}
284 * @global object $bp BuddyPress global settings
285 * @uses groups_is_user_member()
286 * @uses bp_current_action()
287 * @uses bp_is_current_action()
288 * @uses bp_get_activity_slug()
289 * @uses bp_action_variable()
290 * @uses wp_parse_args()
291 * @uses bp_is_active()
292 * @uses friends_get_friend_user_ids()
293 * @uses groups_get_user_groups()
294 * @uses bp_activity_get_user_favorites()
295 * @uses apply_filters() To call the 'bp_has_activities' hook
296 *
297 * @return bool Returns true when activities are found
298 */
299function bp_has_activities( $args = '' ) {
300        global $activities_template, $bp;
301
302        /***
303         * Set the defaults based on the current page. Any of these will be overridden
304         * if arguments are directly passed into the loop. Custom plugins should always
305         * pass their parameters directly to the loop.
306         */
307        $user_id     = false;
308        $include     = false;
309        $exclude     = false;
310        $in          = false;
311        $show_hidden = false;
312        $object      = false;
313        $primary_id  = false;
314
315        // User filtering
316        if ( bp_displayed_user_id() )
317                $user_id = bp_displayed_user_id();
318
319        // Group filtering
320        if ( !empty( $bp->groups->current_group ) ) {
321                $object = $bp->groups->id;
322                $primary_id = $bp->groups->current_group->id;
323
324                if ( ( 'public' != $bp->groups->current_group->status ) && ( groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) || bp_current_user_can( 'bp_moderate' ) ) )
325                        $show_hidden = true;
326        }
327
328        // The default scope should recognize custom slugs
329        if ( array_key_exists( bp_current_action(), (array) $bp->loaded_components ) ) {
330                $scope = $bp->loaded_components[bp_current_action()];
331        }
332        else
333                $scope = bp_current_action();
334
335        // Support for permalinks on single item pages: /groups/my-group/activity/124/
336        if ( bp_is_current_action( bp_get_activity_slug() ) )
337                $include = bp_action_variable( 0 );
338
339        // Note: any params used for filtering can be a single value, or multiple values comma separated.
340        $defaults = array(
341                'display_comments' => 'threaded',   // false for none, stream/threaded - show comments in the stream or threaded under items
342                'include'          => $include,     // pass an activity_id or string of IDs comma-separated
343                'exclude'          => $exclude,     // pass an activity_id or string of IDs comma-separated
344                'in'               => $in,          // comma-separated list or array of activity IDs among which to search
345                'sort'             => 'DESC',       // sort DESC or ASC
346                'page'             => 1,            // which page to load
347                'per_page'         => 20,           // number of items per page
348                'max'              => false,        // max number to return
349                'show_hidden'      => $show_hidden, // Show activity items that are hidden site-wide?
350                'spam'             => 'ham_only',   // Hide spammed items
351
352                'page_arg'         => 'acpage',     // See https://buddypress.trac.wordpress.org/ticket/3679
353
354                // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions)
355                'scope'            => $scope,
356
357                // Filtering
358                'user_id'          => $user_id,     // user_id to filter on
359                'object'           => $object,      // object to filter on e.g. groups, profile, status, friends
360                'action'           => false,        // action to filter on e.g. activity_update, new_forum_post, profile_updated
361                'primary_id'       => $primary_id,  // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
362                'secondary_id'     => false,        // secondary object ID to filter on e.g. a post_id
363
364                // Searching
365                'search_terms'     => false         // specify terms to search on
366        );
367
368        $r = wp_parse_args( $args, $defaults );
369        extract( $r );
370
371        if ( empty( $search_terms ) && ! empty( $_REQUEST['s'] ) )
372                $search_terms = $_REQUEST['s'];
373
374        // If you have passed a "scope" then this will override any filters you have passed.
375        if ( 'just-me' == $scope || 'friends' == $scope || 'groups' == $scope || 'favorites' == $scope || 'mentions' == $scope ) {
376                if ( 'just-me' == $scope )
377                        $display_comments = 'stream';
378
379                // determine which user_id applies
380                if ( empty( $user_id ) )
381                        $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id();
382
383                // are we displaying user specific activity?
384                if ( is_numeric( $user_id ) ) {
385                        $show_hidden = ( $user_id == bp_loggedin_user_id() && $scope != 'friends' ) ? 1 : 0;
386
387                        switch ( $scope ) {
388                                case 'friends':
389                                        if ( bp_is_active( 'friends' ) )
390                                                $friends = friends_get_friend_user_ids( $user_id );
391                                                if ( empty( $friends ) )
392                                                        return false;
393
394                                                $user_id = implode( ',', (array) $friends );
395                                        break;
396                                case 'groups':
397                                        if ( bp_is_active( 'groups' ) ) {
398                                                $groups = groups_get_user_groups( $user_id );
399                                                if ( empty( $groups['groups'] ) )
400                                                        return false;
401
402                                                $object = $bp->groups->id;
403                                                $primary_id = implode( ',', (array) $groups['groups'] );
404
405                                                $user_id = 0;
406                                        }
407                                        break;
408                                case 'favorites':
409                                        $favs = bp_activity_get_user_favorites( $user_id );
410                                        if ( empty( $favs ) )
411                                                return false;
412
413                                        $in          = implode( ',', (array) $favs );
414                                        $display_comments = true;
415                                        $user_id = 0;
416                                        break;
417                                case 'mentions':
418
419                                        // Start search at @ symbol and stop search at closing tag delimiter.
420                                        $search_terms     = '@' . bp_core_get_username( $user_id ) . '<';
421                                        $display_comments = 'stream';
422                                        $user_id = 0;
423                                        break;
424                        }
425                }
426        }
427
428        // Do not exceed the maximum per page
429        if ( !empty( $max ) && ( (int) $per_page > (int) $max ) )
430                $per_page = $max;
431
432        // Support for basic filters in earlier BP versions is disabled by default. To enable, put
433        //   add_filter( 'bp_activity_enable_afilter_support', '__return_true' );
434        // into bp-custom.php or your theme's functions.php
435        if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) )
436                $filter = array( 'object' => $_GET['afilter'] );
437        else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
438                $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
439        else
440                $filter = false;
441
442        // If specific activity items have been requested, override the $hide_spam argument. This prevents backpat errors with AJAX.
443        if ( !empty( $include ) && ( 'ham_only' == $spam ) )
444                $spam = 'all';
445
446        $template_args = array(
447                'page'             => $page,
448                'per_page'         => $per_page,
449                'page_arg'         => $page_arg,
450                'max'              => $max,
451                'sort'             => $sort,
452                'include'          => $include,
453                'exclude'          => $exclude,
454                'in'               => $in,
455                'filter'           => $filter,
456                'search_terms'     => $search_terms,
457                'display_comments' => $display_comments,
458                'show_hidden'      => $show_hidden,
459                'spam'             => $spam
460        );
461
462        $activities_template = new BP_Activity_Template( $template_args );
463
464        return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $template_args );
465}
466
467/**
468 * Determines if there are still activities left in the loop.
469 *
470 * @since BuddyPress (1.0)
471 *
472 * @global object $activities_template {@link BP_Activity_Template}
473 * @uses BP_Activity_Template::user_activities() {@link BP_Activity_Template::user_activities()}
474 *
475 * @return bool Returns true when activities are found
476 */
477function bp_activities() {
478        global $activities_template;
479        return $activities_template->user_activities();
480}
481
482/**
483 * Gets the current activity object in the loop
484 *
485 * @since BuddyPress (1.0)
486 *
487 * @global object $activities_template {@link BP_Activity_Template}
488 * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
489 *
490 * @return object The current activity within the loop
491 */
492function bp_the_activity() {
493        global $activities_template;
494        return $activities_template->the_activity();
495}
496
497/**
498 * Outputs the activity pagination count
499 *
500 * @since BuddyPress (1.0)
501 *
502 * @global object $activities_template {@link BP_Activity_Template}
503 * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
504 */
505function bp_activity_pagination_count() {
506        echo bp_get_activity_pagination_count();
507}
508
509        /**
510         * Returns the activity pagination count
511         *
512         * @since BuddyPress (1.2)
513         *
514         * @global object $activities_template {@link BP_Activity_Template}
515         * @uses bp_core_number_format()
516         *
517         * @return string The pagination text
518         */
519        function bp_get_activity_pagination_count() {
520                global $activities_template;
521
522                $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
523                $from_num  = bp_core_number_format( $start_num );
524                $to_num    = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );
525                $total     = bp_core_number_format( $activities_template->total_activity_count );
526
527                return sprintf( __( 'Viewing item %1$s to %2$s (of %3$s items)', 'buddypress' ), $from_num, $to_num, $total );
528        }
529
530/**
531 * Outputs the activity pagination links
532 *
533 * @since BuddyPress (1.0)
534 *
535 * @uses bp_get_activity_pagination_links()
536 */
537function bp_activity_pagination_links() {
538        echo bp_get_activity_pagination_links();
539}
540
541        /**
542         * Outputs the activity pagination links
543         *
544         * @since BuddyPress (1.0)
545         *
546         * @global object $activities_template {@link BP_Activity_Template}
547         * @uses apply_filters() To call the 'bp_get_activity_pagination_links' hook
548         *
549         * @return string The pagination links
550         */
551        function bp_get_activity_pagination_links() {
552                global $activities_template;
553
554                return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );
555        }
556
557/**
558 * Returns true when there are more activity items to be shown than currently appear
559 *
560 * @since BuddyPress (1.5)
561 *
562 * @global object $activities_template {@link BP_Activity_Template}
563 * @uses apply_filters() To call the 'bp_activity_has_more_items' hook
564 *
565 * @return bool $has_more_items True if more items, false if not
566 */
567function bp_activity_has_more_items() {
568        global $activities_template;
569
570        $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
571        $has_more_items  = (int) $remaining_pages ? true : false;
572
573        return apply_filters( 'bp_activity_has_more_items', $has_more_items );
574}
575
576/**
577 * Outputs the activity count
578 *
579 * @since BuddyPress (1.2)
580 *
581 * @uses bp_get_activity_count()
582 */
583function bp_activity_count() {
584        echo bp_get_activity_count();
585}
586
587        /**
588         * Returns the activity count
589         *
590         * @since BuddyPress (1.2)
591         *
592         * @global object $activities_template {@link BP_Activity_Template}
593         * @uses apply_filters() To call the 'bp_get_activity_count' hook
594         *
595         * @return int The activity count
596         */
597        function bp_get_activity_count() {
598                global $activities_template;
599
600                return apply_filters( 'bp_get_activity_count', (int) $activities_template->activity_count );
601        }
602
603/**
604 * Outputs the number of activities per page
605 *
606 * @since BuddyPress (1.2)
607 *
608 * @uses bp_get_activity_per_page()
609 */
610function bp_activity_per_page() {
611        echo bp_get_activity_per_page();
612}
613
614        /**
615         * Returns the number of activities per page
616         *
617         * @since BuddyPress (1.2)
618         *
619         * @global object $activities_template {@link BP_Activity_Template}
620         * @uses apply_filters() To call the 'bp_get_activity_per_page' hook
621         *
622         * @return int The activities per page
623         */
624        function bp_get_activity_per_page() {
625                global $activities_template;
626
627                return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->pag_num );
628        }
629
630/**
631 * Outputs the activities title
632 *
633 * @since BuddyPress (1.0)
634 *
635 * @uses bp_get_activities_title()
636 */
637function bp_activities_title() {
638        echo bp_get_activities_title();
639}
640
641        /**
642         * Returns the activities title
643         *
644         * @since BuddyPress (1.0)
645         *
646         * @global string $bp_activity_title
647         * @uses apply_filters() To call the 'bp_get_activities_title' hook
648         *
649         * @return int The activities title
650         */
651        function bp_get_activities_title() {
652                global $bp_activity_title;
653
654                return apply_filters( 'bp_get_activities_title', $bp_activity_title );
655        }
656
657/**
658 * {@internal Missing Description}
659 *
660 * @since BuddyPress (1.0)
661 *
662 * @uses bp_get_activities_no_activity()
663 */
664function bp_activities_no_activity() {
665        echo bp_get_activities_no_activity();
666}
667
668        /**
669         * {@internal Missing Description}
670         *
671         * @since BuddyPress (1.0)
672         *
673         * @global string $bp_activity_no_activity
674         * @uses apply_filters() To call the 'bp_get_activities_no_activity' hook
675         *
676         * @return unknown_type
677         */
678        function bp_get_activities_no_activity() {
679                global $bp_activity_no_activity;
680
681                return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
682        }
683
684/**
685 * Outputs the activity id
686 *
687 * @since BuddyPress (1.2)
688 *
689 * @uses bp_get_activity_id()
690 */
691function bp_activity_id() {
692        echo bp_get_activity_id();
693}
694
695        /**
696         * Returns the activity id
697         *
698         * @since BuddyPress (1.2)
699         *
700         * @global object $activities_template {@link BP_Activity_Template}
701         * @uses apply_filters() To call the 'bp_get_activity_id' hook
702         *
703         * @return int The activity id
704         */
705        function bp_get_activity_id() {
706                global $activities_template;
707                return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
708        }
709
710/**
711 * Outputs the activity item id
712 *
713 * @since BuddyPress (1.2)
714 *
715 * @uses bp_get_activity_item_id()
716 */
717function bp_activity_item_id() {
718        echo bp_get_activity_item_id();
719}
720
721        /**
722         * Returns the activity item id
723         *
724         * @since BuddyPress (1.2)
725         *
726         * @global object $activities_template {@link BP_Activity_Template}
727         * @uses apply_filters() To call the 'bp_get_activity_item_id' hook
728         *
729         * @return int The activity item id
730         */
731        function bp_get_activity_item_id() {
732                global $activities_template;
733                return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
734        }
735
736/**
737 * Outputs the activity secondary item id
738 *
739 * @since BuddyPress (1.2)
740 *
741 * @uses bp_get_activity_secondary_item_id()
742 */
743function bp_activity_secondary_item_id() {
744        echo bp_get_activity_secondary_item_id();
745}
746
747        /**
748         * Returns the activity secondary item id
749         *
750         * @since BuddyPress (1.2)
751         *
752         * @global object $activities_template {@link BP_Activity_Template}
753         * @uses apply_filters() To call the 'bp_get_activity_secondary_item_id' hook
754         *
755         * @return int The activity secondary item id
756         */
757        function bp_get_activity_secondary_item_id() {
758                global $activities_template;
759                return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
760        }
761
762/**
763 * Outputs the date the activity was recorded
764 *
765 * @since BuddyPress (1.2)
766 *
767 * @uses bp_get_activity_date_recorded()
768 */
769function bp_activity_date_recorded() {
770        echo bp_get_activity_date_recorded();
771}
772
773        /**
774         * Returns the date the activity was recorded
775         *
776         * @since BuddyPress (1.2)
777         *
778         * @global object $activities_template {@link BP_Activity_Template}
779         * @uses apply_filters() To call the 'bp_get_activity_date_recorded' hook
780         *
781         * @return string The date the activity was recorded
782         */
783        function bp_get_activity_date_recorded() {
784                global $activities_template;
785                return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
786        }
787
788/**
789 * Outputs the activity object name
790 *
791 * @since BuddyPress (1.2)
792 *
793 * @uses bp_get_activity_object_name()
794 */
795function bp_activity_object_name() {
796        echo bp_get_activity_object_name();
797}
798
799        /**
800         * Returns the activity object name
801         *
802         * @since BuddyPress (1.2)
803         *
804         * @global object $activities_template {@link BP_Activity_Template}
805         * @uses apply_filters() To call the 'bp_get_activity_object_name' hook
806         *
807         * @return string The activity object name
808         */
809        function bp_get_activity_object_name() {
810                global $activities_template;
811                return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
812        }
813
814/**
815 * Outputs the activity type
816 *
817 * @since BuddyPress (1.2)
818 *
819 * @uses bp_get_activity_type()
820 */
821function bp_activity_type() {
822        echo bp_get_activity_type();
823}
824
825        /**
826         * Returns the activity type
827         *
828         * @since BuddyPress (1.2)
829         *
830         * @global object $activities_template {@link BP_Activity_Template}
831         * @uses apply_filters() To call the 'bp_get_activity_type' hook
832         *
833         * @return string The activity type
834         */
835        function bp_get_activity_type() {
836                global $activities_template;
837                return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
838        }
839
840        /**
841         * Outputs the activity action name
842         *
843         * Just a wrapper for bp_activity_type()
844         *
845         * @since BuddyPress (1.2)
846         * @deprecated BuddyPress (1.5)
847         *
848         * @todo Properly deprecate in favor of bp_activity_type() and
849         *               remove redundant echo
850         *
851         * @uses bp_activity_type()
852         */
853        function bp_activity_action_name() { echo bp_activity_type(); }
854
855        /**
856         * Returns the activity type
857         *
858         * Just a wrapper for bp_get_activity_type()
859         *
860         * @since BuddyPress (1.2)
861         * @deprecated BuddyPress (1.5)
862         *
863         * @todo Properly deprecate in favor of bp_get_activity_type()
864         *
865         * @uses bp_get_activity_type()
866         *
867         * @return string The activity type
868         */
869        function bp_get_activity_action_name() { return bp_get_activity_type(); }
870
871/**
872 * Outputs the activity user id
873 *
874 * @since BuddyPress (1.1)
875 *
876 * @uses bp_get_activity_user_id()
877 */
878function bp_activity_user_id() {
879        echo bp_get_activity_user_id();
880}
881
882        /**
883         * Returns the activity user id
884         *
885         * @since BuddyPress (1.1)
886         *
887         * @global object $activities_template {@link BP_Activity_Template}
888         * @uses apply_filters() To call the 'bp_get_activity_user_id' hook
889         *
890         * @return int The activity user id
891         */
892        function bp_get_activity_user_id() {
893                global $activities_template;
894                return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
895        }
896
897/**
898 * Outputs the activity user link
899 *
900 * @since BuddyPress (1.2)
901 *
902 * @uses bp_get_activity_user_link()
903 */
904function bp_activity_user_link() {
905        echo bp_get_activity_user_link();
906}
907
908        /**
909         * Returns the activity user link
910         *
911         * @since BuddyPress (1.2)
912         *
913         * @global object $activities_template {@link BP_Activity_Template}
914         * @uses bp_core_get_user_domain()
915         * @uses apply_filters() To call the 'bp_get_activity_user_link' hook
916         *
917         * @return string $link The activity user link
918         */
919        function bp_get_activity_user_link() {
920                global $activities_template;
921
922                if ( empty( $activities_template->activity->user_id ) )
923                        $link = $activities_template->activity->primary_link;
924                else
925                        $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login );
926
927                return apply_filters( 'bp_get_activity_user_link', $link );
928        }
929
930/**
931 * Output the avatar of the user that performed the action
932 *
933 * @since BuddyPress (1.1)
934 *
935 * @param array $args
936 *
937 * @uses bp_get_activity_avatar()
938 */
939function bp_activity_avatar( $args = '' ) {
940        echo bp_get_activity_avatar( $args );
941}
942        /**
943         * Return the avatar of the user that performed the action
944         *
945         * @since BuddyPress (1.1)
946         *
947         * @param array $args optional
948         *
949         * @global object $activities_template {@link BP_Activity_Template}
950         * @global object $bp BuddyPress global settings
951         * @uses bp_is_single_activity()
952         * @uses wp_parse_args()
953         * @uses apply_filters() To call the 'bp_get_activity_avatar_object_' . $current_activity_item->component hook
954         * @uses apply_filters() To call the 'bp_get_activity_avatar_item_id' hook
955         * @uses bp_core_fetch_avatar()
956         * @uses apply_filters() To call the 'bp_get_activity_avatar' hook
957         *
958         * @return string User avatar
959         */
960        function bp_get_activity_avatar( $args = '' ) {
961                global $activities_template;
962
963                $bp = buddypress();
964
965                // On activity permalink pages, default to the full-size avatar
966                $type_default = bp_is_single_activity() ? 'full' : 'thumb';
967
968                // Within the activity comment loop, the current activity should be set
969                // to current_comment. Otherwise, just use activity.
970                $current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity;
971
972                // Activity user display name
973                $dn_default  = isset( $current_activity_item->display_name ) ? $current_activity_item->display_name : '';
974
975                // Prepend some descriptive text to alt
976                $alt_default = !empty( $dn_default ) ? sprintf( __( 'Profile picture of %s', 'buddypress' ), $dn_default ) : __( 'Profile picture', 'buddypress' );
977
978                $defaults = array(
979                        'alt'     => $alt_default,
980                        'class'   => 'avatar',
981                        'email'   => false,
982                        'type'    => $type_default,
983                        'user_id' => false
984                );
985
986                $r = wp_parse_args( $args, $defaults );
987                extract( $r, EXTR_SKIP );
988
989                if ( !isset( $height ) && !isset( $width ) ) {
990
991                        // Backpat
992                        if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) {
993                                $height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height;
994                        } else {
995                                $height = 20;
996                        }
997
998                        // Backpat
999                        if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) {
1000                                $width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width;
1001                        } else {
1002                                $width = 20;
1003                        }
1004                }
1005
1006                // Primary activity avatar is always a user, but can be modified via a filter
1007                $object  = apply_filters( 'bp_get_activity_avatar_object_' . $current_activity_item->component, 'user' );
1008                $item_id = !empty( $user_id ) ? $user_id : $current_activity_item->user_id;
1009                $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $item_id );
1010
1011                // If this is a user object pass the users' email address for Gravatar so we don't have to refetch it.
1012                if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) )
1013                        $email = $current_activity_item->user_email;
1014
1015                return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array(
1016                        'item_id' => $item_id,
1017                        'object'  => $object,
1018                        'type'    => $type,
1019                        'alt'     => $alt,
1020                        'class'   => $class,
1021                        'width'   => $width,
1022                        'height'  => $height,
1023                        'email'   => $email
1024                ) ) );
1025        }
1026
1027/**
1028 * Output the avatar of the object that action was performed on
1029 *
1030 * @since BuddyPress (1.2)
1031 *
1032 * @param array $args optional
1033 *
1034 * @uses bp_get_activity_secondary_avatar()
1035 */
1036function bp_activity_secondary_avatar( $args = '' ) {
1037        echo bp_get_activity_secondary_avatar( $args );
1038}
1039
1040        /**
1041         * Return the avatar of the object that action was performed on
1042         *
1043         * @since BuddyPress (1.2)
1044         *
1045         * @param array $args optional
1046         *
1047         * @global object $activities_template {@link BP_Activity_Template}
1048         * @uses wp_parse_args()
1049         * @uses get_blog_option()
1050         * @uses apply_filters() To call the 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component hook
1051         * @uses apply_filters() To call the 'bp_get_activity_secondary_avatar_item_id' hook
1052         * @uses bp_core_fetch_avatar()
1053         * @uses apply_filters() To call the 'bp_get_activity_secondary_avatar' hook
1054         *
1055         * @return string The secondary avatar
1056         */
1057        function bp_get_activity_secondary_avatar( $args = '' ) {
1058                global $activities_template;
1059
1060                $r = wp_parse_args( $args, array(
1061                        'alt'        => '',
1062                        'type'       => 'thumb',
1063                        'width'      => 20,
1064                        'height'     => 20,
1065                        'class'      => 'avatar',
1066                        'link_class' => '',
1067                        'linked'     => true,
1068                        'email'      => false
1069                ) );
1070                extract( $r, EXTR_SKIP );
1071
1072                // Set item_id and object (default to user)
1073                switch ( $activities_template->activity->component ) {
1074                        case 'groups' :
1075                                $object  = 'group';
1076                                $item_id = $activities_template->activity->item_id;
1077
1078                                // Only if groups is active
1079                                if ( bp_is_active( 'groups' ) ) {
1080                                        $group = groups_get_group( array( 'group_id' => $item_id ) );
1081                                        $link  = bp_get_group_permalink( $group );
1082                                        $name  = $group->name;
1083                                } else {
1084                                        $name = '';
1085                                }
1086
1087                                if ( empty( $alt ) ) {
1088                                        $alt = __( 'Group logo', 'buddypress' );
1089
1090                                        if ( ! empty( $name ) ) {
1091                                                $alt = sprintf( __( 'Group logo of %s', 'buddypress' ), $name );
1092                                        }
1093                                }
1094
1095                                break;
1096                        case 'blogs' :
1097                                $object  = 'blog';
1098                                $item_id = $activities_template->activity->item_id;
1099                                $link    = home_url();
1100
1101                                if ( empty( $alt ) ) {
1102                                        $alt = sprintf( __( 'Profile picture of the author of the site %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) );
1103                                }
1104
1105                                break;
1106                        case 'friends' :
1107                                $object  = 'user';
1108                                $item_id = $activities_template->activity->secondary_item_id;
1109                                $link    = bp_core_get_userlink( $item_id, false, true );
1110
1111                                if ( empty( $alt ) ) {
1112                                        $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $activities_template->activity->secondary_item_id ) );
1113                                }
1114
1115                                break;
1116                        default :
1117                                $object  = 'user';
1118                                $item_id = $activities_template->activity->user_id;
1119                                $email   = $activities_template->activity->user_email;
1120                                $link    = bp_core_get_userlink( $item_id, false, true );
1121
1122                                if ( empty( $alt ) ) {
1123                                        $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), $activities_template->activity->display_name );
1124                                }
1125
1126                                break;
1127                }
1128
1129                // Allow object, item_id, and link to be filtered
1130                $object  = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );
1131                $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );
1132
1133                // If we have no item_id or object, there is no avatar to display
1134                if ( empty( $item_id ) || empty( $object ) ) {
1135                        return false;
1136                }
1137
1138                // Get the avatar
1139                $avatar = bp_core_fetch_avatar( array(
1140                        'item_id' => $item_id,
1141                        'object'  => $object,
1142                        'type'    => $type,
1143                        'alt'     => $alt,
1144                        'class'   => $class,
1145                        'width'   => $width,
1146                        'height'  => $height,
1147                        'email'   => $email
1148                ) );
1149
1150                if ( !empty( $linked ) ) {
1151                        $link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template->activity->component );
1152
1153                        return sprintf( '<a href="%s" class="%s">%s</a>',
1154                                $link,
1155                                $link_class,
1156                                apply_filters( 'bp_get_activity_secondary_avatar', $avatar )
1157                        );
1158                }
1159
1160                // else
1161                return apply_filters( 'bp_get_activity_secondary_avatar', $avatar );
1162        }
1163
1164/**
1165 * Output the activity action
1166 *
1167 * @since BuddyPress (1.2)
1168 *
1169 * @param array $args See bp_get_activity_action()
1170 * @uses bp_get_activity_action()
1171 */
1172function bp_activity_action( $args = array() ) {
1173        echo bp_get_activity_action( $args );
1174}
1175
1176        /**
1177         * Return the activity action
1178         *
1179         * @since BuddyPress (1.2)
1180         *
1181         * @global object $activities_template {@link BP_Activity_Template}
1182         * @param array $args Only parameter is "no_timestamp". If true, timestamp is shown in output.
1183         * @uses apply_filters_ref_array() To call the 'bp_get_activity_action_pre_meta' hook
1184         * @uses bp_insert_activity_meta()
1185         * @uses apply_filters_ref_array() To call the 'bp_get_activity_action' hook
1186         *
1187         * @return string The activity action
1188         */
1189        function bp_get_activity_action( $args = array() ) {
1190                global $activities_template;
1191
1192                $defaults = array(
1193                        'no_timestamp' => false,
1194                );
1195
1196                $args = wp_parse_args( $args, $defaults );
1197                extract( $args, EXTR_SKIP );
1198
1199                $action = $activities_template->activity->action;
1200                $action = apply_filters_ref_array( 'bp_get_activity_action_pre_meta', array( $action, &$activities_template->activity, $args ) );
1201
1202                if ( ! empty( $action ) && ! $no_timestamp )
1203                        $action = bp_insert_activity_meta( $action );
1204
1205                return apply_filters_ref_array( 'bp_get_activity_action', array( $action, &$activities_template->activity, $args ) );
1206        }
1207
1208/**
1209 * Output the activity content body
1210 *
1211 * @since BuddyPress (1.2)
1212 *
1213 * @uses bp_get_activity_content_body()
1214 */
1215function bp_activity_content_body() {
1216        echo bp_get_activity_content_body();
1217}
1218
1219        /**
1220         * Return the activity content body
1221         *
1222         * @since BuddyPress (1.2)
1223         *
1224         * @global object $activities_template {@link BP_Activity_Template}
1225         * @uses bp_insert_activity_meta()
1226         * @uses apply_filters_ref_array() To call the 'bp_get_activity_content_body' hook
1227         *
1228         * @return string The activity content body
1229         */
1230        function bp_get_activity_content_body() {
1231                global $activities_template;
1232
1233                // Backwards compatibility if action is not being used
1234                if ( empty( $activities_template->activity->action ) && !empty( $activities_template->activity->content ) )
1235                        $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );
1236
1237                return apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) );
1238        }
1239
1240/**
1241 * Does the activity have content?
1242 *
1243 * @since BuddyPress (1.2)
1244 *
1245 * @global object $activities_template {@link BP_Activity_Template}
1246 *
1247 * @return bool True if activity has content, false otherwise
1248 */
1249function bp_activity_has_content() {
1250        global $activities_template;
1251
1252        if ( !empty( $activities_template->activity->content ) )
1253                return true;
1254
1255        return false;
1256}
1257
1258/**
1259 * Output the activity content
1260 *
1261 * @since BuddyPress (1.0)
1262 * @deprecated BuddyPress (1.5)
1263 *
1264 * @todo properly deprecate this function
1265 *
1266 * @uses bp_get_activity_content()
1267 */
1268function bp_activity_content() {
1269        echo bp_get_activity_content();
1270}
1271
1272        /**
1273         * Return the activity content
1274         *
1275         * @since BuddyPress (1.0)
1276         * @deprecated BuddyPress (1.5)
1277         *
1278         * @todo properly deprecate this function
1279         *
1280         * @uses bp_get_activity_action()
1281         * @uses bp_get_activity_content_body()
1282         * @uses apply_filters() To call the 'bp_get_activity_content' hook
1283         *
1284         * @return string The activity content
1285         */
1286        function bp_get_activity_content() {
1287                /**
1288                 * If you want to filter activity update content, please use
1289                 * the filter 'bp_get_activity_content_body'
1290                 *
1291                 * This function is mainly for backwards comptibility.
1292                 */
1293
1294                $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body();
1295                return apply_filters( 'bp_get_activity_content', $content );
1296        }
1297
1298/**
1299 * Insert activity meta
1300 *
1301 * @since BuddyPress (1.2)
1302 *
1303 * @param string $content
1304 *
1305 * @global object $activities_template {@link BP_Activity_Template}
1306 * @uses bp_core_time_since()
1307 * @uses apply_filters_ref_array() To call the 'bp_activity_time_since' hook
1308 * @uses bp_is_single_activity()
1309 * @uses bp_activity_get_permalink()
1310 * @uses esc_attr__()
1311 * @uses apply_filters_ref_array() To call the 'bp_activity_permalink' hook
1312 * @uses apply_filters() To call the 'bp_insert_activity_meta' hook
1313 *
1314 * @return string The activity content
1315 */
1316function bp_insert_activity_meta( $content ) {
1317        global $activities_template;
1318
1319        // Strip any legacy time since placeholders from BP 1.0-1.1
1320        $content = str_replace( '<span class="time-since">%s</span>', '', $content );
1321
1322        // Insert the time since.
1323        $time_since = apply_filters_ref_array( 'bp_activity_time_since', array( '<span class="time-since">' . bp_core_time_since( $activities_template->activity->date_recorded ) . '</span>', &$activities_template->activity ) );
1324
1325        // Insert the permalink
1326        if ( !bp_is_single_activity() )
1327                $content = apply_filters_ref_array( 'bp_activity_permalink', array( sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ), esc_attr__( 'View Discussion', 'buddypress' ), $time_since ), &$activities_template->activity ) );
1328        else
1329                $content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH );
1330
1331        return apply_filters( 'bp_insert_activity_meta', $content );
1332}
1333
1334/**
1335 * Determine if the current user can delete an activity item
1336 *
1337 * @since BuddyPress (1.2)
1338 *
1339 * @param object $activity Optional
1340 *
1341 * @global object $activities_template {@link BP_Activity_Template}
1342 * @uses apply_filters() To call the 'bp_activity_user_can_delete' hook
1343 *
1344 * @return bool True if can delete, false otherwise
1345 */
1346function bp_activity_user_can_delete( $activity = false ) {
1347        global $activities_template;
1348
1349        if ( !$activity )
1350                $activity = $activities_template->activity;
1351
1352        if ( isset( $activity->current_comment ) )
1353                $activity = $activity->current_comment;
1354
1355        $can_delete = false;
1356
1357        if ( bp_current_user_can( 'bp_moderate' ) )
1358                $can_delete = true;
1359
1360        if ( is_user_logged_in() && $activity->user_id == bp_loggedin_user_id() )
1361                $can_delete = true;
1362
1363        if ( bp_is_item_admin() && bp_is_single_item() )
1364                $can_delete = true;
1365
1366        return apply_filters( 'bp_activity_user_can_delete', $can_delete );
1367}
1368
1369/**
1370 * Output the activity parent content
1371 *
1372 * @since BuddyPress (1.2)
1373 *
1374 * @param array $args Optional
1375 *
1376 * @uses bp_get_activity_parent_content()
1377 */
1378function bp_activity_parent_content( $args = '' ) {
1379        echo bp_get_activity_parent_content($args);
1380}
1381
1382        /**
1383         * Return the activity content
1384         *
1385         * @since BuddyPress (1.2)
1386         *
1387         * @param array $args Optional
1388         *
1389         * @global object $activities_template {@link BP_Activity_Template}
1390         * @uses wp_parse_args()
1391         * @uses apply_filters() To call the 'bp_get_activity_parent_content' hook
1392         *
1393         * @return mixed False on failure, otherwise the activity parent content
1394         */
1395        function bp_get_activity_parent_content( $args = '' ) {
1396                global $activities_template;
1397
1398                $defaults = array(
1399                        'hide_user' => false
1400                );
1401
1402                $r = wp_parse_args( $args, $defaults );
1403                extract( $r, EXTR_SKIP );
1404
1405                // Get the ID of the parent activity content
1406                if ( !$parent_id = $activities_template->activity->item_id )
1407                        return false;
1408
1409                // Bail if no parent content
1410                if ( empty( $activities_template->activity_parents[$parent_id] ) )
1411                        return false;
1412
1413                // Bail if no action
1414                if ( empty( $activities_template->activity_parents[$parent_id]->action ) )
1415                        return false;
1416
1417                // Content always includes action
1418                $content = $activities_template->activity_parents[$parent_id]->action;
1419
1420                // Maybe append activity content, if it exists
1421                if ( ! empty( $activities_template->activity_parents[$parent_id]->content ) )
1422                        $content .= ' ' . $activities_template->activity_parents[$parent_id]->content;
1423
1424                // Remove the time since content for backwards compatibility
1425                $content = str_replace( '<span class="time-since">%s</span>', '', $content );
1426
1427                // Remove images
1428                $content = preg_replace( '/<img[^>]*>/Ui', '', $content );
1429
1430                return apply_filters( 'bp_get_activity_parent_content', $content );
1431        }
1432
1433/**
1434 * Output the parent activity's user ID
1435 *
1436 * @since BuddyPress (1.7)
1437 */
1438function bp_activity_parent_user_id() {
1439        echo bp_get_activity_parent_user_id();
1440}
1441
1442        /**
1443         * Return the parent activity's user ID
1444         *
1445         * @global BP_Activity_Template $activities_template
1446         * @return bool|int False if parent activity can't be found, otherwise returns the parent activity's user ID
1447         * @since BuddyPress (1.7)
1448         */
1449        function bp_get_activity_parent_user_id() {
1450                global $activities_template;
1451
1452                // Bail if no activity on no item ID
1453                if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) )
1454                        return false;
1455
1456                // Get the ID of the parent activity content
1457                if ( !$parent_id = $activities_template->activity->item_id )
1458                        return false;
1459
1460                // Bail if no parent item
1461                if ( empty( $activities_template->activity_parents[$parent_id] ) )
1462                        return false;
1463
1464                // Bail if no parent user ID
1465                if ( empty( $activities_template->activity_parents[$parent_id]->user_id ) )
1466                        return false;
1467
1468                $retval = $activities_template->activity_parents[$parent_id]->user_id;
1469
1470                return (int) apply_filters( 'bp_get_activity_parent_user_id', $retval );
1471        }
1472
1473/**
1474 * Output whether or not the current activity is in a current user's favorites
1475 *
1476 * @since BuddyPress (1.2)
1477 *
1478 * @uses bp_get_activity_is_favorite()
1479 */
1480function bp_activity_is_favorite() {
1481        echo bp_get_activity_is_favorite();
1482}
1483
1484        /**
1485         * Return whether or not the current activity is in a current user's favorites
1486         *
1487         * @since BuddyPress (1.2)
1488         *
1489         * @global object $activities_template {@link BP_Activity_Template}
1490         * @uses apply_filters() To call the 'bp_get_activity_is_favorite' hook
1491         *
1492         * @return bool True if user favorite, false otherwise
1493         */
1494        function bp_get_activity_is_favorite() {
1495                global $activities_template;
1496
1497                return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) );
1498        }
1499
1500/**
1501 * Echoes the comment markup for an activity item
1502 *
1503 * @since BuddyPress (1.2)
1504 *
1505 * @todo deprecate $args param
1506 *
1507 * @param string $args Unused. Appears to be left over from an earlier implementation.
1508 */
1509function bp_activity_comments( $args = '' ) {
1510        echo bp_activity_get_comments( $args );
1511}
1512
1513        /**
1514         * Gets the comment markup for an activity item
1515         *
1516         * @since BuddyPress (1.2)
1517         *
1518         * @todo deprecate $args param
1519         *
1520         * @todo Given that checks for children already happen in bp_activity_recurse_comments(),
1521         *    this function can probably be streamlined or removed.
1522         *
1523         * @param string $args Unused. Appears to be left over from an earlier implementation.
1524         *
1525         * @global object $activities_template {@link BP_Activity_Template}
1526         * @uses bp_activity_recurse_comments()
1527         */
1528        function bp_activity_get_comments( $args = '' ) {
1529                global $activities_template;
1530
1531                if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
1532                        return false;
1533
1534                bp_activity_recurse_comments( $activities_template->activity );
1535        }
1536
1537                /**
1538                 * Loops through a level of activity comments and loads the template for each
1539                 *
1540                 * Note: The recursion itself used to happen entirely in this function. Now it is
1541                 * split between here and the comment.php template.
1542                 *
1543                 * @since BuddyPress (1.2)
1544                 *
1545                 * @todo remove $counter global
1546                 *
1547                 * @param object $comment The activity object currently being recursed
1548                 *
1549                 * @global object $activities_template {@link BP_Activity_Template}
1550                 * @uses locate_template()
1551                 */
1552                function bp_activity_recurse_comments( $comment ) {
1553                        global $activities_template;
1554
1555                        if ( empty( $comment ) )
1556                                return false;
1557
1558                        if ( empty( $comment->children ) )
1559                                return false;
1560
1561                        echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>');
1562                        foreach ( (array) $comment->children as $comment_child ) {
1563                                // Put the comment into the global so it's available to filters
1564                                $activities_template->activity->current_comment = $comment_child;
1565
1566                                $template = bp_locate_template( 'activity/comment.php', false, false );
1567
1568                                // Backward compatibility. In older versions of BP, the markup was
1569                                // generated in the PHP instead of a template. This ensures that
1570                                // older themes (which are not children of bp-default and won't
1571                                // have the new template) will still work.
1572                                if ( !$template ) {
1573                                        $template = BP_PLUGIN_DIR . '/bp-themes/bp-default/activity/comment.php';
1574                                }
1575
1576                                load_template( $template, false );
1577
1578                                unset( $activities_template->activity->current_comment );
1579                        }
1580                        echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>');
1581                }
1582
1583/**
1584 * Utility function that returns the comment currently being recursed
1585 *
1586 * @since BuddyPress (1.5)
1587 *
1588 * @global object $activities_template {@link BP_Activity_Template}
1589 * @uses apply_filters() To call the 'bp_activity_current_comment' hook
1590 *
1591 * @return object|bool $current_comment The activity comment currently being displayed. False on failure
1592 */
1593function bp_activity_current_comment() {
1594        global $activities_template;
1595
1596        $current_comment = !empty( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : false;
1597
1598        return apply_filters( 'bp_activity_current_comment', $current_comment );
1599}
1600
1601
1602/**
1603 * Echoes the id of the activity comment currently being displayed
1604 *
1605 * @since BuddyPress (1.5)
1606 *
1607 * @uses bp_get_activity_comment_id()
1608 */
1609function bp_activity_comment_id() {
1610        echo bp_get_activity_comment_id();
1611}
1612
1613        /**
1614         * Gets the id of the activity comment currently being displayed
1615         *
1616         * @since BuddyPress (1.5)
1617         *
1618         * @global object $activities_template {@link BP_Activity_Template}
1619         * @uses apply_filters() To call the 'bp_activity_comment_id' hook
1620         *
1621         * @return int $comment_id The id of the activity comment currently being displayed
1622         */
1623        function bp_get_activity_comment_id() {
1624                global $activities_template;
1625
1626                $comment_id = isset( $activities_template->activity->current_comment->id ) ? $activities_template->activity->current_comment->id : false;
1627
1628                return apply_filters( 'bp_activity_comment_id', $comment_id );
1629        }
1630
1631/**
1632 * Echoes the user_id of the author of the activity comment currently being displayed
1633 *
1634 * @since BuddyPress (1.5)
1635 *
1636 * @uses bp_get_activity_comment_user_id()
1637 */
1638function bp_activity_comment_user_id() {
1639        echo bp_get_activity_comment_user_id();
1640}
1641
1642        /**
1643         * Gets the user_id of the author of the activity comment currently being displayed
1644         *
1645         * @since BuddyPress (1.5)
1646         *
1647         * @global object $activities_template {@link BP_Activity_Template}
1648         * @uses apply_filters() To call the 'bp_activity_comment_user_id' hook
1649         *
1650         * @return int|bool $user_id The user_id of the author of the displayed activity comment. False on failure
1651         */
1652        function bp_get_activity_comment_user_id() {
1653                global $activities_template;
1654
1655                $user_id = isset( $activities_template->activity->current_comment->user_id ) ? $activities_template->activity->current_comment->user_id : false;
1656
1657                return apply_filters( 'bp_activity_comment_user_id', $user_id );
1658        }
1659
1660/**
1661 * Echoes the author link for the activity comment currently being displayed
1662 *
1663 * @since BuddyPress (1.5)
1664 *
1665 * @uses bp_get_activity_comment_user_link()
1666 */
1667function bp_activity_comment_user_link() {
1668        echo bp_get_activity_comment_user_link();
1669}
1670
1671        /**
1672         * Gets the author link for the activity comment currently being displayed
1673         *
1674         * @since BuddyPress (1.5)
1675         *
1676         * @uses bp_core_get_user_domain()
1677         * @uses bp_get_activity_comment_user_id()
1678         * @uses apply_filters() To call the 'bp_activity_comment_user_link' hook
1679         *
1680         * @return string $user_link The URL of the activity comment author's profile
1681         */
1682        function bp_get_activity_comment_user_link() {
1683                $user_link = bp_core_get_user_domain( bp_get_activity_comment_user_id() );
1684
1685                return apply_filters( 'bp_activity_comment_user_link', $user_link );
1686        }
1687
1688/**
1689 * Echoes the author name for the activity comment currently being displayed
1690 *
1691 * @since BuddyPress (1.5)
1692 *
1693 * @uses bp_get_activity_comment_name()
1694 */
1695function bp_activity_comment_name() {
1696        echo bp_get_activity_comment_name();
1697}
1698
1699        /**
1700         * Gets the author name for the activity comment currently being displayed
1701         *
1702         * The use of the bp_acomment_name filter is deprecated. Please use bp_activity_comment_name
1703         *
1704         * @since BuddyPress (1.5)
1705         *
1706         * @global object $activities_template {@link BP_Activity_Template}
1707         * @uses apply_filters() To call the 'bp_acomment_name' hook
1708         * @uses apply_filters() To call the 'bp_activity_comment_name' hook
1709         *
1710         * @return string $name The full name of the activity comment author
1711         */
1712        function bp_get_activity_comment_name() {
1713                global $activities_template;
1714
1715                if ( isset( $activities_template->activity->current_comment->user_fullname ) )
1716                        $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment );  // backward compatibility
1717                else
1718                        $name = $activities_template->activity->current_comment->display_name;
1719
1720                return apply_filters( 'bp_activity_comment_name', $name );
1721        }
1722
1723/**
1724 * Echoes the date_recorded of the activity comment currently being displayed
1725 *
1726 * @since BuddyPress (1.5)
1727 *
1728 * @uses bp_get_activity_comment_date_recorded()
1729 */
1730function bp_activity_comment_date_recorded() {
1731        echo bp_get_activity_comment_date_recorded();
1732}
1733
1734        /**
1735         * Gets the date_recorded for the activity comment currently being displayed
1736         *
1737         * @since BuddyPress (1.5)
1738         *
1739         * @global object $activities_template {@link BP_Activity_Template}
1740         * @uses bp_core_time_since()
1741         * @uses apply_filters() To call the 'bp_activity_comment_date_recorded' hook
1742         *
1743         * @return string|bool $date_recorded Time since the activity was recorded, of the form "%s ago". False on failure
1744         */
1745        function bp_get_activity_comment_date_recorded() {
1746                global $activities_template;
1747
1748                if ( empty( $activities_template->activity->current_comment->date_recorded ) )
1749                        return false;
1750
1751                $date_recorded = bp_core_time_since( $activities_template->activity->current_comment->date_recorded );
1752
1753                return apply_filters( 'bp_activity_comment_date_recorded', $date_recorded );
1754        }
1755
1756/**
1757 * Echoes the 'delete' URL for the activity comment currently being displayed
1758 *
1759 * @since BuddyPress (1.5)
1760 *
1761 * @uses bp_get_activity_comment_delete_link()
1762 */
1763function bp_activity_comment_delete_link() {
1764        echo bp_get_activity_comment_delete_link();
1765}
1766
1767        /**
1768         * Gets the 'delete' URL for the activity comment currently being displayed
1769         *
1770         * @since BuddyPress (1.5)
1771         *
1772         * @uses wp_nonce_url()
1773         * @uses bp_get_root_domain()
1774         * @uses bp_get_activity_slug()
1775         * @uses bp_get_activity_comment_id()
1776         * @uses apply_filters() To call the 'bp_activity_comment_delete_link' hook
1777         *
1778         * @return string $link The nonced URL for deleting the current activity comment
1779         */
1780        function bp_get_activity_comment_delete_link() {
1781                $link = wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/delete/' . bp_get_activity_comment_id() . '?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' );
1782
1783                return apply_filters( 'bp_activity_comment_delete_link', $link );
1784        }
1785
1786/**
1787 * Echoes the content of the activity comment currently being displayed
1788 *
1789 * @since BuddyPress (1.5)
1790 *
1791 * @uses bp_get_activity_comment_content()
1792 */
1793function bp_activity_comment_content() {
1794        echo bp_get_activity_comment_content();
1795}
1796
1797        /**
1798         * Gets the content of the activity comment currently being displayed
1799         *
1800         * The content is run through two filters. bp_get_activity_content will apply all filters
1801         * applied to activity items in general. Use bp_activity_comment_content to modify the
1802         * content of activity comments only.
1803         *
1804         * @since BuddyPress (1.5)
1805         *
1806         * @global object $activities_template {@link BP_Activity_Template}
1807         * @uses apply_filters() To call the 'bp_get_activity_content' hook
1808         * @uses apply_filters() To call the 'bp_activity_comment_content' hook
1809         *
1810         * @return string $content The content of the current activity comment
1811         */
1812        function bp_get_activity_comment_content() {
1813                global $activities_template;
1814
1815                $content = apply_filters( 'bp_get_activity_content', $activities_template->activity->current_comment->content );
1816
1817                return apply_filters( 'bp_activity_comment_content', $content );
1818        }
1819
1820/**
1821 * Echoes the activity comment count
1822 *
1823 * @since BuddyPress (1.2)
1824 *
1825 * @uses bp_activity_get_comment_count()
1826 */
1827function bp_activity_comment_count() {
1828        echo bp_activity_get_comment_count();
1829}
1830
1831        /**
1832         * Gets the content of the activity comment currently being displayed
1833         *
1834         * The content is run through two filters. bp_get_activity_content will apply all filters
1835         * applied to activity items in general. Use bp_activity_comment_content to modify the
1836         * content of activity comments only.
1837         *
1838         * @since BuddyPress (1.2)
1839         *
1840         * @todo deprecate $args
1841         *
1842         * @global object $activities_template {@link BP_Activity_Template}
1843         * @uses bp_activity_recurse_comment_count()
1844         * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
1845         *
1846         * @return int $count The activity comment count. Defaults to zero
1847         */
1848        function bp_activity_get_comment_count( $args = '' ) {
1849                global $activities_template;
1850
1851                if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
1852                        return 0;
1853
1854                $count = bp_activity_recurse_comment_count( $activities_template->activity );
1855
1856                return apply_filters( 'bp_activity_get_comment_count', (int) $count );
1857        }
1858
1859                /**
1860                 * Gets the content of the activity comment currently being displayed
1861                 *
1862                 * The content is run through two filters. bp_get_activity_content will apply all filters
1863                 * applied to activity items in general. Use bp_activity_comment_content to modify the
1864                 * content of activity comments only.
1865                 *
1866                 * @since BuddyPress (1.2)
1867                 *
1868                 * @todo investigate why bp_activity_recurse_comment_count() is used while being declared
1869                 *
1870                 * @param object $comment Activity comments object
1871                 *
1872                 * @uses bp_activity_recurse_comment_count()
1873                 * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
1874                 *
1875                 * @return int $count The activity comment count.
1876                 */
1877                function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
1878
1879                        if ( empty( $comment->children ) )
1880                                return $count;
1881
1882                        foreach ( (array) $comment->children as $comment ) {
1883                                $count++;
1884                                $count = bp_activity_recurse_comment_count( $comment, $count );
1885                        }
1886
1887                        return $count;
1888                }
1889
1890/**
1891 * Echoes the activity comment link
1892 *
1893 * @since BuddyPress (1.2)
1894 *
1895 * @uses bp_get_activity_comment_link()
1896 */
1897function bp_activity_comment_link() {
1898        echo bp_get_activity_comment_link();
1899}
1900
1901        /**
1902         * Gets the activity comment link
1903         *
1904         * @since BuddyPress (1.2)
1905         *
1906         * @global object $activities_template {@link BP_Activity_Template}
1907         * @uses apply_filters() To call the 'bp_get_activity_comment_link' hook
1908         *
1909         * @return string The activity comment link
1910         */
1911        function bp_get_activity_comment_link() {
1912                global $activities_template;
1913                return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
1914        }
1915
1916/**
1917 * Echoes the activity comment form no javascript display CSS
1918 *
1919 * @since BuddyPress (1.2)
1920 *
1921 * @uses bp_get_activity_comment_form_nojs_display()
1922 */
1923function bp_activity_comment_form_nojs_display() {
1924        echo bp_get_activity_comment_form_nojs_display();
1925}
1926
1927        /**
1928         * Gets the activity comment form no javascript display CSS
1929         *
1930         * @since BuddyPress (1.2)
1931         *
1932         * @global object $activities_template {@link BP_Activity_Template}
1933         *
1934         * @return string|bool The activity comment form no javascript display CSS. False on failure
1935         */
1936        function bp_get_activity_comment_form_nojs_display() {
1937                global $activities_template;
1938                if ( isset( $_GET['ac'] ) && $_GET['ac'] == $activities_template->activity->id . '/' )
1939                        return 'style="display: block"';
1940
1941                return false;
1942        }
1943
1944/**
1945 * Echoes the activity comment form action
1946 *
1947 * @since BuddyPress (1.2)
1948 *
1949 * @uses bp_get_activity_comment_form_action()
1950 */
1951function bp_activity_comment_form_action() {
1952        echo bp_get_activity_comment_form_action();
1953}
1954
1955        /**
1956         * Gets the activity comment form action
1957         *
1958         * @since BuddyPress (1.2)
1959         *
1960         * @uses home_url()
1961         * @uses bp_get_activity_root_slug()
1962         * @uses apply_filters() To call the 'bp_get_activity_comment_form_action' hook
1963         *
1964         * @return string The activity comment form action
1965         */
1966        function bp_get_activity_comment_form_action() {
1967                return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) );
1968        }
1969
1970/**
1971 * Echoes the activity permalink id
1972 *
1973 * @since BuddyPress (1.2)
1974 *
1975 * @uses bp_get_activity_permalink_id()
1976 */
1977function bp_activity_permalink_id() {
1978        echo bp_get_activity_permalink_id();
1979}
1980
1981        /**
1982         * Gets the activity permalink id
1983         *
1984         * @since BuddyPress (1.2)
1985         *
1986         * @uses apply_filters() To call the 'bp_get_activity_permalink_id' hook
1987         *
1988         * @return string The activity permalink id
1989         */
1990        function bp_get_activity_permalink_id() {
1991                return apply_filters( 'bp_get_activity_permalink_id', bp_current_action() );
1992        }
1993
1994/**
1995 * Echoes the activity thread permalink
1996 *
1997 * @since BuddyPress (1.2)
1998 *
1999 * @uses bp_get_activity_permalink_id()
2000 */
2001function bp_activity_thread_permalink() {
2002        echo bp_get_activity_thread_permalink();
2003}
2004
2005        /**
2006         * Gets the activity thread permalink
2007         *
2008         * @since BuddyPress (1.2)
2009         *
2010         * @uses bp_activity_get_permalink()
2011         * @uses apply_filters() To call the 'bp_get_activity_thread_permalink' hook
2012         *
2013         * @return string $link The activity thread permalink
2014         */
2015        function bp_get_activity_thread_permalink() {
2016                global $activities_template;
2017
2018                $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
2019
2020                return apply_filters( 'bp_get_activity_thread_permalink', $link );
2021        }
2022
2023/**
2024 * Echoes the activity favorite link
2025 *
2026 * @since BuddyPress (1.2)
2027 *
2028 * @uses bp_get_activity_favorite_link()
2029 */
2030function bp_activity_favorite_link() {
2031        echo bp_get_activity_favorite_link();
2032}
2033
2034        /**
2035         * Gets the activity favorite link
2036         *
2037         * @since BuddyPress (1.2)
2038         *
2039         * @global object $activities_template {@link BP_Activity_Template}
2040         * @uses wp_nonce_url()
2041         * @uses home_url()
2042         * @uses bp_get_activity_root_slug()
2043         * @uses apply_filters() To call the 'bp_get_activity_favorite_link' hook
2044         *
2045         * @return string The activity favorite link
2046         */
2047        function bp_get_activity_favorite_link() {
2048                global $activities_template;
2049                return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
2050        }
2051
2052/**
2053 * Echoes the activity unfavorite link
2054 *
2055 * @since BuddyPress (1.2)
2056 *
2057 * @uses bp_get_activity_unfavorite_link()
2058 */
2059function bp_activity_unfavorite_link() {
2060        echo bp_get_activity_unfavorite_link();
2061}
2062
2063        /**
2064         * Gets the activity unfavorite link
2065         *
2066         * @since BuddyPress (1.2)
2067         *
2068         * @global object $activities_template {@link BP_Activity_Template}
2069         * @uses wp_nonce_url()
2070         * @uses home_url()
2071         * @uses bp_get_activity_root_slug()
2072         * @uses apply_filters() To call the 'bp_get_activity_unfavorite_link' hook
2073         *
2074         * @return string The activity unfavorite link
2075         */
2076        function bp_get_activity_unfavorite_link() {
2077                global $activities_template;
2078                return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
2079        }
2080
2081/**
2082 * Echoes the activity CSS class
2083 *
2084 * @since BuddyPress (1.0)
2085 *
2086 * @uses bp_get_activity_css_class()
2087 */
2088function bp_activity_css_class() {
2089        echo bp_get_activity_css_class();
2090}
2091
2092        /**
2093         * Gets the activity CSS class
2094         *
2095         * @since BuddyPress (1.0)
2096         *
2097         * @global object $activities_template {@link BP_Activity_Template}
2098         * @uses apply_filters() To call the 'bp_activity_mini_activity_types' hook
2099         * @uses bp_activity_get_comment_count()
2100         * @uses bp_activity_can_comment()
2101         * @uses apply_filters() To call the 'bp_get_activity_css_class' hook
2102         *
2103         * @return string The activity css class
2104         */
2105        function bp_get_activity_css_class() {
2106                global $activities_template;
2107
2108                $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
2109                        'friendship_accepted',
2110                        'friendship_created',
2111                        'new_blog',
2112                        'joined_group',
2113                        'created_group',
2114                        'new_member'
2115                ) );
2116
2117                $class = ' activity-item';
2118
2119                if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) )
2120                        $class .= ' mini';
2121
2122                if ( bp_activity_get_comment_count() && bp_activity_can_comment() )
2123                        $class .= ' has-comments';
2124
2125                return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
2126        }
2127
2128/**
2129 * Display the activity delete link.
2130 *
2131 * @since BuddyPress (1.1)
2132 *
2133 * @uses bp_get_activity_delete_link()
2134 */
2135function bp_activity_delete_link() {
2136        echo bp_get_activity_delete_link();
2137}
2138
2139        /**
2140         * Return the activity delete link.
2141         *
2142         * @since BuddyPress (1.1)
2143         *
2144         * @global object $activities_template {@link BP_Activity_Template}
2145         * @uses bp_get_root_domain()
2146         * @uses bp_get_activity_root_slug()
2147         * @uses bp_is_activity_component()
2148         * @uses bp_current_action()
2149         * @uses add_query_arg()
2150         * @uses wp_get_referer()
2151         * @uses wp_nonce_url()
2152         * @uses apply_filters() To call the 'bp_get_activity_delete_link' hook
2153         *
2154         * @return string $link Activity delete link. Contains $redirect_to arg if on single activity page.
2155         */
2156        function bp_get_activity_delete_link() {
2157                global $activities_template;
2158
2159                $url   = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id;
2160                $class = 'delete-activity';
2161
2162                // Determine if we're on a single activity page, and customize accordingly
2163                if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {
2164                        $url   = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url );
2165                        $class = 'delete-activity-single';
2166                }
2167
2168                $link = '<a href="' . wp_nonce_url( $url, 'bp_activity_delete_link' ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>';
2169                return apply_filters( 'bp_get_activity_delete_link', $link );
2170        }
2171
2172/**
2173 * Display the activity latest update link.
2174 *
2175 * @since BuddyPress (1.2)
2176 *
2177 * @param int $user_id Defaults to 0
2178 *
2179 * @uses bp_get_activity_latest_update()
2180 */
2181function bp_activity_latest_update( $user_id = 0 ) {
2182        echo bp_get_activity_latest_update( $user_id );
2183}
2184
2185        /**
2186         * Return the activity latest update link.
2187         *
2188         * @since BuddyPress (1.2)
2189         *
2190         * @param int $user_id Defaults to 0
2191         *
2192         * @uses bp_is_user_inactive()
2193         * @uses bp_core_is_user_deleted()
2194         * @uses bp_get_user_meta()
2195         * @uses apply_filters() To call the 'bp_get_activity_latest_update_excerpt' hook
2196         * @uses bp_create_excerpt()
2197         * @uses bp_get_root_domain()
2198         * @uses bp_get_activity_root_slug()
2199         * @uses apply_filters() To call the 'bp_get_activity_latest_update' hook
2200         *
2201         * @return string|bool $latest_update The activity latest update link. False on failure
2202         */
2203        function bp_get_activity_latest_update( $user_id = 0 ) {
2204
2205                if ( empty( $user_id ) )
2206                        $user_id = bp_displayed_user_id();
2207
2208                if ( bp_is_user_inactive( $user_id ) )
2209                        return false;
2210
2211                if ( !$update = bp_get_user_meta( $user_id, 'bp_latest_update', true ) )
2212                        return false;
2213
2214                $latest_update = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 358 ) ) ) );
2215                $latest_update .= ' <a href="' . bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $update['id'] . '/"> ' . __( 'View', 'buddypress' ) . '</a>';
2216
2217                return apply_filters( 'bp_get_activity_latest_update', $latest_update  );
2218        }
2219
2220/**
2221 * Display the activity filter links.
2222 *
2223 * @since BuddyPress (1.1)
2224 *
2225 * @param array $args Defaults to false
2226 *
2227 * @uses bp_get_activity_filter_links()
2228 */
2229function bp_activity_filter_links( $args = false ) {
2230        echo bp_get_activity_filter_links( $args );
2231}
2232
2233        /**
2234         * Return the activity filter links.
2235         *
2236         * @since BuddyPress (1.1)
2237         *
2238         * @param array $args Defaults to false
2239         *
2240         * @uses wp_parse_args()
2241         * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
2242         * @uses esc_attr()
2243         * @uses add_query_arg()
2244         * @uses remove_query_arg()
2245         * @uses apply_filters() To call the 'bp_get_activity_filter_link_href' hook
2246         * @uses apply_filters() To call the 'bp_get_activity_filter_links' hook
2247         *
2248         * @return string|bool $component_links The activity filter links. False on failure
2249         */
2250        function bp_get_activity_filter_links( $args = false ) {
2251
2252                $defaults = array(
2253                        'style' => 'list'
2254                );
2255
2256                $r = wp_parse_args( $args, $defaults );
2257                extract( $r, EXTR_SKIP );
2258
2259                // Define local variable
2260                $component_links = array();
2261
2262                // Fetch the names of components that have activity recorded in the DB
2263                $components = BP_Activity_Activity::get_recorded_components();
2264
2265                if ( empty( $components ) )
2266                        return false;
2267
2268                foreach ( (array) $components as $component ) {
2269
2270                        // Skip the activity comment filter
2271                        if ( 'activity' == $component )
2272                                continue;
2273
2274                        if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] )
2275                                $selected = ' class="selected"';
2276                        else
2277                                unset($selected);
2278
2279                        $component = esc_attr( $component );
2280
2281                        switch ( $style ) {
2282                                case 'list':
2283                                        $tag = 'li';
2284                                        $before = '<li id="afilter-' . $component . '"' . $selected . '>';
2285                                        $after = '</li>';
2286                                break;
2287                                case 'paragraph':
2288                                        $tag = 'p';
2289                                        $before = '<p id="afilter-' . $component . '"' . $selected . '>';
2290                                        $after = '</p>';
2291                                break;
2292                                case 'span':
2293                                        $tag = 'span';
2294                                        $before = '<span id="afilter-' . $component . '"' . $selected . '>';
2295                                        $after = '</span>';
2296                                break;
2297                        }
2298
2299                        $link = add_query_arg( 'afilter', $component );
2300                        $link = remove_query_arg( 'acpage' , $link );
2301                        $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
2302
2303                        $component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( $component ) . '</a>' . $after;
2304                }
2305
2306                $link = remove_query_arg( 'afilter' , $link );
2307
2308                if ( isset( $_GET['afilter'] ) )
2309                        $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr( $link ) . '">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
2310
2311                return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
2312        }
2313
2314/**
2315 * Determine if a comment can be made on an activity item
2316 *
2317 * @since BuddyPress (1.2)
2318 *
2319 * @global object $activities_template {@link BP_Activity_Template}
2320 * @uses bp_get_activity_action_name()
2321 * @uses apply_filters() To call the 'bp_activity_can_comment' hook
2322 *
2323 * @return bool $can_comment Defaults to true
2324 */
2325function bp_activity_can_comment() {
2326        global $activities_template;
2327
2328        $can_comment = true;
2329
2330        if ( false === $activities_template->disable_blogforum_replies || (int) $activities_template->disable_blogforum_replies ) {
2331                if ( 'new_blog_post' == bp_get_activity_action_name() || 'new_blog_comment' == bp_get_activity_action_name() || 'new_forum_topic' == bp_get_activity_action_name() || 'new_forum_post' == bp_get_activity_action_name() )
2332                        $can_comment = false;
2333        }
2334
2335        if ( 'activity_comment' == bp_get_activity_action_name() )
2336                $can_comment = false;
2337
2338        return apply_filters( 'bp_activity_can_comment', $can_comment );
2339}
2340
2341/**
2342 * Determine if a comment can be made on an activity reply item
2343 *
2344 * @since BuddyPress (1.5)
2345 *
2346 * @param object $comment Activity comment
2347 *
2348 * @uses apply_filters() To call the 'bp_activity_can_comment_reply' hook
2349 *
2350 * @return bool $can_comment Defaults to true
2351 */
2352function bp_activity_can_comment_reply( $comment ) {
2353        $can_comment = true;
2354
2355        return apply_filters( 'bp_activity_can_comment_reply', $can_comment, $comment );
2356}
2357
2358/**
2359 * Determine if an favorites are allowed
2360 *
2361 * @since BuddyPress (1.5)
2362 *
2363 * @uses apply_filters() To call the 'bp_activity_can_favorite' hook
2364 *
2365 * @return bool $can_favorite Defaults to true
2366 */
2367function bp_activity_can_favorite() {
2368        $can_favorite = true;
2369
2370        return apply_filters( 'bp_activity_can_favorite', $can_favorite );
2371}
2372
2373/**
2374 * Echoes the total favorite count for a specified user
2375 *
2376 * @since BuddyPress (1.2)
2377 *
2378 * @param int $user_id Defaults to 0
2379 *
2380 * @uses bp_get_total_favorite_count_for_user()
2381 */
2382function bp_total_favorite_count_for_user( $user_id = 0 ) {
2383        echo bp_get_total_favorite_count_for_user( $user_id );
2384}
2385
2386        /**
2387         * Returns the total favorite count for a specified user
2388         *
2389         * @since BuddyPress (1.2)
2390         *
2391         * @param int $user_id Defaults to 0
2392         *
2393         * @uses bp_activity_total_favorites_for_user()
2394         * @uses apply_filters() To call the 'bp_get_total_favorite_count_for_user' hook
2395         *
2396         * @return int The total favorite count for a specified user
2397         */
2398        function bp_get_total_favorite_count_for_user( $user_id = 0 ) {
2399                return apply_filters( 'bp_get_total_favorite_count_for_user', bp_activity_total_favorites_for_user( $user_id ) );
2400        }
2401
2402/**
2403 * Echoes the total mention count for a specified user
2404 *
2405 * @since BuddyPress (1.2)
2406 *
2407 * @param int $user_id Defaults to 0
2408 *
2409 * @uses bp_get_total_favorite_count_for_user()
2410 */
2411function bp_total_mention_count_for_user( $user_id = 0 ) {
2412        echo bp_get_total_favorite_count_for_user( $user_id );
2413}
2414
2415        /**
2416         * Returns the total mention count for a specified user
2417         *
2418         * @since BuddyPress (1.2)
2419         *
2420         * @param int $user_id Defaults to 0
2421         * @uses bp_get_user_meta()
2422         * @uses apply_filters() To call the 'bp_get_total_mention_count_for_user' hook
2423         * @return int The total mention count for a specified user
2424         */
2425        function bp_get_total_mention_count_for_user( $user_id = 0 ) {
2426                return apply_filters( 'bp_get_total_mention_count_for_user', bp_get_user_meta( $user_id, 'bp_new_mention_count', true ) );
2427        }
2428
2429/**
2430 * Echoes the public message link for displayed user
2431 *
2432 * @since BuddyPress (1.2)
2433 *
2434 * @uses bp_get_send_public_message_link()
2435 */
2436function bp_send_public_message_link() {
2437        echo bp_get_send_public_message_link();
2438}
2439
2440        /**
2441         * Returns the public message link for displayed user
2442         *
2443         * @since BuddyPress (1.2)
2444         *
2445         * @global object $bp BuddyPress global settings
2446         * @uses bp_is_my_profile()
2447         * @uses is_user_logged_in()
2448         * @uses wp_nonce_url()
2449         * @uses bp_loggedin_user_domain()
2450         * @uses bp_get_activity_slug()
2451         * @uses bp_core_get_username()
2452         * @uses apply_filters() To call the 'bp_get_send_public_message_link' hook
2453         *
2454         * @return string The public message link for displayed user
2455         */
2456        function bp_get_send_public_message_link() {
2457                global $bp;
2458
2459                if ( bp_is_my_profile() || !is_user_logged_in() )
2460                        return false;
2461
2462                return apply_filters( 'bp_get_send_public_message_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_activity_slug() . '/?r=' . bp_core_get_username( bp_displayed_user_id(), bp_get_displayed_user_username(), $bp->displayed_user->userdata->user_login ) ) );
2463        }
2464
2465/**
2466 * Echoes the mentioned user display name
2467 *
2468 * @since BuddyPress (1.2)
2469 *
2470 * @param int|string User id or username
2471 *
2472 * @uses bp_get_mentioned_user_display_name()
2473 */
2474function bp_mentioned_user_display_name( $user_id_or_username ) {
2475        echo bp_get_mentioned_user_display_name( $user_id_or_username );
2476}
2477
2478        /**
2479         * Returns the mentioned user display name
2480         *
2481         * @since BuddyPress (1.2)
2482         *
2483         * @param int|string User id or username
2484         *
2485         * @uses bp_core_get_user_displayname()
2486         * @uses apply_filters() To call the 'bp_get_mentioned_user_display_name' hook
2487         *
2488         * @return string The mentioned user display name
2489         */
2490        function bp_get_mentioned_user_display_name( $user_id_or_username ) {
2491                if ( !$name = bp_core_get_user_displayname( $user_id_or_username ) )
2492                        $name = __( 'a user', 'buddypress' );
2493
2494                return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username );
2495        }
2496
2497/**
2498 * Output button for sending a public message
2499 *
2500 * @since BuddyPress (1.2)
2501 *
2502 * @param array $args Optional
2503 *
2504 * @uses bp_get_send_public_message_button()
2505 */
2506function bp_send_public_message_button( $args = '' ) {
2507        echo bp_get_send_public_message_button( $args );
2508}
2509
2510        /**
2511         * Return button for sending a public message
2512         *
2513         * @since BuddyPress (1.2)
2514         *
2515         * @param array $args Optional
2516         *
2517         * @uses bp_get_send_public_message_link()
2518         * @uses wp_parse_args()
2519         * @uses bp_get_button()
2520         * @uses apply_filters() To call the 'bp_get_send_public_message_button' hook
2521         *
2522         * @return string The button for sending a public message
2523         */
2524        function bp_get_send_public_message_button( $args = '' ) {
2525                $defaults = array(
2526                        'id'                => 'public_message',
2527                        'component'         => 'activity',
2528                        'must_be_logged_in' => true,
2529                        'block_self'        => true,
2530                        'wrapper_id'        => 'post-mention',
2531                        'link_href'         => bp_get_send_public_message_link(),
2532                        'link_title'        => __( 'Send a public message on your activity stream.', 'buddypress' ),
2533                        'link_text'         => __( 'Public Message', 'buddypress' ),
2534                        'link_class'        => 'activity-button mention'
2535                );
2536
2537                $button = wp_parse_args( $args, $defaults );
2538
2539                // Filter and return the HTML button
2540                return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $button ) );
2541        }
2542
2543/**
2544 * Outputs the activity post form action
2545 *
2546 * @since BuddyPress (1.2)
2547 *
2548 * @uses bp_get_activity_post_form_action()
2549 */
2550function bp_activity_post_form_action() {
2551        echo bp_get_activity_post_form_action();
2552}
2553
2554        /**
2555         * Returns the activity post form action
2556         *
2557         * @since BuddyPress (1.2)
2558         *
2559         * @uses home_url()
2560         * @uses bp_get_activity_root_slug()
2561         * @uses apply_filters() To call the 'bp_get_activity_post_form_action' hook
2562         *
2563         * @return string The activity post form action
2564         */
2565        function bp_get_activity_post_form_action() {
2566                return apply_filters( 'bp_get_activity_post_form_action', home_url( bp_get_activity_root_slug() . '/post/' ) );
2567        }
2568
2569/**
2570 * Looks at all the activity comments on the current activity item, and prints the comments' authors's avatar wrapped in <LI> tags.
2571 *
2572 * Use this function to easily output activity comment authors' avatars.
2573 *
2574 * @param array $args See {@link bp_core_fetch_avatar} for accepted values
2575 * @since BuddyPress (1.7)
2576 */
2577function bp_activity_comments_user_avatars( $args = array() ) {
2578        $defaults = array(
2579                'height' => false,
2580                'html'   => true,
2581                'type'   => 'thumb',
2582                'width'  => false,
2583        );
2584
2585        $args = wp_parse_args( $args, $defaults );
2586        extract( $args, EXTR_SKIP );
2587
2588        // Get the user IDs of everyone who has left a comment to the current activity item
2589        $user_ids = bp_activity_get_comments_user_ids();
2590
2591        $output = array();
2592        foreach ( (array) $user_ids as $user_id ) {
2593                $profile_link = bp_core_get_user_domain( $user_id );
2594                $image_html   = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'height' => $height, 'html' => $html, 'type' => $type, 'width' => $width, ) );
2595
2596                $output[] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $profile_link ), $image_html );
2597        }
2598
2599        echo apply_filters( 'bp_activity_comments_user_avatars', '<li>' . implode( '</li><li>', $output ) . '</li>', $args, $output );
2600}
2601
2602/**
2603 * Returns the user IDs of everyone who's written an activity comment on the current activity item.
2604 *
2605 * @return bool|array Returns false if there is no current activity items
2606 * @since BuddyPress (1.7)
2607 */
2608function bp_activity_get_comments_user_ids() {
2609        if ( empty( $GLOBALS['activities_template']->activity ) || empty( $GLOBALS['activities_template']->activity->children ) )
2610                return false;
2611
2612        $user_ids = (array) bp_activity_recurse_comments_user_ids( $GLOBALS['activities_template']->activity->children );
2613        return apply_filters( 'bp_activity_get_comments_user_ids', array_unique( $user_ids ) );
2614}
2615
2616        /**
2617         * Recurse through all activity comments and collect the IDs of the users who wrote them.
2618         *
2619         * @param array $comments Array of {@link BP_Activity_Activity} items
2620         * @return array Array of user IDs
2621         * @since BuddyPress (1.7)
2622         */
2623        function bp_activity_recurse_comments_user_ids( array $comments ) {
2624                $user_ids = array();
2625
2626                foreach ( $comments as $comment ) {
2627                        // If a user is a spammer, their activity items will have been automatically marked as spam. Skip these.
2628                        if ( $comment->is_spam )
2629                                continue;
2630
2631                        $user_ids[] = $comment->user_id;
2632
2633                        // Check for commentception
2634                        if ( ! empty( $comment->children ) )
2635                                $user_ids = array_merge( $user_ids, bp_activity_recurse_comments_user_ids( $comment->children ) );
2636                }
2637
2638                return $user_ids;
2639        }
2640
2641
2642/**
2643 * Renders a list of all the registered activity types for use in a <select> element, or as <input type="checkbox">.
2644 *
2645 * @param string $output Optional. Either 'select' or 'checkbox'. Defaults to select.
2646 * @param string|array $args Optional extra arguments:
2647 *  checkbox_name - Used when type=checkbox. Sets the item's name property.
2648 *  selected      - Array of strings of activity types to mark as selected/checked.
2649 * @since BuddyPress (1.7)
2650 */
2651function bp_activity_types_list( $output = 'select', $args = '' ) {
2652        $defaults = array(
2653                'checkbox_name' => 'bp_activity_types',
2654                'selected'      => array(),
2655        );
2656        $args = wp_parse_args( $args, $defaults );
2657
2658        $activities = bp_activity_get_types();
2659        natsort( $activities );
2660
2661        // Loop through the activity types and output markup
2662        foreach ( $activities as $type => $description ) {
2663
2664                // See if we need to preselect the current type
2665                $checked  = checked(  true, in_array( $type, (array) $args['selected'] ), false );
2666                $selected = selected( true, in_array( $type, (array) $args['selected'] ), false );
2667
2668                if ( 'select' == $output )
2669                        printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $type ), $selected, esc_html( $description ) );
2670
2671                elseif ( 'checkbox' == $output )
2672                        printf( '<label style="">%1$s<input type="checkbox" name="%2$s[]" value="%3$s" %4$s/></label>', esc_html( $description ), esc_attr( $args['checkbox_name'] ), esc_attr( $type ), $checked );
2673
2674                // Allow custom markup
2675                do_action( 'bp_activity_types_list_' . $output, $args, $type, $description );
2676        }
2677
2678        // Backpat with BP-Default for dropdown boxes only
2679        if ( 'select' == $output )
2680                do_action( 'bp_activity_filter_options' );
2681}
2682
2683
2684/* RSS Feed Template Tags ****************************************************/
2685
2686/**
2687 * Outputs the sitewide activity feed link
2688 *
2689 * @since BuddyPress (1.0)
2690 *
2691 * @uses bp_get_sitewide_activity_feed_link()
2692 */
2693function bp_sitewide_activity_feed_link() {
2694        echo bp_get_sitewide_activity_feed_link();
2695}
2696
2697        /**
2698         * Returns the sitewide activity feed link
2699         *
2700         * @since BuddyPress (1.0)
2701         *
2702         * @uses home_url()
2703         * @uses bp_get_activity_root_slug()
2704         * @uses apply_filters() To call the 'bp_get_sitewide_activity_feed_link' hook
2705         *
2706         * @return string The sitewide activity feed link
2707         */
2708        function bp_get_sitewide_activity_feed_link() {
2709                return apply_filters( 'bp_get_sitewide_activity_feed_link', bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/feed/' );
2710        }
2711
2712/**
2713 * Outputs the member activity feed link
2714 *
2715 * @since BuddyPress (1.2)
2716 *
2717 * @uses bp_get_member_activity_feed_link()
2718 */
2719function bp_member_activity_feed_link() {
2720        echo bp_get_member_activity_feed_link();
2721}
2722
2723/**
2724 * Outputs the member activity feed link
2725 *
2726 * @since BuddyPress (1.0)
2727 * @deprecated BuddyPress (1.2)
2728 *
2729 * @todo properly deprecated in favor of bp_member_activity_feed_link()
2730 *
2731 * @uses bp_get_member_activity_feed_link()
2732 */
2733function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link(); }
2734
2735        /**
2736         * Returns the member activity feed link
2737         *
2738         * @since BuddyPress (1.2)
2739         *
2740         * @uses bp_is_profile_component()
2741         * @uses bp_is_current_action()
2742         * @uses bp_displayed_user_domain()
2743         * @uses bp_get_activity_slug()
2744         * @uses bp_is_active()
2745         * @uses bp_get_friends_slug()
2746         * @uses bp_get_groups_slug()
2747         * @uses apply_filters() To call the 'bp_get_activities_member_rss_link' hook
2748         *
2749         * @return string $link The member activity feed link
2750         */
2751        function bp_get_member_activity_feed_link() {
2752
2753                if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) )
2754                        $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/';
2755                elseif ( bp_is_active( 'friends' ) && bp_is_current_action( bp_get_friends_slug() ) )
2756                        $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/';
2757                elseif ( bp_is_active( 'groups'  ) && bp_is_current_action( bp_get_groups_slug()  ) )
2758                        $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/';
2759                elseif ( 'favorites' == bp_current_action() )
2760                        $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
2761                elseif ( 'mentions' == bp_current_action() )
2762                        $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
2763                else
2764                        $link = '';
2765
2766                return apply_filters( 'bp_get_activities_member_rss_link', $link );
2767        }
2768
2769        /**
2770         * Returns the member activity feed link
2771         *
2772         * @since BuddyPress (1.0)
2773         * @deprecated BuddyPress (1.2)
2774         *
2775         * @todo properly deprecated in favor of bp_get_member_activity_feed_link()
2776         *
2777         * @uses bp_get_member_activity_feed_link()
2778         *
2779         * @return string The member activity feed link
2780         */
2781        function bp_get_activities_member_rss_link() { return bp_get_member_activity_feed_link(); }
2782
2783
2784/** Template tags for RSS feed output ****************************************/
2785
2786/**
2787 * Outputs the activity feed item guid
2788 *
2789 * @since BuddyPress (1.0)
2790 *
2791 * @uses bp_activity_feed_item_guid()
2792 */
2793function bp_activity_feed_item_guid() {
2794        echo bp_get_activity_feed_item_guid();
2795}
2796
2797        /**
2798         * Returns the activity feed item guid
2799         *
2800         * @since BuddyPress (1.2)
2801         *
2802         * @global object $activities_template {@link BP_Activity_Template}
2803         * @uses apply_filters() To call the 'bp_get_activity_feed_item_guid' hook
2804         *
2805         * @return string The activity feed item guid
2806         */
2807        function bp_get_activity_feed_item_guid() {
2808                global $activities_template;
2809
2810                return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );
2811        }
2812
2813/**
2814 * Outputs the activity feed item title
2815 *
2816 * @since BuddyPress (1.0)
2817 *
2818 * @uses bp_get_activity_feed_item_title()
2819 */
2820function bp_activity_feed_item_title() {
2821        echo bp_get_activity_feed_item_title();
2822}
2823
2824        /**
2825         * Returns the activity feed item title
2826         *
2827         * @since BuddyPress (1.0)
2828         *
2829         * @global object $activities_template {@link BP_Activity_Template}
2830         * @uses ent2ncr()
2831         * @uses convert_chars()
2832         * @uses bp_create_excerpt()
2833         * @uses apply_filters() To call the 'bp_get_activity_feed_item_title' hook
2834         *
2835         * @return string $title The activity feed item title
2836         */
2837        function bp_get_activity_feed_item_title() {
2838                global $activities_template;
2839
2840                if ( !empty( $activities_template->activity->action ) )
2841                        $content = $activities_template->activity->action;
2842                else
2843                        $content = $activities_template->activity->content;
2844
2845                $content = explode( '<span', $content );
2846                $title = strip_tags( ent2ncr( trim( convert_chars( $content[0] ) ) ) );
2847
2848                if ( ':' == substr( $title, -1 ) )
2849                        $title = substr( $title, 0, -1 );
2850
2851                if ( 'activity_update' == $activities_template->activity->type )
2852                        $title .= ': ' . strip_tags( ent2ncr( trim( convert_chars( bp_create_excerpt( $activities_template->activity->content, 70, array( 'ending' => " [&#133;]" ) ) ) ) ) );
2853
2854                return apply_filters( 'bp_get_activity_feed_item_title', $title );
2855        }
2856
2857/**
2858 * Outputs the activity feed item link
2859 *
2860 * @since BuddyPress (1.0)
2861 *
2862 * @uses bp_get_activity_feed_item_link()
2863 */
2864function bp_activity_feed_item_link() {
2865        echo bp_get_activity_feed_item_link();
2866}
2867
2868        /**
2869         * Returns the activity feed item link
2870         *
2871         * @since BuddyPress (1.0)
2872         *
2873         * @global object $activities_template {@link BP_Activity_Template}
2874         * @uses apply_filters() To call the 'bp_get_activity_feed_item_link' hook
2875         *
2876         * @return string The activity feed item link
2877         */
2878        function bp_get_activity_feed_item_link() {
2879                global $activities_template;
2880
2881                return apply_filters( 'bp_get_activity_feed_item_link', $activities_template->activity->primary_link );
2882        }
2883
2884/**
2885 * Outputs the activity feed item date
2886 *
2887 * @since BuddyPress (1.0)
2888 *
2889 * @uses bp_get_activity_feed_item_date()
2890 */
2891function bp_activity_feed_item_date() {
2892        echo bp_get_activity_feed_item_date();
2893}
2894
2895        /**
2896         * Returns the activity feed item date
2897         *
2898         * @since BuddyPress (1.0)
2899         *
2900         * @global object $activities_template {@link BP_Activity_Template}
2901         * @uses apply_filters() To call the 'bp_get_activity_feed_item_date' hook
2902         *
2903         * @return string The activity feed item date
2904         */
2905        function bp_get_activity_feed_item_date() {
2906                global $activities_template;
2907
2908                return apply_filters( 'bp_get_activity_feed_item_date', $activities_template->activity->date_recorded );
2909        }
2910
2911/**
2912 * Outputs the activity feed item description
2913 *
2914 * @since BuddyPress (1.0)
2915 *
2916 * @uses bp_get_activity_feed_item_description()
2917 */
2918function bp_activity_feed_item_description() {
2919        echo bp_get_activity_feed_item_description();
2920}
2921
2922        /**
2923         * Returns the activity feed item description
2924         *
2925         * @since BuddyPress (1.0)
2926         *
2927         * @global object $activities_template {@link BP_Activity_Template}
2928         * @uses ent2ncr()
2929         * @uses convert_chars()
2930         * @uses apply_filters() To call the 'bp_get_activity_feed_item_description' hook
2931         *
2932         * @return string The activity feed item description
2933         */
2934        function bp_get_activity_feed_item_description() {
2935                global $activities_template;
2936
2937                $content = '';
2938                if ( ! empty( $activities_template->activity->content ) )
2939                        $content = $activities_template->activity->content;
2940
2941                return apply_filters( 'bp_get_activity_feed_item_description', ent2ncr( convert_chars( str_replace( '%s', '', $content ) ) ) );
2942        }
2943
2944/**
2945 * Template tag so we can hook activity feed to <head>
2946 *
2947 * @since BuddyPress (1.5)
2948 *
2949 * @uses bloginfo()
2950 * @uses bp_sitewide_activity_feed_link()
2951 */
2952function bp_activity_sitewide_feed() {
2953?>
2954
2955        <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ) ?> | <?php _e( 'Site Wide Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_sitewide_activity_feed_link() ?>" />
2956
2957<?php
2958}
2959add_action( 'bp_head', 'bp_activity_sitewide_feed' );