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