Skip to:
Content

BuddyPress.org


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.