Changeset 1021 for trunk/bp-activity/bp-activity-classes.php
- Timestamp:
- 02/06/2009 03:07:48 AM (17 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
r909 r1021 31 31 global $wpdb, $bp; 32 32 33 $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $this->table_name . "WHERE id = %d", $this->id ) );33 $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE id = %d", $this->id ) ); 34 34 35 35 $this->item_id = $activity->item_id; … … 55 55 if ( !$this->exists() ) { 56 56 // Insert the new activity into the activity table. 57 $activity = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $this->table_name . "( item_id, secondary_item_id, user_id, component_name, component_action, date_recorded, is_private, no_sitewide_cache ) VALUES ( %d, %d, %d, %s, %s, FROM_UNIXTIME(%d), %d, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_recorded, $this->is_private, $this->no_sitewide_cache ) );57 $activity = $wpdb->query( $wpdb->prepare( "INSERT INTO {$this->table_name} ( item_id, secondary_item_id, user_id, component_name, component_action, date_recorded, is_private, no_sitewide_cache ) VALUES ( %d, %d, %d, %s, %s, FROM_UNIXTIME(%d), %d, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_recorded, $this->is_private, $this->no_sitewide_cache ) ); 58 58 59 59 // Fetch the formatted activity content so we can add it to the cache. 60 if ( function_exists( $bp [$this->component_name]['format_activity_function']) ) {61 if ( !$activity_content = call_user_func( $bp[$this->component_name]['format_activity_function'], $this->item_id, $this->user_id, $this->component_action, $this->secondary_item_id, $this->for_secondary_user ) )60 if ( function_exists( $bp->{$this->component_name}->format_activity_function ) ) { 61 if ( !$activity_content = call_user_func( $bp->{$this->component_name}->format_activity_function, $this->item_id, $this->user_id, $this->component_action, $this->secondary_item_id, $this->for_secondary_user ) ) 62 62 return false; 63 63 } 64 64 65 65 // Add the cached version of the activity to the cached activity table. 66 $activity_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $this->table_name_cached . "( item_id, secondary_item_id, content, primary_link, component_name, component_action, date_cached, date_recorded, is_private ) VALUES ( %d, %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $activity_content['content'], $activity_content['primary_link'], $this->component_name, $this->component_action, time(), $this->date_recorded, $this->is_private ) );66 $activity_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO {$this->table_name_cached} ( item_id, secondary_item_id, content, primary_link, component_name, component_action, date_cached, date_recorded, is_private ) VALUES ( %d, %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $activity_content['content'], $activity_content['primary_link'], $this->component_name, $this->component_action, time(), $this->date_recorded, $this->is_private ) ); 67 67 68 68 // Add the cached version of the activity to the sitewide activity table. 69 69 if ( !$this->no_sitewide_cache ) 70 $sitewide_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['activity']['table_name_sitewide'] . "( user_id, item_id, secondary_item_id, content, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %d, %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d) )", $this->user_id, $this->item_id, $this->secondary_item_id, $activity_content['content'], $activity_content['primary_link'], $this->component_name, $this->component_action, time(), $this->date_recorded ) );70 $sitewide_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name_sitewide} ( user_id, item_id, secondary_item_id, content, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %d, %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d) )", $this->user_id, $this->item_id, $this->secondary_item_id, $activity_content['content'], $activity_content['primary_link'], $this->component_name, $this->component_action, time(), $this->date_recorded ) ); 71 71 72 72 if ( $activity && $activity_cached ) … … 79 79 function exists() { 80 80 global $wpdb, $bp; 81 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM " . $this->table_name . "WHERE item_id = %d AND secondary_item_id = %d AND user_id = %d AND component_name = %s AND component_action = %s", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action ) );81 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$this->table_name} WHERE item_id = %d AND secondary_item_id = %d AND user_id = %d AND component_name = %s AND component_action = %s", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action ) ); 82 82 } 83 83 … … 90 90 return false; 91 91 92 if ( !$bp ['activity'])92 if ( !$bp->activity ) 93 93 bp_activity_setup_globals(); 94 94 … … 98 98 //error_log($wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) ); 99 99 //error_log($wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d{$secondary_sql} AND component_name = %s AND component_action = %s", $item_id, $component_name, $component_action ) ); 100 //error_log($wpdb->prepare( "DELETE FROM " . $bp ['activity']['table_name_sitewide']. " WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );100 //error_log($wpdb->prepare( "DELETE FROM " . $bp->activity->table_name_sitewide . " WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) ); 101 101 102 102 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) ); … … 104 104 // Delete this entry from the users' cache table and the sitewide cache table 105 105 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d{$secondary_sql} AND component_name = %s AND component_action = %s", $item_id, $component_name, $component_action ) ); 106 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['activity']['table_name_sitewide'] . "WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );106 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_sitewide} WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) ); 107 107 108 108 return true; … … 113 113 114 114 if ( !$user_id ) 115 $user_id = $bp ['current_userid'];115 $user_id = $bp->displayed_user->id; 116 116 117 117 if ( !$user_id ) … … 127 127 128 128 /* Determine whether or not to use the cached activity stream, or re-select and cache a new stream */ 129 $last_cached = get_usermeta( $bp ['current_userid'], 'bp_activity_last_cached' );129 $last_cached = get_usermeta( $bp->displayed_user->id, 'bp_activity_last_cached' ); 130 130 131 131 if ( strtotime( BP_ACTIVITY_CACHE_LENGTH, (int)$last_cached ) >= time() ) { … … 134 134 135 135 // Use the cached activity stream. 136 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_current_user_cached'] . "WHERE date_recorded >= FROM_UNIXTIME(%d) $privacy_sql ORDER BY date_recorded DESC $limit_sql", $since ) );136 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_current_user_cached} WHERE date_recorded >= FROM_UNIXTIME(%d) $privacy_sql ORDER BY date_recorded DESC $limit_sql", $since ) ); 137 137 138 138 for ( $i = 0; $i < count( $activities ); $i++ ) { … … 152 152 153 153 // Reselect, format and cache a new activity stream. Override the limit otherwise we might only cache 5 items when viewing a profile page. 154 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_current_user'] . "WHERE date_recorded >= FROM_UNIXTIME(%d) $privacy_sql ORDER BY date_recorded DESC LIMIT 30", $since ) );154 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_current_user} WHERE date_recorded >= FROM_UNIXTIME(%d) $privacy_sql ORDER BY date_recorded DESC LIMIT 30", $since ) ); 155 155 156 156 for ( $i = 0; $i < count( $activities ); $i++ ) { 157 if ( function_exists( $bp [$activities[$i]->component_name]['format_activity_function']) ) {158 if ( !$content = call_user_func( $bp[$activities[$i]->component_name]['format_activity_function'], $activities[$i]->item_id, $activities[$i]->user_id, $activities[$i]->component_action, $activities[$i]->secondary_item_id ) )157 if ( function_exists( $bp->{$activities[$i]->component_name}->format_activity_function ) ) { 158 if ( !$content = call_user_func( $bp->{$activities[$i]->component_name}->format_activity_function, $activities[$i]->item_id, $activities[$i]->user_id, $activities[$i]->component_action, $activities[$i]->secondary_item_id ) ) 159 159 continue; 160 160 … … 199 199 200 200 /* Determine whether or not to use the cached friends activity stream, or re-select and cache a new stream */ 201 $last_cached = get_usermeta( $bp ['loggedin_userid'], 'bp_activity_friends_last_cached' );201 $last_cached = get_usermeta( $bp->loggedin_user->id, 'bp_activity_friends_last_cached' ); 202 202 203 203 if ( strtotime( BP_ACTIVITY_CACHE_LENGTH, (int)$last_cached ) >= time() ) { … … 206 206 207 207 // Use the cached activity stream. 208 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_loggedin_user_friends_cached'] . "ORDER BY date_recorded DESC $limit_sql" ) );208 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_loggedin_user_friends_cached} ORDER BY date_recorded DESC $limit_sql" ) ); 209 209 210 210 for ( $i = 0; $i < count( $activities ); $i++ ) { … … 231 231 $table_name = $wpdb->base_prefix . 'user_' . $friend_ids[$i] . '_activity_cached'; 232 232 233 $activities[$i]['activity'] = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $table_name . "WHERE is_private = 0 ORDER BY date_recorded $limit_sql" ) );233 $activities[$i]['activity'] = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE is_private = 0 ORDER BY date_recorded $limit_sql" ) ); 234 234 $activities[$i]['full_name'] = bp_fetch_user_fullname( $friend_ids[$i], false ); 235 235 } … … 265 265 266 266 /* Remove entries that are older than 6 months */ 267 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp ['activity']['table_name_sitewide']. " WHERE DATE_ADD(date_recorded, INTERVAL 6 MONTH) <= NOW()" ) );268 269 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp ['activity']['table_name_sitewide']. " ORDER BY date_recorded DESC $limit_sql" ) );267 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->activity->table_name_sitewide . " WHERE DATE_ADD(date_recorded, INTERVAL 6 MONTH) <= NOW()" ) ); 268 269 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp->activity->table_name_sitewide . " ORDER BY date_recorded DESC $limit_sql" ) ); 270 270 271 271 for ( $i = 0; $i < count( $activities ); $i++ ) { … … 289 289 $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) ); 290 290 $activity_feed[$i]['link'] = $activities[$i]['primary_link']; 291 $activity_feed[$i]['description'] = sprintf ( $activities[$i]['content'], '' );291 $activity_feed[$i]['description'] = sprintf( $activities[$i]['content'], '' ); 292 292 $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded']; 293 293 } … … 300 300 301 301 /* Empty the cache */ 302 $wpdb->query( "TRUNCATE TABLE " . $bp['activity']['table_name_loggedin_user_friends_cached']);302 $wpdb->query( "TRUNCATE TABLE {$bp->activity->table_name_loggedin_user_friends_cached}" ); 303 303 304 304 for ( $i = 0; $i < count($activity_array); $i++ ) { 305 305 // Cache that sucka... 306 $cached = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['activity']['table_name_loggedin_user_friends_cached'] . "( user_id, content, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s )", $activity_array[$i]['user_id'], $activity_array[$i]['content'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'] ) );307 } 308 309 update_usermeta( $bp ['loggedin_userid'], 'bp_activity_friends_last_cached', time() );306 $cached = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name_loggedin_user_friends_cached} ( user_id, content, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s )", $activity_array[$i]['user_id'], $activity_array[$i]['content'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'] ) ); 307 } 308 309 update_usermeta( $bp->loggedin_user->id, 'bp_activity_friends_last_cached', time() ); 310 310 } 311 311 … … 314 314 315 315 /* Empty the cache */ 316 $wpdb->query( "TRUNCATE TABLE " . $bp['activity']['table_name_current_user_cached']);316 $wpdb->query( "TRUNCATE TABLE {$bp->activity->table_name_current_user_cached}" ); 317 317 318 318 /* Empty user's activities from the sitewide stream */ 319 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp ['activity']['table_name_sitewide']. " WHERE user_id = %d", $user_id ) );319 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->activity->table_name_sitewide . " WHERE user_id = %d", $user_id ) ); 320 320 321 321 for ( $i = 0; $i < count($activity_array); $i++ ) { … … 323 323 324 324 // Cache that sucka... 325 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp ['activity']['table_name_current_user_cached']. " ( content, item_id, secondary_item_id, primary_link, component_name, component_action, date_cached, date_recorded, is_private ) VALUES ( %s, %d, %d, %s, %s, %s, FROM_UNIXTIME(%d), %s, %d )", $activity_array[$i]['content'], $activity_array[$i]['item_id'], $activity_array[$i]['secondary_item_id'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'], $activity_array[$i]['is_private'] ) );325 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp->activity->table_name_current_user_cached . " ( content, item_id, secondary_item_id, primary_link, component_name, component_action, date_cached, date_recorded, is_private ) VALUES ( %s, %d, %d, %s, %s, %s, FROM_UNIXTIME(%d), %s, %d )", $activity_array[$i]['content'], $activity_array[$i]['item_id'], $activity_array[$i]['secondary_item_id'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'], $activity_array[$i]['is_private'] ) ); 326 326 327 327 // Add to the sitewide activity stream 328 328 if ( !$activity_array[$i]['is_private'] && !$activity_array[$i]['no_sitewide_cache'] ) 329 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp ['activity']['table_name_sitewide']. " ( user_id, content, item_id, secondary_item_id, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %s, %d, %d, %s, %s, %s, FROM_UNIXTIME(%d), %s )", $user_id, $activity_array[$i]['content'], $activity_array[$i]['item_id'], $activity_array[$i]['secondary_item_id'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'] ) );330 } 331 332 update_usermeta( $bp ['current_userid'], 'bp_activity_last_cached', time() );329 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp->activity->table_name_sitewide . " ( user_id, content, item_id, secondary_item_id, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %s, %d, %d, %s, %s, %s, FROM_UNIXTIME(%d), %s )", $user_id, $activity_array[$i]['content'], $activity_array[$i]['item_id'], $activity_array[$i]['secondary_item_id'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'] ) ); 330 } 331 332 update_usermeta( $bp->displayed_user->id, 'bp_activity_last_cached', time() ); 333 333 } 334 334 … … 337 337 338 338 /* Empty user's activities from the sitewide stream */ 339 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp ['activity']['table_name_sitewide']. " WHERE user_id = %d", $user_id ) );339 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->activity->table_name_sitewide . " WHERE user_id = %d", $user_id ) ); 340 340 341 341 /* Empty the user's activity items and cached activity items */ … … 349 349 global $bp, $wpdb; 350 350 351 return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM " . $bp ['activity']['table_name_sitewide']. " ORDER BY date_recorded ASC LIMIT 1" ) );351 return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM " . $bp->activity->table_name_sitewide . " ORDER BY date_recorded ASC LIMIT 1" ) ); 352 352 } 353 353
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)