Ticket #5130: 5130.03.patch
| File 5130.03.patch, 43.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_comment' : 1497 case 'new_forum_post' : 1498 $can_comment = false; 1499 break; 1500 } 1501 } 1502 1503 // activity comments require special checking 1504 if ( 'activity_comment' == $item['type'] ) { 1505 // blogs 1506 if ( bp_is_active( 'blogs' ) ) { 1507 // grab the parent activity entry 1508 $parent_activity = new BP_Activity_Activity( $item['item_id'] ); 1509 1510 // fetch blog post comment depth and if the blog post's comments are open 1511 bp_blogs_setup_activity_loop_globals( array( 1512 'blog_id' => $parent_activity->item_id, 1513 'post_id' => $parent_activity->secondary_item_id, 1514 'type' => $parent_activity->type, 1515 'id' => $parent_activity->id 1516 ) ); 1517 1518 // check if the activity item can be replied to 1519 if ( false === bp_blogs_can_comment_reply( true, $item ) ) { 1520 $can_comment = false; 1521 } 1522 1523 } 1524 1525 } 1526 1527 return apply_filters( 'bp_activity_list_table_can_comment', $can_comment ); 1528 } 1529 1530 /** 1448 1531 * Flatten the activity array. 1449 1532 * 1450 1533 * In some cases, BuddyPress gives us a structured tree of activity -
bp-activity/bp-activity-functions.php
1507 1507 * You may want to hook into this filter if you want to override this function and 1508 1508 * handle the deletion of child comments differently. Make sure you return false. 1509 1509 */ 1510 if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) 1511 return false; 1510 if ( ! apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) { 1511 return true; 1512 } 1512 1513 1513 1514 // Delete any children of this comment. 1514 1515 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 * Deletes associated post comments when a blog post is deleted. 351 * 352 * Currently, this also occurs if the blog post is *trashed* because 353 * {@link bp_blogs_transition_activity_status()} doesn't support trash / untrash 354 * routines. 355 * 356 * This function will be removed once bp_blogs_transition_activity_status() is 357 * modified to work with trash / untrash post statuses. 358 * 359 * @since BuddyPress (2.0.0) 360 * 361 * @param int $blog_id The blog ID 362 * @param int $post_id The post ID 363 */ 364 function bp_blogs_sync_delete_post_comments_on_post_delete( $blog_id, $post_id ) { 365 // get the activity ID for the blog post 366 $post_activity_id = bp_activity_get_activity_id( array( 367 'component' => buddypress()->blogs->id, 368 'item_id' => $blog_id, 369 'secondary_item_id' => $post_id, 370 'type' => 'new_blog_post', 371 ) ); 372 373 // fetch the activity comments for the activity item 374 $activity_comments = bp_activity_get( array( 375 'in' => $post_activity_id, 376 'display_comments' => 'stream', 377 ) ); 378 379 // get all activity comment IDs for the pending deleted item 380 $activity_ids = bp_activity_recurse_comments_activity_ids( $activity_comments ); 381 382 if ( empty( $activity_ids ) ) { 383 return; 384 } 385 386 // handle multisite 387 // switch to the blog where the comment was made 388 switch_to_blog( $blog_id ); 389 390 // remove associated blog comments 391 bp_blogs_remove_associated_blog_comments( $activity_ids ); 392 393 // multisite again! 394 restore_current_blog(); 395 } 396 add_action( 'bp_blogs_before_remove_post', 'bp_blogs_sync_delete_post_comments_on_post_delete', 10, 2 ); 397 398 /** 399 * Syncs activity comments and posts them back as blog comments. 400 * 401 * Note: This is only a one-way sync - activity comments -> blog comment. 402 * 403 * For blog post -> activity comment, see {@link bp_blogs_record_comment()}. 404 * 405 * @since BuddyPress (2.0.0) 406 * 407 * @param int $comment_id The activity ID for the posted activity comment. 408 * @param array $params Parameters for the activity comment. 409 * @param object Parameters of the parent activity item (in this case, the blog post). 410 */ 411 function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) { 412 // if parent activity isn't a blog post, stop now! 413 if ( $parent_activity->type != 'new_blog_post' ) { 414 return; 415 } 416 417 // if activity comments are disabled for blog posts, stop now! 418 if ( bp_disable_blogforum_comments() ) { 419 return; 420 } 421 422 // get userdata 423 if ( $params['user_id'] == bp_loggedin_user_id() ) { 424 $user = buddypress()->loggedin_user->userdata; 425 } else { 426 $user = bp_core_get_core_userdata( $params['user_id'] ); 427 } 428 429 // see if a parent WP comment ID exists 430 if ( ! empty( $params['parent_id'] ) ) { 431 $comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' ); 432 } else { 433 $comment_parent = 0; 434 } 435 436 // comment args 437 $args = array( 438 'comment_post_ID' => $parent_activity->secondary_item_id, 439 'comment_author' => bp_core_get_user_displayname( $params['user_id'] ), 440 'comment_author_email' => $user->user_email, 441 'comment_author_url' => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ), 442 'comment_content' => $params['content'], 443 'comment_type' => '', // could be interesting to add 'buddypress' here... 444 'comment_parent' => (int) $comment_parent, 445 'user_id' => $params['user_id'], 446 447 // commenting these out for now 448 //'comment_author_IP' => '127.0.0.1', 449 //'comment_agent' => '', 450 451 'comment_approved' => 1 452 ); 453 454 // prevent separate activity entry being made 455 remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 456 457 // handle multisite 458 switch_to_blog( $parent_activity->item_id ); 459 460 // handle timestamps for the WP comment after we've switched to the blog 461 $args['comment_date'] = current_time( 'mysql' ); 462 $args['comment_date_gmt'] = current_time( 'mysql', 1 ); 463 464 // post the comment 465 $post_comment_id = wp_insert_comment( $args ); 466 467 // add meta to comment 468 add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id ); 469 470 // add meta to activity comment 471 bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id ); 472 473 // resave activity comment with WP comment permalink 474 // 475 // in bp_blogs_activity_comment_permalink(), we change activity comment 476 // permalinks to use the post comment link 477 // 478 // @todo since this is done after AJAX posting, the activity comment permalink 479 // doesn't change on the frontend until the next page refresh. 480 $resave_activity = new BP_Activity_Activity( $comment_id ); 481 $resave_activity->primary_link = get_comment_link( $post_comment_id ); 482 $resave_activity->save(); 483 484 // multisite again! 485 restore_current_blog(); 486 487 // add the comment hook back 488 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 489 490 do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user ); 491 } 492 493 /** 494 * Deletes the blog comment when the associated activity comment is deleted. 495 * 496 * Note: This is hooked on the 'bp_activity_delete_comment_pre' filter instead 497 * of the 'bp_activity_delete_comment' action because we need to fetch the 498 * activity comment children before they are deleted. 499 * 500 * @since BuddyPress (2.0.0) 501 * 502 * @param bool $retval 503 * @param int $parent_activity_id The parent activity ID for the activity comment. 504 * @param int $activity_id The activity ID for the pending deleted activity comment. 505 */ 506 function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) { 507 // check if parent activity is a blog post 508 $parent_activity = new BP_Activity_Activity( $parent_activity_id ); 509 if ( 'new_blog_post' != $parent_activity->type ) { 510 return $retval; 511 } 512 513 // fetch the activity comments for the activity item 514 $activity = bp_activity_get( array( 515 'in' => $activity_id, 516 'display_comments' => 'stream', 517 ) ); 518 519 // get all activity comment IDs for the pending deleted item 520 $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 521 $activity_ids[] = $activity_id; 522 523 // handle multisite 524 // switch to the blog where the comment was made 525 switch_to_blog( $parent_activity->item_id ); 526 527 // remove associated blog comments 528 bp_blogs_remove_associated_blog_comments( $activity_ids ); 529 530 // multisite again! 531 restore_current_blog(); 532 533 // rebuild activity comment tree 534 // emulate bp_activity_delete_comment() 535 BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id ); 536 537 // we're overriding the default bp_activity_delete_comment() functionality 538 // so we need to return false 539 return false; 540 } 541 542 /** 543 * Updates the blog comment when the associated activity comment is edited. 544 * 545 * @since BuddyPress (2.0.0) 546 * 547 * @param BP_Activity_Activity $activity The activity object. 548 */ 549 function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity ) { 550 // not an activity comment? stop now! 551 if ( 'activity_comment' !== $activity->type ) { 552 return; 553 } 554 555 // this is an existing entry, so stop! 556 // we only want edits! 557 if ( empty( $activity->id ) ) { 558 return; 559 } 560 561 // prevent recursion 562 remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 563 564 // Try to see if a corresponding blog comment exists 565 $post_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' ); 566 567 if ( empty( $post_comment_id ) ) { 568 return; 569 } 570 571 // fetch parent activity item 572 $parent_activity = new BP_Activity_Activity( $activity->item_id ); 573 574 // sanity check 575 if ( 'new_blog_post' !== $parent_activity->type ) { 576 return; 577 } 578 579 // handle multisite 580 switch_to_blog( $parent_activity->item_id ); 581 582 // update the blog post comment 583 wp_update_comment( array( 584 'comment_ID' => $post_comment_id, 585 'comment_content' => $activity->content 586 ) ); 587 588 restore_current_blog(); 589 } 590 add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 591 592 /** 593 * Utility function to set up some variables for use in the activity loop. 594 * 595 * Grabs the blog's comment depth and the post's open comment status options 596 * for later use in the activity and activity comment loops. 597 * 598 * This is to prevent having to requery these items later on. 599 * 600 * @since BuddyPress (2.0.0) 601 * 602 * @see bp_blogs_disable_activity_commenting() 603 * @see bp_blogs_setup_comment_loop_globals_on_ajax() 604 * 605 * @param array $r { 606 * @type int $blog_id The blog ID to check. 607 * @type int $post_id The post ID to check. 608 * @type string $type The activity type to check. 609 * } 610 */ 611 function bp_blogs_setup_activity_loop_globals( $r = array() ) { 612 if ( empty( $r['blog_id'] ) || empty( $r['post_id'] ) || empty( $r['type'] ) ) { 613 return; 614 } 615 616 // parent not a blog post? stop now! 617 if ( 'new_blog_post' !== $r['type'] ) { 618 return; 619 } 620 621 if ( empty( $r['id'] ) ) { 622 $r['id'] = bp_get_activity_id(); 623 } 624 625 // if we've already done this before, stop now! 626 if ( isset( buddypress()->blogs->allow_comments[ $r['id'] ] ) ) { 627 return; 628 } 629 630 // BP's 'comments_open' filter trumps all! 631 // so we have to remove it temporarily 632 remove_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 633 634 // handle multisite 635 switch_to_blog( $r['blog_id'] ); 636 637 // check if the WP post allows comments 638 // this also checks if comments should be closed based on age if enabled 639 $allow_comments = comments_open( $r['post_id'] ); 640 641 // check the comment thread depth for the blog 642 $thread_depth = (int) get_option( 'thread_comments' ); 643 if ( ! empty( $thread_depth ) ) { 644 $thread_depth = get_option( 'thread_comments_depth' ); 645 } else { 646 $thread_depth = 1; 647 } 648 649 restore_current_blog(); 650 651 // reinstate BP's comment filter 652 add_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 653 654 // initialize a local object so we won't have to query this again in the 655 // comment loop 656 if ( empty( buddypress()->blogs->allow_comments ) ) { 657 buddypress()->blogs->allow_comments = array(); 658 } 659 if ( empty( buddypress()->blogs->thread_depth ) ) { 660 buddypress()->blogs->thread_depth = array(); 661 } 662 663 // cache comment settings in the buddypress() singleton to reference later in 664 // the activity comment loop 665 // @see bp_blogs_disable_activity_replies() 666 // 667 // thread_depth is keyed by activity ID instead of blog ID because when we're 668 // in a comment loop, we don't have access to the blog ID... 669 // should probably object cache these values instead... 670 buddypress()->blogs->allow_comments[ $r['id'] ] = $allow_comments; 671 buddypress()->blogs->thread_depth[ $r['id'] ] = $thread_depth; 672 } 673 674 /** 675 * Set up some globals used in the activity comment loop when AJAX is used. 676 * 677 * @since BuddyPress (2.0.0) 678 * 679 * @see bp_blogs_setup_activity_loop_globals() 680 */ 681 function bp_blogs_setup_comment_loop_globals_on_ajax() { 682 // not AJAX? stop now! 683 if ( ! defined( 'DOING_AJAX' ) ) { 684 return; 685 } 686 if ( false === (bool) constant( 'DOING_AJAX' ) ) { 687 return; 688 } 689 690 // get the parent activity item 691 $comment = bp_activity_current_comment(); 692 $parent_activity = new BP_Activity_Activity( $comment->item_id ); 693 694 // setup the globals 695 bp_blogs_setup_activity_loop_globals( array( 696 'blog_id' => $parent_activity->item_id, 697 'post_id' => $parent_activity->secondary_item_id, 698 'type' => $parent_activity->type, 699 ) ); 700 } 701 add_action( 'bp_before_activity_comment', 'bp_blogs_setup_comment_loop_globals_on_ajax' ); 702 703 /** 704 * Disable activity commenting for blog posts based on certain criteria. 705 * 706 * If activity commenting is enabled for blog posts, we still need to disable 707 * commenting if: 708 * - comments are disabled for the WP blog post from the admin dashboard 709 * - the WP blog post is supposed to be automatically closed from comments 710 * based on a certain age 711 * - the activity entry is a 'new_blog_comment' type 712 * 713 * @since BuddyPress (2.0.0) 714 * 715 * @param bool $retval Is activity commenting enabled for this activity entry? 716 * @return bool 717 */ 718 function bp_blogs_disable_activity_commenting( $retval ) { 719 // if activity commenting is disabled, return current value 720 if ( bp_disable_blogforum_comments() ) { 721 return $retval; 722 } 723 724 // activity commenting is enabled for blog posts 725 switch ( bp_get_activity_action_name() ) { 726 727 // we still have to disable activity commenting for 'new_blog_comment' items 728 // commenting should only be done on the parent 'new_blog_post' item 729 case 'new_blog_comment' : 730 $retval = false; 731 732 break; 733 734 // check if commenting is disabled for the WP blog post 735 // we should extrapolate this and automate this for plugins... or not 736 case 'new_blog_post' : 737 738 // setup some globals we'll need to reference later 739 bp_blogs_setup_activity_loop_globals( array( 740 'blog_id' => bp_get_activity_item_id(), 741 'post_id' => bp_get_activity_secondary_item_id(), 742 'type' => bp_get_activity_action_name(), 743 ) ); 744 745 // if comments are closed for the WP blog post, we should disable 746 // activity comments for this activity entry 747 if ( empty( buddypress()->blogs->allow_comments[bp_get_activity_id()] ) ) { 748 $retval = false; 749 } 750 751 break; 752 } 753 754 return $retval; 755 } 756 add_filter( 'bp_activity_can_comment', 'bp_blogs_disable_activity_commenting' ); 757 758 /** 759 * Check if an activity comment associated with a blog post can be replied to. 760 * 761 * By default, disables replying to activity comments if the corresponding WP 762 * blog post no longer accepts comments. 763 * 764 * This check uses a locally-cached value set in {@link bp_blogs_disable_activity_commenting()} 765 * via {@link bp_blogs_setup_activity_loop_globals()}. 766 * 767 * @since BuddyPress (2.0.0) 768 * 769 * @param bool $retval Are replies allowed for this activity reply? 770 * @param object $comment The activity comment object 771 * @return bool 772 */ 773 function bp_blogs_can_comment_reply( $retval, $comment ) { 774 if ( is_array( $comment ) ) { 775 $comment = (object) $comment; 776 } 777 778 // check comment depth and disable if depth is too large 779 if ( isset( buddypress()->blogs->thread_depth[$comment->item_id] ) ){ 780 if ( $comment->mptt_left > buddypress()->blogs->thread_depth[$comment->item_id] ) { 781 $retval = false; 782 } 783 } 784 785 // check if we should disable activity replies based on the parent activity 786 if ( isset( buddypress()->blogs->allow_comments[$comment->item_id] ) ){ 787 // the blog post has closed off commenting, so we should disable all activity 788 // comments under the parent 'new_blog_post' activity entry 789 if ( empty( buddypress()->blogs->allow_comments[$comment->item_id] ) ) { 790 $retval = false; 791 } 792 } 793 794 return $retval; 795 } 796 add_filter( 'bp_activity_can_comment_reply', 'bp_blogs_can_comment_reply', 10, 2 ); 797 798 /** 799 * Changes activity comment permalinks to use the blog comment permalink 800 * instead of the activity permalink. 801 * 802 * This is only done if activity commenting is allowed and whether the parent 803 * activity item is a 'new_blog_post' entry. 804 * 805 * @since BuddyPress (2.0.0) 806 * 807 * @param string $retval The activity comment permalink 808 * @return string 809 */ 810 function bp_blogs_activity_comment_permalink( $retval ) { 811 global $activities_template; 812 813 if ( isset( buddypress()->blogs->allow_comments[$activities_template->activity->current_comment->item_id] ) ){ 814 $retval = $activities_template->activity->current_comment->primary_link; 815 } 816 817 return $retval; 818 } 819 add_filter( 'bp_get_activity_comment_permalink', 'bp_blogs_activity_comment_permalink' ); -
bp-blogs/bp-blogs-functions.php
262 262 * 263 263 * @since BuddyPress (2.0.0) 264 264 * 265 * @todo Support trashing / untrashing similar to bp_blogs_transition_activity_status() 266 * for post comments. 267 * 265 268 * @param string $new_status New status for the post. 266 269 * @param string $old_status Old status for the post. 267 270 * @param object $post Post data. … … 441 444 $post_permalink = get_permalink( $recorded_comment->comment_post_ID ); 442 445 $comment_link = get_comment_link( $recorded_comment->comment_ID ); 443 446 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>' ); 447 // Setup activity args 448 $args = array(); 449 449 450 $activity_content = $recorded_comment->comment_content; 450 $args['user_id'] = $user_id; 451 $args['content'] = apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $recorded_comment->comment_content, &$recorded_comment, $comment_link ) ); 452 $args['primary_link'] = apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$recorded_comment ) ); 453 $args['recorded_time'] = $recorded_comment->comment_date_gmt; 451 454 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 ) ); 455 if ( is_multisite() ) { 456 $args['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>' ); 457 } else { 458 $args['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>' ); 459 } 460 461 // Setup some different activity args depending if activity commenting is 462 // enabled or not 463 464 // if cannot comment, record separate activity entry 465 // this is the old way of doing things 466 if ( bp_disable_blogforum_comments() ) { 467 $args['type'] = 'new_blog_comment'; 468 $args['item_id'] = $blog_id; 469 $args['secondary_item_id'] = $comment_id; 470 471 // record the activity entry 472 bp_blogs_record_activity( $args ); 473 474 // record comment as BP activity comment under the parent 'new_blog_post' 475 // activity item 476 } else { 477 // this is a comment edit 478 // check to see if corresponding activity entry already exists 479 if ( ! empty( $_REQUEST['action'] ) ) { 480 $existing_activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 481 482 if ( ! empty( $existing_activity_id ) ) { 483 $args['id'] = $existing_activity_id; 484 } 485 } 486 487 // find the parent 'new_blog_post' activity entry 488 $parent_activity_id = bp_activity_get_activity_id( array( 489 'user_id' => $user_id, 490 'component' => 'blogs', 491 'type' => 'new_blog_post', 492 'item_id' => $blog_id, 493 'secondary_item_id' => $recorded_comment->comment_post_ID 494 ) ); 495 496 // we found the parent activity entry 497 // so let's go ahead and reconfigure some activity args 498 if ( ! empty( $parent_activity_id ) ) { 499 // set the 'item_id' with the parent activity entry ID 500 $args['item_id'] = $parent_activity_id; 501 502 // now see if the WP parent comment has a BP activity ID 503 $comment_parent = 0; 504 if ( ! empty( $recorded_comment->comment_parent ) ) { 505 $comment_parent = get_comment_meta( $recorded_comment->comment_parent, 'bp_activity_comment_id', true ); 506 } 507 508 // WP parent comment does not have a BP activity ID 509 // so set to 'new_blog_post' activity ID 510 if ( empty( $comment_parent ) ) { 511 $comment_parent = $parent_activity_id; 512 } 513 514 $args['secondary_item_id'] = $comment_parent; 515 $args['component'] = 'activity'; 516 $args['type'] = 'activity_comment'; 517 518 // could not find corresponding parent activity entry 519 // so wipe out $args array 520 } else { 521 $args = array(); 522 } 523 524 // Record in activity streams 525 if ( ! empty( $args ) ) { 526 // @todo should we use bp_activity_new_comment()? that function will also send 527 // an email to people in the activity comment thread 528 // 529 // what if a site already has some comment email notification plugin setup? 530 // this is why I decided to go with bp_activity_add() to avoid any conflict 531 // with existing comment email notification plugins 532 $comment_activity_id = bp_activity_add( $args ); 533 534 if ( empty( $args['id'] ) ) { 535 // add meta to activity comment 536 bp_activity_update_meta( $comment_activity_id, 'bp_blogs_post_comment_id', $comment_id ); 537 538 // add meta to comment 539 add_comment_meta( $comment_id, 'bp_activity_comment_id', $comment_activity_id ); 540 } 541 } 542 } 462 543 463 544 // Update the blogs last active date 464 545 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() ); … … 632 713 function bp_blogs_remove_comment( $comment_id ) { 633 714 global $wpdb; 634 715 635 // Delete activity stream item 636 bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) ); 716 // activity comments are disabled for blog posts 717 // which means that individual activity items exist for blog comments 718 if ( bp_disable_blogforum_comments() ) { 719 // Delete the individual activity stream item 720 bp_blogs_delete_activity( array( 721 'item_id' => $wpdb->blogid, 722 'secondary_item_id' => $comment_id, 723 'type' => 'new_blog_comment' 724 ) ); 725 726 // activity comments are enabled for blog posts 727 // remove the associated activity item 728 } else { 729 // get associated activity ID from comment meta 730 $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 731 732 // delete the associated activity comment 733 // 734 // also removes child post comments and associated activity comments 735 if ( ! empty( $activity_id ) && bp_is_active( 'activity' ) ) { 736 // fetch the activity comments for the activity item 737 $activity = bp_activity_get( array( 738 'in' => $activity_id, 739 'display_comments' => 'stream', 740 ) ); 741 742 // get all activity comment IDs for the pending deleted item 743 if ( ! empty( $activity['activities'] ) ) { 744 $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 745 $activity_ids[] = $activity_id; 746 747 // delete activity items 748 foreach ( $activity_ids as $activity_id ) { 749 bp_activity_delete( array( 750 'id' => $activity_id 751 ) ); 752 } 753 754 // remove associated blog comments 755 bp_blogs_remove_associated_blog_comments( $activity_ids ); 756 757 // rebuild activity comment tree 758 BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id ); 759 } 760 } 761 } 637 762 638 763 do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() ); 639 764 } 640 765 add_action( 'delete_comment', 'bp_blogs_remove_comment' ); 641 766 642 767 /** 768 * Removes blog comments that are associated with activity comments. 769 * 770 * @since BuddyPress (2.0.0) 771 * 772 * @see bp_blogs_remove_comment() 773 * @see bp_blogs_sync_delete_from_activity_comment() 774 * 775 * @param array $activity_ids The activity IDs to check association with blog 776 * comments. 777 */ 778 function bp_blogs_remove_associated_blog_comments( $activity_ids = array() ) { 779 // query args 780 $query_args = array( 781 'meta_query' => array( 782 array( 783 'key' => 'bp_activity_comment_id', 784 'value' => implode( ',', (array) $activity_ids ), 785 'compare' => 'IN', 786 ) 787 ) 788 ); 789 790 // get comment 791 $comment_query = new WP_Comment_Query; 792 $comments = $comment_query->query( $query_args ); 793 794 // found the corresponding comments 795 // let's delete them! 796 foreach ( $comments as $comment ) { 797 // we force delete the comment, since activity items are deleted immediately 798 wp_delete_comment( $comment->comment_ID, true ); 799 } 800 } 801 802 /** 643 803 * When a blog comment status transition occurs, update the relevant activity's status. 644 804 * 645 805 * @since BuddyPress (1.6.0) … … 667 827 */ 668 828 669 829 // 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' ) ) ) 830 if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) { 671 831 return bp_blogs_remove_comment( $comment->comment_ID ); 672 832 673 833 // These clauses handle trash, spam, and un-spams. 674 elseif ( in_array( $new_status, array( 'trash', 'spam' ) ) )834 } elseif ( in_array( $new_status, array( 'trash', 'spam' ) ) ) { 675 835 $action = 'spam_activity'; 676 elseif ( 'approved' == $new_status )836 } elseif ( 'approved' == $new_status ) { 677 837 $action = 'ham_activity'; 838 } 678 839 679 840 // 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', ) ); 841 if ( bp_disable_blogforum_comments() ) { 842 $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', ) ); 843 } else { 844 $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ); 845 } 681 846 682 847 // Check activity item exists 683 if ( ! $activity_id ) { 684 848 if ( empty( $activity_id ) ) { 685 849 // If no activity exists, but the comment has been approved, record it into the activity table. 686 if ( 'approved' == $new_status ) 850 if ( 'approved' == $new_status ) { 687 851 return bp_blogs_record_comment( $comment->comment_ID, true ); 852 } 688 853 689 854 return; 690 855 } -
bp-blogs/bp-blogs-loader.php
73 73 74 74 // Setup the globals 75 75 parent::setup_globals( $args ); 76 77 // Activity comment post callback 78 $this->activity_comment_post_callback = apply_filters( 'bp_blogs_activity_comment_post_callback', array( 79 'add' => 'bp_blogs_sync_add_from_activity_comment', 80 'delete' => 'bp_blogs_sync_delete_from_activity_comment' 81 ) ); 76 82 } 77 83 78 84 /** -
bp-core/bp-core-component.php
85 85 public $notification_callback = ''; 86 86 87 87 /** 88 * Callback to do something whenever an activity comment is saved or deleted. 89 * 90 * @since BuddyPress (2.0.0) 91 * 92 * @var array 93 */ 94 public $activity_comment_post_callback = ''; 95 96 /** 88 97 * WordPress Toolbar links. 89 98 * 90 99 * @var array $admin_menu … … 336 345 public function setup_actions() { 337 346 338 347 // Setup globals 339 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ), 10 );348 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ), 10 ); 340 349 341 350 // Include required files. Called early to ensure that BP core 342 351 // components are loaded before plugins that hook their loader functions 343 352 // to bp_include with the default priority of 10. This is for backwards 344 353 // compatibility; henceforth, plugins should register themselves by 345 354 // extending this base class. 346 add_action( 'bp_include', array( $this, 'includes' ), 8 );355 add_action( 'bp_include', array( $this, 'includes' ), 8 ); 347 356 348 357 // Setup navigation 349 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 );358 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 ); 350 359 351 360 // Setup WP Toolbar menus 352 add_action( 'bp_setup_admin_bar', array( $this, 'setup_admin_bar' ), $this->adminbar_myaccount_order );361 add_action( 'bp_setup_admin_bar', array( $this, 'setup_admin_bar' ), $this->adminbar_myaccount_order ); 353 362 354 363 // Setup component title 355 add_action( 'bp_setup_title', array( $this, 'setup_title' ), 10 );364 add_action( 'bp_setup_title', array( $this, 'setup_title' ), 10 ); 356 365 357 366 // Register post types 358 add_action( 'bp_register_post_types', array( $this, 'register_post_types' ), 10 );367 add_action( 'bp_register_post_types', array( $this, 'register_post_types' ), 10 ); 359 368 360 369 // Register taxonomies 361 add_action( 'bp_register_taxonomies', array( $this, 'register_taxonomies' ), 10 );370 add_action( 'bp_register_taxonomies', array( $this, 'register_taxonomies' ), 10 ); 362 371 363 372 // Add the rewrite tags 364 add_action( 'bp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10 );373 add_action( 'bp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10 ); 365 374 366 375 // Add the rewrite rules 367 add_action( 'bp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ), 10 );376 add_action( 'bp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ), 10 ); 368 377 369 378 // Add the permalink structure 370 add_action( 'bp_add_permastructs', array( $this, 'add_permastructs' ), 10 );379 add_action( 'bp_add_permastructs', array( $this, 'add_permastructs' ), 10 ); 371 380 372 381 // Allow components to parse the main query 373 add_action( 'bp_parse_query', array( $this, 'parse_query' ), 10 );382 add_action( 'bp_parse_query', array( $this, 'parse_query' ), 10 ); 374 383 375 384 // Generate rewrite rules 376 add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 ); 385 add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 ); 386 387 // Activity comment callback setup 388 add_action( 'bp_setup_globals', array( $this, 'activity_comment_post_callback' ), 10 ); 377 389 378 390 // Additional actions can be attached here 379 391 do_action( 'bp_' . $this->id . '_setup_actions' ); … … 602 614 public function generate_rewrite_rules() { 603 615 do_action( 'bp_' . $this->id . '_generate_rewrite_rules' ); 604 616 } 617 618 /** 619 * Setup activity comment post callback. 620 * 621 * If a component has the 'activity_comment_post_callback' property set, 622 * automatically setup the hooks to be used. 623 * 624 * @since BuddyPress (2.0.0 625 */ 626 public function activity_comment_post_callback() { 627 // if activity component is not active or callback is not an array, stop now! 628 if ( ! bp_is_active( 'activity' ) || ! is_array( $this->activity_comment_post_callback ) ) { 629 return; 630 } 631 632 $callback = $this->activity_comment_post_callback; 633 634 // Activity comment addition callback 635 if ( ! empty( $callback['add'] ) && is_callable( $callback['add'] ) ) { 636 add_action( 'bp_activity_comment_posted', $callback['add'], 10, 3 ); 637 } 638 639 // Activity comment deletion callback 640 if ( ! empty( $callback['delete'] ) && is_callable( $callback['delete'] ) ) { 641 add_filter( 'bp_activity_delete_comment_pre', $callback['delete'], 10, 3 ); 642 } 643 644 } 605 645 } 606 646 endif; // BP_Component -
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)