Changeset 10516 for trunk/src/bp-activity/bp-activity-admin.php
- Timestamp:
- 02/05/2016 03:54:56 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-admin.php
r10487 r10516 16 16 // Include WP's list table class. 17 17 if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); 18 19 require dirname( __FILE__ ) . '/classes/class-bp-activity-list-table.php'; 18 20 19 21 // Per_page screen option. Has to be hooked in extremely early. … … 1039 1041 <?php 1040 1042 } 1041 1042 /**1043 * List table class for the Activity component admin page.1044 *1045 * @since 1.6.01046 */1047 class BP_Activity_List_Table extends WP_List_Table {1048 1049 /**1050 * What type of view is being displayed?1051 *1052 * E.g. "all", "pending", "approved", "spam"...1053 *1054 * @since 1.6.01055 * @var string $view1056 */1057 public $view = 'all';1058 1059 /**1060 * How many activity items have been marked as spam.1061 *1062 * @since 1.6.01063 * @var int $spam_count1064 */1065 public $spam_count = 0;1066 1067 /**1068 * Store activity-to-user-ID mappings for use in the In Response To column.1069 *1070 * @since 1.6.01071 * @var array $activity_user_id1072 */1073 protected $activity_user_id = array();1074 1075 /**1076 * If users can comment on blog & forum activity items.1077 *1078 * @link https://buddypress.trac.wordpress.org/ticket/62771079 *1080 * @since 2.2.21081 * @var bool $disable_blogforum_comments1082 */1083 public $disable_blogforum_comments = false;1084 1085 /**1086 * Constructor.1087 *1088 * @since 1.6.01089 */1090 public function __construct() {1091 1092 // See if activity commenting is enabled for blog / forum activity items.1093 $this->disable_blogforum_comments = bp_disable_blogforum_comments();1094 1095 // Define singular and plural labels, as well as whether we support AJAX.1096 parent::__construct( array(1097 'ajax' => false,1098 'plural' => 'activities',1099 'singular' => 'activity',1100 'screen' => get_current_screen(),1101 ) );1102 }1103 1104 /**1105 * Handle filtering of data, sorting, pagination, and any other data manipulation prior to rendering.1106 *1107 * @since 1.6.01108 */1109 function prepare_items() {1110 1111 // Option defaults.1112 $filter = array();1113 $include_id = false;1114 $search_terms = false;1115 $sort = 'DESC';1116 $spam = 'ham_only';1117 1118 // Set current page.1119 $page = $this->get_pagenum();1120 1121 // Set per page from the screen options.1122 $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) );1123 1124 // Check if we're on the "Spam" view.1125 if ( !empty( $_REQUEST['activity_status'] ) && 'spam' == $_REQUEST['activity_status'] ) {1126 $spam = 'spam_only';1127 $this->view = 'spam';1128 }1129 1130 // Sort order.1131 if ( !empty( $_REQUEST['order'] ) && 'desc' != $_REQUEST['order'] )1132 $sort = 'ASC';1133 1134 // Order by.1135 /*if ( !empty( $_REQUEST['orderby'] ) ) {1136 }*/1137 1138 // Filter.1139 if ( !empty( $_REQUEST['activity_type'] ) )1140 $filter = array( 'action' => $_REQUEST['activity_type'] );1141 1142 // Are we doing a search?1143 if ( !empty( $_REQUEST['s'] ) )1144 $search_terms = $_REQUEST['s'];1145 1146 // Check if user has clicked on a specific activity (if so, fetch only that, and any related, activity).1147 if ( !empty( $_REQUEST['aid'] ) )1148 $include_id = (int) $_REQUEST['aid'];1149 1150 // Get the spam total (ignoring any search query or filter).1151 $spams = bp_activity_get( array(1152 'display_comments' => 'stream',1153 'show_hidden' => true,1154 'spam' => 'spam_only',1155 'count_total' => 'count_query',1156 ) );1157 $this->spam_count = $spams['total'];1158 unset( $spams );1159 1160 // Get the activities from the database.1161 $activities = bp_activity_get( array(1162 'display_comments' => 'stream',1163 'filter' => $filter,1164 'in' => $include_id,1165 'page' => $page,1166 'per_page' => $per_page,1167 'search_terms' => $search_terms,1168 'show_hidden' => true,1169 // 'sort' => $sort,1170 'spam' => $spam,1171 'count_total' => 'count_query',1172 ) );1173 1174 // If we're viewing a specific activity, flatten all activities into a single array.1175 if ( $include_id ) {1176 $activities['activities'] = BP_Activity_List_Table::flatten_activity_array( $activities['activities'] );1177 $activities['total'] = count( $activities['activities'] );1178 1179 // Sort the array by the activity object's date_recorded value.1180 usort( $activities['activities'], create_function( '$a, $b', 'return $a->date_recorded > $b->date_recorded;' ) );1181 }1182 1183 // The bp_activity_get function returns an array of objects; cast these to arrays for WP_List_Table.1184 $new_activities = array();1185 foreach ( $activities['activities'] as $activity_item ) {1186 $new_activities[] = (array) $activity_item;1187 1188 // Build an array of activity-to-user ID mappings for better efficiency in the In Response To column.1189 $this->activity_user_id[$activity_item->id] = $activity_item->user_id;1190 }1191 1192 // Set raw data to display.1193 $this->items = $new_activities;1194 1195 // Store information needed for handling table pagination.1196 $this->set_pagination_args( array(1197 'per_page' => $per_page,1198 'total_items' => $activities['total'],1199 'total_pages' => ceil( $activities['total'] / $per_page )1200 ) );1201 1202 // Don't truncate activity items; bp_activity_truncate_entry() needs to be used inside a BP_Activity_Template loop.1203 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );1204 }1205 1206 /**1207 * Get an array of all the columns on the page.1208 *1209 * @since 1.6.01210 *1211 * @return array Column headers.1212 */1213 function get_column_info() {1214 $this->_column_headers = array(1215 $this->get_columns(),1216 array(),1217 $this->get_sortable_columns(),1218 $this->get_default_primary_column_name(),1219 );1220 1221 return $this->_column_headers;1222 }1223 1224 /**1225 * Get name of default primary column1226 *1227 * @since 2.3.31228 *1229 * @return string1230 */1231 protected function get_default_primary_column_name() {1232 return 'author';1233 }1234 1235 /**1236 * Display a message on screen when no items are found (e.g. no search matches).1237 *1238 * @since 1.6.01239 */1240 function no_items() {1241 _e( 'No activities found.', 'buddypress' );1242 }1243 1244 /**1245 * Output the Activity data table.1246 *1247 * @since 1.6.01248 */1249 function display() {1250 $this->display_tablenav( 'top' ); ?>1251 1252 <h2 class="screen-reader-text"><?php _e( 'Activities list', 'buddypress' ); ?></h2>1253 1254 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">1255 <thead>1256 <tr>1257 <?php $this->print_column_headers(); ?>1258 </tr>1259 </thead>1260 1261 <tfoot>1262 <tr>1263 <?php $this->print_column_headers( false ); ?>1264 </tr>1265 </tfoot>1266 1267 <tbody id="the-comment-list">1268 <?php $this->display_rows_or_placeholder(); ?>1269 </tbody>1270 </table>1271 <?php1272 1273 $this->display_tablenav( 'bottom' );1274 }1275 1276 /**1277 * Generate content for a single row of the table.1278 *1279 * @since 1.6.01280 *1281 * @param object $item The current item.1282 */1283 function single_row( $item ) {1284 static $even = false;1285 1286 if ( $even ) {1287 $row_class = ' class="even"';1288 } else {1289 $row_class = ' class="alternate odd"';1290 }1291 1292 if ( 'activity_comment' === $item['type'] ) {1293 $root_id = $item['item_id'];1294 } else {1295 $root_id = $item['id'];1296 }1297 1298 echo '<tr' . $row_class . ' id="activity-' . esc_attr( $item['id'] ) . '" data-parent_id="' . esc_attr( $item['id'] ) . '" data-root_id="' . esc_attr( $root_id ) . '">';1299 echo $this->single_row_columns( $item );1300 echo '</tr>';1301 1302 $even = ! $even;1303 }1304 1305 /**1306 * Get the list of views available on this table (e.g. "all", "spam").1307 *1308 * @since 1.6.01309 */1310 function get_views() {1311 $url_base = add_query_arg( array( 'page' => 'bp-activity' ), bp_get_admin_url( 'admin.php' ) ); ?>1312 1313 <h2 class="screen-reader-text"><?php _e( 'Filter activities list', 'buddypress' ); ?></h2>1314 1315 <ul class="subsubsub">1316 <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>1317 <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>1318 1319 <?php1320 1321 /**1322 * Fires inside listing of views so plugins can add their own.1323 *1324 * @since 1.6.01325 *1326 * @param string $url_base Current URL base for view.1327 * @param string $view Current view being displayed.1328 */1329 do_action( 'bp_activity_list_table_get_views', $url_base, $this->view ); ?>1330 </ul>1331 <?php1332 }1333 1334 /**1335 * Get bulk actions.1336 *1337 * @since 1.6.01338 *1339 * @return array Key/value pairs for the bulk actions dropdown.1340 */1341 function get_bulk_actions() {1342 $actions = array();1343 $actions['bulk_spam'] = __( 'Mark as Spam', 'buddypress' );1344 $actions['bulk_ham'] = __( 'Not Spam', 'buddypress' );1345 $actions['bulk_delete'] = __( 'Delete Permanently', 'buddypress' );1346 1347 /**1348 * Filters the default bulk actions so plugins can add custom actions.1349 *1350 * @since 1.6.01351 *1352 * @param array $actions Default available actions for bulk operations.1353 */1354 return apply_filters( 'bp_activity_list_table_get_bulk_actions', $actions );1355 }1356 1357 /**1358 * Get the table column titles.1359 *1360 * @since 1.6.01361 *1362 * @see WP_List_Table::single_row_columns()1363 *1364 * @return array The columns to appear in the Activity list table.1365 */1366 function get_columns() {1367 /**1368 * Filters the titles for the columns for the activity list table.1369 *1370 * @since 2.4.01371 *1372 * @param array $value Array of slugs and titles for the columns.1373 */1374 return apply_filters( 'bp_activity_list_table_get_columns', array(1375 'cb' => '<input name type="checkbox" />',1376 'author' => _x('Author', 'Admin SWA column header', 'buddypress' ),1377 'comment' => _x( 'Activity', 'Admin SWA column header', 'buddypress' ),1378 'action' => _x( 'Action', 'Admin SWA column header', 'buddypress' ),1379 'response' => _x( 'In Response To', 'Admin SWA column header', 'buddypress' ),1380 ) );1381 }1382 1383 /**1384 * Get the column names for sortable columns.1385 *1386 * Currently, returns an empty array (no columns are sortable).1387 *1388 * @since 1.6.01389 * @todo For this to work, BP_Activity_Activity::get() needs updating1390 * to support ordering by specific fields.1391 *1392 * @return array The columns that can be sorted on the Activity screen.1393 */1394 function get_sortable_columns() {1395 return array();1396 1397 /*return array(1398 'author' => array( 'activity_author', false ), // Intentionally not using "=>"1399 );*/1400 }1401 1402 /**1403 * Markup for the "filter" part of the form (i.e. which activity type to display).1404 *1405 * @since 1.6.01406 *1407 * @param string $which 'top' or 'bottom'.1408 */1409 function extra_tablenav( $which ) {1410 1411 // Bail on bottom table nav.1412 if ( 'bottom' === $which ) {1413 return;1414 }1415 1416 // Is any filter currently selected?1417 $selected = ( ! empty( $_REQUEST['activity_type'] ) ) ? $_REQUEST['activity_type'] : '';1418 1419 // Get the actions.1420 $activity_actions = bp_activity_get_actions(); ?>1421 1422 <div class="alignleft actions">1423 <label for="activity-type" class="screen-reader-text"><?php _e( 'Filter by activity type', 'buddypress' ); ?></label>1424 <select name="activity_type" id="activity-type">1425 <option value="" <?php selected( ! $selected ); ?>><?php _e( 'View all actions', 'buddypress' ); ?></option>1426 1427 <?php foreach ( $activity_actions as $component => $actions ) : ?>1428 1429 <optgroup label="<?php echo ucfirst( $component ); ?>">1430 1431 <?php foreach ( $actions as $action_key => $action_values ) : ?>1432 1433 <?php1434 1435 // Skip the incorrectly named pre-1.6 action.1436 if ( 'friends_register_activity_action' !== $action_key ) : ?>1437 1438 <option value="<?php echo esc_attr( $action_key ); ?>" <?php selected( $action_key, $selected ); ?>><?php echo esc_html( $action_values[ 'value' ] ); ?></option>1439 1440 <?php endif; ?>1441 1442 <?php endforeach; ?>1443 1444 </optgroup>1445 1446 <?php endforeach; ?>1447 1448 </select>1449 1450 <?php submit_button( __( 'Filter', 'buddypress' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) ); ?>1451 </div>1452 1453 <?php1454 }1455 1456 /**1457 * Override WP_List_Table::row_actions().1458 *1459 * Basically a duplicate of the row_actions() method, but removes the1460 * unnecessary <button> addition.1461 *1462 * @since 2.3.31463 * @since 2.3.4 Visibility set to public for compatibility with WP < 4.0.0.1464 *1465 * @param array $actions The list of actions.1466 * @param bool $always_visible Whether the actions should be always visible.1467 * @return string1468 */1469 public function row_actions( $actions, $always_visible = false ) {1470 $action_count = count( $actions );1471 $i = 0;1472 1473 if ( !$action_count )1474 return '';1475 1476 $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';1477 foreach ( $actions as $action => $link ) {1478 ++$i;1479 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';1480 $out .= "<span class='$action'>$link$sep</span>";1481 }1482 $out .= '</div>';1483 1484 return $out;1485 }1486 1487 /**1488 * Checkbox column markup.1489 *1490 * @since 1.6.01491 *1492 * @see WP_List_Table::single_row_columns()1493 *1494 * @param array $item A singular item (one full row).1495 */1496 function column_cb( $item ) {1497 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'] );1498 }1499 1500 /**1501 * Author column markup.1502 *1503 * @since 1.6.01504 *1505 * @see WP_List_Table::single_row_columns()1506 *1507 * @param array $item A singular item (one full row).1508 */1509 function column_author( $item ) {1510 echo '<strong>' . get_avatar( $item['user_id'], '32' ) . ' ' . bp_core_get_userlink( $item['user_id'] ) . '</strong>';1511 }1512 1513 /**1514 * Action column markup.1515 *1516 * @since 2.0.01517 *1518 * @see WP_List_Table::single_row_columns()1519 *1520 * @param array $item A singular item (one full row).1521 */1522 function column_action( $item ) {1523 $actions = bp_activity_admin_get_activity_actions();1524 1525 if ( isset( $actions[ $item['type'] ] ) ) {1526 echo $actions[ $item['type'] ];1527 } else {1528 printf( __( 'Unregistered action - %s', 'buddypress' ), $item['type'] );1529 }1530 }1531 1532 /**1533 * Content column, and "quick admin" rollover actions.1534 *1535 * Called "comment" in the CSS so we can re-use some WP core CSS.1536 *1537 * @since 1.6.01538 *1539 * @see WP_List_Table::single_row_columns()1540 *1541 * @param array $item A singular item (one full row).1542 */1543 function column_comment( $item ) {1544 // Determine what type of item (row) we're dealing with.1545 if ( $item['is_spam'] )1546 $item_status = 'spam';1547 else1548 $item_status = 'all';1549 1550 // Preorder items: Reply | Edit | Spam | Delete Permanently.1551 $actions = array(1552 'reply' => '',1553 'edit' => '',1554 'spam' => '', 'unspam' => '',1555 'delete' => '',1556 );1557 1558 // Build actions URLs.1559 $base_url = bp_get_admin_url( 'admin.php?page=bp-activity&aid=' . $item['id'] );1560 $spam_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'spam-activity_' . $item['id'] ) );1561 1562 $delete_url = $base_url . "&action=delete&$spam_nonce";1563 $edit_url = $base_url . '&action=edit';1564 $ham_url = $base_url . "&action=ham&$spam_nonce";1565 $spam_url = $base_url . "&action=spam&$spam_nonce";1566 1567 // Rollover actions.1568 // Reply - JavaScript only; implemented by AJAX.1569 if ( 'spam' != $item_status ) {1570 if ( $this->can_comment( $item ) ) {1571 $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) );1572 } else {1573 $actions['reply'] = sprintf( '<span class="form-input-tip" title="%s">%s</span>', __( 'Replies are disabled for this activity item', 'buddypress' ), __( 'Replies disabled', 'buddypress' ) );1574 }1575 1576 // Edit.1577 $actions['edit'] = sprintf( '<a href="%s">%s</a>', $edit_url, __( 'Edit', 'buddypress' ) );1578 }1579 1580 // Spam/unspam.1581 if ( 'spam' == $item_status )1582 $actions['unspam'] = sprintf( '<a href="%s">%s</a>', $ham_url, __( 'Not Spam', 'buddypress' ) );1583 else1584 $actions['spam'] = sprintf( '<a href="%s">%s</a>', $spam_url, __( 'Spam', 'buddypress' ) );1585 1586 // Delete.1587 $actions['delete'] = sprintf( '<a href="%s" onclick="%s">%s</a>', $delete_url, "javascript:return confirm('" . esc_js( __( 'Are you sure?', 'buddypress' ) ) . "'); ", __( 'Delete Permanently', 'buddypress' ) );1588 1589 // Start timestamp.1590 echo '<div class="submitted-on">';1591 1592 /**1593 * Filters available actions for plugins to alter.1594 *1595 * @since 1.6.01596 *1597 * @param array $actions Array of available actions user could use.1598 * @param array $item Current item being added to page.1599 */1600 $actions = apply_filters( 'bp_activity_admin_comment_row_actions', array_filter( $actions ), $item );1601 1602 /* translators: 2: activity admin ui date/time */1603 printf(1604 __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>', 'buddypress' ),1605 bp_activity_get_permalink( $item['id'] ),1606 date_i18n( bp_get_option( 'date_format' ), strtotime( $item['date_recorded'] ) ),1607 get_date_from_gmt( $item['date_recorded'], bp_get_option( 'time_format' ) )1608 );1609 1610 // End timestamp.1611 echo '</div>';1612 1613 // Get activity content - if not set, use the action.1614 if ( ! empty( $item['content'] ) ) {1615 1616 /**1617 * Filters current activity item content.1618 *1619 * @since 1.2.01620 *1621 * @param array $item Array index holding current activity item content.1622 */1623 $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $item['content'] ) );1624 } else {1625 /**1626 * Filters current activity item action.1627 *1628 * @since 1.2.01629 *1630 * @var array $item Array index holding current activity item action.1631 */1632 $content = apply_filters_ref_array( 'bp_get_activity_action', array( $item['action'] ) );1633 }1634 1635 /**1636 * Filter here to add extra output to the activity content into the Administration.1637 *1638 * @since 2.4.01639 *1640 * @param string $content The activity content.1641 * @param array $item The activity object converted into an array.1642 */1643 echo apply_filters( 'bp_activity_admin_comment_content', $content, $item ) . ' ' . $this->row_actions( $actions );1644 }1645 1646 /**1647 * "In response to" column markup.1648 *1649 * @since 1.6.01650 *1651 * @see WP_List_Table::single_row_columns()1652 *1653 * @param array $item A singular item (one full row).1654 */1655 function column_response( $item ) {1656 1657 // Is $item is a root activity?1658 ?>1659 1660 <div class="response-links">1661 1662 <?php1663 // Activity permalink.1664 $activity_permalink = '';1665 if ( ! $item['is_spam'] ) {1666 $activity_permalink = '<a href="' . bp_activity_get_permalink( $item['id'], (object) $item ) . '" class="comments-view-item-link">' . __( 'View Activity', 'buddypress' ) . '</a>';1667 }1668 1669 /**1670 * Filters default list of default root activity types.1671 *1672 * @since 1.6.01673 *1674 * @param array $value Array of default activity types.1675 * @param array $item Current item being displayed.1676 */1677 if ( empty( $item['item_id'] ) || ! in_array( $item['type'], apply_filters( 'bp_activity_admin_root_activity_types', array( 'activity_comment' ), $item ) ) ) {1678 echo $activity_permalink;1679 1680 $comment_count = !empty( $item['children'] ) ? bp_activity_recurse_comment_count( (object) $item ) : 0;1681 $root_activity_url = bp_get_admin_url( 'admin.php?page=bp-activity&aid=' . $item['id'] );1682 1683 // If the activity has comments, display a link to the activity's permalink, with its comment count in a speech bubble.1684 if ( $comment_count ) {1685 $title_attr = sprintf( _n( '%s related activity', '%s related activities', $comment_count, 'buddypress' ), number_format_i18n( $comment_count ) );1686 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 ) );1687 }1688 1689 // For non-root activities, display a link to the replied-to activity's author's profile.1690 } else {1691 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 />';1692 echo $activity_permalink;1693 }1694 ?>1695 1696 </div>1697 1698 <?php1699 }1700 1701 /**1702 * Allow plugins to add their custom column.1703 *1704 * @since 2.4.01705 *1706 * @param array $item Information about the current row.1707 * @param string $column_name The column name.1708 * @return string1709 */1710 public function column_default( $item = array(), $column_name = '' ) {1711 1712 /**1713 * Filters a string to allow plugins to add custom column content.1714 *1715 * @since 2.4.01716 *1717 * @param string $value Empty string.1718 * @param string $column_name Name of the column being rendered.1719 * @param array $item The current activity item in the loop.1720 */1721 return apply_filters( 'bp_activity_admin_get_custom_column', '', $column_name, $item );1722 }1723 1724 /**1725 * Get the user id associated with a given activity item.1726 *1727 * Wraps bp_activity_get_specific(), with some additional logic for1728 * avoiding duplicate queries.1729 *1730 * @since 1.6.01731 *1732 * @param int $activity_id Activity ID to retrieve User ID for.1733 * @return int User ID of the activity item in question.1734 */1735 protected function get_activity_user_id( $activity_id ) {1736 // If there is an existing activity/user ID mapping, just return the user ID.1737 if ( ! empty( $this->activity_user_id[$activity_id] ) ) {1738 return $this->activity_user_id[$activity_id];1739 1740 /*1741 * We don't have a mapping. This means the $activity_id is not on the current1742 * page of results, so fetch its details from the database.1743 */1744 } else {1745 $activity = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all', ) );1746 1747 /*1748 * If, somehow, the referenced activity has been deleted, leaving its associated1749 * activities as orphans, use the logged in user's ID to avoid errors.1750 */1751 if ( empty( $activity['activities'] ) )1752 return bp_loggedin_user_id();1753 1754 // Store the new activity/user ID mapping for any later re-use.1755 $this->activity_user_id[ $activity['activities'][0]->id ] = $activity['activities'][0]->user_id;1756 1757 // Return the user ID.1758 return $activity['activities'][0]->user_id;1759 }1760 }1761 1762 /**1763 * Checks if an activity item can be replied to.1764 *1765 * This method merges functionality from {@link bp_activity_can_comment()} and1766 * {@link bp_blogs_disable_activity_commenting()}. This is done because the activity1767 * list table doesn't use a BuddyPress activity loop, which prevents those1768 * functions from working as intended.1769 *1770 * @since 2.0.01771 *1772 * @param array $item An array version of the BP_Activity_Activity object.1773 * @return bool $can_comment1774 */1775 protected function can_comment( $item ) {1776 $can_comment = true;1777 1778 if ( $this->disable_blogforum_comments ) {1779 switch ( $item['type'] ) {1780 case 'new_blog_post' :1781 case 'new_blog_comment' :1782 case 'new_forum_topic' :1783 case 'new_forum_post' :1784 $can_comment = false;1785 break;1786 }1787 1788 // Activity comments supported.1789 } else {1790 // Activity comment.1791 if ( 'activity_comment' == $item['type'] ) {1792 // Blogs.1793 if ( bp_is_active( 'blogs' ) ) {1794 // Grab the parent activity entry.1795 $parent_activity = new BP_Activity_Activity( $item['item_id'] );1796 1797 // Fetch blog post comment depth and if the blog post's comments are open.1798 bp_blogs_setup_activity_loop_globals( $parent_activity );1799 1800 // Check if the activity item can be replied to.1801 if ( false === bp_blogs_can_comment_reply( true, $item ) ) {1802 $can_comment = false;1803 }1804 }1805 1806 // Blog post.1807 } elseif ( 'new_blog_post' == $item['type'] ) {1808 if ( bp_is_active( 'blogs' ) ) {1809 bp_blogs_setup_activity_loop_globals( (object) $item );1810 1811 if ( empty( buddypress()->blogs->allow_comments[$item['id']] ) ) {1812 $can_comment = false;1813 }1814 }1815 }1816 }1817 1818 /**1819 * Filters if an activity item can be commented on or not.1820 *1821 * @since 2.0.01822 *1823 * @param bool $can_comment Whether an activity item can be commented on or not.1824 */1825 return apply_filters( 'bp_activity_list_table_can_comment', $can_comment );1826 }1827 1828 /**1829 * Flatten the activity array.1830 *1831 * In some cases, BuddyPress gives us a structured tree of activity1832 * items plus their comments. This method converts it to a flat array.1833 *1834 * @since 1.6.01835 *1836 * @param array $tree Source array.1837 * @return array Flattened array.1838 */1839 public static function flatten_activity_array( $tree ){1840 foreach ( (array) $tree as $node ) {1841 if ( isset( $node->children ) ) {1842 1843 foreach ( BP_Activity_List_Table::flatten_activity_array( $node->children ) as $child ) {1844 $tree[] = $child;1845 }1846 1847 unset( $node->children );1848 }1849 }1850 1851 return $tree;1852 }1853 }
Note: See TracChangeset
for help on using the changeset viewer.