Example #1
0
/**
 * Mark an activity item as ham.
 *
 * @since BuddyPress (1.6.0)
 *
 * @param BP_Activity_Activity $activity The activity item to be hammed.
 * @param string $source Optional. Default is "by_a_person" (ie, a person has
 *        manually marked the activity as spam). BP core also accepts
 *        'by_akismet'.
 */
function bp_activity_mark_as_ham(&$activity, $source = 'by_a_person')
{
    $bp = buddypress();
    $activity->is_spam = 0;
    // Clear the activity stream first page cache
    wp_cache_delete('bp_activity_sitewide_front', 'bp');
    // Clear the activity comment cache for this activity item
    wp_cache_delete($activity->id, 'bp_activity_comments');
    // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity
    if ('by_a_person' == $source && !empty($bp->activity->akismet)) {
        remove_action('bp_activity_before_save', array($bp->activity->akismet, 'check_activity'), 4, 1);
        // Build data package for Akismet
        $activity_data = BP_Akismet::build_akismet_data_package($activity);
        // Tell Akismet this is spam
        $activity_data = $bp->activity->akismet->send_akismet_request($activity_data, 'submit', 'ham');
        // Update meta
        add_action('bp_activity_after_save', array($bp->activity->akismet, 'update_activity_ham_meta'), 1, 1);
    }
    do_action('bp_activity_mark_as_ham', $activity, $source);
}
/**
 * Mark an activity item as ham.
 *
 * @since 1.6.0
 *
 * @param BP_Activity_Activity $activity The activity item to be hammed. Passed by reference.
 * @param string               $source   Optional. Default is "by_a_person" (ie, a person has
 *                                       manually marked the activity as spam). BP core also accepts
 *                                       'by_akismet'.
 */
function bp_activity_mark_as_ham(&$activity, $source = 'by_a_person')
{
    $bp = buddypress();
    $activity->is_spam = 0;
    // Clear the activity stream first page cache.
    wp_cache_delete('bp_activity_sitewide_front', 'bp');
    // Clear the activity comment cache for this activity item.
    wp_cache_delete($activity->id, 'bp_activity_comments');
    // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity.
    if ('by_a_person' == $source && !empty($bp->activity->akismet)) {
        remove_action('bp_activity_before_save', array($bp->activity->akismet, 'check_activity'), 4, 1);
        // Build data package for Akismet.
        $activity_data = BP_Akismet::build_akismet_data_package($activity);
        // Tell Akismet this is spam.
        $activity_data = $bp->activity->akismet->send_akismet_request($activity_data, 'submit', 'ham');
        // Update meta.
        add_action('bp_activity_after_save', array($bp->activity->akismet, 'update_activity_ham_meta'), 1, 1);
    }
    /**
     * Fires at the end of the process to mark an activity item as ham.
     *
     * @since 1.6.0
     *
     * @param BP_Activity_Activity $activity Activity item being marked as ham.
     * @param string               $source   Source of determination of ham status. For example
     *                                       "by_a_person" or "by_akismet".
     */
    do_action('bp_activity_mark_as_ham', $activity, $source);
}
 /**
  * History meta box for the Activity admin edit screen
  *
  * @param object $item Activity item
  * @since BuddyPress (1.6)
  * @todo Update activity meta to allow >1 record with the same key (iterate through $history).
  * @see http://buddypress.trac.wordpress.org/ticket/3907
  */
 function history_metabox($item)
 {
     $history = BP_Akismet::get_activity_history($item->id);
     if (empty($history)) {
         return;
     }
     echo '<div class="akismet-history"><div>';
     printf(_x('<span>%1$s</span> &mdash; %2$s', 'x hours ago - akismet cleared this item', 'buddypress'), bp_core_time_since($history[2]), esc_html($history[1]));
     echo '</div></div>';
 }
 /**
  * Update activity meta after an automatic spam check (not user initiated)
  *
  * @param BP_Activity_Activity $activity The activity to check
  * @since 1.6
  */
 public function update_activity_akismet_meta($activity)
 {
     // Check we're dealing with what was last updated by Akismet
     if (empty($this->last_activity) || !empty($this->last_activity) && $activity->id != $this->last_activity->id) {
         return;
     }
     // By default, only handle activity updates and activity comments.
     if (!in_array($this->last_activity->type, BP_Akismet::get_activity_types())) {
         return;
     }
     // Spam
     if ('true' == $this->last_activity->akismet_submission['bp_as_result']) {
         bp_activity_update_meta($activity->id, '_bp_akismet_result', 'true');
         $this->update_activity_history($activity->id, __('Akismet caught this item as spam', 'buddypress'), 'check-spam');
         // Not spam
     } elseif ('false' == $this->last_activity->akismet_submission['bp_as_result']) {
         bp_activity_update_meta($activity->id, '_bp_akismet_result', 'false');
         $this->update_activity_history($activity->id, __('Akismet cleared this item', 'buddypress'), 'check-ham');
         // Uh oh, something's gone horribly wrong. Unexpected result.
     } else {
         bp_activity_update_meta($activity->id, '_bp_akismet_error', bp_core_current_time());
         $this->update_activity_history($activity->id, sprintf(__('Akismet was unable to check this item (response: %s), will automatically retry again later.', 'buddypress'), $this->last_activity->akismet_submission['bp_as_result']), 'check-error');
     }
     // Record the original data which was submitted to Akismet for checking
     bp_activity_update_meta($activity->id, '_bp_akismet_submission', $this->last_activity->akismet_submission);
 }