Changeset 2083
- Timestamp:
- 11/06/2009 10:34:10 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-blogs/bp-blogs-classes.php
r2055 r2083 5 5 var $user_id; 6 6 var $blog_id; 7 7 8 8 function bp_blogs_blog( $id = null ) { 9 9 global $bp, $wpdb; 10 10 11 11 if ( !$user_id ) 12 12 $user_id = $bp->displayed_user->id; … … 17 17 } 18 18 } 19 19 20 20 function populate() { 21 21 global $wpdb, $bp; 22 22 23 23 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) ); 24 24 … … 26 26 $this->blog_id = $blog->blog_id; 27 27 } 28 28 29 29 function save() { 30 30 global $wpdb, $bp; 31 31 32 32 $this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id ); 33 33 $this->blog_id = apply_filters( 'bp_blogs_blog_id_before_save', $this->blog_id, $this->id ); 34 34 35 35 do_action( 'bp_blogs_blog_before_save', $this ); 36 36 37 37 // Don't try and save if there is no user ID or blog ID set. 38 38 if ( !$this->user_id || !$this->blog_id ) 39 39 return false; 40 40 41 41 // Don't save if this blog has already been recorded for the user. 42 42 if ( !$this->id && $this->exists() ) 43 43 return false; 44 44 45 45 if ( $this->id ) { 46 46 // Update … … 50 50 $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id ); 51 51 } 52 52 53 53 if ( !$wpdb->query($sql) ) 54 54 return false; 55 55 56 56 do_action( 'bp_blogs_blog_after_save', $this ); 57 57 58 58 if ( $this->id ) 59 59 return $this->id; … … 61 61 return $wpdb->insert_id; 62 62 } 63 63 64 64 function exists() { 65 65 global $bp, $wpdb; 66 66 67 67 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 ) ); 68 68 } 69 69 70 70 /* Static Functions */ 71 71 72 72 function delete_blog_for_all( $blog_id ) { 73 73 global $wpdb, $bp; 74 75 if ( !$bp->blogs ) 76 bp_blogs_setup_globals(); 77 74 75 if ( !$bp->blogs ) 76 bp_blogs_setup_globals(); 77 78 78 bp_blogs_delete_blogmeta( $blog_id ); 79 79 80 80 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) ); 81 81 } 82 82 83 83 function delete_blog_for_user( $blog_id, $user_id = null ) { 84 84 global $wpdb, $bp; 85 86 if ( !$bp->blogs ) 87 bp_blogs_setup_globals(); 88 85 86 if ( !$bp->blogs ) 87 bp_blogs_setup_globals(); 88 89 89 if ( !$user_id ) 90 90 $user_id = $bp->loggedin_user->id; … … 92 92 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) ); 93 93 } 94 94 95 95 function delete_blogs_for_user( $user_id = null ) { 96 96 global $wpdb, $bp; 97 97 98 98 if ( !$bp->blogs ) 99 99 bp_blogs_setup_globals(); … … 104 104 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) ); 105 105 } 106 106 107 107 function get_blogs_for_user( $user_id = null ) { 108 108 global $bp, $wpdb; 109 110 if ( !$bp->blogs ) 111 bp_blogs_setup_globals(); 112 109 110 if ( !$bp->blogs ) 111 bp_blogs_setup_globals(); 112 113 113 if ( !$user_id ) 114 114 $user_id = $bp->displayed_user->id; 115 115 116 116 // Show logged in users their hidden blogs. 117 117 if ( !bp_is_home() ) 118 $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 WHEREwb.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) );118 $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.id, bm1.meta_value as name, bm2.meta_value as description, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1, {$bp->blogs->table_name_blogmeta} bm2 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND b.blog_id = bm2.blog_id AND bm1.meta_key = 'name' AND bm2.meta_key = 'description' AND 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) ); 119 119 else 120 $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 WHEREwb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) );121 120 $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.id, bm1.meta_value as name, bm2.meta_value as description, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1, {$bp->blogs->table_name_blogmeta} bm2 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND b.blog_id = bm2.blog_id AND bm1.meta_key = 'name' AND bm2.meta_key = 'description' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) ); 121 122 122 $total_blog_count = BP_Blogs_Blog::total_blog_count( $user_id ); 123 124 for ( $i = 0; $i < count($blog_ids); $i++ ) { 125 $blogs[] = array( 126 'id' => $blog_ids[$i], 127 'siteurl' => get_blog_option($blog_ids[$i], 'siteurl'), 128 'title' => get_blog_option($blog_ids[$i], 'blogname'), 129 'description' => get_blog_option($blog_ids[$i], 'blogdescription') 130 ); 131 } 132 133 return array( 'blogs' => $blogs, 'count' => $total_blog_count ); 134 } 135 123 124 foreach ( (array)$blogs as $blog ) { 125 $user_blogs[$blog->id] = new stdClass; 126 $user_blogs[$blog->id]->id = $blog->id; 127 $user_blogs[$blog->id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path; 128 $user_blogs[$blog->id]->name = $blog->name; 129 $user_blogs[$blog->id]->description = $blog->description; 130 } 131 132 return array( 'blogs' => $user_blogs, 'count' => $total_blog_count ); 133 } 134 136 135 function is_recorded( $blog_id ) { 137 136 global $bp, $wpdb; 138 139 if ( !$bp->blogs ) 140 bp_blogs_setup_globals(); 141 137 138 if ( !$bp->blogs ) 139 bp_blogs_setup_globals(); 140 142 141 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) ); 143 142 } 144 143 145 144 function total_blog_count( $user_id = null ) { 146 145 global $bp, $wpdb; 147 148 if ( !$bp->blogs ) 149 bp_blogs_setup_globals(); 150 146 147 if ( !$bp->blogs ) 148 bp_blogs_setup_globals(); 149 151 150 if ( !$user_id ) 152 151 $user_id = $bp->displayed_user->id; … … 156 155 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) ); 157 156 else 158 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) ); 159 } 160 157 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) ); 158 } 159 161 160 function get_all( $limit = null, $page = null ) { 162 161 global $bp, $wpdb; 163 164 if ( !$bp->blogs ) 165 bp_blogs_setup_globals(); 166 162 163 if ( !$bp->blogs ) 164 bp_blogs_setup_globals(); 165 167 166 if ( $limit && $page ) { 168 167 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 169 168 $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' ORDER BY CONVERT(bm.meta_value, SIGNED) DESC" ) ); 170 169 } 171 170 172 171 $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' ORDER BY CONVERT(bm.meta_value, SIGNED) DESC {$pag_sql}" ) ); 173 172 174 173 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); 175 174 } 176 175 177 176 function get_by_letter( $letter, $limit = null, $page = null ) { 178 177 global $bp, $wpdb; 179 180 if ( !$bp->blogs ) 181 bp_blogs_setup_globals(); 182 178 179 if ( !$bp->blogs ) 180 bp_blogs_setup_globals(); 181 183 182 $letter = like_escape( $wpdb->escape( $letter ) ); 184 183 185 184 if ( $limit && $page ) { 186 185 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 187 186 $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' AND wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" ) ); 188 187 } 189 188 190 189 $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' AND wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" ) ); 191 192 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); 193 } 194 190 191 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); 192 } 193 195 194 function search_blogs( $filter, $limit = null, $page = null ) { 196 195 global $wpdb, $bp; 197 198 if ( !$bp->blogs ) 199 bp_blogs_setup_globals(); 200 196 197 if ( !$bp->blogs ) 198 bp_blogs_setup_globals(); 199 201 200 $filter = like_escape( $wpdb->escape( $filter ) ); 202 201 203 202 if ( $limit && $page ) { 204 203 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); … … 207 206 208 207 $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) AND wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" ) ); 209 210 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); 211 } 212 208 209 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); 210 } 211 213 212 function get_random( $limit = null, $page = null ) { 214 213 global $bp, $wpdb; 215 216 if ( !$bp->blogs ) 217 bp_blogs_setup_globals(); 218 214 215 if ( !$bp->blogs ) 216 bp_blogs_setup_globals(); 217 219 218 if ( $limit && $page ) { 220 219 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 221 220 $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()" ) ); 222 221 } 223 224 $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}" ) ); 225 222 223 $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}" ) ); 224 226 225 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); 227 226 } 228 227 229 228 function get_active( $limit = null, $page = null ) { 230 229 global $bp, $wpdb; 231 232 if ( !$bp->blogs ) 233 bp_blogs_setup_globals(); 234 230 231 if ( !$bp->blogs ) 232 bp_blogs_setup_globals(); 233 235 234 if ( $limit && $page ) { 236 235 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 237 236 $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' ORDER BY CONVERT(bm.meta_value, SIGNED) DESC" ) ); 238 237 } 239 238 240 239 $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 AND bm.meta_key = 'last_activity' ORDER BY CONVERT(bm.meta_value, SIGNED) DESC {$pag_sql}" ) ); 241 240 242 241 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); 243 242 } 244 243 245 244 function get_newest( $limit = null, $page = null ) { 246 245 global $bp, $wpdb; 247 248 if ( !$bp->blogs ) 249 bp_blogs_setup_globals(); 250 246 247 if ( !$bp->blogs ) 248 bp_blogs_setup_globals(); 249 251 250 if ( $limit && $page ) { 252 251 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 253 252 $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(wb.blog_id) FROM {$wpdb->base_prefix}blogs wb WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 ORDER BY wb.registered DESC" ) ); 254 253 } 255 254 256 255 $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT wb.blog_id FROM {$wpdb->base_prefix}blogs wb WHERE wb.public = 1 AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 ORDER BY wb.registered DESC {$pag_sql}" ) ); 257 256 258 257 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); 259 258 } 260 259 261 260 function is_hidden( $blog_id ) { 262 261 global $wpdb; … … 264 263 if ( !$bp->blogs ) 265 264 bp_blogs_setup_globals(); 266 265 267 266 if ( !(int)$wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) ) 268 267 return true; 269 268 270 269 return false; 271 270 } … … 278 277 var $post_id; 279 278 var $date_created; 280 279 281 280 function bp_blogs_post( $id = null, $blog_id = null, $post_id = null ) { 282 281 global $bp, $wpdb; … … 297 296 else 298 297 $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d AND post_id = %d", $this->blog_id, $this->post_id ) ); 299 300 $this->id = $post->id; 298 299 $this->id = $post->id; 301 300 $this->user_id = $post->user_id; 302 301 $this->blog_id = $post->blog_id; … … 304 303 $this->date_created = $post->date_created; 305 304 } 306 305 307 306 function save() { 308 307 global $wpdb, $bp; 309 308 310 309 $this->post_id = apply_filters( 'bp_blogs_post_id_before_save', $this->post_id, $this->id ); 311 310 $this->blog_id = apply_filters( 'bp_blogs_post_blog_id_before_save', $this->blog_id, $this->id ); … … 322 321 $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blog_posts} ( post_id, blog_id, user_id, date_created ) VALUES ( %d, %d, %d, FROM_UNIXTIME(%d) )", $this->post_id, $this->blog_id, $this->user_id, $this->date_created ); 323 322 } 324 323 325 324 if ( !$wpdb->query($sql) ) 326 325 return false; 327 326 328 327 do_action( 'bp_blogs_post_after_save', $this ); 329 328 330 329 if ( $this->id ) 331 330 return $this->id; 332 331 else 333 return $wpdb->insert_id; 334 } 335 332 return $wpdb->insert_id; 333 } 334 336 335 /* Static Functions */ 337 336 338 337 function delete( $post_id, $blog_id ) { 339 338 global $wpdb, $bp, $current_user; 340 339 341 340 if ( !$bp->blogs ) 342 341 bp_blogs_setup_globals(); … … 344 343 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 ) ); 345 344 } 346 345 347 346 function delete_oldest( $user_id = null ) { 348 347 global $wpdb, $bp; 349 350 if ( !$bp->blogs ) 351 bp_blogs_setup_globals(); 352 348 349 if ( !$bp->blogs ) 350 bp_blogs_setup_globals(); 351 353 352 if ( !$user_id ) 354 353 $user_id = $current_user->ID; 355 356 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) ); 357 } 358 354 355 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) ); 356 } 357 359 358 function delete_posts_for_user( $user_id = null ) { 360 359 global $wpdb, $bp; 361 360 362 361 if ( !$bp->blogs ) 363 362 bp_blogs_setup_globals(); … … 368 367 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d", $user_id ) ); 369 368 } 370 369 371 370 function delete_posts_for_blog( $blog_id ) { 372 371 global $wpdb, $bp; 373 374 if ( !$bp->blogs ) 375 bp_blogs_setup_globals(); 376 372 373 if ( !$bp->blogs ) 374 bp_blogs_setup_globals(); 375 377 376 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) ); 378 377 } 379 378 380 379 function get_latest_posts( $blog_id = null, $limit = 5 ) { 381 380 global $wpdb, $bp; 382 383 if ( !$bp->blogs ) 384 bp_blogs_setup_globals(); 385 381 382 if ( !$bp->blogs ) 383 bp_blogs_setup_globals(); 384 386 385 if ( $blog_id ) 387 386 $blog_sql = $wpdb->prepare( " AND p.blog_id = %d", $blog_id ); 388 387 389 388 $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 $blog_sql ORDER BY p.date_created DESC LIMIT $limit" ) ); 390 389 … … 392 391 $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]); 393 392 } 394 393 395 394 return $posts; 396 395 } 397 396 398 397 function get_posts_for_user( $user_id = null ) { 399 398 global $bp, $wpdb; 400 401 if ( !$bp->blogs ) 402 bp_blogs_setup_globals(); 403 399 400 if ( !$bp->blogs ) 401 bp_blogs_setup_globals(); 402 404 403 if ( !$user_id ) 405 404 $user_id = $bp->displayed_user->id; 406 405 407 406 // Show a logged in user their posts on private blogs, but not anyone else. 408 407 if ( !bp_is_home() ) { … … 411 410 } else { 412 411 $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d ORDER BY p.date_created DESC", $user_id) ); 413 $total_post_count = $wpdb->get_var( $wpdb->prepare( "SELECT count(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id) ); 412 $total_post_count = $wpdb->get_var( $wpdb->prepare( "SELECT count(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id) ); 414 413 } 415 414 … … 420 419 return array( 'posts' => $posts, 'count' => $total_post_count ); 421 420 } 422 421 423 422 function fetch_post_content( $post_object ) { 424 423 // TODO: switch_to_blog() calls are expensive and this needs to be changed. … … 430 429 return $post; 431 430 } 432 431 433 432 function get_total_recorded_for_user( $user_id = null ) { 434 433 global $bp, $wpdb; 435 436 if ( !$bp->blogs ) 437 bp_blogs_setup_globals(); 438 434 435 if ( !$bp->blogs ) 436 bp_blogs_setup_globals(); 437 439 438 if ( !$user_id ) 440 439 $user_id = $current_user->ID; … … 442 441 return $wpdb->get_var( $wpdb->prepare( "SELECT count(post_id) FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d", $user_id ) ); 443 442 } 444 443 445 444 function is_recorded( $post_id, $blog_id, $user_id = null ) { 446 445 global $bp, $wpdb, $current_user; 447 448 if ( !$bp->blogs ) 449 bp_blogs_setup_globals(); 450 446 447 if ( !$bp->blogs ) 448 bp_blogs_setup_globals(); 449 451 450 if ( !$user_id ) 452 451 $user_id = $current_user->ID; 453 452 454 453 return $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$bp->blogs->table_name_blog_posts} WHERE post_id = %d AND blog_id = %d AND user_id = %d", $post_id, $blog_id, $user_id ) ); 455 454 } 456 455 457 456 function total_post_count( $blog_id ) { 458 457 global $bp, $wpdb; 459 460 if ( !$bp->blogs ) 461 bp_blogs_setup_globals(); 462 458 459 if ( !$bp->blogs ) 460 bp_blogs_setup_globals(); 461 463 462 if ( !$blog_id ) 464 463 return false; 465 466 return $wpdb->get_var( $wpdb->prepare( "SELECT count(post_id) FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) ); 467 } 468 464 465 return $wpdb->get_var( $wpdb->prepare( "SELECT count(post_id) FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) ); 466 } 467 469 468 function get_all() { 470 469 global $bp, $wpdb; 471 472 if ( !$bp->blogs ) 473 bp_blogs_setup_globals(); 474 470 471 if ( !$bp->blogs ) 472 bp_blogs_setup_globals(); 473 475 474 return $wpdb->get_col( $wpdb->prepare( "SELECT post_id, blog_id FROM " . $bp->blogs->table_name_blog_posts ) ); 476 475 } 477 476 478 477 } 479 478 … … 485 484 var $comment_post_id; 486 485 var $date_created; 487 486 488 487 function bp_blogs_comment( $id = false, $blog_id = false, $comment_id = false ) { 489 488 global $bp, $wpdb; … … 491 490 if ( !$user_id ) 492 491 $user_id = $bp->displayed_user->id; 493 492 494 493 if ( $id || ( !$id && $blog_id && $comment_id ) ) { 495 494 $this->id = $id; … … 502 501 function populate() { 503 502 global $wpdb, $bp; 504 503 505 504 if ( $this->id ) 506 505 $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_comments} WHERE id = %d", $this->id ) ); 507 506 else 508 507 $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d AND comment_id = %d", (int)$this->blog_id, (int)$this->comment_id ) ); 509 508 510 509 $this->comment_id = $comment->comment_id; 511 510 $this->user_id = $comment->user_id; … … 514 513 $this->date_created = $comment->date_created; 515 514 } 516 515 517 516 function save() { 518 517 global $wpdb, $bp; … … 525 524 526 525 do_action( 'bp_blogs_comment_before_save', $this ); 527 526 528 527 if ( $this->id ) { 529 528 // Update … … 536 535 if ( !$wpdb->query($sql) ) 537 536 return false; 538 537 539 538 do_action( 'bp_blogs_comment_after_save', $this ); 540 539 541 540 if ( $this->id ) 542 541 return $this->id; 543 542 else 544 return $wpdb->insert_id; 543 return $wpdb->insert_id; 545 544 } 546 545 547 546 /* Static Functions */ 548 547 549 548 function delete( $comment_id, $blog_id ) { 550 549 global $wpdb, $bp, $current_user; 551 552 if ( !$bp->blogs ) 553 bp_blogs_setup_globals(); 554 550 551 if ( !$bp->blogs ) 552 bp_blogs_setup_globals(); 553 555 554 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 ) ); 556 555 } 557 556 558 557 function delete_oldest( $user_id = null ) { 559 558 global $wpdb, $bp, $current_user; 560 561 if ( !$bp->blogs ) 562 bp_blogs_setup_globals(); 563 559 560 if ( !$bp->blogs ) 561 bp_blogs_setup_globals(); 562 564 563 if ( !$user_id ) 565 564 $user_id = $current_user->ID; 566 567 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) ); 568 } 569 565 566 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) ); 567 } 568 570 569 function delete_comments_for_user( $user_id = null ) { 571 570 global $wpdb, $bp; 572 571 573 572 if ( !$bp->blogs ) 574 573 bp_blogs_setup_globals(); … … 579 578 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d", $user_id ) ); 580 579 } 581 580 582 581 function delete_comments_for_blog( $blog_id ) { 583 582 global $wpdb, $bp; 584 585 if ( !$bp->blogs ) 586 bp_blogs_setup_globals(); 587 583 584 if ( !$bp->blogs ) 585 bp_blogs_setup_globals(); 586 588 587 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d", $blog_id ) ); 589 588 } 590 589 591 590 function get_comments_for_user( $user_id = null ) { 592 591 global $bp, $wpdb; 593 592 594 593 if ( !$bp->blogs ) 595 594 bp_blogs_setup_globals(); … … 597 596 if ( !$user_id ) 598 597 $user_id = $bp->displayed_user->id; 599 598 600 599 // Show the logged in user their comments on hidden blogs, but not to anyone else. 601 600 if ( !bp_is_home() ) { … … 604 603 } else { 605 604 $comment_ids = $wpdb->get_results( $wpdb->prepare( "SELECT c.comment_id, c.blog_id FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d ORDER BY c.date_created ASC", $user_id) ); 606 $total_comment_count = $wpdb->get_var( $wpdb->prepare( "SELECT count(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d", $user_id) ); 607 } 608 605 $total_comment_count = $wpdb->get_var( $wpdb->prepare( "SELECT count(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d", $user_id) ); 606 } 607 609 608 for ( $i = 0; $i < count($comment_ids); $i++ ) { 610 609 $comments[$i] = BP_Blogs_Comment::fetch_comment_content($comment_ids[$i]); … … 613 612 return array( 'comments' => $comments, 'count' => $total_comment_count ); 614 613 } 615 616 function fetch_comment_content( $comment_object ) { 614 615 function fetch_comment_content( $comment_object ) { 617 616 switch_to_blog($comment_object->blog_id); 618 617 $comment = get_comment($comment_object->comment_id); … … 620 619 $comment->post = &get_post( $comment->comment_post_ID ); 621 620 restore_current_blog(); 622 621 623 622 return $comment; 624 623 } 625 624 626 625 function get_total_recorded_for_user( $user_id = null ) { 627 626 global $bp, $wpdb, $current_user; 628 629 if ( !$bp->blogs ) 630 bp_blogs_setup_globals(); 631 627 628 if ( !$bp->blogs ) 629 bp_blogs_setup_globals(); 630 632 631 if ( !$user_id ) 633 632 $user_id = $current_user->ID; … … 635 634 return $wpdb->get_var( $wpdb->prepare( "SELECT count(comment_id) FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d", $user_id ) ); 636 635 } 637 636 638 637 function total_comment_count( $blog_id, $post_id ) { 639 638 global $bp, $wpdb; 640 641 if ( !$bp->blogs ) 642 bp_blogs_setup_globals(); 643 639 640 if ( !$bp->blogs ) 641 bp_blogs_setup_globals(); 642 644 643 if ( $post_id ) 645 644 $post_sql = $wpdb->prepare( " AND comment_post_id = %d", $post_id ); … … 647 646 return $wpdb->get_var( $wpdb->prepare( "SELECT count(comment_id) WHERE blog_id = %d{$post_sql}", $blog_id ) ); 648 647 } 649 650 648 649 651 650 function is_recorded( $comment_id, $comment_post_id, $blog_id, $user_id = null ) { 652 651 global $bp, $wpdb, $current_user; 653 654 if ( !$bp->blogs ) 655 bp_blogs_setup_globals(); 656 652 653 if ( !$bp->blogs ) 654 bp_blogs_setup_globals(); 655 657 656 if ( !$user_id ) 658 657 $user_id = $current_user->ID; 659 658 660 659 return $wpdb->get_var( $wpdb->prepare( "SELECT comment_id FROM {$bp->blogs->table_name_blog_comments} WHERE comment_id = %d AND blog_id = %d AND comment_post_id = %d AND user_id = %d", $comment_id, $blog_id, $comment_post_id, $user_id ) ); 661 660 } 662 661 663 662 } 664 663 -
trunk/bp-core/bp-core-adminbar.php
r2077 r2083 132 132 133 133 if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id, 'bp' ) ) { 134 $blogs = get_blogs_of_user( $bp->loggedin_user->id );134 $blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id ); 135 135 wp_cache_set( 'bp_blogs_of_user_' . $bp->loggedin_user->id, $blogs, 'bp' ); 136 136 } … … 143 143 144 144 echo '<ul>'; 145 if ( is_array( $blogs )) { 145 146 if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) { 146 147 147 148 $counter = 0; 148 foreach ( $blogsas $blog ) {149 $role = get_blog_role_for_user( $bp->loggedin_user->id, $blog-> userblog_id );149 foreach ( $blogs['blogs'] as $blog ) { 150 $role = get_blog_role_for_user( $bp->loggedin_user->id, $blog->id ); 150 151 151 152 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; 152 153 echo '<li' . $alt . '>'; 153 echo '<a href="' . $blog->siteurl . '">' . $blog-> blogname . ' (' . $role . ')</a>';154 echo '<a href="' . $blog->siteurl . '">' . $blog->name . ' (' . $role . ')</a>'; 154 155 if ( !( 'Subscriber' == $role ) ) { // then they have something to display on the flyout menu 155 156 echo '<ul>'; 156 echo '<li class="alt"><a href="' . $blog->siteurl . ' /wp-admin/">' . __('Dashboard', 'buddypress') . '</a></li>';157 echo '<li><a href="' . $blog->siteurl . ' /wp-admin/post-new.php">' . __('New Post', 'buddypress') . '</a></li>';158 echo '<li class="alt"><a href="' . $blog->siteurl . ' /wp-admin/edit.php">' . __('Manage Posts', 'buddypress') . '</a></li>';159 echo '<li><a href="' . $blog->siteurl . ' /wp-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>';157 echo '<li class="alt"><a href="' . $blog->siteurl . 'wp-admin/">' . __('Dashboard', 'buddypress') . '</a></li>'; 158 echo '<li><a href="' . $blog->siteurl . 'wp-admin/post-new.php">' . __('New Post', 'buddypress') . '</a></li>'; 159 echo '<li class="alt"><a href="' . $blog->siteurl . 'wp-admin/edit.php">' . __('Manage Posts', 'buddypress') . '</a></li>'; 160 echo '<li><a href="' . $blog->siteurl . 'wp-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>'; 160 161 if ( 'Admin' == $role ) { 161 echo '<li class="alt"><a href="' . $blog->siteurl . ' /wp-admin/themes.php">' . __('Switch Theme', 'buddypress') . '</a></li>';162 echo '<li class="alt"><a href="' . $blog->siteurl . 'wp-admin/themes.php">' . __('Switch Theme', 'buddypress') . '</a></li>'; 162 163 } 163 164 echo '</ul>';
Note: See TracChangeset
for help on using the changeset viewer.