Changeset 1794
- Timestamp:
- 09/04/2009 10:42:52 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-blogs.php
r1790 r1794 264 264 265 265 function bp_blogs_delete_activity( $args = true ) { 266 if ( function_exists('bp_activity_delete ') ) {266 if ( function_exists('bp_activity_delete_by_item_id') ) { 267 267 extract($args); 268 bp_activity_delete_by_item_id( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ); 268 269 bp_activity_delete_by_item_id( array( 270 'item_id' => $item_id, 271 'component_name' => $component_name, 272 'component_action' => $component_action, 273 'user_id' => $user_id, 274 'secondary_item_id' => $secondary_item_id 275 ) ); 269 276 } 270 277 } … … 300 307 } 301 308 302 function bp_blogs_record_blog( $blog_id, $user_id ) {309 function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 303 310 global $bp; 304 311 … … 312 319 $recorded_blog->user_id = $user_id; 313 320 $recorded_blog->blog_id = $blog_id; 314 321 315 322 $recorded_blog_id = $recorded_blog->save(); 316 323 … … 319 326 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', time() ); 320 327 321 if ( (int)$_POST['blog_public'] ) 322 $is_private = 0; 323 else 324 $is_private = 1; 325 326 /* Record this in activity streams */ 327 bp_blogs_record_activity( array( 328 'user_id' => $recorded_blog->user_id, 329 'content' => sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), 330 'primary_link' => get_blog_option( $recorded_blog->blog_id, 'siteurl' ), 331 'component_action' => 'new_blog', 332 'item_id' => $recorded_blog_id 333 ) ); 334 335 do_action( 'bp_blogs_new_blog', $recorded_blog, $is_private, $is_recorded ); 328 /* Only record this activity if the blog is public */ 329 if ( (int)$_POST['blog_public'] && !$no_activity ) { 330 /* Record this in activity streams */ 331 bp_blogs_record_activity( array( 332 'user_id' => $recorded_blog->user_id, 333 'content' => sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), 334 'primary_link' => get_blog_option( $recorded_blog->blog_id, 'siteurl' ), 335 'component_action' => 'new_blog', 336 'item_id' => $recorded_blog->blog_id 337 ) ); 338 } 339 340 do_action( 'bp_blogs_new_blog', &$recorded_blog, $is_private, $is_recorded ); 336 341 } 337 342 add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 ); 338 343 339 function bp_blogs_record_post( $post_id, $ blog_id = false, $user_id = false ) {344 function bp_blogs_record_post( $post_id, $post, $user_id = false ) { 340 345 global $bp, $wpdb; 341 346 342 347 $post_id = (int)$post_id; 343 $ post = get_post($post_id);348 $blog_id = (int)$wpdb->blogid; 344 349 345 350 if ( !$user_id ) 346 351 $user_id = (int)$post->post_author; 347 348 if ( !$blog_id ) 349 $blog_id = (int)$wpdb->blogid; 352 350 353 351 354 /* This is to stop infinate loops with Donncha's sitewide tags plugin */ … … 364 367 $recorded_post->blog_id = $blog_id; 365 368 $recorded_post->post_id = $post_id; 366 $recorded_post->date_created = strtotime( $post->post_date _gmt);369 $recorded_post->date_created = strtotime( $post->post_date ); 367 370 368 371 $recorded_post_id = $recorded_post->save(); … … 372 375 $post_permalink = bp_post_get_permalink( $post, $blog_id ); 373 376 377 $activity_content = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); 378 $activity_content .= "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>"; 379 374 380 /* Record this in activity streams */ 375 381 bp_blogs_record_activity( array( 376 382 'user_id' => (int)$post->post_author, 377 'content' => sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ),383 'content' => $activity_content, 378 384 'primary_link' => $post_permalink, 379 385 'component_action' => 'new_blog_post', 380 'item_id' => $recorded_post ->id,381 'recorded_time' => $recorded_post->date_created386 'item_id' => $recorded_post_id, 387 'recorded_time' => strtotime( $post->post_date ) 382 388 ) ); 383 389 } … … 385 391 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id ); 386 392 387 /** 388 * Delete the recorded post if: 389 * - The status is no longer "published" 390 * - The post is password protected 391 */ 392 if ( 'publish' != $post->post_status || '' != $post->post_password ) 393 bp_blogs_remove_post( $post_id, $blog_id ); 394 395 // Check to see if the post author has changed. 396 if ( (int)$existing_post->user_id != (int)$post->post_author ) { 393 /* Delete and the activity stream item as we are probably going to re-add it later with new info. */ 394 bp_blogs_delete_activity( array( 'item_id' => $existing_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post' ) ); 395 396 /* Delete the recorded post if the status is not published or it is password protected */ 397 if ( 'publish' != $post->post_status || '' != $post->post_password ) { 398 return bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 399 400 /* If the post author has changed, delete the post and re-add it. */ 401 } else if ( (int)$existing_post->user_id != (int)$post->post_author ) { 397 402 // Delete the existing recorded post 398 bp_blogs_remove_post( $post_id, $blog_id );403 bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 399 404 400 405 // Re-record the post with the new author. 401 bp_blogs_record_post( $post_id ); 406 bp_blogs_record_post( $post_id ); 402 407 } 403 408 409 /* Now re-record the post in the activity streams */ 404 410 $post_permalink = bp_post_get_permalink( $post, $blog_id ); 405 411 406 /* Delete and re-add the activity stream item to reflect potential content changes. */ 407 bp_blogs_delete_activity( array( 'item_id' => $recorded_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post', 'user_id' => $recorded_post->user_id ) ); 408 412 413 $activity_content = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); 414 $activity_content .= "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>"; 415 409 416 /* Record this in activity streams */ 410 417 bp_blogs_record_activity( array( 411 418 'user_id' => (int)$post->post_author, 412 'content' => sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ),419 'content' => $activity_content, 413 420 'primary_link' => $post_permalink, 414 421 'component_action' => 'new_blog_post', 415 422 'item_id' => $existing_post->id, 416 'recorded_time' => $existing_post->date_created423 'recorded_time' => strtotime( $post->post_date ) 417 424 ) ); 418 425 } … … 420 427 do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded ); 421 428 } 422 add_action( 'publish_post', 'bp_blogs_record_post' ); 423 add_action( 'edit_post', 'bp_blogs_record_post' ); 429 add_action( 'save_post', 'bp_blogs_record_post', 10, 2 ); 424 430 425 431 function bp_blogs_record_comment( $comment_id, $is_approved ) { … … 430 436 431 437 $comment = get_comment($comment_id); 438 $comment->post = get_post( $comment->comment_post_ID ); 432 439 433 440 /* Get the user_id from the author email. */ … … 443 450 $recorded_comment->comment_id = $comment_id; 444 451 $recorded_comment->comment_post_id = $comment->comment_post_ID; 445 $recorded_comment->date_created = strtotime( $comment->comment_date _gmt);452 $recorded_comment->date_created = strtotime( $comment->comment_date ); 446 453 447 454 $recorded_commment_id = $recorded_comment->save(); … … 450 457 451 458 $comment_link = bp_post_get_permalink( $comment->post, $recorded_comment->blog_id ); 452 $content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' ) . ' <span class="time-since">%s</span>'; 459 $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' ); 460 $activity_content .= '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>'; 461 462 /* Record this in activity streams */ 463 bp_blogs_record_activity( array( 464 'user_id' => $recorded_comment->user_id, 465 'content' => $activity_content, 466 'primary_link' => $comment_link, 467 'component_action' => 'new_blog_comment', 468 'item_id' => $comment_id, 469 'secondary_item_id' => $recorded_comment->blog_id, 470 'recorded_time' => $recorded_comment->date_created 471 ) ); 472 473 return $recorded_comment; 474 } 475 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 476 477 function bp_blogs_approve_comment( $comment_id, $comment ) { 478 global $bp, $wpdb; 479 480 $recorded_comment = bp_blogs_record_comment( $comment_id, true ); 481 $comment = get_comment($comment_id); 482 $comment->post = get_post( $comment->comment_post_ID ); 483 484 bp_blogs_delete_activity( array( 'item_id' => $comment_id, 'secondary_item_id' => $recorded_comment->blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_comment' ) ); 485 486 $comment_link = bp_post_get_permalink( $comment->post, $comment->blog_id ); 487 $content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $recorded_comment->user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' ); 453 488 $content .= '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>'; 454 489 … … 459 494 'primary_link' => $comment_link, 460 495 'component_action' => 'new_blog_comment', 461 'item_id' => $recorded_comment->blog_id, 462 'recorded_time' => $recorded_comment->date_created 463 ) ); 464 } 465 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 466 467 function bp_blogs_approve_comment( $comment_id, $comment ) { 468 global $bp, $wpdb; 469 470 $recorded_comment = bp_blogs_record_comment( $comment_id, true ); 471 $comment = get_comment($comment_id); 472 473 bp_blogs_delete_activity( array( 'item_id' => $recorded_comment->blog_id, 'secondary_item_id' => $recorded_commment_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_comment', 'user_id' => $recorded_comment->user_id ) ); 474 475 $comment_link = bp_post_get_permalink( $comment->post, $comment->blog_id ); 476 $content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' ) . ' <span class="time-since">%s</span>'; 477 $content .= '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>'; 478 479 /* Record this in activity streams */ 480 bp_blogs_record_activity( array( 481 'user_id' => $recorded_comment->user_id, 482 'content' => $content, 483 'primary_link' => $comment_link, 484 'component_action' => 'new_blog_comment', 485 'item_id' => $recorded_comment->blog_id, 496 'item_id' => $comment_id, 497 'secondary_item_id' => $recorded_comment->blog_id, 486 498 'recorded_time' => $recorded_comment->date_created 487 499 ) ); … … 498 510 function bp_blogs_add_user_to_blog( $user_id, $role, $blog_id ) { 499 511 if ( $role != 'subscriber' ) { 500 bp_blogs_record_blog( $blog_id, $user_id );512 bp_blogs_record_blog( $blog_id, $user_id, $no_activity = true ); 501 513 } 502 514 } … … 516 528 517 529 // Delete activity stream item 518 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog' , 'user_id' => $bp->loggedin_user->id) );530 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog' ) ); 519 531 520 532 do_action( 'bp_blogs_remove_blog', $blog_id ); … … 531 543 532 544 // Delete activity stream item 533 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog' , 'user_id' => $current_user->ID) );545 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog' ) ); 534 546 535 547 do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id ); … … 537 549 add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 ); 538 550 539 function bp_blogs_remove_post( $post_id ) {551 function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) { 540 552 global $current_blog, $bp; 541 553 542 554 $post_id = (int)$post_id; 543 $blog_id = (int)$current_blog->blog_id; 544 545 $post = new BP_Blogs_Post( null, $blog_id, $post_id ); 555 556 if ( !$blog_id ) 557 $blog_id = (int)$current_blog->blog_id; 558 559 if ( !$existing_post ) 560 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id ); 546 561 547 562 // Delete post from the bp_blogs table … … 549 564 550 565 // Delete activity stream item 551 bp_blogs_delete_activity( array( 'item_id' => $ post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post', 'user_id' => $post->user_id) );566 bp_blogs_delete_activity( array( 'item_id' => $existing_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post' ) ); 552 567 553 568 do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $post->user_id ); … … 562 577 563 578 // Delete activity stream item 564 bp_blogs_delete_activity( array( 'item_id' => $ recorded_comment->blog_id, 'secondary_item_id' => $recorded_comment->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_comment', 'user_id' => $recorded_comment->user_id) );579 bp_blogs_delete_activity( array( 'item_id' => $comment_id, 'secondary_item_id' => $recorded_comment->blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_comment' ) ); 565 580 566 581 do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id, $bp->loggedin_user->id ); … … 577 592 578 593 // Delete activity stream item 579 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => false , 'user_id' => $bp->loggedin_user->id) );594 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => false ) ); 580 595 581 596 do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
Note: See TracChangeset
for help on using the changeset viewer.