BP_Activity_List_Table

List table class for the Activity component admin page.

Defined (1)

The class is defined in the following location(s).

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