Changeset 5259 for trunk/bp-activity/bp-activity-classes.php
- Timestamp:
- 10/24/2011 02:00:04 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r5109 r5259 1 1 <?php 2 3 2 /** 4 3 * BuddyPress Activity Classes 5 4 * 6 5 * @package BuddyPress 7 * @subpackage Activity Classes6 * @subpackage Activity 8 7 */ 9 8 … … 25 24 var $mptt_left; 26 25 var $mptt_right; 27 28 function bp_activity_activity( $id = false ) { 29 $this->__construct( $id ); 30 } 26 var $is_spam; 31 27 32 28 function __construct( $id = false ) { 33 global $bp;34 35 29 if ( !empty( $id ) ) { 36 30 $this->id = $id; … … 56 50 $this->mptt_left = $row->mptt_left; 57 51 $this->mptt_right = $row->mptt_right; 52 $this->is_spam = $row->is_spam; 58 53 } 59 54 } … … 75 70 $this->mptt_left = apply_filters_ref_array( 'bp_activity_mptt_left_before_save', array( $this->mptt_left, &$this ) ); 76 71 $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 ) ); 77 73 78 74 // Use this, not the filters above … … 87 83 // If we have an existing ID, update the activity item, otherwise insert it. 88 84 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 ); 92 88 93 89 if ( !$wpdb->query( $q ) ) … … 103 99 104 100 // 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 ) { 107 102 global $wpdb, $bp; 108 103 … … 114 109 // Where conditions 115 110 $where_conditions = array(); 111 112 // Spam 113 if ( $hide_spam ) 114 $where_conditions['spam_sql'] = 'a.is_spam = 0'; 116 115 117 116 // Searching … … 192 191 193 192 if ( $activities && $display_comments ) 194 $activities = BP_Activity_Activity::append_comments( $activities );193 $activities = BP_Activity_Activity::append_comments( $activities, $hide_spam ); 195 194 196 195 // If $max is set, only return up to the max results … … 357 356 } 358 357 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 ) { 360 369 global $bp, $wpdb; 361 370 … … 365 374 foreach( (array)$activities as $activity ) { 366 375 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 ); 368 377 } 369 378 … … 376 385 } 377 386 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 ) { 379 400 global $wpdb, $bp; 380 401 … … 391 412 } 392 413 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 393 422 // 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 ); 395 424 396 425 // Loop descendants and build an assoc array
Note: See TracChangeset
for help on using the changeset viewer.