component ) ) die( __( 'ERROR: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddypress' ) ); // @todo: Check if user is allowed to create new activity items // if ( ! current_user_can( 'bp_new_activity' ) ) if ( ! current_user_can( 'bp_moderate' ) ) die( '-1' ); // Add new activity comment. $new_activity_id = bp_activity_new_comment( array( 'activity_id' => $root_id, // ID of the root activity item. 'content' => $_REQUEST['content'], 'parent_id' => $parent_id, // ID of a parent comment. ) ); // Fetch the new activity item, as we need it to create table markup to return. $new_activity = new BP_Activity_Activity( $new_activity_id ); // This needs to be set for the BP_Activity_List_Table constructor to work. set_current_screen( 'toplevel_page_bp-activity' ); // Set up an output buffer. ob_start(); $list_table = new BP_Activity_List_Table(); $list_table->single_row( (array) $new_activity ); // Get table markup. $response = array( 'data' => ob_get_contents(), 'id' => $new_activity_id, 'position' => -1, 'what' => 'bp_activity', ); ob_end_clean(); // Send response. $r = new WP_Ajax_Response(); $r->add( $response ); $r->send(); exit(); } add_action( 'wp_ajax_bp-activity-admin-reply', 'bp_activity_admin_reply' ); /** * Handle save/update of screen options for the Activity component admin screen. * * @since 1.6.0 * * @param string $value Will always be false unless another plugin filters it first. * @param string $option Screen option name. * @param string $new_value Screen option form value. * @return string Option value. False to abandon update. */ function bp_activity_admin_screen_options( $value, $option, $new_value ) { if ( 'toplevel_page_bp_activity_per_page' != $option && 'toplevel_page_bp_activity_network_per_page' != $option ) return $value; // Per page. $new_value = (int) $new_value; if ( $new_value < 1 || $new_value > 999 ) return $value; return $new_value; } /** * Hide the advanced edit meta boxes by default, so we don't clutter the screen. * * @since 1.6.0 * * @param array $hidden Array of items to hide. * @param WP_Screen $screen Screen identifier. * @return array Hidden Meta Boxes. */ function bp_activity_admin_edit_hidden_metaboxes( $hidden, $screen ) { if ( empty( $screen->id ) || 'toplevel_page_bp-activity' != $screen->id && 'toplevel_page_bp-activity_network' != $screen->id ) return $hidden; // Hide the primary link meta box by default. $hidden = array_merge( (array) $hidden, array( 'bp_activity_itemids', 'bp_activity_link', 'bp_activity_type', 'bp_activity_userid', ) ); /** * Filters default hidden metaboxes so plugins can alter list. * * @since 1.6.0 * * @param array $hidden Default metaboxes to hide. * @param WP_Screen $screen Screen identifier. */ return apply_filters( 'bp_hide_meta_boxes', array_unique( $hidden ), $screen ); } add_filter( 'default_hidden_meta_boxes', 'bp_activity_admin_edit_hidden_metaboxes', 10, 2 ); /** * Set up the Activity admin page. * * Does the following: * - Register contextual help and screen options for this admin page. * - Enqueues scripts and styles. * - Catches POST and GET requests related to Activity. * * @since 1.6.0 * * @global object $bp BuddyPress global settings. * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table. */ function bp_activity_admin_load() { global $bp_activity_list_table; $bp = buddypress(); // Decide whether to load the dev version of the CSS and JavaScript. $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : 'min.'; $doaction = bp_admin_list_table_current_bulk_action(); /** * Fires at top of Activity admin page. * * @since 1.6.0 * * @param string $doaction Current $_GET action being performed in admin screen. */ do_action( 'bp_activity_admin_load', $doaction ); // Edit screen. if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) { // Columns screen option. add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) ); get_current_screen()->add_help_tab( array( 'id' => 'bp-activity-edit-overview', 'title' => __( 'Overview', 'buddypress' ), 'content' => '

' . __( 'You edit activities made on your site similar to the way you edit a comment. This is useful if you need to change which page the activity links to, or when you notice that the author has made a typographical error.', 'buddypress' ) . '

' . '

' . __( 'The two big editing areas for the activity title and content are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Primary Item/Secondary Item, Link, Type, Author ID) or to choose a 1- or 2-column layout for this screen.', 'buddypress' ) . '

' . '

' . __( 'You can also moderate the activity from this screen using the Status box, where you can also change the timestamp of the activity.', 'buddypress' ) . '

' ) ); get_current_screen()->add_help_tab( array( 'id' => 'bp-activity-edit-advanced', 'title' => __( 'Item, Link, Type', 'buddypress' ), 'content' => '

