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


Generated: Mon Sep 27 01:00:56 2021 Cross-referenced by PHPXref 0.7.1