Changeset 10374 for trunk/src/bp-blogs/bp-blogs-activity.php
- Timestamp:
- 11/23/2015 03:55:00 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-blogs/bp-blogs-activity.php
r10253 r10374 20 20 $bp = buddypress(); 21 21 22 // Bail if activity is not active 22 // Bail if activity is not active. 23 23 if ( ! bp_is_active( 'activity' ) ) { 24 24 return false; … … 37 37 } 38 38 39 // Only add the comment type if the 'post' post type is trackable 39 // Only add the comment type if the 'post' post type is trackable. 40 40 if ( post_type_supports( 'post', 'buddypress-activity' ) ) { 41 41 bp_activity_set_action( … … 66 66 * @param string $action Static activity action. 67 67 * @param object $activity Activity data object. 68 *69 68 * @return string 70 69 */ … … 75 74 $action = sprintf( __( '%s created the site %s', 'buddypress' ), bp_core_get_userlink( $activity->user_id ), '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' ); 76 75 77 // Legacy filter - requires the BP_Blogs_Blog object 76 // Legacy filter - requires the BP_Blogs_Blog object. 78 77 if ( has_filter( 'bp_blogs_activity_created_blog_action' ) ) { 79 78 $user_blog = BP_Blogs_Blog::get_user_blog( $activity->user_id, $activity->item_id ); … … 105 104 * @param string $action Static activity action. 106 105 * @param object $activity Activity data object. 107 *108 106 * @return string Constructed activity action. 109 107 */ … … 141 139 } 142 140 143 // Should be the case when the post has just been published 141 // Should be the case when the post has just been published. 144 142 if ( isset( $activity->post_title ) ) { 145 143 $post_title = $activity->post_title; 146 144 147 // If activity already exists try to get the post title from activity meta 145 // If activity already exists try to get the post title from activity meta. 148 146 } else if ( ! empty( $activity->id ) ) { 149 147 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); … … 152 150 /** 153 151 * In case the post was published without a title 154 * or the activity meta was not found 152 * or the activity meta was not found. 155 153 */ 156 154 if ( empty( $post_title ) ) { 157 // Defaults to no title 155 // Defaults to no title. 158 156 $post_title = esc_html__( '(no title)', 'buddypress' ); 159 157 … … 167 165 } 168 166 169 // Make sure the activity exists before saving the post title in activity meta 167 // Make sure the activity exists before saving the post title in activity meta. 170 168 if ( ! empty( $activity->id ) ) { 171 169 bp_activity_update_meta( $activity->id, 'post_title', $post_title ); … … 176 174 } 177 175 178 // Build the 'post link' part of the activity action string 176 // Build the 'post link' part of the activity action string. 179 177 $post_link = '<a href="' . esc_url( $post_url ) . '">' . $post_title . '</a>'; 180 178 181 179 $user_link = bp_core_get_userlink( $activity->user_id ); 182 180 183 // Build the complete activity action string 181 // Build the complete activity action string. 184 182 if ( is_multisite() ) { 185 183 $action = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' ); … … 188 186 } 189 187 190 // Legacy filter - requires the post object 188 // Legacy filter - requires the post object. 191 189 if ( has_filter( 'bp_blogs_activity_new_post_action' ) ) { 192 190 switch_to_blog( $activity->item_id ); … … 217 215 * @param string $action Static activity action. 218 216 * @param object $activity Activity data object. 219 *220 217 * @return string Constructed activity action. 221 218 */ … … 235 232 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 236 233 237 // Should only be empty at the time of post creation 234 // Should only be empty at the time of post creation. 238 235 if ( empty( $post_url ) || empty( $post_title ) ) { 239 236 switch_to_blog( $activity->item_id ); … … 265 262 } 266 263 267 // Legacy filter - requires the comment object 264 // Legacy filter - requires the comment object. 268 265 if ( has_filter( 'bp_blogs_activity_new_comment_action' ) ) { 269 266 switch_to_blog( $activity->item_id ); … … 295 292 * 296 293 * @param array $activities Array of activity items. 297 *298 294 * @return array 299 295 */ … … 338 334 function bp_blogs_record_activity( $args = '' ) { 339 335 340 // Bail if activity is not active 336 // Bail if activity is not active. 341 337 if ( ! bp_is_active( 'activity' ) ) { 342 338 return false; … … 415 411 function bp_blogs_delete_activity( $args = '' ) { 416 412 417 // Bail if activity is not active 413 // Bail if activity is not active. 418 414 if ( ! bp_is_active( 'activity' ) ) { 419 415 return false; … … 444 440 * @since 2.0.0 445 441 * 446 * @param object $activity The BP_Activity_Activity object 447 * 442 * @param object $activity The BP_Activity_Activity object. 448 443 * @return bool 449 444 */ … … 453 448 $blog_id = $activity->item_id; 454 449 455 // see if we've mirrored the close comments option before450 // See if we've mirrored the close comments option before. 456 451 $days_old = bp_blogs_get_blogmeta( $blog_id, 'close_comments_days_old' ); 457 452 458 // we've never cached these items before, so do it now453 // We've never cached these items before, so do it now. 459 454 if ( '' === $days_old ) { 460 455 switch_to_blog( $blog_id ); 461 456 462 // use comments_open()457 // Use comments_open(). 463 458 remove_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 464 459 $open = comments_open( $activity->secondary_item_id ); 465 460 add_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 466 461 467 // might as well mirror values to blogmeta since we're here!462 // Might as well mirror values to blogmeta since we're here! 468 463 $thread_depth = get_option( 'thread_comments' ); 469 464 if ( ! empty( $thread_depth ) ) { 470 465 $thread_depth = get_option( 'thread_comments_depth' ); 471 466 } else { 472 // perhaps filter this?467 // Perhaps filter this? 473 468 $thread_depth = 1; 474 469 } … … 480 475 restore_current_blog(); 481 476 482 // check blogmeta and manually check activity item483 // basically a copy of _close_comments_for_old_post()477 // Check blogmeta and manually check activity item. 478 // Basically a copy of _close_comments_for_old_post(). 484 479 } else { 485 480 486 // comments are closed481 // Comments are closed. 487 482 if ( 'closed' == bp_activity_get_meta( $activity->id, 'post_comment_status' ) ) { 488 483 return false; … … 498 493 } 499 494 500 /* commenting out for now - needs some more thought... 495 /* 496 Commenting out for now - needs some more thought... 501 497 should we add the post type to activity meta? 502 498 … … 535 531 */ 536 532 function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) { 537 // if parent activity isn't a blog post, stop now!533 // If parent activity isn't a blog post, stop now! 538 534 if ( $parent_activity->type != 'new_blog_post' ) { 539 535 return; 540 536 } 541 537 542 // if activity comments are disabled for blog posts, stop now!538 // If activity comments are disabled for blog posts, stop now! 543 539 if ( bp_disable_blogforum_comments() ) { 544 540 return; 545 541 } 546 542 547 // get userdata543 // Get userdata. 548 544 if ( $params['user_id'] == bp_loggedin_user_id() ) { 549 545 $user = buddypress()->loggedin_user->userdata; … … 552 548 } 553 549 554 // see if a parent WP comment ID exists550 // See if a parent WP comment ID exists. 555 551 if ( ! empty( $params['parent_id'] ) ) { 556 552 $comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' ); … … 559 555 } 560 556 561 // comment args557 // Comment args. 562 558 $args = array( 563 559 'comment_post_ID' => $parent_activity->secondary_item_id, … … 566 562 'comment_author_url' => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ), 567 563 'comment_content' => $params['content'], 568 'comment_type' => '', // could be interesting to add 'buddypress' here...564 'comment_type' => '', // Could be interesting to add 'buddypress' here... 569 565 'comment_parent' => (int) $comment_parent, 570 566 'user_id' => $params['user_id'], 571 567 572 // commenting these out for now 573 //'comment_author_IP' => '127.0.0.1', 574 //'comment_agent' => '', 575 568 // Commenting these out for now 569 // 'comment_author_IP' => '127.0.0.1', 570 // 'comment_agent' => '', . 576 571 'comment_approved' => 1 577 572 ); 578 573 579 // prevent separate activity entry being made574 // Prevent separate activity entry being made. 580 575 remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 581 576 582 // handle multisite577 // Handle multisite. 583 578 switch_to_blog( $parent_activity->item_id ); 584 579 585 // handle timestamps for the WP comment after we've switched to the blog580 // Handle timestamps for the WP comment after we've switched to the blog. 586 581 $args['comment_date'] = current_time( 'mysql' ); 587 582 $args['comment_date_gmt'] = current_time( 'mysql', 1 ); 588 583 589 // post the comment584 // Post the comment. 590 585 $post_comment_id = wp_insert_comment( $args ); 591 586 592 // add meta to comment587 // Add meta to comment. 593 588 add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id ); 594 589 595 // add meta to activity comment590 // Add meta to activity comment. 596 591 bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id ); 597 592 598 // resave activity comment with WP comment permalink593 // Resave activity comment with WP comment permalink. 599 594 // 600 595 // in bp_blogs_activity_comment_permalink(), we change activity comment … … 602 597 // 603 598 // @todo since this is done after AJAX posting, the activity comment permalink 604 // 599 // doesn't change on the frontend until the next page refresh. 605 600 $resave_activity = new BP_Activity_Activity( $comment_id ); 606 601 $resave_activity->primary_link = get_comment_link( $post_comment_id ); … … 614 609 $resave_activity->save(); 615 610 616 // add the edit activity comment hook back611 // Add the edit activity comment hook back. 617 612 add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 618 613 619 // multisite again!614 // Multisite again! 620 615 restore_current_blog(); 621 616 622 // add the comment hook back617 // Add the comment hook back. 623 618 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 624 619 … … 646 641 * @since 2.0.0 647 642 * 648 * @param bool $retval 643 * @param bool $retval Whether BuddyPress should continue or not. 649 644 * @param int $parent_activity_id The parent activity ID for the activity comment. 650 645 * @param int $activity_id The activity ID for the pending deleted activity comment. 651 *652 646 * @return bool 653 647 */ 654 648 function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) { 655 // check if parent activity is a blog post649 // Check if parent activity is a blog post. 656 650 $parent_activity = new BP_Activity_Activity( $parent_activity_id ); 657 651 if ( 'new_blog_post' != $parent_activity->type ) { … … 659 653 } 660 654 661 // fetch the activity comments for the activity item655 // Fetch the activity comments for the activity item. 662 656 $activity = bp_activity_get( array( 663 657 'in' => $activity_id, … … 665 659 ) ); 666 660 667 // get all activity comment IDs for the pending deleted item661 // Get all activity comment IDs for the pending deleted item. 668 662 $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 669 663 $activity_ids[] = $activity_id; 670 664 671 // handle multisite672 // switch to the blog where the comment was made 665 // Handle multisite 666 // switch to the blog where the comment was made. 673 667 switch_to_blog( $parent_activity->item_id ); 674 668 675 // remove associated blog comments669 // Remove associated blog comments. 676 670 bp_blogs_remove_associated_blog_comments( $activity_ids, current_user_can( 'moderate_comments' ) ); 677 671 678 // multisite again!672 // Multisite again! 679 673 restore_current_blog(); 680 674 681 // rebuild activity comment tree682 // emulate bp_activity_delete_comment() 675 // Rebuild activity comment tree 676 // emulate bp_activity_delete_comment(). 683 677 BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id ); 684 678 685 // we're overriding the default bp_activity_delete_comment() functionality686 // so we need to return false 679 // We're overriding the default bp_activity_delete_comment() functionality 680 // so we need to return false. 687 681 return false; 688 682 } … … 697 691 */ 698 692 function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity ) { 699 // not an activity comment? stop now!693 // Not an activity comment? stop now! 700 694 if ( 'activity_comment' !== $activity->type ) { 701 695 return; 702 696 } 703 697 704 // this is a new entry, so stop!705 // we only want edits!698 // This is a new entry, so stop! 699 // We only want edits! 706 700 if ( empty( $activity->id ) ) { 707 701 return; 708 702 } 709 703 710 // prevent recursion704 // Prevent recursion. 711 705 remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 712 706 713 // Try to see if a corresponding blog comment exists 707 // Try to see if a corresponding blog comment exists. 714 708 $post_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' ); 715 709 … … 718 712 } 719 713 720 // fetch parent activity item714 // Fetch parent activity item. 721 715 $parent_activity = new BP_Activity_Activity( $activity->item_id ); 722 716 723 // sanity check717 // Sanity check. 724 718 if ( 'new_blog_post' !== $parent_activity->type ) { 725 719 return; 726 720 } 727 721 728 // handle multisite722 // Handle multisite. 729 723 switch_to_blog( $parent_activity->item_id ); 730 724 731 // update the blog post comment725 // Update the blog post comment. 732 726 wp_update_comment( array( 733 727 'comment_ID' => $post_comment_id, … … 783 777 * 784 778 * @param array $args Arguments passed from bp_parse_args() in bp_has_activities(). 785 *786 779 * @return array $args 787 780 */ … … 790 783 $bp = buddypress(); 791 784 792 // Bail if this is not a 'new_blog_comment' query 785 // Bail if this is not a 'new_blog_comment' query. 793 786 if ( 'new_blog_comment' !== $args['action'] ) { 794 787 return $args; … … 802 795 } 803 796 804 // Init the filter query 797 // Init the filter query. 805 798 $filter_query = array(); 806 799 … … 833 826 $args['filter_query'] = $filter_query; 834 827 835 // Make sure to have comment in stream mode && avoid duplicate content 828 // Make sure to have comment in stream mode && avoid duplicate content. 836 829 $args['display_comments'] = 'stream'; 837 830 838 // Finally reset the action 831 // Finally reset the action. 839 832 $args['action'] = ''; 840 833 841 // Return the original arguments 834 // Return the original arguments. 842 835 return $args; 843 836 } … … 864 857 } 865 858 866 // parent not a blog post? stop now!859 // Parent not a blog post? stop now! 867 860 if ( 'new_blog_post' !== $activity->type ) { 868 861 return; … … 873 866 } 874 867 875 // if we've already done this before, stop now!868 // If we've already done this before, stop now! 876 869 if ( isset( buddypress()->blogs->allow_comments[ $activity->id ] ) ) { 877 870 return; … … 881 874 $thread_depth = bp_blogs_get_blogmeta( $activity->item_id, 'thread_comments_depth' ); 882 875 883 // initialize a local object so we won't have to query this again in the884 // comment loop 876 // Initialize a local object so we won't have to query this again in the 877 // comment loop. 885 878 if ( empty( buddypress()->blogs->allow_comments ) ) { 886 879 buddypress()->blogs->allow_comments = array(); … … 890 883 } 891 884 892 // cache comment settings in the buddypress() singleton to reference later in885 // Cache comment settings in the buddypress() singleton to reference later in 893 886 // the activity comment loop 894 887 // @see bp_blogs_disable_activity_replies() … … 909 902 */ 910 903 function bp_blogs_setup_comment_loop_globals_on_ajax() { 911 // not AJAX? stop now!904 // Not AJAX? stop now! 912 905 if ( ! defined( 'DOING_AJAX' ) ) { 913 906 return; … … 917 910 } 918 911 919 // get the parent activity item912 // Get the parent activity item. 920 913 $comment = bp_activity_current_comment(); 921 914 $parent_activity = new BP_Activity_Activity( $comment->item_id ); 922 915 923 // setup the globals916 // Setup the globals. 924 917 bp_blogs_setup_activity_loop_globals( $parent_activity ); 925 918 } … … 938 931 * @since 2.0.0 939 932 * 940 * @param bool $retval Is activity commenting enabled for this activity entry? 941 * 933 * @param bool $retval Is activity commenting enabled for this activity entry. 942 934 * @return bool 943 935 */ 944 936 function bp_blogs_disable_activity_commenting( $retval ) { 945 // if activity commenting is disabled, return current value937 // If activity commenting is disabled, return current value. 946 938 if ( bp_disable_blogforum_comments() ) { 947 939 return $retval; 948 940 } 949 941 950 // activity commenting is enabled for blog posts942 // Activity commenting is enabled for blog posts. 951 943 switch ( bp_get_activity_action_name() ) { 952 944 953 // we still have to disable activity commenting for 'new_blog_comment' items954 // commenting should only be done on the parent 'new_blog_post' item 945 // We still have to disable activity commenting for 'new_blog_comment' items 946 // commenting should only be done on the parent 'new_blog_post' item. 955 947 case 'new_blog_comment' : 956 948 $retval = false; … … 958 950 break; 959 951 960 // check if commenting is disabled for the WP blog post961 // we should extrapolate this and automate this for plugins... or not 952 // Check if commenting is disabled for the WP blog post 953 // we should extrapolate this and automate this for plugins... or not. 962 954 case 'new_blog_post' : 963 955 global $activities_template; 964 956 965 // setup some globals we'll need to reference later957 // Setup some globals we'll need to reference later. 966 958 bp_blogs_setup_activity_loop_globals( $activities_template->activity ); 967 959 968 // if comments are closed for the WP blog post, we should disable969 // activity comments for this activity entry 960 // If comments are closed for the WP blog post, we should disable 961 // activity comments for this activity entry. 970 962 if ( empty( buddypress()->blogs->allow_comments[bp_get_activity_id()] ) ) { 971 963 $retval = false; … … 990 982 * @since 2.0.0 991 983 * 992 * @param bool $retval Are replies allowed for this activity reply ?984 * @param bool $retval Are replies allowed for this activity reply. 993 985 * @param object|array $comment The activity comment object. 994 986 * … … 1000 992 } 1001 993 1002 // check comment depth and disable if depth is too large994 // Check comment depth and disable if depth is too large. 1003 995 if ( isset( buddypress()->blogs->thread_depth[$comment->item_id] ) ){ 1004 996 if ( $comment->mptt_left > buddypress()->blogs->thread_depth[$comment->item_id] ) { … … 1007 999 } 1008 1000 1009 // check if we should disable activity replies based on the parent activity1001 // Check if we should disable activity replies based on the parent activity. 1010 1002 if ( isset( buddypress()->blogs->allow_comments[$comment->item_id] ) ){ 1011 // the blog post has closed off commenting, so we should disable all activity1012 // comments under the parent 'new_blog_post' activity entry 1003 // The blog post has closed off commenting, so we should disable all activity 1004 // comments under the parent 'new_blog_post' activity entry. 1013 1005 if ( empty( buddypress()->blogs->allow_comments[$comment->item_id] ) ) { 1014 1006 $retval = false; … … 1030 1022 * 1031 1023 * @param string $retval The activity comment permalink. 1032 *1033 1024 * @return string 1034 1025 */ … … 1036 1027 global $activities_template; 1037 1028 1038 // Get the current comment ID 1029 // Get the current comment ID. 1039 1030 $item_id = isset( $activities_template->activity->current_comment->item_id ) 1040 1031 ? $activities_template->activity->current_comment->item_id 1041 1032 : false; 1042 1033 1043 // Maybe adjust the link if item ID exists 1034 // Maybe adjust the link if item ID exists. 1044 1035 if ( ( false !== $item_id ) && isset( buddypress()->blogs->allow_comments[ $item_id ] ) ) { 1045 1036 $retval = $activities_template->activity->current_comment->primary_link; … … 1058 1049 * 1059 1050 * @param string $retval The activity permalink. 1060 * @param BP_Activity_Activity $activity 1061 * 1051 * @param BP_Activity_Activity $activity Activity object. 1062 1052 * @return string 1063 1053 */ … … 1085 1075 * 1086 1076 * @param string $retval The activity action. 1087 * @param BP_Activity_Activity $activity 1088 * 1077 * @param BP_Activity_Activity $activity Activity object. 1089 1078 * @return string 1090 1079 */ … … 1097 1086 1098 1087 if ( ! empty( $blog_comment_id ) ) { 1099 // fetch the parent blog post activity item1088 // Fetch the parent blog post activity item. 1100 1089 $parent_blog_post_activity = new BP_Activity_Activity( $activity->item_id ); 1101 1090 1102 // fake a 'new_blog_comment' activity object1091 // Fake a 'new_blog_comment' activity object. 1103 1092 $object = $activity; 1104 1093 1105 // override 'item_id' to use blog ID1094 // Override 'item_id' to use blog ID. 1106 1095 $object->item_id = $parent_blog_post_activity->item_id; 1107 1096 1108 // override 'secondary_item_id' to use comment ID1097 // Override 'secondary_item_id' to use comment ID. 1109 1098 $object->secondary_item_id = $blog_comment_id; 1110 1099 1111 // now format the activity action using the 'new_blog_comment' action callback1100 // Now format the activity action using the 'new_blog_comment' action callback. 1112 1101 $retval = bp_blogs_format_activity_action_new_blog_comment( '', $object ); 1113 1102 }
Note: See TracChangeset
for help on using the changeset viewer.