' . __( 'Primary Item/Secondary Item - These identify the object that created the activity. For example, the fields could reference a comment left on a specific site. Some types of activity may only use one, or none, of these fields.', 'buddypress' ) . '

' . '

' . __( 'Link - Used by some types of activity (e.g blog posts and comments, and forum topics and replies) to store a link back to the original content.', 'buddypress' ) . '

' . '

' . __( 'Type - Each distinct kind of activity has its own type. For example, created_group is used when a group is created and joined_group is used when a user joins a group.', 'buddypress' ) . '

' . '

' . __( 'For information about when and how BuddyPress uses all of these settings, see the Managing Activity link in the panel to the side.', 'buddypress' ) . '

' ) ); // Help panel - sidebar links. get_current_screen()->set_help_sidebar( '

' . __( 'For more information:', 'buddypress' ) . '

' . '

' . __( 'Managing Activity', 'buddypress' ) . '

' . '

' . __( 'Support Forums', 'buddypress' ) . '

' ); // Register metaboxes for the edit screen. add_meta_box( 'submitdiv', _x( 'Status', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_status', get_current_screen()->id, 'side', 'core' ); add_meta_box( 'bp_activity_itemids', _x( 'Primary Item/Secondary Item', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_itemids', get_current_screen()->id, 'normal', 'core' ); add_meta_box( 'bp_activity_link', _x( 'Link', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_link', get_current_screen()->id, 'normal', 'core' ); add_meta_box( 'bp_activity_type', _x( 'Type', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_type', get_current_screen()->id, 'normal', 'core' ); add_meta_box( 'bp_activity_userid', _x( 'Author ID', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_userid', get_current_screen()->id, 'normal', 'core' ); /** * Fires after the registration of all of the default activity meta boxes. * * @since 2.4.0 */ do_action( 'bp_activity_admin_meta_boxes' ); // Enqueue JavaScript files. wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'comment' ); // Index screen. } else { // Create the Activity screen list table. $bp_activity_list_table = new BP_Activity_List_Table(); // The per_page screen option. add_screen_option( 'per_page', array( 'label' => _x( 'Activity', 'Activity items per page (screen options)', 'buddypress' )) ); // Help panel - overview text. get_current_screen()->add_help_tab( array( 'id' => 'bp-activity-overview', 'title' => __( 'Overview', 'buddypress' ), 'content' => '

' . __( 'You can manage activities made on your site similar to the way you manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on activities using the on-hover action links or the Bulk Actions.', 'buddypress' ) . '

' . '

' . __( 'There are many different types of activities. Some are generated automatically by BuddyPress and other plugins, and some are entered directly by a user in the form of status update. To help manage the different activity types, use the filter dropdown box to switch between them.', 'buddypress' ) . '

' ) ); // Help panel - moderation text. get_current_screen()->add_help_tab( array( 'id' => 'bp-activity-moderating', 'title' => __( 'Moderating Activity', 'buddypress' ), 'content' => '

' . __( 'In the Activity column, above each activity it says “Submitted on,” followed by the date and time the activity item was generated on your site. Clicking on the date/time link will take you to that activity on your live site. Hovering over any activity gives you options to reply, edit, spam mark, or delete that activity.', 'buddypress' ) . '

' . '

' . __( "In the In Response To column, if the activity was in reply to another activity, it shows that activity's author's picture and name, and a link to that activity on your live site. If there is a small bubble, the number in it shows how many other activities are related to this one; these are usually comments. Clicking the bubble will filter the activity screen to show only related activity items.", 'buddypress' ) . '

' ) ); // Help panel - sidebar links. get_current_screen()->set_help_sidebar( '

' . __( 'For more information:', 'buddypress' ) . '

' . '

' . __( 'Support Forums', 'buddypress' ) . '

' ); } // Enqueue CSS and JavaScript. wp_enqueue_script( 'bp_activity_admin_js', $bp->plugin_url . "bp-activity/admin/js/admin.{$min}js", array( 'jquery', 'wp-ajax-response' ), bp_get_version(), true ); wp_localize_script( 'bp_activity_admin_js', 'bp_activity_admin_vars', array( 'page' => get_current_screen()->id ) ); wp_enqueue_style( 'bp_activity_admin_css', $bp->plugin_url . "bp-activity/admin/css/admin.{$min}css", array(), bp_get_version() ); wp_style_add_data( 'bp_activity_admin_css', 'rtl', true ); if ( $min ) { wp_style_add_data( 'bp_activity_admin_css', 'suffix', $min ); } /** * Fires after the activity js and style has been enqueued. * * @since 2.4.0 */ do_action( 'bp_activity_admin_enqueue_scripts' ); // Handle spam/un-spam/delete of activities. if ( !empty( $doaction ) && ! in_array( $doaction, array( '-1', 'edit', 'save', ) ) ) { // Build redirection URL. $redirect_to = remove_query_arg( array( 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), wp_get_referer() ); $redirect_to = add_query_arg( 'paged', $bp_activity_list_table->get_pagenum(), $redirect_to ); // Get activity IDs. $activity_ids = array_map( 'absint', (array) $_REQUEST['aid'] ); /** * Filters list of IDs being spammed/un-spammed/deleted. * * @since 1.6.0 * * @param array $activity_ids Activity IDs to spam/un-spam/delete. */ $activity_ids = apply_filters( 'bp_activity_admin_action_activity_ids', $activity_ids ); // Is this a bulk request? if ( 'bulk_' == substr( $doaction, 0, 5 ) && ! empty( $_REQUEST['aid'] ) ) { // Check this is a valid form submission. check_admin_referer( 'bulk-activities' ); // Trim 'bulk_' off the action name to avoid duplicating a ton of code. $doaction = substr( $doaction, 5 ); // This is a request to delete, spam, or un-spam, a single item. } elseif ( !empty( $_REQUEST['aid'] ) ) { // Check this is a valid form submission. check_admin_referer( 'spam-activity_' . $activity_ids[0] ); } // Initialise counters for how many of each type of item we perform an action on. $deleted = $spammed = $unspammed = 0; // Store any errors that occurs when updating the database items. $errors = array(); // "We'd like to shoot the monster, could you move, please?" foreach ( $activity_ids as $activity_id ) { // @todo: Check the permissions on each //if ( ! current_user_can( 'bp_edit_activity', $activity_id ) ) // continue; // Get the activity from the database. $activity = new BP_Activity_Activity( $activity_id ); if ( empty( $activity->component ) ) { $errors[] = $activity_id; continue; } switch ( $doaction ) { case 'delete' : if ( 'activity_comment' == $activity->type ) bp_activity_delete_comment( $activity->item_id, $activity->id ); else bp_activity_delete( array( 'id' => $activity->id ) ); $deleted++; break; case 'ham' : /** * Remove moderation and blacklist checks in case we want to ham an activity * which contains one of these listed keys. */ remove_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 ); remove_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2, 1 ); bp_activity_mark_as_ham( $activity ); $result = $activity->save(); // Check for any error during activity save. if ( ! $result ) $errors[] = $activity->id; else $unspammed++; break; case 'spam' : bp_activity_mark_as_spam( $activity ); $result = $activity->save(); // Check for any error during activity save. if ( ! $result ) $errors[] = $activity->id; else $spammed++; break; default: break; } // Release memory. unset( $activity ); } /** * Fires before redirect for plugins to do something with activity. * * Passes an activity array counts how many were spam, not spam, deleted, and IDs that were errors. * * @since 1.6.0 * * @param array $value Array holding spam, not spam, deleted counts, error IDs. * @param string $redirect_to URL to redirect to. * @param array $activity_ids Original array of activity IDs. */ do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids ); // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done. if ( $spammed ) $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to ); if ( $unspammed ) $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to ); if ( $deleted ) $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to ); // If an error occurred, pass back the activity ID that failed. if ( ! empty( $errors ) ) $redirect_to = add_query_arg( 'error', implode ( ',', array_map( 'absint', $errors ) ), $redirect_to ); /** * Filters redirect URL after activity spamming/un-spamming/deletion occurs. * * @since 1.6.0 * * @param string $redirect_to URL to redirect to. */ wp_redirect( apply_filters( 'bp_activity_admin_action_redirect', $redirect_to ) ); exit; // Save the edit. } elseif ( $doaction && 'save' == $doaction ) { // Build redirection URL. $redirect_to = remove_query_arg( array( 'action', 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] ); // Get activity ID. $activity_id = (int) $_REQUEST['aid']; // Check this is a valid form submission. check_admin_referer( 'edit-activity_' . $activity_id ); // Get the activity from the database. $activity = new BP_Activity_Activity( $activity_id ); // If the activity doesn't exist, just redirect back to the index. if ( empty( $activity->component ) ) { wp_redirect( $redirect_to ); exit; } // Check the form for the updated properties. // Store any error that occurs when updating the database item. $error = 0; // Activity spam status. $prev_spam_status = $new_spam_status = false; if ( ! empty( $_POST['activity_status'] ) ) { $prev_spam_status = $activity->is_spam; $new_spam_status = ( 'spam' == $_POST['activity_status'] ) ? true : false; } // Activity action. if ( isset( $_POST['bp-activities-action'] ) ) $activity->action = $_POST['bp-activities-action']; // Activity content. if ( isset( $_POST['bp-activities-content'] ) ) $activity->content = $_POST['bp-activities-content']; // Activity primary link. if ( ! empty( $_POST['bp-activities-link'] ) ) $activity->primary_link = $_POST['bp-activities-link']; // Activity user ID. if ( ! empty( $_POST['bp-activities-userid'] ) ) $activity->user_id = (int) $_POST['bp-activities-userid']; // Activity item primary ID. if ( isset( $_POST['bp-activities-primaryid'] ) ) $activity->item_id = (int) $_POST['bp-activities-primaryid']; // Activity item secondary ID. if ( isset( $_POST['bp-activities-secondaryid'] ) ) $activity->secondary_item_id = (int) $_POST['bp-activities-secondaryid']; // Activity type. if ( ! empty( $_POST['bp-activities-type'] ) ) { $actions = bp_activity_admin_get_activity_actions(); // Check that the new type is a registered activity type. if ( in_array( $_POST['bp-activities-type'], $actions ) ) { $activity->type = $_POST['bp-activities-type']; } } // Activity timestamp. if ( ! empty( $_POST['aa'] ) && ! empty( $_POST['mm'] ) && ! empty( $_POST['jj'] ) && ! empty( $_POST['hh'] ) && ! empty( $_POST['mn'] ) && ! empty( $_POST['ss'] ) ) { $aa = $_POST['aa']; $mm = $_POST['mm']; $jj = $_POST['jj']; $hh = $_POST['hh']; $mn = $_POST['mn']; $ss = $_POST['ss']; $aa = ( $aa <= 0 ) ? date( 'Y' ) : $aa; $mm = ( $mm <= 0 ) ? date( 'n' ) : $mm; $jj = ( $jj > 31 ) ? 31 : $jj; $jj = ( $jj <= 0 ) ? date( 'j' ) : $jj; $hh = ( $hh > 23 ) ? $hh -24 : $hh; $mn = ( $mn > 59 ) ? $mn -60 : $mn; $ss = ( $ss > 59 ) ? $ss -60 : $ss; // Reconstruct the date into a timestamp. $gmt_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); $activity->date_recorded = $gmt_date; } // Has the spam status has changed? if ( $new_spam_status != $prev_spam_status ) { if ( $new_spam_status ) bp_activity_mark_as_spam( $activity ); else bp_activity_mark_as_ham( $activity ); } // Save. $result = $activity->save(); // Clear the activity stream first page cache, in case this activity's timestamp was changed. wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); // Check for any error during activity save. if ( false === $result ) $error = $activity->id; /** * Fires before redirect so plugins can do something first on save action. * * @since 1.6.0 * * @param array Array holding activity object and ID that holds error. */ do_action_ref_array( 'bp_activity_admin_edit_after', array( &$activity, $error ) ); // If an error occurred, pass back the activity ID that failed. if ( $error ) $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to ); else $redirect_to = add_query_arg( 'updated', (int) $activity->id, $redirect_to ); /** * Filters URL to redirect to after saving. * * @since 1.6.0 * * @param string $redirect_to URL to redirect to. */ wp_redirect( apply_filters( 'bp_activity_admin_edit_redirect', $redirect_to ) ); exit; // If a referrer and a nonce is supplied, but no action, redirect back. } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) ); exit; } } /** * Output the Activity component admin screens. * * @since 1.6.0 */ function bp_activity_admin() { // Decide whether to load the index or edit screen. $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; // Display the single activity edit screen. if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) bp_activity_admin_edit(); // Otherwise, display the Activity index screen. else bp_activity_admin_index(); } /** * Display the single activity edit screen. * * @since 1.6.0 */ function bp_activity_admin_edit() { // @todo: Check if user is allowed to edit activity items // if ( ! current_user_can( 'bp_edit_activity' ) ) if ( ! is_super_admin() ) die( '-1' ); // Get the activity from the database. $activity = bp_activity_get( array( 'in' => ! empty( $_REQUEST['aid'] ) ? (int) $_REQUEST['aid'] : 0, 'max' => 1, 'show_hidden' => true, 'spam' => 'all', 'display_comments' => 0 ) ); if ( ! empty( $activity['activities'][0] ) ) { $activity = $activity['activities'][0]; // Workaround to use WP's touch_time() without duplicating that function. $GLOBALS['comment'] = new stdClass; $GLOBALS['comment']->comment_date = $activity->date_recorded; } else { $activity = ''; } // Construct URL for form. $form_url = remove_query_arg( array( 'action', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] ); $form_url = add_query_arg( 'action', 'save', $form_url ); /** * Fires before activity edit form is displays so plugins can modify the activity. * * @since 1.6.0 * * @param array $value Array holding single activity object that was passed by reference. */ do_action_ref_array( 'bp_activity_admin_edit', array( &$activity ) ); ?>

action ), 'bp-activities-action', array( 'media_buttons' => false, 'textarea_rows' => 7, 'teeny' => true, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ) ) ); ?>

