Ticket #5130: 5130.05.patch
| File 5130.05.patch, 44.3 KB (added by , 12 years ago) |
|---|
-
bp-activity/admin/css/admin.css
75 75 #bp-activities-primaryid { 76 76 margin-bottom: 1em; 77 77 } 78 .column-action { 79 width: 12%; 80 } 81 No newline at end of file -
bp-activity/admin/css/admin.min.css
1 .akismet-status{float:right}.akismet-status a{color:#AAA;font-style:italic}.akismet-history{margin:13px}.akismet-history div{margin-bottom:13px}.akismet-history span{color:#999}#wp-bp-activities-wrap{padding:5px 0}#bp-activities{height:120px}#bp-replyhead{font-size:1em;line-height:1.4em;margin:0}#bp-replysubmit{margin:0;padding:0 0 3px;text-align:center}#bp-replysubmit .error{color:red;line-height:21px;text-align:center;vertical-align:center}#bp-replysubmit img.waiting{float:right;padding:4px 10px 0;vertical-align:top}#bp-activities-form .column-response img{float:left;margin-right:10px;margin-top:1px}.activity-errors{list-style-type:disc;margin-left:2em}#bp_activity_action div.inside,#bp_activity_content div.inside{line-height:0}#bp_activity_action h3,#bp_activity_content h3{cursor:auto}#bp_activity_action td.mceIframeContainer,#bp_activity_content td.mceIframeContainer{background-color:white}#post-body #bp-activities-action_resize,#post-body #bp-activities-content_resize{position:inherit;margin-top:-2px}#bp_activity_link input{width:99%}#bp-activities-primaryid{margin-bottom:1em} 2 No newline at end of file 1 .akismet-status{float:right}.akismet-status a{color:#AAA;font-style:italic}.akismet-history{margin:13px}.akismet-history div{margin-bottom:13px}.akismet-history span{color:#999}#wp-bp-activities-wrap{padding:5px 0}#bp-activities{height:120px}#bp-replyhead{font-size:1em;line-height:1.4em;margin:0}#bp-replysubmit{margin:0;padding:0 0 3px;text-align:center}#bp-replysubmit .error{color:red;line-height:21px;text-align:center;vertical-align:center}#bp-replysubmit img.waiting{float:right;padding:4px 10px 0;vertical-align:top}#bp-activities-form .column-response img{float:left;margin-right:10px;margin-top:1px}.activity-errors{list-style-type:disc;margin-left:2em}#bp_activity_action div.inside,#bp_activity_content div.inside{line-height:0}#bp_activity_action h3,#bp_activity_content h3{cursor:auto}#bp_activity_action td.mceIframeContainer,#bp_activity_content td.mceIframeContainer{background-color:white}#post-body #bp-activities-action_resize,#post-body #bp-activities-content_resize{position:inherit;margin-top:-2px}#bp_activity_link input{width:99%}#bp-activities-primaryid{margin-bottom:1em}.column-action{width:12%} 2 No newline at end of file -
bp-activity/bp-activity-admin.php
458 458 459 459 // Activity type 460 460 if ( ! empty( $_POST['bp-activities-type'] ) ) { 461 $actions = array(); 462 463 // Walk through the registered actions, and build an array of actions/values. 464 foreach ( $bp->activity->actions as $action ) { 465 $action = array_values( (array) $action ); 466 467 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) 468 $actions[] = $action[$i]['key']; 469 } 470 471 // This was a mis-named activity type from before BP 1.6 472 unset( $actions['friends_register_activity_action'] ); 461 $actions = bp_activity_admin_get_activity_actions(); 473 462 474 463 // Check that the new type is a registered activity type 475 if ( in_array( $_POST['bp-activities-type'], $actions ) ) 464 if ( in_array( $_POST['bp-activities-type'], $actions ) ) { 476 465 $activity->type = $_POST['bp-activities-type']; 466 } 477 467 } 478 468 479 469 // Activity timestamp … … 736 726 } 737 727 738 728 /** 739 * Activity type metabox for the Activity admin edit screen729 * Get flattened array of all registered activity actions. 740 730 * 741 * @since BuddyPress (1.6.0)731 * Format is [activity_type] => Pretty name for activity type. 742 732 * 743 * @ global object $bp BuddyPress global settings.733 * @since BuddyPress (2.0.0) 744 734 * 745 * @ param object $item Activity item.735 * @return array 746 736 */ 747 function bp_activity_admin_edit_metabox_type( $item ) { 748 global $bp; 749 737 function bp_activity_admin_get_activity_actions() { 750 738 $actions = array(); 751 $selected = $item->type;752 739 753 740 // Walk through the registered actions, and build an array of actions/values. 754 foreach ( $bp->activity->actions as $action ) {741 foreach ( buddypress()->activity->actions as $action ) { 755 742 $action = array_values( (array) $action ); 756 743 757 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) 744 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) { 758 745 $actions[ $action[$i]['key'] ] = $action[$i]['value']; 746 } 759 747 } 760 748 761 749 // This was a mis-named activity type from before BP 1.6 … … 764 752 // Sort array by the human-readable value 765 753 natsort( $actions ); 766 754 755 return $actions; 756 } 757 758 /** 759 * Activity type metabox for the Activity admin edit screen 760 * 761 * @since BuddyPress (1.6.0) 762 * 763 * @global object $bp BuddyPress global settings. 764 * 765 * @param object $item Activity item. 766 */ 767 function bp_activity_admin_edit_metabox_type( $item ) { 768 $actions = bp_activity_admin_get_activity_actions(); 769 $selected = $item->type; 770 767 771 // If the activity type is not registered properly (eg, a plugin has 768 772 // not called bp_activity_set_action()), add the raw type to the end 769 773 // of the list … … 974 978 */ 975 979 public function __construct() { 976 980 981 // See if activity commenting is enabled for blog / forum activity items 982 $this->disable_blogforum_comments = bp_disable_blogforum_comments(); 983 977 984 // Define singular and plural labels, as well as whether we support AJAX. 978 985 parent::__construct( array( 979 986 'ajax' => false, … … 1217 1224 'cb' => '<input name type="checkbox" />', 1218 1225 'author' => __( 'Author', 'buddypress' ), 1219 1226 'comment' => __( 'Activity', 'buddypress' ), 1227 'action' => __( 'Action', 'buddypress' ), 1220 1228 'response' => __( 'In Response To', 'buddypress' ), 1221 1229 ); 1222 1230 } … … 1300 1308 } 1301 1309 1302 1310 /** 1311 * Action column markup. 1312 * 1313 * @since BuddyPress (2.0.0) 1314 * 1315 * @see WP_List_Table::single_row_columns() 1316 * 1317 * @param array $item A singular item (one full row). 1318 */ 1319 function column_action( $item ) { 1320 $actions = bp_activity_admin_get_activity_actions(); 1321 1322 if ( isset( $actions[ $item['type'] ] ) ) { 1323 echo $actions[ $item['type'] ]; 1324 } else { 1325 printf( __( 'Unregistered action - %s', 'buddypress' ), $item['type'] ); 1326 } 1327 } 1328 1329 /** 1303 1330 * Content column, and "quick admin" rollover actions. 1304 1331 * 1305 1332 * Called "comment" in the CSS so we can re-use some WP core CSS. … … 1338 1365 1339 1366 // Reply - javascript only; implemented by AJAX. 1340 1367 if ( 'spam' != $item_status ) { 1341 $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) ); 1368 if ( $this->can_comment( $item ) ) { 1369 $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) ); 1370 } else { 1371 $actions['reply'] = sprintf( '<span class="form-input-tip" title="%s">%s</span>', __( 'Replies are disabled for this activity item', 'buddypress' ), __( 'Replies disabled', 'buddypress' ) ); 1372 } 1342 1373 1343 1374 // Edit 1344 1375 $actions['edit'] = sprintf( '<a href="%s">%s</a>', $edit_url, __( 'Edit', 'buddypress' ) ); … … 1445 1476 } 1446 1477 1447 1478 /** 1479 * Checks if an activity item can be replied to. 1480 * 1481 * This method merges functionality from {@link bp_activity_can_comment()} and 1482 * {@link bp_blogs_disable_activity_commenting()}. This is done because the activity 1483 * list table doesn't use a BuddyPress activity loop, which prevents those 1484 * functions from working as intended. 1485 * 1486 * @since BuddyPress (2.0.0) 1487 * 1488 * @param array $item An array version of the BP_Activity_Activity object. 1489 * @return bool 1490 */ 1491 protected function can_comment( $item ) { 1492 $can_comment = true; 1493 1494 if ( $this->disable_blogforum_comments ) { 1495 switch ( $item['type'] ) { 1496 case 'new_blog_post' : 1497 case 'new_blog_comment' : 1498 case 'new_forum_topic' : 1499 case 'new_forum_post' : 1500 $can_comment = false; 1501 break; 1502 } 1503 1504 // activity comments require special checking 1505 } elseif ( 'activity_comment' == $item['type'] ) { 1506 // blogs 1507 if ( bp_is_active( 'blogs' ) ) { 1508 // grab the parent activity entry 1509 $parent_activity = new BP_Activity_Activity( $item['item_id'] ); 1510 1511 // fetch blog post comment depth and if the blog post's comments are open 1512 bp_blogs_setup_activity_loop_globals( $parent_activity ); 1513 1514 // check if the activity item can be replied to 1515 if ( false === bp_blogs_can_comment_reply( true, $item ) ) { 1516 $can_comment = false; 1517 } 1518 } 1519 } 1520 1521 return apply_filters( 'bp_activity_list_table_can_comment', $can_comment ); 1522 } 1523 1524 /** 1448 1525 * Flatten the activity array. 1449 1526 * 1450 1527 * In some cases, BuddyPress gives us a structured tree of activity -
bp-activity/bp-activity-functions.php
1522 1522 * You may want to hook into this filter if you want to override this function and 1523 1523 * handle the deletion of child comments differently. Make sure you return false. 1524 1524 */ 1525 if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) 1526 return false; 1525 if ( ! apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) { 1526 return true; 1527 } 1527 1528 1528 1529 // Delete any children of this comment. 1529 1530 bp_activity_delete_children( $activity_id, $comment_id ); -
bp-activity/bp-activity-template.php
2972 2972 } 2973 2973 2974 2974 /** 2975 * Recurse through all activity comments and return the activity comment IDs. 2976 * 2977 * @since BuddyPress (2.0.0) 2978 * 2979 * @param array $activity Array of activities generated from {@link bp_activity_get()}. 2980 * @return array 2981 */ 2982 function bp_activity_recurse_comments_activity_ids( $activity = array(), $activity_ids = array() ) { 2983 if ( is_array( $activity ) && ! empty( $activity['activities'] ) ) { 2984 $activity = $activity['activities'][0]; 2985 } 2986 2987 if ( ! empty( $activity->children ) ) { 2988 foreach ($activity->children as $child ) { 2989 $activity_ids[] = $child->id; 2990 2991 if( ! empty( $child->children ) ) { 2992 $activity_ids = bp_activity_recurse_comments_activity_ids( $child, $activity_ids ); 2993 } 2994 } 2995 } 2996 2997 return $activity_ids; 2998 } 2999 3000 /** 2975 3001 * Output the mentionname for the displayed user. 2976 3002 * 2977 3003 * @since BuddyPress (1.9.0) -
bp-blogs/bp-blogs-activity.php
345 345 'secondary_item_id' => $secondary_item_id 346 346 ) ); 347 347 } 348 349 /** 350 * Check if a blog post's activity item should be closed from commenting. 351 * 352 * This mirrors the {@link comments_open()} and {@link _close_comments_for_old_post()} 353 * functions, but for use with the BuddyPress activity stream to be as 354 * lightweight as possible. 355 * 356 * By lightweight, we actually mirror a few of the blog's commenting settings 357 * to blogmeta and checks the values in blogmeta instead. This is to prevent 358 * multiple {@link switch_to_blog()} calls in the activity stream. 359 * 360 * @param object $activity The BP_Activity_Activity object 361 * @return bool 362 */ 363 function bp_blogs_comments_open( $activity ) { 364 $open = true; 365 366 $blog_id = $activity->item_id; 367 368 // see if we've mirrored the close comments option before 369 $days_old = bp_blogs_get_blogmeta( $blog_id, 'close_comments_days_old' ); 370 371 // we've never cached these items before, so do it now 372 if ( '' === $days_old ) { 373 switch_to_blog( $blog_id ); 374 375 // use comments_open() 376 remove_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 377 $open = comments_open( $activity->secondary_item_id ); 378 add_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 379 380 // might as well mirror values to blogmeta since we're here! 381 $thread_depth = get_option( 'thread_comments' ); 382 if ( ! empty( $thread_depth ) ) { 383 $thread_depth = get_option( 'thread_comments_depth' ); 384 } else { 385 // perhaps filter this? 386 $thread_depth = 1; 387 } 388 389 bp_blogs_update_blogmeta( $blog_id, 'close_comments_for_old_posts', get_option( 'close_comments_for_old_posts' ) ); 390 bp_blogs_update_blogmeta( $blog_id, 'close_comments_days_old', get_option( 'close_comments_days_old' ) ); 391 bp_blogs_update_blogmeta( $blog_id, 'thread_comments_depth', $thread_depth ); 392 393 restore_current_blog(); 394 395 // check blogmeta and manually check activity item 396 // basically a copy of _close_comments_for_old_post() 397 } else { 398 399 if ( ! bp_blogs_get_blogmeta( $blog_id, 'close_comments_for_old_posts' ) ) { 400 return $open; 401 } 402 403 $days_old = (int) $days_old; 404 if ( ! $days_old ) { 405 return $open; 406 } 407 408 /* commenting out for now - needs some more thought... 409 should we add the post type to activity meta? 410 411 $post = get_post($post_id); 412 413 // This filter is documented in wp-includes/comment.php 414 $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); 415 if ( ! in_array( $post->post_type, $post_types ) ) 416 return $open; 417 */ 418 419 if ( time() - strtotime( $activity->date_recorded ) > ( $days_old * DAY_IN_SECONDS ) ) { 420 return false; 421 } 422 423 return $open; 424 } 425 426 return $open; 427 } 428 429 /** POST COMMENT SYNCHRONIZATION ****************************************/ 430 431 /** 432 * Syncs activity comments and posts them back as blog comments. 433 * 434 * Note: This is only a one-way sync - activity comments -> blog comment. 435 * 436 * For blog post -> activity comment, see {@link bp_blogs_record_comment()}. 437 * 438 * @since BuddyPress (2.0.0) 439 * 440 * @param int $comment_id The activity ID for the posted activity comment. 441 * @param array $params Parameters for the activity comment. 442 * @param object Parameters of the parent activity item (in this case, the blog post). 443 */ 444 function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) { 445 // if parent activity isn't a blog post, stop now! 446 if ( $parent_activity->type != 'new_blog_post' ) { 447 return; 448 } 449 450 // if activity comments are disabled for blog posts, stop now! 451 if ( bp_disable_blogforum_comments() ) { 452 return; 453 } 454 455 // get userdata 456 if ( $params['user_id'] == bp_loggedin_user_id() ) { 457 $user = buddypress()->loggedin_user->userdata; 458 } else { 459 $user = bp_core_get_core_userdata( $params['user_id'] ); 460 } 461 462 // see if a parent WP comment ID exists 463 if ( ! empty( $params['parent_id'] ) ) { 464 $comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' ); 465 } else { 466 $comment_parent = 0; 467 } 468 469 // comment args 470 $args = array( 471 'comment_post_ID' => $parent_activity->secondary_item_id, 472 'comment_author' => bp_core_get_user_displayname( $params['user_id'] ), 473 'comment_author_email' => $user->user_email, 474 'comment_author_url' => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ), 475 'comment_content' => $params['content'], 476 'comment_type' => '', // could be interesting to add 'buddypress' here... 477 'comment_parent' => (int) $comment_parent, 478 'user_id' => $params['user_id'], 479 480 // commenting these out for now 481 //'comment_author_IP' => '127.0.0.1', 482 //'comment_agent' => '', 483 484 'comment_approved' => 1 485 ); 486 487 // prevent separate activity entry being made 488 remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 489 490 // handle multisite 491 switch_to_blog( $parent_activity->item_id ); 492 493 // handle timestamps for the WP comment after we've switched to the blog 494 $args['comment_date'] = current_time( 'mysql' ); 495 $args['comment_date_gmt'] = current_time( 'mysql', 1 ); 496 497 // post the comment 498 $post_comment_id = wp_insert_comment( $args ); 499 500 // add meta to comment 501 add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id ); 502 503 // add meta to activity comment 504 bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id ); 505 506 // resave activity comment with WP comment permalink 507 // 508 // in bp_blogs_activity_comment_permalink(), we change activity comment 509 // permalinks to use the post comment link 510 // 511 // @todo since this is done after AJAX posting, the activity comment permalink 512 // doesn't change on the frontend until the next page refresh. 513 $resave_activity = new BP_Activity_Activity( $comment_id ); 514 $resave_activity->primary_link = get_comment_link( $post_comment_id ); 515 $resave_activity->save(); 516 517 // multisite again! 518 restore_current_blog(); 519 520 // add the comment hook back 521 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 522 523 do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user ); 524 } 525 add_action( 'bp_activity_comment_posted', 'bp_blogs_sync_add_from_activity_comment', 10, 3 ); 526 527 /** 528 * Deletes the blog comment when the associated activity comment is deleted. 529 * 530 * Note: This is hooked on the 'bp_activity_delete_comment_pre' filter instead 531 * of the 'bp_activity_delete_comment' action because we need to fetch the 532 * activity comment children before they are deleted. 533 * 534 * @since BuddyPress (2.0.0) 535 * 536 * @param bool $retval 537 * @param int $parent_activity_id The parent activity ID for the activity comment. 538 * @param int $activity_id The activity ID for the pending deleted activity comment. 539 */ 540 function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) { 541 // check if parent activity is a blog post 542 $parent_activity = new BP_Activity_Activity( $parent_activity_id ); 543 if ( 'new_blog_post' != $parent_activity->type ) { 544 return $retval; 545 } 546 547 // fetch the activity comments for the activity item 548 $activity = bp_activity_get( array( 549 'in' => $activity_id, 550 'display_comments' => 'stream', 551 ) ); 552 553 // get all activity comment IDs for the pending deleted item 554 $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 555 $activity_ids[] = $activity_id; 556 557 // handle multisite 558 // switch to the blog where the comment was made 559 switch_to_blog( $parent_activity->item_id ); 560 561 // remove associated blog comments 562 bp_blogs_remove_associated_blog_comments( $activity_ids, current_user_can( 'moderate_comments' ) ); 563 564 // multisite again! 565 restore_current_blog(); 566 567 // rebuild activity comment tree 568 // emulate bp_activity_delete_comment() 569 BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id ); 570 571 // we're overriding the default bp_activity_delete_comment() functionality 572 // so we need to return false 573 return false; 574 } 575 add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activity_comment', 10, 3 ); 576 577 /** 578 * Updates the blog comment when the associated activity comment is edited. 579 * 580 * @since BuddyPress (2.0.0) 581 * 582 * @param BP_Activity_Activity $activity The activity object. 583 */ 584 function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity ) { 585 // not an activity comment? stop now! 586 if ( 'activity_comment' !== $activity->type ) { 587 return; 588 } 589 590 // this is a new entry, so stop! 591 // we only want edits! 592 if ( empty( $activity->id ) ) { 593 return; 594 } 595 596 // prevent recursion 597 remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 598 599 // Try to see if a corresponding blog comment exists 600 $post_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' ); 601 602 if ( empty( $post_comment_id ) ) { 603 return; 604 } 605 606 // fetch parent activity item 607 $parent_activity = new BP_Activity_Activity( $activity->item_id ); 608 609 // sanity check 610 if ( 'new_blog_post' !== $parent_activity->type ) { 611 return; 612 } 613 614 // handle multisite 615 switch_to_blog( $parent_activity->item_id ); 616 617 // update the blog post comment 618 wp_update_comment( array( 619 'comment_ID' => $post_comment_id, 620 'comment_content' => $activity->content 621 ) ); 622 623 restore_current_blog(); 624 } 625 add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 626 627 /** 628 * When a post is trashed, remove each comment's associated activity meta. 629 * 630 * When a post is trashed and later untrashed, we currently don't reinstate 631 * activity items for these comments since their activity entries are already 632 * deleted when initially trashed. 633 * 634 * Since these activity entries are deleted, we need to remove the deleted 635 * activity comment IDs from each comment's meta when a post is trashed. 636 * 637 * @since BuddyPress (2.0.0) 638 * 639 * @param int $post_id The post ID 640 * @param array $statuses Array of comment statuses. The key is comment ID, the 641 * value is the $comment->comment_approved value. 642 */ 643 function bp_blogs_remove_activity_meta_for_trashed_comments( $post_id, $statuses ) { 644 foreach ( $statuses as $comment_id => $comment_approved ) { 645 delete_comment_meta( $comment_id, 'bp_activity_comment_id' ); 646 } 647 } 648 add_action( 'trashed_post_comments', 'bp_blogs_remove_activity_meta_for_trashed_comments', 10, 2 ); 649 650 /** 651 * Utility function to set up some variables for use in the activity loop. 652 * 653 * Grabs the blog's comment depth and the post's open comment status options 654 * for later use in the activity and activity comment loops. 655 * 656 * This is to prevent having to requery these items later on. 657 * 658 * @since BuddyPress (2.0.0) 659 * 660 * @see bp_blogs_disable_activity_commenting() 661 * @see bp_blogs_setup_comment_loop_globals_on_ajax() 662 * 663 * @param object $activity The BP_Activity_Activity object 664 */ 665 function bp_blogs_setup_activity_loop_globals( $activity ) { 666 if ( ! is_object( $activity ) ) { 667 return; 668 } 669 670 // parent not a blog post? stop now! 671 if ( 'new_blog_post' !== $activity->type ) { 672 return; 673 } 674 675 if ( empty( $activity->id ) ) { 676 return; 677 } 678 679 // if we've already done this before, stop now! 680 if ( isset( buddypress()->blogs->allow_comments[ $activity->id ] ) ) { 681 return; 682 } 683 684 $allow_comments = bp_blogs_comments_open( $activity ); 685 $thread_depth = bp_blogs_get_blogmeta( $activity->item_id, 'thread_comments_depth' ); 686 687 // initialize a local object so we won't have to query this again in the 688 // comment loop 689 if ( empty( buddypress()->blogs->allow_comments ) ) { 690 buddypress()->blogs->allow_comments = array(); 691 } 692 if ( empty( buddypress()->blogs->thread_depth ) ) { 693 buddypress()->blogs->thread_depth = array(); 694 } 695 696 // cache comment settings in the buddypress() singleton to reference later in 697 // the activity comment loop 698 // @see bp_blogs_disable_activity_replies() 699 // 700 // thread_depth is keyed by activity ID instead of blog ID because when we're 701 // in a comment loop, we don't have access to the blog ID... 702 // should probably object cache these values instead... 703 buddypress()->blogs->allow_comments[ $activity->id ] = $allow_comments; 704 buddypress()->blogs->thread_depth[ $activity->id ] = $thread_depth; 705 } 706 707 /** 708 * Set up some globals used in the activity comment loop when AJAX is used. 709 * 710 * @since BuddyPress (2.0.0) 711 * 712 * @see bp_blogs_setup_activity_loop_globals() 713 */ 714 function bp_blogs_setup_comment_loop_globals_on_ajax() { 715 // not AJAX? stop now! 716 if ( ! defined( 'DOING_AJAX' ) ) { 717 return; 718 } 719 if ( false === (bool) constant( 'DOING_AJAX' ) ) { 720 return; 721 } 722 723 // get the parent activity item 724 $comment = bp_activity_current_comment(); 725 $parent_activity = new BP_Activity_Activity( $comment->item_id ); 726 727 // setup the globals 728 bp_blogs_setup_activity_loop_globals( $parent_activity ); 729 } 730 add_action( 'bp_before_activity_comment', 'bp_blogs_setup_comment_loop_globals_on_ajax' ); 731 732 /** 733 * Disable activity commenting for blog posts based on certain criteria. 734 * 735 * If activity commenting is enabled for blog posts, we still need to disable 736 * commenting if: 737 * - comments are disabled for the WP blog post from the admin dashboard 738 * - the WP blog post is supposed to be automatically closed from comments 739 * based on a certain age 740 * - the activity entry is a 'new_blog_comment' type 741 * 742 * @since BuddyPress (2.0.0) 743 * 744 * @param bool $retval Is activity commenting enabled for this activity entry? 745 * @return bool 746 */ 747 function bp_blogs_disable_activity_commenting( $retval ) { 748 // if activity commenting is disabled, return current value 749 if ( bp_disable_blogforum_comments() ) { 750 return $retval; 751 } 752 753 // activity commenting is enabled for blog posts 754 switch ( bp_get_activity_action_name() ) { 755 756 // we still have to disable activity commenting for 'new_blog_comment' items 757 // commenting should only be done on the parent 'new_blog_post' item 758 case 'new_blog_comment' : 759 $retval = false; 760 761 break; 762 763 // check if commenting is disabled for the WP blog post 764 // we should extrapolate this and automate this for plugins... or not 765 case 'new_blog_post' : 766 global $activities_template; 767 768 // setup some globals we'll need to reference later 769 bp_blogs_setup_activity_loop_globals( $activities_template->activity ); 770 771 // if comments are closed for the WP blog post, we should disable 772 // activity comments for this activity entry 773 if ( empty( buddypress()->blogs->allow_comments[bp_get_activity_id()] ) ) { 774 $retval = false; 775 } 776 777 break; 778 } 779 780 return $retval; 781 } 782 add_filter( 'bp_activity_can_comment', 'bp_blogs_disable_activity_commenting' ); 783 784 /** 785 * Check if an activity comment associated with a blog post can be replied to. 786 * 787 * By default, disables replying to activity comments if the corresponding WP 788 * blog post no longer accepts comments. 789 * 790 * This check uses a locally-cached value set in {@link bp_blogs_disable_activity_commenting()} 791 * via {@link bp_blogs_setup_activity_loop_globals()}. 792 * 793 * @since BuddyPress (2.0.0) 794 * 795 * @param bool $retval Are replies allowed for this activity reply? 796 * @param object $comment The activity comment object 797 * @return bool 798 */ 799 function bp_blogs_can_comment_reply( $retval, $comment ) { 800 if ( is_array( $comment ) ) { 801 $comment = (object) $comment; 802 } 803 804 // check comment depth and disable if depth is too large 805 if ( isset( buddypress()->blogs->thread_depth[$comment->item_id] ) ){ 806 if ( $comment->mptt_left > buddypress()->blogs->thread_depth[$comment->item_id] ) { 807 $retval = false; 808 } 809 } 810 811 // check if we should disable activity replies based on the parent activity 812 if ( isset( buddypress()->blogs->allow_comments[$comment->item_id] ) ){ 813 // the blog post has closed off commenting, so we should disable all activity 814 // comments under the parent 'new_blog_post' activity entry 815 if ( empty( buddypress()->blogs->allow_comments[$comment->item_id] ) ) { 816 $retval = false; 817 } 818 } 819 820 return $retval; 821 } 822 add_filter( 'bp_activity_can_comment_reply', 'bp_blogs_can_comment_reply', 10, 2 ); 823 824 /** 825 * Changes activity comment permalinks to use the blog comment permalink 826 * instead of the activity permalink. 827 * 828 * This is only done if activity commenting is allowed and whether the parent 829 * activity item is a 'new_blog_post' entry. 830 * 831 * @since BuddyPress (2.0.0) 832 * 833 * @param string $retval The activity comment permalink 834 * @return string 835 */ 836 function bp_blogs_activity_comment_permalink( $retval ) { 837 global $activities_template; 838 839 if ( isset( buddypress()->blogs->allow_comments[$activities_template->activity->current_comment->item_id] ) ){ 840 $retval = $activities_template->activity->current_comment->primary_link; 841 } 842 843 return $retval; 844 } 845 add_filter( 'bp_get_activity_comment_permalink', 'bp_blogs_activity_comment_permalink' ); -
bp-blogs/bp-blogs-functions.php
182 182 if ( !bp_blogs_is_blog_recordable( $blog_id, $user_id ) ) 183 183 return false; 184 184 185 $url = get_home_url( $blog_id ); 186 $name = get_blog_option( $blog_id, 'blogname' ); 187 $description = get_blog_option( $blog_id, 'blogdescription' ); 185 $name = get_blog_option( $blog_id, 'blogname' ); 188 186 189 if ( empty( $name ) ) 187 if ( empty( $name ) ) { 190 188 return false; 189 } 190 191 $url = get_home_url( $blog_id ); 192 $description = get_blog_option( $blog_id, 'blogdescription' ); 193 $close_old_posts = get_blog_option( $blog_id, 'close_comments_for_old_posts' ); 194 $close_days_old = get_blog_option( $blog_id, 'close_comments_days_old' ); 195 196 $thread_depth = get_blog_option( $blog_id, 'thread_comments' ); 197 if ( ! empty( $thread_depth ) ) { 198 $thread_depth = get_blog_option( $blog_id, 'thread_comments_depth' ); 199 } else { 200 // perhaps filter this? 201 $thread_depth = 1; 202 } 191 203 192 204 $recorded_blog = new BP_Blogs_Blog; 193 205 $recorded_blog->user_id = $user_id; … … 199 211 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name ); 200 212 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description ); 201 213 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() ); 214 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_for_old_posts', $close_old_posts ); 215 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_days_old', $close_days_old ); 216 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'thread_comments_depth', $thread_depth ); 202 217 203 218 $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true; 204 219 $is_private = !apply_filters( 'bp_is_new_blog_public', !$is_private ); … … 252 267 add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 ); 253 268 254 269 /** 270 * Update "Close comments for old posts" option in BuddyPress blogmeta table. 271 * 272 * @since BuddyPress (2.0.0) 273 * 274 * @global object $wpdb DB Layer. 275 * 276 * @param string $oldvalue Value before save. Passed by do_action() but 277 * unused here. 278 * @param string $newvalue Value to change meta to. 279 */ 280 function bp_blogs_update_option_close_comments_for_old_posts( $oldvalue, $newvalue ) { 281 global $wpdb; 282 283 bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_for_old_posts', $newvalue ); 284 } 285 add_action( 'update_option_close_comments_for_old_posts', 'bp_blogs_update_option_close_comments_for_old_posts', 10, 2 ); 286 287 /** 288 * Update "Close comments after days old" option in BuddyPress blogmeta table. 289 * 290 * @since BuddyPress (2.0.0) 291 * 292 * @global object $wpdb DB Layer. 293 * 294 * @param string $oldvalue Value before save. Passed by do_action() but 295 * unused here. 296 * @param string $newvalue Value to change meta to. 297 */ 298 function bp_blogs_update_option_close_close_comments_days_old( $oldvalue, $newvalue ) { 299 global $wpdb; 300 301 bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_days_old', $newvalue ); 302 } 303 add_action( 'update_option_close_comments_days_old', 'bp_blogs_update_option_close_comments_days_old', 10, 2 ); 304 305 /** 306 * When toggling threaded comments, update thread depth in blogmeta table. 307 * 308 * @since BuddyPress (2.0.0) 309 * 310 * @global object $wpdb DB Layer. 311 * 312 * @param string $oldvalue Value before save. Passed by do_action() but 313 * unused here. 314 * @param string $newvalue Value to change meta to. 315 */ 316 function bp_blogs_update_option_thread_comments( $oldvalue, $newvalue ) { 317 global $wpdb; 318 319 if ( empty( $newvalue ) ) { 320 $thread_depth = 1; 321 } else { 322 $thread_depth = get_option( 'thread_comments_depth' ); 323 } 324 325 bp_blogs_update_blogmeta( $wpdb->blogid, 'thread_comments_depth', $thread_depth ); 326 } 327 add_action( 'update_option_thread_comments', 'bp_blogs_update_option_thread_comments', 10, 2 ); 328 329 /** 330 * When updating comment depth, update thread depth in blogmeta table. 331 * 332 * @since BuddyPress (2.0.0) 333 * 334 * @global object $wpdb DB Layer. 335 * 336 * @param string $oldvalue Value before save. Passed by do_action() but 337 * unused here. 338 * @param string $newvalue Value to change meta to. 339 */ 340 function bp_blogs_update_option_thread_comments_depth( $oldvalue, $newvalue ) { 341 global $wpdb; 342 343 $comments_enabled = get_option( 'thread_comments' ); 344 345 if ( $comments_enabled ) { 346 bp_blogs_update_blogmeta( $wpdb->blogid, 'thread_comments_depth', $newvalue ); 347 } 348 } 349 add_action( 'update_option_thread_comments_depth', 'bp_blogs_update_option_thread_comments_depth', 10, 2 ); 350 351 /** 255 352 * Detect a change in post status, and initiate an activity update if necessary. 256 353 * 257 354 * Posts get new activity updates when (a) they are being published, and (b) … … 262 359 * 263 360 * @since BuddyPress (2.0.0) 264 361 * 362 * @todo Support untrashing better 363 * 265 364 * @param string $new_status New status for the post. 266 365 * @param string $old_status Old status for the post. 267 366 * @param object $post Post data. … … 275 374 276 375 // Publishing a previously unpublished post 277 376 if ( 'publish' === $new_status ) { 278 return bp_blogs_record_post( $post->ID, $post ); 377 // Untrashing the post 378 // Nothing here yet 379 if ( 'trash' == $old_status ) {} 380 381 // Record the post 382 bp_blogs_record_post( $post->ID, $post ); 279 383 280 384 // Unpublishing a previously published post 281 385 } else if ( 'publish' === $old_status ) { 282 return bp_blogs_remove_post( $post->ID ); 386 // Some form of pending status 387 // Only remove the activity entry 388 bp_blogs_delete_activity( array( 389 'item_id' => get_current_blog_id(), 390 'secondary_item_id' => $post->ID, 391 'component' => buddypress()->blogs->id, 392 'type' => 'new_blog_post' 393 ) ); 283 394 } 284 395 } 285 396 add_action( 'transition_post_status', 'bp_blogs_catch_transition_post_status', 10, 3 ); … … 369 480 370 481 // Update the blogs last activity 371 482 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() ); 372 } else {373 bp_blogs_remove_post( $post_id, $blog_id, $user_id );374 483 } 375 484 376 485 do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id ); … … 441 550 $post_permalink = get_permalink( $recorded_comment->comment_post_ID ); 442 551 $comment_link = get_comment_link( $recorded_comment->comment_ID ); 443 552 444 // Prepare to record in activity streams 445 if ( is_multisite() ) 446 $activity_action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ); 447 else 448 $activity_action = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' ); 553 // Setup activity args 554 $args = array(); 555 556 $args['user_id'] = $user_id; 557 $args['content'] = apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $recorded_comment->comment_content, &$recorded_comment, $comment_link ) ); 558 $args['primary_link'] = apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$recorded_comment ) ); 559 $args['recorded_time'] = $recorded_comment->comment_date_gmt; 560 561 // Setup some different activity args depending if activity commenting is 562 // enabled or not 563 564 // if cannot comment, record separate activity entry 565 // this is the old way of doing things 566 if ( bp_disable_blogforum_comments() ) { 567 $args['type'] = 'new_blog_comment'; 568 $args['item_id'] = $blog_id; 569 $args['secondary_item_id'] = $comment_id; 570 571 // record the activity entry 572 bp_blogs_record_activity( $args ); 573 574 // record comment as BP activity comment under the parent 'new_blog_post' 575 // activity item 576 } else { 577 // this is a comment edit 578 // check to see if corresponding activity entry already exists 579 if ( ! empty( $_REQUEST['action'] ) ) { 580 $existing_activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 581 582 if ( ! empty( $existing_activity_id ) ) { 583 $args['id'] = $existing_activity_id; 584 } 585 } 449 586 450 $activity_content = $recorded_comment->comment_content; 587 // find the parent 'new_blog_post' activity entry 588 $parent_activity_id = bp_activity_get_activity_id( array( 589 'user_id' => $user_id, 590 'component' => 'blogs', 591 'type' => 'new_blog_post', 592 'item_id' => $blog_id, 593 'secondary_item_id' => $recorded_comment->comment_post_ID 594 ) ); 595 596 // we found the parent activity entry 597 // so let's go ahead and reconfigure some activity args 598 if ( ! empty( $parent_activity_id ) ) { 599 // set the 'item_id' with the parent activity entry ID 600 $args['item_id'] = $parent_activity_id; 601 602 // now see if the WP parent comment has a BP activity ID 603 $comment_parent = 0; 604 if ( ! empty( $recorded_comment->comment_parent ) ) { 605 $comment_parent = get_comment_meta( $recorded_comment->comment_parent, 'bp_activity_comment_id', true ); 606 } 451 607 452 // Record in activity streams 453 bp_blogs_record_activity( array( 454 'user_id' => $user_id, 455 'content' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $activity_content, &$recorded_comment, $comment_link ) ), 456 'primary_link' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$recorded_comment ) ), 457 'type' => 'new_blog_comment', 458 'item_id' => $blog_id, 459 'secondary_item_id' => $comment_id, 460 'recorded_time' => $recorded_comment->comment_date_gmt 461 ) ); 608 // WP parent comment does not have a BP activity ID 609 // so set to 'new_blog_post' activity ID 610 if ( empty( $comment_parent ) ) { 611 $comment_parent = $parent_activity_id; 612 } 613 614 $args['secondary_item_id'] = $comment_parent; 615 $args['component'] = 'activity'; 616 $args['type'] = 'activity_comment'; 617 618 // could not find corresponding parent activity entry 619 // so wipe out $args array 620 } else { 621 $args = array(); 622 } 623 624 // Record in activity streams 625 if ( ! empty( $args ) ) { 626 // @todo should we use bp_activity_new_comment()? that function will also send 627 // an email to people in the activity comment thread 628 // 629 // what if a site already has some comment email notification plugin setup? 630 // this is why I decided to go with bp_activity_add() to avoid any conflict 631 // with existing comment email notification plugins 632 $comment_activity_id = bp_activity_add( $args ); 633 634 if ( empty( $args['id'] ) ) { 635 // add meta to activity comment 636 bp_activity_update_meta( $comment_activity_id, 'bp_blogs_post_comment_id', $comment_id ); 637 638 // add meta to comment 639 add_comment_meta( $comment_id, 'bp_activity_comment_id', $comment_activity_id ); 640 } 641 } 642 } 462 643 463 644 // Update the blogs last active date 464 645 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() ); … … 632 813 function bp_blogs_remove_comment( $comment_id ) { 633 814 global $wpdb; 634 815 635 // Delete activity stream item 636 bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) ); 816 // activity comments are disabled for blog posts 817 // which means that individual activity items exist for blog comments 818 if ( bp_disable_blogforum_comments() ) { 819 // Delete the individual activity stream item 820 bp_blogs_delete_activity( array( 821 'item_id' => $wpdb->blogid, 822 'secondary_item_id' => $comment_id, 823 'type' => 'new_blog_comment' 824 ) ); 825 826 // activity comments are enabled for blog posts 827 // remove the associated activity item 828 } else { 829 // get associated activity ID from comment meta 830 $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 831 832 // delete the associated activity comment 833 // 834 // also removes child post comments and associated activity comments 835 if ( ! empty( $activity_id ) && bp_is_active( 'activity' ) ) { 836 // fetch the activity comments for the activity item 837 $activity = bp_activity_get( array( 838 'in' => $activity_id, 839 'display_comments' => 'stream', 840 ) ); 841 842 // get all activity comment IDs for the pending deleted item 843 if ( ! empty( $activity['activities'] ) ) { 844 $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 845 $activity_ids[] = $activity_id; 846 847 // delete activity items 848 foreach ( $activity_ids as $activity_id ) { 849 bp_activity_delete( array( 850 'id' => $activity_id 851 ) ); 852 } 853 854 // remove associated blog comments 855 bp_blogs_remove_associated_blog_comments( $activity_ids ); 856 857 // rebuild activity comment tree 858 BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id ); 859 } 860 } 861 } 637 862 638 863 do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() ); 639 864 } 640 865 add_action( 'delete_comment', 'bp_blogs_remove_comment' ); 641 866 642 867 /** 868 * Removes blog comments that are associated with activity comments. 869 * 870 * @since BuddyPress (2.0.0) 871 * 872 * @see bp_blogs_remove_comment() 873 * @see bp_blogs_sync_delete_from_activity_comment() 874 * 875 * @param array $activity_ids The activity IDs to check association with blog 876 * comments. 877 * @param bool $force_delete Whether to force delete the comments. If false, 878 * comments are trashed instead. 879 */ 880 function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $force_delete = true ) { 881 // query args 882 $query_args = array( 883 'meta_query' => array( 884 array( 885 'key' => 'bp_activity_comment_id', 886 'value' => implode( ',', (array) $activity_ids ), 887 'compare' => 'IN', 888 ) 889 ) 890 ); 891 892 // get comment 893 $comment_query = new WP_Comment_Query; 894 $comments = $comment_query->query( $query_args ); 895 896 // found the corresponding comments 897 // let's delete them! 898 foreach ( $comments as $comment ) { 899 wp_delete_comment( $comment->comment_ID, $force_delete ); 900 901 // if we're trashing the comment, remove the meta key as well 902 if ( empty( $force_delete ) ) { 903 delete_comment_meta( $comment->comment_ID, 'bp_activity_comment_id' ); 904 } 905 } 906 } 907 908 /** 643 909 * When a blog comment status transition occurs, update the relevant activity's status. 644 910 * 645 911 * @since BuddyPress (1.6.0) … … 667 933 */ 668 934 669 935 // This clause was moved in from bp_blogs_remove_comment() in BuddyPress 1.6. It handles delete/hold. 670 if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) 936 if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) { 671 937 return bp_blogs_remove_comment( $comment->comment_ID ); 672 938 673 939 // These clauses handle trash, spam, and un-spams. 674 elseif ( in_array( $new_status, array( 'trash', 'spam' ) ) )940 } elseif ( in_array( $new_status, array( 'trash', 'spam' ) ) ) { 675 941 $action = 'spam_activity'; 676 elseif ( 'approved' == $new_status )942 } elseif ( 'approved' == $new_status ) { 677 943 $action = 'ham_activity'; 944 } 678 945 679 946 // Get the activity 680 $activity_id = bp_activity_get_activity_id( array( 'component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment', ) ); 947 if ( bp_disable_blogforum_comments() ) { 948 $activity_id = bp_activity_get_activity_id( array( 'component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment', ) ); 949 } else { 950 $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ); 951 } 681 952 682 953 // Check activity item exists 683 if ( ! $activity_id ) { 684 954 if ( empty( $activity_id ) ) { 685 955 // If no activity exists, but the comment has been approved, record it into the activity table. 686 if ( 'approved' == $new_status ) 956 if ( 'approved' == $new_status ) { 687 957 return bp_blogs_record_comment( $comment->comment_ID, true ); 958 } 688 959 689 960 return; 690 961 } -
bp-core/bp-core-options.php
226 226 * @return mixed The value for the option. 227 227 */ 228 228 function bp_get_option( $option_name, $default = '' ) { 229 $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default ); 229 // check buddypress()->site_options array first 230 if ( isset( buddypress()->site_options[$option_name] ) ) { 231 $value = buddypress()->site_options[$option_name]; 232 233 // query for the option if not available 234 } else { 235 $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default ); 236 } 230 237 231 238 return apply_filters( 'bp_get_option', $value ); 232 239 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)