[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-nouveau/includes/activity/ -> template-tags.php (source)

   1  <?php
   2  /**
   3   * Activity Template tags
   4   *
   5   * @since 3.0.0
   6   * @version 8.1.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * Before Activity's directory content legacy do_action hooks wrapper
  14   *
  15   * @since 3.0.0
  16   */
  17  function bp_nouveau_before_activity_directory_content() {
  18      /**
  19       * Fires at the begining of the templates BP injected content.
  20       *
  21       * @since 2.3.0
  22       */
  23      do_action( 'bp_before_directory_activity' );
  24  
  25      /**
  26       * Fires before the activity directory display content.
  27       *
  28       * @since 1.2.0
  29       */
  30      do_action( 'bp_before_directory_activity_content' );
  31  }
  32  
  33  /**
  34   * After Activity's directory content legacy do_action hooks wrapper
  35   *
  36   * @since 3.0.0
  37   */
  38  function bp_nouveau_after_activity_directory_content() {
  39      /**
  40       * Fires after the display of the activity list.
  41       *
  42       * @since 1.5.0
  43       */
  44      do_action( 'bp_after_directory_activity_list' );
  45  
  46      /**
  47       * Fires inside and displays the activity directory display content.
  48       */
  49      do_action( 'bp_directory_activity_content' );
  50  
  51      /**
  52       * Fires after the activity directory display content.
  53       *
  54       * @since 1.2.0
  55       */
  56      do_action( 'bp_after_directory_activity_content' );
  57  
  58      /**
  59       * Fires after the activity directory listing.
  60       *
  61       * @since 1.5.0
  62       */
  63      do_action( 'bp_after_directory_activity' );
  64  }
  65  
  66  /**
  67   * Enqueue needed scripts for the Activity Post Form
  68   *
  69   * @since 3.0.0
  70   * @since 5.0.0 Move the `bp_before_activity_post_form` hook inside the Activity post form.
  71   */
  72  function bp_nouveau_before_activity_post_form() {
  73      if ( bp_nouveau_current_user_can( 'publish_activity' ) ) {
  74          wp_enqueue_script( 'bp-nouveau-activity-post-form' );
  75      }
  76  }
  77  
  78  /**
  79   * Load JS Templates for the Activity Post Form
  80   *
  81   * @since 3.0.0
  82   */
  83  function bp_nouveau_after_activity_post_form() {
  84      if ( bp_nouveau_current_user_can( 'publish_activity' ) ) {
  85          bp_get_template_part( 'common/js-templates/activity/form' );
  86      }
  87  
  88      /**
  89       * Fires after the activity post form.
  90       *
  91       * @since 1.2.0
  92       */
  93      do_action( 'bp_after_activity_post_form' );
  94  }
  95  
  96  /**
  97   * Display the displayed user activity post form if needed
  98   *
  99   * @since 3.0.0
 100   *
 101   * @return string HTML.
 102   */
 103  function bp_nouveau_activity_member_post_form() {
 104  
 105      /**
 106       * Fires before the display of the member activity post form.
 107       *
 108       * @since 1.2.0
 109       */
 110      do_action( 'bp_before_member_activity_post_form' );
 111  
 112      if ( is_user_logged_in() && bp_is_my_profile() && ( ! bp_current_action() || bp_is_current_action( 'just-me' ) ) ) {
 113          bp_get_template_part( 'activity/post-form' );
 114      }
 115  
 116      /**
 117       * Fires after the display of the member activity post form.
 118       *
 119       * @since 1.2.0
 120       */
 121      do_action( 'bp_after_member_activity_post_form' );
 122  }
 123  
 124  /**
 125   * Fire specific hooks into the activity entry template
 126   *
 127   * @since 3.0.0
 128   *
 129   * @param string $when   Optional. Either 'before' or 'after'.
 130   * @param string $suffix Optional. Use it to add terms at the end of the hook name.
 131   */
 132  function bp_nouveau_activity_hook( $when = '', $suffix = '' ) {
 133      $hook = array( 'bp' );
 134  
 135      if ( $when ) {
 136          $hook[] = $when;
 137      }
 138  
 139      // It's a activity entry hook
 140      $hook[] = 'activity';
 141  
 142      if ( $suffix ) {
 143          $hook[] = $suffix;
 144      }
 145  
 146      bp_nouveau_hook( $hook );
 147  }
 148  
 149  /**
 150   * Checks if an activity of the loop has some content.
 151   *
 152   * @since 3.0.0
 153   *
 154   * @return bool True if the activity has some content. False Otherwise.
 155   */
 156  function bp_nouveau_activity_has_content() {
 157      return bp_activity_has_content() || (bool) has_action( 'bp_activity_entry_content' );
 158  }
 159  
 160  /**
 161   * Output the Activity content into the loop.
 162   *
 163   * @since 3.0.0
 164   */
 165  function bp_nouveau_activity_content() {
 166      if ( bp_activity_has_content() ) {
 167          bp_activity_content_body();
 168      }
 169  
 170      /**
 171       * Fires after the display of an activity entry content.
 172       *
 173       * @since 1.2.0
 174       */
 175      do_action( 'bp_activity_entry_content' );
 176  }
 177  
 178  /**
 179   * Output the Activity timestamp into the bp-timestamp attribute.
 180   *
 181   * @since 3.0.0
 182   */
 183  function bp_nouveau_activity_timestamp() {
 184      echo esc_attr( bp_nouveau_get_activity_timestamp() );
 185  }
 186  
 187      /**
 188       * Get the Activity timestamp.
 189       *
 190       * @since 3.0.0
 191       *
 192       * @return integer The Activity timestamp.
 193       */
 194  	function bp_nouveau_get_activity_timestamp() {
 195          /**
 196           * Filter here to edit the activity timestamp.
 197           *
 198           * @since 3.0.0
 199           *
 200           * @param integer $value The Activity timestamp.
 201           */
 202          return apply_filters( 'bp_nouveau_get_activity_timestamp', strtotime( bp_get_activity_date_recorded() ) );
 203      }
 204  
 205  /**
 206   * Output the action buttons inside an Activity Loop.
 207   *
 208   * @since 3.0.0
 209   *
 210   * @param array $args See bp_nouveau_wrapper() for the description of parameters.
 211   */
 212  function bp_nouveau_activity_entry_buttons( $args = array() ) {
 213      $output = join( ' ', bp_nouveau_get_activity_entry_buttons( $args ) );
 214  
 215      ob_start();
 216  
 217      /**
 218       * Fires at the end of the activity entry meta data area.
 219       *
 220       * @since 1.2.0
 221       */
 222      do_action( 'bp_activity_entry_meta' );
 223  
 224      $output .= ob_get_clean();
 225  
 226      $has_content = trim( $output, ' ' );
 227      if ( ! $has_content ) {
 228          return;
 229      }
 230  
 231      if ( ! $args ) {
 232          $args = array( 'classes' => array( 'activity-meta' ) );
 233      }
 234  
 235      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 236  }
 237  
 238      /**
 239       * Get the action buttons inside an Activity Loop.
 240       *
 241       * @todo This function is too large and needs refactoring and reviewing.
 242       * @since 3.0.0
 243       *
 244       * @param array $args See bp_nouveau_wrapper() for the description of parameters.
 245       * @return array      Activity action buttons used into an Activity Loop.
 246       */
 247  	function bp_nouveau_get_activity_entry_buttons( $args ) {
 248          $buttons = array();
 249  
 250          if ( ! isset( $GLOBALS['activities_template'] ) ) {
 251              return $buttons;
 252          }
 253  
 254          $activity_id    = bp_get_activity_id();
 255          $activity_type  = bp_get_activity_type();
 256          $parent_element = '';
 257          $button_element = 'a';
 258  
 259          if ( ! $activity_id ) {
 260              return $buttons;
 261          }
 262  
 263          /*
 264           * If the container is set to 'ul' force the $parent_element to 'li',
 265           * else use parent_element args if set.
 266           *
 267           * This will render li elements around anchors/buttons.
 268           */
 269          if ( isset( $args['container'] ) && 'ul' === $args['container'] ) {
 270              $parent_element = 'li';
 271          } elseif ( ! empty( $args['parent_element'] ) ) {
 272              $parent_element = $args['parent_element'];
 273          }
 274  
 275          $parent_attr = ( ! empty( $args['parent_attr'] ) ) ? $args['parent_attr'] : array();
 276  
 277          /*
 278           * If we have a arg value for $button_element passed through
 279           * use it to default all the $buttons['button_element'] values
 280           * otherwise default to 'a' (anchor)
 281           * Or override & hardcode the 'element' string on $buttons array.
 282           *
 283           */
 284          if ( ! empty( $args['button_element'] ) ) {
 285              $button_element = $args['button_element'];
 286          }
 287  
 288          /*
 289           * The view conversation button and the comment one are sharing
 290           * the same id because when display_comments is on stream mode,
 291           * it is not possible to comment an activity comment and as we
 292           * are updating the links to avoid sorting the activity buttons
 293           * for each entry of the loop, it's a convenient way to make
 294           * sure the right button will be displayed.
 295           */
 296          if ( $activity_type === 'activity_comment' ) {
 297              $buttons['activity_conversation'] = array(
 298                  'id'                => 'activity_conversation',
 299                  'position'          => 5,
 300                  'component'         => 'activity',
 301                  'parent_element'    => $parent_element,
 302                  'parent_attr'       => $parent_attr,
 303                  'must_be_logged_in' => false,
 304                  'button_element'    => $button_element,
 305                  'button_attr'       => array(
 306                      'class'           => 'button view bp-secondary-action bp-tooltip',
 307                      'data-bp-tooltip' => __( 'View Conversation', 'buddypress' ),
 308                      ),
 309                  'link_text' => sprintf(
 310                      '<span class="bp-screen-reader-text">%1$s</span>',
 311                      __( 'View Conversation', 'buddypress' )
 312                  ),
 313              );
 314  
 315              // If button element set add url link to data-attr
 316              if ( 'button' === $button_element ) {
 317                  $buttons['activity_conversation']['button_attr']['data-bp-url'] = bp_get_activity_thread_permalink();
 318              } else {
 319                  $buttons['activity_conversation']['button_attr']['href'] = bp_get_activity_thread_permalink();
 320                  $buttons['activity_conversation']['button_attr']['role'] = 'button';
 321              }
 322  
 323          /*
 324           * We always create the Button to make sure we always have the right numbers of buttons,
 325           * no matter the previous activity had less.
 326           */
 327          } else {
 328              $buttons['activity_conversation'] =  array(
 329                  'id'                => 'activity_conversation',
 330                  'position'          => 5,
 331                  'component'         => 'activity',
 332                  'parent_element'    => $parent_element,
 333                  'parent_attr'       => $parent_attr,
 334                  'must_be_logged_in' => true,
 335                  'button_element'    => $button_element,
 336                  'button_attr'       => array(
 337                      'id'              => 'acomment-comment-' . $activity_id,
 338                      'class'           => 'button acomment-reply bp-primary-action bp-tooltip',
 339                      'data-bp-tooltip' => _x( 'Comment', 'button', 'buddypress' ),
 340                      'aria-expanded'   => 'false',
 341                  ),
 342                  'link_text'  => sprintf(
 343                      '<span class="bp-screen-reader-text">%1$s</span> <span class="comment-count">%2$s</span>',
 344                      _x( 'Comment', 'link', 'buddypress' ),
 345                      esc_html( bp_activity_get_comment_count() )
 346                  ),
 347              );
 348  
 349              // If button element set add href link to data-attr
 350              if ( 'button' === $button_element ) {
 351                  $buttons['activity_conversation']['button_attr']['data-bp-url'] = bp_get_activity_comment_link();
 352              } else {
 353                  $buttons['activity_conversation']['button_attr']['href'] = bp_get_activity_comment_link();
 354                  $buttons['activity_conversation']['button_attr']['role'] = 'button';
 355              }
 356  
 357          }
 358  
 359          if ( bp_activity_can_favorite() ) {
 360  
 361              // If button element set attr needs to be data-* else 'href'
 362              if ( 'button' === $button_element ) {
 363                  $key = 'data-bp-nonce';
 364              } else {
 365                  $key = 'href';
 366              }
 367  
 368              if ( ! bp_get_activity_is_favorite() ) {
 369                  $fav_args = array(
 370                      'parent_element'   => $parent_element,
 371                      'parent_attr'      => $parent_attr,
 372                      'button_element'   => $button_element,
 373                      'link_class'       => 'button fav bp-secondary-action bp-tooltip',
 374                      'data_bp_tooltip'  => __( 'Mark as Favorite', 'buddypress' ),
 375                      'link_text'        => __( 'Mark as Favorite', 'buddypress' ),
 376                      'aria-pressed'     => 'false',
 377                      'link_attr'        => bp_get_activity_favorite_link(),
 378                  );
 379  
 380              } else {
 381                  $fav_args = array(
 382                      'parent_element'  => $parent_element,
 383                      'parent_attr'     => $parent_attr,
 384                      'button_element'  => $button_element,
 385                      'link_class'      => 'button unfav bp-secondary-action bp-tooltip',
 386                      'data_bp_tooltip' => __( 'Remove Favorite', 'buddypress' ),
 387                      'link_text'       => __( 'Remove Favorite', 'buddypress' ),
 388                      'aria-pressed'    => 'true',
 389                      'link_attr'       => bp_get_activity_unfavorite_link(),
 390                  );
 391              }
 392  
 393              $buttons['activity_favorite'] =  array(
 394                  'id'                => 'activity_favorite',
 395                  'position'          => 15,
 396                  'component'         => 'activity',
 397                  'parent_element'    => $parent_element,
 398                  'parent_attr'       => $parent_attr,
 399                  'must_be_logged_in' => true,
 400                  'button_element'    => $fav_args['button_element'],
 401                  'link_text'         => sprintf( '<span class="bp-screen-reader-text">%1$s</span>', esc_html( $fav_args['link_text'] ) ),
 402                  'button_attr'       => array(
 403                      $key              => $fav_args['link_attr'],
 404                      'class'           => $fav_args['link_class'],
 405                      'data-bp-tooltip' => $fav_args['data_bp_tooltip'],
 406                      'aria-pressed'    => $fav_args['aria-pressed'],
 407                  ),
 408              );
 409          }
 410  
 411          // The delete button is always created, and removed later on if needed.
 412          $delete_args = array();
 413  
 414          /*
 415           * As the delete link is filterable we need this workaround
 416           * to try to intercept the edits the filter made and build
 417           * a button out of it.
 418           */
 419          if ( has_filter( 'bp_get_activity_delete_link' ) ) {
 420              preg_match( '/<a\s[^>]*>(.*)<\/a>/siU', bp_get_activity_delete_link(), $link );
 421  
 422              if ( ! empty( $link[0] ) && ! empty( $link[1] ) ) {
 423                  $delete_args['link_text'] = $link[1];
 424                  $subject = str_replace( $delete_args['link_text'], '', $link[0] );
 425              }
 426  
 427              preg_match_all( '/([\w\-]+)=([^"\'> ]+|([\'"]?)(?:[^\3]|\3+)+?\3)/', $subject, $attrs );
 428  
 429              if ( ! empty( $attrs[1] ) && ! empty( $attrs[2] ) ) {
 430                  foreach ( $attrs[1] as $key_attr => $key_value ) {
 431                      $delete_args[ 'link_'. $key_value ] = trim( $attrs[2][$key_attr], '"' );
 432                  }
 433              }
 434  
 435              $delete_args = bp_parse_args(
 436                  $delete_args,
 437                  array(
 438                      'link_text'   => '',
 439                      'button_attr' => array(
 440                          'link_id'         => '',
 441                          'link_href'       => '',
 442                          'link_class'      => '',
 443                          'link_rel'        => 'nofollow',
 444                          'data_bp_tooltip' => '',
 445                      ),
 446                  ),
 447                  'nouveau_get_activity_entry_buttons'
 448              );
 449          }
 450  
 451          if ( empty( $delete_args['link_href'] ) ) {
 452              $delete_args = array(
 453                  'button_element'  => $button_element,
 454                  'link_id'         => '',
 455                  'link_class'      => 'button item-button bp-secondary-action bp-tooltip delete-activity confirm',
 456                  'link_rel'        => 'nofollow',
 457                  'data_bp_tooltip' => _x( 'Delete', 'button', 'buddypress' ),
 458                  'link_text'       => _x( 'Delete', 'button', 'buddypress' ),
 459                  'link_href'       => bp_get_activity_delete_url(),
 460              );
 461  
 462              // If button element set add nonce link to data-attr attr
 463              if ( 'button' === $button_element ) {
 464                  $delete_args['data-attr'] = bp_get_activity_delete_url();
 465                  $delete_args['link_href'] = '';
 466              } else {
 467                  $delete_args['link_href'] = bp_get_activity_delete_url();
 468                  $delete_args['data-attr'] = '';
 469              }
 470          }
 471  
 472          $buttons['activity_delete'] = array(
 473              'id'                => 'activity_delete',
 474              'position'          => 35,
 475              'component'         => 'activity',
 476              'parent_element'    => $parent_element,
 477              'parent_attr'       => $parent_attr,
 478              'must_be_logged_in' => true,
 479              'button_element'    => $button_element,
 480              'button_attr'       => array(
 481                  'id'              => $delete_args['link_id'],
 482                  'href'            => $delete_args['link_href'],
 483                  'class'           => $delete_args['link_class'],
 484                  'data-bp-tooltip' => $delete_args['data_bp_tooltip'],
 485                  'data-bp-nonce'   => $delete_args['data-attr'] ,
 486              ),
 487              'link_text'  => sprintf( '<span class="bp-screen-reader-text">%s</span>', esc_html( $delete_args['data_bp_tooltip'] ) ),
 488          );
 489  
 490          // Add the Spam Button if supported
 491          if ( bp_is_akismet_active() && isset( buddypress()->activity->akismet ) && bp_activity_user_can_mark_spam() ) {
 492              $buttons['activity_spam'] = array(
 493                  'id'                => 'activity_spam',
 494                  'position'          => 45,
 495                  'component'         => 'activity',
 496                  'parent_element'    => $parent_element,
 497                  'parent_attr'       => $parent_attr,
 498                  'must_be_logged_in' => true,
 499                  'button_element'    => $button_element,
 500                  'button_attr'       => array(
 501                      'class'           => 'bp-secondary-action spam-activity confirm button item-button bp-tooltip',
 502                      'id'              => 'activity_make_spam_' . $activity_id,
 503                      'data-bp-tooltip' => _x( 'Spam', 'button', 'buddypress' ),
 504                      ),
 505                  'link_text'  => sprintf(
 506                      /** @todo: use a specific css rule for this *************************************************************/
 507                      '<span class="dashicons dashicons-flag" style="color:#a00;vertical-align:baseline;width:18px;height:18px" aria-hidden="true"></span><span class="bp-screen-reader-text">%s</span>',
 508                      esc_html_x( 'Spam', 'button', 'buddypress' )
 509                  ),
 510              );
 511  
 512              // If button element, add nonce link to data attribute.
 513              if ( 'button' === $button_element ) {
 514                  $data_element = 'data-bp-nonce';
 515              } else {
 516                  $data_element = 'href';
 517              }
 518  
 519              $buttons['activity_spam']['button_attr'][ $data_element ] = wp_nonce_url(
 520                  bp_get_root_domain() . '/' . bp_nouveau_get_component_slug( 'activity' ) . '/spam/' . $activity_id . '/',
 521                  'bp_activity_akismet_spam_' . $activity_id
 522              );
 523          }
 524  
 525          /**
 526           * Filter to add your buttons, use the position argument to choose where to insert it.
 527           *
 528           * @since 3.0.0
 529           *
 530           * @param array $buttons     The list of buttons.
 531           * @param int   $activity_id The current activity ID.
 532           */
 533          $buttons_group = apply_filters( 'bp_nouveau_get_activity_entry_buttons', $buttons, $activity_id );
 534  
 535          if ( ! $buttons_group ) {
 536              return array();
 537          }
 538  
 539          // It's the first entry of the loop, so build the Group and sort it
 540          if ( ! isset( bp_nouveau()->activity->entry_buttons ) || ! is_a( bp_nouveau()->activity->entry_buttons, 'BP_Buttons_Group' ) ) {
 541              $sort = true;
 542              bp_nouveau()->activity->entry_buttons = new BP_Buttons_Group( $buttons_group );
 543  
 544          // It's not the first entry, the order is set, we simply need to update the Buttons Group
 545          } else {
 546              $sort = false;
 547              bp_nouveau()->activity->entry_buttons->update( $buttons_group );
 548          }
 549  
 550          $return = bp_nouveau()->activity->entry_buttons->get( $sort );
 551  
 552          if ( ! $return ) {
 553              return array();
 554          }
 555  
 556          // Remove the Comment button if the user can't comment
 557          if ( ! bp_activity_can_comment() && $activity_type !== 'activity_comment' ) {
 558              unset( $return['activity_conversation'] );
 559          }
 560  
 561          // Remove the Delete button if the user can't delete
 562          if ( ! bp_activity_user_can_delete() ) {
 563              unset( $return['activity_delete'] );
 564          }
 565  
 566          if ( isset( $return['activity_spam'] ) && ! in_array( $activity_type, BP_Akismet::get_activity_types(), true ) ) {
 567              unset( $return['activity_spam'] );
 568          }
 569  
 570          /**
 571           * Leave a chance to adjust the $return
 572           *
 573           * @since 3.0.0
 574           *
 575           * @param array $return      The list of buttons ordered.
 576           * @param int   $activity_id The current activity ID.
 577           */
 578          do_action_ref_array( 'bp_nouveau_return_activity_entry_buttons', array( &$return, $activity_id ) );
 579  
 580          return $return;
 581      }
 582  
 583  /**
 584   * Output Activity Comments if any
 585   *
 586   * @since 3.0.0
 587   */
 588  function bp_nouveau_activity_comments() {
 589      global $activities_template;
 590  
 591      if ( empty( $activities_template->activity->children ) ) {
 592          return;
 593      }
 594  
 595      bp_nouveau_activity_recurse_comments( $activities_template->activity );
 596  }
 597  
 598  /**
 599   * Loops through a level of activity comments and loads the template for each.
 600   *
 601   * Note: This is an adaptation of the bp_activity_recurse_comments() BuddyPress core function
 602   *
 603   * @since 3.0.0
 604   *
 605   * @param object $comment The activity object currently being recursed.
 606   */
 607  function bp_nouveau_activity_recurse_comments( $comment ) {
 608      global $activities_template;
 609  
 610      if ( empty( $comment->children ) ) {
 611          return;
 612      }
 613  
 614      /**
 615       * Filters the opening tag for the template that lists activity comments.
 616       *
 617       * @since 1.6.0
 618       *
 619       * @param string $value Opening tag for the HTML markup to use.
 620       */
 621      echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>' );
 622  
 623      foreach ( (array) $comment->children as $comment_child ) {
 624  
 625          // Put the comment into the global so it's available to filters.
 626          $activities_template->activity->current_comment = $comment_child;
 627  
 628          /**
 629           * Fires before the display of an activity comment.
 630           *
 631           * @since 1.5.0
 632           */
 633          do_action( 'bp_before_activity_comment' );
 634  
 635          bp_get_template_part( 'activity/comment' );
 636  
 637          /**
 638           * Fires after the display of an activity comment.
 639           *
 640           * @since 1.5.0
 641           */
 642          do_action( 'bp_after_activity_comment' );
 643  
 644          unset( $activities_template->activity->current_comment );
 645      }
 646  
 647      /**
 648       * Filters the closing tag for the template that list activity comments.
 649       *
 650       * @since 1.6.0
 651       *
 652       * @param string $value Closing tag for the HTML markup to use.
 653       */
 654      echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>' );
 655  }
 656  
 657  /**
 658   * Ouptut the Activity comment action string
 659   *
 660   * @since 3.0.0
 661   */
 662  function bp_nouveau_activity_comment_action() {
 663      echo bp_nouveau_get_activity_comment_action();
 664  }
 665  
 666      /**
 667       * Get the Activity comment action string
 668       *
 669       * @since 3.0.0
 670       */
 671  	function bp_nouveau_get_activity_comment_action() {
 672  
 673          /**
 674           * Filter to edit the activity comment action.
 675           *
 676           * @since 3.0.0
 677           *
 678           * @param string $value HTML Output
 679           */
 680          return apply_filters( 'bp_nouveau_get_activity_comment_action',
 681              /* translators: 1: user profile link, 2: user name, 3: activity permalink, 4: activity recorded date, 5: activity timestamp, 6: activity human time since */
 682              sprintf( __( '<a href="%1$s">%2$s</a> replied <a href="%3$s" class="activity-time-since"><time class="time-since" datetime="%4$s" data-bp-timestamp="%5$d">%6$s</time></a>', 'buddypress' ),
 683                  esc_url( bp_get_activity_comment_user_link() ),
 684                  esc_html( bp_get_activity_comment_name() ),
 685                  esc_url( bp_get_activity_comment_permalink() ),
 686                  esc_attr( bp_get_activity_comment_date_recorded_raw() ),
 687                  esc_attr( strtotime( bp_get_activity_comment_date_recorded_raw() ) ),
 688                  esc_attr( bp_get_activity_comment_date_recorded() )
 689          ) );
 690      }
 691  
 692  /**
 693   * Load the Activity comment form
 694   *
 695   * @since 3.0.0
 696   */
 697  function bp_nouveau_activity_comment_form() {
 698      bp_get_template_part( 'activity/comment-form' );
 699  }
 700  
 701  /**
 702   * Output the action buttons for the activity comments
 703   *
 704   * @since 3.0.0
 705   *
 706   * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 707   */
 708  function bp_nouveau_activity_comment_buttons( $args = array() ) {
 709      $output = join( ' ', bp_nouveau_get_activity_comment_buttons( $args ) );
 710  
 711      ob_start();
 712      /**
 713       * Fires after the defualt comment action options display.
 714       *
 715       * @since 1.6.0
 716       */
 717      do_action( 'bp_activity_comment_options' );
 718  
 719      $output     .= ob_get_clean();
 720      $has_content = trim( $output, ' ' );
 721      if ( ! $has_content ) {
 722          return;
 723      }
 724  
 725      if ( ! $args ) {
 726          $args = array( 'classes' => array( 'acomment-options' ) );
 727      }
 728  
 729      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 730  }
 731  
 732      /**
 733       * Get the action buttons for the activity comments
 734       *
 735       * @since 3.0.0
 736       *
 737       * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 738       *
 739       * @return array
 740       */
 741  	function bp_nouveau_get_activity_comment_buttons($args) {
 742          $buttons = array();
 743  
 744          if ( ! isset( $GLOBALS['activities_template'] ) ) {
 745              return $buttons;
 746          }
 747  
 748          $activity_comment_id = bp_get_activity_comment_id();
 749          $activity_id         = bp_get_activity_id();
 750  
 751          if ( ! $activity_comment_id || ! $activity_id ) {
 752              return $buttons;
 753          }
 754  
 755          /*
 756           * If the 'container' is set to 'ul'
 757           * set a var $parent_element to li
 758           * otherwise simply pass any value found in args
 759           * or set var false.
 760           */
 761          if ( 'ul' === $args['container']  ) {
 762              $parent_element = 'li';
 763          } elseif ( ! empty( $args['parent_element'] ) ) {
 764              $parent_element = $args['parent_element'];
 765          } else {
 766              $parent_element = false;
 767          }
 768  
 769          $parent_attr = ( ! empty( $args['parent_attr'] ) ) ? $args['parent_attr'] : array();
 770  
 771          /*
 772           * If we have a arg value for $button_element passed through
 773           * use it to default all the $buttons['button_element'] values
 774           * otherwise default to 'a' (anchor).
 775           */
 776          if ( ! empty( $args['button_element'] ) ) {
 777              $button_element = $args['button_element'] ;
 778          } else {
 779              $button_element = 'a';
 780          }
 781  
 782          $buttons = array(
 783              'activity_comment_reply' => array(
 784                  'id'                => 'activity_comment_reply',
 785                  'position'          => 5,
 786                  'component'         => 'activity',
 787                  'must_be_logged_in' => true,
 788                  'parent_element'    => $parent_element,
 789                  'parent_attr'       => $parent_attr,
 790                  'button_element'    => $button_element,
 791                  'link_text'         => _x( 'Reply', 'link', 'buddypress' ),
 792                  'button_attr'       => array(
 793                      'class' => "acomment-reply bp-primary-action",
 794                      'id'    => sprintf( 'acomment-reply-%1$s-from-%2$s', $activity_id, $activity_comment_id ),
 795                  ),
 796              ),
 797              'activity_comment_delete' => array(
 798                  'id'                => 'activity_comment_delete',
 799                  'position'          => 15,
 800                  'component'         => 'activity',
 801                  'must_be_logged_in' => true,
 802                  'parent_element'    => $parent_element,
 803                  'parent_attr'       => $parent_attr,
 804                  'button_element'    => $button_element,
 805                  'link_text'         => _x( 'Delete', 'link', 'buddypress' ),
 806                  'button_attr'       => array(
 807                      'class' => 'delete acomment-delete confirm bp-secondary-action',
 808                      'rel'   => 'nofollow',
 809                  ),
 810              ),
 811          );
 812  
 813          // If button element set add nonce link to data-attr attr
 814          if ( 'button' === $button_element ) {
 815              $buttons['activity_comment_reply']['button_attr']['data-bp-act-reply-nonce'] = sprintf( '#acomment-%s', $activity_comment_id );
 816              $buttons['activity_comment_delete']['button_attr']['data-bp-act-reply-delete-nonce'] = bp_get_activity_comment_delete_link();
 817          } else {
 818              $buttons['activity_comment_reply']['button_attr']['href'] = sprintf( '#acomment-%s', $activity_comment_id );
 819              $buttons['activity_comment_delete']['button_attr']['href'] = bp_get_activity_comment_delete_link();
 820          }
 821  
 822          // Add the Spam Button if supported
 823          if ( bp_is_akismet_active() && isset( buddypress()->activity->akismet ) && bp_activity_user_can_mark_spam() ) {
 824              $buttons['activity_comment_spam'] = array(
 825                  'id'                => 'activity_comment_spam',
 826                  'position'          => 25,
 827                  'component'         => 'activity',
 828                  'must_be_logged_in' => true,
 829                  'parent_element'    => $parent_element,
 830                  'parent_attr'       => $parent_attr,
 831                  'button_element'    => $button_element,
 832                  'link_text'         => _x( 'Spam', 'link', 'buddypress' ),
 833                  'button_attr'       => array(
 834                      'id'     => "activity_make_spam_{$activity_comment_id}",
 835                      'class'  => 'bp-secondary-action spam-activity-comment confirm',
 836                      'rel'    => 'nofollow',
 837                  ),
 838              );
 839  
 840              // If button element set add nonce link to data-attr attr
 841              if ( 'button' === $button_element ) {
 842                  $data_element = 'data-bp-act-spam-nonce';
 843              } else {
 844                  $data_element = 'href';
 845              }
 846  
 847              $buttons['activity_comment_spam']['button_attr'][ $data_element ] = wp_nonce_url(
 848                  bp_get_root_domain() . '/' . bp_nouveau_get_component_slug( 'activity' ) . '/spam/' . $activity_comment_id . '/?cid=' . $activity_comment_id,
 849                  'bp_activity_akismet_spam_' . $activity_comment_id
 850              );
 851          }
 852  
 853          /**
 854           * Filter to add your buttons, use the position argument to choose where to insert it.
 855           *
 856           * @since 3.0.0
 857           *
 858           * @param array $buttons             The list of buttons.
 859           * @param int   $activity_comment_id The current activity comment ID.
 860           * @param int   $activity_id         The current activity ID.
 861           */
 862          $buttons_group = apply_filters( 'bp_nouveau_get_activity_comment_buttons', $buttons, $activity_comment_id, $activity_id );
 863  
 864          if ( ! $buttons_group ) {
 865              return $buttons;
 866          }
 867  
 868          // It's the first comment of the loop, so build the Group and sort it
 869          if ( ! isset( bp_nouveau()->activity->comment_buttons ) || ! is_a( bp_nouveau()->activity->comment_buttons, 'BP_Buttons_Group' ) ) {
 870              $sort = true;
 871              bp_nouveau()->activity->comment_buttons = new BP_Buttons_Group( $buttons_group );
 872  
 873          // It's not the first comment, the order is set, we simply need to update the Buttons Group
 874          } else {
 875              $sort = false;
 876              bp_nouveau()->activity->comment_buttons->update( $buttons_group );
 877          }
 878  
 879          $return = bp_nouveau()->activity->comment_buttons->get( $sort );
 880  
 881          if ( ! $return ) {
 882              return array();
 883          }
 884  
 885          /**
 886           * If post comment / Activity comment sync is on, it's safer
 887           * to unset the comment button just before returning it.
 888           */
 889          if ( ! bp_activity_can_comment_reply( bp_activity_current_comment() ) ) {
 890              unset( $return['activity_comment_reply'] );
 891          }
 892  
 893          /**
 894           * If there was an activity of the user before one af another
 895           * user as we're updating buttons, we need to unset the delete link
 896           */
 897          if ( ! bp_activity_user_can_delete() ) {
 898              unset( $return['activity_comment_delete'] );
 899          }
 900  
 901          if ( isset( $return['activity_comment_spam'] ) && ( ! bp_activity_current_comment() || ! in_array( bp_activity_current_comment()->type, BP_Akismet::get_activity_types(), true ) ) ) {
 902              unset( $return['activity_comment_spam'] );
 903          }
 904  
 905          /**
 906           * Leave a chance to adjust the $return
 907           *
 908           * @since 3.0.0
 909           *
 910           * @param array $return              The list of buttons ordered.
 911           * @param int   $activity_comment_id The current activity comment ID.
 912           * @param int   $activity_id         The current activity ID.
 913           */
 914          do_action_ref_array( 'bp_nouveau_return_activity_comment_buttons', array( &$return, $activity_comment_id, $activity_id ) );
 915  
 916          return $return;
 917      }
 918  
 919  /**
 920   * Outputs the Activity RSS link.
 921   *
 922   * @since 8.0.0
 923   */
 924  function bp_nouveau_activity_rss_link() {
 925      echo esc_url( bp_nouveau_activity_get_rss_link() );
 926  }
 927  
 928      /**
 929       * Returns the Activity RSS link.
 930       *
 931       * @since 8.0.0
 932       *
 933       * @return string The Activity RSS link.
 934       */
 935  	function bp_nouveau_activity_get_rss_link() {
 936          $bp_nouveau = bp_nouveau();
 937          $link       = '';
 938  
 939          if ( isset( $bp_nouveau->activity->current_rss_feed['link'] ) ) {
 940              $link = $bp_nouveau->activity->current_rss_feed['link'];
 941          }
 942  
 943          /**
 944           * Filter here to edit the Activity RSS link.
 945           *
 946           * @since 8.0.0
 947           *
 948           * @param string The Activity RSS link.
 949           */
 950          return apply_filters( 'bp_nouveau_activity_get_rss_link', $link );
 951      }
 952  
 953  /**
 954   * Outputs the Activity RSS Tooltip.
 955   *
 956   * @since 8.0.0
 957   */
 958  function bp_nouveau_activity_rss_tooltip() {
 959      echo esc_attr( bp_nouveau_activity_get_rss_tooltip() );
 960  }
 961  
 962      /**
 963       * Returns the Activity RSS Tooltip.
 964       *
 965       * @since 8.0.0
 966       *
 967       * @return string The Activity RSS Tooltip.
 968       */
 969  	function bp_nouveau_activity_get_rss_tooltip() {
 970          $bp_nouveau = bp_nouveau();
 971          $tooltip       = '';
 972  
 973          if ( isset( $bp_nouveau->activity->current_rss_feed['tooltip'] ) ) {
 974              $tooltip = $bp_nouveau->activity->current_rss_feed['tooltip'];
 975          }
 976  
 977          /**
 978           * Filter here to edit the Activity RSS Tooltip.
 979           *
 980           * @since 8.0.0
 981           *
 982           * @param string The Activity RSS Tooltip.
 983           */
 984          return apply_filters( 'bp_nouveau_activity_get_rss_tooltip', $tooltip );
 985      }
 986  
 987  /**
 988   * Outputs the Activity RSS screen reader text.
 989   *
 990   * @since 8.0.0
 991   */
 992  function bp_nouveau_activity_rss_screen_reader_text() {
 993      echo esc_attr( bp_nouveau_activity_get_rss_screen_reader_text() );
 994  }
 995  
 996      /**
 997       * Returns the Activity RSS screen reader text.
 998       *
 999       * @since 8.0.0
1000       *
1001       * @return string The Activity RSS screen reader text.
1002       */
1003      function bp_nouveau_activity_get_rss_screen_reader_text() {
1004          $bp_nouveau         = bp_nouveau();
1005          $screen_reader_text = '';
1006  
1007          if ( isset( $bp_nouveau->activity->current_rss_feed['tooltip'] ) ) {
1008              $screen_reader_text = $bp_nouveau->activity->current_rss_feed['tooltip'];
1009          }
1010  
1011          /**
1012           * Filter here to edit the Activity RSS screen reader text.
1013           *
1014           * @since 8.0.0
1015           *
1016           * @param string The Activity RSS screen reader text.
1017           */
1018          return apply_filters( 'bp_nouveau_activity_get_rss_screen_reader_text', $screen_reader_text );
1019      }


Generated: Mon Jun 21 01:01:38 2021 Cross-referenced by PHPXref 0.7.1