content ), 'bp-activities-content', array( 'media_buttons' => false, 'teeny' => true, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ) ) ); ?>
id, 'side', $activity ); ?>
id, 'normal', $activity ); ?> id, 'advanced', $activity ); ?>
id ); ?>


date_recorded ) ); ?> ' . $date . '' ); ?> 
Pretty name for activity type. * * @since 2.0.0 * * @return array $actions */ function bp_activity_admin_get_activity_actions() { $actions = array(); // Walk through the registered actions, and build an array of actions/values. foreach ( bp_activity_get_actions() as $action ) { $action = array_values( (array) $action ); for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) { $actions[ $action[$i]['key'] ] = $action[$i]['value']; } } // This was a mis-named activity type from before BP 1.6. unset( $actions['friends_register_activity_action'] ); // Sort array by the human-readable value. natsort( $actions ); return $actions; } /** * Activity type metabox for the Activity admin edit screen. * * @since 1.6.0 * * @param object $item Activity item. */ function bp_activity_admin_edit_metabox_type( $item ) { $bp = buddypress(); $actions = array(); $selected = $item->type; // Walk through the registered actions, and build an array of actions/values. foreach ( bp_activity_get_actions() as $action ) { $action = array_values( (array) $action ); for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) $actions[ $action[$i]['key'] ] = $action[$i]['value']; } // This was a mis-named activity type from before BP 1.6. unset( $actions['friends_register_activity_action'] ); // Sort array by the human-readable value. natsort( $actions ); /* * If the activity type is not registered properly (eg, a plugin has * not called bp_activity_set_action()), add the raw type to the end * of the list. */ if ( ! isset( $actions[ $selected ] ) ) { _doing_it_wrong( __FUNCTION__, sprintf( __( 'This activity item has a type (%s) that is not registered using bp_activity_set_action(), so no label is available.', 'buddypress' ), $selected ), '2.0.0' ); $actions[ $selected ] = $selected; } ?>

0 ) $messages[] = sprintf( _n( '%s activity item has been permanently deleted.', '%s activity items have been permanently deleted.', $deleted, 'buddypress' ), number_format_i18n( $deleted ) ); if ( ! empty( $errors ) ) { if ( 1 == count( $errors ) ) { $messages[] = sprintf( __( 'An error occurred when trying to update activity ID #%s.', 'buddypress' ), number_format_i18n( $errors[0] ) ); } else { $error_msg = __( 'Errors occurred when trying to update these activity items:', 'buddypress' ); $error_msg .= ''; $messages[] = $error_msg; } } if ( $spammed > 0 ) $messages[] = sprintf( _n( '%s activity item has been successfully spammed.', '%s activity items have been successfully spammed.', $spammed, 'buddypress' ), number_format_i18n( $spammed ) ); if ( $unspammed > 0 ) $messages[] = sprintf( _n( '%s activity item has been successfully unspammed.', '%s activity items have been successfully unspammed.', $unspammed, 'buddypress' ), number_format_i18n( $unspammed ) ); if ( $updated > 0 ) $messages[] = __( 'The activity item has been updated successfully.', 'buddypress' ); } // Prepare the activity items for display. $bp_activity_list_table->prepare_items(); /** * Fires before edit form is displayed so plugins can modify the activity messages. * * @since 1.6.0 * * @param array $messages Array of messages to display at top of page. */ do_action( 'bp_activity_admin_index', $messages ); ?>

