Changeset 2381 for trunk/bp-activity/bp-activity-classes.php
- Timestamp:
- 01/20/2010 04:21:20 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/bp-activity/bp-activity-classes.php (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r2369 r2381 7 7 var $user_id; 8 8 var $primary_link; 9 var $component_name; 10 var $component_action; 9 var $component; 10 var $type; 11 var $action; 12 var $content; 11 13 var $date_recorded; 12 14 var $hide_sitewide = false; … … 24 26 global $wpdb, $bp; 25 27 26 $ activity= $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );28 $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) ); 27 29 28 30 if ( $activity ) { 29 $this->id = $activity->id; 30 $this->item_id = $activity->item_id; 31 $this->secondary_item_id = $activity->secondary_item_id; 32 $this->user_id = $activity->user_id; 33 $this->content = $activity->content; 34 $this->primary_link = $activity->primary_link; 35 $this->component_name = $activity->component_name; 36 $this->component_action = $activity->component_action; 37 $this->date_recorded = $activity->date_recorded; 38 $this->hide_sitewide = $activity->hide_sitewide; 31 $this->id = $row->id; 32 $this->item_id = $row->item_id; 33 $this->secondary_item_id = $row->secondary_item_id; 34 $this->user_id = $row->user_id; 35 $this->primary_link = $row->primary_link; 36 $this->component = $row->component; 37 $this->type = $row->type; 38 $this->action = $row->type; 39 $this->content = $row->content; 40 $this->date_recorded = $row->date_recorded; 41 $this->hide_sitewide = $row->hide_sitewide; 39 42 } 40 43 } … … 45 48 do_action( 'bp_activity_before_save', $this ); 46 49 47 if ( !$this->component _name || !$this->component_action)50 if ( !$this->component || !$this->type ) 48 51 return false; 49 52 … … 53 56 /* If we have an existing ID, update the activity item, otherwise insert it. */ 54 57 if ( $this->id ) 55 $q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component _name = %s, component_action = %s, content = %s, primary_link = %s, date_recorded = FROM_UNIXTIME(%d), item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id );58 $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 = FROM_UNIXTIME(%d), 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 ); 56 59 else 57 $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component _name, component_action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s, %s, %d )", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );60 $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, FROM_UNIXTIME(%d), %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 ); 58 61 59 62 if ( !$wpdb->query( $q ) ) … … 68 71 /* Static Functions */ 69 72 70 function delete( $item_id, $component _name, $component_action, $user_id = false, $secondary_item_id = false ) {73 function delete( $item_id, $component, $type, $user_id = false, $secondary_item_id = false ) { 71 74 global $wpdb, $bp; 72 75 … … 74 77 $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %s", $secondary_item_id ); 75 78 76 if ( $ component_action)77 $ component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action);79 if ( $type ) 80 $type_sql = $wpdb->prepare( "AND type = %s", $type ); 78 81 79 82 if ( $user_id ) … … 81 84 82 85 /* Fetch the activity IDs so we can delete any comments for this activity item */ 83 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component _name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name) );84 85 error_log( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component _name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name) );86 87 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component _name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name) ) )86 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component = %s {$type_sql} {$user_sql}", $item_id, $component ) ); 87 88 error_log( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component = %s {$type_sql} {$user_sql}", $item_id, $component ) ); 89 90 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component = %s {$type_sql} {$user_sql}", $item_id, $component ) ) ) 88 91 return false; 89 92 … … 98 101 } 99 102 100 function delete_by_item_id( $item_id, $component _name, $component_action, $user_id = false, $secondary_item_id = false ) {101 return BP_Activity_Activity::delete( $item_id, $component _name, $component_action, $user_id, $secondary_item_id );103 function delete_by_item_id( $item_id, $component, $type, $user_id = false, $secondary_item_id = false ) { 104 return BP_Activity_Activity::delete( $item_id, $component, $type, $user_id, $secondary_item_id ); 102 105 } 103 106 … … 115 118 } 116 119 117 function delete_by_content( $user_id, $content, $component _name, $component_action) {120 function delete_by_content( $user_id, $content, $component, $type ) { 118 121 global $bp, $wpdb; 119 122 120 123 /* Fetch the activity ID so we can delete any comments for this activity item */ 121 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component _name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action) );122 123 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component _name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action) ) )124 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component = %s AND type = %s", $user_id, $content, $component, $type ) ); 125 126 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component = %s AND type = %s", $user_id, $content, $component, $type ) ) ) 124 127 return false; 125 128 … … 134 137 } 135 138 136 function delete_for_user_by_component( $user_id, $component _name) {139 function delete_for_user_by_component( $user_id, $component ) { 137 140 global $bp, $wpdb; 138 141 139 142 /* Fetch the activity IDs so we can delete any comments for this activity item */ 140 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND component _name = %s", $user_id, $component_name) );141 142 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component _name = %s", $user_id, $component_name) ) )143 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND component = %s", $user_id, $component ) ); 144 145 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component = %s", $user_id, $component ) ) ) 143 146 return false; 144 147 … … 178 181 $activity_ids = $wpdb->escape( $activity_ids ); 179 182 180 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE component_action= 'activity_comment' AND item_id IN ({$activity_ids})" ) );183 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ) ); 181 184 } 182 185 … … 238 241 /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */ 239 242 if ( !$display_comments || 'threaded' == $display_comments ) { 240 $where_conditions[] = "a. component_action!= 'activity_comment'";243 $where_conditions[] = "a.type != 'activity_comment'"; 241 244 } 242 245 … … 268 271 $activity_ids = $wpdb->escape( $activity_ids ); 269 272 273 if ( empty( $activity_ids ) ) 274 return false; 275 270 276 if ( $per_page && $page ) 271 277 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) ); … … 294 300 /* Now fetch the activity comments and parse them into the correct position in the activities array. */ 295 301 foreach( $activities as $activity ) { 296 if ( 'activity_comment' != $activity-> component_action&& $activity->mptt_left && $activity->mptt_right )302 if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right ) 297 303 $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right ); 298 304 } … … 320 326 } 321 327 322 $descendants = $wpdb->get_results( $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. component_action= '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 ) );328 $descendants = $wpdb->get_results( $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 ) ); 323 329 324 330 /* Loop descendants and build an assoc array */ … … 348 354 349 355 /* Get all descendants of this node */ 350 $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE component_action= 'activity_comment' AND secondary_item_id = %d", $parent_id ) );356 $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) ); 351 357 352 358 /* Loop the descendants and recalculate the left and right values */ … … 358 364 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) ); 359 365 else 360 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE component_action= 'activity_comment' AND id = %d", $left, $right, $parent_id ) );366 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) ); 361 367 362 368 /* Return the right value of this node + 1 */ … … 364 370 } 365 371 366 function get_recorded_component _names() {367 global $wpdb, $bp; 368 369 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component _name FROM {$bp->activity->table_name} ORDER BY component_nameASC" ) );372 function get_recorded_components() { 373 global $wpdb, $bp; 374 375 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component FROM {$bp->activity->table_name} ORDER BY component ASC" ) ); 370 376 } 371 377 … … 414 420 $counter = 1; 415 421 foreach( (array) $object_filter as $object ) { 416 $object_sql .= $wpdb->prepare( "a.component _name= %s", trim( $object ) );422 $object_sql .= $wpdb->prepare( "a.component = %s", trim( $object ) ); 417 423 418 424 if ( $counter != count( $object_filter ) ) … … 432 438 $counter = 1; 433 439 foreach( (array) $action_filter as $action ) { 434 $action_sql .= $wpdb->prepare( "a. component_action= %s", trim( $action ) );440 $action_sql .= $wpdb->prepare( "a.type = %s", trim( $action ) ); 435 441 436 442 if ( $counter != count( $action_filter ) )
Note: See TracChangeset
for help on using the changeset viewer.