Changeset 2077 for trunk/bp-activity/bp-activity-classes.php
- Timestamp:
- 11/02/2009 07:54:21 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/bp-activity/bp-activity-classes.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r2036 r2077 11 11 var $date_recorded; 12 12 var $hide_sitewide = false; 13 13 14 14 function bp_activity_activity( $id = false ) { 15 15 global $bp; 16 16 17 17 if ( $id ) { 18 18 $this->id = $id; … … 20 20 } 21 21 } 22 22 23 23 function populate() { 24 24 global $wpdb, $bp; 25 25 26 26 $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) ); 27 27 28 28 $this->id = $activity->id; 29 29 $this->item_id = $activity->item_id; … … 37 37 $this->hide_sitewide = $activity->hide_sitewide; 38 38 } 39 39 40 40 function save() { 41 41 global $wpdb, $bp, $current_user; 42 42 43 43 do_action( 'bp_activity_before_save', $this ); 44 44 45 45 if ( !$this->component_name || !$this->component_action ) 46 46 return false; 47 47 48 48 /*** 49 49 * Before v1.1 of BuddyPress, activity content was calculated at a later point. This is no longer the … … 54 54 if ( !$fetched_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 ) ) 55 55 return false; 56 56 57 57 $this->content = $fetched_content['content']; 58 58 $this->primary_link = $fetched_content['primary_link']; 59 59 } 60 60 } 61 61 62 62 if ( !$this->primary_link ) 63 63 $this->primary_link = $bp->loggedin_user->domain; 64 64 65 65 if ( $existing_activity_id = $this->exists() ) 66 66 BP_Activity_Activity::delete_by_activity_id( $existing_activity_id ); 67 67 68 68 /* If we have an existing ID, update the activity item, otherwise insert it. */ 69 69 if ( $this->id ) { … … 81 81 return false; 82 82 } 83 83 84 84 function exists() { 85 85 global $wpdb, $bp; 86 86 87 87 /* This doesn't seem to be working correctly at the moment, so it is disabled [TODO] */ 88 88 return false; 89 89 90 90 /* If we have an item id, try and match on that, if not do a content match */ 91 91 if ( $this->item_id ) { 92 92 if ( $this->secondary_item_id ) 93 93 $secondary_sql = $wpdb->prepare( " AND secondary_item_id = %s", $secondary_item_id ); 94 95 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) ); 94 95 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) ); 96 96 } else { 97 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) ); 98 } 99 } 100 101 /* Static Functions */ 97 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) ); 98 } 99 } 100 101 /* Static Functions */ 102 102 103 103 function delete( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) { … … 106 106 if ( $secondary_item_id ) 107 107 $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %s", $secondary_item_id ); 108 108 109 109 if ( $component_action ) 110 110 $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action ); 111 111 112 112 if ( $user_id ) 113 113 $user_sql = $wpdb->prepare( "AND user_id = %d", $user_id ); … … 115 115 return $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 ) ); 116 116 } 117 117 118 118 function delete_by_item_id( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) { 119 119 return BP_Activity_Activity::delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ); … … 122 122 function delete_by_activity_id( $activity_id ) { 123 123 global $bp, $wpdb; 124 124 125 125 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE id = %d", $activity_id ) ); 126 126 } 127 127 128 128 function delete_by_content( $user_id, $content, $component_name, $component_action ) { 129 129 global $bp, $wpdb; 130 131 return $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 ) ); 132 } 133 130 131 return $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 ) ); 132 } 133 134 134 function delete_for_user_by_component( $user_id, $component_name ) { 135 135 global $bp, $wpdb; 136 137 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) ); 138 } 139 136 137 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) ); 138 } 139 140 140 function delete_for_user( $user_id ) { 141 141 global $wpdb, $bp; … … 143 143 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d", $user_id ) ); 144 144 } 145 145 146 146 function get_activity_for_user( $user_id, $max_items, $limit, $page, $filter ) { 147 147 global $wpdb, $bp; 148 148 149 149 if ( $limit && $page ) 150 150 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); … … 152 152 if ( $max_items ) 153 153 $max_sql = $wpdb->prepare( "LIMIT %d", $max_items ); 154 154 155 155 /* Sort out filtering */ 156 156 if ( $filter ) 157 157 $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ); 158 158 159 159 if ( $limit && $page && $max_items ) 160 160 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql", $user_id ) ); 161 161 else 162 162 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql", $user_id ) ); 163 163 164 164 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $max_sql", $user_id ) ); 165 165 166 166 return array( 'activities' => $activities, 'total' => (int)$total_activities ); 167 167 } 168 168 169 169 function get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $limit, $page, $filter ) { 170 170 global $wpdb, $bp; 171 171 172 172 // TODO: Max items per friend not yet implemented. 173 173 174 174 if ( !function_exists('friends_get_friend_user_ids') ) 175 175 return false; … … 177 177 if ( $limit && $page ) 178 178 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 179 179 180 180 if ( $max_items ) 181 181 $max_sql = $wpdb->prepare( "LIMIT %d", $max_items ); … … 189 189 if ( !$friend_ids ) 190 190 return false; 191 191 192 192 $friend_ids = implode( ',', $friend_ids ); 193 193 194 194 if ( $limit && $page && $max_items ) 195 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql" ) ); 195 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql" ) ); 196 196 else 197 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql" ) ); 198 199 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) ); 200 197 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql" ) ); 198 199 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) ); 200 201 201 return array( 'activities' => $activities, 'total' => (int)$total_activities ); 202 202 } 203 203 204 204 function get_sitewide_activity( $max, $limit, $page, $filter ) { 205 205 global $wpdb, $bp; 206 206 207 207 if ( $limit && $page ) 208 208 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 209 209 210 210 if ( $max ) 211 211 $max_sql = $wpdb->prepare( "LIMIT %d", $max ); 212 212 213 213 /* Sort out filtering */ 214 214 if ( $filter ) … … 224 224 return array( 'activities' => $activities, 'total' => (int)$total_activities ); 225 225 } 226 226 227 227 function get_recorded_component_names() { 228 228 global $wpdb, $bp; 229 229 230 230 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component_name FROM {$bp->activity->table_name} ORDER BY component_name ASC" ) ); 231 231 } 232 232 233 233 function get_sitewide_items_for_feed( $limit = 35 ) { 234 234 global $wpdb, $bp; 235 235 236 236 $activities = bp_activity_get_sitewide_activity( $limit ); 237 237 for ( $i = 0; $i < count($activities); $i++ ) { … … 244 244 } 245 245 246 return $activity_feed; 247 } 248 246 return $activity_feed; 247 } 248 249 249 function get_filter_sql( $filter_array ) { 250 250 global $wpdb; 251 251 252 252 if ( !empty( $filter_array['object'] ) ) { 253 253 $object_filter = explode( ',', $filter_array['object'] ); 254 254 $object_sql = ' AND ( '; 255 255 256 256 $counter = 1; 257 257 foreach( (array) $object_filter as $object ) { 258 258 $object_sql .= $wpdb->prepare( "component_name = %s", trim( $object ) ); 259 259 260 260 if ( $counter != count( $object_filter ) ) 261 261 $object_sql .= ' || '; 262 262 263 263 $counter++; 264 264 } 265 265 266 266 $object_sql .= ' )'; 267 267 } … … 270 270 $action_filter = explode( ',', $filter_array['action'] ); 271 271 $action_sql = ' AND ( '; 272 272 273 273 $counter = 1; 274 274 foreach( (array) $action_filter as $action ) { 275 275 $action_sql .= $wpdb->prepare( "component_action = %s", trim( $action ) ); 276 276 277 277 if ( $counter != count( $action_filter ) ) 278 278 $action_sql .= ' || '; 279 279 280 280 $counter++; 281 281 } 282 282 283 283 $action_sql .= ' )'; 284 284 } … … 287 287 $pid_filter = explode( ',', $filter_array['primary_id'] ); 288 288 $pid_sql = ' AND ( '; 289 289 290 290 $counter = 1; 291 291 foreach( (array) $pid_filter as $pid ) { 292 292 $pid_sql .= $wpdb->prepare( "item_id = %s", trim( $pid ) ); 293 293 294 294 if ( $counter != count( $pid_filter ) ) 295 295 $pid_sql .= ' || '; 296 296 297 297 $counter++; 298 298 } 299 299 300 300 $pid_sql .= ' )'; 301 301 } … … 304 304 $sid_filter = explode( ',', $filter_array['secondary_id'] ); 305 305 $sid_sql = ' AND ( '; 306 306 307 307 $counter = 1; 308 308 foreach( (array) $sid_filter as $sid ) { 309 309 $sid_sql .= $wpdb->prepare( "secondary_item_id = %s", trim( $sid ) ); 310 310 311 311 if ( $counter != count( $sid_filter ) ) 312 312 $sid_sql .= ' || '; 313 313 314 314 $counter++; 315 315 } 316 316 317 317 $sid_sql .= ' )'; 318 318 } 319 319 320 320 return $object_sql . $action_sql . $pid_sql . $sid_sql; 321 321 } 322 322 323 323 function get_last_updated() { 324 324 global $bp, $wpdb; 325 325 326 326 return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded ASC LIMIT 1" ) ); 327 327 } 328 328 329 329 function check_exists_by_content( $content ) { 330 330 global $wpdb, $bp;
Note: See TracChangeset
for help on using the changeset viewer.