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


Generated: Sat Dec 14 01:00:55 2024 Cross-referenced by PHPXref 0.7.1