Changeset 375 for trunk/bp-activity/bp-activity-classes.php
- Timestamp:
- 10/09/2008 04:37:49 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r364 r375 67 67 $activity_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $this->table_name_cached . " ( content, component_name, date_cached, date_recorded, is_private ) VALUES ( %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d), %d )", $activity_content, $this->component_name, time(), $this->date_recorded, $this->is_private ) ); 68 68 69 // Add the cached version of the activity to the cached activity table. 70 $sitewide_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['activity']['table_name_sitewide'] . " ( user_id, content, component_name, date_cached, date_recorded ) VALUES ( %d, %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d) )", $bp['loggedin_userid'], $activity_content, $this->component_name, time(), $this->date_recorded ) ); 71 69 72 if ( $activity && $activity_cached ) 70 73 return true; … … 104 107 $last_cached = get_usermeta( $bp['current_userid'], 'bp_activity_last_cached' ); 105 108 106 if ( strtotime( BP_ACTIVITY_CACHE_LENGTH, (int)$last_cached ) >= time() ) {109 if ( strtotime( BP_ACTIVITY_CACHE_LENGTH, (int)$last_cached ) <= time() ) { 107 110 108 111 //echo '<small style="color: green">** Debug: Using Cache **</small>'; … … 140 143 unset($activities_formatted[$i]); 141 144 } 142 145 143 146 if ( count($activities_formatted) ) 144 BP_Activity_Activity::cache_activities( $activities_formatted );147 BP_Activity_Activity::cache_activities( $activities_formatted, $user_id ); 145 148 } 146 149 … … 209 212 } 210 213 214 function get_sitewide_activity( $limit = 15 ) { 215 global $wpdb, $bp; 216 217 if ( $limit ) 218 $limit_sql = $wpdb->prepare( " LIMIT %d", $limit ); 219 220 /* Remove entries that are older than 1 week */ 221 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['activity']['table_name_sitewide'] . " WHERE DATE_ADD(date_recorded, INTERVAL 1 WEEK) <= NOW()" ) ); 222 223 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_sitewide'] . " ORDER BY date_recorded DESC $limit_sql" ) ); 224 225 for ( $i = 0; $i < count( $activities ); $i++ ) { 226 $activities_formatted[$i]['content'] = $activities[$i]->content; 227 $activities_formatted[$i]['date_recorded'] = $activities[$i]->date_recorded; 228 $activities_formatted[$i]['component_name'] = $activities[$i]->component_name; 229 } 230 231 return $activities_formatted; 232 } 233 211 234 function cache_friends_activities( $activity_array ) { 212 235 global $wpdb, $bp; … … 223 246 } 224 247 225 function cache_activities( $activity_array ) {248 function cache_activities( $activity_array, $user_id ) { 226 249 global $wpdb, $bp; 227 250 … … 229 252 $wpdb->query( "TRUNCATE TABLE " . $bp['activity']['table_name_current_user_cached'] ); 230 253 254 /* Empty user's activities from the sitewide stream */ 255 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['activity']['table_name_sitewide'] . " WHERE user_id = %d", $user_id ) ); 256 231 257 for ( $i = 0; $i < count($activity_array); $i++ ) { 258 if ( $activity_array[$i]['content'] == '' ) continue; 259 232 260 // Cache that sucka... 233 261 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['activity']['table_name_current_user_cached'] . " ( content, component_name, date_cached, date_recorded, is_private ) VALUES ( %s, %s, FROM_UNIXTIME(%d), %s, %d )", $activity_array[$i]['content'], $activity_array[$i]['component_name'], time(), $activity_array[$i]['date_recorded'], $activity_array[$i]['is_private'] ) ); 262 263 // Add to the sitewide activity stream 264 if ( !$activity_array[$i]['is_private'] ) 265 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['activity']['table_name_sitewide'] . " ( user_id, content, component_name, date_cached, date_recorded ) VALUES ( %d, %s, %s, FROM_UNIXTIME(%d), %s )", $user_id, $activity_array[$i]['content'], $activity_array[$i]['component_name'], time(), $activity_array[$i]['date_recorded'] ) ); 234 266 } 235 267
Note: See TracChangeset
for help on using the changeset viewer.