Ticket #3856: 3856.04.patch
File 3856.04.patch, 45.7 KB (added by , 11 years ago) |
---|
-
bp-activity/bp-activity-classes.php
class BP_Activity_Activity { 161 161 $this->mptt_right = $row->mptt_right; 162 162 $this->is_spam = $row->is_spam; 163 163 } 164 165 $action = bp_activity_generate_action_string( $this ); 166 167 if ( $action ) { 168 $this->action = $action; 169 } 164 170 } 165 171 166 172 /** … … class BP_Activity_Activity { 442 448 if ( $activities && $display_comments ) 443 449 $activities = BP_Activity_Activity::append_comments( $activities, $spam ); 444 450 451 // Pre-fetch data associated with activity users and other objects 452 BP_Activity_Activity::prefetch_object_data( $activities ); 453 454 // Generate action strings 455 $activities = BP_Activity_Activity::generate_action_strings( $activities ); 456 445 457 // If $max is set, only return up to the max results 446 458 if ( !empty( $max ) ) { 447 459 if ( (int) $total_activities > (int) $max ) … … class BP_Activity_Activity { 559 571 } 560 572 561 573 /** 574 * Pre-fetch data for objects associated with activity items. 575 * 576 * Activity items are associated with users, and often with other 577 * BuddyPress data objects. Here, we pre-fetch data about these 578 * associated objects, so that inline lookups - done primarily when 579 * building action strings - do not result in excess database queries. 580 * 581 * The only object data required for activity component activity types 582 * (activity_update and activity_comment) is related to users, and that 583 * info is fetched separately in BP_Activity_Activity::get_activity_data(). 584 * So this method contains nothing but a filter that allows other 585 * components, such as bp-friends and bp-groups, to hook in and prime 586 * their own caches at the beginning of an activity loop. 587 * 588 * @since BuddyPress (2.0.0) 589 * 590 * @param array $activities Array of activities. 591 */ 592 protected static function prefetch_object_data( $activities ) { 593 return apply_filters( 'bp_activity_prefetch_object_data', $activities ); 594 } 595 596 /** 597 * Generate action strings for the activities located in BP_Activity_Activity::get(). 598 * 599 * @since BuddyPress (2.0.0) 600 * 601 * @param array $activities Array of activities. 602 * @return array 603 */ 604 protected static function generate_action_strings( $activities ) { 605 foreach ( $activities as $key => $activity ) { 606 $generated_action = bp_activity_generate_action_string( $activity ); 607 if ( false !== $generated_action ) { 608 $activity->action = $generated_action; 609 } 610 611 $activities[ $key ] = $activity; 612 } 613 614 return $activities; 615 } 616 617 /** 562 618 * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get(). 563 619 * 564 620 * We use WP_Meta_Query to do the heavy lifting of parsing the -
bp-activity/bp-activity-functions.php
function bp_activity_get_userid_from_mentionname( $mentionname ) { 266 266 * @param string $component_id The unique string ID of the component. 267 267 * @param string $key The action key. 268 268 * @param string $value The action value. 269 * @param callable $format_callback Callback for formatting the action string. 269 270 * @return bool False if any param is empty, otherwise true. 270 271 */ 271 function bp_activity_set_action( $component_id, $key, $value ) {272 function bp_activity_set_action( $component_id, $key, $value, $format_callback = false ) { 272 273 global $bp; 273 274 274 275 // Return false if any of the above values are not set 275 if ( empty( $component_id ) || empty( $key ) || empty( $value ) ) 276 if ( empty( $component_id ) || empty( $key ) || empty( $value ) ) { 276 277 return false; 278 } 277 279 278 280 // Set activity action 279 281 if ( !isset( $bp->activity->actions ) || !is_object( $bp->activity->actions ) ) { 280 282 $bp->activity->actions = new stdClass; 281 283 } 282 284 285 // Verify callback 286 if ( ! is_callable( $format_callback ) ) { 287 $format_callback = ''; 288 } 289 283 290 if ( !isset( $bp->activity->actions->{$component_id} ) || !is_object( $bp->activity->actions->{$component_id} ) ) { 284 291 $bp->activity->actions->{$component_id} = new stdClass; 285 292 } 286 293 287 294 $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array( 288 'key' => $key, 289 'value' => $value 295 'key' => $key, 296 'value' => $value, 297 'format_callback' => $format_callback, 290 298 ), $component_id, $key, $value ); 291 299 292 300 return true; … … add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' ); 857 865 function bp_activity_register_activity_actions() { 858 866 global $bp; 859 867 860 bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted a status update', 'buddypress' ) ); 861 bp_activity_set_action( $bp->activity->id, 'activity_comment', __( 'Replied to a status update', 'buddypress' ) ); 868 bp_activity_set_action( 869 $bp->activity->id, 870 'activity_update', 871 __( 'Posted a status update', 'buddypress' ), 872 'bp_activity_format_activity_action_activity_update' 873 ); 874 875 bp_activity_set_action( 876 $bp->activity->id, 877 'activity_comment', 878 __( 'Replied to a status update', 'buddypress' ), 879 'bp_activity_format_activity_action_activity_comment' 880 ); 862 881 863 882 do_action( 'bp_activity_register_activity_actions' ); 864 883 … … function bp_activity_register_activity_actions() { 867 886 } 868 887 add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actions' ); 869 888 889 /** 890 * Generate an activity action string for an activity item. 891 * 892 * @param object $activity Activity data object. 893 * @return string|bool Returns false if no callback is found, otherwise returns 894 * the formatted action string. 895 */ 896 function bp_activity_generate_action_string( $activity ) { 897 // Check for valid input 898 if ( empty( $activity->component ) || empty( $activity->type ) ) { 899 return false; 900 } 901 902 // Check for registered format callback 903 if ( empty( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'] ) ) { 904 return false; 905 } 906 907 return call_user_func( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], $activity ); 908 } 909 910 /** 911 * Format 'activity_update' activity actions. 912 * 913 * @since BuddyPress (2.0.0) 914 * 915 * @param object $activity Activity data object. 916 * @return string 917 */ 918 function bp_activity_format_activity_action_activity_update( $activity ) { 919 $action = sprintf( __( '%s posted an update', 'buddypress' ), bp_activity_get_userlink( $activity ) ); 920 return apply_filters( 'bp_activity_new_update_action', $action, $activity ); 921 } 922 923 /** 924 * Format 'activity_comment' activity actions. 925 * 926 * @since BuddyPress (2.0.0) 927 * 928 * @param object $activity Activity data object. 929 * @return string 930 */ 931 function bp_activity_format_activity_action_activity_comment( $activity ) { 932 $action = sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_activity_get_userlink( $activity ) ); 933 return apply_filters( 'bp_activity_comment_action', $action, $activity ); 934 } 935 936 /** 937 * Gets the user link for activity items. 938 * 939 * During the activity loop, we have already queried all the userdata for each 940 * activity item, therefore we can reference these items directly instead of 941 * bp_core_get_userlink(), which can lead to unnecessary queries. 942 * 943 * @since BuddyPress (2.0.0) 944 * 945 * @param object $activity Activity data object. 946 * @return string 947 */ 948 function bp_activity_get_userlink( $activity ) { 949 // $activity->user_nicename is only populated during an activity loop 950 // not during a new BP_Activity_Activity object 951 // 952 // in these cases, fetch userlink as always 953 if ( empty( $activity->user_nicename ) ) { 954 return bp_core_get_userlink( $activity->user_id ); 955 } 956 957 $url = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ); 958 959 // apply 'bp_core_get_userlink' just in case 960 return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '" title="' . $activity->user_fullname . '">' . $activity->user_fullname . '</a>', $activity->user_id ); 961 } 962 870 963 /****************************************************************************** 871 964 * Business functions are where all the magic happens in BuddyPress. They will 872 965 * handle the actual saving or manipulation of information. Usually they will … … function bp_activity_add( $args = '' ) { 1087 1180 $activity->user_id = $user_id; 1088 1181 $activity->component = $component; 1089 1182 $activity->type = $type; 1090 $activity->action = $action;1091 1183 $activity->content = $content; 1092 1184 $activity->primary_link = $primary_link; 1093 1185 $activity->item_id = $item_id; … … function bp_activity_add( $args = '' ) { 1095 1187 $activity->date_recorded = $recorded_time; 1096 1188 $activity->hide_sitewide = $hide_sitewide; 1097 1189 $activity->is_spam = $is_spam; 1190 $activity->action = ! empty( $action ) ? $action : bp_activity_generate_action_string( $activity ); 1098 1191 1099 1192 if ( !$activity->save() ) 1100 1193 return false; … … function bp_activity_post_update( $args = '' ) { 1150 1243 1151 1244 // Record this on the user's profile 1152 1245 $from_user_link = bp_core_get_userlink( $user_id ); 1153 $activity_action = sprintf( __( '%s posted an update', 'buddypress' ), $from_user_link );1154 1246 $activity_content = $content; 1155 1247 $primary_link = bp_core_get_userlink( $user_id, false, true ); 1156 1248 1157 1249 // Now write the values 1158 1250 $activity_id = bp_activity_add( array( 1159 1251 'user_id' => $user_id, 1160 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),1161 1252 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ), 1162 1253 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ), 1163 1254 'component' => $bp->activity->id, 1164 'type' => 'activity_update' 1255 'type' => 'activity_update', 1165 1256 ) ); 1166 1257 1167 1258 $activity_content = apply_filters( 'bp_activity_latest_update_content', $content, $activity_content ); … … function bp_activity_new_comment( $args = '' ) { 1230 1321 // Insert the activity comment 1231 1322 $comment_id = bp_activity_add( array( 1232 1323 'id' => $id, 1233 'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),1234 1324 'content' => apply_filters( 'bp_activity_comment_content', $content ), 1235 1325 'component' => buddypress()->activity->id, 1236 1326 'type' => 'activity_comment', -
bp-blogs/bp-blogs-activity.php
function bp_blogs_register_activity_actions() { 28 28 } 29 29 30 30 if ( is_multisite() ) { 31 bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New site created', 'buddypress' ) ); 31 bp_activity_set_action( 32 $bp->blogs->id, 33 'new_blog', 34 __( 'New site created', 'buddypress' ), 35 'bp_blogs_format_activity_action_new_blog' 36 ); 32 37 } 33 38 34 bp_activity_set_action( $bp->blogs->id, 'new_blog_post', __( 'New post published', 'buddypress' ) ); 35 bp_activity_set_action( $bp->blogs->id, 'new_blog_comment', __( 'New post comment posted', 'buddypress' ) ); 39 bp_activity_set_action( 40 $bp->blogs->id, 41 'new_blog_post', 42 __( 'New post published', 'buddypress' ), 43 'bp_blogs_format_activity_action_new_blog_post' 44 ); 45 46 bp_activity_set_action( 47 $bp->blogs->id, 48 'new_blog_comment', 49 __( 'New post comment posted', 'buddypress' ), 50 'bp_blogs_format_activity_action_new_blog_comment' 51 ); 36 52 37 53 do_action( 'bp_blogs_register_activity_actions' ); 38 54 } 39 55 add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' ); 40 56 41 57 /** 58 * Format 'new_blog' activity actions. 59 * 60 * @since BuddyPress (2.0.0) 61 * 62 * @param obj $activity Activity data object. 63 */ 64 function bp_blogs_format_activity_action_new_blog( $activity ) { 65 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 66 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 67 68 $action = sprintf( __( '%s created the site %s', 'buddypress' ), bp_activity_get_userlink( $activity ), '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' ); 69 70 // Legacy filter - requires the BP_Blogs_Blog object 71 if ( has_filter( 'bp_blogs_activity_created_blog_action' ) ) { 72 $user_blog = BP_Blogs_Blog::get_user_blog( $activity->user_id, $activity->item_id ); 73 if ( $user_blog ) { 74 $recorded_blog = new BP_Blogs_Blog( $user_blog ); 75 } 76 77 if ( isset( $recorded_blog ) ) { 78 $action = apply_filters( 'bp_blogs_activity_created_blog_action', $action, $recorded_blog, $blog_name, bp_blogs_get_blogmeta( $activity->item_id, 'description' ) ); 79 } 80 } 81 82 return apply_filters( 'bp_blogs_format_activity_action_new_blog', $action, $activity ); 83 } 84 85 /** 86 * Format 'new_blog_post' activity actions. 87 * 88 * @since BuddyPress (2.0.0) 89 * 90 * @param obj $activity Activity data object. 91 */ 92 function bp_blogs_format_activity_action_new_blog_post( $activity ) { 93 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 94 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 95 96 if ( empty( $blog_url ) || empty( $blog_name ) ) { 97 $blog_url = get_home_url( $activity->item_id ); 98 $blog_name = get_blog_option( $activity->item_id, 'blogname' ); 99 100 bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url ); 101 bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name ); 102 } 103 104 $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) ); 105 106 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 107 108 // Should only be empty at the time of post creation 109 if ( empty( $post_title ) ) { 110 switch_to_blog( $activity->item_id ); 111 112 $post = get_post( $activity->secondary_item_id ); 113 if ( is_a( $post, 'WP_Post' ) ) { 114 $post_title = $post->post_title; 115 bp_activity_update_meta( $activity->id, 'post_title', $post_title ); 116 } 117 118 restore_current_blog(); 119 } 120 121 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; 122 123 $user_link = bp_activity_get_userlink( $activity ); 124 125 if ( is_multisite() ) { 126 $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>' ); 127 } else { 128 $action = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress' ), $user_link, $post_link ); 129 } 130 131 // Legacy filter - requires the post object 132 if ( has_filter( 'bp_blogs_activity_new_post_action' ) ) { 133 switch_to_blog( $activity->item_id ); 134 $post = get_post( $activity->secondary_item_id ); 135 restore_current_blog(); 136 137 if ( ! empty( $post ) && ! is_wp_error( $post ) ) { 138 $action = apply_filters( 'bp_blogs_activity_new_post_action', $action, $post, $post_url ); 139 } 140 } 141 142 return apply_filters( 'bp_blogs_format_activity_action_new_blog_post', $action, $activity ); 143 } 144 145 /** 146 * Format 'new_blog_comment' activity actions. 147 * 148 * @since BuddyPress (2.0.0) 149 * 150 * @param obj $activity Activity data object. 151 */ 152 function bp_blogs_format_activity_action_new_blog_comment( $activity ) { 153 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 154 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 155 156 if ( empty( $blog_url ) || empty( $blog_name ) ) { 157 $blog_url = get_home_url( $activity->item_id ); 158 $blog_name = get_blog_option( $activity->item_id, 'blogname' ); 159 160 bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url ); 161 bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name ); 162 } 163 164 $post_url = bp_activity_get_meta( $activity->id, 'post_url' ); 165 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 166 167 // Should only be empty at the time of post creation 168 if ( empty( $post_url ) || empty( $post_title ) ) { 169 switch_to_blog( $activity->item_id ); 170 171 $comment = get_comment( $activity->secondary_item_id ); 172 173 if ( ! empty( $comment->comment_post_ID ) ) { 174 $post_url = add_query_arg( 'p', $comment->comment_post_ID, trailingslashit( $blog_url ) ); 175 bp_activity_update_meta( $activity->id, 'post_url', $post_url ); 176 177 $post = get_post( $comment->comment_post_ID ); 178 179 if ( is_a( $post, 'WP_Post' ) ) { 180 $post_title = $post->post_title; 181 bp_activity_update_meta( $activity->id, 'post_title', $post_title ); 182 } 183 } 184 185 restore_current_blog(); 186 } 187 188 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; 189 $user_link = bp_activity_get_userlink( $activity ); 190 191 if ( is_multisite() ) { 192 $action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' ); 193 } else { 194 $action = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), $user_link, $post_link ); 195 } 196 197 // Legacy filter - requires the comment object 198 if ( has_filter( 'bp_blogs_activity_new_comment_action' ) ) { 199 switch_to_blog( $activity->item_id ); 200 $comment = get_comment( $activity->secondary_item_id ); 201 restore_current_blog(); 202 203 if ( ! empty( $comment ) && ! is_wp_error( $comment ) ) { 204 $action = apply_filters( 'bp_blogs_activity_new_comment_action', $action, $comment, $post_url . '#' . $activity->secondary_item_id ); 205 } 206 } 207 208 return apply_filters( 'bp_blogs_format_activity_action_new_blog_comment', $action, $activity ); 209 } 210 211 /** 212 * Fetch data related to blogs at the beginning of an activity loop. 213 * 214 * This reduces database overhead during the activity loop. 215 * 216 * @since BuddyPress (2.0.0) 217 * 218 * @param array $activities Array of activity items. 219 * @return array 220 */ 221 function bp_blogs_prefetch_activity_object_data( $activities ) { 222 if ( empty( $activities ) ) { 223 return $activities; 224 } 225 226 $blog_ids = array(); 227 228 foreach ( $activities as $activity ) { 229 if ( buddypress()->blogs->id !== $activity->component ) { 230 continue; 231 } 232 233 $blog_ids[] = $activity->item_id; 234 } 235 236 if ( ! empty( $blog_ids ) ) { 237 bp_blogs_update_meta_cache( $blog_ids ); 238 } 239 } 240 add_filter( 'bp_activity_prefetch_object_data', 'bp_blogs_prefetch_activity_object_data' ); 241 /** 42 242 * Record blog-related activity to the activity stream. 43 243 * 44 244 * @since BuddyPress (1.0.0) -
bp-blogs/bp-blogs-classes.php
class BP_Blogs_Blog { 503 503 504 504 return false; 505 505 } 506 507 /** 508 * Get ID of user-blog link. 509 * 510 * @param int $user_id ID of user. 511 * @param int $blog_id ID of blog. 512 * @return int|bool ID of user-blog link, or false if not found. 513 */ 514 public static function get_user_blog( $user_id, $blog_id ) { 515 global $bp, $wpdb; 516 517 $user_blog = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) ); 518 519 if ( empty( $user_blog ) ) { 520 $user_blog = false; 521 } else { 522 $user_blog = intval( $user_blog ); 523 } 524 525 return $user_blog; 526 } 506 527 } -
bp-blogs/bp-blogs-functions.php
function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 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 ); 185 186 $name = get_blog_option( $blog_id, 'blogname' ); 186 187 $description = get_blog_option( $blog_id, 'blogdescription' ); 187 188 … … function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 194 195 $recorded_blog_id = $recorded_blog->save(); 195 196 $is_recorded = !empty( $recorded_blog_id ) ? true : false; 196 197 198 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'url', $url ); 197 199 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name ); 198 200 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description ); 199 201 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() ); … … function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 207 209 // Record this in activity streams 208 210 bp_blogs_record_activity( array( 209 211 'user_id' => $recorded_blog->user_id, 210 'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the site %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_home_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), $recorded_blog, $name, $description ), 211 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_home_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ), 212 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', $url, $recorded_blog->blog_id ), 212 213 'type' => 'new_blog', 213 214 'item_id' => $recorded_blog->blog_id 214 215 ) ); … … function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) { 355 356 356 357 bp_blogs_record_activity( array( 357 358 'user_id' => (int) $post->post_author, 358 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ),359 359 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ), 360 360 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), 361 361 'type' => 'new_blog_post', … … function bp_blogs_record_comment( $comment_id, $is_approved = true ) { 450 450 // Record in activity streams 451 451 bp_blogs_record_activity( array( 452 452 'user_id' => $user_id, 453 'action' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_action', array( $activity_action, &$recorded_comment, $comment_link ) ),454 453 'content' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $activity_content, &$recorded_comment, $comment_link ) ), 455 454 'primary_link' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$recorded_comment ) ), 456 455 'type' => 'new_blog_comment', -
bp-friends/bp-friends-activity.php
function friends_register_activity_actions() { 92 92 $bp = buddypress(); 93 93 94 94 // These two added in BP 1.6 95 bp_activity_set_action( $bp->friends->id, 'friendship_accepted', __( 'Friendships accepted', 'buddypress' ) ); 96 bp_activity_set_action( $bp->friends->id, 'friendship_created', __( 'New friendships', 'buddypress' ) ); 95 bp_activity_set_action( 96 $bp->friends->id, 97 'friendship_accepted', 98 __( 'Friendships accepted', 'buddypress' ), 99 'bp_friends_format_activity_action_friendship_accepted' 100 ); 101 102 bp_activity_set_action( 103 $bp->friends->id, 104 'friendship_created', 105 __( 'New friendships', 'buddypress' ), 106 'bp_friends_format_activity_action_friendship_created' 107 ); 97 108 98 109 // < BP 1.6 backpat 99 110 bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) ); … … function friends_register_activity_actions() { 103 114 add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' ); 104 115 105 116 /** 117 * Format 'friendship_accepted' activity actions. 118 * 119 * @since BuddyPress (2.0.0) 120 * 121 * @param object $activity Activity data. 122 * @return string $action Formatted activity action. 123 */ 124 function bp_friends_format_activity_action_friendship_accepted( $activity ) { 125 $initiator_link = bp_activity_get_userlink( $activity ); 126 $friend_link = bp_core_get_userlink( $activity->secondary_item_id ); 127 128 $action = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ); 129 130 // Backward compatibility for legacy filter 131 // The old filter has the $friendship object passed to it. We want to 132 // avoid having to build this object if it's not necessary 133 if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) { 134 $friendship = new BP_Friends_Friendship( $activity->item_id ); 135 $action = apply_filters( 'friends_activity_friendsip_accepted_action', $action, $friendship ); 136 } 137 138 return apply_filters( 'bp_friends_format_activity_action_friendship_accepted', $action, $activity ); 139 } 140 141 /** 142 * Format 'friendship_created' activity actions. 143 * 144 * @since BuddyPress (2.0.0) 145 * 146 * @param object $activity Activity data. 147 * @return string $action Formatted activity action. 148 */ 149 function bp_friends_format_activity_action_friendship_created( $activity ) { 150 $initiator_link = bp_activity_get_userlink( $activity ); 151 $friend_link = bp_core_get_userlink( $activity->secondary_item_id ); 152 153 $action = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ); 154 155 // Backward compatibility for legacy filter 156 // The old filter has the $friendship object passed to it. We want to 157 // avoid having to build this object if it's not necessary 158 if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) { 159 $friendship = new BP_Friends_Friendship( $activity->item_id ); 160 $action = apply_filters( 'friends_activity_friendsip_accepted_action', $action, $friendship ); 161 } 162 163 return apply_filters( 'bp_friends_format_activity_action_friendship_created', $action, $activity ); 164 } 165 166 /** 167 * Fetch data related to friended users at the beginning of an activity loop. 168 * 169 * This reduces database overhead during the activity loop. 170 * 171 * @since BuddyPress (2.0.0) 172 * 173 * @param array $activities Array of activity items. 174 * @return array 175 */ 176 function bp_friends_prefetch_activity_object_data( $activities ) { 177 if ( empty( $activities ) ) { 178 return $activities; 179 } 180 181 $friend_ids = array(); 182 183 foreach ( $activities as $activity ) { 184 if ( buddypress()->friends->id !== $activity->component ) { 185 continue; 186 } 187 188 $friend_ids[] = $activity->secondary_item_id; 189 } 190 191 if ( ! empty( $friend_ids ) ) { 192 // Fire a user query to prime user caches 193 new BP_User_Query( array( 194 'user_ids' => $friend_ids, 195 'populate_extras' => false, 196 'update_meta_cache' => false, 197 ) ); 198 } 199 } 200 add_filter( 'bp_activity_prefetch_object_data', 'bp_friends_prefetch_activity_object_data' ); 201 202 /** 106 203 * Add activity stream items when one members accepts another members request 107 204 * for virtual friendship. 108 205 * … … function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_use 128 225 friends_record_activity( array( 129 226 'user_id' => $initiator_user_id, 130 227 'type' => 'friendship_created', 131 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), $friendship ),132 228 'item_id' => $friendship_id, 133 229 'secondary_item_id' => $friend_user_id 134 230 ) ); … … function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_use 137 233 friends_record_activity( array( 138 234 'user_id' => $friend_user_id, 139 235 'type' => 'friendship_created', 140 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), $friendship ),141 236 'item_id' => $friendship_id, 142 237 'secondary_item_id' => $initiator_user_id, 143 238 'hide_sitewide' => true // We've already got the first entry site wide -
bp-groups/bp-groups-actions.php
function groups_action_create_group() { 150 150 151 151 // Once we compelete all steps, record the group creation in the activity stream. 152 152 groups_record_activity( array( 153 'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%1$s created the group %2$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ),154 153 'type' => 'created_group', 155 154 'item_id' => $bp->groups->new_group_id 156 155 ) ); -
bp-groups/bp-groups-activity.php
function groups_register_activity_actions() { 23 23 return false; 24 24 } 25 25 26 bp_activity_set_action( $bp->groups->id, 'created_group', __( 'Created a group', 'buddypress' ) ); 27 bp_activity_set_action( $bp->groups->id, 'joined_group', __( 'Joined a group', 'buddypress' ) ); 26 bp_activity_set_action( 27 $bp->groups->id, 28 'created_group', 29 __( 'Created a group', 'buddypress' ), 30 'bp_groups_format_activity_action_created_group' 31 ); 32 33 bp_activity_set_action( 34 $bp->groups->id, 35 'joined_group', 36 __( 'Joined a group', 'buddypress' ), 37 'bp_groups_format_activity_action_joined_group' 38 ); 28 39 29 40 // These actions are for the legacy forums 30 41 // Since the bbPress plugin also shares the same 'forums' identifier, we also … … function groups_register_activity_actions() { 39 50 add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' ); 40 51 41 52 /** 53 * Format 'created_group' activity actions. 54 * 55 * @since BuddyPress (2.0.0) 56 * 57 * @param object $activity Activity data object. 58 * @return string 59 */ 60 function bp_groups_format_activity_action_created_group( $activity ) { 61 $user_link = bp_activity_get_userlink( $activity ); 62 63 $group = groups_get_group( array( 64 'group_id' => $activity->item_id, 65 'populate_extras' => false, 66 ) ); 67 $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>'; 68 69 $action = sprintf( __( '%1$s created the group %2$s', 'buddypress'), $user_link, $group_link ); 70 71 return apply_filters( 'groups_activity_created_group_action', $action, $activity ); 72 } 73 74 /** 75 * Format 'joined_group' activity actions. 76 * 77 * @since BuddyPress (2.0.0) 78 * 79 * @param object $activity Activity data object. 80 * @return string 81 */ 82 function bp_groups_format_activity_action_joined_group( $activity ) { 83 $user_link = bp_activity_get_userlink( $activity ); 84 85 $group = groups_get_group( array( 86 'group_id' => $activity->item_id, 87 'populate_extras' => false, 88 ) ); 89 $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>'; 90 91 $action = sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), $user_link, $group_link ); 92 93 // Legacy filters (do not follow parameter patterns of other activity 94 // action filters, and requires apply_filters_ref_array()) 95 if ( has_filter( 'groups_activity_membership_accepted_action' ) ) { 96 $action = apply_filters_ref_array( 'groups_activity_membership_accepted_action', array( $action, $user_link, &$group ) ); 97 } 98 99 // Another legacy filter 100 if ( has_filter( 'groups_activity_accepted_invite_action' ) ) { 101 $action = apply_filters_ref_array( 'groups_activity_accepted_invite_action', array( $action, $activity->user_id, &$group ) ); 102 } 103 104 return apply_filters( 'bp_groups_format_activity_action_joined_group', $action, $activity ); 105 } 106 107 /** 108 * Fetch data related to groups at the beginning of an activity loop. 109 * 110 * This reduces database overhead during the activity loop. 111 * 112 * @since BuddyPress (2.0.0) 113 * 114 * @param array $activities Array of activity items. 115 * @return array 116 */ 117 function bp_groups_prefetch_activity_object_data( $activities ) { 118 $group_ids = array(); 119 120 if ( empty( $activities ) ) { 121 return $activities; 122 } 123 124 foreach ( $activities as $activity ) { 125 if ( buddypress()->groups->id !== $activity->component ) { 126 continue; 127 } 128 129 $group_ids[] = $activity->item_id; 130 } 131 132 if ( ! empty( $group_ids ) ) { 133 134 // TEMPORARY - Once the 'populate_extras' issue is solved 135 // in the groups component, we can do this with groups_get_groups() 136 // rather than manually 137 $uncached_ids = array(); 138 foreach ( $group_ids as $group_id ) { 139 if ( false === wp_cache_get( $group_id, 'bp_groups' ) ) { 140 $uncached_ids[] = $group_id; 141 } 142 } 143 144 global $wpdb, $bp; 145 $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) ); 146 $groups = $wpdb->get_results( "SELECT * FROM {$bp->groups->table_name} WHERE id IN ({$uncached_ids_sql})" ); 147 foreach ( $groups as $group ) { 148 wp_cache_set( $group->id, $group, 'bp_groups' ); 149 } 150 } 151 } 152 add_filter( 'bp_activity_prefetch_object_data', 'bp_groups_prefetch_activity_object_data' ); 153 154 /** 42 155 * Record an activity item related to the Groups component. 43 156 * 44 157 * A wrapper for {@link bp_activity_add()} that provides some Groups-specific … … function bp_groups_membership_accepted_add_activity( $user_id, $group_id ) { 141 254 'type' => 'joined_group', 142 255 'item_id' => $group_id, 143 256 'user_id' => $user_id 144 ) ); 257 ) ); 145 258 } 146 259 add_action( 'groups_membership_accepted', 'bp_groups_membership_accepted_add_activity', 10, 2 ); 147 260 … … function bp_groups_leave_group_delete_recent_activity( $group_id, $user_id ) { 192 305 } 193 306 add_action( 'groups_leave_group', 'bp_groups_leave_group_delete_recent_activity', 10, 2 ); 194 307 add_action( 'groups_remove_member', 'bp_groups_leave_group_delete_recent_activity', 10, 2 ); 195 add_action( 'groups_ban_member', 'bp_groups_leave_group_delete_recent_activity', 10, 2 ); 196 No newline at end of file 308 add_action( 'groups_ban_member', 'bp_groups_leave_group_delete_recent_activity', 10, 2 ); -
bp-groups/bp-groups-functions.php
function groups_join_group( $group_id, $user_id = 0 ) { 329 329 330 330 // Record this in activity streams 331 331 groups_record_activity( array( 332 'action' => apply_filters( 'groups_activity_joined_group', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>' ) ),333 332 'type' => 'joined_group', 334 333 'item_id' => $group_id, 335 'user_id' => $user_id 334 'user_id' => $user_id, 336 335 ) ); 337 336 338 337 // Modify group meta -
bp-groups/bp-groups-screens.php
function groups_screen_group_invites() { 49 49 $group = groups_get_group( array( 'group_id' => $group_id ) ); 50 50 51 51 groups_record_activity( array( 52 'action' => apply_filters_ref_array( 'groups_activity_accepted_invite_action', array( sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), bp_loggedin_user_id(), &$group ) ),53 52 'type' => 'joined_group', 54 53 'item_id' => $group->id 55 54 ) ); -
bp-members/bp-members-functions.php
function bp_core_new_user_activity( $user ) { 1553 1553 1554 1554 bp_activity_add( array( 1555 1555 'user_id' => $user_id, 1556 'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),1557 1556 'component' => 'xprofile', 1558 1557 'type' => 'new_member' 1559 1558 ) ); -
bp-xprofile/bp-xprofile-activity.php
function xprofile_register_activity_actions() { 17 17 global $bp; 18 18 19 19 // Register the activity stream actions for this component 20 bp_activity_set_action( $bp->profile->id, 'new_avatar', __( 'Member changed profile picture', 'buddypress' ) ); 21 bp_activity_set_action( $bp->profile->id, 'new_member', __( 'New member registered', 'buddypress' ) ); 22 bp_activity_set_action( $bp->profile->id, 'updated_profile', __( 'Updated Profile', 'buddypress' ) ); 20 bp_activity_set_action( 21 $bp->profile->id, 22 'new_avatar', 23 __( 'Member changed profile picture', 'buddypress' ), 24 'bp_xprofile_format_activity_action_new_avatar' 25 ); 26 27 bp_activity_set_action( 28 $bp->profile->id, 29 'new_member', 30 __( 'New member registered', 'buddypress' ), 31 'bp_xprofile_format_activity_action_new_member' 32 ); 33 34 bp_activity_set_action( 35 $bp->profile->id, 36 'updated_profile', 37 __( 'Updated Profile', 'buddypress' ), 38 'bp_xprofile_format_activity_action_updated_profile' 39 ); 23 40 24 41 do_action( 'xprofile_register_activity_actions' ); 25 42 } 26 43 add_action( 'bp_register_activity_actions', 'xprofile_register_activity_actions' ); 27 44 28 45 /** 46 * Format 'new_avatar' activity actions. 47 * 48 * @since BuddyPress (2.0.0) 49 * 50 * @param object $activity Activity object. 51 * @return string 52 */ 53 function bp_xprofile_format_activity_action_new_avatar( $activity ) { 54 $userlink = bp_activity_get_userlink( $activity ); 55 $action = sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink ); 56 57 // Legacy filter - pass $user_id instead of $activity 58 if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) { 59 $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id ); 60 } 61 62 return apply_filters( 'bp_xprofile_format_activity_action_new_avatar', $action, $activity ); 63 } 64 65 /** 66 * Format 'new_member' activity actions. 67 * 68 * @since BuddyPress (2.0.0) 69 * 70 * @param object $activity Activity object. 71 * @return string 72 */ 73 function bp_xprofile_format_activity_action_new_member( $activity ) { 74 $userlink = bp_activity_get_userlink( $activity ); 75 $action = sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ); 76 77 // Legacy filter - pass $user_id instead of $activity 78 if ( has_filter( 'bp_core_activity_registered_member_action' ) ) { 79 $action = apply_filters( 'bp_core_activity_registered_member_action', $action, $activity->user_id ); 80 } 81 82 return apply_filters( 'bp_xprofile_format_activity_action_new_member', $action, $activity ); 83 } 84 85 /** 86 * Format 'updated_profile' activity actions. 87 * 88 * @since BuddyPress (2.0.0) 89 * 90 * @param object $activity Activity object. 91 * @return string 92 */ 93 function bp_xprofile_format_activity_action_updated_profile( $activity ) { 94 // Note for translators: The natural phrasing in English, "Joe updated 95 // his profile", requires that we know Joe's gender, which we don't. If 96 // your language doesn't have this restriction, feel free to use a more 97 // natural translation. 98 $profile_link = trailingslashit( bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . buddypress()->profile->slug ); 99 $action = sprintf( __( '%1$s’s profile was updated', 'buddypress' ), '<a href="' . $profile_link . '">' . bp_core_get_user_displayname( $activity->user_id ) . '</a>' ); 100 101 return apply_filters( 'bp_xprofile_format_activity_action_updated_profile', $action, $activity ); 102 } 103 104 /** 29 105 * Records activity for the logged in user within the profile component so that 30 106 * it will show in the users activity stream (if installed) 31 107 * … … function bp_xprofile_new_avatar_activity() { 126 202 127 203 bp_activity_add( array( 128 204 'user_id' => $user_id, 129 'action' => apply_filters( 'bp_xprofile_new_avatar_action', sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink ), $user_id ),130 205 'component' => 'profile', 131 206 'type' => 'new_avatar' 132 207 ) ); … … function bp_xprofile_updated_profile_activity( $user_id, $field_ids, $errors, $o 207 282 } 208 283 209 284 // If we've reached this point, assemble and post the activity item 210 211 // Note for translators: The natural phrasing in English, "Joe updated212 // his profile", requires that we know Joe's gender, which we don't. If213 // your language doesn't have this restriction, feel free to use a more214 // natural translation.215 285 $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . buddypress()->profile->slug ); 216 $action = sprintf( __( '%1$s’s profile was updated', 'buddypress' ), '<a href="' . $profile_link . '">' . bp_core_get_user_displayname( $user_id ) . '</a>' );217 286 218 287 $retval = xprofile_record_activity( array( 219 288 'user_id' => $user_id, 220 'action' => $action,221 289 'primary_link' => $profile_link, 222 290 'component' => buddypress()->profile->id, 223 291 'type' => 'updated_profile', -
tests/includes/factory.php
class BP_UnitTest_Factory_For_Activity extends WP_UnitTest_Factory_For_Thing { 19 19 parent::__construct( $factory ); 20 20 21 21 $this->default_generation_definitions = array( 22 'action' => new WP_UnitTest_Generator_Sequence( 'Activity action %s' ),23 22 'component' => buddypress()->activity->id, 24 23 'content' => new WP_UnitTest_Generator_Sequence( 'Activity content %s' ), 25 24 'primary_link' => 'http://example.com', -
tests/testcases/activity/functions.php
Bar!'; 540 540 remove_filter( 'bp_is_username_compatibility_mode', '__return_true' ); 541 541 } 542 542 543 /** 544 * @group activity_action 545 * @group bp_activity_format_activity_action_activity_update 546 */ 547 public function test_bp_activity_format_activity_action_activity_update() { 548 $u = $this->create_user(); 549 $a = $this->factory->activity->create( array( 550 'component' => buddypress()->activity->id, 551 'type' => 'activity_update', 552 'user_id' => $u, 553 ) ); 554 555 $a_obj = new BP_Activity_Activity( $a ); 556 557 $expected = sprintf( '%s posted an update', bp_core_get_userlink( $u ) ); 558 559 $this->assertSame( $expected, $a_obj->action ); 560 } 561 562 /** 563 * @group activity_action 564 * @group bp_activity_format_activity_action_activity_comment 565 */ 566 public function test_bp_activity_format_activity_action_activity_comment() { 567 $u = $this->create_user(); 568 $a = $this->factory->activity->create( array( 569 'component' => buddypress()->activity->id, 570 'type' => 'activity_comment', 571 'user_id' => $u, 572 ) ); 573 574 $a_obj = new BP_Activity_Activity( $a ); 575 576 $expected = sprintf( '%s posted a new activity comment', bp_core_get_userlink( $u ) ); 577 578 $this->assertSame( $expected, $a_obj->action ); 579 } 580 543 581 } -
tests/testcases/xprofile/activity.php
class BP_Tests_XProfile_Activity extends BP_UnitTestCase { 270 270 $this->assertTrue( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) ); 271 271 } 272 272 273 /** 274 * @group activity_action 275 * @group bp_xprofile_format_activity_action_new_avatar 276 */ 277 public function test_bp_xprofile_format_activity_action_new_avatar() { 278 $u = $this->create_user(); 279 $a = $this->factory->activity->create( array( 280 'component' => buddypress()->profile->id, 281 'type' => 'new_avatar', 282 'user_id' => $u, 283 ) ); 284 285 $expected = sprintf( __( '%s changed their profile picture', 'buddypress' ), bp_core_get_userlink( $u ) ); 286 287 $a_obj = new BP_Activity_Activity( $a ); 288 289 $this->assertSame( $expected, $a_obj->action ); 290 } 291 292 /** 293 * @group activity_action 294 * @group bp_xprofile_format_activity_action_new_member 295 */ 296 public function test_bp_xprofile_format_activity_action_new_member_xprofile_on() { 297 $active = bp_is_active( 'xprofile' ); 298 buddypress()->active_components['xprofile'] = '1'; 299 300 $u = $this->create_user(); 301 $a = $this->factory->activity->create( array( 302 'component' => buddypress()->profile->id, 303 'type' => 'new_member', 304 'user_id' => $u, 305 ) ); 306 307 $expected = sprintf( __( '%s became a registered member', 'buddypress' ), bp_core_get_userlink( $u ) ); 308 309 $a_obj = new BP_Activity_Activity( $a ); 310 311 $this->assertSame( $expected, $a_obj->action ); 312 313 if ( ! $active ) { 314 unset( buddypress()->active_components['xprofile'] ); 315 } 316 } 317 318 /** 319 * @group activity_action 320 * @group bp_xprofile_format_activity_action_new_member 321 */ 322 public function test_bp_xprofile_format_activity_action_new_member_xprofile_off() { 323 $active = bp_is_active( 'xprofile' ); 324 unset( buddypress()->active_components['xprofile'] ); 325 326 $u = $this->create_user(); 327 $a = $this->factory->activity->create( array( 328 'component' => buddypress()->profile->id, 329 'type' => 'new_member', 330 'user_id' => $u, 331 ) ); 332 333 $expected = sprintf( __( '%s became a registered member', 'buddypress' ), bp_core_get_userlink( $u ) ); 334 335 $a_obj = new BP_Activity_Activity( $a ); 336 337 $this->assertSame( $expected, $a_obj->action ); 338 339 if ( $active ) { 340 buddypress()->active_components['xprofile'] = '1'; 341 } 342 } 343 344 /** 345 * @group activity_action 346 * @group bp_xprofile_format_activity_action_updated_profile 347 */ 348 public function test_bp_xprofile_format_activity_action_updated_profile() { 349 $u = $this->create_user(); 350 $a = $this->factory->activity->create( array( 351 'component' => buddypress()->profile->id, 352 'type' => 'updated_profile', 353 'user_id' => $u, 354 ) ); 355 356 $expected = sprintf( __( '%s’s profile was updated', 'buddypress' ), '<a href="' . bp_core_get_user_domain( $u ) . buddypress()->profile->slug . '/">' . bp_core_get_user_displayname( $u ) . '</a>' ); 357 358 $a_obj = new BP_Activity_Activity( $a ); 359 360 $this->assertSame( $expected, $a_obj->action ); 361 } 273 362 274 363 protected function setup_updated_profile_data() { 275 364 $this->updated_profile_data['u'] = $this->create_user();