예제 #1
0
/**
 * 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 BuddyPress (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 BuddyPress (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' => '<p>' . __('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') . '</p>' . '<p>' . __('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') . '</p>' . '<p>' . __('You can also moderate the activity from this screen using the Status box, where you can also change the timestamp of the activity.', 'buddypress') . '</p>'));
        get_current_screen()->add_help_tab(array('id' => 'bp-activity-edit-advanced', 'title' => __('Item, Link, Type', 'buddypress'), 'content' => '<p>' . __('<strong>Primary Item/Secondary Item</strong> - 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') . '</p>' . '<p>' . __('<strong>Link</strong> - 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') . '</p>' . '<p>' . __('<strong>Type</strong> - Each distinct kind of activity has its own type. For example, <code>created_group</code> is used when a group is created and <code>joined_group</code> is used when a user joins a group.', 'buddypress') . '</p>' . '<p>' . __('For information about when and how BuddyPress uses all of these settings, see the Managing Activity link in the panel to the side.', 'buddypress') . '</p>'));
        // Help panel - sidebar links
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://codex.buddypress.org/administrator-guide/activity-stream-management-panels/">Managing Activity</a>', 'buddypress') . '</p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
        // 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');
        // 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();
        // 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' => '<p>' . __('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') . '</p>' . '<p>' . __('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') . '</p>'));
        // Help panel - moderation text
        get_current_screen()->add_help_tab(array('id' => 'bp-activity-moderating', 'title' => __('Moderating Activity', 'buddypress'), 'content' => '<p>' . __('In the <strong>Activity</strong> column, above each activity it says &#8220;Submitted on,&#8221; 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') . '</p>' . '<p>' . __("In the <strong>In Response To</strong> 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') . '</p>'));
        // Help panel - sidebar links
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
    }
    // 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);
    }
    // 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 BuddyPress (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 BuddyPress (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 BuddyPress (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 BuddyPress (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 BuddyPress (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;
    }
}
예제 #2
0
/**
 * Mark all of the user's activity as ham (not spam).
 *
 * @since BuddyPress (1.6.0)
 *
 * @global object $wpdb WordPress database access object.
 * @global object $bp BuddyPress global settings.
 *
 * @param int $user_id ID of the user whose activity is being hammed.
 */
