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


Generated: Tue Jul 16 01:01:43 2019 Cross-referenced by PHPXref 0.7.1