[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Activity Template Functions. 4 * 5 * @package BuddyPress 6 * @subpackage ActivityTemplate 7 * @since 1.5.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Output the activity component slug. 15 * 16 * @since 1.5.0 17 * 18 */ 19 function bp_activity_slug() { 20 echo bp_get_activity_slug(); 21 } 22 /** 23 * Return the activity component slug. 24 * 25 * @since 1.5.0 26 * 27 * 28 * @return string The activity component slug. 29 */ 30 function bp_get_activity_slug() { 31 32 /** 33 * Filters the activity component slug. 34 * 35 * @since 1.5.0 36 * 37 * @param string $slug Activity component slug. 38 */ 39 return apply_filters( 'bp_get_activity_slug', buddypress()->activity->slug ); 40 } 41 42 /** 43 * Output the activity component root slug. 44 * 45 * @since 1.5.0 46 * 47 */ 48 function bp_activity_root_slug() { 49 echo bp_get_activity_root_slug(); 50 } 51 /** 52 * Return the activity component root slug. 53 * 54 * @since 1.5.0 55 * 56 * 57 * @return string The activity component root slug. 58 */ 59 function bp_get_activity_root_slug() { 60 61 /** 62 * Filters the activity component root slug. 63 * 64 * @since 1.5.0 65 * 66 * @param string $root_slug Activity component root slug. 67 */ 68 return apply_filters( 'bp_get_activity_root_slug', buddypress()->activity->root_slug ); 69 } 70 71 /** 72 * Output activity directory permalink. 73 * 74 * @since 1.5.0 75 * 76 */ 77 function bp_activity_directory_permalink() { 78 echo esc_url( bp_get_activity_directory_permalink() ); 79 } 80 /** 81 * Return activity directory permalink. 82 * 83 * @since 1.5.0 84 * 85 * 86 * @return string Activity directory permalink. 87 */ 88 function bp_get_activity_directory_permalink() { 89 90 /** 91 * Filters the activity directory permalink. 92 * 93 * @since 1.5.0 94 * 95 * @param string $url Permalink url for the activity directory. 96 */ 97 return apply_filters( 'bp_get_activity_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() ) ); 98 } 99 100 /** 101 * Initialize the activity loop. 102 * 103 * Based on the $args passed, bp_has_activities() populates the 104 * $activities_template global, enabling the use of BuddyPress templates and 105 * template functions to display a list of activity items. 106 * 107 * @since 1.0.0 108 * @since 2.4.0 Introduced the `$fields` parameter. 109 * 110 * @global object $activities_template {@link BP_Activity_Template} 111 * 112 * @param array|string $args { 113 * Arguments for limiting the contents of the activity loop. Most arguments 114 * are in the same format as {@link BP_Activity_Activity::get()}. However, 115 * because the format of the arguments accepted here differs in a number of 116 * ways, and because bp_has_activities() determines some default arguments in 117 * a dynamic fashion, we list all accepted arguments here as well. 118 * 119 * Arguments can be passed as an associative array, or as a URL querystring 120 * (eg, 'user_id=4&display_comments=threaded'). 121 * 122 * @type int $page Which page of results to fetch. Using page=1 without per_page will result 123 * in no pagination. Default: 1. 124 * @type int|bool $per_page Number of results per page. Default: 20. 125 * @type string $page_arg String used as a query parameter in pagination links. Default: 'acpage'. 126 * @type int|bool $max Maximum number of results to return. Default: false (unlimited). 127 * @type string $fields Activity fields to retrieve. 'all' to fetch entire activity objects, 128 * 'ids' to get only the activity IDs. Default 'all'. 129 * @type string|bool $count_total If true, an additional DB query is run to count the total activity items 130 * for the query. Default: false. 131 * @type string $sort 'ASC' or 'DESC'. Default: 'DESC'. 132 * @type array|bool $exclude Array of activity IDs to exclude. Default: false. 133 * @type array|bool $in Array of IDs to limit query by (IN). 'in' is intended to be used in 134 * conjunction with other filter parameters. Default: false. 135 * @type array|bool $include Array of exact activity IDs to query. Providing an 'include' array will 136 * override all other filters passed in the argument array. When viewing the 137 * permalink page for a single activity item, this value defaults to the ID of 138 * that item. Otherwise the default is false. 139 * @type array $meta_query Limit by activitymeta by passing an array of meta_query conditions. See 140 * {@link WP_Meta_Query::queries} for a description of the syntax. 141 * @type array $date_query Limit by date by passing an array of date_query conditions. See first 142 * parameter of {@link WP_Date_Query::__construct()} for syntax. 143 * @type array $filter_query Advanced activity filtering. See {@link BP_Activity_Query::__construct()}. 144 * @type string $search_terms Limit results by a search term. Default: false. 145 * @type string $scope Use a BuddyPress pre-built filter. 146 * - 'just-me' retrieves items belonging only to a user; this is equivalent 147 * to passing a 'user_id' argument. 148 * - 'friends' retrieves items belonging to the friends of a user. 149 * - 'groups' retrieves items belonging to groups to which a user belongs to. 150 * - 'favorites' retrieves a user's favorited activity items. 151 * - 'mentions' retrieves items where a user has received an @-mention. 152 * The default value of 'scope' is set to one of the above if that value 153 * appears in the appropriate place in the URL; eg, 'scope' will be 'groups' 154 * when visiting http://example.com/members/joe/activity/groups/. Otherwise 155 * defaults to false. 156 * @type int|array|bool $user_id The ID(s) of user(s) whose activity should be fetched. Pass a single ID or 157 * an array of IDs. When viewing a user profile page (but not that user's 158 * activity subpages, ie My Friends, My Groups, etc), 'user_id' defaults to 159 * the ID of the displayed user. Otherwise the default is false. 160 * @type string|array|bool $object Filters by the `component` column in the database, which is generally the 161 * component ID in the case of BuddyPress components, or the plugin slug in 162 * the case of plugins. For example, 'groups' will limit results to those that 163 * are associated with the BP Groups component. Accepts a single component 164 * string, or an array of multiple components. Defaults to 'groups' when 165 * viewing the page of a single group, the My Groups activity filter, or the 166 * Activity > Groups filter of a user profile. Otherwise defaults to false. 167 * @type string|array|bool $action Filters by the `type` column in the database, which is a string 168 * categorizing the activity item (eg, 'new_blog_post', 'created_group'). 169 * Accepts a comma-delimited string or an array of types. Default: false. 170 * @type int|array|bool $primary_id Filters by the `item_id` column in the database. The meaning of 171 * 'primary_id' differs between components/types; for example, in the case of 172 * 'created_group', 'primary_id' is the ID of the group. Accepts a single ID, 173 * or an array of multiple IDs. When viewing a single group, defaults to the 174 * current group ID. When viewing a user's Groups stream page, defaults to the 175 * IDs of the user's groups. Otherwise defaults to false. 176 * @type int|array|bool $secondary_id Filters by the `secondary_item_id` column in the database. The meaning of 177 * 'secondary_id' differs between components/types. Accepts a single ID, or an 178 * array of multiple IDs. Defaults to false. 179 * @type int $offset Return only activity items with an ID greater than or equal to this one. 180 * Note that providing an offset will disable pagination. Default: false. 181 * @type string|bool $display_comments How to handle activity comments. Possible values: 182 * - 'threaded' - comments appear in a threaded tree, under their parent 183 * items. 184 * - 'stream' - the activity stream is presented in a flat manner, with 185 * comments sorted in chronological order alongside other activity items. 186 * - false - don't fetch activity comments at all. 187 * Default: 'threaded'. 188 * @type bool $show_hidden Whether to show items marked hide_sitewide. Defaults to false, except in 189 * the following cases: 190 * - User is viewing his own activity stream. 191 * - User is viewing the activity stream of a non-public group of which he 192 * is a member. 193 * @type string|bool $spam Spam status. 'ham_only', 'spam_only', or false to show all activity 194 * regardless of spam status. Default: 'ham_only'. 195 * @type bool $populate_extras Whether to pre-fetch the activity metadata for the queried items. 196 * Default: true. 197 * } 198 * @return bool Returns true when activities are found, otherwise false. 199 */ 200 function bp_has_activities( $args = '' ) { 201 global $activities_template; 202 203 // Get BuddyPress. 204 $bp = buddypress(); 205 206 /* 207 * Smart Defaults. 208 */ 209 210 // User filtering. 211 $user_id = bp_displayed_user_id() 212 ? bp_displayed_user_id() 213 : false; 214 215 // Group filtering. 216 if ( bp_is_group() ) { 217 $object = $bp->groups->id; 218 $primary_id = bp_get_current_group_id(); 219 $show_hidden = (bool) ( groups_is_user_member( bp_loggedin_user_id(), $primary_id ) || bp_current_user_can( 'bp_moderate' ) ); 220 } else { 221 $object = false; 222 $primary_id = false; 223 $show_hidden = false; 224 } 225 226 // The default scope should recognize custom slugs. 227 $scope = array_key_exists( bp_current_action(), (array) $bp->loaded_components ) 228 ? $bp->loaded_components[ bp_current_action() ] 229 : bp_current_action(); 230 231 // Support for permalinks on single item pages: /groups/my-group/activity/124/. 232 $include = bp_is_current_action( bp_get_activity_slug() ) 233 ? bp_action_variable( 0 ) 234 : false; 235 236 $search_terms_default = false; 237 $search_query_arg = bp_core_get_component_search_query_arg( 'activity' ); 238 if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { 239 $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] ); 240 } 241 242 /* 243 * Parse Args. 244 */ 245 246 // Note: any params used for filtering can be a single value, or multiple 247 // values comma separated. 248 $r = bp_parse_args( 249 $args, 250 array( 251 'display_comments' => 'threaded', // False for none, stream/threaded - show comments in the stream or threaded under items. 252 'include' => $include, // Pass an activity_id or string of IDs comma-separated. 253 'exclude' => false, // Pass an activity_id or string of IDs comma-separated. 254 'in' => false, // Comma-separated list or array of activity IDs among which to search. 255 'sort' => 'DESC', // Sort DESC or ASC. 256 'page' => 1, // Which page to load. 257 'per_page' => 20, // Number of items per page. 258 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679. 259 'max' => false, // Max number to return. 260 'fields' => 'all', 261 'count_total' => false, 262 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide? 263 'spam' => 'ham_only', // Hide spammed items. 264 265 // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions). 266 'scope' => $scope, 267 268 // Filtering. 269 'user_id' => $user_id, // user_id to filter on. 270 'object' => $object, // Object to filter on e.g. groups, profile, status, friends. 271 'action' => false, // Action to filter on e.g. activity_update, profile_updated. 272 'primary_id' => $primary_id, // Object ID to filter on e.g. a group_id or blog_id etc. 273 'secondary_id' => false, // Secondary object ID to filter on e.g. a post_id. 274 'offset' => false, // Return only items >= this ID. 275 'since' => false, // Return only items recorded since this Y-m-d H:i:s date. 276 277 'meta_query' => false, // Filter on activity meta. See WP_Meta_Query for format. 278 'date_query' => false, // Filter by date. See first parameter of WP_Date_Query for format. 279 'filter_query' => false, // Advanced filtering. See BP_Activity_Query for format. 280 281 // Searching. 282 'search_terms' => $search_terms_default, 283 'update_meta_cache' => true, 284 ), 285 'has_activities' 286 ); 287 288 /* 289 * Smart Overrides. 290 */ 291 292 // Translate various values for 'display_comments' 293 // This allows disabling comments via ?display_comments=0 294 // or =none or =false. Final true is a strict type check. See #5029. 295 if ( in_array( $r['display_comments'], array( 0, '0', 'none', 'false' ), true ) ) { 296 $r['display_comments'] = false; 297 } 298 299 // Ignore pagination if an offset is passed. 300 if ( ! empty( $r['offset'] ) ) { 301 $r['page'] = 0; 302 } 303 304 // Search terms. 305 if ( ! empty( $_REQUEST['s'] ) && empty( $r['search_terms'] ) ) { 306 $r['search_terms'] = $_REQUEST['s']; 307 } 308 309 // Do not exceed the maximum per page. 310 if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) { 311 $r['per_page'] = $r['max']; 312 } 313 314 /** 315 * Filters whether BuddyPress should enable afilter support. 316 * 317 * Support for basic filters in earlier BP versions is disabled by default. 318 * To enable, put add_filter( 'bp_activity_enable_afilter_support', '__return_true' ); 319 * into bp-custom.php or your theme's functions.php. 320 * 321 * @since 1.6.0 322 * 323 * @param bool $value True if BuddyPress should enable afilter support. 324 */ 325 if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) ) { 326 $r['filter'] = array( 327 'object' => $_GET['afilter'] 328 ); 329 } elseif ( ! empty( $r['user_id'] ) || ! empty( $r['object'] ) || ! empty( $r['action'] ) || ! empty( $r['primary_id'] ) || ! empty( $r['secondary_id'] ) || ! empty( $r['offset'] ) || ! empty( $r['since'] ) ) { 330 $r['filter'] = array( 331 'user_id' => $r['user_id'], 332 'object' => $r['object'], 333 'action' => $r['action'], 334 'primary_id' => $r['primary_id'], 335 'secondary_id' => $r['secondary_id'], 336 'offset' => $r['offset'], 337 'since' => $r['since'] 338 ); 339 } else { 340 $r['filter'] = false; 341 } 342 343 // If specific activity items have been requested, override the $hide_spam 344 // argument. This prevents backpat errors with AJAX. 345 if ( ! empty( $r['include'] ) && ( 'ham_only' === $r['spam'] ) ) { 346 $r['spam'] = 'all'; 347 } 348 349 /* 350 * Query 351 */ 352 353 $activities_template = new BP_Activity_Template( $r ); 354 355 /** 356 * Filters whether or not there are activity items to display. 357 * 358 * @since 1.1.0 359 * 360 * @param bool $value Whether or not there are activity items to display. 361 * @param string $activities_template Current activities template being used. 362 * @param array $r Array of arguments passed into the BP_Activity_Template class. 363 */ 364 return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $r ); 365 } 366 367 /** 368 * Determine if there are still activities left in the loop. 369 * 370 * @since 1.0.0 371 * 372 * @global object $activities_template {@link BP_Activity_Template} 373 * 374 * @return bool Returns true when activities are found. 375 */ 376 function bp_activities() { 377 global $activities_template; 378 return $activities_template->user_activities(); 379 } 380 381 /** 382 * Get the current activity object in the loop. 383 * 384 * @since 1.0.0 385 * 386 * @global object $activities_template {@link BP_Activity_Template} 387 * 388 * @return object The current activity within the loop. 389 */ 390 function bp_the_activity() { 391 global $activities_template; 392 return $activities_template->the_activity(); 393 } 394 395 /** 396 * Output the URL for the Load More link. 397 * 398 * @since 2.1.0 399 */ 400 function bp_activity_load_more_link() { 401 echo esc_url( bp_get_activity_load_more_link() ); 402 } 403 /** 404 * Get the URL for the Load More link. 405 * 406 * @since 2.1.0 407 * 408 * @return string $link 409 */ 410 function bp_get_activity_load_more_link() { 411 global $activities_template; 412 413 $url = bp_get_requested_url(); 414 $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $url ); 415 416 /** 417 * Filters the Load More link URL. 418 * 419 * @since 2.1.0 420 * 421 * @param string $link The "Load More" link URL with appropriate query args. 422 * @param string $url The original URL. 423 * @param object $activities_template The activity template loop global. 424 */ 425 return apply_filters( 'bp_get_activity_load_more_link', $link, $url, $activities_template ); 426 } 427 428 /** 429 * Output the activity pagination count. 430 * 431 * @since 1.0.0 432 * 433 * @global object $activities_template {@link BP_Activity_Template} 434 */ 435 function bp_activity_pagination_count() { 436 echo bp_get_activity_pagination_count(); 437 } 438 439 /** 440 * Return the activity pagination count. 441 * 442 * @since 1.2.0 443 * 444 * @global object $activities_template {@link BP_Activity_Template} 445 * 446 * @return string The pagination text. 447 */ 448 function bp_get_activity_pagination_count() { 449 global $activities_template; 450 451 $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1; 452 $from_num = bp_core_number_format( $start_num ); 453 $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 ) ); 454 $total = bp_core_number_format( $activities_template->total_activity_count ); 455 456 if ( 1 == $activities_template->total_activity_count ) { 457 $message = __( 'Viewing 1 item', 'buddypress' ); 458 } else { 459 /* translators: 1: the from number item. 2: the to number item. 3: the total number of items. */ 460 $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s item', 'Viewing %1$s - %2$s of %3$s items', $activities_template->total_activity_count, 'buddypress' ), $from_num, $to_num, $total ); 461 } 462 463 return $message; 464 } 465 466 /** 467 * Output the activity pagination links. 468 * 469 * @since 1.0.0 470 * 471 */ 472 function bp_activity_pagination_links() { 473 echo bp_get_activity_pagination_links(); 474 } 475 476 /** 477 * Return the activity pagination links. 478 * 479 * @since 1.0.0 480 * 481 * @global object $activities_template {@link BP_Activity_Template} 482 * 483 * @return string The pagination links. 484 */ 485 function bp_get_activity_pagination_links() { 486 global $activities_template; 487 488 /** 489 * Filters the activity pagination link output. 490 * 491 * @since 1.0.0 492 * 493 * @param string $pag_links Output for the activity pagination links. 494 */ 495 return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links ); 496 } 497 498 /** 499 * Return true when there are more activity items to be shown than currently appear. 500 * 501 * @since 1.5.0 502 * 503 * @global object $activities_template {@link BP_Activity_Template} 504 * 505 * @return bool $has_more_items True if more items, false if not. 506 */ 507 function bp_activity_has_more_items() { 508 global $activities_template; 509 510 if ( ! empty( $activities_template->has_more_items ) ) { 511 $has_more_items = true; 512 } else { 513 $remaining_pages = 0; 514 515 if ( ! empty( $activities_template->pag_page ) ) { 516 $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) ); 517 } 518 519 $has_more_items = (int) $remaining_pages > 0; 520 } 521 522 /** 523 * Filters whether there are more activity items to display. 524 * 525 * @since 1.5.0 526 * 527 * @param bool $has_more_items Whether or not there are more activity items to display. 528 */ 529 return apply_filters( 'bp_activity_has_more_items', $has_more_items ); 530 } 531 532 /** 533 * Output the activity count. 534 * 535 * @since 1.2.0 536 * 537 */ 538 function bp_activity_count() { 539 echo bp_get_activity_count(); 540 } 541 542 /** 543 * Return the activity count. 544 * 545 * @since 1.2.0 546 * 547 * @global object $activities_template {@link BP_Activity_Template} 548 * 549 * @return int The activity count. 550 */ 551 function bp_get_activity_count() { 552 global $activities_template; 553 554 /** 555 * Filters the activity count for the activity template. 556 * 557 * @since 1.2.0 558 * 559 * @param int $activity_count The count for total activity. 560 */ 561 return apply_filters( 'bp_get_activity_count', (int) $activities_template->activity_count ); 562 } 563 564 /** 565 * Output the number of activities per page. 566 * 567 * @since 1.2.0 568 * 569 */ 570 function bp_activity_per_page() { 571 echo bp_get_activity_per_page(); 572 } 573 574 /** 575 * Return the number of activities per page. 576 * 577 * @since 1.2.0 578 * 579 * @global object $activities_template {@link BP_Activity_Template} 580 * 581 * @return int The activities per page. 582 */ 583 function bp_get_activity_per_page() { 584 global $activities_template; 585 586 /** 587 * Filters the activity posts per page value. 588 * 589 * @since 1.2.0 590 * 591 * @param int $pag_num How many post should be displayed for pagination. 592 */ 593 return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->pag_num ); 594 } 595 596 /** 597 * Output the activities title. 598 * 599 * @since 1.0.0 600 * 601 * @todo Deprecate. 602 */ 603 function bp_activities_title() { 604 echo bp_get_activities_title(); 605 } 606 607 /** 608 * Return the activities title. 609 * 610 * @since 1.0.0 611 * 612 * @global string $bp_activity_title 613 * @todo Deprecate. 614 * 615 * @return string The activities title. 616 */ 617 function bp_get_activities_title() { 618 global $bp_activity_title; 619 620 /** 621 * Filters the activities title for the activity template. 622 * 623 * @since 1.0.0 624 * 625 * @param string $bp_activity_title The title to be displayed. 626 */ 627 return apply_filters( 'bp_get_activities_title', $bp_activity_title ); 628 } 629 630 /** 631 * {@internal Missing Description} 632 * 633 * @since 1.0.0 634 * 635 * @todo Deprecate. 636 */ 637 function bp_activities_no_activity() { 638 echo bp_get_activities_no_activity(); 639 } 640 641 /** 642 * {@internal Missing Description} 643 * 644 * @since 1.0.0 645 * 646 * @global string $bp_activity_no_activity 647 * @todo Deprecate. 648 * 649 * @return string 650 */ 651 function bp_get_activities_no_activity() { 652 global $bp_activity_no_activity; 653 654 /** 655 * Filters the text used when there is no activity to display. 656 * 657 * @since 1.0.0 658 * 659 * @param string $bp_activity_no_activity Text to display for no activity. 660 */ 661 return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity ); 662 } 663 664 /** 665 * Output the activity ID. 666 * 667 * @since 1.2.0 668 * 669 */ 670 function bp_activity_id() { 671 echo bp_get_activity_id(); 672 } 673 674 /** 675 * Return the activity ID. 676 * 677 * @since 1.2.0 678 * 679 * @global object $activities_template {@link BP_Activity_Template} 680 * 681 * @return int The activity ID. 682 */ 683 function bp_get_activity_id() { 684 global $activities_template; 685 686 /** 687 * Filters the activity ID being displayed. 688 * 689 * @since 1.2.0 690 * 691 * @param int $id The activity ID. 692 */ 693 return apply_filters( 'bp_get_activity_id', $activities_template->activity->id ); 694 } 695 696 /** 697 * Output the activity item ID. 698 * 699 * @since 1.2.0 700 * 701 */ 702 function bp_activity_item_id() { 703 echo bp_get_activity_item_id(); 704 } 705 706 /** 707 * Return the activity item ID. 708 * 709 * @since 1.2.0 710 * 711 * @global object $activities_template {@link BP_Activity_Template} 712 * 713 * @return int The activity item ID. 714 */ 715 function bp_get_activity_item_id() { 716 global $activities_template; 717 718 /** 719 * Filters the activity item ID being displayed. 720 * 721 * @since 1.2.0 722 * 723 * @param int $item_id The activity item ID. 724 */ 725 return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id ); 726 } 727 728 /** 729 * Output the activity secondary item ID. 730 * 731 * @since 1.2.0 732 * 733 */ 734 function bp_activity_secondary_item_id() { 735 echo bp_get_activity_secondary_item_id(); 736 } 737 738 /** 739 * Return the activity secondary item ID. 740 * 741 * @since 1.2.0 742 * 743 * @global object $activities_template {@link BP_Activity_Template} 744 * 745 * @return int The activity secondary item ID. 746 */ 747 function bp_get_activity_secondary_item_id() { 748 global $activities_template; 749 750 /** 751 * Filters the activity secondary item ID being displayed. 752 * 753 * @since 1.2.0 754 * 755 * @param int $secondary_item_id The activity secondary item ID. 756 */ 757 return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id ); 758 } 759 760 /** 761 * Output the date the activity was recorded. 762 * 763 * @since 1.2.0 764 * 765 */ 766 function bp_activity_date_recorded() { 767 echo bp_get_activity_date_recorded(); 768 } 769 770 /** 771 * Return the date the activity was recorded. 772 * 773 * @since 1.2.0 774 * 775 * @global object $activities_template {@link BP_Activity_Template} 776 * 777 * @return string The date the activity was recorded. 778 */ 779 function bp_get_activity_date_recorded() { 780 global $activities_template; 781 782 /** 783 * Filters the date the activity was recorded. 784 * 785 * @since 1.2.0 786 * 787 * @param int $date_recorded The activity's date. 788 */ 789 return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded ); 790 } 791 792 /** 793 * Output the display name of the member who posted the activity. 794 * 795 * @since 2.1.0 796 * 797 */ 798 function bp_activity_member_display_name() { 799 echo bp_get_activity_member_display_name(); 800 } 801 802 /** 803 * Return the display name of the member who posted the activity. 804 * 805 * @since 2.1.0 806 * 807 * @global object $activities_template {@link BP_Activity_Template} 808 * 809 * @return string The date the activity was recorded. 810 */ 811 function bp_get_activity_member_display_name() { 812 global $activities_template; 813 814 $retval = isset( $activities_template->activity->display_name ) 815 ? $activities_template->activity->display_name 816 : ''; 817 818 /** 819 * Filters the display name of the member who posted the activity. 820 * 821 * @since 2.1.0 822 * 823 * @param int $retval Display name for the member who posted. 824 */ 825 return apply_filters( 'bp_get_activity_member_display_name', $retval ); 826 } 827 828 /** 829 * Output the activity object name. 830 * 831 * @since 1.2.0 832 * 833 */ 834 function bp_activity_object_name() { 835 echo bp_get_activity_object_name(); 836 } 837 838 /** 839 * Return the activity object name. 840 * 841 * @since 1.2.0 842 * 843 * @global object $activities_template {@link BP_Activity_Template} 844 * 845 * @return string The activity object name. 846 */ 847 function bp_get_activity_object_name() { 848 global $activities_template; 849 850 /** 851 * Filters the activity object name. 852 * 853 * @since 1.2.0 854 * 855 * @param string $activity_component The activity object name. 856 */ 857 return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component ); 858 } 859 860 /** 861 * Output the activity type. 862 * 863 * @since 1.2.0 864 * 865 */ 866 function bp_activity_type() { 867 echo bp_get_activity_type(); 868 } 869 870 /** 871 * Return the activity type. 872 * 873 * @since 1.2.0 874 * 875 * @global object $activities_template {@link BP_Activity_Template} 876 * 877 * @return string The activity type. 878 */ 879 function bp_get_activity_type() { 880 global $activities_template; 881 882 /** 883 * Filters the activity type. 884 * 885 * @since 1.2.0 886 * 887 * @param string $activity_type The activity type. 888 */ 889 return apply_filters( 'bp_get_activity_type', $activities_template->activity->type ); 890 } 891 892 /** 893 * Return the activity type template part name. 894 * 895 * @since 10.0.0 896 * 897 * @global object $activities_template {@link BP_Activity_Template} 898 * 899 * @return string The activity type template part name. 900 */ 901 function bp_activity_type_part() { 902 global $activities_template; 903 904 $name = ''; 905 if ( isset( $activities_template->activity->type ) && $activities_template->activity->type ) { 906 $name = str_replace( '_', '-', $activities_template->activity->type ); 907 } 908 909 return $name; 910 } 911 912 /** 913 * Output the activity action name. 914 * 915 * Just a wrapper for bp_activity_type(). 916 * 917 * @since 1.2.0 918 * @deprecated 1.5.0 919 * 920 * @todo Properly deprecate in favor of bp_activity_type() and 921 * remove redundant echo 922 * 923 */ 924 function bp_activity_action_name() { echo bp_activity_type(); } 925 926 /** 927 * Return the activity type. 928 * 929 * Just a wrapper for bp_get_activity_type(). 930 * 931 * @since 1.2.0 932 * @deprecated 1.5.0 933 * 934 * @todo Properly deprecate in favor of bp_get_activity_type(). 935 * 936 * 937 * @return string The activity type. 938 */ 939 function bp_get_activity_action_name() { return bp_get_activity_type(); } 940 941 /** 942 * Output the activity user ID. 943 * 944 * @since 1.1.0 945 * 946 */ 947 function bp_activity_user_id() { 948 echo bp_get_activity_user_id(); 949 } 950 951 /** 952 * Return the activity user ID. 953 * 954 * @since 1.1.0 955 * 956 * @global object $activities_template {@link BP_Activity_Template} 957 * 958 * @return int The activity user ID. 959 */ 960 function bp_get_activity_user_id() { 961 global $activities_template; 962 963 /** 964 * Filters the activity user ID. 965 * 966 * @since 1.1.0 967 * 968 * @param int $user_id The activity user ID. 969 */ 970 return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id ); 971 } 972 973 /** 974 * Output the activity user link. 975 * 976 * @since 1.2.0 977 * 978 */ 979 function bp_activity_user_link() { 980 echo bp_get_activity_user_link(); 981 } 982 983 /** 984 * Return the activity user link. 985 * 986 * @since 1.2.0 987 * 988 * @global object $activities_template {@link BP_Activity_Template} 989 * 990 * @return string $link The activity user link. 991 */ 992 function bp_get_activity_user_link() { 993 global $activities_template; 994 995 if ( empty( $activities_template->activity->user_id ) || empty( $activities_template->activity->user_nicename ) || empty( $activities_template->activity->user_login ) ) { 996 $link = $activities_template->activity->primary_link; 997 } else { 998 $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login ); 999 } 1000 1001 /** 1002 * Filters the activity user link. 1003 * 1004 * @since 1.2.0 1005 * 1006 * @param string $link The activity user link. 1007 */ 1008 return apply_filters( 'bp_get_activity_user_link', $link ); 1009 } 1010 1011 /** 1012 * Output the avatar of the user that performed the action. 1013 * 1014 * @since 1.1.0 1015 * 1016 * @see bp_get_activity_avatar() for description of arguments. 1017 * 1018 * @param array|string $args See {@link bp_get_activity_avatar()} for description. 1019 */ 1020 function bp_activity_avatar( $args = '' ) { 1021 echo bp_get_activity_avatar( $args ); 1022 } 1023 /** 1024 * Return the avatar of the user that performed the action. 1025 * 1026 * @since 1.1.0 1027 * 1028 * @see bp_core_fetch_avatar() For a description of the arguments. 1029 * @global object $activities_template {@link BP_Activity_Template} 1030 * 1031 * @param array|string $args { 1032 * Arguments are listed here with an explanation of their defaults. 1033 * For more information about the arguments, see 1034 * {@link bp_core_fetch_avatar()}. 1035 * @type string $alt Default: 'Profile picture of [user name]' if 1036 * activity user name is available, otherwise 'Profile picture'. 1037 * @type string $class Default: 'avatar'. 1038 * @type string|bool $email Default: Email of the activity's 1039 * associated user, if available. Otherwise false. 1040 * @type string $type Default: 'full' when viewing a single activity 1041 * permalink page, otherwise 'thumb'. 1042 * @type int|bool $user_id Default: ID of the activity's user. 1043 * } 1044 * @return string User avatar string. 1045 */ 1046 function bp_get_activity_avatar( $args = '' ) { 1047 global $activities_template; 1048 1049 $bp = buddypress(); 1050 1051 // On activity permalink pages, default to the full-size avatar. 1052 $type_default = bp_is_single_activity() ? 'full' : 'thumb'; 1053 1054 // Within the activity comment loop, the current activity should be set 1055 // to current_comment. Otherwise, just use activity. 1056 $current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity; 1057 1058 // Activity user display name. 1059 $dn_default = isset( $current_activity_item->display_name ) ? $current_activity_item->display_name : ''; 1060 1061 // Prepend some descriptive text to alt. 1062 $alt_default = __( 'Profile picture', 'buddypress' ); 1063 if ( ! empty( $dn_default ) ) { 1064 /* translators: %s: member name */ 1065 $alt_default = sprintf( __( 'Profile picture of %s', 'buddypress' ), $dn_default ); 1066 } 1067 1068 $defaults = array( 1069 'alt' => $alt_default, 1070 'class' => 'avatar', 1071 'email' => false, 1072 'type' => $type_default, 1073 'user_id' => false 1074 ); 1075 1076 $r = bp_parse_args( 1077 $args, 1078 $defaults 1079 ); 1080 1081 extract( $r, EXTR_SKIP ); 1082 1083 if ( !isset( $height ) && !isset( $width ) ) { 1084 1085 // Backpat. 1086 if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) { 1087 $height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height; 1088 } else { 1089 $height = 20; 1090 } 1091 1092 // Backpat. 1093 if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) { 1094 $width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width; 1095 } else { 1096 $width = 20; 1097 } 1098 } 1099 1100 /** 1101 * Filters the activity avatar object based on current activity item component. 1102 * 1103 * This is a variable filter dependent on the component used. 1104 * Possible hooks are bp_get_activity_avatar_object_blog, 1105 * bp_get_activity_avatar_object_group, and bp_get_activity_avatar_object_user. 1106 * 1107 * @since 1.1.0 1108 * 1109 * @param string $component Component being displayed. 1110 */ 1111 $object = apply_filters( 'bp_get_activity_avatar_object_' . $current_activity_item->component, 'user' ); 1112 $item_id = !empty( $user_id ) ? $user_id : $current_activity_item->user_id; 1113 1114 /** 1115 * Filters the activity avatar item ID. 1116 * 1117 * @since 1.2.10 1118 * 1119 * @param int $item_id Item ID for the activity avatar. 1120 */ 1121 $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $item_id ); 1122 1123 // If this is a user object pass the users' email address for Gravatar so we don't have to prefetch it. 1124 if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) ) { 1125 $email = $current_activity_item->user_email; 1126 } 1127 1128 /** 1129 * Filters the value returned by bp_core_fetch_avatar. 1130 * 1131 * @since 1.1.3 1132 * 1133 * @param array $value HTML image element containing the activity avatar. 1134 */ 1135 return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 1136 'item_id' => $item_id, 1137 'object' => $object, 1138 'type' => $type, 1139 'alt' => $alt, 1140 'class' => $class, 1141 'width' => $width, 1142 'height' => $height, 1143 'email' => $email 1144 ) ) ); 1145 } 1146 1147 /** 1148 * Output the avatar of the object that action was performed on. 1149 * 1150 * @since 1.2.0 1151 * 1152 * @see bp_get_activity_secondary_avatar() for description of arguments. 1153 * 1154 * @param array|string $args See {@link bp_get_activity_secondary_avatar} for description. 1155 */ 1156 function bp_activity_secondary_avatar( $args = '' ) { 1157 echo bp_get_activity_secondary_avatar( $args ); 1158 } 1159 1160 /** 1161 * Return the avatar of the object that action was performed on. 1162 * 1163 * @since 1.2.0 1164 * 1165 * @see bp_core_fetch_avatar() for description of arguments. 1166 * @global object $activities_template {@link BP_Activity_Template} 1167 * 1168 * @param array|string $args { 1169 * For a complete description of arguments, see {@link bp_core_fetch_avatar()}. 1170 * @type string $alt Default value varies based on current activity 1171 * item component. 1172 * @type string $type Default: 'full' when viewing a single activity 1173 * permalink page, otherwise 'thumb'. 1174 * @type string $class Default: 'avatar'. 1175 * @type string|bool $email Default: email of the activity's user. 1176 * @type int|bool $user_id Default: ID of the activity's user. 1177 * } 1178 * @return string The secondary avatar. 1179 */ 1180 function bp_get_activity_secondary_avatar( $args = '' ) { 1181 global $activities_template; 1182 1183 $r = bp_parse_args( 1184 $args, 1185 array( 1186 'alt' => '', 1187 'type' => 'thumb', 1188 'width' => 20, 1189 'height' => 20, 1190 'class' => 'avatar', 1191 'link_class' => '', 1192 'linked' => true, 1193 'email' => false, 1194 ) 1195 ); 1196 1197 extract( $r, EXTR_SKIP ); 1198 1199 // Set item_id and object (default to user). 1200 switch ( $activities_template->activity->component ) { 1201 case 'groups' : 1202 if ( bp_disable_group_avatar_uploads() ) { 1203 return false; 1204 } 1205 1206 $object = 'group'; 1207 $item_id = $activities_template->activity->item_id; 1208 $link = ''; 1209 $name = ''; 1210 1211 // Only if groups is active. 1212 if ( bp_is_active( 'groups' ) ) { 1213 $group = groups_get_group( $item_id ); 1214 $link = bp_get_group_permalink( $group ); 1215 $name = $group->name; 1216 } 1217 1218 if ( empty( $alt ) ) { 1219 $alt = __( 'Group logo', 'buddypress' ); 1220 1221 if ( ! empty( $name ) ) { 1222 /* translators: %s: the Group name */ 1223 $alt = sprintf( __( 'Group logo of %s', 'buddypress' ), $name ); 1224 } 1225 } 1226 1227 break; 1228 case 'blogs' : 1229 $object = 'blog'; 1230 $item_id = $activities_template->activity->item_id; 1231 $link = home_url(); 1232 1233 if ( empty( $alt ) ) { 1234 /* translators: %s: the blog name */ 1235 $alt = sprintf( __( 'Profile picture of the author of the site %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) ); 1236 } 1237 1238 break; 1239 case 'friends' : 1240 $object = 'user'; 1241 $item_id = $activities_template->activity->secondary_item_id; 1242 $link = bp_core_get_userlink( $item_id, false, true ); 1243 1244 if ( empty( $alt ) ) { 1245 /* translators: %s: member name */ 1246 $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $activities_template->activity->secondary_item_id ) ); 1247 } 1248 1249 break; 1250 default : 1251 $object = 'user'; 1252 $item_id = $activities_template->activity->user_id; 1253 $email = $activities_template->activity->user_email; 1254 $link = bp_core_get_userlink( $item_id, false, true ); 1255 1256 if ( empty( $alt ) ) { 1257 /* translators: %s: member name */ 1258 $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), $activities_template->activity->display_name ); 1259 } 1260 1261 break; 1262 } 1263 1264 /** 1265 * Filters the activity secondary avatar object based on current activity item component. 1266 * 1267 * This is a variable filter dependent on the component used. Possible hooks are 1268 * bp_get_activity_secondary_avatar_object_blog, bp_get_activity_secondary_avatar_object_group, 1269 * and bp_get_activity_secondary_avatar_object_user. 1270 * 1271 * @since 1.2.10 1272 * 1273 * @param string $object Component being displayed. 1274 */ 1275 $object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object ); 1276 1277 /** 1278 * Filters the activity secondary avatar item ID. 1279 * 1280 * @since 1.2.10 1281 * 1282 * @param int $item_id ID for the secondary avatar item. 1283 */ 1284 $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id ); 1285 1286 // If we have no item_id or object, there is no avatar to display. 1287 if ( empty( $item_id ) || empty( $object ) ) { 1288 return false; 1289 } 1290 1291 // Get the avatar. 1292 $avatar = bp_core_fetch_avatar( array( 1293 'item_id' => $item_id, 1294 'object' => $object, 1295 'type' => $type, 1296 'alt' => $alt, 1297 'class' => $class, 1298 'width' => $width, 1299 'height' => $height, 1300 'email' => $email 1301 ) ); 1302 1303 if ( !empty( $linked ) ) { 1304 1305 /** 1306 * Filters the secondary avatar link for current activity. 1307 * 1308 * @since 1.7.0 1309 * 1310 * @param string $link Link to wrap the avatar image in. 1311 * @param string $component Activity component being acted on. 1312 */ 1313 $link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template->activity->component ); 1314 1315 /** 1316 * Filters the determined avatar for the secondary activity item. 1317 * 1318 * @since 1.2.10 1319 * 1320 * @param string $avatar Formatted HTML <img> element, or raw avatar URL. 1321 */ 1322 $avatar = apply_filters( 'bp_get_activity_secondary_avatar', $avatar ); 1323 1324 return sprintf( '<a href="%s" class="%s">%s</a>', 1325 $link, 1326 $link_class, 1327 $avatar 1328 ); 1329 } 1330 1331 /** This filter is documented in bp-activity/bp-activity-template.php */ 1332 return apply_filters( 'bp_get_activity_secondary_avatar', $avatar ); 1333 } 1334 1335 /** 1336 * Output the activity action. 1337 * 1338 * @since 1.2.0 1339 * 1340 * @param array $args See bp_get_activity_action(). 1341 */ 1342 function bp_activity_action( $args = array() ) { 1343 echo bp_get_activity_action( $args ); 1344 } 1345 1346 /** 1347 * Return the activity action. 1348 * 1349 * @since 1.2.0 1350 * @since 1.7.0 Introduce function parameter, $args. 1351 * 1352 * @global object $activities_template {@link BP_Activity_Template} 1353 * 1354 * @param array $args { 1355 * @type bool $no_timestamp Whether to exclude the timestamp. 1356 * } 1357 * 1358 * @return string The activity action. 1359 */ 1360 function bp_get_activity_action( $args = array() ) { 1361 global $activities_template; 1362 1363 $r = bp_parse_args( 1364 $args, 1365 array( 1366 'no_timestamp' => false, 1367 ) 1368 ); 1369 1370 /** 1371 * Filters the activity action before the action is inserted as meta. 1372 * 1373 * @since 1.2.10 1374 * 1375 * @param array $value Array containing the current action, the current activity, and the $args array passed into the function. 1376 */ 1377 $action = apply_filters_ref_array( 'bp_get_activity_action_pre_meta', array( 1378 $activities_template->activity->action, 1379 &$activities_template->activity, 1380 $r 1381 ) ); 1382 1383 // Prepend the activity action meta (link, time since, etc...). 1384 if ( ! empty( $action ) && empty( $r['no_timestamp'] ) ) { 1385 $action = bp_insert_activity_meta( $action ); 1386 } 1387 1388 /** 1389 * Filters the activity action after the action has been inserted as meta. 1390 * 1391 * @since 1.2.0 1392 * @since 1.7.0 Now passes a 3rd parameter, $r, an array of arguments from the function. 1393 * 1394 * @param array $value Array containing the current action, the current activity, and the $r array passed into the function. 1395 */ 1396 return apply_filters_ref_array( 'bp_get_activity_action', array( 1397 $action, 1398 &$activities_template->activity, 1399 $r 1400 ) ); 1401 } 1402 1403 /** 1404 * Output the activity content body. 1405 * 1406 * @since 1.2.0 1407 */ 1408 function bp_activity_content_body() { 1409 echo bp_get_activity_content_body(); 1410 } 1411 1412 /** 1413 * Return the activity content body. 1414 * 1415 * @since 1.2.0 1416 * 1417 * @global object $activities_template {@link BP_Activity_Template} 1418 * 1419 * @return string The activity content body. 1420 */ 1421 function bp_get_activity_content_body() { 1422 global $activities_template; 1423 1424 // Backwards compatibility if action is not being used. 1425 if ( empty( $activities_template->activity->action ) && ! empty( $activities_template->activity->content ) ) { 1426 $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content ); 1427 } 1428 1429 /** 1430 * Filters the activity content body. 1431 * 1432 * @since 1.2.0 1433 * 1434 * @param string $content Content body. 1435 * @param object $activity Activity object. Passed by reference. 1436 */ 1437 return apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) ); 1438 } 1439 1440 /** 1441 * Does the activity have content? 1442 * 1443 * @since 1.2.0 1444 * @since 10.0.0 Generate a richer content for activity types supporting the feature. 1445 * 1446 * @global object $activities_template {@link BP_Activity_Template} 1447 * 1448 * @return bool True if activity has content, false otherwise. 1449 */ 1450 function bp_activity_has_content() { 1451 global $activities_template; 1452 1453 $has_content = ! empty( $activities_template->activity->content ); 1454 if ( ! $has_content ) { 1455 $activity_type = bp_get_activity_type(); 1456 1457 if ( bp_activity_type_supports( $activity_type, 'generated-content' ) ) { 1458 $bp = buddypress(); 1459 $generated_content = new stdClass(); 1460 $activity = $activities_template->activity; 1461 $user_id = $activity->user_id; 1462 1463 // Set generated content properties. 1464 if ( 'new_avatar' === $activity_type ) { 1465 $avatars = array(); 1466 1467 // Use the avatar history to display the avatar that was in use at the time the activity was posted. 1468 if ( ! bp_avatar_history_is_disabled() ) { 1469 $avatars = bp_avatar_get_version( $user_id, 'user', bp_get_activity_date_recorded() ); 1470 1471 if ( $avatars && 1 === count( $avatars ) ) { 1472 $avatar = reset( $avatars ); 1473 $historical_avatar = trailingslashit( $avatar->parent_dir_url ) . $avatar->name; 1474 1475 // Add historical avatar to the current activity. 1476 $generated_content->user_profile_photo = array( 1477 'value' => $historical_avatar, 1478 'sanitize_callback' => 'esc_url', 1479 ); 1480 } 1481 1482 // Otherwise use the current/latest avatar. 1483 } else { 1484 $generated_content->user_profile_photo = array( 1485 'value' => bp_core_fetch_avatar( 1486 array( 1487 'item_id' => $user_id, 1488 'object' => 'user', 1489 'type' => 'full', 1490 'width' => bp_core_avatar_full_width(), 1491 'height' => bp_core_avatar_full_height(), 1492 'html' => false, 1493 ) 1494 ), 1495 'sanitize_callback' => 'esc_url', 1496 ); 1497 } 1498 } 1499 1500 if ( in_array( $activity_type, array( 'new_member', 'friendship_created', 'updated_profile' ), true ) ) { 1501 if ( 'friendship_created' === $activity_type ) { 1502 $user_id = $activity->secondary_item_id; 1503 } 1504 1505 if ( isset( $bp->avatar->show_avatars ) && $bp->avatar->show_avatars ) { 1506 $generated_content->user_profile_photo = array( 1507 'value' => bp_core_fetch_avatar( 1508 array( 1509 'item_id' => $user_id, 1510 'object' => 'user', 1511 'type' => 'full', 1512 'width' => bp_core_avatar_full_width(), 1513 'height' => bp_core_avatar_full_height(), 1514 'html' => false, 1515 ) 1516 ), 1517 'sanitize_callback' => 'esc_url', 1518 ); 1519 } 1520 } 1521 1522 // Set common generated content properties. 1523 if ( in_array( $activity_type, array( 'new_avatar', 'new_member', 'friendship_created', 'updated_profile' ), true ) ) { 1524 $generated_content->user_url = array( 1525 'value' => bp_core_get_user_domain( $user_id ), 1526 'sanitize_callback' => 'esc_url', 1527 ); 1528 1529 $generated_content->user_display_name = array( 1530 'value' => bp_core_get_user_displayname( $user_id ), 1531 'sanitize_callback' => 'esc_html', 1532 ); 1533 1534 $generated_content->user_mention_name = array( 1535 'value' => bp_activity_get_user_mentionname( $user_id ), 1536 'sanitize_callback' => 'esc_html', 1537 ); 1538 1539 $generated_content->user_mention_url = array( 1540 'value' => wp_nonce_url( 1541 add_query_arg( 1542 array( 1543 'r' => $generated_content->user_mention_name['value'], 1544 ), 1545 bp_get_activity_directory_permalink() 1546 ) 1547 ), 1548 'sanitize_callback' => 'esc_url', 1549 ); 1550 1551 if ( bp_displayed_user_use_cover_image_header() ) { 1552 $generated_content->user_cover_image = array( 1553 'value' => bp_attachments_get_attachment( 1554 'url', 1555 array( 1556 'object_dir' => 'members', 1557 'item_id' => $user_id, 1558 ) 1559 ), 1560 'sanitize_callback' => 'esc_url', 1561 ); 1562 } 1563 } 1564 1565 if ( 'created_group' === $activity_type || 'joined_group' === $activity_type ) { 1566 $group = bp_get_group( $activity->item_id ); 1567 1568 if ( isset( $bp->avatar->show_avatars ) && $bp->avatar->show_avatars && ! bp_disable_group_avatar_uploads() ) { 1569 $generated_content->group_profile_photo = array( 1570 'value' => bp_core_fetch_avatar( 1571 array( 1572 'item_id' => $group->id, 1573 'object' => 'group', 1574 'type' => 'full', 1575 'width' => bp_core_avatar_full_width(), 1576 'height' => bp_core_avatar_full_height(), 1577 'html' => false, 1578 ) 1579 ), 1580 'sanitize_callback' => 'esc_url', 1581 ); 1582 } 1583 1584 $generated_content->group_url = array( 1585 'value' => bp_get_group_permalink( $group ), 1586 'sanitize_callback' => 'esc_url', 1587 ); 1588 1589 $generated_content->group_name = array( 1590 'value' => bp_get_group_name( $group ), 1591 'sanitize_callback' => 'esc_html', 1592 ); 1593 1594 if ( bp_group_use_cover_image_header() ) { 1595 $generated_content->group_cover_image = array( 1596 'value' => bp_get_group_cover_url( $group ), 1597 'sanitize_callback' => 'esc_url', 1598 ); 1599 } 1600 } 1601 1602 // Update the corresponding entry into the activities template global. 1603 if ( get_object_vars( $generated_content ) ) { 1604 $activity_id = $activities_template->activity->id; 1605 $activity_index = 0; 1606 1607 // Find the activity index. 1608 while ( (int) $activities_template->activities[ $activity_index ]->id !== (int) $activity_id ) { 1609 $activity_index++; 1610 } 1611 1612 // Add the generated content object. 1613 $activities_template->activities[ $activity_index ]->generated_content = $generated_content; 1614 $has_content = true; 1615 } 1616 } 1617 } 1618 1619 return $has_content; 1620 } 1621 1622 /** 1623 * Does this property has been generated? 1624 * 1625 * @since 10.0.0 1626 * 1627 * @param string $property The name of the property to check into the generated content. 1628 * @return bool True if the property is not empty. False otherwise. 1629 */ 1630 function bp_activity_has_generated_content_part( $property = '' ) { 1631 return bp_activity_get_generated_content_part( $property, 'boolean' ); 1632 } 1633 1634 /** 1635 * Outputs a property of the activity generated content. 1636 * 1637 * @since 10.0.0 1638 * 1639 * @param string $property The name of the property to check into the generated content. 1640 */ 1641 function bp_activity_generated_content_part( $property = '' ) { 1642 echo bp_activity_get_generated_content_part( $property ); 1643 } 1644 1645 /** 1646 * Returns the property of the activity generated content. 1647 * 1648 * @since 10.0.0 1649 * 1650 * @param string $property The name of the property to check into the generated content. 1651 * @param string $return Whether to return the property value or a boolean to check it exists. 1652 * @return bool|string A boolean when requested, false if there is no value, the HTML output otherwise. 1653 */ 1654 function bp_activity_get_generated_content_part( $property = '', $return = '' ) { 1655 global $activities_template; 1656 1657 if ( ! isset( $activities_template->activity->generated_content->{$property} ) ) { 1658 return false; 1659 } 1660 1661 $content_part = $activities_template->activity->generated_content->{$property}; 1662 1663 if ( ! isset( $content_part['value'] ) || ! $content_part['value'] ) { 1664 return false; 1665 } 1666 1667 if ( 'boolean' === $return ) { 1668 return true; 1669 } 1670 1671 /** 1672 * Filter here to edit the generated content part. 1673 * 1674 * @since 10.0.0 1675 * 1676 * @param string $value The generated content part. 1677 * @param string $property The property the content part is attached to. 1678 */ 1679 $value = apply_filters( 'bp_activity_get_generated_content_part', $content_part['value'], $property ); 1680 1681 if ( isset( $content_part['sanitize_callback'] ) && $content_part['sanitize_callback'] ) { 1682 return call_user_func( $content_part['sanitize_callback'], $value ); 1683 } 1684 1685 return $value; 1686 } 1687 1688 /** 1689 * Output the activity content. 1690 * 1691 * @since 1.0.0 1692 * @deprecated 1.5.0 1693 * 1694 * @todo properly deprecate this function. 1695 * 1696 */ 1697 function bp_activity_content() { 1698 echo bp_get_activity_content(); 1699 } 1700 1701 /** 1702 * Return the activity content. 1703 * 1704 * @since 1.0.0 1705 * @deprecated 1.5.0 1706 * 1707 * @todo properly deprecate this function. 1708 * 1709 * 1710 * @return string The activity content. 1711 */ 1712 function bp_get_activity_content() { 1713 1714 /** 1715 * If you want to filter activity update content, please use 1716 * the filter 'bp_get_activity_content_body'. 1717 * 1718 * This function is mainly for backwards compatibility. 1719 */ 1720 $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body(); 1721 return apply_filters( 'bp_get_activity_content', $content ); 1722 } 1723 1724 /** 1725 * Attach metadata about an activity item to the activity content. 1726 * 1727 * This metadata includes the time since the item was posted (which will appear 1728 * as a link to the item's permalink). 1729 * 1730 * @since 1.2.0 1731 * 1732 * @global object $activities_template {@link BP_Activity_Template} 1733 * 1734 * @param string $content The activity content. 1735 * @return string The activity content with the metadata string attached. 1736 */ 1737 function bp_insert_activity_meta( $content = '' ) { 1738 global $activities_template; 1739 1740 // Strip any legacy time since placeholders from BP 1.0-1.1. 1741 $new_content = str_replace( '<span class="time-since">%s</span>', '', $content ); 1742 1743 // Get the time since this activity was recorded. 1744 $date_recorded = bp_core_time_since( $activities_template->activity->date_recorded ); 1745 1746 // Set up 'time-since' <span>. 1747 $time_since = sprintf( 1748 '<span class="time-since" data-livestamp="%1$s">%2$s</span>', 1749 bp_core_get_iso8601_date( $activities_template->activity->date_recorded ), 1750 $date_recorded 1751 ); 1752 1753 /** 1754 * Filters the activity item time since markup. 1755 * 1756 * @since 1.2.0 1757 * 1758 * @param array $value Array containing the time since markup and the current activity component. 1759 */ 1760 $time_since = apply_filters_ref_array( 'bp_activity_time_since', array( 1761 $time_since, 1762 &$activities_template->activity 1763 ) ); 1764 1765 // Insert the permalink. 1766 if ( ! bp_is_single_activity() ) { 1767 1768 // Setup variables for activity meta. 1769 $activity_permalink = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 1770 $activity_meta = sprintf( '%1$s <a href="%2$s" class="view activity-time-since bp-tooltip" data-bp-tooltip="%3$s">%4$s</a>', 1771 $new_content, 1772 $activity_permalink, 1773 esc_attr__( 'View Discussion', 'buddypress' ), 1774 $time_since 1775 ); 1776 1777 /** 1778 * Filters the activity permalink to be added to the activity content. 1779 * 1780 * @since 1.2.0 1781 * 1782 * @param array $value Array containing the html markup for the activity permalink, after being parsed by 1783 * sprintf and current activity component. 1784 */ 1785 $new_content = apply_filters_ref_array( 'bp_activity_permalink', array( 1786 $activity_meta, 1787 &$activities_template->activity 1788 ) ); 1789 } else { 1790 $new_content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH ); 1791 } 1792 1793 /** 1794 * Filters the activity content after activity metadata has been attached. 1795 * 1796 * @since 1.2.0 1797 * 1798 * @param string $content Activity content with the activity metadata added. 1799 */ 1800 return apply_filters( 'bp_insert_activity_meta', $new_content, $content ); 1801 } 1802 1803 /** 1804 * Determine if the current user can delete an activity item. 1805 * 1806 * @since 1.2.0 1807 * 1808 * @global object $activities_template {@link BP_Activity_Template} 1809 * 1810 * @param false|BP_Activity_Activity $activity Optional. Falls back on the current item in the loop. 1811 * @return bool True if can delete, false otherwise. 1812 */ 1813 function bp_activity_user_can_delete( $activity = false ) { 1814 global $activities_template; 1815 1816 // Try to use current activity if none was passed. 1817 if ( empty( $activity ) && ! empty( $activities_template->activity ) ) { 1818 $activity = $activities_template->activity; 1819 } 1820 1821 // If current_comment is set, we'll use that in place of the main activity. 1822 if ( isset( $activity->current_comment ) ) { 1823 $activity = $activity->current_comment; 1824 } 1825 1826 // Assume the user cannot delete the activity item. 1827 $can_delete = false; 1828 1829 // Only logged in users can delete activity. 1830 if ( is_user_logged_in() ) { 1831 1832 // Community moderators can always delete activity (at least for now). 1833 if ( bp_current_user_can( 'bp_moderate' ) ) { 1834 $can_delete = true; 1835 } 1836 1837 // Users are allowed to delete their own activity. This is actually 1838 // quite powerful, because doing so also deletes all comments to that 1839 // activity item. We should revisit this eventually. 1840 if ( isset( $activity->user_id ) && ( $activity->user_id === bp_loggedin_user_id() ) ) { 1841 $can_delete = true; 1842 } 1843 1844 /* 1845 * Viewing a single item, and this user is an admin of that item. 1846 * 1847 * Group activity items are handled separately. 1848 * See bp_groups_filter_activity_user_can_delete(). 1849 */ 1850 if ( 'groups' !== $activity->component && bp_is_single_item() && bp_is_item_admin() ) { 1851 $can_delete = true; 1852 } 1853 } 1854 1855 /** 1856 * Filters whether the current user can delete an activity item. 1857 * 1858 * @since 1.5.0 1859 * 1860 * @param bool $can_delete Whether the user can delete the item. 1861 * @param object $activity Current activity item object. 1862 */ 1863 return (bool) apply_filters( 'bp_activity_user_can_delete', $can_delete, $activity ); 1864 } 1865 1866 /** 1867 * Output the activity parent content. 1868 * 1869 * @since 1.2.0 1870 * 1871 * @see bp_get_activity_parent_content() for a description of arguments. 1872 * 1873 * @param array|string $args See {@link bp_get_activity_parent_content} for description. 1874 */ 1875 function bp_activity_parent_content( $args = '' ) { 1876 echo bp_get_activity_parent_content($args); 1877 } 1878 1879 /** 1880 * Return the activity content. 1881 * 1882 * @since 1.2.0 1883 * 1884 * @global object $activities_template {@link BP_Activity_Template} 1885 * 1886 * @param string $args Unused. Left over from an earlier implementation. 1887 * @return mixed False on failure, otherwise the activity parent content. 1888 */ 1889 function bp_get_activity_parent_content( $args = '' ) { 1890 global $activities_template; 1891 1892 // Bail if no activity on no item ID. 1893 if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) { 1894 return false; 1895 } 1896 1897 // Get the ID of the parent activity content. 1898 $parent_id = $activities_template->activity->item_id; 1899 1900 // Bail if no parent content. 1901 if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) { 1902 return false; 1903 } 1904 1905 // Bail if no action. 1906 if ( empty( $activities_template->activity_parents[ $parent_id ]->action ) ) { 1907 return false; 1908 } 1909 1910 // Content always includes action. 1911 $content = $activities_template->activity_parents[ $parent_id ]->action; 1912 1913 // Maybe append activity content, if it exists. 1914 if ( ! empty( $activities_template->activity_parents[ $parent_id ]->content ) ) { 1915 $content .= ' ' . $activities_template->activity_parents[ $parent_id ]->content; 1916 } 1917 1918 // Remove the time since content for backwards compatibility. 1919 $content = str_replace( '<span class="time-since">%s</span>', '', $content ); 1920 1921 // Remove images. 1922 $content = preg_replace( '/<img[^>]*>/Ui', '', $content ); 1923 1924 /** 1925 * Filters the activity parent content. 1926 * 1927 * @since 1.2.0 1928 * 1929 * @param string $content Content set to be displayed as parent content. 1930 */ 1931 return apply_filters( 'bp_get_activity_parent_content', $content ); 1932 } 1933 1934 /** 1935 * Output the parent activity's user ID. 1936 * 1937 * @since 1.7.0 1938 */ 1939 function bp_activity_parent_user_id() { 1940 echo bp_get_activity_parent_user_id(); 1941 } 1942 1943 /** 1944 * Return the parent activity's user ID. 1945 * 1946 * @since 1.7.0 1947 * 1948 * @global BP_Activity_Template $activities_template 1949 * 1950 * @return bool|int False if parent activity can't be found, otherwise 1951 * the parent activity's user ID. 1952 */ 1953 function bp_get_activity_parent_user_id() { 1954 global $activities_template; 1955 1956 // Bail if no activity on no item ID. 1957 if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) { 1958 return false; 1959 } 1960 1961 // Get the ID of the parent activity content. 1962 $parent_id = $activities_template->activity->item_id; 1963 1964 // Bail if no parent item. 1965 if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) { 1966 return false; 1967 } 1968 1969 // Bail if no parent user ID. 1970 if ( empty( $activities_template->activity_parents[ $parent_id ]->user_id ) ) { 1971 return false; 1972 } 1973 1974 $retval = $activities_template->activity_parents[ $parent_id ]->user_id; 1975 1976 /** 1977 * Filters the activity parent item's user ID. 1978 * 1979 * @since 1.7.0 1980 * 1981 * @param int $retval ID for the activity parent's user. 1982 */ 1983 return (int) apply_filters( 'bp_get_activity_parent_user_id', $retval ); 1984 } 1985 1986 /** 1987 * Output whether or not the current activity is in a current user's favorites. 1988 * 1989 * @since 1.2.0 1990 * 1991 */ 1992 function bp_activity_is_favorite() { 1993 echo bp_get_activity_is_favorite(); 1994 } 1995 1996 /** 1997 * Return whether the current activity is in a current user's favorites. 1998 * 1999 * @since 1.2.0 2000 * 2001 * @global object $activities_template {@link BP_Activity_Template} 2002 * 2003 * @return bool True if user favorite, false otherwise. 2004 */ 2005 function bp_get_activity_is_favorite() { 2006 global $activities_template; 2007 2008 /** 2009 * Filters whether the current activity item is in the current user's favorites. 2010 * 2011 * @since 1.2.0 2012 * 2013 * @param bool $value Whether or not the current activity item is in the current user's favorites. 2014 */ 2015 return (bool) apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) ); 2016 } 2017 2018 /** 2019 * Output the comment markup for an activity item. 2020 * 2021 * @since 1.2.0 2022 * 2023 * @todo deprecate $args param 2024 * 2025 * @param array|string $args See {@link bp_activity_get_comments} for description. 2026 */ 2027 function bp_activity_comments( $args = '' ) { 2028 echo bp_activity_get_comments( $args ); 2029 } 2030 2031 /** 2032 * Get the comment markup for an activity item. 2033 * 2034 * @since 1.2.0 2035 * 2036 * @todo deprecate $args param 2037 * @todo Given that checks for children already happen in bp_activity_recurse_comments(), 2038 * this function can probably be streamlined or removed. 2039 * 2040 * @global object $activities_template {@link BP_Activity_Template} 2041 * 2042 * @param string $args Unused. Left over from an earlier implementation. 2043 * @return bool 2044 */ 2045 function bp_activity_get_comments( $args = '' ) { 2046 global $activities_template; 2047 2048 if ( empty( $activities_template->activity->children ) ) { 2049 return false; 2050 } 2051 2052 bp_activity_recurse_comments( $activities_template->activity ); 2053 } 2054 2055 /** 2056 * Loops through a level of activity comments and loads the template for each. 2057 * 2058 * Note: The recursion itself used to happen entirely in this function. Now it is 2059 * split between here and the comment.php template. 2060 * 2061 * @since 1.2.0 2062 * 2063 * @global object $activities_template {@link BP_Activity_Template} 2064 * 2065 * @param object $comment The activity object currently being recursed. 2066 * @return bool|string 2067 */ 2068 function bp_activity_recurse_comments( $comment ) { 2069 global $activities_template; 2070 2071 if ( empty( $comment ) ) { 2072 return false; 2073 } 2074 2075 if ( empty( $comment->children ) ) { 2076 return false; 2077 } 2078 2079 /** 2080 * Filters the opening tag for the template that lists activity comments. 2081 * 2082 * @since 1.6.0 2083 * 2084 * @param string $value Opening tag for the HTML markup to use. 2085 */ 2086 echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>' ); 2087 foreach ( (array) $comment->children as $comment_child ) { 2088 2089 // Put the comment into the global so it's available to filters. 2090 $activities_template->activity->current_comment = $comment_child; 2091 2092 $template = bp_locate_template( 'activity/comment.php', false, false ); 2093 2094 // Backward compatibility. In older versions of BP, the markup was 2095 // generated in the PHP instead of a template. This ensures that 2096 // older themes (which are not children of bp-default and won't 2097 // have the new template) will still work. 2098 if ( !$template ) { 2099 $template = buddypress()->plugin_dir . '/bp-themes/bp-default/activity/comment.php'; 2100 } 2101 2102 load_template( $template, false ); 2103 2104 unset( $activities_template->activity->current_comment ); 2105 } 2106 2107 /** 2108 * Filters the closing tag for the template that list activity comments. 2109 * 2110 * @since 1.6.0 2111 * 2112 * @param string $value Closing tag for the HTML markup to use. 2113 */ 2114 echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>' ); 2115 } 2116 2117 /** 2118 * Utility function that returns the comment currently being recursed. 2119 * 2120 * @since 1.5.0 2121 * 2122 * @global object $activities_template {@link BP_Activity_Template} 2123 * 2124 * @return object|bool $current_comment The activity comment currently being 2125 * displayed. False on failure. 2126 */ 2127 function bp_activity_current_comment() { 2128 global $activities_template; 2129 2130 $current_comment = !empty( $activities_template->activity->current_comment ) 2131 ? $activities_template->activity->current_comment 2132 : false; 2133 2134 /** 2135 * Filters the current comment being recursed. 2136 * 2137 * @since 1.5.0 2138 * 2139 * @param object|bool $current_comment The activity comment currently being displayed. False on failure. 2140 */ 2141 return apply_filters( 'bp_activity_current_comment', $current_comment ); 2142 } 2143 2144 2145 /** 2146 * Output the ID of the activity comment currently being displayed. 2147 * 2148 * @since 1.5.0 2149 * 2150 */ 2151 function bp_activity_comment_id() { 2152 echo bp_get_activity_comment_id(); 2153 } 2154 2155 /** 2156 * Return the ID of the activity comment currently being displayed. 2157 * 2158 * @since 1.5.0 2159 * 2160 * @global object $activities_template {@link BP_Activity_Template} 2161 * 2162 * @return int|bool $comment_id The ID of the activity comment currently 2163 * being displayed, false if none is found. 2164 */ 2165 function bp_get_activity_comment_id() { 2166 global $activities_template; 2167 2168 $comment_id = isset( $activities_template->activity->current_comment->id ) ? $activities_template->activity->current_comment->id : false; 2169 2170 /** 2171 * Filters the ID of the activity comment currently being displayed. 2172 * 2173 * @since 1.5.0 2174 * 2175 * @param int|bool $comment_id ID for the comment currently being displayed. 2176 */ 2177 return apply_filters( 'bp_activity_comment_id', $comment_id ); 2178 } 2179 2180 /** 2181 * Output the ID of the author of the activity comment currently being displayed. 2182 * 2183 * @since 1.5.0 2184 * 2185 */ 2186 function bp_activity_comment_user_id() { 2187 echo bp_get_activity_comment_user_id(); 2188 } 2189 2190 /** 2191 * Return the ID of the author of the activity comment currently being displayed. 2192 * 2193 * @since 1.5.0 2194 * 2195 * @global object $activities_template {@link BP_Activity_Template} 2196 * 2197 * @return int|bool $user_id The user_id of the author of the displayed 2198 * activity comment. False on failure. 2199 */ 2200 function bp_get_activity_comment_user_id() { 2201 global $activities_template; 2202 2203 $user_id = isset( $activities_template->activity->current_comment->user_id ) ? $activities_template->activity->current_comment->user_id : false; 2204 2205 /** 2206 * Filters the ID of the author of the activity comment currently being displayed. 2207 * 2208 * @since 1.5.0 2209 * 2210 * @param int|bool $user_id ID for the author of the comment currently being displayed. 2211 */ 2212 return apply_filters( 'bp_activity_comment_user_id', $user_id ); 2213 } 2214 2215 /** 2216 * Output the author link for the activity comment currently being displayed. 2217 * 2218 * @since 1.5.0 2219 * 2220 */ 2221 function bp_activity_comment_user_link() { 2222 echo bp_get_activity_comment_user_link(); 2223 } 2224 2225 /** 2226 * Return the author link for the activity comment currently being displayed. 2227 * 2228 * @since 1.5.0 2229 * 2230 * 2231 * @return string $user_link The URL of the activity comment author's profile. 2232 */ 2233 function bp_get_activity_comment_user_link() { 2234 $user_link = bp_core_get_user_domain( bp_get_activity_comment_user_id() ); 2235 2236 /** 2237 * Filters the author link for the activity comment currently being displayed. 2238 * 2239 * @since 1.5.0 2240 * 2241 * @param string $user_link Link for the author of the activity comment currently being displayed. 2242 */ 2243 return apply_filters( 'bp_activity_comment_user_link', $user_link ); 2244 } 2245 2246 /** 2247 * Output the author name for the activity comment currently being displayed. 2248 * 2249 * @since 1.5.0 2250 * 2251 */ 2252 function bp_activity_comment_name() { 2253 echo bp_get_activity_comment_name(); 2254 } 2255 2256 /** 2257 * Return the author name for the activity comment currently being displayed. 2258 * 2259 * The use of the 'bp_acomment_name' filter is deprecated. Please use 2260 * 'bp_activity_comment_name'. 2261 * 2262 * @since 1.5.0 2263 * 2264 * @global object $activities_template {@link BP_Activity_Template} 2265 * 2266 * @return string $name The full name of the activity comment author. 2267 */ 2268 function bp_get_activity_comment_name() { 2269 global $activities_template; 2270 2271 if ( isset( $activities_template->activity->current_comment->user_fullname ) ) { 2272 2273 $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // Backward compatibility. 2274 } else { 2275 $name = $activities_template->activity->current_comment->display_name; 2276 } 2277 2278 /** 2279 * Filters the name of the author for the activity comment. 2280 * 2281 * @since 1.5.0 2282 * 2283 * @param string $name Name to be displayed with the activity comment. 2284 */ 2285 return apply_filters( 'bp_activity_comment_name', $name ); 2286 } 2287 2288 /** 2289 * Output the formatted date_recorded of the activity comment currently being displayed. 2290 * 2291 * @since 1.5.0 2292 * 2293 */ 2294 function bp_activity_comment_date_recorded() { 2295 echo bp_get_activity_comment_date_recorded(); 2296 } 2297 2298 /** 2299 * Return the formatted date_recorded for the activity comment currently being displayed. 2300 * 2301 * @since 1.5.0 2302 * 2303 * 2304 * @return string|bool $date_recorded Time since the activity was recorded, 2305 * in the form "%s ago". False on failure. 2306 */ 2307 function bp_get_activity_comment_date_recorded() { 2308 2309 /** 2310 * Filters the recorded date of the activity comment currently being displayed. 2311 * 2312 * @since 1.5.0 2313 * 2314 * @param string|bool Date for the activity comment currently being displayed. 2315 */ 2316 return apply_filters( 'bp_activity_comment_date_recorded', bp_core_time_since( bp_get_activity_comment_date_recorded_raw() ) ); 2317 } 2318 2319 /** 2320 * Output the date_recorded of the activity comment currently being displayed. 2321 * 2322 * @since 2.3.0 2323 * 2324 */ 2325 function bp_activity_comment_date_recorded_raw() { 2326 echo bp_get_activity_comment_date_recorded_raw(); 2327 } 2328 2329 /** 2330 * Return the date_recorded for the activity comment currently being displayed. 2331 * 2332 * @since 2.3.0 2333 * 2334 * @global object $activities_template {@link BP_Activity_Template} 2335 * 2336 * @return string|bool $date_recorded Time since the activity was recorded, 2337 * in the form "%s ago". False on failure. 2338 */ 2339 function bp_get_activity_comment_date_recorded_raw() { 2340 global $activities_template; 2341 2342 /** 2343 * Filters the raw recorded date of the activity comment currently being displayed. 2344 * 2345 * @since 2.3.0 2346 * 2347 * @param string|bool Raw date for the activity comment currently being displayed. 2348 */ 2349 return apply_filters( 'bp_activity_comment_date_recorded', $activities_template->activity->current_comment->date_recorded ); 2350 } 2351 2352 /** 2353 * Output the 'delete' URL for the activity comment currently being displayed. 2354 * 2355 * @since 1.5.0 2356 * 2357 */ 2358 function bp_activity_comment_delete_link() { 2359 echo bp_get_activity_comment_delete_link(); 2360 } 2361 2362 /** 2363 * Gets the 'delete' URL for the activity comment currently being displayed. 2364 * 2365 * @since 1.5.0 2366 * 2367 * 2368 * @return string $link The nonced URL for deleting the current 2369 * activity comment. 2370 */ 2371 function bp_get_activity_comment_delete_link() { 2372 $link = wp_nonce_url( trailingslashit( bp_get_activity_directory_permalink() . 'delete/' . bp_get_activity_comment_id() ) . '?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' ); 2373 2374 /** 2375 * Filters the link used for deleting the activity comment currently being displayed. 2376 * 2377 * @since 1.5.0 2378 * 2379 * @param string $link Link to use for deleting the currently displayed activity comment. 2380 */ 2381 return apply_filters( 'bp_activity_comment_delete_link', $link ); 2382 } 2383 2384 /** 2385 * Output the content of the activity comment currently being displayed. 2386 * 2387 * @since 1.5.0 2388 * 2389 */ 2390 function bp_activity_comment_content() { 2391 echo bp_get_activity_comment_content(); 2392 } 2393 2394 /** 2395 * Return the content of the activity comment currently being displayed. 2396 * 2397 * The content is run through two filters. 'bp_get_activity_content' 2398 * will apply all filters applied to activity items in general. Use 2399 * 'bp_activity_comment_content' to modify the content of activity 2400 * comments only. 2401 * 2402 * @since 1.5.0 2403 * 2404 * @global object $activities_template {@link BP_Activity_Template} 2405 * 2406 * @return string $content The content of the current activity comment. 2407 */ 2408 function bp_get_activity_comment_content() { 2409 global $activities_template; 2410 2411 /** This filter is documented in bp-activity/bp-activity-template.php */ 2412 $content = apply_filters( 'bp_get_activity_content', $activities_template->activity->current_comment->content ); 2413 2414 /** 2415 * Filters the content of the current activity comment. 2416 * 2417 * @since 1.2.0 2418 * @since 3.0.0 Added $context parameter to disambiguate from bp_get_activity_comment_content(). 2419 * 2420 * @param string $content The content of the current activity comment. 2421 * @param string $context This filter's context ("get"). 2422 */ 2423 return apply_filters( 'bp_activity_comment_content', $content, 'get' ); 2424 } 2425 2426 /** 2427 * Output the activity comment count. 2428 * 2429 * @since 1.2.0 2430 * 2431 */ 2432 function bp_activity_comment_count() { 2433 echo bp_activity_get_comment_count(); 2434 } 2435 2436 /** 2437 * Return the comment count of an activity item. 2438 * 2439 * @since 1.2.0 2440 * 2441 * @global object $activities_template {@link BP_Activity_Template} 2442 * 2443 * @param array|null $deprecated Deprecated. 2444 * @return int $count The activity comment count. 2445 */ 2446 function bp_activity_get_comment_count( $deprecated = null ) { 2447 global $activities_template; 2448 2449 // Deprecated notice about $args. 2450 if ( ! empty( $deprecated ) ) { 2451 _deprecated_argument( 2452 __FUNCTION__, 2453 '1.2', 2454 sprintf( 2455 /* translators: 1: the name of the function. 2: the name of the file. */ 2456 __( '%1$s no longer accepts arguments. See the inline documentation at %2$s for more details.', 'buddypress' ), 2457 __FUNCTION__, 2458 __FILE__ 2459 ) 2460 ); 2461 } 2462 2463 // Get the count using the purpose-built recursive function. 2464 $count = ! empty( $activities_template->activity->children ) 2465 ? bp_activity_recurse_comment_count( $activities_template->activity ) 2466 : 0; 2467 2468 /** 2469 * Filters the activity comment count. 2470 * 2471 * @since 1.2.0 2472 * 2473 * @param int $count The activity comment count. 2474 */ 2475 return apply_filters( 'bp_activity_get_comment_count', (int) $count ); 2476 } 2477 2478 /** 2479 * Return the total number of comments to the current comment. 2480 * 2481 * This function recursively adds the total number of comments each 2482 * activity child has, and returns them. 2483 * 2484 * @since 1.2.0 2485 * 2486 * 2487 * @param object $comment Activity comment object. 2488 * @param int $count The current iteration count. 2489 * @return int $count The activity comment count. 2490 */ 2491 function bp_activity_recurse_comment_count( $comment, $count = 0 ) { 2492 2493 // Copy the count. 2494 $new_count = $count; 2495 2496 // Loop through children and recursively count comments. 2497 if ( ! empty( $comment->children ) ) { 2498 foreach ( (array) $comment->children as $comment ) { 2499 $new_count++; 2500 $new_count = bp_activity_recurse_comment_count( $comment, $new_count ); 2501 } 2502 } 2503 2504 /** 2505 * Filters the total number of comments for the current comment. 2506 * 2507 * @since 2.1.0 2508 * 2509 * @param int $new_count New total count for the current comment. 2510 * @param object $comment Activity comment object. 2511 * @param int $count Current iteration count for the current comment. 2512 */ 2513 return apply_filters( 'bp_activity_recurse_comment_count', $new_count, $comment, $count ); 2514 } 2515 2516 /** 2517 * Output the depth of the current activity comment. 2518 * 2519 * @since 2.0.0 2520 * @since 2.8.0 Added $comment as a parameter. 2521 * 2522 * @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary 2523 * when used in activity comment loop. 2524 */ 2525 function bp_activity_comment_depth( $comment = 0 ) { 2526 echo bp_activity_get_comment_depth( $comment ); 2527 } 2528 2529 /** 2530 * Return the current activity comment depth. 2531 * 2532 * @since 2.0.0 2533 * @since 2.8.0 Added $comment as a parameter. 2534 * 2535 * @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary 2536 * when used in activity comment loop. 2537 * @return int 2538 */ 2539 function bp_activity_get_comment_depth( $comment = 0 ) { 2540 $depth = 0; 2541 2542 // Activity comment loop takes precedence. 2543 if ( isset( $GLOBALS['activities_template']->activity->current_comment->depth ) ) { 2544 $depth = $GLOBALS['activities_template']->activity->current_comment->depth; 2545 2546 // Get depth for activity comment manually. 2547 } elseif ( ! empty( $comment ) ) { 2548 // We passed an activity ID, so fetch the activity object. 2549 if ( is_int( $comment ) ) { 2550 $comment = new BP_Activity_Activity( $comment ); 2551 } 2552 2553 // Recurse through activity tree to find the depth. 2554 if ( is_object( $comment ) && isset( $comment->type ) && 'activity_comment' === $comment->type ) { 2555 // Fetch the entire root comment tree... ugh. 2556 $comments = BP_Activity_Activity::get_activity_comments( $comment->item_id, 1, constant( 'PHP_INT_MAX' ) ); 2557 2558 // Recursively find our comment object from the comment tree. 2559 $iterator = new RecursiveArrayIterator( $comments ); 2560 $recursive = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::SELF_FIRST ); 2561 foreach ( $recursive as $cid => $cobj ) { 2562 // Skip items that are not a comment object. 2563 if ( ! is_numeric( $cid ) || ! is_object( $cobj ) ) { 2564 continue; 2565 } 2566 2567 // We found the activity comment! Set the depth. 2568 if ( $cid === $comment->id && isset( $cobj->depth ) ) { 2569 $depth = $cobj->depth; 2570 break; 2571 } 2572 } 2573 } 2574 } 2575 2576 /** 2577 * Filters the comment depth of the current activity comment. 2578 * 2579 * @since 2.0.0 2580 * 2581 * @param int $depth Depth for the current activity comment. 2582 */ 2583 return apply_filters( 'bp_activity_get_comment_depth', $depth ); 2584 } 2585 2586 /** 2587 * Output the activity comment link. 2588 * 2589 * @since 1.2.0 2590 * 2591 */ 2592 function bp_activity_comment_link() { 2593 echo bp_get_activity_comment_link(); 2594 } 2595 2596 /** 2597 * Return the activity comment link. 2598 * 2599 * @since 1.2.0 2600 * 2601 * @global object $activities_template {@link BP_Activity_Template} 2602 * 2603 * @return string The activity comment link. 2604 */ 2605 function bp_get_activity_comment_link() { 2606 global $activities_template; 2607 2608 /** 2609 * Filters the comment link for the current activity comment. 2610 * 2611 * @since 1.2.0 2612 * 2613 * @param string $value Constructed URL parameters with activity IDs. 2614 */ 2615 return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id ); 2616 } 2617 2618 /** 2619 * Output the activity comment form no JavaScript display CSS. 2620 * 2621 * @since 1.2.0 2622 * 2623 */ 2624 function bp_activity_comment_form_nojs_display() { 2625 echo bp_get_activity_comment_form_nojs_display(); 2626 } 2627 2628 /** 2629 * Return the activity comment form no JavaScript display CSS. 2630 * 2631 * @since 1.2.0 2632 * 2633 * @global object $activities_template {@link BP_Activity_Template} 2634 * 2635 * @return string|false The activity comment form no JavaScript 2636 * display CSS. False on failure. 2637 */ 2638 function bp_get_activity_comment_form_nojs_display() { 2639 global $activities_template; 2640 2641 if ( isset( $_GET['ac'] ) && ( $_GET['ac'] === ( $activities_template->activity->id . '/' ) ) ) { 2642 return 'style="display: block"'; 2643 } 2644 2645 return false; 2646 } 2647 2648 /** 2649 * Output the activity comment form action. 2650 * 2651 * @since 1.2.0 2652 * 2653 */ 2654 function bp_activity_comment_form_action() { 2655 echo bp_get_activity_comment_form_action(); 2656 } 2657 2658 /** 2659 * Return the activity comment form action. 2660 * 2661 * @since 1.2.0 2662 * 2663 * 2664 * @return string The activity comment form action. 2665 */ 2666 function bp_get_activity_comment_form_action() { 2667 2668 /** 2669 * Filters the activity comment form action URL. 2670 * 2671 * @since 1.2.0 2672 * 2673 * @param string $value URL to use in the comment form's action attribute. 2674 */ 2675 return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) ); 2676 } 2677 2678 /** 2679 * Output the activity permalink ID. 2680 * 2681 * @since 1.2.0 2682 * 2683 */ 2684 function bp_activity_permalink_id() { 2685 echo bp_get_activity_permalink_id(); 2686 } 2687 2688 /** 2689 * Return the activity permalink ID. 2690 * 2691 * @since 1.2.0 2692 * 2693 * 2694 * @return string The activity permalink ID. 2695 */ 2696 function bp_get_activity_permalink_id() { 2697 2698 /** 2699 * Filters the activity action permalink ID. 2700 * 2701 * @since 1.2.0 2702 * 2703 * @param string $value Current action for the activity item. 2704 */ 2705 return apply_filters( 'bp_get_activity_permalink_id', bp_current_action() ); 2706 } 2707 2708 /** 2709 * Output the activity thread permalink. 2710 * 2711 * @since 1.2.0 2712 * 2713 */ 2714 function bp_activity_thread_permalink() { 2715 echo esc_url( bp_get_activity_thread_permalink() ); 2716 } 2717 2718 /** 2719 * Return the activity thread permalink. 2720 * 2721 * @since 1.2.0 2722 * 2723 * 2724 * @return string $link The activity thread permalink. 2725 */ 2726 function bp_get_activity_thread_permalink() { 2727 global $activities_template; 2728 2729 $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 2730 2731 /** 2732 * Filters the activity thread permalink. 2733 * 2734 * @since 1.2.0 2735 * 2736 * @param string $link The activity thread permalink. 2737 */ 2738 return apply_filters( 'bp_get_activity_thread_permalink', $link ); 2739 } 2740 2741 /** 2742 * Output the activity comment permalink. 2743 * 2744 * @since 1.8.0 2745 * 2746 */ 2747 function bp_activity_comment_permalink() { 2748 echo esc_url( bp_get_activity_comment_permalink() ); 2749 } 2750 /** 2751 * Return the activity comment permalink. 2752 * 2753 * @since 1.8.0 2754 * 2755 * @return string $link The activity comment permalink. 2756 */ 2757 function bp_get_activity_comment_permalink() { 2758 global $activities_template; 2759 2760 $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 2761 2762 // Used for filter below. 2763 $comment_id = isset( $activities_template->activity->current_comment->id ) 2764 ? $activities_template->activity->current_comment->id 2765 : 0; 2766 2767 /** 2768 * Filters the activity comment permalink. 2769 * 2770 * @since 1.8.0 2771 * 2772 * @param string $link Activity comment permalink. 2773 * @param int $comment_id ID for the current activity comment. 2774 */ 2775 return apply_filters( 'bp_get_activity_comment_permalink', $link, $comment_id ); 2776 } 2777 2778 /** 2779 * Output the activity favorite link. 2780 * 2781 * @since 1.2.0 2782 * 2783 */ 2784 function bp_activity_favorite_link() { 2785 echo bp_get_activity_favorite_link(); 2786 } 2787 2788 /** 2789 * Return the activity favorite link. 2790 * 2791 * @since 1.2.0 2792 * 2793 * @global object $activities_template {@link BP_Activity_Template} 2794 * 2795 * @return string The activity favorite link. 2796 */ 2797 function bp_get_activity_favorite_link() { 2798 global $activities_template; 2799 2800 /** 2801 * Filters the activity favorite link. 2802 * 2803 * @since 1.2.0 2804 * 2805 * @param string $value Constructed link for favoriting the activity comment. 2806 */ 2807 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' ) ); 2808 } 2809 2810 /** 2811 * Output the activity unfavorite link. 2812 * 2813 * @since 1.2.0 2814 * 2815 */ 2816 function bp_activity_unfavorite_link() { 2817 echo bp_get_activity_unfavorite_link(); 2818 } 2819 2820 /** 2821 * Return the activity unfavorite link. 2822 * 2823 * @since 1.2.0 2824 * 2825 * @global object $activities_template {@link BP_Activity_Template} 2826 * 2827 * @return string The activity unfavorite link. 2828 */ 2829 function bp_get_activity_unfavorite_link() { 2830 global $activities_template; 2831 2832 /** 2833 * Filters the activity unfavorite link. 2834 * 2835 * @since 1.2.0 2836 * 2837 * @param string $value Constructed link for unfavoriting the activity comment. 2838 */ 2839 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' ) ); 2840 } 2841 2842 /** 2843 * Output the activity CSS class. 2844 * 2845 * @since 1.0.0 2846 * 2847 */ 2848 function bp_activity_css_class() { 2849 echo bp_get_activity_css_class(); 2850 } 2851 2852 /** 2853 * Return the current activity item's CSS class. 2854 * 2855 * @since 1.0.0 2856 * 2857 * @global object $activities_template {@link BP_Activity_Template} 2858 * 2859 * @return string The activity item's CSS class. 2860 */ 2861 function bp_get_activity_css_class() { 2862 global $activities_template; 2863 2864 /** 2865 * Filters the available mini activity actions available as CSS classes. 2866 * 2867 * @since 1.2.0 2868 * 2869 * @param array $value Array of classes used to determine classes applied to HTML element. 2870 */ 2871 $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array( 2872 'friendship_accepted', 2873 'friendship_created', 2874 'new_blog', 2875 'joined_group', 2876 'created_group', 2877 'new_member' 2878 ) ); 2879 2880 $class = ' activity-item'; 2881 2882 if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) ) { 2883 $class .= ' mini'; 2884 } 2885 2886 if ( bp_activity_get_comment_count() && bp_activity_can_comment() ) { 2887 $class .= ' has-comments'; 2888 } 2889 2890 /** 2891 * Filters the determined classes to add to the HTML element. 2892 * 2893 * @since 1.0.0 2894 * 2895 * @param string $value Classes to be added to the HTML element. 2896 */ 2897 return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class ); 2898 } 2899 2900 /** 2901 * Output the activity delete link. 2902 * 2903 * @since 1.1.0 2904 * 2905 */ 2906 function bp_activity_delete_link() { 2907 echo bp_get_activity_delete_link(); 2908 } 2909 2910 /** 2911 * Return the activity delete link. 2912 * 2913 * @since 1.1.0 2914 * 2915 * @global object $activities_template {@link BP_Activity_Template} 2916 * 2917 * @return string $link Activity delete link. Contains $redirect_to arg 2918 * if on single activity page. 2919 */ 2920 function bp_get_activity_delete_link() { 2921 2922 $url = bp_get_activity_delete_url(); 2923 $class = 'delete-activity'; 2924 2925 // Determine if we're on a single activity page, and customize accordingly. 2926 if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { 2927 $class = 'delete-activity-single'; 2928 } elseif ( 'activity_comment' === bp_get_activity_type() ) { 2929 $class = 'acomment-delete'; 2930 } 2931 2932 $link = '<a href="' . esc_url( $url ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>'; 2933 2934 /** 2935 * Filters the activity delete link. 2936 * 2937 * @since 1.1.0 2938 * 2939 * @param string $link Activity delete HTML link. 2940 */ 2941 return apply_filters( 'bp_get_activity_delete_link', $link ); 2942 } 2943 2944 /** 2945 * Output the URL to delete a single activity stream item. 2946 * 2947 * @since 2.1.0 2948 * 2949 */ 2950 function bp_activity_delete_url() { 2951 echo esc_url( bp_get_activity_delete_url() ); 2952 } 2953 /** 2954 * Return the URL to delete a single activity item. 2955 * 2956 * @since 2.1.0 2957 * 2958 * @global object $activities_template {@link BP_Activity_Template} 2959 * 2960 * @return string $link Activity delete link. Contains $redirect_to arg 2961 * if on single activity page. 2962 */ 2963 function bp_get_activity_delete_url() { 2964 global $activities_template; 2965 2966 $activity_id = 0; 2967 if ( isset( $activities_template->activity->id ) ) { 2968 $activity_id = (int) $activities_template->activity->id; 2969 } 2970 2971 $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activity_id ); 2972 2973 // Determine if we're on a single activity page, and customize accordingly. 2974 if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { 2975 $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url ); 2976 } elseif ( 'activity_comment' === bp_get_activity_type() ) { 2977 $url = add_query_arg( 'cid', $activity_id, $url ); 2978 } 2979 2980 $url = wp_nonce_url( $url, 'bp_activity_delete_link' ); 2981 2982 /** 2983 * Filters the activity delete URL. 2984 * 2985 * @since 2.1.0 2986 * 2987 * @param string $url Activity delete URL. 2988 */ 2989 return apply_filters( 'bp_get_activity_delete_url', $url ); 2990 } 2991 2992 /** 2993 * Output the activity latest update link. 2994 * 2995 * @since 1.2.0 2996 * 2997 * @see bp_get_activity_latest_update() for description of parameters. 2998 * 2999 * @param int $user_id See {@link bp_get_activity_latest_update()} for description. 3000 */ 3001 function bp_activity_latest_update( $user_id = 0 ) { 3002 echo bp_get_activity_latest_update( $user_id ); 3003 } 3004 3005 /** 3006 * Return the activity latest update link. 3007 * 3008 * @since 1.2.0 3009 * 3010 * 3011 * @param int $user_id If empty, will fall back on displayed user. 3012 * @return string|bool $latest_update The activity latest update link. 3013 * False on failure. 3014 */ 3015 function bp_get_activity_latest_update( $user_id = 0 ) { 3016 3017 if ( empty( $user_id ) ) { 3018 $user_id = bp_displayed_user_id(); 3019 } 3020 3021 if ( bp_is_user_inactive( $user_id ) ) { 3022 return false; 3023 } 3024 3025 if ( !$update = bp_get_user_meta( $user_id, 'bp_latest_update', true ) ) { 3026 return false; 3027 } 3028 3029 /** 3030 * Filters the latest update excerpt. 3031 * 3032 * @since 1.2.10 3033 * @since 2.6.0 Added the `$user_id` parameter. 3034 * 3035 * @param string $value The excerpt for the latest update. 3036 * @param int $user_id ID of the queried user. 3037 */ 3038 $latest_update = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], bp_activity_get_excerpt_length() ) ) ), $user_id ); 3039 3040 $latest_update = sprintf( 3041 '%s <a href="%s">%s</a>', 3042 $latest_update, 3043 esc_url_raw( bp_activity_get_permalink( $update['id'] ) ), 3044 esc_attr__( 'View', 'buddypress' ) 3045 ); 3046 3047 /** 3048 * Filters the latest update excerpt with view link appended to the end. 3049 * 3050 * @since 1.2.0 3051 * @since 2.6.0 Added the `$user_id` parameter. 3052 * 3053 * @param string $latest_update The latest update with "view" link appended to it. 3054 * @param int $user_id ID of the queried user. 3055 */ 3056 return apply_filters( 'bp_get_activity_latest_update', $latest_update, $user_id ); 3057 } 3058 3059 /** 3060 * Output the activity filter links. 3061 * 3062 * @since 1.1.0 3063 * 3064 * @see bp_get_activity_filter_links() for description of parameters. 3065 * 3066 * @param array|bool $args See {@link bp_get_activity_filter_links()} for description. 3067 */ 3068 function bp_activity_filter_links( $args = false ) { 3069 echo bp_get_activity_filter_links( $args ); 3070 } 3071 3072 /** 3073 * Return the activity filter links. 3074 * 3075 * @since 1.1.0 3076 * 3077 * 3078 * @param array|bool $args { 3079 * @type string $style The type of markup to use for the links. 3080 * 'list', 'paragraph', or 'span'. Default: 'list'. 3081 * } 3082 * @return string|bool $component_links The activity filter links. 3083 * False on failure. 3084 */ 3085 function bp_get_activity_filter_links( $args = false ) { 3086 3087 $r = bp_parse_args( 3088 $args, 3089 array( 3090 'style' => 'list', 3091 ) 3092 ); 3093 3094 // Define local variable. 3095 $component_links = array(); 3096 3097 // Fetch the names of components that have activity recorded in the DB. 3098 $components = BP_Activity_Activity::get_recorded_components(); 3099 3100 if ( empty( $components ) ) { 3101 return false; 3102 } 3103 3104 foreach ( (array) $components as $component ) { 3105 3106 // Skip the activity comment filter. 3107 if ( 'activity' == $component ) { 3108 continue; 3109 } 3110 3111 if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] ) { 3112 $selected = ' class="selected"'; 3113 } else { 3114 $selected = ''; 3115 } 3116 3117 $component = esc_attr( $component ); 3118 3119 switch ( $r['style'] ) { 3120 case 'list': 3121 $tag = 'li'; 3122 $before = '<li id="afilter-' . $component . '"' . $selected . '>'; 3123 $after = '</li>'; 3124 break; 3125 case 'paragraph': 3126 $tag = 'p'; 3127 $before = '<p id="afilter-' . $component . '"' . $selected . '>'; 3128 $after = '</p>'; 3129 break; 3130 case 'span': 3131 $tag = 'span'; 3132 $before = '<span id="afilter-' . $component . '"' . $selected . '>'; 3133 $after = '</span>'; 3134 break; 3135 } 3136 3137 $link = add_query_arg( 'afilter', $component ); 3138 $link = remove_query_arg( 'acpage' , $link ); 3139 3140 /** 3141 * Filters the activity filter link URL for the current activity component. 3142 * 3143 * @since 1.1.0 3144 * 3145 * @param string $link The URL for the current component. 3146 * @param string $component The current component getting links constructed for. 3147 */ 3148 $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component ); 3149 3150 $component_links[] = $before . '<a href="' . esc_url( $link ) . '">' . ucwords( $component ) . '</a>' . $after; 3151 } 3152 3153 $link = remove_query_arg( 'afilter' , $link ); 3154 3155 if ( isset( $_GET['afilter'] ) ) { 3156 $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_url( $link ) . '">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>'; 3157 } 3158 3159 /** 3160 * Filters all of the constructed filter links. 3161 * 3162 * @since 1.1.0 3163 * @since 2.6.0 Added the `$r` parameter. 3164 * 3165 * @param string $value All of the links to be displayed to the user. 3166 * @param array $r Array of parsed arguments. 3167 */ 3168 return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ), $r ); 3169 } 3170 3171 /** 3172 * Determine if a comment can be made on an activity item. 3173 * 3174 * @since 1.2.0 3175 * 3176 * @global object $activities_template {@link BP_Activity_Template} 3177 * 3178 * @return bool $can_comment True if item can receive comments. 3179 */ 3180 function bp_activity_can_comment() { 3181 global $activities_template; 3182 $bp = buddypress(); 3183 3184 // Determine ability to comment based on activity type name. 3185 $activity_type = bp_get_activity_type(); 3186 3187 // Get the 'comment-reply' support for the current activity type. 3188 $can_comment = bp_activity_type_supports( $activity_type, 'comment-reply' ); 3189 3190 // Neutralize activity_comment. 3191 if ( 'activity_comment' === $activity_type ) { 3192 $can_comment = false; 3193 } 3194 3195 /** 3196 * Filters whether a comment can be made on an activity item. 3197 * 3198 * @since 1.5.0 3199 * @since 2.5.0 Use $activity_type instead of $activity_name for the second parameter. 3200 * 3201 * @param bool $can_comment Status on if activity can be commented on. 3202 * @param string $activity_type Current activity type being checked on. 3203 */ 3204 return apply_filters( 'bp_activity_can_comment', $can_comment, $activity_type ); 3205 } 3206 3207 /** 3208 * Determine whether a comment can be made on an activity reply item. 3209 * 3210 * @since 1.5.0 3211 * 3212 * @param bool|object $comment Activity comment. 3213 * @return bool $can_comment True if comment can receive comments, 3214 * otherwise false. 3215 */ 3216 function bp_activity_can_comment_reply( $comment = false ) { 3217 3218 // Assume activity can be commented on. 3219 $can_comment = true; 3220 3221 // Check that comment exists. 3222 if ( empty( $comment ) ) { 3223 $comment = bp_activity_current_comment(); 3224 } 3225 3226 if ( ! empty( $comment ) ) { 3227 3228 // Fall back on current comment in activity loop. 3229 $comment_depth = isset( $comment->depth ) 3230 ? intval( $comment->depth ) 3231 : bp_activity_get_comment_depth( $comment ); 3232 3233 // Threading is turned on, so check the depth. 3234 if ( get_option( 'thread_comments' ) ) { 3235 $can_comment = (bool) ( $comment_depth < get_option( 'thread_comments_depth' ) ); 3236 3237 // No threading for comment replies if no threading for comments. 3238 } else { 3239 $can_comment = false; 3240 } 3241 } 3242 3243 /** 3244 * Filters whether a comment can be made on an activity reply item. 3245 * 3246 * @since 1.5.0 3247 * 3248 * @param bool $can_comment Status on if activity reply can be commented on. 3249 * @param object $comment Current comment object being checked on. 3250 */ 3251 return (bool) apply_filters( 'bp_activity_can_comment_reply', $can_comment, $comment ); 3252 } 3253 3254 /** 3255 * Determine whether favorites are allowed. 3256 * 3257 * Defaults to true, but can be modified by plugins. 3258 * 3259 * @since 1.5.0 3260 * 3261 * @return bool True if comment can receive comments. 3262 */ 3263 function bp_activity_can_favorite() { 3264 3265 /** 3266 * Filters whether or not users can favorite activity items. 3267 * 3268 * @since 1.5.0 3269 * 3270 * @param bool $value Whether or not favoriting is enabled. 3271 */ 3272 return apply_filters( 'bp_activity_can_favorite', true ); 3273 } 3274 3275 /** 3276 * Output the total favorite count for a specified user. 3277 * 3278 * @since 1.2.0 3279 * 3280 * @see bp_get_total_favorite_count_for_user() for description of parameters. 3281 * 3282 * @param int $user_id See {@link bp_get_total_favorite_count_for_user()}. 3283 */ 3284 function bp_total_favorite_count_for_user( $user_id = 0 ) { 3285 echo bp_get_total_favorite_count_for_user( $user_id ); 3286 } 3287 3288 /** 3289 * Return the total favorite count for a specified user. 3290 * 3291 * @since 1.2.0 3292 * 3293 * 3294 * @param int $user_id ID of user being queried. Default: displayed user ID. 3295 * @return int The total favorite count for the specified user. 3296 */ 3297 function bp_get_total_favorite_count_for_user( $user_id = 0 ) { 3298 $retval = false; 3299 3300 if ( bp_activity_can_favorite() ) { 3301 // Default to displayed user if none is passed. 3302 $user_id = empty( $user_id ) 3303 ? bp_displayed_user_id() 3304 : $user_id; 3305 3306 // Get user meta if user ID exists. 3307 if ( ! empty( $user_id ) ) { 3308 $retval = bp_activity_total_favorites_for_user( $user_id ); 3309 } 3310 } 3311 3312 /** 3313 * Filters the total favorite count for a user. 3314 * 3315 * @since 1.2.0 3316 * @since 2.6.0 Added the `$user_id` parameter. 3317 * 3318 * @param int|bool $retval Total favorite count for a user. False on no favorites. 3319 * @param int $user_id ID of the queried user. 3320 */ 3321 return apply_filters( 'bp_get_total_favorite_count_for_user', $retval, $user_id ); 3322 } 3323 3324 3325 /** 3326 * Output the total mention count for a specified user. 3327 * 3328 * @since 1.2.0 3329 * 3330 * @see bp_get_total_mention_count_for_user() for description of parameters. 3331 * 3332 * @param int $user_id See {@link bp_get_total_mention_count_for_user()}. 3333 */ 3334 function bp_total_mention_count_for_user( $user_id = 0 ) { 3335 echo bp_get_total_mention_count_for_user( $user_id ); 3336 } 3337 3338 /** 3339 * Return the total mention count for a specified user. 3340 * 3341 * @since 1.2.0 3342 * 3343 * 3344 * @param int $user_id ID of user being queried. Default: displayed user ID. 3345 * @return int The total mention count for the specified user. 3346 */ 3347 function bp_get_total_mention_count_for_user( $user_id = 0 ) { 3348 3349 // Default to displayed user if none is passed. 3350 $user_id = empty( $user_id ) 3351 ? bp_displayed_user_id() 3352 : $user_id; 3353 3354 // Get user meta if user ID exists. 3355 $retval = ! empty( $user_id ) 3356 ? bp_get_user_meta( $user_id, 'bp_new_mention_count', true ) 3357 : false; 3358 3359 /** 3360 * Filters the total mention count for a user. 3361 * 3362 * @since 1.2.0 3363 * @since 2.6.0 Added the `$user_id` parameter. 3364 * 3365 * @param int|bool $retval Total mention count for a user. False on no mentions. 3366 * @param int $user_id ID of the queried user. 3367 */ 3368 return apply_filters( 'bp_get_total_mention_count_for_user', $retval, $user_id ); 3369 } 3370 3371 /** 3372 * Output the public message link for displayed user. 3373 * 3374 * @since 1.2.0 3375 * 3376 */ 3377 function bp_send_public_message_link() { 3378 echo esc_url( bp_get_send_public_message_link() ); 3379 } 3380 3381 /** 3382 * Return the public message link for the displayed user. 3383 * 3384 * @since 1.2.0 3385 * 3386 * 3387 * @return string The public message link for the displayed user. 3388 */ 3389 function bp_get_send_public_message_link() { 3390 3391 // No link if not logged in, not looking at someone else's profile. 3392 if ( ! is_user_logged_in() || ! bp_is_user() || bp_is_my_profile() ) { 3393 $retval = ''; 3394 } else { 3395 $args = array( 'r' => bp_get_displayed_user_mentionname() ); 3396 $url = add_query_arg( $args, bp_get_activity_directory_permalink() ); 3397 $retval = wp_nonce_url( $url ); 3398 } 3399 3400 /** 3401 * Filters the public message link for the displayed user. 3402 * 3403 * @since 1.2.0 3404 * 3405 * @param string $retval The URL for the public message link. 3406 */ 3407 return apply_filters( 'bp_get_send_public_message_link', $retval ); 3408 } 3409 3410 /** 3411 * Recurse through all activity comments and return the activity comment IDs. 3412 * 3413 * @since 2.0.0 3414 * 3415 * @param array $activity Array of activities generated from {@link bp_activity_get()}. 3416 * @param array $activity_ids Used for recursion purposes in this function. 3417 * @return array 3418 */ 3419 function bp_activity_recurse_comments_activity_ids( $activity = array(), $activity_ids = array() ) { 3420 if ( is_array( $activity ) && ! empty( $activity['activities'] ) ) { 3421 $activity = $activity['activities'][0]; 3422 } 3423 3424 if ( ! empty( $activity->children ) ) { 3425 foreach ($activity->children as $child ) { 3426 $activity_ids[] = $child->id; 3427 3428 if( ! empty( $child->children ) ) { 3429 $activity_ids = bp_activity_recurse_comments_activity_ids( $child, $activity_ids ); 3430 } 3431 } 3432 } 3433 3434 return $activity_ids; 3435 } 3436 3437 /** 3438 * Output the mentioned user display name. 3439 * 3440 * @since 1.2.0 3441 * 3442 * @see bp_get_mentioned_user_display_name() for description of parameters. 3443 * 3444 * @param int|string|bool $user_id_or_username See {@link bp_get_mentioned_user_display_name()}. 3445 */ 3446 function bp_mentioned_user_display_name( $user_id_or_username = false ) { 3447 echo bp_get_mentioned_user_display_name( $user_id_or_username ); 3448 } 3449 3450 /** 3451 * Returns the mentioned user display name. 3452 * 3453 * @since 1.2.0 3454 * 3455 * 3456 * @param int|string|bool $user_id_or_username User ID or username. 3457 * @return string The mentioned user's display name. 3458 */ 3459 function bp_get_mentioned_user_display_name( $user_id_or_username = false ) { 3460 3461 // Get user display name. 3462 $name = bp_core_get_user_displayname( $user_id_or_username ); 3463 3464 // If user somehow has no name, return this really lame string. 3465 if ( empty( $name ) ) { 3466 $name = __( 'a user', 'buddypress' ); 3467 } 3468 3469 /** 3470 * Filters the mentioned user display name. 3471 * 3472 * @since 1.2.0 3473 * 3474 * @param string $name Display name for the mentioned user. 3475 * @param int|string $user_id_or_username User ID or username use for query. 3476 */ 3477 return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username ); 3478 } 3479 3480 /** 3481 * Output button for sending a public message (an @-mention). 3482 * 3483 * @since 1.2.0 3484 * 3485 * @see bp_get_send_public_message_button() for description of parameters. 3486 * 3487 * @param array|string $args See {@link bp_get_send_public_message_button()}. 3488 */ 3489 function bp_send_public_message_button( $args = '' ) { 3490 echo bp_get_send_public_message_button( $args ); 3491 } 3492 3493 /** 3494 * Return button for sending a public message (an @-mention). 3495 * 3496 * @since 1.2.0 3497 * 3498 * 3499 * @param array|string $args { 3500 * All arguments are optional. See {@link BP_Button} for complete 3501 * descriptions. 3502 * @type string $id Default: 'public_message'. 3503 * @type string $component Default: 'activity'. 3504 * @type bool $must_be_logged_in Default: true. 3505 * @type bool $block_self Default: true. 3506 * @type string $wrapper_id Default: 'post-mention'. 3507 * @type string $link_href Default: the public message link for 3508 * the current member in the loop. 3509 * @type string $link_text Default: 'Public Message'. 3510 * @type string $link_class Default: 'activity-button mention'. 3511 * } 3512 * @return string The button for sending a public message. 3513 */ 3514 function bp_get_send_public_message_button( $args = '' ) { 3515 3516 $r = bp_parse_args( 3517 $args, 3518 array( 3519 'id' => 'public_message', 3520 'component' => 'activity', 3521 'must_be_logged_in' => true, 3522 'block_self' => true, 3523 'wrapper_id' => 'post-mention', 3524 'link_href' => bp_get_send_public_message_link(), 3525 'link_text' => __( 'Public Message', 'buddypress' ), 3526 'link_class' => 'activity-button mention', 3527 ) 3528 ); 3529 3530 /** 3531 * Filters the public message button HTML. 3532 * 3533 * @since 1.2.10 3534 * 3535 * @param array $r Array of arguments for the public message button HTML. 3536 */ 3537 return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $r ) ); 3538 } 3539 3540 /** 3541 * Output the activity post form action. 3542 * 3543 * @since 1.2.0 3544 * 3545 */ 3546 function bp_activity_post_form_action() { 3547 echo bp_get_activity_post_form_action(); 3548 } 3549 3550 /** 3551 * Return the activity post form action. 3552 * 3553 * @since 1.2.0 3554 * 3555 * 3556 * @return string The activity post form action. 3557 */ 3558 function bp_get_activity_post_form_action() { 3559 3560 /** 3561 * Filters the action url used for the activity post form. 3562 * 3563 * @since 1.2.0 3564 * 3565 * @param string $value URL to be used for the activity post form. 3566 */ 3567 return apply_filters( 'bp_get_activity_post_form_action', home_url( bp_get_activity_root_slug() . '/post/' ) ); 3568 } 3569 3570 /** 3571 * Echo a list of linked avatars of users who have commented on the current activity item. 3572 * 3573 * Use this function to easily output activity comment authors' avatars. 3574 * 3575 * Avatars are wrapped in <li> elements, but you've got to provide your own 3576 * <ul> or <ol> wrapper markup. 3577 * 3578 * @since 1.7.0 3579 * 3580 * @see bp_core_fetch_avatar() for a description of arguments. 3581 * 3582 * @param array $args See {@link bp_core_fetch_avatar()}. 3583 */ 3584 function bp_activity_comments_user_avatars( $args = array() ) { 3585 3586 $r = bp_parse_args( 3587 $args, 3588 array( 3589 'height' => false, 3590 'html' => true, 3591 'type' => 'thumb', 3592 'width' => false, 3593 ) 3594 ); 3595 3596 // Get the user IDs of everyone who has left a comment to the current activity item. 3597 $user_ids = bp_activity_get_comments_user_ids(); 3598 $output = array(); 3599 $retval = ''; 3600 3601 if ( ! empty( $user_ids ) ) { 3602 foreach ( (array) $user_ids as $user_id ) { 3603 3604 // Skip an empty user ID. 3605 if ( empty( $user_id ) ) { 3606 continue; 3607 } 3608 3609 // Get profile link for this user. 3610 $profile_link = bp_core_get_user_domain( $user_id ); 3611 3612 // Get avatar for this user. 3613 $image_html = bp_core_fetch_avatar( array( 3614 'item_id' => $user_id, 3615 'height' => $r['height'], 3616 'html' => $r['html'], 3617 'type' => $r['type'], 3618 'width' => $r['width'] 3619 ) ); 3620 3621 // If user has link & avatar, add them to the output array. 3622 if ( ! empty( $profile_link ) && ! empty( $image_html ) ) { 3623 $output[] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $profile_link ), $image_html ); 3624 } 3625 } 3626 3627 // If output array is not empty, wrap everything in some list items. 3628 if ( ! empty( $output ) ) { 3629 $retval = '<li>' . implode( '</li><li>', $output ) . '</li>'; 3630 } 3631 } 3632 3633 /** 3634 * Filters the list of linked avatars for users who have commented on the current activity item. 3635 * 3636 * @since 1.7.0 3637 * 3638 * @param string $retval HTML markup for the list of avatars. 3639 * @param array $r Array of arguments used for each avatar. 3640 * @param array $output Array of each avatar found, before imploded into single string. 3641 */ 3642 echo apply_filters( 'bp_activity_comments_user_avatars', $retval, $r, $output ); 3643 } 3644 3645 /** 3646 * Return the IDs of every user who's left a comment on the current activity item. 3647 * 3648 * @since 1.7.0 3649 * 3650 * @return bool|array An array of IDs, or false if none are found. 3651 */ 3652 function bp_activity_get_comments_user_ids() { 3653 global $activities_template; 3654 3655 $user_ids = ! empty( $activities_template->activity->children ) 3656 ? (array) bp_activity_recurse_comments_user_ids( $activities_template->activity->children ) 3657 : array(); 3658 3659 /** 3660 * Filters the list of user IDs for the current activity item. 3661 * 3662 * @since 1.7.0 3663 * 3664 * @param array $value Array of unique user IDs for the current activity item. 3665 */ 3666 return apply_filters( 'bp_activity_get_comments_user_ids', array_unique( $user_ids ) ); 3667 } 3668 3669 /** 3670 * Recurse through all activity comments and collect the IDs of the users who wrote them. 3671 * 3672 * @since 1.7.0 3673 * 3674 * @param array $comments Array of {@link BP_Activity_Activity} items. 3675 * @return array Array of user IDs. 3676 */ 3677 function bp_activity_recurse_comments_user_ids( array $comments = array() ) { 3678 3679 // Default user ID's array. 3680 $user_ids = array(); 3681 3682 // Loop through comments and try to get user ID's. 3683 if ( ! empty( $comments ) ) { 3684 foreach ( $comments as $comment ) { 3685 3686 // If a user is a spammer, their activity items will have been 3687 // automatically marked as spam. Skip these. 3688 if ( ! empty( $comment->is_spam ) ) { 3689 continue; 3690 } 3691 3692 // Add user ID to array. 3693 $user_ids[] = $comment->user_id; 3694 3695 // Check for commentception. 3696 if ( ! empty( $comment->children ) ) { 3697 $user_ids = array_merge( $user_ids, bp_activity_recurse_comments_user_ids( $comment->children ) ); 3698 } 3699 } 3700 } 3701 3702 /** 3703 * Filters the list of user IDs for the current activity comment item. 3704 * 3705 * @since 2.1.0 3706 * 3707 * @param array $user_ids Array of user IDs for the current activity comment item. 3708 * @param array $comments Array of comments being checked for user IDs. 3709 */ 3710 return apply_filters( 'bp_activity_recurse_comments_user_ids', $user_ids, $comments ); 3711 } 3712 3713 /** 3714 * Output the mentionname for the displayed user. 3715 * 3716 * @since 1.9.0 3717 */ 3718 function bp_displayed_user_mentionname() { 3719 echo bp_get_displayed_user_mentionname(); 3720 } 3721 /** 3722 * Get the mentionname for the displayed user. 3723 * 3724 * @since 1.9.0 3725 * 3726 * @return string Mentionname for the displayed user, if available. 3727 */ 3728 function bp_get_displayed_user_mentionname() { 3729 3730 /** 3731 * Filters the mentionname for the displayed user. 3732 * 3733 * @since 1.9.0 3734 * 3735 * @param string $value The mentionanme for the displayed user. 3736 */ 3737 return apply_filters( 'bp_get_displayed_user_mentionname', bp_activity_get_user_mentionname( bp_displayed_user_id() ) ); 3738 } 3739 3740 /** 3741 * Echo a list of all registered activity types for use in dropdowns or checkbox lists. 3742 * 3743 * @since 1.7.0 3744 * 3745 * @param string $output Optional. Either 'select' or 'checkbox'. Default: 'select'. 3746 * @param array|string $args { 3747 * Optional extra arguments. 3748 * @type string $checkbox_name When returning checkboxes, sets the 'name' 3749 * attribute. 3750 * @type array|string $selected A list of types that should be checked/ 3751 * selected. 3752 * } 3753 */ 3754 function bp_activity_types_list( $output = 'select', $args = '' ) { 3755 3756 $args = bp_parse_args( 3757 $args, 3758 array( 3759 'checkbox_name' => 'bp_activity_types', 3760 'selected' => array(), 3761 ) 3762 ); 3763 3764 $activities = bp_activity_get_types(); 3765 natsort( $activities ); 3766 3767 // Loop through the activity types and output markup. 3768 foreach ( $activities as $type => $description ) { 3769 3770 // See if we need to preselect the current type. 3771 $checked = checked( true, in_array( $type, (array) $args['selected'] ), false ); 3772 $selected = selected( true, in_array( $type, (array) $args['selected'] ), false ); 3773 3774 // Switch output based on the element. 3775 switch ( $output ) { 3776 case 'select' : 3777 printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $type ), $selected, esc_html( $description ) ); 3778 break; 3779 case 'checkbox' : 3780 printf( '<label style="" for="%1$s[]">%2$s<input type="checkbox" id="%1$s[]" name="%1$s[]" value="%3$s" %4$s/></label>', esc_attr( $args['checkbox_name'] ), esc_html( $description ), esc_attr( $args['checkbox_name'] ), esc_attr( $args['checkbox_name'] ), esc_attr( $type ), $checked ); 3781 break; 3782 } 3783 3784 /** 3785 * Fires at the end of the listing of activity types. 3786 * 3787 * This is a variable action hook. The actual hook to use will depend on the output type specified. 3788 * Two default hooks are bp_activity_types_list_select and bp_activity_types_list_checkbox. 3789 * 3790 * @since 1.7.0 3791 * 3792 * @param array $args Array of arguments passed into function. 3793 * @param string $type Activity type being rendered in the output. 3794 * @param string $description Description of the activity type being rendered. 3795 */ 3796 do_action( 'bp_activity_types_list_' . $output, $args, $type, $description ); 3797 } 3798 3799 // Backpat with BP-Default for dropdown boxes only. 3800 if ( 'select' === $output ) { 3801 do_action( 'bp_activity_filter_options' ); 3802 } 3803 } 3804 3805 3806 /* RSS Feed Template Tags ****************************************************/ 3807 3808 /** 3809 * Output the sitewide activity feed link. 3810 * 3811 * @since 1.0.0 3812 * 3813 */ 3814 function bp_sitewide_activity_feed_link() { 3815 echo bp_get_sitewide_activity_feed_link(); 3816 } 3817 3818 /** 3819 * Returns the sitewide activity feed link. 3820 * 3821 * @since 1.0.0 3822 * 3823 * 3824 * @return string The sitewide activity feed link. 3825 */ 3826 function bp_get_sitewide_activity_feed_link() { 3827 3828 /** 3829 * Filters the sidewide activity feed link. 3830 * 3831 * @since 1.0.0 3832 * 3833 * @param string $value The feed link for sitewide activity. 3834 */ 3835 return apply_filters( 'bp_get_sitewide_activity_feed_link', bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/feed/' ); 3836 } 3837 3838 /** 3839 * Output the member activity feed link. 3840 * 3841 * @since 1.2.0 3842 * 3843 */ 3844 function bp_member_activity_feed_link() { 3845 echo bp_get_member_activity_feed_link(); 3846 } 3847 3848 /** 3849 * Output the member activity feed link. 3850 * 3851 * @since 1.0.0 3852 * @deprecated 1.2.0 3853 * 3854 * @todo properly deprecate in favor of bp_member_activity_feed_link(). 3855 * 3856 */ 3857 function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link(); } 3858 3859 /** 3860 * Return the member activity feed link. 3861 * 3862 * @since 1.2.0 3863 * 3864 * 3865 * @return string $link The member activity feed link. 3866 */ 3867 function bp_get_member_activity_feed_link() { 3868 3869 // Single member activity feed link. 3870 if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) ) { 3871 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/'; 3872 3873 // Friend feed link. 3874 } elseif ( bp_is_active( 'friends' ) && bp_is_current_action( bp_get_friends_slug() ) ) { 3875 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/'; 3876 3877 // Group feed link. 3878 } elseif ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) { 3879 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/'; 3880 3881 // Favorites activity feed link. 3882 } elseif ( 'favorites' === bp_current_action() ) { 3883 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/'; 3884 3885 // Mentions activity feed link. 3886 } elseif ( ( 'mentions' === bp_current_action() ) && bp_activity_do_mentions() ) { 3887 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/'; 3888 3889 // No feed link. 3890 } else { 3891 $link = ''; 3892 } 3893 3894 /** 3895 * Filters the member activity feed link. 3896 * 3897 * @since 1.0.0 3898 * 3899 * @param string $link URL for the member activity feed. 3900 */ 3901 return apply_filters( 'bp_get_activities_member_rss_link', $link ); 3902 } 3903 3904 /** 3905 * Return the member activity feed link. 3906 * 3907 * @since 1.0.0 3908 * @deprecated 1.2.0 3909 * 3910 * @todo properly deprecate in favor of bp_get_member_activity_feed_link(). 3911 * 3912 * 3913 * @return string The member activity feed link. 3914 */ 3915 function bp_get_activities_member_rss_link() { return bp_get_member_activity_feed_link(); } 3916 3917 3918 /** Template tags for RSS feed output ****************************************/ 3919 3920 /** 3921 * Outputs the activity feed item guid. 3922 * 3923 * @since 1.0.0 3924 * 3925 */ 3926 function bp_activity_feed_item_guid() { 3927 echo bp_get_activity_feed_item_guid(); 3928 } 3929 3930 /** 3931 * Returns the activity feed item guid. 3932 * 3933 * @since 1.2.0 3934 * 3935 * @global object $activities_template {@link BP_Activity_Template} 3936 * 3937 * @return string The activity feed item guid. 3938 */ 3939 function bp_get_activity_feed_item_guid() { 3940 global $activities_template; 3941 3942 /** 3943 * Filters the activity feed item guid. 3944 * 3945 * @since 1.1.3 3946 * 3947 * @param string $value Calculated md5 value for the activity feed item. 3948 */ 3949 return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) ); 3950 } 3951 3952 /** 3953 * Output the activity feed item title. 3954 * 3955 * @since 1.0.0 3956 * 3957 */ 3958 function bp_activity_feed_item_title() { 3959 echo bp_get_activity_feed_item_title(); 3960 } 3961 3962 /** 3963 * Return the activity feed item title. 3964 * 3965 * @since 1.0.0 3966 * 3967 * @global object $activities_template {@link BP_Activity_Template} 3968 * 3969 * @return string $title The activity feed item title. 3970 */ 3971 function bp_get_activity_feed_item_title() { 3972 global $activities_template; 3973 3974 if ( !empty( $activities_template->activity->action ) ) { 3975 $content = $activities_template->activity->action; 3976 } else { 3977 $content = $activities_template->activity->content; 3978 } 3979 3980 $content = explode( '<span', $content ); 3981 $title = strip_tags( ent2ncr( trim( convert_chars( $content[0] ) ) ) ); 3982 3983 if ( ':' === substr( $title, -1 ) ) { 3984 $title = substr( $title, 0, -1 ); 3985 } 3986 3987 if ( 'activity_update' === $activities_template->activity->type ) { 3988 $title .= ': ' . strip_tags( ent2ncr( trim( convert_chars( bp_create_excerpt( $activities_template->activity->content, 70, array( 'ending' => " […]" ) ) ) ) ) ); 3989 } 3990 3991 /** 3992 * Filters the activity feed item title. 3993 * 3994 * @since 1.0.0 3995 * 3996 * @param string $title The title for the activity feed item. 3997 */ 3998 return apply_filters( 'bp_get_activity_feed_item_title', $title ); 3999 } 4000 4001 /** 4002 * Output the activity feed item link. 4003 * 4004 * @since 1.0.0 4005 * 4006 */ 4007 function bp_activity_feed_item_link() { 4008 echo bp_get_activity_feed_item_link(); 4009 } 4010 4011 /** 4012 * Return the activity feed item link. 4013 * 4014 * @since 1.0.0 4015 * 4016 * @global object $activities_template {@link BP_Activity_Template} 4017 * 4018 * @return string The activity feed item link. 4019 */ 4020 function bp_get_activity_feed_item_link() { 4021 global $activities_template; 4022 4023 $retval = ! empty( $activities_template->activity->primary_link ) 4024 ? $activities_template->activity->primary_link 4025 : ''; 4026 4027 /** 4028 * Filters the activity feed item link. 4029 * 4030 * @since 1.0.0 4031 * 4032 * @param string $retval The URL for the activity feed item. 4033 */ 4034 return apply_filters( 'bp_get_activity_feed_item_link', $retval ); 4035 } 4036 4037 /** 4038 * Output the activity feed item date. 4039 * 4040 * @since 1.0.0 4041 * 4042 */ 4043 function bp_activity_feed_item_date() { 4044 echo bp_get_activity_feed_item_date(); 4045 } 4046 4047 /** 4048 * Return the activity feed item date. 4049 * 4050 * @since 1.0.0 4051 * 4052 * @global object $activities_template {@link BP_Activity_Template} 4053 * 4054 * @return string The activity feed item date. 4055 */ 4056 function bp_get_activity_feed_item_date() { 4057 global $activities_template; 4058 4059 $retval = ! empty( $activities_template->activity->date_recorded ) 4060 ? $activities_template->activity->date_recorded 4061 : ''; 4062 4063 /** 4064 * Filters the activity feed item date. 4065 * 4066 * @since 1.0.0 4067 * 4068 * @param string $retval The date for the activity feed item. 4069 */ 4070 return apply_filters( 'bp_get_activity_feed_item_date', $retval ); 4071 } 4072 4073 /** 4074 * Output the activity feed item description. 4075 * 4076 * @since 1.0.0 4077 * 4078 */ 4079 function bp_activity_feed_item_description() { 4080 echo bp_get_activity_feed_item_description(); 4081 } 4082 4083 /** 4084 * Return the activity feed item description. 4085 * 4086 * @since 1.0.0 4087 * 4088 * @global object $activities_template {@link BP_Activity_Template} 4089 * 4090 * @return string The activity feed item description. 4091 */ 4092 function bp_get_activity_feed_item_description() { 4093 global $activities_template; 4094 4095 // Get the content, if exists. 4096 $content = ! empty( $activities_template->activity->content ) 4097 ? $activities_template->activity->content 4098 : ''; 4099 4100 // Perform a few string conversions on the content, if it's not empty. 4101 if ( ! empty( $content ) ) { 4102 $content = ent2ncr( convert_chars( str_replace( '%s', '', $content ) ) ); 4103 } 4104 4105 /** 4106 * Filters the activity feed item description. 4107 * 4108 * @since 1.0.0 4109 * 4110 * @param string $content The description for the activity feed item. 4111 */ 4112 return apply_filters( 'bp_get_activity_feed_item_description', $content ); 4113 } 4114 4115 /** 4116 * Template tag so we can hook activity feed to <head>. 4117 * 4118 * @since 1.5.0 4119 * 4120 */ 4121 function bp_activity_sitewide_feed() { 4122 ?> 4123 4124 <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() ?>" /> 4125 4126 <?php 4127 } 4128 add_action( 'bp_head', 'bp_activity_sitewide_feed' ); 4129 4130 /** 4131 * Display available filters depending on the scope. 4132 * 4133 * @since 2.1.0 4134 * 4135 * @param string $context The current context. 'activity', 'member', 4136 * 'member_groups', 'group'. 4137 */ 4138 function bp_activity_show_filters( $context = '' ) { 4139 echo bp_get_activity_show_filters( $context ); 4140 } 4141 /** 4142 * Get available filters depending on the scope. 4143 * 4144 * @since 2.1.0 4145 * 4146 * @param string $context The current context. 'activity', 'member', 4147 * 'member_groups', 'group'. 4148 * 4149 * @return string HTML for <option> values. 4150 */ 4151 function bp_get_activity_show_filters( $context = '' ) { 4152 $filters = array(); 4153 $actions = bp_activity_get_actions_for_context( $context ); 4154 foreach ( $actions as $action ) { 4155 // Friends activity collapses two filters into one. 4156 if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) { 4157 $action['key'] = 'friendship_accepted,friendship_created'; 4158 } 4159 4160 // The 'activity_update' filter is already used by the Activity component. 4161 if ( 'bp_groups_format_activity_action_group_activity_update' === $action['format_callback'] ) { 4162 continue; 4163 } 4164 4165 $filters[ $action['key'] ] = $action['label']; 4166 } 4167 4168 /** 4169 * Filters the options available in the activity filter dropdown. 4170 * 4171 * @since 2.2.0 4172 * 4173 * @param array $filters Array of filter options for the given context, in the following format: $option_value => $option_name. 4174 * @param string $context Context for the filter. 'activity', 'member', 'member_groups', 'group'. 4175 */ 4176 $filters = apply_filters( 'bp_get_activity_show_filters_options', $filters, $context ); 4177 4178 // Build the options output. 4179 $output = ''; 4180 4181 if ( ! empty( $filters ) ) { 4182 foreach ( $filters as $value => $filter ) { 4183 $output .= '<option value="' . esc_attr( $value ) . '">' . esc_html( $filter ) . '</option>' . "\n"; 4184 } 4185 } 4186 4187 /** 4188 * Filters the HTML markup result for the activity filter dropdown. 4189 * 4190 * @since 2.1.0 4191 * 4192 * @param string $output HTML output for the activity filter dropdown. 4193 * @param array $filters Array of filter options for the given context, in the following format: $option_value => $option_name. 4194 * @param string $context Context for the filter. 'activity', 'member', 'member_groups', 'group'. 4195 */ 4196 return apply_filters( 'bp_get_activity_show_filters', $output, $filters, $context ); 4197 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |