[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Activity component admin list table. 4 * 5 * Props to WordPress core for the Comments admin screen, and its contextual 6 * help text, on which this implementation is heavily based. 7 * 8 * @package BuddyPress 9 * @subpackage ActivityAdmin 10 * @since 1.6.0 11 */ 12 13 // Exit if accessed directly. 14 defined( 'ABSPATH' ) || exit; 15 16 /** 17 * List table class for the Activity component admin page. 18 * 19 * @since 1.6.0 20 */ 21 class BP_Activity_List_Table extends WP_List_Table { 22 23 /** 24 * What type of view is being displayed? 25 * 26 * E.g. "all", "pending", "approved", "spam"... 27 * 28 * @since 1.6.0 29 * @var string $view 30 */ 31 public $view = 'all'; 32 33 /** 34 * How many activity items have been marked as spam. 35 * 36 * @since 1.6.0 37 * @var int $spam_count 38 */ 39 public $spam_count = 0; 40 41 /** 42 * Store activity-to-user-ID mappings for use in the In Response To column. 43 * 44 * @since 1.6.0 45 * @var array $activity_user_id 46 */ 47 protected $activity_user_id = array(); 48 49 /** 50 * If users can comment on post and comment activity items. 51 * 52 * @link https://buddypress.trac.wordpress.org/ticket/6277 53 * 54 * @since 2.2.2 55 * @var bool $disable_blogforum_comments 56 */ 57 public $disable_blogforum_comments = false; 58 59 /** 60 * Constructor. 61 * 62 * @since 1.6.0 63 */ 64 public function __construct() { 65 66 // See if activity commenting is enabled for post/comment activity items. 67 $this->disable_blogforum_comments = bp_disable_blogforum_comments(); 68 69 // Define singular and plural labels, as well as whether we support AJAX. 70 parent::__construct( array( 71 'ajax' => false, 72 'plural' => 'activities', 73 'singular' => 'activity', 74 'screen' => get_current_screen(), 75 ) ); 76 } 77 78 /** 79 * Handle filtering of data, sorting, pagination, and any other data manipulation prior to rendering. 80 * 81 * @since 1.6.0 82 */ 83 function prepare_items() { 84 85 // Option defaults. 86 $filter = array(); 87 $filter_query = false; 88 $include_id = false; 89 $search_terms = false; 90 $sort = 'DESC'; 91 $spam = 'ham_only'; 92 93 // Set current page. 94 $page = $this->get_pagenum(); 95 96 // Set per page from the screen options. 97 $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 98 99 // Check if we're on the "Spam" view. 100 if ( !empty( $_REQUEST['activity_status'] ) && 'spam' == $_REQUEST['activity_status'] ) { 101 $spam = 'spam_only'; 102 $this->view = 'spam'; 103 } 104 105 // Sort order. 106 if ( !empty( $_REQUEST['order'] ) && 'desc' != $_REQUEST['order'] ) 107 $sort = 'ASC'; 108 109 // Order by. 110 /*if ( !empty( $_REQUEST['orderby'] ) ) { 111 }*/ 112 113 // Filter. 114 if ( ! empty( $_REQUEST['activity_type'] ) ) { 115 $filter = array( 'action' => $_REQUEST['activity_type'] ); 116 117 /** 118 * Filter here to override the filter with a filter query 119 * 120 * @since 2.5.0 121 * 122 * @param array $filter 123 */ 124 $has_filter_query = apply_filters( 'bp_activity_list_table_filter_activity_type_items', $filter ); 125 126 if ( ! empty( $has_filter_query['filter_query'] ) ) { 127 // Reset the filter 128 $filter = array(); 129 130 // And use the filter query instead 131 $filter_query = $has_filter_query['filter_query']; 132 } 133 } 134 135 // Are we doing a search? 136 if ( !empty( $_REQUEST['s'] ) ) 137 $search_terms = $_REQUEST['s']; 138 139 // Check if user has clicked on a specific activity (if so, fetch only that, and any related, activity). 140 if ( !empty( $_REQUEST['aid'] ) ) 141 $include_id = (int) $_REQUEST['aid']; 142 143 // Get the spam total (ignoring any search query or filter). 144 $spams = bp_activity_get( array( 145 'display_comments' => 'stream', 146 'show_hidden' => true, 147 'spam' => 'spam_only', 148 'count_total' => 'count_query', 149 ) ); 150 $this->spam_count = $spams['total']; 151 unset( $spams ); 152 153 // Get the activities from the database. 154 $activities = bp_activity_get( array( 155 'display_comments' => 'stream', 156 'filter' => $filter, 157 'in' => $include_id, 158 'page' => $page, 159 'per_page' => $per_page, 160 'search_terms' => $search_terms, 161 'filter_query' => $filter_query, 162 'show_hidden' => true, 163 // 'sort' => $sort, 164 'spam' => $spam, 165 'count_total' => 'count_query', 166 ) ); 167 168 // If we're viewing a specific activity, flatten all activities into a single array. 169 if ( $include_id ) { 170 $activities['activities'] = BP_Activity_List_Table::flatten_activity_array( $activities['activities'] ); 171 $activities['total'] = count( $activities['activities'] ); 172 173 // Sort the array by the activity object's date_recorded value. 174 usort( $activities['activities'], function( $a, $b ) { return $a->date_recorded > $b->date_recorded; } ); 175 } 176 177 // The bp_activity_get function returns an array of objects; cast these to arrays for WP_List_Table. 178 $new_activities = array(); 179 foreach ( $activities['activities'] as $activity_item ) { 180 $new_activities[] = (array) $activity_item; 181 182 // Build an array of activity-to-user ID mappings for better efficiency in the In Response To column. 183 $this->activity_user_id[$activity_item->id] = $activity_item->user_id; 184 } 185 186 // Set raw data to display. 187 $this->items = $new_activities; 188 189 // Store information needed for handling table pagination. 190 $this->set_pagination_args( array( 191 'per_page' => $per_page, 192 'total_items' => $activities['total'], 193 'total_pages' => ceil( $activities['total'] / $per_page ) 194 ) ); 195 196 // Don't truncate activity items; bp_activity_truncate_entry() needs to be used inside a BP_Activity_Template loop. 197 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 198 } 199 200 /** 201 * Get an array of all the columns on the page. 202 * 203 * @since 1.6.0 204 * 205 * @return array Column headers. 206 */ 207 function get_column_info() { 208 $this->_column_headers = array( 209 $this->get_columns(), 210 array(), 211 $this->get_sortable_columns(), 212 $this->get_default_primary_column_name(), 213 ); 214 215 return $this->_column_headers; 216 } 217 218 /** 219 * Get name of default primary column 220 * 221 * @since 2.3.3 222 * 223 * @return string 224 */ 225 protected function get_default_primary_column_name() { 226 return 'author'; 227 } 228 229 /** 230 * Display a message on screen when no items are found (e.g. no search matches). 231 * 232 * @since 1.6.0 233 */ 234 function no_items() { 235 _e( 'No activities found.', 'buddypress' ); 236 } 237 238 /** 239 * Output the Activity data table. 240 * 241 * @since 1.6.0 242 */ 243 function display() { 244 $this->display_tablenav( 'top' ); ?> 245 246 <h2 class="screen-reader-text"><?php 247 /* translators: accessibility text */ 248 _e( 'Activities list', 'buddypress' ); 249 ?></h2> 250 251 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0"> 252 <thead> 253 <tr> 254 <?php $this->print_column_headers(); ?> 255 </tr> 256 </thead> 257 258 <tbody id="the-comment-list"> 259 <?php $this->display_rows_or_placeholder(); ?> 260 </tbody> 261 262 <tfoot> 263 <tr> 264 <?php $this->print_column_headers( false ); ?> 265 </tr> 266 </tfoot> 267 </table> 268 <?php 269 270 $this->display_tablenav( 'bottom' ); 271 } 272 273 /** 274 * Generate content for a single row of the table. 275 * 276 * @since 1.6.0 277 * 278 * @param object $item The current item. 279 */ 280 function single_row( $item ) { 281 static $even = false; 282 283 if ( $even ) { 284 $row_class = ' class="even"'; 285 } else { 286 $row_class = ' class="alternate odd"'; 287 } 288 289 if ( 'activity_comment' === $item['type'] ) { 290 $root_id = $item['item_id']; 291 } else { 292 $root_id = $item['id']; 293 } 294 295 echo '<tr' . $row_class . ' id="activity-' . esc_attr( $item['id'] ) . '" data-parent_id="' . esc_attr( $item['id'] ) . '" data-root_id="' . esc_attr( $root_id ) . '">'; 296 echo $this->single_row_columns( $item ); 297 echo '</tr>'; 298 299 $even = ! $even; 300 } 301 302 /** 303 * Get the list of views available on this table (e.g. "all", "spam"). 304 * 305 * @since 1.6.0 306 */ 307 function get_views() { 308 $url_base = add_query_arg( array( 'page' => 'bp-activity' ), bp_get_admin_url( 'admin.php' ) ); ?> 309 310 <h2 class="screen-reader-text"><?php 311 /* translators: accessibility text */ 312 _e( 'Filter activities list', 'buddypress' ); 313 ?></h2> 314 315 <ul class="subsubsub"> 316 <li class="all"><a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'spam' != $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddypress' ); ?></a> |</li> 317 <li class="spam"><a href="<?php echo esc_url( add_query_arg( array( 'activity_status' => 'spam' ), $url_base ) ); ?>" class="<?php if ( 'spam' == $this->view ) echo 'current'; ?>"><?php printf( __( 'Spam <span class="count">(%s)</span>', 'buddypress' ), number_format_i18n( $this->spam_count ) ); ?></a></li> 318 319 <?php 320 321 /** 322 * Fires inside listing of views so plugins can add their own. 323 * 324 * @since 1.6.0 325 * 326 * @param string $url_base Current URL base for view. 327 * @param string $view Current view being displayed. 328 */ 329 do_action( 'bp_activity_list_table_get_views', $url_base, $this->view ); ?> 330 </ul> 331 <?php 332 } 333 334 /** 335 * Get bulk actions. 336 * 337 * @since 1.6.0 338 * 339 * @return array Key/value pairs for the bulk actions dropdown. 340 */ 341 public function get_bulk_actions() { 342 343 /** 344 * Filters the default bulk actions so plugins can add custom actions. 345 * 346 * @since 1.6.0 347 * 348 * @param array $actions Default available actions for bulk operations. 349 */ 350 return apply_filters( 'bp_activity_list_table_get_bulk_actions', array( 351 'bulk_spam' => __( 'Mark as Spam', 'buddypress' ), 352 'bulk_ham' => __( 'Not Spam', 'buddypress' ), 353 'bulk_delete' => __( 'Delete Permanently', 'buddypress' ), 354 ) ); 355 } 356 357 /** 358 * Get the table column titles. 359 * 360 * @since 1.6.0 361 * 362 * @see WP_List_Table::single_row_columns() 363 * 364 * @return array The columns to appear in the Activity list table. 365 */ 366 function get_columns() { 367 368 /** 369 * Filters the titles for the columns for the activity list table. 370 * 371 * @since 2.4.0 372 * 373 * @param array $value Array of slugs and titles for the columns. 374 */ 375 return apply_filters( 'bp_activity_list_table_get_columns', array( 376 'cb' => '<input name type="checkbox" />', 377 'author' => _x( 'Author', 'Admin SWA column header', 'buddypress' ), 378 'comment' => _x( 'Activity', 'Admin SWA column header', 'buddypress' ), 379 'action' => _x( 'Action', 'Admin SWA column header', 'buddypress' ), 380 'response' => _x( 'In Response To', 'Admin SWA column header', 'buddypress' ), 381 ) ); 382 } 383 384 /** 385 * Get the column names for sortable columns. 386 * 387 * @since 1.6.0 388 * 389 * @return array The columns that can be sorted on the Activity screen. 390 */ 391 public function get_sortable_columns() { 392 393 /** 394 * Filters the column names for the sortable columns. 395 * 396 * @since 5.0.0 397 * 398 * @param array $value Array of column names. 399 */ 400 return apply_filters( 'bp_activity_list_table_get_sortable_columns', array() ); 401 } 402 403 /** 404 * Markup for the "filter" part of the form (i.e. which activity type to display). 405 * 406 * @since 1.6.0 407 * 408 * @param string $which 'top' or 'bottom'. 409 */ 410 function extra_tablenav( $which ) { 411 412 // Bail on bottom table nav. 413 if ( 'bottom' === $which ) { 414 return; 415 } 416 417 // Is any filter currently selected? 418 $selected = ( ! empty( $_REQUEST['activity_type'] ) ) ? $_REQUEST['activity_type'] : ''; 419 420 // Get the actions. 421 $activity_actions = bp_activity_get_actions(); ?> 422 423 <div class="alignleft actions"> 424 <label for="activity-type" class="screen-reader-text"><?php 425 /* translators: accessibility text */ 426 _e( 'Filter by activity type', 'buddypress' ); 427 ?></label> 428 <select name="activity_type" id="activity-type"> 429 <option value="" <?php selected( ! $selected ); ?>><?php _e( 'View all actions', 'buddypress' ); ?></option> 430 431 <?php foreach ( $activity_actions as $component => $actions ) : ?> 432 <?php 433 // Older avatar activity items use 'profile' for component. See r4273. 434 if ( $component === 'profile' ) { 435 $component = 'xprofile'; 436 } 437 438 // The 'activity_update' filter is already used by the Activity component. 439 if ( isset( $actions->activity_update ) && 'bp_groups_format_activity_action_group_activity_update' === $actions->activity_update['format_callback'] ) { 440 unset( $actions->activity_update ); 441 } 442 443 if ( bp_is_active( $component ) ) { 444 if ( $component === 'xprofile' ) { 445 $component_name = buddypress()->profile->name; 446 } else { 447 $component_name = buddypress()->$component->name; 448 } 449 450 } else { 451 // Prevent warnings by other plugins if a component is disabled but the activity type has been registered. 452 $component_name = ucfirst( $component ); 453 } 454 ?> 455 456 <optgroup label="<?php echo esc_html( $component_name ); ?>"> 457 458 <?php foreach ( $actions as $action_key => $action_values ) : ?> 459 460 <?php 461 462 // Skip the incorrectly named pre-1.6 action. 463 if ( 'friends_register_activity_action' !== $action_key ) : ?> 464 465 <option value="<?php echo esc_attr( $action_key ); ?>" <?php selected( $action_key, $selected ); ?>><?php echo esc_html( $action_values[ 'value' ] ); ?></option> 466 467 <?php endif; ?> 468 469 <?php endforeach; ?> 470 471 </optgroup> 472 473 <?php endforeach; ?> 474 475 </select> 476 477 <?php submit_button( __( 'Filter', 'buddypress' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) ); ?> 478 </div> 479 480 <?php 481 } 482 483 /** 484 * Override WP_List_Table::row_actions(). 485 * 486 * Basically a duplicate of the row_actions() method, but removes the 487 * unnecessary <button> addition. 488 * 489 * @since 2.3.3 490 * @since 2.3.4 Visibility set to public for compatibility with WP < 4.0.0. 491 * 492 * @param array $actions The list of actions. 493 * @param bool $always_visible Whether the actions should be always visible. 494 * @return string 495 */ 496 public function row_actions( $actions, $always_visible = false ) { 497 $action_count = count( $actions ); 498 $i = 0; 499 500 if ( !$action_count ) 501 return ''; 502 503 $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; 504 foreach ( $actions as $action => $link ) { 505 ++$i; 506 ( $i == $action_count ) ? $sep = '' : $sep = ' | '; 507 $out .= "<span class='$action'>$link$sep</span>"; 508 } 509 $out .= '</div>'; 510 511 return $out; 512 } 513 514 /** 515 * Checkbox column markup. 516 * 517 * @since 1.6.0 518 * 519 * @see WP_List_Table::single_row_columns() 520 * 521 * @param array $item A singular item (one full row). 522 */ 523 function column_cb( $item ) { 524 /* translators: accessibility text */ 525 printf( '<label class="screen-reader-text" for="aid-%1$d">' . __( 'Select activity item %1$d', 'buddypress' ) . '</label><input type="checkbox" name="aid[]" value="%1$d" id="aid-%1$d" />', $item['id'] ); 526 } 527 528 /** 529 * Author column markup. 530 * 531 * @since 1.6.0 532 * 533 * @see WP_List_Table::single_row_columns() 534 * 535 * @param array $item A singular item (one full row). 536 */ 537 function column_author( $item ) { 538 echo '<strong>' . get_avatar( $item['user_id'], '32' ) . ' ' . bp_core_get_userlink( $item['user_id'] ) . '</strong>'; 539 } 540 541 /** 542 * Action column markup. 543 * 544 * @since 2.0.0 545 * 546 * @see WP_List_Table::single_row_columns() 547 * 548 * @param array $item A singular item (one full row). 549 */ 550 function column_action( $item ) { 551 $actions = bp_activity_admin_get_activity_actions(); 552 553 if ( isset( $actions[ $item['type'] ] ) ) { 554 echo $actions[ $item['type'] ]; 555 } else { 556 printf( __( 'Unregistered action - %s', 'buddypress' ), $item['type'] ); 557 } 558 } 559 560 /** 561 * Content column, and "quick admin" rollover actions. 562 * 563 * Called "comment" in the CSS so we can re-use some WP core CSS. 564 * 565 * @since 1.6.0 566 * 567 * @see WP_List_Table::single_row_columns() 568 * 569 * @param array $item A singular item (one full row). 570 */ 571 function column_comment( $item ) { 572 // Determine what type of item (row) we're dealing with. 573 if ( $item['is_spam'] ) 574 $item_status = 'spam'; 575 else 576 $item_status = 'all'; 577 578 // Preorder items: Reply | Edit | Spam | Delete Permanently. 579 $actions = array( 580 'reply' => '', 581 'edit' => '', 582 'spam' => '', 'unspam' => '', 583 'delete' => '', 584 ); 585 586 // Build actions URLs. 587 $base_url = bp_get_admin_url( 'admin.php?page=bp-activity&aid=' . $item['id'] ); 588 $spam_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'spam-activity_' . $item['id'] ) ); 589 590 $delete_url = $base_url . "&action=delete&$spam_nonce"; 591 $edit_url = $base_url . '&action=edit'; 592 $ham_url = $base_url . "&action=ham&$spam_nonce"; 593 $spam_url = $base_url . "&action=spam&$spam_nonce"; 594 595 // Rollover actions. 596 // Reply - JavaScript only; implemented by AJAX. 597 if ( 'spam' != $item_status ) { 598 if ( $this->can_comment( $item ) ) { 599 $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) ); 600 } else { 601 $actions['reply'] = sprintf( '<span class="form-input-tip">%s</span>', __( 'Replies disabled', 'buddypress' ) ); 602 } 603 604 // Edit. 605 $actions['edit'] = sprintf( '<a href="%s">%s</a>', $edit_url, __( 'Edit', 'buddypress' ) ); 606 } 607 608 // Spam/unspam. 609 if ( 'spam' == $item_status ) 610 $actions['unspam'] = sprintf( '<a href="%s">%s</a>', $ham_url, __( 'Not Spam', 'buddypress' ) ); 611 else 612 $actions['spam'] = sprintf( '<a href="%s">%s</a>', $spam_url, __( 'Spam', 'buddypress' ) ); 613 614 // Delete. 615 $actions['delete'] = sprintf( '<a href="%s" onclick="%s">%s</a>', $delete_url, "javascript:return confirm('" . esc_js( __( 'Are you sure?', 'buddypress' ) ) . "'); ", __( 'Delete Permanently', 'buddypress' ) ); 616 617 // Start timestamp. 618 echo '<div class="submitted-on">'; 619 620 /** 621 * Filters available actions for plugins to alter. 622 * 623 * @since 1.6.0 624 * 625 * @param array $actions Array of available actions user could use. 626 * @param array $item Current item being added to page. 627 */ 628 $actions = apply_filters( 'bp_activity_admin_comment_row_actions', array_filter( $actions ), $item ); 629 630 printf( 631 /* translators: %s: activity date and time */ 632 __( 'Submitted on %s', 'buddypress' ), 633 sprintf( 634 '<a href="%1$s">%2$s</a>', 635 bp_activity_get_permalink( $item['id'] ), 636 sprintf( 637 /* translators: 1: activity date, 2: activity time */ 638 __( '%1$s at %2$s', 'buddypress' ), 639 date_i18n( bp_get_option( 'date_format' ), strtotime( $item['date_recorded'] ) ), 640 get_date_from_gmt( $item['date_recorded'], bp_get_option( 'time_format' ) ) 641 ) 642 ) 643 ); 644 645 // End timestamp. 646 echo '</div>'; 647 648 // Get activity content - if not set, use the action. 649 if ( ! empty( $item['content'] ) ) { 650 $activity = new BP_Activity_Activity( $item['id'] ); 651 652 /** This filter is documented in bp-activity/bp-activity-template.php */ 653 $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $item['content'], &$activity ) ); 654 } else { 655 /** 656 * Filters current activity item action. 657 * 658 * @since 1.2.0 659 * 660 * @var array $item Array index holding current activity item action. 661 */ 662 $content = apply_filters_ref_array( 'bp_get_activity_action', array( $item['action'] ) ); 663 } 664 665 /** 666 * Filter here to add extra output to the activity content into the Administration. 667 * 668 * @since 2.4.0 669 * 670 * @param string $content The activity content. 671 * @param array $item The activity object converted into an array. 672 */ 673 echo apply_filters( 'bp_activity_admin_comment_content', $content, $item ) . ' ' . $this->row_actions( $actions ); 674 } 675 676 /** 677 * "In response to" column markup. 678 * 679 * @since 1.6.0 680 * 681 * @see WP_List_Table::single_row_columns() 682 * 683 * @param array $item A singular item (one full row). 684 */ 685 function column_response( $item ) { 686 687 // Is $item is a root activity? 688 ?> 689 690 <div class="response-links"> 691 692 <?php 693 // Activity permalink. 694 $activity_permalink = ''; 695 if ( ! $item['is_spam'] ) { 696 $activity_permalink = '<a href="' . bp_activity_get_permalink( $item['id'], (object) $item ) . '" class="comments-view-item-link">' . __( 'View Activity', 'buddypress' ) . '</a>'; 697 } 698 699 /** 700 * Filters default list of default root activity types. 701 * 702 * @since 1.6.0 703 * 704 * @param array $value Array of default activity types. 705 * @param array $item Current item being displayed. 706 */ 707 if ( empty( $item['item_id'] ) || ! in_array( $item['type'], apply_filters( 'bp_activity_admin_root_activity_types', array( 'activity_comment' ), $item ) ) ) { 708 echo $activity_permalink; 709 710 $comment_count = !empty( $item['children'] ) ? bp_activity_recurse_comment_count( (object) $item ) : 0; 711 $root_activity_url = bp_get_admin_url( 'admin.php?page=bp-activity&aid=' . $item['id'] ); 712 713 // If the activity has comments, display a link to the activity's permalink, with its comment count in a speech bubble. 714 if ( $comment_count ) { 715 printf( '<a href="%1$s" class="post-com-count post-com-count-approved"><span class="comment-count comment-count-approved">%2$s</span></a>', esc_url( $root_activity_url ), number_format_i18n( $comment_count ) ); 716 } 717 718 // For non-root activities, display a link to the replied-to activity's author's profile. 719 } else { 720 echo '<strong>' . get_avatar( $this->get_activity_user_id( $item['item_id'] ), '32' ) . ' ' . bp_core_get_userlink( $this->get_activity_user_id( $item['item_id'] ) ) . '</strong><br />'; 721 echo $activity_permalink; 722 } 723 ?> 724 725 </div> 726 727 <?php 728 } 729 730 /** 731 * Allow plugins to add their custom column. 732 * 733 * @since 2.4.0 734 * 735 * @param array $item Information about the current row. 736 * @param string $column_name The column name. 737 * @return string 738 */ 739 public function column_default( $item = array(), $column_name = '' ) { 740 741 /** 742 * Filters a string to allow plugins to add custom column content. 743 * 744 * @since 2.4.0 745 * 746 * @param string $value Empty string. 747 * @param string $column_name Name of the column being rendered. 748 * @param array $item The current activity item in the loop. 749 */ 750 return apply_filters( 'bp_activity_admin_get_custom_column', '', $column_name, $item ); 751 } 752 753 /** 754 * Get the user id associated with a given activity item. 755 * 756 * Wraps bp_activity_get_specific(), with some additional logic for 757 * avoiding duplicate queries. 758 * 759 * @since 1.6.0 760 * 761 * @param int $activity_id Activity ID to retrieve User ID for. 762 * @return int User ID of the activity item in question. 763 */ 764 protected function get_activity_user_id( $activity_id ) { 765 // If there is an existing activity/user ID mapping, just return the user ID. 766 if ( ! empty( $this->activity_user_id[$activity_id] ) ) { 767 return $this->activity_user_id[$activity_id]; 768 769 /* 770 * We don't have a mapping. This means the $activity_id is not on the current 771 * page of results, so fetch its details from the database. 772 */ 773 } else { 774 $activity = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all', ) ); 775 776 /* 777 * If, somehow, the referenced activity has been deleted, leaving its associated 778 * activities as orphans, use the logged in user's ID to avoid errors. 779 */ 780 if ( empty( $activity['activities'] ) ) 781 return bp_loggedin_user_id(); 782 783 // Store the new activity/user ID mapping for any later re-use. 784 $this->activity_user_id[ $activity['activities'][0]->id ] = $activity['activities'][0]->user_id; 785 786 // Return the user ID. 787 return $activity['activities'][0]->user_id; 788 } 789 } 790 791 /** 792 * Checks if an activity item can be replied to. 793 * 794 * This method merges functionality from {@link bp_activity_can_comment()} and 795 * {@link bp_blogs_disable_activity_commenting()}. This is done because the activity 796 * list table doesn't use a BuddyPress activity loop, which prevents those 797 * functions from working as intended. 798 * 799 * @since 2.0.0 800 * @since 2.5.0 Include Post type activities types 801 * 802 * @param array $item An array version of the BP_Activity_Activity object. 803 * @return bool $can_comment 804 */ 805 protected function can_comment( $item ) { 806 $can_comment = bp_activity_type_supports( $item['type'], 'comment-reply' ); 807 808 if ( ! $this->disable_blogforum_comments && bp_is_active( 'blogs' ) ) { 809 $parent_activity = false; 810 811 if ( bp_activity_type_supports( $item['type'], 'post-type-comment-tracking' ) ) { 812 $parent_activity = (object) $item; 813 } elseif ( 'activity_comment' === $item['type'] ) { 814 $parent_activity = new BP_Activity_Activity( $item['item_id'] ); 815 $can_comment = bp_activity_can_comment_reply( (object) $item ); 816 } 817 818 if ( isset( $parent_activity->type ) && bp_activity_post_type_get_tracking_arg( $parent_activity->type, 'post_type' ) ) { 819 // Fetch blog post comment depth and if the blog post's comments are open. 820 bp_blogs_setup_activity_loop_globals( $parent_activity ); 821 822 $can_comment = bp_blogs_can_comment_reply( true, $item ); 823 } 824 } 825 826 /** 827 * Filters if an activity item can be commented on or not. 828 * 829 * @since 2.0.0 830 * @since 2.5.0 Add a second parameter to include the activity item into the filter. 831 * 832 * @param bool $can_comment Whether an activity item can be commented on or not. 833 * @param array $item An array version of the BP_Activity_Activity object. 834 */ 835 return apply_filters( 'bp_activity_list_table_can_comment', $can_comment, $item ); 836 } 837 838 /** 839 * Flatten the activity array. 840 * 841 * In some cases, BuddyPress gives us a structured tree of activity 842 * items plus their comments. This method converts it to a flat array. 843 * 844 * @since 1.6.0 845 * 846 * @param array $tree Source array. 847 * @return array Flattened array. 848 */ 849 public static function flatten_activity_array( $tree ){ 850 foreach ( (array) $tree as $node ) { 851 if ( isset( $node->children ) ) { 852 853 foreach ( BP_Activity_List_Table::flatten_activity_array( $node->children ) as $child ) { 854 $tree[] = $child; 855 } 856 857 unset( $node->children ); 858 } 859 } 860 861 return $tree; 862 } 863 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Dec 10 01:01:39 2019 | Cross-referenced by PHPXref 0.7.1 |