Changeset 12544
- Timestamp:
- 01/29/2020 08:36:15 PM (5 years ago)
- Location:
- trunk/src/bp-blogs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-blogs/bp-blogs-activity.php
r12393 r12544 288 288 $blog_url = false; 289 289 290 // Try to get the blog url from the activity object 290 // Try to get the blog url from the activity object. 291 291 if ( isset( $activity->blog_url ) ) { 292 292 $blog_url = $activity->blog_url; … … 297 297 $blog_name = false; 298 298 299 // Try to get the blog name from the activity object 299 // Try to get the blog name from the activity object. 300 300 if ( isset( $activity->blog_name ) ) { 301 301 $blog_name = $activity->blog_name; … … 314 314 $post_url = false; 315 315 316 // Try to get the post url from the activity object 316 // Try to get the post url from the activity object. 317 317 if ( isset( $activity->post_url ) ) { 318 318 $post_url = $activity->post_url; … … 329 329 $post_title = false; 330 330 331 // Should be the case when the comment has just been published 331 // Should be the case when the comment has just been published. 332 332 if ( isset( $activity->post_title ) ) { 333 333 $post_title = $activity->post_title; 334 334 335 // If activity already exists try to get the post title from activity meta 335 // If activity already exists try to get the post title from activity meta. 336 336 } elseif ( ! empty( $activity->id ) ) { 337 337 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); … … 790 790 } 791 791 792 // Get associated post type and set default comment parent 792 // Get associated post type and set default comment parent. 793 793 $post_type = bp_activity_post_type_get_tracking_arg( $parent_activity->type, 'post_type' ); 794 794 $comment_parent = 0; … … 806 806 'comment_author_url' => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ), 807 807 'comment_content' => $params['content'], 808 'comment_type' => '', // Could be interesting to add ' buddypress' here...808 'comment_type' => '', // Could be interesting to add 'BuddyPress' here... 809 809 'comment_parent' => (int) $comment_parent, 810 810 'user_id' => $params['user_id'], … … 910 910 $activity_ids[] = $activity_id; 911 911 912 // Handle multisite 912 // Handle multisite. 913 913 // switch to the blog where the comment was made. 914 914 switch_to_blog( $parent_activity->item_id ); … … 924 924 BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id ); 925 925 926 // Avoid the error message although the comments were successfully deleted 926 // Avoid the error message although the comments were successfully deleted. 927 927 $deleted = true; 928 928 … … 947 947 } 948 948 949 // fetch parent activity item949 // Fetch parent activity item. 950 950 $parent_activity = new BP_Activity_Activity( $activity->item_id ); 951 951 952 // if parent activity isn't a post type having the buddypress-activity support for comments, stop now!952 // If parent activity isn't a post type having the buddypress-activity support for comments, stop now! 953 953 if ( ! bp_activity_type_supports( $parent_activity->type, 'post-type-comment-tracking' ) ) { 954 954 return; … … 972 972 switch_to_blog( $parent_activity->item_id ); 973 973 974 // Get the comment status 974 // Get the comment status. 975 975 $post_comment_status = wp_get_comment_status( $post_comment_id ); 976 976 $old_comment_status = $post_comment_status; 977 977 978 // No need to edit the activity, as it's the activity who's updating the comment 978 // No need to edit the activity, as it's the activity who's updating the comment. 979 979 remove_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10 ); 980 980 remove_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10 ); … … 996 996 } 997 997 998 // Restore actions 998 // Restore actions. 999 999 add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 ); 1000 1000 add_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10, 4 ); … … 1055 1055 } 1056 1056 1057 // Get the associated post type 1057 // Get the associated post type. 1058 1058 $post_type = bp_activity_post_type_get_tracking_arg( $args['action'], 'post_type' ); 1059 1059 1060 // Bail if this is not an activity associated with a post type 1060 // Bail if this is not an activity associated with a post type. 1061 1061 if ( empty( $post_type ) ) { 1062 1062 return $args; 1063 1063 } 1064 1064 1065 // Bail if this is an activity about posts and not comments 1065 // Bail if this is an activity about posts and not comments. 1066 1066 if ( bp_activity_post_type_get_tracking_arg( $args['action'], 'comment_action_id' ) ) { 1067 1067 return $args; … … 1236 1236 // It's a post type supporting comment tracking. 1237 1237 if ( bp_activity_type_supports( $type, 'post-type-comment-tracking' ) ) { 1238 // The activity type is supporting comments or replies 1238 // The activity type is supporting comments or replies. 1239 1239 if ( bp_activity_type_supports( $type, 'post-type-comment-reply' ) ) { 1240 1240 // Setup some globals we'll need to reference later. … … 1251 1251 $retval = false; 1252 1252 } 1253 // The activity type does not support comments or replies 1253 // The activity type does not support comments or replies. 1254 1254 } else { 1255 1255 $retval = false; … … 1286 1286 } 1287 1287 1288 // Check the parent activity 1288 // Check the parent activity. 1289 1289 $parent_activity = new BP_Activity_Activity( bp_get_activity_item_id() ); 1290 1290 … … 1439 1439 $bp = buddypress(); 1440 1440 1441 // Check if a comment action id is set for the parent activity 1441 // Check if a comment action id is set for the parent activity. 1442 1442 $comment_action_id = bp_activity_post_type_get_tracking_arg( $parent_activity->type, 'comment_action_id' ); 1443 1443 1444 // Use the action string callback for the activity type 1444 // Use the action string callback for the activity type. 1445 1445 if ( ! empty( $comment_action_id ) ) { 1446 1446 // Fake a 'new_{post_type}_comment' by cloning the activity object. 1447 1447 $object = clone $activity; 1448 1448 1449 // Set the type of the activity to be a comment about a post type 1449 // Set the type of the activity to be a comment about a post type. 1450 1450 $object->type = $comment_action_id; 1451 1451 … … 1456 1456 $object->secondary_item_id = $blog_comment_id; 1457 1457 1458 // Get the format callback for this activity comment 1458 // Get the format callback for this activity comment. 1459 1459 $format_callback = bp_activity_post_type_get_tracking_arg( $comment_action_id, 'format_callback' ); 1460 1460 1461 // now format the activity action using the 'new_{post_type}_comment' action callback1461 // Now format the activity action using the 'new_{post_type}_comment' action callback. 1462 1462 if ( is_callable( $format_callback ) ) { 1463 1463 $retval = call_user_func_array( $format_callback, array( '', $object ) ); -
trunk/src/bp-blogs/bp-blogs-functions.php
r12311 r12544 46 46 // Parse query arguments. 47 47 $r = bp_parse_args( $args, array( 48 'type' => 'active', // 'active', 'alphabetical', 'newest', or 'random' 49 'include_blog_ids' => false, // Array of blog IDs to include 50 'user_id' => false, // Limit to blogs this user can post to 51 'search_terms' => false, // Limit to blogs matching these search terms 52 'per_page' => 20, // The number of results to return per page 53 'page' => 1, // The page to return if limiting per page 54 'update_meta_cache' => true // Whether to pre-fetch blogmeta 48 'type' => 'active', // 'active', 'alphabetical', 'newest', or 'random'. 49 'include_blog_ids' => false, // Array of blog IDs to include. 50 'user_id' => false, // Limit to blogs this user can post to. 51 'search_terms' => false, // Limit to blogs matching these search terms. 52 'per_page' => 20, // The number of results to return per page. 53 'page' => 1, // The page to return if limiting per page. 54 'update_meta_cache' => true // Whether to pre-fetch blogmeta. 55 55 ), 'blogs_get_blogs' ); 56 56 … … 107 107 ), 'record_existing_blogs' ); 108 108 109 // Truncate all BP blogs tables if starting fresh 109 // Truncate all BP blogs tables if starting fresh. 110 110 if ( empty( $r['offset'] ) && empty( $r['blog_ids'] ) ) { 111 111 $bp = buddypress(); 112 112 113 // Truncate user blogs table 113 // Truncate user blogs table. 114 114 $truncate = $wpdb->query( "TRUNCATE {$bp->blogs->table_name}" ); 115 115 if ( is_wp_error( $truncate ) ) { … … 117 117 } 118 118 119 // Truncate user blogmeta table 119 // Truncate user blogmeta table. 120 120 $truncate = $wpdb->query( "TRUNCATE {$bp->blogs->table_name_blogmeta}" ); 121 121 if ( is_wp_error( $truncate ) ) { … … 124 124 } 125 125 126 // Multisite 126 // Multisite. 127 127 if ( is_multisite() ) { 128 128 $sql = array(); 129 129 $sql['select'] = $wpdb->prepare( "SELECT blog_id, last_updated FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0 AND site_id = %d", $r['site_id'] ); 130 130 131 // Omit root blog if large network 131 // Omit root blog if large network. 132 132 if ( bp_is_large_install() ) { 133 133 $sql['omit_root_blog'] = $wpdb->prepare( "AND blog_id != %d", bp_get_root_blog_id() ); 134 134 } 135 135 136 // Filter by selected blog IDs 136 // Filter by selected blog IDs. 137 137 if ( ! empty( $r['blog_ids'] ) ) { 138 138 $in = implode( ',', wp_parse_id_list( $r['blog_ids'] ) ); … … 162 162 } 163 163 164 // Bail if there are no blogs 164 // Bail if there are no blogs. 165 165 if ( empty( $blogs ) ) { 166 // Make sure we remove our offset marker 166 // Make sure we remove our offset marker. 167 167 if ( is_multisite() ) { 168 168 bp_delete_option( '_bp_record_blogs_offset' ); … … 193 193 bp_blogs_add_user_to_blog( $user_id, false, $blog->blog_id ); 194 194 195 // Clear cache 195 // Clear cache. 196 196 bp_blogs_clear_blog_object_cache( $blog->blog_id, $user_id ); 197 197 } 198 198 199 // Update blog last activity timestamp 199 // Update blog last activity timestamp. 200 200 if ( ! empty( $blog->last_updated ) && false !== strtotime( $blog->last_updated ) ) { 201 201 bp_blogs_update_blogmeta( $blog->blog_id, 'last_activity', $blog->last_updated ); … … 203 203 } 204 204 205 // See if we need to do this again 205 // See if we need to do this again. 206 206 if ( is_multisite() && empty( $r['blog_ids'] ) ) { 207 207 $sql['offset'] = $wpdb->prepare( " OFFSET %d", $r['limit'] + $r['offset'] ); 208 208 209 // Check if there are more blogs to record 209 // Check if there are more blogs to record. 210 210 $blog_ids = $wpdb->get_results( implode( ' ', $sql ) ); 211 211 212 // We have more blogs; record offset and re-run function 212 // We have more blogs; record offset and re-run function. 213 213 if ( ! empty( $blog_ids ) ) { 214 214 bp_update_option( '_bp_record_blogs_offset', $r['limit'] + $r['offset'] ); … … 223 223 return; 224 224 225 // No more blogs; delete offset marker 225 // No more blogs; delete offset marker. 226 226 } else { 227 227 bp_delete_option( '_bp_record_blogs_offset' ); … … 727 727 $blog_id = get_current_blog_id(); 728 728 729 // These activity metadatas are used to build the new_blog_comment action string 729 // These activity metadatas are used to build the new_blog_comment action string. 730 730 if ( ! empty( $activity_id ) && ! empty( $activity_args['item_id'] ) && 'new_blog_comment' === $activity_post_object->comment_action_id ) { 731 // add some post info in activity meta731 // Add some post info in activity meta. 732 732 bp_activity_update_meta( $activity_id, 'post_title', $comment->post->post_title ); 733 733 bp_activity_update_meta( $activity_id, 'post_url', esc_url_raw( add_query_arg( 'p', $comment->post->ID, home_url( '/' ) ) ) ); 734 734 } 735 735 736 // Sync comment - activity comment 736 // Sync comment - activity comment. 737 737 if ( ! bp_disable_blogforum_comments() ) { 738 738 … … 750 750 751 751 if ( isset( $activity_post_object->action_id ) && isset( $activity_post_object->component_id ) ) { 752 // find the parent 'new_post_type' activity entry752 // Find the parent 'new_post_type' activity entry. 753 753 $parent_activity_id = bp_activity_get_activity_id( array( 754 754 'component' => $activity_post_object->component_id, … … 764 764 } 765 765 766 // we found the parent activity entry767 // so let's go ahead and reconfigure some activity args 766 // We found the parent activity entry 767 // so let's go ahead and reconfigure some activity args. 768 768 if ( ! empty( $parent_activity_id ) ) { 769 // set the parent activity entry ID769 // Set the parent activity entry ID. 770 770 $activity_args['activity_id'] = $parent_activity_id; 771 771 772 // now see if the WP parent comment has a BP activity ID772 // Now see if the WP parent comment has a BP activity ID. 773 773 $comment_parent = 0; 774 774 if ( ! empty( $comment->comment_parent ) ) { … … 777 777 778 778 // WP parent comment does not have a BP activity ID 779 // so set to 'new_' . post_type activity ID 779 // so set to 'new_' . post_type activity ID. 780 780 if ( empty( $comment_parent ) ) { 781 781 $comment_parent = $parent_activity_id; … … 785 785 $activity_args['skip_notification'] = true; 786 786 787 // could not find corresponding parent activity entry788 // so wipe out $args array 787 // Could not find corresponding parent activity entry 788 // so wipe out $args array. 789 789 } else { 790 790 $activity_args = array(); 791 791 } 792 792 793 // Record in activity streams 793 // Record in activity streams. 794 794 if ( ! empty( $activity_args ) ) { 795 795 $activity_id = bp_activity_new_comment( $activity_args ); 796 796 797 797 if ( empty( $activity_args['id'] ) ) { 798 // The activity metadata to inform about the corresponding comment ID 798 // The activity metadata to inform about the corresponding comment ID. 799 799 bp_activity_update_meta( $activity_id, "bp_blogs_{$comment->post->post_type}_comment_id", $comment->comment_ID ); 800 800 801 // The comment metadata to inform about the corresponding activity ID 801 // The comment metadata to inform about the corresponding activity ID. 802 802 add_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', $activity_id ); 803 803 804 // These activity metadatas are used to build the new_blog_comment action string 804 // These activity metadatas are used to build the new_blog_comment action string. 805 805 if ( 'new_blog_comment' === $activity_post_object->comment_action_id ) { 806 806 bp_activity_update_meta( $activity_id, 'post_title', $comment->post->post_title ); … … 1055 1055 */ 1056 1056 if ( ! empty( $activity_id ) ) { 1057 // fetch the activity comments for the activity item1057 // Fetch the activity comments for the activity item. 1058 1058 $activity = bp_activity_get( array( 1059 1059 'in' => $activity_id, … … 1062 1062 ) ); 1063 1063 1064 // get all activity comment IDs for the pending deleted item1064 // Get all activity comment IDs for the pending deleted item. 1065 1065 if ( ! empty( $activity['activities'] ) ) { 1066 1066 $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 1067 1067 $activity_ids[] = $activity_id; 1068 1068 1069 // delete activity items1069 // Delete activity items. 1070 1070 foreach ( $activity_ids as $activity_id ) { 1071 1071 bp_activity_delete( array( … … 1074 1074 } 1075 1075 1076 // remove associated blog comments1076 // Remove associated blog comments. 1077 1077 bp_blogs_remove_associated_blog_comments( $activity_ids ); 1078 1078 1079 // rebuild activity comment tree1079 // Rebuild activity comment tree. 1080 1080 BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id ); 1081 1081 1082 // Set the result 1082 // Set the result. 1083 1083 $deleted = true; 1084 1084 } -
trunk/src/bp-blogs/classes/class-bp-blogs-blog.php
r11237 r12544 87 87 88 88 /** 89 * Filters the blog blogID before save.89 * Filters the blog ID before save. 90 90 * 91 91 * @since 1.0.0
Note: See TracChangeset
for help on using the changeset viewer.