[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Filters related to the Activity component.
   4   *
   5   * @package BuddyPress
   6   * @subpackage ActivityFilters
   7   * @since 1.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /* Filters *******************************************************************/
  14  
  15  // Apply WordPress defined filters.
  16  add_filter( 'bp_get_activity_content_body',          'bp_activity_filter_kses', 1 );
  17  add_filter( 'bp_get_activity_parent_content',        'bp_activity_filter_kses', 1 );
  18  add_filter( 'bp_get_activity_latest_update',         'bp_activity_filter_kses', 1 );
  19  add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_filter_kses', 1 );
  20  add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_filter_kses', 1 );
  21  add_filter( 'bp_activity_content_before_save',       'bp_activity_filter_kses', 1 );
  22  add_filter( 'bp_activity_action_before_save',        'bp_activity_filter_kses', 1 );
  23  add_filter( 'bp_activity_latest_update_content',     'bp_activity_filter_kses', 1 );
  24  
  25  add_filter( 'bp_get_activity_action',                'force_balance_tags' );
  26  add_filter( 'bp_get_activity_content_body',          'force_balance_tags' );
  27  add_filter( 'bp_get_activity_content',               'force_balance_tags' );
  28  add_filter( 'bp_get_activity_latest_update',         'force_balance_tags' );
  29  add_filter( 'bp_get_activity_latest_update_excerpt', 'force_balance_tags' );
  30  add_filter( 'bp_get_activity_feed_item_description', 'force_balance_tags' );
  31  add_filter( 'bp_activity_content_before_save',       'force_balance_tags' );
  32  add_filter( 'bp_activity_action_before_save',        'force_balance_tags' );
  33  
  34  if ( function_exists( 'wp_encode_emoji' ) ) {
  35      add_filter( 'bp_activity_content_before_save', 'wp_encode_emoji' );
  36  }
  37  
  38  add_filter( 'bp_get_activity_action',                'wptexturize' );
  39  add_filter( 'bp_get_activity_content_body',          'wptexturize' );
  40  add_filter( 'bp_get_activity_content',               'wptexturize' );
  41  add_filter( 'bp_get_activity_parent_content',        'wptexturize' );
  42  add_filter( 'bp_get_activity_latest_update',         'wptexturize' );
  43  add_filter( 'bp_get_activity_latest_update_excerpt', 'wptexturize' );
  44  add_filter( 'bp_activity_get_embed_excerpt',         'wptexturize' );
  45  
  46  add_filter( 'bp_get_activity_action',                'convert_smilies' );
  47  add_filter( 'bp_get_activity_content_body',          'convert_smilies' );
  48  add_filter( 'bp_get_activity_content',               'convert_smilies' );
  49  add_filter( 'bp_get_activity_parent_content',        'convert_smilies' );
  50  add_filter( 'bp_get_activity_latest_update',         'convert_smilies' );
  51  add_filter( 'bp_get_activity_latest_update_excerpt', 'convert_smilies' );
  52  add_filter( 'bp_activity_get_embed_excerpt',         'convert_smilies' );
  53  
  54  add_filter( 'bp_get_activity_action',                'convert_chars' );
  55  add_filter( 'bp_get_activity_content_body',          'convert_chars' );
  56  add_filter( 'bp_get_activity_content',               'convert_chars' );
  57  add_filter( 'bp_get_activity_parent_content',        'convert_chars' );
  58  add_filter( 'bp_get_activity_latest_update',         'convert_chars' );
  59  add_filter( 'bp_get_activity_latest_update_excerpt', 'convert_chars' );
  60  add_filter( 'bp_activity_get_embed_excerpt',         'convert_chars' );
  61  
  62  add_filter( 'bp_get_activity_action',                'wpautop' );
  63  add_filter( 'bp_get_activity_content_body',          'wpautop' );
  64  add_filter( 'bp_get_activity_content',               'wpautop' );
  65  add_filter( 'bp_get_activity_feed_item_description', 'wpautop' );
  66  add_filter( 'bp_activity_get_embed_excerpt',         'wpautop' );
  67  
  68  add_filter( 'bp_get_activity_action',                'make_clickable', 9 );
  69  add_filter( 'bp_get_activity_content_body',          'make_clickable', 9 );
  70  add_filter( 'bp_get_activity_content',               'make_clickable', 9 );
  71  add_filter( 'bp_get_activity_parent_content',        'make_clickable', 9 );
  72  add_filter( 'bp_get_activity_latest_update',         'make_clickable', 9 );
  73  add_filter( 'bp_get_activity_latest_update_excerpt', 'make_clickable', 9 );
  74  add_filter( 'bp_get_activity_feed_item_description', 'make_clickable', 9 );
  75  add_filter( 'bp_activity_get_embed_excerpt',         'make_clickable', 9 );
  76  
  77  add_filter( 'bp_acomment_name',                      'stripslashes_deep', 5 );
  78  add_filter( 'bp_get_activity_action',                'stripslashes_deep', 5 );
  79  add_filter( 'bp_get_activity_content',               'stripslashes_deep', 5 );
  80  add_filter( 'bp_get_activity_content_body',          'stripslashes_deep', 5 );
  81  add_filter( 'bp_get_activity_parent_content',        'stripslashes_deep', 5 );
  82  add_filter( 'bp_get_activity_latest_update',         'stripslashes_deep', 5 );
  83  add_filter( 'bp_get_activity_latest_update_excerpt', 'stripslashes_deep', 5 );
  84  add_filter( 'bp_get_activity_feed_item_description', 'stripslashes_deep', 5 );
  85  
  86  add_filter( 'bp_activity_primary_link_before_save',  'esc_url_raw' );
  87  
  88  // Apply BuddyPress-defined filters.
  89  add_filter( 'bp_get_activity_content',               'bp_activity_make_nofollow_filter' );
  90  add_filter( 'bp_get_activity_content_body',          'bp_activity_make_nofollow_filter' );
  91  add_filter( 'bp_get_activity_parent_content',        'bp_activity_make_nofollow_filter' );
  92  add_filter( 'bp_get_activity_latest_update',         'bp_activity_make_nofollow_filter' );
  93  add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
  94  add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
  95  
  96  add_filter( 'pre_comment_content',                   'bp_activity_at_name_filter' );
  97  add_filter( 'the_content',                           'bp_activity_at_name_filter' );
  98  add_filter( 'bp_activity_get_embed_excerpt',         'bp_activity_at_name_filter' );
  99  
 100  add_filter( 'bp_get_activity_parent_content',        'bp_create_excerpt' );
 101  
 102  add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
 103  add_filter( 'bp_get_activity_content',      'bp_activity_truncate_entry', 5 );
 104  
 105  add_filter( 'bp_get_total_favorite_count_for_user', 'bp_core_number_format' );
 106  add_filter( 'bp_get_total_mention_count_for_user',  'bp_core_number_format' );
 107  
 108  add_filter( 'bp_activity_get_embed_excerpt', 'bp_activity_embed_excerpt_onclick_location_filter', 9 );
 109  
 110  // Personal data export.
 111  add_filter( 'wp_privacy_personal_data_exporters', 'bp_activity_register_personal_data_exporter' );
 112  
 113  /* Actions *******************************************************************/
 114  
 115  // At-name filter.
 116  add_action( 'bp_activity_before_save', 'bp_activity_at_name_filter_updates' );
 117  
 118  // Activity stream moderation.
 119  add_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 );
 120  add_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys',  2, 1 );
 121  
 122  /** Functions *****************************************************************/
 123  
 124  /**
 125   * Types of activity stream items to moderate.
 126   *
 127   * @since 1.6.0
 128   *
 129   * @return array $types List of the activity types to moderate.
 130   */
 131  function bp_activity_get_moderated_activity_types() {
 132      $types = array(
 133          'activity_comment',
 134          'activity_update'
 135      );
 136  
 137      /**
 138       * Filters the default activity types that BuddyPress should moderate.
 139       *
 140       * @since 1.6.0
 141       *
 142       * @param array $types Default activity types to moderate.
 143       */
 144      return apply_filters( 'bp_activity_check_activity_types', $types );
 145  }
 146  
 147  /**
 148   * Moderate the posted activity item, if it contains moderate keywords.
 149   *
 150   * @since 1.6.0
 151   *
 152   * @param BP_Activity_Activity $activity The activity object to check.
 153   */
 154  function bp_activity_check_moderation_keys( $activity ) {
 155  
 156      // Only check specific types of activity updates.
 157      if ( ! in_array( $activity->type, bp_activity_get_moderated_activity_types() ) ) {
 158          return;
 159      }
 160  
 161      // Send back the error so activity update fails.
 162      // @todo This is temporary until some kind of moderation is built.
 163      $moderate = bp_core_check_for_moderation( $activity->user_id, '', $activity->content, 'wp_error' );
 164      if ( is_wp_error( $moderate ) ) {
 165          $activity->errors = $moderate;
 166  
 167          // Backpat.
 168          $activity->component = false;
 169      }
 170  }
 171  
 172  /**
 173   * Mark the posted activity as spam, if it contains blacklist keywords.
 174   *
 175   * @since 1.6.0
 176   *
 177   * @param BP_Activity_Activity $activity The activity object to check.
 178   */
 179  function bp_activity_check_blacklist_keys( $activity ) {
 180  
 181      // Only check specific types of activity updates.
 182      if ( ! in_array( $activity->type, bp_activity_get_moderated_activity_types() ) ) {
 183          return;
 184      }
 185  
 186      // Send back the error so activity update fails.
 187      // @todo This is temporary until some kind of trash status is built.
 188      $blacklist = bp_core_check_for_blacklist( $activity->user_id, '', $activity->content, 'wp_error' );
 189      if ( is_wp_error( $blacklist ) ) {
 190          $activity->errors = $blacklist;
 191  
 192          // Backpat.
 193          $activity->component = false;
 194      }
 195  }
 196  
 197  /**
 198   * Custom kses filtering for activity content.
 199   *
 200   * @since 1.1.0
 201   *
 202   * @param string $content The activity content.
 203   * @return string $content Filtered activity content.
 204   */
 205  function bp_activity_filter_kses( $content ) {
 206      $activity_allowedtags = bp_get_allowedtags();
 207  
 208      // Don't allow 'class' or 'id'.
 209      foreach ( $activity_allowedtags as $el => &$atts ) {
 210          unset( $atts['class'] );
 211          unset( $atts['id'] );
 212      }
 213  
 214      /**
 215       * Filters the allowed HTML tags for BuddyPress Activity content.
 216       *
 217       * @since 1.2.0
 218       *
 219       * @param array $value Array of allowed HTML tags and attributes.
 220       */
 221      $activity_allowedtags = apply_filters( 'bp_activity_allowed_tags', $activity_allowedtags );
 222      return wp_kses( $content, $activity_allowedtags );
 223  }
 224  
 225  /**
 226   * Find and link @-mentioned users in the contents of a given item.
 227   *
 228   * @since 1.2.0
 229   *
 230   * @param string $content     The contents of a given item.
 231   * @param int    $activity_id The activity id. Deprecated.
 232   * @return string $content Content filtered for mentions.
 233   */
 234  function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
 235  
 236      // Are mentions disabled?
 237      if ( ! bp_activity_do_mentions() ) {
 238          return $content;
 239      }
 240  
 241      // Try to find mentions.
 242      $usernames = bp_activity_find_mentions( $content );
 243  
 244      // No mentions? Stop now!
 245      if ( empty( $usernames ) )
 246          return $content;
 247  
 248      // We don't want to link @mentions that are inside of links, so we
 249      // temporarily remove them.
 250      $replace_count = 0;
 251      $replacements = array();
 252      foreach ( $usernames as $username ) {
 253          // Prevent @ name linking inside <a> tags.
 254          preg_match_all( '/(<a.*?(?!<\/a>)@' . $username . '.*?<\/a>)/', $content, $content_matches );
 255          if ( ! empty( $content_matches[1] ) ) {
 256              foreach ( $content_matches[1] as $replacement ) {
 257                  $replacements[ '#BPAN' . $replace_count ] = $replacement;
 258                  $content = str_replace( $replacement, '#BPAN' . $replace_count, $content );
 259                  $replace_count++;
 260              }
 261          }
 262      }
 263  
 264      // Linkify the mentions with the username.
 265      foreach ( (array) $usernames as $user_id => $username ) {
 266          $content = preg_replace( '/(@' . $username . '\b)/', "<a class='bp-suggestions-mention' href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
 267      }
 268  
 269      // Put everything back.
 270      if ( ! empty( $replacements ) ) {
 271          foreach ( $replacements as $placeholder => $original ) {
 272              $content = str_replace( $placeholder, $original, $content );
 273          }
 274      }
 275  
 276      // Return the content.
 277      return $content;
 278  }
 279  
 280  /**
 281   * Catch mentions in an activity item before it is saved into the database.
 282   *
 283   * If mentions are found, replace @mention text with user links and add our
 284   * hook to send mention notifications after the activity item is saved.
 285   *
 286   * @since 1.5.0
 287   *
 288   * @param BP_Activity_Activity $activity Activity Object.
 289   */
 290  function bp_activity_at_name_filter_updates( $activity ) {
 291      // Are mentions disabled?
 292      if ( ! bp_activity_do_mentions() ) {
 293          return;
 294      }
 295  
 296      // If activity was marked as spam, stop the rest of this function.
 297      if ( ! empty( $activity->is_spam ) )
 298          return;
 299  
 300      // Try to find mentions.
 301      $usernames = bp_activity_find_mentions( $activity->content );
 302  
 303      // We have mentions!
 304      if ( ! empty( $usernames ) ) {
 305          // Replace @mention text with userlinks.
 306          foreach( (array) $usernames as $user_id => $username ) {
 307              $activity->content = preg_replace( '/(@' . $username . '\b)/', "<a class='bp-suggestions-mention' href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $activity->content );
 308          }
 309  
 310          // Add our hook to send @mention emails after the activity item is saved.
 311          add_action( 'bp_activity_after_save', 'bp_activity_at_name_send_emails' );
 312  
 313          // Temporary variable to avoid having to run bp_activity_find_mentions() again.
 314          buddypress()->activity->mentioned_users = $usernames;
 315      }
 316  }
 317  
 318  /**
 319   * Sends emails and BP notifications for users @-mentioned in an activity item.
 320   *
 321   * @since 1.7.0
 322   *
 323   * @param BP_Activity_Activity $activity The BP_Activity_Activity object.
 324   */
 325  function bp_activity_at_name_send_emails( $activity ) {
 326      // Are mentions disabled?
 327      if ( ! bp_activity_do_mentions() ) {
 328          return;
 329      }
 330  
 331      $bp = buddypress();
 332  
 333      // If our temporary variable doesn't exist, stop now.
 334      if ( empty( $bp->activity->mentioned_users ) )
 335          return;
 336  
 337      // Grab our temporary variable from bp_activity_at_name_filter_updates().
 338      $usernames = $bp->activity->mentioned_users;
 339  
 340      // Get rid of temporary variable.
 341      unset( $bp->activity->mentioned_users );
 342  
 343      // Send @mentions and setup BP notifications.
 344      foreach( (array) $usernames as $user_id => $username ) {
 345  
 346          /**
 347           * Filters BuddyPress' ability to send email notifications for @mentions.
 348           *
 349           * @since 1.6.0
 350           * @since 2.5.0 Introduced `$user_id` and `$activity` parameters.
 351           *
 352           * @param bool                 $value     Whether or not BuddyPress should send a notification to the mentioned users.
 353           * @param array                $usernames Array of users potentially notified.
 354           * @param int                  $user_id   ID of the current user being notified.
 355           * @param BP_Activity_Activity $activity  Activity object.
 356           */
 357          if ( apply_filters( 'bp_activity_at_name_do_notifications', true, $usernames, $user_id, $activity ) ) {
 358              bp_activity_at_message_notification( $activity->id, $user_id );
 359          }
 360  
 361          // Updates mention count for the user.
 362          bp_activity_update_mention_count_for_user( $user_id, $activity->id );
 363      }
 364  }
 365  
 366  /**
 367   * Catch links in activity text so rel=nofollow can be added.
 368   *
 369   * @since 1.2.0
 370   *
 371   * @param string $text Activity text.
 372   * @return string $text Text with rel=nofollow added to any links.
 373   */
 374  function bp_activity_make_nofollow_filter( $text ) {
 375      return preg_replace_callback( '|<a (.+?)>|i', 'bp_activity_make_nofollow_filter_callback', $text );
 376  }
 377  
 378      /**
 379       * Add rel=nofollow to a link.
 380       *
 381       * @since 1.2.0
 382       *
 383       * @param array $matches Items matched by preg_replace_callback() in bp_activity_make_nofollow_filter().
 384       * @return string $text Link with rel=nofollow added.
 385       */
 386  	function bp_activity_make_nofollow_filter_callback( $matches ) {
 387          $text = $matches[1];
 388          $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
 389          return "<a $text rel=\"nofollow\">";
 390      }
 391  
 392  /**
 393   * Truncate long activity entries when viewed in activity streams.
 394   *
 395   * This method can only be used inside the Activity loop.
 396   *
 397   * @since 1.5.0
 398   * @since 2.6.0 Added $args parameter.
 399   *
 400   * @param string $text The original activity entry text.
 401   * @param array  $args {
 402   *     Optional parameters. See $options argument of {@link bp_create_excerpt()}
 403   *     for all available parameters.
 404   * }
 405   * @return string $excerpt The truncated text.
 406   */
 407  function bp_activity_truncate_entry( $text, $args = array() ) {
 408      global $activities_template;
 409  
 410      /**
 411       * Provides a filter that lets you choose whether to skip this filter on a per-activity basis.
 412       *
 413       * @since 2.3.0
 414       *
 415       * @param bool $value If true, text should be checked to see if it needs truncating.
 416       */
 417      $maybe_truncate_text = apply_filters(
 418          'bp_activity_maybe_truncate_entry',
 419          isset( $activities_template->activity->type ) && ! in_array( $activities_template->activity->type, array( 'new_blog_post', ), true )
 420      );
 421  
 422      // The full text of the activity update should always show on the single activity screen.
 423      if ( empty( $args['force_truncate'] ) && ( ! $maybe_truncate_text || bp_is_single_activity() ) ) {
 424          return $text;
 425      }
 426  
 427      /**
 428       * Filters the appended text for the activity excerpt.
 429       *
 430       * @since 1.5.0
 431       *
 432       * @param string $value Internationalized "Read more" text.
 433       */
 434      $append_text    = apply_filters( 'bp_activity_excerpt_append_text', __( '[Read more]', 'buddypress' ) );
 435  
 436      $excerpt_length = bp_activity_get_excerpt_length();
 437  
 438      $args = wp_parse_args( $args, array( 'ending' => __( '&hellip;', 'buddypress' ) ) );
 439  
 440      // Run the text through the excerpt function. If it's too short, the original text will be returned.
 441      $excerpt        = bp_create_excerpt( $text, $excerpt_length, $args );
 442  
 443      /*
 444       * If the text returned by bp_create_excerpt() is different from the original text (ie it's
 445       * been truncated), add the "Read More" link. Note that bp_create_excerpt() is stripping
 446       * shortcodes, so we have strip them from the $text before the comparison.
 447       */
 448      if ( strlen( $excerpt ) < strlen( strip_shortcodes( $text ) ) ) {
 449          $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
 450  
 451          $excerpt = sprintf( '%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', $excerpt, $id, bp_get_activity_thread_permalink(), $append_text );
 452      }
 453  
 454      /**
 455       * Filters the composite activity excerpt entry.
 456       *
 457       * @since 1.5.0
 458       *
 459       * @param string $excerpt     Excerpt text and markup to be displayed.
 460       * @param string $text        The original activity entry text.
 461       * @param string $append_text The final append text applied.
 462       */
 463      return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );
 464  }
 465  
 466  /**
 467   * Include extra JavaScript dependencies for activity component.
 468   *
 469   * @since 2.0.0
 470   *
 471   * @param array $js_handles The original dependencies.
 472   * @return array $js_handles The new dependencies.
 473   */
 474  function bp_activity_get_js_dependencies( $js_handles = array() ) {
 475      if ( bp_activity_do_heartbeat() ) {
 476          $js_handles[] = 'heartbeat';
 477      }
 478  
 479      return $js_handles;
 480  }
 481  add_filter( 'bp_core_get_js_dependencies', 'bp_activity_get_js_dependencies', 10, 1 );
 482  
 483  /**
 484   * Add a just-posted classes to the most recent activity item.
 485   *
 486   * We use these classes to avoid pagination issues when items are loaded
 487   * dynamically into the activity stream.
 488   *
 489   * @since 2.0.0
 490   *
 491   * @param string $classes Array of classes for most recent activity item.
 492   * @return string $classes
 493   */
 494  function bp_activity_newest_class( $classes = '' ) {
 495      $bp = buddypress();
 496  
 497      if ( ! empty( $bp->activity->last_recorded ) && $bp->activity->last_recorded == bp_get_activity_date_recorded() ) {
 498          $classes .= ' new-update';
 499      }
 500  
 501      $classes .= ' just-posted';
 502      return $classes;
 503  }
 504  
 505  /**
 506   * Check if Activity Heartbeat feature i on to add a timestamp class.
 507   *
 508   * @since 2.0.0
 509   *
 510   * @param string $classes Array of classes for timestamp.
 511   * @return string $classes
 512   */
 513  function bp_activity_timestamp_class( $classes = '' ) {
 514  
 515      if ( ! bp_activity_do_heartbeat() ) {
 516          return $classes;
 517      }
 518  
 519      $activity_date = bp_get_activity_date_recorded();
 520  
 521      if ( empty( $activity_date ) ) {
 522          return $classes;
 523      }
 524  
 525      $classes .= ' date-recorded-' . strtotime( $activity_date );
 526  
 527      return $classes;
 528  }
 529  add_filter( 'bp_get_activity_css_class', 'bp_activity_timestamp_class', 9, 1 );
 530  
 531  /**
 532   * Use WordPress Heartbeat API to check for latest activity update.
 533   *
 534   * @since 2.0.0
 535   *
 536   * @param array $response Array containing Heartbeat API response.
 537   * @param array $data     Array containing data for Heartbeat API response.
 538   * @return array $response
 539   */
 540  function bp_activity_heartbeat_last_recorded( $response = array(), $data = array() ) {
 541      if ( empty( $data['bp_activity_last_recorded'] ) ) {
 542          return $response;
 543      }
 544  
 545      // Use the querystring argument stored in the cookie (to preserve
 546      // filters), but force the offset to get only new items.
 547      $activity_latest_args = bp_parse_args(
 548          bp_ajax_querystring( 'activity' ),
 549          array( 'since' => date( 'Y-m-d H:i:s', $data['bp_activity_last_recorded'] ) ),
 550          'activity_latest_args'
 551      );
 552  
 553      if ( ! empty( $data['bp_activity_last_recorded_search_terms'] ) && empty( $activity_latest_args['search_terms'] ) ) {
 554          $activity_latest_args['search_terms'] = addslashes( $data['bp_activity_last_recorded_search_terms'] );
 555      }
 556  
 557      $newest_activities = array();
 558      $last_activity_recorded = 0;
 559  
 560      // Temporarily add a just-posted class for new activity items.
 561      add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
 562  
 563      ob_start();
 564      if ( bp_has_activities( $activity_latest_args ) ) {
 565          while ( bp_activities() ) {
 566              bp_the_activity();
 567  
 568              $atime = strtotime( bp_get_activity_date_recorded() );
 569              if ( $last_activity_recorded < $atime ) {
 570                  $last_activity_recorded = $atime;
 571              }
 572  
 573              bp_get_template_part( 'activity/entry' );
 574          }
 575      }
 576  
 577      $newest_activities['activities']    = ob_get_contents();
 578      $newest_activities['last_recorded'] = $last_activity_recorded;
 579      ob_end_clean();
 580  
 581      // Remove the temporary filter.
 582      remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10 );
 583  
 584      if ( ! empty( $newest_activities['last_recorded'] ) ) {
 585          $response['bp_activity_newest_activities'] = $newest_activities;
 586      }
 587  
 588      return $response;
 589  }
 590  add_filter( 'heartbeat_received', 'bp_activity_heartbeat_last_recorded', 10, 2 );
 591  add_filter( 'heartbeat_nopriv_received', 'bp_activity_heartbeat_last_recorded', 10, 2 );
 592  
 593  /**
 594   * Set the strings for WP HeartBeat API where needed.
 595   *
 596   * @since 2.0.0
 597   *
 598   * @param array $strings Localized strings.
 599   * @return array $strings
 600   */
 601  function bp_activity_heartbeat_strings( $strings = array() ) {
 602  
 603      if ( ! bp_activity_do_heartbeat() ) {
 604          return $strings;
 605      }
 606  
 607      $global_pulse = 0;
 608  
 609      /**
 610       * Filter that checks whether the global heartbeat settings already exist.
 611       *
 612       * @since 2.0.0
 613       *
 614       * @param array $value Heartbeat settings array.
 615       */
 616      $heartbeat_settings = apply_filters( 'heartbeat_settings', array() );
 617      if ( ! empty( $heartbeat_settings['interval'] ) ) {
 618          // 'Fast' is 5
 619          $global_pulse = is_numeric( $heartbeat_settings['interval'] ) ? absint( $heartbeat_settings['interval'] ) : 5;
 620      }
 621  
 622      /**
 623       * Filters the pulse frequency to be used for the BuddyPress Activity heartbeat.
 624       *
 625       * @since 2.0.0
 626       *
 627       * @param int $value The frequency in seconds between pulses.
 628       */
 629      $bp_activity_pulse = apply_filters( 'bp_activity_heartbeat_pulse', 15 );
 630  
 631      /**
 632       * Use the global pulse value unless:
 633       * a. the BP-specific value has been specifically filtered, or
 634       * b. it doesn't exist (ie, BP will be the only one using the heartbeat,
 635       *    so we're responsible for enabling it)
 636       */
 637      if ( has_filter( 'bp_activity_heartbeat_pulse' ) || empty( $global_pulse ) ) {
 638          $pulse = $bp_activity_pulse;
 639      } else {
 640          $pulse = $global_pulse;
 641      }
 642  
 643      $strings = array_merge( $strings, array(
 644          'newest' => __( 'Load Newest', 'buddypress' ),
 645          'pulse'  => absint( $pulse ),
 646      ) );
 647  
 648      return $strings;
 649  }
 650  add_filter( 'bp_core_get_js_strings', 'bp_activity_heartbeat_strings', 10, 1 );
 651  
 652  /** Scopes ********************************************************************/
 653  
 654  /**
 655   * Set up activity arguments for use with the 'just-me' scope.
 656   *
 657   * @since 2.2.0
 658   *
 659   * @param array $retval Empty array by default.
 660   * @param array $filter Current activity arguments.
 661   * @return array $retval
 662   */
 663  function bp_activity_filter_just_me_scope( $retval = array(), $filter = array() ) {
 664  
 665      // Determine the user_id.
 666      if ( ! empty( $filter['user_id'] ) ) {
 667          $user_id = $filter['user_id'];
 668      } else {
 669          $user_id = bp_displayed_user_id()
 670              ? bp_displayed_user_id()
 671              : bp_loggedin_user_id();
 672      }
 673  
 674      // Should we show all items regardless of sitewide visibility?
 675      $show_hidden = array();
 676      if ( ! empty( $user_id ) && $user_id !== bp_loggedin_user_id() ) {
 677          $show_hidden = array(
 678              'column' => 'hide_sitewide',
 679              'value'  => 0
 680          );
 681      }
 682  
 683      $retval = array(
 684          'relation' => 'AND',
 685          array(
 686              'column' => 'user_id',
 687              'value'  => $user_id
 688          ),
 689          $show_hidden,
 690  
 691          // Overrides.
 692          'override' => array(
 693              'display_comments' => 'stream',
 694              'filter'           => array( 'user_id' => 0 ),
 695              'show_hidden'      => true
 696          ),
 697      );
 698  
 699      return $retval;
 700  }
 701  add_filter( 'bp_activity_set_just-me_scope_args', 'bp_activity_filter_just_me_scope', 10, 2 );
 702  
 703  /**
 704   * Set up activity arguments for use with the 'favorites' scope.
 705   *
 706   * @since 2.2.0
 707   *
 708   * @param array $retval Empty array by default.
 709   * @param array $filter Current activity arguments.
 710   * @return array $retval
 711   */
 712  function bp_activity_filter_favorites_scope( $retval = array(), $filter = array() ) {
 713  
 714      // Determine the user_id.
 715      if ( ! empty( $filter['user_id'] ) ) {
 716          $user_id = $filter['user_id'];
 717      } else {
 718          $user_id = bp_displayed_user_id()
 719              ? bp_displayed_user_id()
 720              : bp_loggedin_user_id();
 721      }
 722  
 723      // Determine the favorites.
 724      $favs = bp_activity_get_user_favorites( $user_id );
 725      if ( empty( $favs ) ) {
 726          $favs = array( 0 );
 727      }
 728  
 729      // Should we show all items regardless of sitewide visibility?
 730      $show_hidden = array();
 731      if ( ! empty( $user_id ) && ( $user_id !== bp_loggedin_user_id() ) ) {
 732          $show_hidden = array(
 733              'column' => 'hide_sitewide',
 734              'value'  => 0
 735          );
 736      }
 737  
 738      $retval = array(
 739          'relation' => 'AND',
 740          array(
 741              'column'  => 'id',
 742              'compare' => 'IN',
 743              'value'   => (array) $favs
 744          ),
 745          $show_hidden,
 746  
 747          // Overrides.
 748          'override' => array(
 749              'display_comments' => true,
 750              'filter'           => array( 'user_id' => 0 ),
 751              'show_hidden'      => true
 752          ),
 753      );
 754  
 755      return $retval;
 756  }
 757  add_filter( 'bp_activity_set_favorites_scope_args', 'bp_activity_filter_favorites_scope', 10, 2 );
 758  
 759  
 760  /**
 761   * Set up activity arguments for use with the 'favorites' scope.
 762   *
 763   * @since 2.2.0
 764   *
 765   * @param array $retval Empty array by default.
 766   * @param array $filter Current activity arguments.
 767   * @return array $retval
 768   */
 769  function bp_activity_filter_mentions_scope( $retval = array(), $filter = array() ) {
 770  
 771      // Are mentions disabled?
 772      if ( ! bp_activity_do_mentions() ) {
 773          return $retval;
 774      }
 775  
 776      // Determine the user_id.
 777      if ( ! empty( $filter['user_id'] ) ) {
 778          $user_id = $filter['user_id'];
 779      } else {
 780          $user_id = bp_displayed_user_id()
 781              ? bp_displayed_user_id()
 782              : bp_loggedin_user_id();
 783      }
 784  
 785      // Should we show all items regardless of sitewide visibility?
 786      $show_hidden = array();
 787      if ( ! empty( $user_id ) && $user_id !== bp_loggedin_user_id() ) {
 788          $show_hidden = array(
 789              'column' => 'hide_sitewide',
 790              'value'  => 0
 791          );
 792      }
 793  
 794      $retval = array(
 795          'relation' => 'AND',
 796          array(
 797              'column'  => 'content',
 798              'compare' => 'LIKE',
 799  
 800              // Start search at @ symbol and stop search at closing tag delimiter.
 801              'value'   => '@' . bp_activity_get_user_mentionname( $user_id ) . '<'
 802          ),
 803          $show_hidden,
 804  
 805          // Overrides.
 806          'override' => array(
 807              'display_comments' => 'stream',
 808              'filter'           => array( 'user_id' => 0 ),
 809              'show_hidden'      => true
 810          ),
 811      );
 812  
 813      return $retval;
 814  }
 815  add_filter( 'bp_activity_set_mentions_scope_args', 'bp_activity_filter_mentions_scope', 10, 2 );
 816  
 817  /**
 818   * Registers Activity personal data exporter.
 819   *
 820   * @since 4.0.0
 821   * @since 5.0.0 adds an `exporter_bp_friendly_name` param to exporters.
 822   *
 823   * @param array $exporters  An array of personal data exporters.
 824   * @return array An array of personal data exporters.
 825   */
 826  function bp_activity_register_personal_data_exporter( $exporters ) {
 827      $exporters['buddypress-activity'] = array(
 828          'exporter_friendly_name'    => __( 'BuddyPress Activity Data', 'buddypress' ),
 829          'callback'                  => 'bp_activity_personal_data_exporter',
 830          'exporter_bp_friendly_name' => _x( 'Activity Data', 'BuddyPress Activity data exporter friendly name', 'buddypress' ),
 831      );
 832  
 833      return $exporters;
 834  }


Generated: Fri Dec 13 01:01:36 2019 Cross-referenced by PHPXref 0.7.1