[ 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 5.0.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  	function bp_nouveau_get_activity_entry_buttons( $args ) {
 245          $buttons = array();
 246  
 247          if ( ! isset( $GLOBALS['activities_template'] ) ) {
 248              return $buttons;
 249          }
 250  
 251          $activity_id    = bp_get_activity_id();
 252          $activity_type  = bp_get_activity_type();
 253          $parent_element = '';
 254          $button_element = 'a';
 255  
 256          if ( ! $activity_id ) {
 257              return $buttons;
 258          }
 259  
 260          /*
 261           * If the container is set to 'ul' force the $parent_element to 'li',
 262           * else use parent_element args if set.
 263           *
 264           * This will render li elements around anchors/buttons.
 265           */
 266          if ( isset( $args['container'] ) && 'ul' === $args['container'] ) {
 267              $parent_element = 'li';
 268          } elseif ( ! empty( $args['parent_element'] ) ) {
 269              $parent_element = $args['parent_element'];
 270          }
 271  
 272          $parent_attr = ( ! empty( $args['parent_attr'] ) ) ? $args['parent_attr'] : array();
 273  
 274          /*
 275           * If we have a arg value for $button_element passed through
 276           * use it to default all the $buttons['button_element'] values
 277           * otherwise default to 'a' (anchor)
 278           * Or override & hardcode the 'element' string on $buttons array.
 279           *
 280           */
 281          if ( ! empty( $args['button_element'] ) ) {
 282              $button_element = $args['button_element'];
 283          }
 284  
 285          /*
 286           * The view conversation button and the comment one are sharing
 287           * the same id because when display_comments is on stream mode,
 288           * it is not possible to comment an activity comment and as we
 289           * are updating the links to avoid sorting the activity buttons
 290           * for each entry of the loop, it's a convenient way to make
 291           * sure the right button will be displayed.
 292           */
 293          if ( $activity_type === 'activity_comment' ) {
 294              $buttons['activity_conversation'] = array(
 295                  'id'                => 'activity_conversation',
 296                  'position'          => 5,
 297                  'component'         => 'activity',
 298                  'parent_element'    => $parent_element,
 299                  'parent_attr'       => $parent_attr,
 300                  'must_be_logged_in' => false,
 301                  'button_element'    => $button_element,
 302                  'button_attr'       => array(
 303                      'class'           => 'button view bp-secondary-action bp-tooltip',
 304                      'data-bp-tooltip' => __( 'View Conversation', 'buddypress' ),
 305                      ),
 306                  'link_text' => sprintf(
 307                      '<span class="bp-screen-reader-text">%1$s</span>',
 308                      __( 'View Conversation', 'buddypress' )
 309                  ),
 310              );
 311  
 312              // If button element set add url link to data-attr
 313              if ( 'button' === $button_element ) {
 314                  $buttons['activity_conversation']['button_attr']['data-bp-url'] = bp_get_activity_thread_permalink();
 315              } else {
 316                  $buttons['activity_conversation']['button_attr']['href'] = bp_get_activity_thread_permalink();
 317                  $buttons['activity_conversation']['button_attr']['role'] = 'button';
 318              }
 319  
 320          /*
 321           * We always create the Button to make sure we always have the right numbers of buttons,
 322           * no matter the previous activity had less.
 323           */
 324          } else {
 325              $buttons['activity_conversation'] =  array(
 326                  'id'                => 'activity_conversation',
 327                  'position'          => 5,
 328                  'component'         => 'activity',
 329                  'parent_element'    => $parent_element,
 330                  'parent_attr'       => $parent_attr,
 331                  'must_be_logged_in' => true,
 332                  'button_element'    => $button_element,
 333                  'button_attr'       => array(
 334                      'id'              => 'acomment-comment-' . $activity_id,
 335                      'class'           => 'button acomment-reply bp-primary-action bp-tooltip',
 336                      'data-bp-tooltip' => _x( 'Comment', 'button', 'buddypress' ),
 337                      'aria-expanded'   => 'false',
 338                  ),
 339                  'link_text'  => sprintf(
 340                      '<span class="bp-screen-reader-text">%1$s</span> <span class="comment-count">%2$s</span>',
 341                      _x( 'Comment', 'link', 'buddypress' ),
 342                      esc_html( bp_activity_get_comment_count() )
 343                  ),
 344              );
 345  
 346              // If button element set add href link to data-attr
 347              if ( 'button' === $button_element ) {
 348                  $buttons['activity_conversation']['button_attr']['data-bp-url'] = bp_get_activity_comment_link();
 349              } else {
 350                  $buttons['activity_conversation']['button_attr']['href'] = bp_get_activity_comment_link();
 351                  $buttons['activity_conversation']['button_attr']['role'] = 'button';
 352              }
 353  
 354          }
 355  
 356          if ( bp_activity_can_favorite() ) {
 357  
 358              // If button element set attr needs to be data-* else 'href'
 359              if ( 'button' === $button_element ) {
 360                  $key = 'data-bp-nonce';
 361              } else {
 362                  $key = 'href';
 363              }
 364  
 365              if ( ! bp_get_activity_is_favorite() ) {
 366                  $fav_args = array(
 367                      'parent_element'   => $parent_element,
 368                      'parent_attr'      => $parent_attr,
 369                      'button_element'   => $button_element,
 370                      'link_class'       => 'button fav bp-secondary-action bp-tooltip',
 371                      'data_bp_tooltip'  => __( 'Mark as Favorite', 'buddypress' ),
 372                      'link_text'        => __( 'Mark as Favorite', 'buddypress' ),
 373                      'aria-pressed'     => 'false',
 374                      'link_attr'        => bp_get_activity_favorite_link(),
 375                  );
 376  
 377              } else {
 378                  $fav_args = array(
 379                      'parent_element'  => $parent_element,
 380                      'parent_attr'     => $parent_attr,
 381                      'button_element'  => $button_element,
 382                      'link_class'      => 'button unfav bp-secondary-action bp-tooltip',
 383                      'data_bp_tooltip' => __( 'Remove Favorite', 'buddypress' ),
 384                      'link_text'       => __( 'Remove Favorite', 'buddypress' ),
 385                      'aria-pressed'    => 'true',
 386                      'link_attr'       => bp_get_activity_unfavorite_link(),
 387                  );
 388              }
 389  
 390              $buttons['activity_favorite'] =  array(
 391                  'id'                => 'activity_favorite',
 392                  'position'          => 15,
 393                  'component'         => 'activity',
 394                  'parent_element'    => $parent_element,
 395                  'parent_attr'       => $parent_attr,
 396                  'must_be_logged_in' => true,
 397                  'button_element'    => $fav_args['button_element'],
 398                  'link_text'         => sprintf( '<span class="bp-screen-reader-text">%1$s</span>', esc_html( $fav_args['link_text'] ) ),
 399                  'button_attr'       => array(
 400                      $key              => $fav_args['link_attr'],
 401                      'class'           => $fav_args['link_class'],
 402                      'data-bp-tooltip' => $fav_args['data_bp_tooltip'],
 403                      'aria-pressed'    => $fav_args['aria-pressed'],
 404                  ),
 405              );
 406          }
 407  
 408          // The delete button is always created, and removed later on if needed.
 409          $delete_args = array();
 410  
 411          /*
 412           * As the delete link is filterable we need this workaround
 413           * to try to intercept the edits the filter made and build
 414           * a button out of it.
 415           */
 416          if ( has_filter( 'bp_get_activity_delete_link' ) ) {
 417              preg_match( '/<a\s[^>]*>(.*)<\/a>/siU', bp_get_activity_delete_link(), $link );
 418  
 419              if ( ! empty( $link[0] ) && ! empty( $link[1] ) ) {
 420                  $delete_args['link_text'] = $link[1];
 421                  $subject = str_replace( $delete_args['link_text'], '', $link[0] );
 422              }
 423  
 424              preg_match_all( '/([\w\-]+)=([^"\'> ]+|([\'"]?)(?:[^\3]|\3+)+?\3)/', $subject, $attrs );
 425  
 426              if ( ! empty( $attrs[1] ) && ! empty( $attrs[2] ) ) {
 427                  foreach ( $attrs[1] as $key_attr => $key_value ) {
 428                      $delete_args[ 'link_'. $key_value ] = trim( $attrs[2][$key_attr], '"' );
 429                  }
 430              }
 431  
 432              $delete_args = bp_parse_args(
 433                  $delete_args,
 434                  array(
 435                      'link_text'   => '',
 436                      'button_attr' => array(
 437                          'link_id'         => '',
 438                          'link_href'       => '',
 439                          'link_class'      => '',
 440                          'link_rel'        => 'nofollow',
 441                          'data_bp_tooltip' => '',
 442                      ),
 443                  ),
 444                  'nouveau_get_activity_entry_buttons'
 445              );
 446          }
 447  
 448          if ( empty( $delete_args['link_href'] ) ) {
 449              $delete_args = array(
 450                  'button_element'  => $button_element,
 451                  'link_id'         => '',
 452                  'link_class'      => 'button item-button bp-secondary-action bp-tooltip delete-activity confirm',
 453                  'link_rel'        => 'nofollow',
 454                  'data_bp_tooltip' => _x( 'Delete', 'button', 'buddypress' ),
 455                  'link_text'       => _x( 'Delete', 'button', 'buddypress' ),
 456                  'link_href'       => bp_get_activity_delete_url(),
 457              );
 458  
 459              // If button element set add nonce link to data-attr attr
 460              if ( 'button' === $button_element ) {
 461                  $delete_args['data-attr'] = bp_get_activity_delete_url();
 462                  $delete_args['link_href'] = '';
 463              } else {
 464                  $delete_args['link_href'] = bp_get_activity_delete_url();
 465                  $delete_args['data-attr'] = '';
 466              }
 467          }
 468  
 469          $buttons['activity_delete'] = array(
 470              'id'                => 'activity_delete',
 471              'position'          => 35,
 472              'component'         => 'activity',
 473              'parent_element'    => $parent_element,
 474              'parent_attr'       => $parent_attr,
 475              'must_be_logged_in' => true,
 476              'button_element'    => $button_element,
 477              'button_attr'       => array(
 478                  'id'              => $delete_args['link_id'],
 479                  'href'            => $delete_args['link_href'],
 480                  'class'           => $delete_args['link_class'],
 481                  'data-bp-tooltip' => $delete_args['data_bp_tooltip'],
 482                  'data-bp-nonce'   => $delete_args['data-attr'] ,
 483              ),
 484              'link_text'  => sprintf( '<span class="bp-screen-reader-text">%s</span>', esc_html( $delete_args['data_bp_tooltip'] ) ),
 485          );
 486  
 487          // Add the Spam Button if supported
 488          if ( bp_is_akismet_active() && isset( buddypress()->activity->akismet ) && bp_activity_user_can_mark_spam() ) {
 489              $buttons['activity_spam'] = array(
 490                  'id'                => 'activity_spam',
 491                  'position'          => 45,
 492                  'component'         => 'activity',
 493                  'parent_element'    => $parent_element,
 494                  'parent_attr'       => $parent_attr,
 495                  'must_be_logged_in' => true,
 496                  'button_element'    => $button_element,
 497                  'button_attr'       => array(
 498                      'class'           => 'bp-secondary-action spam-activity confirm button item-button bp-tooltip',
 499                      'id'              => 'activity_make_spam_' . $activity_id,
 500                      'data-bp-tooltip' => _x( 'Spam', 'button', 'buddypress' ),
 501                      ),
 502                  'link_text'  => sprintf(
 503                      /** @todo: use a specific css rule for this *************************************************************/
 504                      '<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>',
 505                      esc_html_x( 'Spam', 'button', 'buddypress' )
 506                  ),
 507              );
 508  
 509              // If button element, add nonce link to data attribute.
 510              if ( 'button' === $button_element ) {
 511                  $data_element = 'data-bp-nonce';
 512              } else {
 513                  $data_element = 'href';
 514              }
 515  
 516              $buttons['activity_spam']['button_attr'][ $data_element ] = wp_nonce_url(
 517                  bp_get_root_domain() . '/' . bp_get_activity_slug() . '/spam/' . $activity_id . '/',
 518                  'bp_activity_akismet_spam_' . $activity_id
 519              );
 520          }
 521  
 522          /**
 523           * Filter to add your buttons, use the position argument to choose where to insert it.
 524           *
 525           * @since 3.0.0
 526           *
 527           * @param array $buttons     The list of buttons.
 528           * @param int   $activity_id The current activity ID.
 529           */
 530          $buttons_group = apply_filters( 'bp_nouveau_get_activity_entry_buttons', $buttons, $activity_id );
 531  
 532          if ( ! $buttons_group ) {
 533              return $buttons;
 534          }
 535  
 536          // It's the first entry of the loop, so build the Group and sort it
 537          if ( ! isset( bp_nouveau()->activity->entry_buttons ) || ! is_a( bp_nouveau()->activity->entry_buttons, 'BP_Buttons_Group' ) ) {
 538              $sort = true;
 539              bp_nouveau()->activity->entry_buttons = new BP_Buttons_Group( $buttons_group );
 540  
 541          // It's not the first entry, the order is set, we simply need to update the Buttons Group
 542          } else {
 543              $sort = false;
 544              bp_nouveau()->activity->entry_buttons->update( $buttons_group );
 545          }
 546  
 547          $return = bp_nouveau()->activity->entry_buttons->get( $sort );
 548  
 549          if ( ! $return ) {
 550              return array();
 551          }
 552  
 553          // Remove the Comment button if the user can't comment
 554          if ( ! bp_activity_can_comment() && $activity_type !== 'activity_comment' ) {
 555              unset( $return['activity_conversation'] );
 556          }
 557  
 558          // Remove the Delete button if the user can't delete
 559          if ( ! bp_activity_user_can_delete() ) {
 560              unset( $return['activity_delete'] );
 561          }
 562  
 563          if ( isset( $return['activity_spam'] ) && ! in_array( $activity_type, BP_Akismet::get_activity_types(), true ) ) {
 564              unset( $return['activity_spam'] );
 565          }
 566  
 567          /**
 568           * Leave a chance to adjust the $return
 569           *
 570           * @since 3.0.0
 571           *
 572           * @param array $return      The list of buttons ordered.
 573           * @param int   $activity_id The current activity ID.
 574           */
 575          do_action_ref_array( 'bp_nouveau_return_activity_entry_buttons', array( &$return, $activity_id ) );
 576  
 577          return $return;
 578      }
 579  
 580  /**
 581   * Output Activity Comments if any
 582   *
 583   * @since 3.0.0
 584   */
 585  function bp_nouveau_activity_comments() {
 586      global $activities_template;
 587  
 588      if ( empty( $activities_template->activity->children ) ) {
 589          return;
 590      }
 591  
 592      bp_nouveau_activity_recurse_comments( $activities_template->activity );
 593  }
 594  
 595  /**
 596   * Loops through a level of activity comments and loads the template for each.
 597   *
 598   * Note: This is an adaptation of the bp_activity_recurse_comments() BuddyPress core function
 599   *
 600   * @since 3.0.0
 601   *
 602   * @param object $comment The activity object currently being recursed.
 603   */
 604  function bp_nouveau_activity_recurse_comments( $comment ) {
 605      global $activities_template;
 606  
 607      if ( empty( $comment->children ) ) {
 608          return;
 609      }
 610  
 611      /**
 612       * Filters the opening tag for the template that lists activity comments.
 613       *
 614       * @since 1.6.0
 615       *
 616       * @param string $value Opening tag for the HTML markup to use.
 617       */
 618      echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>' );
 619  
 620      foreach ( (array) $comment->children as $comment_child ) {
 621  
 622          // Put the comment into the global so it's available to filters.
 623          $activities_template->activity->current_comment = $comment_child;
 624  
 625          /**
 626           * Fires before the display of an activity comment.
 627           *
 628           * @since 1.5.0
 629           */
 630          do_action( 'bp_before_activity_comment' );
 631  
 632          bp_get_template_part( 'activity/comment' );
 633  
 634          /**
 635           * Fires after the display of an activity comment.
 636           *
 637           * @since 1.5.0
 638           */
 639          do_action( 'bp_after_activity_comment' );
 640  
 641          unset( $activities_template->activity->current_comment );
 642      }
 643  
 644      /**
 645       * Filters the closing tag for the template that list activity comments.
 646       *
 647       * @since 1.6.0
 648       *
 649       * @param string $value Closing tag for the HTML markup to use.
 650       */
 651      echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>' );
 652  }
 653  
 654  /**
 655   * Ouptut the Activity comment action string
 656   *
 657   * @since 3.0.0
 658   */
 659  function bp_nouveau_activity_comment_action() {
 660      echo bp_nouveau_get_activity_comment_action();
 661  }
 662  
 663      /**
 664       * Get the Activity comment action string
 665       *
 666       * @since 3.0.0
 667       */
 668  	function bp_nouveau_get_activity_comment_action() {
 669  
 670          /**
 671           * Filter to edit the activity comment action.
 672           *
 673           * @since 3.0.0
 674           *
 675           * @param string $value HTML Output
 676           */
 677          return apply_filters( 'bp_nouveau_get_activity_comment_action',
 678              /* translators: 1: user profile link, 2: user name, 3: activity permalink, 4: activity recorded date, 5: activity timestamp, 6: activity human time since */
 679              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' ),
 680                  esc_url( bp_get_activity_comment_user_link() ),
 681                  esc_html( bp_get_activity_comment_name() ),
 682                  esc_url( bp_get_activity_comment_permalink() ),
 683                  esc_attr( bp_get_activity_comment_date_recorded_raw() ),
 684                  esc_attr( strtotime( bp_get_activity_comment_date_recorded_raw() ) ),
 685                  esc_attr( bp_get_activity_comment_date_recorded() )
 686          ) );
 687      }
 688  
 689  /**
 690   * Load the Activity comment form
 691   *
 692   * @since 3.0.0
 693   */
 694  function bp_nouveau_activity_comment_form() {
 695      bp_get_template_part( 'activity/comment-form' );
 696  }
 697  
 698  /**
 699   * Output the action buttons for the activity comments
 700   *
 701   * @since 3.0.0
 702   *
 703   * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 704   */
 705  function bp_nouveau_activity_comment_buttons( $args = array() ) {
 706      $output = join( ' ', bp_nouveau_get_activity_comment_buttons( $args ) );
 707  
 708      ob_start();
 709      /**
 710       * Fires after the defualt comment action options display.
 711       *
 712       * @since 1.6.0
 713       */
 714      do_action( 'bp_activity_comment_options' );
 715  
 716      $output     .= ob_get_clean();
 717      $has_content = trim( $output, ' ' );
 718      if ( ! $has_content ) {
 719          return;
 720      }
 721  
 722      if ( ! $args ) {
 723          $args = array( 'classes' => array( 'acomment-options' ) );
 724      }
 725  
 726      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 727  }
 728  
 729      /**
 730       * Get the action buttons for the activity comments
 731       *
 732       * @since 3.0.0
 733       *
 734       * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 735       *
 736       * @return array
 737       */
 738  	function bp_nouveau_get_activity_comment_buttons($args) {
 739          $buttons = array();
 740  
 741          if ( ! isset( $GLOBALS['activities_template'] ) ) {
 742              return $buttons;
 743          }
 744  
 745          $activity_comment_id = bp_get_activity_comment_id();
 746          $activity_id         = bp_get_activity_id();
 747  
 748          if ( ! $activity_comment_id || ! $activity_id ) {
 749              return $buttons;
 750          }
 751  
 752          /*
 753           * If the 'container' is set to 'ul'
 754           * set a var $parent_element to li
 755           * otherwise simply pass any value found in args
 756           * or set var false.
 757           */
 758          if ( 'ul' === $args['container']  ) {
 759              $parent_element = 'li';
 760          } elseif ( ! empty( $args['parent_element'] ) ) {
 761              $parent_element = $args['parent_element'];
 762          } else {
 763              $parent_element = false;
 764          }
 765  
 766          $parent_attr = ( ! empty( $args['parent_attr'] ) ) ? $args['parent_attr'] : array();
 767  
 768          /*
 769           * If we have a arg value for $button_element passed through
 770           * use it to default all the $buttons['button_element'] values
 771           * otherwise default to 'a' (anchor).
 772           */
 773          if ( ! empty( $args['button_element'] ) ) {
 774              $button_element = $args['button_element'] ;
 775          } else {
 776              $button_element = 'a';
 777          }
 778  
 779          $buttons = array(
 780              'activity_comment_reply' => array(
 781                  'id'                => 'activity_comment_reply',
 782                  'position'          => 5,
 783                  'component'         => 'activity',
 784                  'must_be_logged_in' => true,
 785                  'parent_element'    => $parent_element,
 786                  'parent_attr'       => $parent_attr,
 787                  'button_element'    => $button_element,
 788                  'link_text'         => _x( 'Reply', 'link', 'buddypress' ),
 789                  'button_attr'       => array(
 790                      'class' => "acomment-reply bp-primary-action",
 791                      'id'    => sprintf( 'acomment-reply-%1$s-from-%2$s', $activity_id, $activity_comment_id ),
 792                  ),
 793              ),
 794              'activity_comment_delete' => array(
 795                  'id'                => 'activity_comment_delete',
 796                  'position'          => 15,
 797                  'component'         => 'activity',
 798                  'must_be_logged_in' => true,
 799                  'parent_element'    => $parent_element,
 800                  'parent_attr'       => $parent_attr,
 801                  'button_element'    => $button_element,
 802                  'link_text'         => _x( 'Delete', 'link', 'buddypress' ),
 803                  'button_attr'       => array(
 804                      'class' => 'delete acomment-delete confirm bp-secondary-action',
 805                      'rel'   => 'nofollow',
 806                  ),
 807              ),
 808          );
 809  
 810          // If button element set add nonce link to data-attr attr
 811          if ( 'button' === $button_element ) {
 812              $buttons['activity_comment_reply']['button_attr']['data-bp-act-reply-nonce'] = sprintf( '#acomment-%s', $activity_comment_id );
 813              $buttons['activity_comment_delete']['button_attr']['data-bp-act-reply-delete-nonce'] = bp_get_activity_comment_delete_link();
 814          } else {
 815              $buttons['activity_comment_reply']['button_attr']['href'] = sprintf( '#acomment-%s', $activity_comment_id );
 816              $buttons['activity_comment_delete']['button_attr']['href'] = bp_get_activity_comment_delete_link();
 817          }
 818  
 819          // Add the Spam Button if supported
 820          if ( bp_is_akismet_active() && isset( buddypress()->activity->akismet ) && bp_activity_user_can_mark_spam() ) {
 821              $buttons['activity_comment_spam'] = array(
 822                  'id'                => 'activity_comment_spam',
 823                  'position'          => 25,
 824                  'component'         => 'activity',
 825                  'must_be_logged_in' => true,
 826                  'parent_element'    => $parent_element,
 827                  'parent_attr'       => $parent_attr,
 828                  'button_element'    => $button_element,
 829                  'link_text'         => _x( 'Spam', 'link', 'buddypress' ),
 830                  'button_attr'       => array(
 831                      'id'     => "activity_make_spam_{$activity_comment_id}",
 832                      'class'  => 'bp-secondary-action spam-activity-comment confirm',
 833                      'rel'    => 'nofollow',
 834                  ),
 835              );
 836  
 837              // If button element set add nonce link to data-attr attr
 838              if ( 'button' === $button_element ) {
 839                  $data_element = 'data-bp-act-spam-nonce';
 840              } else {
 841                  $data_element = 'href';
 842              }
 843  
 844              $buttons['activity_comment_spam']['button_attr'][ $data_element ] = wp_nonce_url(
 845                  bp_get_root_domain() . '/' . bp_get_activity_slug() . '/spam/' . $activity_comment_id . '/?cid=' . $activity_comment_id,
 846                  'bp_activity_akismet_spam_' . $activity_comment_id
 847              );
 848          }
 849  
 850          /**
 851           * Filter to add your buttons, use the position argument to choose where to insert it.
 852           *
 853           * @since 3.0.0
 854           *
 855           * @param array $buttons             The list of buttons.
 856           * @param int   $activity_comment_id The current activity comment ID.
 857           * @param int   $activity_id         The current activity ID.
 858           */
 859          $buttons_group = apply_filters( 'bp_nouveau_get_activity_comment_buttons', $buttons, $activity_comment_id, $activity_id );
 860  
 861          if ( ! $buttons_group ) {
 862              return $buttons;
 863          }
 864  
 865          // It's the first comment of the loop, so build the Group and sort it
 866          if ( ! isset( bp_nouveau()->activity->comment_buttons ) || ! is_a( bp_nouveau()->activity->comment_buttons, 'BP_Buttons_Group' ) ) {
 867              $sort = true;
 868              bp_nouveau()->activity->comment_buttons = new BP_Buttons_Group( $buttons_group );
 869  
 870          // It's not the first comment, the order is set, we simply need to update the Buttons Group
 871          } else {
 872              $sort = false;
 873              bp_nouveau()->activity->comment_buttons->update( $buttons_group );
 874          }
 875  
 876          $return = bp_nouveau()->activity->comment_buttons->get( $sort );
 877  
 878          if ( ! $return ) {
 879              return array();
 880          }
 881  
 882          /**
 883           * If post comment / Activity comment sync is on, it's safer
 884           * to unset the comment button just before returning it.
 885           */
 886          if ( ! bp_activity_can_comment_reply( bp_activity_current_comment() ) ) {
 887              unset( $return['activity_comment_reply'] );
 888          }
 889  
 890          /**
 891           * If there was an activity of the user before one af another
 892           * user as we're updating buttons, we need to unset the delete link
 893           */
 894          if ( ! bp_activity_user_can_delete() ) {
 895              unset( $return['activity_comment_delete'] );
 896          }
 897  
 898          if ( isset( $return['activity_comment_spam'] ) && ( ! bp_activity_current_comment() || ! in_array( bp_activity_current_comment()->type, BP_Akismet::get_activity_types(), true ) ) ) {
 899              unset( $return['activity_comment_spam'] );
 900          }
 901  
 902          /**
 903           * Leave a chance to adjust the $return
 904           *
 905           * @since 3.0.0
 906           *
 907           * @param array $return              The list of buttons ordered.
 908           * @param int   $activity_comment_id The current activity comment ID.
 909           * @param int   $activity_id         The current activity ID.
 910           */
 911          do_action_ref_array( 'bp_nouveau_return_activity_comment_buttons', array( &$return, $activity_comment_id, $activity_id ) );
 912  
 913          return $return;
 914      }


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