\n", $messages ); ?>

views(); ?>
search_box( __( 'Search all Activity', 'buddypress' ), 'bp-activity' ); ?> display(); ?>
disable_blogforum_comments = bp_disable_blogforum_comments(); // Define singular and plural labels, as well as whether we support AJAX. parent::__construct( array( 'ajax' => false, 'plural' => 'activities', 'singular' => 'activity', 'screen' => get_current_screen(), ) ); } /** * Handle filtering of data, sorting, pagination, and any other data manipulation prior to rendering. * * @since 1.6.0 */ function prepare_items() { // Option defaults. $filter = array(); $include_id = false; $search_terms = false; $sort = 'DESC'; $spam = 'ham_only'; // Set current page. $page = $this->get_pagenum(); // Set per page from the screen options. $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); // Check if we're on the "Spam" view. if ( !empty( $_REQUEST['activity_status'] ) && 'spam' == $_REQUEST['activity_status'] ) { $spam = 'spam_only'; $this->view = 'spam'; } // Sort order. if ( !empty( $_REQUEST['order'] ) && 'desc' != $_REQUEST['order'] ) $sort = 'ASC'; // Order by. /*if ( !empty( $_REQUEST['orderby'] ) ) { }*/ // Filter. if ( !empty( $_REQUEST['activity_type'] ) ) $filter = array( 'action' => $_REQUEST['activity_type'] ); // Are we doing a search? if ( !empty( $_REQUEST['s'] ) ) $search_terms = $_REQUEST['s']; // Check if user has clicked on a specific activity (if so, fetch only that, and any related, activity). if ( !empty( $_REQUEST['aid'] ) ) $include_id = (int) $_REQUEST['aid']; // Get the spam total (ignoring any search query or filter). $spams = bp_activity_get( array( 'display_comments' => 'stream', 'show_hidden' => true, 'spam' => 'spam_only', 'count_total' => 'count_query', ) ); $this->spam_count = $spams['total']; unset( $spams ); // Get the activities from the database. $activities = bp_activity_get( array( 'display_comments' => 'stream', 'filter' => $filter, 'in' => $include_id, 'page' => $page, 'per_page' => $per_page, 'search_terms' => $search_terms, 'show_hidden' => true, // 'sort' => $sort, 'spam' => $spam, 'count_total' => 'count_query', ) ); // If we're viewing a specific activity, flatten all activities into a single array. if ( $include_id ) { $activities['activities'] = BP_Activity_List_Table::flatten_activity_array( $activities['activities'] ); $activities['total'] = count( $activities['activities'] ); // Sort the array by the activity object's date_recorded value. usort( $activities['activities'], create_function( '$a, $b', 'return $a->date_recorded > $b->date_recorded;' ) ); } // The bp_activity_get function returns an array of objects; cast these to arrays for WP_List_Table. $new_activities = array(); foreach ( $activities['activities'] as $activity_item ) { $new_activities[] = (array) $activity_item; // Build an array of activity-to-user ID mappings for better efficiency in the In Response To column. $this->activity_user_id[$activity_item->id] = $activity_item->user_id; } // Set raw data to display. $this->items = $new_activities; // Store information needed for handling table pagination. $this->set_pagination_args( array( 'per_page' => $per_page, 'total_items' => $activities['total'], 'total_pages' => ceil( $activities['total'] / $per_page ) ) ); // Don't truncate activity items; bp_activity_truncate_entry() needs to be used inside a BP_Activity_Template loop. remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); } /** * Get an array of all the columns on the page. * * @since 1.6.0 * * @return array Column headers. */ function get_column_info() { $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), $this->get_default_primary_column_name(), ); return $this->_column_headers; } /** * Get name of default primary column * * @since 2.3.3 * * @return string */ protected function get_default_primary_column_name() { return 'author'; } /** * Display a message on screen when no items are found (e.g. no search matches). * * @since 1.6.0 */ function no_items() { _e( 'No activities found.', 'buddypress' ); } /** * Output the Activity data table. * * @since 1.6.0 */ function display() { $this->display_tablenav( 'top' ); ?> print_column_headers(); ?> print_column_headers( false ); ?> display_rows_or_placeholder(); ?>
display_tablenav( 'bottom' ); } /** * Generate content for a single row of the table. * * @since 1.6.0 * * @param object $item The current item. */ function single_row( $item ) { static $even = false; if ( $even ) { $row_class = ' class="even"'; } else { $row_class = ' class="alternate odd"'; } if ( 'activity_comment' === $item['type'] ) { $root_id = $item['item_id']; } else { $root_id = $item['id']; } echo ''; echo $this->single_row_columns( $item ); echo ''; $even = ! $even; } /** * Get the list of views available on this table (e.g. "all", "spam"). * * @since 1.6.0 */ function get_views() { $url_base = add_query_arg( array( 'page' => 'bp-activity' ), bp_get_admin_url( 'admin.php' ) ); ?> '', 'author' => _x('Author', 'Admin SWA column header', 'buddypress' ), 'comment' => _x( 'Activity', 'Admin SWA column header', 'buddypress' ), 'action' => _x( 'Action', 'Admin SWA column header', 'buddypress' ), 'response' => _x( 'In Response To', 'Admin SWA column header', 'buddypress' ), ) ); } /** * Get the column names for sortable columns. * * Currently, returns an empty array (no columns are sortable). * * @since 1.6.0 * @todo For this to work, BP_Activity_Activity::get() needs updating * to support ordering by specific fields. * * @return array The columns that can be sorted on the Activity screen. */ function get_sortable_columns() { return array(); /*return array( 'author' => array( 'activity_author', false ), // Intentionally not using "=>" );*/ } /** * Markup for the "filter" part of the form (i.e. which activity type to display). * * @since 1.6.0 * * @param string $which 'top' or 'bottom'. */ function extra_tablenav( $which ) { // Bail on bottom table nav. if ( 'bottom' === $which ) { return; } // Is any filter currently selected? $selected = ( ! empty( $_REQUEST['activity_type'] ) ) ? $_REQUEST['activity_type'] : ''; // Get the actions. $activity_actions = bp_activity_get_actions(); ?>
'post-query-submit' ) ); ?>
addition. * * @since 2.3.3 * @since 2.3.4 Visibility set to public for compatibility with WP < 4.0.0. * * @param array $actions The list of actions. * @param bool $always_visible Whether the actions should be always visible. * @return string */ public function row_actions( $actions, $always_visible = false ) { $action_count = count( $actions ); $i = 0; if ( !$action_count ) return ''; $out = '
'; foreach ( $actions as $action => $link ) { ++$i; ( $i == $action_count ) ? $sep = '' : $sep = ' | '; $out .= "$link$sep"; } $out .= '
'; return $out; } /** * Checkbox column markup. * * @since 1.6.0 * * @see WP_List_Table::single_row_columns() * * @param array $item A singular item (one full row). */ function column_cb( $item ) { printf( '', $item['id'] ); } /** * Author column markup. * * @since 1.6.0 * * @see WP_List_Table::single_row_columns() * * @param array $item A singular item (one full row). */ function column_author( $item ) { echo '' . get_avatar( $item['user_id'], '32' ) . ' ' . bp_core_get_userlink( $item['user_id'] ) . ''; } /** * Action column markup. * * @since 2.0.0 * * @see WP_List_Table::single_row_columns() * * @param array $item A singular item (one full row). */ function column_action( $item ) { $actions = bp_activity_admin_get_activity_actions(); if ( isset( $actions[ $item['type'] ] ) ) { echo $actions[ $item['type'] ]; } else { printf( __( 'Unregistered action - %s', 'buddypress' ), $item['type'] ); } } /** * Content column, and "quick admin" rollover actions. * * Called "comment" in the CSS so we can re-use some WP core CSS. * * @since 1.6.0 * * @see WP_List_Table::single_row_columns() * * @param array $item A singular item (one full row). */ function column_comment( $item ) { // Determine what type of item (row) we're dealing with. if ( $item['is_spam'] ) $item_status = 'spam'; else $item_status = 'all'; // Preorder items: Reply | Edit | Spam | Delete Permanently. $actions = array( 'reply' => '', 'edit' => '', 'spam' => '', 'unspam' => '', 'delete' => '', ); // Build actions URLs. $base_url = bp_get_admin_url( 'admin.php?page=bp-activity&aid=' . $item['id'] ); $spam_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'spam-activity_' . $item['id'] ) ); $delete_url = $base_url . "&action=delete&$spam_nonce"; $edit_url = $base_url . '&action=edit'; $ham_url = $base_url . "&action=ham&$spam_nonce"; $spam_url = $base_url . "&action=spam&$spam_nonce"; // Rollover actions. // Reply - JavaScript only; implemented by AJAX. if ( 'spam' != $item_status ) { if ( $this->can_comment( $item ) ) { $actions['reply'] = sprintf( '%s', __( 'Reply', 'buddypress' ) ); } else { $actions['reply'] = sprintf( '%s', __( 'Replies are disabled for this activity item', 'buddypress' ), __( 'Replies disabled', 'buddypress' ) ); } // Edit. $actions['edit'] = sprintf( '%s', $edit_url, __( 'Edit', 'buddypress' ) ); } // Spam/unspam. if ( 'spam' == $item_status ) $actions['unspam'] = sprintf( '%s', $ham_url, __( 'Not Spam', 'buddypress' ) ); else $actions['spam'] = sprintf( '%s', $spam_url, __( 'Spam', 'buddypress' ) ); // Delete. $actions['delete'] = sprintf( '%s', $delete_url, "javascript:return confirm('" . esc_js( __( 'Are you sure?', 'buddypress' ) ) . "'); ", __( 'Delete Permanently', 'buddypress' ) ); // Start timestamp. echo '
'; /** * Filters available actions for plugins to alter. * * @since 1.6.0 * * @param array $actions Array of available actions user could use. * @param array $item Current item being added to page. */ $actions = apply_filters( 'bp_activity_admin_comment_row_actions', array_filter( $actions ), $item ); /* translators: 2: activity admin ui date/time */ printf( __( 'Submitted on %2$s at %3$s', 'buddypress' ), bp_activity_get_permalink( $item['id'] ), date_i18n( bp_get_option( 'date_format' ), strtotime( $item['date_recorded'] ) ), get_date_from_gmt( $item['date_recorded'], bp_get_option( 'time_format' ) ) ); // End timestamp. echo '
'; // Get activity content - if not set, use the action. if ( ! empty( $item['content'] ) ) { /** * Filters current activity item content. * * @since 1.2.0 * * @param array $item Array index holding current activity item content. */ $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $item['content'] ) ); } else { /** * Filters current activity item action. * * @since 1.2.0 * * @var array $item Array index holding current activity item action. */ $content = apply_filters_ref_array( 'bp_get_activity_action', array( $item['action'] ) ); } /** * Filter here to add extra output to the activity content into the Administration. * * @since 2.4.0 * * @param string $content The activity content. * @param array $item The activity object converted into an array. */ echo apply_filters( 'bp_activity_admin_comment_content', $content, $item ) . ' ' . $this->row_actions( $actions ); } /** * "In response to" column markup. * * @since 1.6.0 * * @see WP_List_Table::single_row_columns() * * @param array $item A singular item (one full row). */ function column_response( $item ) { // Is $item is a root activity? ?> activity_user_id[$activity_id] ) ) { return $this->activity_user_id[$activity_id]; /* * We don't have a mapping. This means the $activity_id is not on the current * page of results, so fetch its details from the database. */ } else { $activity = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all', ) ); /* * If, somehow, the referenced activity has been deleted, leaving its associated * activities as orphans, use the logged in user's ID to avoid errors. */ if ( empty( $activity['activities'] ) ) return bp_loggedin_user_id(); // Store the new activity/user ID mapping for any later re-use. $this->activity_user_id[ $activity['activities'][0]->id ] = $activity['activities'][0]->user_id; // Return the user ID. return $activity['activities'][0]->user_id; } } /** * Checks if an activity item can be replied to. * * This method merges functionality from {@link bp_activity_can_comment()} and * {@link bp_blogs_disable_activity_commenting()}. This is done because the activity * list table doesn't use a BuddyPress activity loop, which prevents those * functions from working as intended. * * @since 2.0.0 * * @param array $item An array version of the BP_Activity_Activity object. * @return bool $can_comment */ protected function can_comment( $item ) { $can_comment = true; if ( $this->disable_blogforum_comments ) { switch ( $item['type'] ) { case 'new_blog_post' : case 'new_blog_comment' : case 'new_forum_topic' : case 'new_forum_post' : $can_comment = false; break; } // Activity comments supported. } else { // Activity comment. if ( 'activity_comment' == $item['type'] ) { // Blogs. if ( bp_is_active( 'blogs' ) ) { // Grab the parent activity entry. $parent_activity = new BP_Activity_Activity( $item['item_id'] ); // Fetch blog post comment depth and if the blog post's comments are open. bp_blogs_setup_activity_loop_globals( $parent_activity ); // Check if the activity item can be replied to. if ( false === bp_blogs_can_comment_reply( true, $item ) ) { $can_comment = false; } } // Blog post. } elseif ( 'new_blog_post' == $item['type'] ) { if ( bp_is_active( 'blogs' ) ) { bp_blogs_setup_activity_loop_globals( (object) $item ); if ( empty( buddypress()->blogs->allow_comments[$item['id']] ) ) { $can_comment = false; } } } } /** * Filters if an activity item can be commented on or not. * * @since 2.0.0 * * @param bool $can_comment Whether an activity item can be commented on or not. */ return apply_filters( 'bp_activity_list_table_can_comment', $can_comment ); } /** * Flatten the activity array. * * In some cases, BuddyPress gives us a structured tree of activity * items plus their comments. This method converts it to a flat array. * * @since 1.6.0 * * @param array $tree Source array. * @return array Flattened array. */ public static function flatten_activity_array( $tree ){ foreach ( (array) $tree as $node ) { if ( isset( $node->children ) ) { foreach ( BP_Activity_List_Table::flatten_activity_array( $node->children ) as $child ) { $tree[] = $child; } unset( $node->children ); } } return $tree; } }