Changeset 1048
- Timestamp:
- 02/10/2009 08:50:05 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity.php
r1040 r1048 306 306 } 307 307 308 function bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) { 308 function bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) { 309 309 if ( !BP_Activity_Activity::delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) ) 310 310 return false; -
trunk/bp-activity/bp-activity-classes.php
r1038 r1048 86 86 function delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id = false ) { 87 87 global $wpdb, $bp; 88 88 89 89 if ( !$user_id ) 90 90 return false; … … 94 94 95 95 if ( $secondary_item_id ) 96 $secondary_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id ); 97 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 //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 ) ); 101 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 ) ); 96 $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id ); 97 98 if ( $component_action ) { 99 $component_action_sql = $wpdb->prepare( "AND component_action = %s AND user_id = %d", $component_action, $user_id ); 100 $cached_component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action ); 101 } 102 103 error_log( $component_action ); 104 105 error_log( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql}", $item_id, $component_name ) ); 106 error_log( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d {$secondary_sql} AND component_name = %s {$cached_component_action_sql}", $item_id, $component_name ) ); 107 error_log( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_sitewide} WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql}", $item_id, $component_name ) ); 108 109 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql}", $item_id, $component_name ) ); 103 110 104 111 // Delete this entry from the users' cache table and the sitewide cache table 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) );112 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d {$secondary_sql} AND component_name = %s {$cached_component_action_sql}", $item_id, $component_name ) ); 113 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_sitewide} WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql}", $item_id, $component_name ) ); 107 114 108 115 return true; -
trunk/bp-blogs.php
r1032 r1048 268 268 break; 269 269 case 'new_blog_post': 270 $post = new BP_Blogs_Post($ item_id);270 $post = new BP_Blogs_Post($secondary_item_id); 271 271 272 272 if ( !$post ) … … 296 296 return false; 297 297 298 $comment = new BP_Blogs_Comment($ item_id);298 $comment = new BP_Blogs_Comment($secondary_item_id); 299 299 300 300 if ( !$comment ) … … 432 432 433 433 // Record in activity streams 434 bp_blogs_record_activity( array( 'item_id' => $recorded_post _id, 'component_name' => 'blogs', 'component_action' => 'new_blog_post', 'is_private' => $is_private, 'user_id' => $recorded_post->user_id ) );434 bp_blogs_record_activity( array( 'item_id' => $recorded_post->blog_id, 'secondary_item_id' => $recorded_post_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_post', 'is_private' => $is_private, 'user_id' => $recorded_post->user_id ) ); 435 435 } 436 436 } else { … … 508 508 509 509 // Record in activity streams 510 bp_blogs_record_activity( array( 'item_id' => $recorded_comm ment_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_comment', 'is_private' => $is_private, 'user_id' => $recorded_comment->user_id ) );510 bp_blogs_record_activity( array( 'item_id' => $recorded_comment->blog_id, 'secondary_item_id' => $recorded_commment_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_comment', 'is_private' => $is_private, 'user_id' => $recorded_comment->user_id ) ); 511 511 } 512 512 } else { … … 635 635 636 636 function bp_blogs_remove_data_for_blog( $blog_id ) { 637 global $bp; 638 637 639 /* If this is regular blog, delete all data for that blog. */ 638 640 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 639 641 BP_Blogs_Post::delete_posts_for_blog( $blog_id ); 640 642 BP_Blogs_Comment::delete_comments_for_blog( $blog_id ); 643 644 // Delete activity stream item 645 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => 'blogs', 'component_action' => false, 'user_id' => $bp->loggedin_user->id ) ); 641 646 642 647 do_action( 'bp_blogs_remove_data_for_blog', $blog_id ); … … 722 727 723 728 if ( !$meta_key ) { 724 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->blogs->table_name_blogpmeta . "WHERE blog_id = %d", $blog_id ) );729 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) ); 725 730 } else if ( !$meta_value ) { 726 731 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s AND meta_value = %s", $blog_id, $meta_key, $meta_value ) ); -
trunk/bp-blogs/bp-blogs-classes.php
r1041 r1048 21 21 global $wpdb, $bp; 22 22 23 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp->blogs->table_name . "WHERE id = %d", $this->id ) );23 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) ); 24 24 25 25 $this->user_id = $blog->user_id; … … 40 40 if ( $this->id ) { 41 41 // Update 42 $sql = $wpdb->prepare( "UPDATE " . $bp->blogs->table_name . "SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id );42 $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name} SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id ); 43 43 } else { 44 44 // Save 45 $sql = $wpdb->prepare( "INSERT INTO " . $bp->blogs->table_name . "( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id );45 $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id ); 46 46 } 47 47 … … 58 58 global $bp, $wpdb; 59 59 60 return $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM " . $bp->blogs->table_name . "WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );60 return $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) ); 61 61 } 62 62 … … 66 66 global $wpdb, $bp; 67 67 68 if ( !$bp->blogs ) 69 bp_blogs_setup_globals(); 70 68 71 bp_blogs_delete_blogmeta( $blog_id ); 69 72 70 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->blogs->table_name . "WHERE blog_id = %d", $blog_id ) );73 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) ); 71 74 } 72 75 … … 74 77 global $wpdb, $bp; 75 78 79 if ( !$bp->blogs ) 80 bp_blogs_setup_globals(); 81 76 82 if ( !$user_id ) 77 83 $user_id = $bp->loggedin_user->id; 78 84 79 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->blogs->table_name . "WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );85 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) ); 80 86 } 81 87 82 88 function delete_blogs_for_user( $user_id = null ) { 83 89 global $wpdb, $bp; 90 91 if ( !$bp->blogs ) 92 bp_blogs_setup_globals(); 84 93 85 94 if ( !$user_id ) 86 95 $user_id = $bp->loggedin_user->id; 87 96 88 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->blogs->table_name . "WHERE user_id = %d", $user_id ) );97 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) ); 89 98 } 90 99 91 100 function get_blogs_for_user( $user_id = null ) { 92 101 global $bp, $wpdb; 102 103 if ( !$bp->blogs ) 104 bp_blogs_setup_globals(); 93 105 94 106 if ( !$user_id ) … … 97 109 // Show logged in users their hidden blogs. 98 110 if ( !bp_is_home() ) 99 $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM " . $bp->blogs->table_name . "b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) );111 $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) ); 100 112 else 101 $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM " . $bp->blogs->table_name . "b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) );113 $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) ); 102 114 103 115 $total_blog_count = BP_Blogs_Blog::total_blog_count( $user_id ); … … 121 133 bp_blogs_setup_globals(); 122 134 123 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM " . $bp->blogs->table_name . "WHERE blog_id = %d", $blog_id ) );135 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) ); 124 136 } 125 137 … … 135 147 // If the user is logged in return the blog count including their hidden blogs. 136 148 if ( !bp_is_home() ) 137 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM " . $bp->blogs->table_name . "b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );149 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) ); 138 150 else 139 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM " . $bp->blogs->table_name . "b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );151 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) ); 140 152 } 141 153 142 154 function get_all( $limit = null, $page = null ) { 143 155 global $bp, $wpdb; 156 157 if ( !$bp->blogs ) 158 bp_blogs_setup_globals(); 144 159 145 160 if ( $limit && $page ) { … … 155 170 function get_by_letter( $letter, $limit = null, $page = null ) { 156 171 global $bp, $wpdb; 172 173 if ( !$bp->blogs ) 174 bp_blogs_setup_globals(); 157 175 158 176 like_escape($letter); … … 171 189 global $wpdb, $bp; 172 190 191 if ( !$bp->blogs ) 192 bp_blogs_setup_globals(); 193 173 194 like_escape($filter); 174 195 … … 186 207 global $bp, $wpdb; 187 208 209 if ( !$bp->blogs ) 210 bp_blogs_setup_globals(); 211 188 212 if ( $limit && $page ) { 189 213 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 190 $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM " . $bp->blogs->table_name . "b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY rand()" ) );191 } 192 193 $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM " . $bp->blogs->table_name . "b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY rand() {$pag_sql}" ) );214 $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY rand()" ) ); 215 } 216 217 $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY rand() {$pag_sql}" ) ); 194 218 195 219 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); … … 198 222 function is_hidden( $blog_id ) { 199 223 global $wpdb; 224 225 if ( !$bp->blogs ) 226 bp_blogs_setup_globals(); 200 227 201 228 if ( !(int)$wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) ) … … 263 290 function delete( $post_id, $blog_id ) { 264 291 global $wpdb, $bp, $current_user; 292 293 if ( !$bp->blogs ) 294 bp_blogs_setup_globals(); 265 295 266 296 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d AND post_id = %d", $blog_id, $post_id ) ); … … 270 300 global $wpdb, $bp; 271 301 302 if ( !$bp->blogs ) 303 bp_blogs_setup_globals(); 304 272 305 if ( !$user_id ) 273 306 $user_id = $current_user->ID; … … 278 311 function delete_posts_for_user( $user_id = null ) { 279 312 global $wpdb, $bp; 313 314 if ( !$bp->blogs ) 315 bp_blogs_setup_globals(); 280 316 281 317 if ( !$user_id ) … … 288 324 global $wpdb, $bp; 289 325 326 if ( !$bp->blogs ) 327 bp_blogs_setup_globals(); 328 290 329 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) ); 291 330 } … … 293 332 function get_latest_posts( $blog_id = null, $limit = 5 ) { 294 333 global $wpdb, $bp; 334 335 if ( !$bp->blogs ) 336 bp_blogs_setup_globals(); 295 337 296 338 if ( $blog_id ) … … 308 350 function get_posts_for_user( $user_id = null ) { 309 351 global $bp, $wpdb; 352 353 if ( !$bp->blogs ) 354 bp_blogs_setup_globals(); 310 355 311 356 if ( !$user_id ) … … 442 487 function delete( $comment_id, $blog_id ) { 443 488 global $wpdb, $bp, $current_user; 489 490 if ( !$bp->blogs ) 491 bp_blogs_setup_globals(); 444 492 445 493 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE comment_id = %d AND blog_id = %d", $comment_id, $blog_id ) ); … … 449 497 global $wpdb, $bp, $current_user; 450 498 499 if ( !$bp->blogs ) 500 bp_blogs_setup_globals(); 501 451 502 if ( !$user_id ) 452 503 $user_id = $current_user->ID; … … 457 508 function delete_comments_for_user( $user_id = null ) { 458 509 global $wpdb, $bp; 510 511 if ( !$bp->blogs ) 512 bp_blogs_setup_globals(); 459 513 460 514 if ( !$user_id ) … … 467 521 global $wpdb, $bp; 468 522 523 if ( !$bp->blogs ) 524 bp_blogs_setup_globals(); 525 469 526 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d", $blog_id ) ); 470 527 } … … 472 529 function get_comments_for_user( $user_id = null ) { 473 530 global $bp, $wpdb; 531 532 if ( !$bp->blogs ) 533 bp_blogs_setup_globals(); 474 534 475 535 if ( !$user_id )
Note: See TracChangeset
for help on using the changeset viewer.