function bp_activity_ham_all_user_data($user_id = 0)
{
    global $wpdb;
    // Do not delete user data unless a logged in user says so
    if (empty($user_id) || !is_user_logged_in()) {
        return false;
    }
    // Get all the user's activities.
    $activities = bp_activity_get(array('display_comments' => 'stream', 'filter' => array('user_id' => $user_id), 'show_hidden' => true, 'spam' => 'all'));
    $bp = buddypress();
    // Mark each as not spam
    foreach ((array) $activities['activities'] as $activity) {
        // Create an activity object
        $activity_obj = new BP_Activity_Activity();
        foreach ($activity as $k => $v) {
            $activity_obj->{$k} = $v;
        }
        // Mark as not spam
        bp_activity_mark_as_ham($activity_obj);
        /*
         * If Akismet is present, update the activity history meta.
         *
         * This is usually taken care of when BP_Activity_Activity::save() happens, but
         * as we're going to be updating all the activity statuses directly, for efficency,
         * we need to update manually.
         */
        if (!empty($bp->activity->akismet)) {
            $bp->activity->akismet->update_activity_ham_meta($activity_obj);
        }
        // Tidy up
        unset($activity_obj);
    }
    // Mark all of this user's activities as spam
    $wpdb->query($wpdb->prepare("UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id));
    // Call an action for plugins to use
    do_action('bp_activity_ham_all_user_data', $user_id, $activities['activities']);
}
예제 #3
0
/**
 * When a blog comment status transition occurs, update the relevant activity's status.
 *
 * @global object $bp BuddyPress global settings
 * @param string $new_status New comment status.
 * @param string $old_status Previous comment status.
 * @param object $comment Comment data.
 * @since 1.6
 */
function bp_blogs_transition_activity_status($new_status, $old_status, $comment)
{
    global $bp;
    // Check the Activity component is active
    if (!bp_is_active('activity')) {
        return;
    }
    /**
     * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
     *
     * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
     * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
     * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
     * Otherwise, record the comment into the activity stream.
     */
    // This clause was moved in from bp_blogs_remove_comment() in BuddyPress 1.6. It handles delete/hold.
    if (in_array($new_status, array('delete', 'hold'))) {
        return bp_blogs_remove_comment($comment->comment_ID);
    } elseif (in_array($new_status, array('trash', 'spam'))) {
        $action = 'spam_activity';
    } elseif ('approved' == $new_status) {
        $action = 'ham_activity';
    }
    // Get the activity
    $activity_id = bp_activity_get_activity_id(array('component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment'));
    // Check activity item exists
    if (!$activity_id) {
        // If no activity exists, but the comment has been approved, record it into the activity table.
        if ('approved' == $new_status) {
            return bp_blogs_record_comment($comment->comment_ID, true);
        }
        return;
    }
    // Create an activity object
    $activity = new BP_Activity_Activity($activity_id);
    if (empty($activity->component)) {
        return;
    }
    // Spam/ham the activity if it's not already in that state
    if ('spam_activity' == $action && !$activity->is_spam) {
        bp_activity_mark_as_spam($activity);
    } elseif ('ham_activity' == $action) {
        bp_activity_mark_as_ham($activity);
    }
    // Add "new_blog_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
    $comment_akismet_history = create_function('$t', '$t[] = "new_blog_comment"; return $t;');
    add_filter('bp_akismet_get_activity_types', $comment_akismet_history);
    // Save the updated activity
    $activity->save();
    // Remove the "new_blog_comment" activity type whitelist so we don't break anything
    remove_filter('bp_akismet_get_activity_types', $comment_akismet_history);
}
/**
 * When a post type comment status transition occurs, update the relevant activity's status.
 *
 * @since 2.5.0
 *
 * @param string     $new_status New comment status.
 * @param string     $old_status Previous comment status.
 * @param WP_Comment $comment Comment data.
 */
function bp_activity_transition_post_type_comment_status($new_status, $old_status, $comment)
{
    $post_type = get_post_type($comment->comment_post_ID);
    if (!$post_type) {
        return;
    }
    // Get the post type tracking args.
    $activity_post_object = bp_activity_get_post_type_tracking_args($post_type);
    // Bail if the activity type does not exist
    if (empty($activity_post_object->comments_tracking->action_id)) {
        return false;
        // Set the $activity_comment_object
    } else {
        $activity_comment_object = $activity_post_object->comments_tracking;
    }
    // Init an empty activity ID
    $activity_id = 0;
    /**
     * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
     *
     * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
     * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
     * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
     * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam.
     * Otherwise, record the comment into the activity stream.
     */
    // This clause handles delete/hold.
    if (in_array($new_status, array('delete', 'hold'))) {
        return bp_activity_post_type_remove_comment($comment->comment_ID, $activity_post_object);
        // These clauses handle trash, spam, and un-spams.
    } elseif (in_array($new_status, array('trash', 'spam', 'unapproved'))) {
        $action = 'spam_activity';
    } elseif ('approved' == $new_status) {
        $action = 'ham_activity';
    }
    // Get the activity
    if (bp_disable_blogforum_comments()) {
        $activity_id = bp_activity_get_activity_id(array('component' => $activity_comment_object->component_id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => $activity_comment_object->action_id));
    } else {
        $activity_id = get_comment_meta($comment->comment_ID, 'bp_activity_comment_id', true);
    }
    /**
     * Leave a chance to plugins to manage activity comments differently.
     *
     * @since  2.5.0
     *
     * @param bool        $value       True to override BuddyPress management.
     * @param string      $post_type   The post type name.
     * @param int         $activity_id The post type activity (0 if not found).
     * @param string      $new_status  The new status of the post type comment.
     * @param string      $old_status  The old status of the post type comment.
     * @param WP_Comment  $comment Comment data.
     */
    if (true === apply_filters('bp_activity_pre_transition_post_type_comment_status', false, $post_type, $activity_id, $new_status, $old_status, $comment)) {
        return false;
    }
    // Check activity item exists
    if (empty($activity_id)) {
        // If no activity exists, but the comment has been approved, record it into the activity table.
        if ('approved' == $new_status) {
            return bp_activity_post_type_comment($comment->comment_ID, true, $activity_post_object);
        }
        return;
    }
    // Create an activity object
    $activity = new BP_Activity_Activity($activity_id);
    if (empty($activity->component)) {
        return;
    }
    // Spam/ham the activity if it's not already in that state
    if ('spam_activity' === $action && !$activity->is_spam) {
        bp_activity_mark_as_spam($activity);
    } elseif ('ham_activity' == $action) {
        bp_activity_mark_as_ham($activity);
    }
    // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
    $post_type_comment_action = $activity_comment_object->action_id;
    $comment_akismet_history = create_function('$t', '$t[] = $post_type_comment_action; return $t;');
    add_filter('bp_akismet_get_activity_types', $comment_akismet_history);
    // Make sure the activity change won't edit the comment if sync is on
    remove_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20);
    // Save the updated activity
    $activity->save();
    // Restore the action
    add_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20);
    // Remove the "new_blog_comment" activity type whitelist so we don't break anything
    remove_filter('bp_akismet_get_activity_types', $comment_akismet_history);
}
예제 #5
0
/**
 * Set up the admin page before any output is sent. Register contextual help and screen options for this admin page.
 *
 * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table
 * @since 1.6
 */
