Skip to:
Content

BuddyPress.org

Changeset 5259


Ignore:
Timestamp:
10/24/2011 02:00:04 PM (10 years ago)
Author:
djpaul
Message:

First pass of Akismet support for the Activity component. See #3660

Location:
trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-actions.php

    r5253 r5259  
    171171}
    172172add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
     173
     174/**
     175 * Mark specific activity item as spam and redirect to previous page
     176 *
     177 * @global object $bp BuddyPress global settings
     178 * @param int $activity_id Activity id to be deleted. Defaults to 0.
     179 * @return bool False on failure
     180 * @since 1.6
     181 */
     182function bp_activity_action_spam_activity( $activity_id = 0 ) {
     183    global $bp;
     184
     185    // Not viewing activity, or action is not spam, or Akismet isn't present
     186    if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )
     187        return false;
     188
     189    if ( empty( $activity_id ) && bp_action_variable( 0 ) )
     190        $activity_id = (int) bp_action_variable( 0 );
     191
     192    // Not viewing a specific activity item
     193    if ( empty( $activity_id ) )
     194        return false;
     195
     196    // Is the current user allowed to spam items?
     197    if ( !BP_Akismet::user_can_mark_spam() )
     198        return false;
     199
     200    // Load up the activity item
     201    $activity = new BP_Activity_Activity( $activity_id );
     202    if ( empty( $activity->id ) )
     203        return false;
     204
     205    // Check nonce
     206    check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
     207
     208    // Call an action before the spamming so plugins can modify things if they want to
     209    do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
     210
     211    // Mark as spam
     212    $bp->activity->akismet->mark_as_spam( $activity );
     213    $activity->save();
     214
     215    // Tell the user the spamming has been succesful
     216    bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) );
     217
     218    do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id );
     219
     220    // Check for the redirect query arg, otherwise let WP handle things
     221    if ( !empty( $_GET['redirect_to'] ) )
     222        bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
     223    else
     224        bp_core_redirect( wp_get_referer() );
     225}
     226add_action( 'bp_actions', 'bp_activity_action_spam_activity' );
    173227
    174228/**
     
    535589add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
    536590
     591
     592/**
     593 * Loads Akismet
     594 *
     595 * @global object $bp BuddyPress global settings
     596 * @since 1.6
     597 */
     598function bp_activity_setup_akismet() {
     599    global $bp;
     600
     601    $akismet_key = bp_get_option( 'wordpress_api_key' );
     602
     603    // Load Akismet support if Akismet is configured
     604    if ( !defined( 'AKISMET_VERSION' ) || ( empty( $akismet_key ) && !defined( 'WPCOM_API_KEY' ) ) )
     605        return;
     606
     607    // Instantiate Akismet for BuddyPress
     608    $bp->activity->akismet = new BP_Akismet();
     609}
    537610?>
  • trunk/bp-activity/bp-activity-classes.php

    r5109 r5259  
    11<?php
    2 
    32/**
    43 * BuddyPress Activity Classes
    54 *
    65 * @package BuddyPress
    7  * @subpackage ActivityClasses
     6 * @subpackage Activity
    87 */
    98
     
    2524    var $mptt_left;
    2625    var $mptt_right;
    27 
    28     function bp_activity_activity( $id = false ) {
    29         $this->__construct( $id );
    30     }
     26    var $is_spam;
    3127
    3228    function __construct( $id = false ) {
    33         global $bp;
    34 
    3529        if ( !empty( $id ) ) {
    3630            $this->id = $id;
     
    5650            $this->mptt_left         = $row->mptt_left;
    5751            $this->mptt_right        = $row->mptt_right;
     52            $this->is_spam           = $row->is_spam;
    5853        }
    5954    }
     
    7570        $this->mptt_left         = apply_filters_ref_array( 'bp_activity_mptt_left_before_save',         array( $this->mptt_left,         &$this ) );
    7671        $this->mptt_right        = apply_filters_ref_array( 'bp_activity_mptt_right_before_save',        array( $this->mptt_right,        &$this ) );
     72        $this->is_spam           = apply_filters_ref_array( 'bp_activity_is_spam_before_save',           array( $this->is_spam,           &$this ) );
    7773
    7874        // Use this, not the filters above
     
    8783        // If we have an existing ID, update the activity item, otherwise insert it.
    8884        if ( $this->id )
    89             $q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id );
    90         else
    91             $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );
     85            $q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %s, secondary_item_id = %s, hide_sitewide = %d, is_spam = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->is_spam, $this->id );
     86        else
     87            $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide, is_spam ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->is_spam );
    9288
    9389        if ( !$wpdb->query( $q ) )
     
    10399
    104100    // Static Functions
    105 
    106     function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false, $exclude = false, $in = false ) {
     101    function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false, $exclude = false, $in = false, $hide_spam = true ) {
    107102        global $wpdb, $bp;
    108103
     
    114109        // Where conditions
    115110        $where_conditions = array();
     111
     112        // Spam
     113        if ( $hide_spam )
     114            $where_conditions['spam_sql'] = 'a.is_spam = 0';
    116115
    117116        // Searching
     
    192191
    193192        if ( $activities && $display_comments )
    194             $activities = BP_Activity_Activity::append_comments( $activities );
     193            $activities = BP_Activity_Activity::append_comments( $activities, $hide_spam );
    195194
    196195        // If $max is set, only return up to the max results
     
    357356    }
    358357
    359     function append_comments( $activities ) {
     358    /**
     359     * Append activity comments to their associated activity items
     360     *
     361     * @global object $bp Global BuddyPress settings object
     362     * @global wpdb $wpdb WordPress database object
     363     * @param array $activities
     364     * @param bool $hide_spam Optional. Defaults to true (don't retrieve spammed items).
     365     * @return array The updated activities with nested comments
     366     * @since 1.2
     367     */
     368    function append_comments( $activities, $hide_spam = true ) {
    360369        global $bp, $wpdb;
    361370
     
    365374        foreach( (array)$activities as $activity ) {
    366375            if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
    367                 $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
     376                $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $hide_spam );
    368377        }
    369378
     
    376385    }
    377386
    378     function get_activity_comments( $activity_id, $left, $right ) {
     387    /**
     388     * Get activity comments that are associated with a specific activity ID
     389     *
     390     * @global object $bp Global BuddyPress settings object
     391     * @global wpdb $wpdb WordPress database object
     392     * @param int $activity_id Activity ID to fetch comments for
     393     * @param int $left Left-most node boundary
     394     * @param into $right Right-most node boundary
     395     * @param bool $hide_spam Optional. Defaults to true (don't retrieve spammed items).
     396     * @return array The updated activities with nested comments
     397     * @since 1.2
     398     */
     399    function get_activity_comments( $activity_id, $left, $right, $hide_spam = true ) {
    379400        global $wpdb, $bp;
    380401
     
    391412            }
    392413
     414            // Don't retrieve activity comments marked as spam
     415            if ( $hide_spam )
     416                $spam_sql = 'AND a.is_spam = 0';
     417            else
     418                $spam_sql = '';
     419
     420            $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' ${spam_sql} AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ), $activity_id, $left, $right, $hide_spam );
     421
    393422            // Retrieve all descendants of the $root node
    394             $descendants = $wpdb->get_results( apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ), $activity_id, $left, $right ) );
     423            $descendants = $wpdb->get_results( $sql );
    395424
    396425            // Loop descendants and build an assoc array
  • trunk/bp-activity/bp-activity-filters.php

    r5109 r5259  
    145145 */
    146146function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
     147    if ( $activity_id & bp_is_active( 'activity' ) ) {
     148        $activity = new BP_Activity_Activity( $activity_id );
     149       
     150        // If this activity has been marked as spam, don't do anything. This prevents @notifications being sent.
     151        if ( !empty( $activity ) && $activity->is_spam )
     152            return $content;
     153    }
     154
    147155    $usernames = bp_activity_find_mentions( $content );
    148 
    149156    foreach( (array)$usernames as $username ) {
    150157        if ( bp_is_username_compatibility_mode() )
  • trunk/bp-activity/bp-activity-functions.php

    r5109 r5259  
    702702        'exclude'          => false,  // Comma-separated list of activity IDs to exclude
    703703        'in'               => false,  // Comma-separated list or array of activity IDs to which you want to limit the query
     704        'hide_spam'        => true,   // Don't retrieve items marked as spam?
    704705
    705706        /**
     
    721722    if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort && empty( $exclude ) ) {
    722723        if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
    723             $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
     724            $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden, false, false, $hide_spam );
    724725            wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
    725726        }
    726     } else
    727         $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden, $exclude, $in );
     727
     728    } else {
     729        $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden, $exclude, $in, $hide_spam );
     730    }
    728731
    729732    return apply_filters_ref_array( 'bp_activity_get', array( &$activity, &$r ) );
     
    746749    $defaults = array(
    747750        'activity_ids'     => false,  // A single activity_id or array of IDs.
     751        'display_comments' => false,  // true or false to display threaded comments for these specific activity items
     752        'hide_spam'        => false,  // Retrieve items marked as spam
     753        'max'              => false,  // Maximum number of results to return
    748754        'page'             => 1,      // page 1 without a per_page will result in no pagination.
    749755        'per_page'         => false,  // results per page
    750         'max'              => false,  // Maximum number of results to return
     756        'show_hidden'      => true,   // When fetching specific items, show all
    751757        'sort'             => 'DESC', // sort ASC or DESC
    752         'display_comments' => false,  // true or false to display threaded comments for these specific activity items
    753         'show_hidden'      => true    // When fetching specific items, show all
    754758    );
    755759    $r = wp_parse_args( $args, $defaults );
    756760    extract( $r, EXTR_SKIP );
    757761
    758     return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, $show_hidden, false, $activity_ids ) );
     762    return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, $show_hidden, false, $activity_ids, $hide_spam ) );
    759763}
    760764
     
    792796        'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
    793797        'recorded_time'     => bp_core_current_time(), // The GMT time that this activity was recorded
    794         'hide_sitewide'     => false  // Should this be hidden on the sitewide activity stream?
     798        'hide_sitewide'     => false, // Should this be hidden on the sitewide activity stream?
     799        'is_spam'           => false, // Is this activity item to be marked as spam?
    795800    );
    796801    $params = wp_parse_args( $args, $defaults );
     
    816821    $activity->date_recorded     = $recorded_time;
    817822    $activity->hide_sitewide     = $hide_sitewide;
     823    $activity->is_spam           = $is_spam;
    818824
    819825    if ( !$activity->save() )
  • trunk/bp-activity/bp-activity-loader.php

    r5109 r5259  
    2525     * @since 1.5.0
    2626     */
    27     function BP_Activity_Component() {
    28         $this->__construct();
    29     }
    30 
    3127    function __construct() {
    3228        parent::start(
     
    5349            'notifications',
    5450        );
     51
     52        // Load Akismet support if Akismet is configured
     53        $akismet_key = bp_get_option( 'wordpress_api_key' );
     54        if ( defined( 'AKISMET_VERSION' ) && ( !empty( $akismet_key ) || defined( 'WPCOM_API_KEY' ) ) )
     55            $includes[] = 'akismet';
    5556
    5657        parent::includes( $includes );
     
    308309        parent::setup_title();
    309310    }
     311
     312    /**
     313     * Setup the actions
     314     *
     315     * @since 1.6
     316     */
     317     function setup_actions() {
     318        // Spam prevention
     319        add_action( 'bp_include', 'bp_activity_setup_akismet' );
     320
     321        parent::setup_actions();
     322    }
    310323}
    311324
    312325// Create the activity component
    313326$bp->activity = new BP_Activity_Component();
    314 
    315327?>
  • trunk/bp-activity/bp-activity-screens.php

    r5109 r5259  
    195195
    196196    // Get the activity details
    197     $activity = bp_activity_get_specific( array( 'activity_ids' => bp_current_action(), 'show_hidden' => true ) );
     197    $activity = bp_activity_get_specific( array( 'activity_ids' => bp_current_action(), 'hide_spam' => true, 'show_hidden' => true ) );
    198198
    199199    // 404 if activity does not exist
  • trunk/bp-activity/bp-activity-template.php

    r5258 r5259  
    105105    var $full_name;
    106106
    107     function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude = false, $in = false ) {
    108         $this->__construct( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude, $in );
    109     }
    110 
    111     function __construct( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude = false, $in = false ) {
     107    function __construct( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude = false, $in = false, $hide_spam = true ) {
    112108        global $bp;
    113109
     
    123119        // Fetch specific activity items based on ID's
    124120        if ( !empty( $include ) )
    125             $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden ) );
     121            $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden, 'hide_spam' => $hide_spam ) );
     122
    126123        // Fetch all activity items
    127124        else
    128             $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in ) );
     125            $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'hide_spam' => $hide_spam ) );
    129126
    130127        if ( !$max || $max >= (int)$this->activities['total'] )
     
    302299        'max'              => false,        // max number to return
    303300        'show_hidden'      => $show_hidden, // Show activity items that are hidden site-wide?
     301        'hide_spam'        => true,         // Don't retrieve items marked as spam?
    304302
    305303        // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions)
     
    385383        $filter = false;
    386384
    387     $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude, $in );
     385    // If specific activity items have been requested, override the $hide_spam argument. This prevents backpat errors with AJAX.
     386    if ( !empty( $include ) && $hide_spam )
     387        $hide_spam = false;
     388
     389    $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude, $in, $hide_spam );
    388390
    389391    return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template );
  • trunk/bp-core/admin/bp-core-schema.php

    r4820 r5259  
    4949
    5050    $sql[] = "CREATE TABLE {$bp_prefix}bp_activity (
    51                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     51                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    5252                user_id bigint(20) NOT NULL,
    5353                component varchar(75) NOT NULL,
     
    6262                mptt_left int(11) NOT NULL DEFAULT 0,
    6363                mptt_right int(11) NOT NULL DEFAULT 0,
     64                is_spam tinyint(1) NOT NULL DEFAULT 0,
    6465                KEY date_recorded (date_recorded),
    6566                KEY user_id (user_id),
     
    7071                KEY mptt_left (mptt_left),
    7172                KEY mptt_right (mptt_right),
    72                 KEY hide_sitewide (hide_sitewide)
    73                ) {$charset_collate};";
     73                KEY hide_sitewide (hide_sitewide),
     74                KEY is_spam (is_spam)
     75            ) {$charset_collate};";
    7476
    7577    $sql[] = "CREATE TABLE {$bp_prefix}bp_activity_meta (
  • trunk/bp-loader.php

    r5223 r5259  
    2222// Define the database version
    2323if ( !defined( 'BP_DB_VERSION' ) )
    24     define( 'BP_DB_VERSION', 5222 );
     24    define( 'BP_DB_VERSION', 5249 );
    2525
    2626// Place your custom code (actions/filters) in a file called
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r5095 r5259  
    223223
    224224    // Load the new activity item into the $activities_template global
    225     bp_has_activities( 'display_comments=stream&include=' . $comment_id );
     225    bp_has_activities( 'display_comments=stream&hide_spam=false&include=' . $comment_id );
    226226
    227227    // Swap the current comment with the activity item we just loaded
     
    317317}
    318318add_action( 'wp_ajax_delete_activity_comment', 'bp_dtheme_delete_activity_comment' );
     319
     320/**
     321 * AJAX spam an activity item or an activity comment
     322 *
     323 * @global object $bp BuddyPress global settings
     324 * @since 1.6
     325 */
     326function bp_dtheme_spam_activity() {
     327    global $bp;
     328
     329    // Check that user is logged in, Activity Streams are enabled, and Akismet is present.
     330    if ( !is_user_logged_in() || !bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) ) {
     331        echo '-1';
     332        return false;
     333    }
     334
     335    // Check an item ID was passed
     336    if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) ) {
     337        echo '-1';
     338        return false;
     339    }
     340
     341    // Is the current user allowed to spam items?
     342    if ( !BP_Akismet::user_can_mark_spam() )
     343        return false;
     344
     345    // Load up the activity item
     346    $activity = new BP_Activity_Activity( (int) $_POST['id'] );
     347    if ( empty( $activity->id ) ) {
     348        echo '-1';
     349        return false;
     350    }
     351
     352    // Check nonce
     353    check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
     354
     355    // Call an action before the spamming so plugins can modify things if they want to
     356    do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
     357
     358    // Mark as spam
     359    $bp->activity->akismet->mark_as_spam( $activity );
     360    $activity->save();
     361
     362    do_action( 'bp_activity_action_spam_activity', $activity->id, $activity->user_id );
     363    return true;
     364}
     365add_action( 'wp_ajax_spam_activity',         'bp_dtheme_spam_activity' );
     366add_action( 'wp_ajax_spam_activity_comment', 'bp_dtheme_spam_activity' );
    319367
    320368/* AJAX mark an activity as a favorite */
  • trunk/bp-themes/bp-default/_inc/global.js

    r4961 r5259  
    6969            'content': content,
    7070            'object': object,
    71             'item_id': item_id
     71            'item_id': item_id,
     72            '_bp_as_nonce': jq('#_bp_as_nonce').val() || ''
    7273        },
    7374        function(response) {
     
    248249        }
    249250
     251        // Spam activity stream items
     252        if ( target.hasClass( 'spam-activity' ) ) {
     253            var li = target.parents( 'div.activity ul li' );
     254            target.addClass( 'loading' );
     255
     256            jq.post( ajaxurl, {
     257                action: 'spam_activity',
     258                'cookie': encodeURIComponent( document.cookie ),
     259                'id': li.attr( 'id' ).substr( 9, li.attr( 'id' ).length ),
     260                '_wpnonce': target.attr( 'href' ).split( '_wpnonce=' )[1]
     261            },
     262
     263            function(response) {
     264                if ( response[0] + response[1] === '-1' ) {
     265                    li.prepend( response.substr( 2, response.length ) );
     266                    li.children( 'div#message' ).hide().fadeIn(300);
     267                } else {
     268                    li.slideUp( 300 );
     269                }
     270            });
     271
     272            return false;
     273        }
     274
    250275        /* Load more updates at the end of the page */
    251276        if ( target.parent().hasClass('load-more') ) {
     
    365390            target.addClass('loading').prop('disabled', true);
    366391
    367             jq.post( ajaxurl, {
     392            var ajaxdata = {
    368393                action: 'new_activity_comment',
    369394                'cookie': encodeURIComponent(document.cookie),
     
    372397                'form_id': form_id[2],
    373398                'content': jq('form#' + form.attr('id') + ' textarea').val()
    374             },
     399            };
     400
     401            // Akismet
     402            var ak_nonce = jq('#_bp_as_nonce_' + comment_id).val();
     403            if ( ak_nonce ) {
     404                ajaxdata['_bp_as_nonce_' + comment_id] = ak_nonce;
     405            }
     406
     407            jq.post( ajaxurl, ajaxdata,
    375408            function(response)
    376409            {
     
    457490        }
    458491
     492        // Spam an activity stream comment
     493        if ( target.hasClass( 'spam-activity-comment' ) ) {
     494            var link_href  = target.attr( 'href' );
     495            var comment_li = target.parent().parent();
     496
     497            target.addClass('loading');
     498
     499            // Remove any error messages
     500            jq( 'div.activity-comments ul div.error' ).remove();
     501
     502            // Reset the form position
     503            comment_li.parents( 'div.activity-comments' ).append( comment_li.parents( 'div.activity-comments' ).children( 'form' ) );
     504
     505            jq.post( ajaxurl, {
     506                action: 'spam_activity_comment',
     507                'cookie': encodeURIComponent( document.cookie ),
     508                '_wpnonce': link_href.split( '_wpnonce=' )[1],
     509                'id': link_href.split( 'cid=' )[1].split( '&' )[0]
     510            },
     511
     512            function ( response ) {
     513                // Check for errors and append if found.
     514                if ( response[0] + response[1] == '-1' ) {
     515                    comment_li.prepend( response.substr( 2, response.length ) ).hide().fadeIn( 200 );
     516
     517                } else {
     518                    var children = jq( 'li#' + comment_li.attr( 'id' ) + ' ul' ).children( 'li' );
     519                    var child_count = 0;
     520                    jq(children).each( function() {
     521                        if ( !jq( this ).is( ':hidden' ) ) {
     522                            child_count++;
     523                        }
     524                    });
     525                    comment_li.fadeOut( 200 );
     526
     527                    // Decrease the "Reply (X)" button count
     528                    var parent_li = comment_li.parents( 'ul#activity-stream > li' );
     529                    jq( 'li#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html( jq( 'li#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html() - ( 1 + child_count ) );
     530                }
     531            });
     532
     533            return false;
     534        }
     535
    459536        /* Showing hidden comments - pause for half a second */
    460537        if ( target.parent().hasClass('show-all') ) {
  • trunk/bp-themes/bp-default/functions.php

    r5251 r5259  
    140140function bp_dtheme_enqueue_scripts() {
    141141    // Bump this when changes are made to bust cache
    142     $version = '20110921';
     142    $version = '20111023';
    143143
    144144    // Enqueue the global JS - Ajax will not work without it
Note: See TracChangeset for help on using the changeset viewer.