[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/ -> bp-activity-template.php (source)

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


Generated: Thu Oct 21 01:00:54 2021 Cross-referenced by PHPXref 0.7.1