function bp_activity_admin_load()
{
    global $bp_activity_list_table;
    // per_page screen option
    add_screen_option('per_page', array('label' => _x('Activities', 'Activity items per page (screen options)', 'buddypress')));
    // Help panel - text
    add_contextual_help(get_current_screen(), '<p>' . __('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') . '</p>' . '<p>' . __('There are many different types of activities. Some are generated by BuddyPress automatically, and others 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') . '</p>' . '<p>' . __('In the Activity column, above each activity it says &#8220;Submitted on,&#8221; 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') . '</p>' . '<p>' . __('In the In Response To column, the text is the name of the user who generated the activity, and a link to the activity on your live site. The small bubble with 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') . '</p>');
    // Help panel - sidebar links
    get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
    // Create the Activity screen list table
    $bp_activity_list_table = new BP_Activity_List_Table();
    // Handle spam/un-spam/delete of activities
    $doaction = $bp_activity_list_table->current_action();
    if ($doaction && 'edit' != $doaction) {
        // Build redirection URL
        $redirect_to = remove_query_arg(array('aid', 'deleted', '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']);
        // 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;
        // "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)) {
                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':
                    bp_activity_mark_as_ham($activity);
                    $activity->save();
                    break;
                case 'spam':
                    bp_activity_mark_as_spam($activity);
                    $activity->save();
                    $spammed++;
                    break;
                default:
                    break;
            }
            // Release memory
            unset($activity);
        }
        // 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);
        }
        // Redirect
        wp_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;
    }
}
예제 #6
0
 /**
  * @group bp_blogs_sync_activity_edit_to_post_comment
  * @group post_type_comment_activities
  * @group imath
  */
 public function test_bp_blogs_sync_activity_edit_to_post_comment_trash_comment_ham_activity()
 {
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     $userdata = get_userdata($u);
     // let's use activity comments instead of single "new_blog_comment" activity items
     add_filter('bp_disable_blogforum_comments', '__return_false');
     // create the blog post
     $post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'post', 'post_title' => 'Test activity comment to post comment'));
     // grab the activity ID for the activity comment
     $a1 = bp_activity_get_activity_id(array('type' => 'new_blog_post', 'component' => buddypress()->blogs->id, 'filter' => array('item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id)));
     $a2 = bp_activity_new_comment(array('content' => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed', 'user_id' => $u, 'activity_id' => $a1));
     $c = bp_activity_get_meta($a2, 'bp_blogs_post_comment_id');
     wp_trash_comment($c);
     $activity = new BP_Activity_Activity($a2);
     bp_activity_mark_as_ham($activity);
     $activity->save();
     $post_comments = get_comments(array('post_id' => $post_id, 'status' => 'approve'));
     $comment = reset($post_comments);
     $this->assertTrue((int) $comment->comment_ID === (int) bp_activity_get_meta($a2, 'bp_blogs_post_comment_id'), 'The comment ID should be in the activity meta');
     $this->assertTrue((int) $a2 === (int) get_comment_meta($comment->comment_ID, 'bp_activity_comment_id', true), 'The activity ID should be in the comment meta');
     // reset
     remove_filter('bp_disable_blogforum_comments', '__return_false');
     $this->set_current_user($old_user);
 }