Ticket #3460: 3460.2.diff
File 3460.2.diff, 18.5 KB (added by , 11 years ago) |
---|
-
bp-activity/bp-activity-template.php
2582 2582 $can_comment = true; 2583 2583 2584 2584 if ( false === $activities_template->disable_blogforum_replies || (int) $activities_template->disable_blogforum_replies ) { 2585 if ( 'new_blog_post' == bp_get_activity_action_name() || 'new_blog_comment' == bp_get_activity_action_name() || 'new_forum_topic' == bp_get_activity_action_name() || 'new_forum_post' == bp_get_activity_action_name() ) 2585 2586 $comment_objects = array( 'new_forum_topic', 'new_forum_post' ); 2587 2588 if( bp_is_active( 'blogs' ) ) { 2589 $available_post_types = get_object_vars( buddypress()->activity->actions->blogs ); 2590 $comment_objects = array_merge( $comment_objects, array_keys( $available_post_types ) ); 2591 } 2592 2593 if ( in_array( bp_get_activity_action_name(), $comment_objects ) ) 2586 2594 $can_comment = false; 2587 2595 } 2588 2596 … … 3269 3277 <?php 3270 3278 } 3271 3279 add_action( 'bp_head', 'bp_activity_sitewide_feed' ); 3280 3281 3282 3283 /** Activity type for post types **/ 3284 function bp_activity_post_type_filter_options() { 3285 echo bp_get_activity_post_type_filter_options(); 3286 } 3287 3288 function bp_get_activity_post_type_filter_options() { 3289 $output = ''; 3290 3291 if( !bp_is_active( 'blogs' ) ) 3292 return $output; 3293 3294 $available_types = buddypress()->activity->actions->blogs; 3295 3296 foreach( $available_types as $post_type ) { 3297 $output .= '<option value="' . $post_type['key'] . '">' . $post_type['value'] . '</option>' ."\n"; 3298 } 3299 3300 return apply_filters( 'bp_get_activity_post_type_filter_options', $output ); 3301 } 3302 3303 -
bp-templates/bp-legacy/buddypress/members/single/activity.php
22 22 23 23 <?php 24 24 if ( !bp_is_current_action( 'groups' ) ) : 25 if ( bp_is_active( 'blogs' ) ) : ?>25 bp_activity_post_type_filter_options(); 26 26 27 <option value="new_blog_post"><?php _e( 'Posts', 'buddypress' ); ?></option>28 <option value="new_blog_comment"><?php _e( 'Comments', 'buddypress' ); ?></option>29 30 <?php31 endif;32 33 27 if ( bp_is_active( 'friends' ) ) : ?> 34 28 35 29 <option value="friendship_accepted,friendship_created"><?php _e( 'Friendships', 'buddypress' ); ?></option> -
bp-templates/bp-legacy/buddypress/activity/index.php
78 78 <option value="-1"><?php _e( 'Everything', 'buddypress' ); ?></option> 79 79 <option value="activity_update"><?php _e( 'Updates', 'buddypress' ); ?></option> 80 80 81 <?php if ( bp_is_active( 'blogs' ) ) :?>81 <?php bp_activity_post_type_filter_options();?> 82 82 83 <option value="new_blog_post"><?php _e( 'Posts', 'buddypress' ); ?></option>84 <option value="new_blog_comment"><?php _e( 'Comments', 'buddypress' ); ?></option>85 86 <?php endif; ?>87 88 83 <?php if ( bp_is_active( 'forums' ) ) : ?> 89 84 90 85 <option value="new_forum_topic"><?php _e( 'Forum Topics', 'buddypress' ); ?></option> -
bp-blogs/bp-blogs-functions.php
278 278 add_action( 'transition_post_status', 'bp_blogs_catch_published_post', 10, 3 ); 279 279 280 280 /** 281 * Callback function to build the permalink to the post type 282 * 283 * @param integer $post_id the post type id 284 * @param integer $blog_id the blog id 285 * @param WP_Post $post Post object. 286 * @uses add_query_arg() To add custom args to the url 287 * @uses get_home_url() 288 * @return string the post type permalink 289 */ 290 function bp_blogs_activity_permalink_post_callback( $post_id = 0, $blog_id = 0, $post = null ) { 291 $post_permalink = add_query_arg( 292 'p', 293 $post_id, 294 trailingslashit( get_home_url( $blog_id ) ) 295 ); 296 297 return $post_permalink; 298 } 299 300 /** 301 * Callback function to build the action for the post type 302 * 303 * @param array $args the available arguments 304 * @uses bp_core_get_userlink() to build the post author profile link 305 * @uses get_blog_option() WordPress function to fetch blog meta. 306 * @return string the activity action 307 */ 308 function bp_blogs_activity_action_post_callback( $args = array() ) { 309 extract( $args, EXTR_SKIP ); 310 311 if ( !empty( $blog_id ) ) 312 $activity_action = sprintf( __( '%1$s wrote a new %2$s, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( (int) $post_author ), $singular_post_type_name, '<a href="' . $post_permalink . '">' . $post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ); 313 else 314 $activity_action = sprintf( __( '%1$s wrote a new %2$s, %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post_author ), $singular_post_type_name, '<a href="' . $post_permalink . '">' . $post_title . '</a>' ); 315 316 return $activity_action; 317 } 318 319 /** 281 320 * Record a new blog post in the BuddyPress activity stream. 282 321 * 283 322 * @param int $post_id ID of the post being recorded. … … 311 350 if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) ) 312 351 return false; 313 352 314 // Don't record this if it's not a post315 if ( ! in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) )) )353 // Don't record this if the post type does not support bp_tracking 354 if ( ! post_type_supports( $post->post_type, 'bp_tracking' ) ) 316 355 return false; 317 356 318 357 $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) ); … … 320 359 if ( 'publish' == $post->post_status && empty( $post->post_password ) ) { 321 360 if ( $is_blog_public || !is_multisite() ) { 322 361 323 // Record this in activity streams 324 $post_permalink = add_query_arg( 325 'p', 326 $post_id, 327 trailingslashit( get_home_url( $blog_id ) ) 362 $post_type_object = get_post_type_object( $post->post_type ); 363 364 if( !empty( $post_type_object->bp_tracking ) ) 365 extract( $post_type_object->bp_tracking, EXTR_SKIP ); 366 367 // Builds the permalink to the post_type 368 if ( !empty( $activity_permalink_post_callback ) && is_callable( $activity_permalink_post_callback ) ) 369 $post_permalink = call_user_func_array( $activity_permalink_post_callback, array( $post_id, $blog_id, $post ) ); 370 else 371 $post_permalink = bp_blogs_activity_permalink_post_callback( $post_id, $blog_id, $post ); 372 373 $action_args = array( 374 'post_author' => $post->post_author, 375 'post_permalink' => $post_permalink, 376 'post_title' => $post->post_title, 377 'singular_post_type_name' => lcfirst( esc_html( $post_type_object->labels->singular_name ) ) 328 378 ); 329 379 330 if ( is_multisite() ) 331 $activity_action = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ); 380 if( is_multisite() ) 381 $action_args['blog_id'] = $blog_id; 382 383 // Builds the activity action for the post type 384 if( !empty( $activity_action_post_callback ) && is_callable( $activity_action_post_callback ) ) 385 $activity_action = call_user_func_array( $activity_action_post_callback, array( $action_args ) ); 332 386 else 333 $activity_action = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>');387 $activity_action = bp_blogs_activity_action_post_callback( $action_args ); 334 388 389 $type_post = !empty( $type_post ) ? $type_post : 'new_blog_'. $post->post_type ; 390 335 391 // Make sure there's not an existing entry for this post (prevent bumping) 336 392 if ( bp_is_active( 'activity' ) ) { 337 393 $existing = bp_activity_get( array( 338 394 'filter' => array( 339 'action' => 'new_blog_post',395 'action' => $type_post, 340 396 'primary_id' => $blog_id, 341 397 'secondary_id' => $post_id, 342 398 ) … … 351 407 352 408 bp_blogs_record_activity( array( 353 409 'user_id' => (int) $post->post_author, 354 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ),355 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ),356 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),357 'type' => 'new_blog_post',410 'action' => apply_filters( "bp_blogs_activity_new_{$post->post_type}_action", $activity_action, $post, $post_permalink ), 411 'content' => apply_filters( "bp_blogs_activity_new_{$post->post_type}_content", $activity_content, $post, $post_permalink ), 412 'primary_link' => apply_filters( "bp_blogs_activity_new_{$post->post_type}_primary_link", $post_permalink, $post_id ), 413 'type' => $type_post, 358 414 'item_id' => $blog_id, 359 415 'secondary_item_id' => $post_id, 360 416 'recorded_time' => $post->post_date_gmt, … … 371 427 } 372 428 373 429 /** 430 * Callback function to build the action for the comment on the post type 431 * 432 * @param array $args the available arguments 433 * @uses bp_core_get_userlink() to build the post author profile link 434 * @uses get_blog_option() WordPress function to fetch blog meta. 435 * @return string the activity action 436 */ 437 function bp_blogs_activity_action_comment_callback( $args = array() ) { 438 extract( $args, EXTR_SKIP ); 439 440 if ( !empty( $blog_id ) ) 441 $activity_action = sprintf( __( '%1$s commented on the %2$s, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( $user_id ), $singular_post_type_name, '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ); 442 else 443 $activity_action = sprintf( __( '%1$s commented on the %2$s, %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), $singular_post_type_name, '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $post_title ) . '</a>' ); 444 445 return $activity_action; 446 } 447 448 /** 374 449 * Record a new blog comment in the BuddyPress activity stream. 375 450 * 376 451 * Only posts the item if blog is public and post is not password-protected. … … 422 497 if ( !empty( $recorded_comment->post->post_password ) ) 423 498 return false; 424 499 425 // Don't record activity if the comment's associated post isn't a WordPress Post426 if ( ! in_array( $recorded_comment->post->post_type, apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) )) )500 // Don't record this if the comment's associated post does not support bp_tracking 501 if ( ! post_type_supports( $recorded_comment->post->post_type, 'bp_tracking' ) ) 427 502 return false; 428 503 429 504 $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) ); … … 431 506 // If blog is public allow activity to be posted 432 507 if ( $is_blog_public ) { 433 508 434 // Get activity related links 435 $post_permalink = get_permalink( $recorded_comment->comment_post_ID ); 436 $comment_link = get_comment_link( $recorded_comment->comment_ID ); 509 $post_type_object = get_post_type_object( $recorded_comment->post->post_type ); 510 511 if( !empty( $post_type_object->bp_tracking ) ) 512 extract( $post_type_object->bp_tracking, EXTR_SKIP ); 437 513 438 // Prepare to record in activity streams439 if ( is_multisite() )440 $ 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>');514 // Builds the permalink to the post_type 515 if ( !empty( $activity_permalink_post_callback ) && is_callable( $activity_permalink_post_callback ) ) 516 $post_permalink = call_user_func_array( $activity_permalink_post_callback, array( $recorded_comment->comment_post_ID, $blog_id, $recorded_comment->post ) ); 441 517 else 442 $ 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>');518 $post_permalink = get_permalink( $recorded_comment->comment_post_ID ); 443 519 520 $action_args = array( 521 'user_id' => $user_id, 522 'post_permalink' => $post_permalink, 523 'post_title' => $recorded_comment->post->post_title, 524 'singular_post_type_name' => lcfirst( esc_html( $post_type_object->labels->singular_name ) ) 525 ); 526 527 if( is_multisite() ) 528 $action_args['blog_id'] = $blog_id; 529 530 // Builds the activity action for the post type 531 if( !empty( $activity_action_comment_callback ) && is_callable( $activity_action_comment_callback ) ) 532 $activity_action = call_user_func_array( $activity_action_comment_callback, array( $action_args ) ); 533 else 534 $activity_action = bp_blogs_activity_action_comment_callback( $action_args ); 535 536 // Get the activity type 537 $comment_prefix = ( 'post' == $recorded_comment->post->post_type ) ? '' : $recorded_comment->post->post_type . '_'; 538 $type_comment = !empty( $type_comment ) ? $type_comment : "new_blog_{$comment_prefix}comment"; 539 540 // Get comment link 541 $comment_link = get_comment_link( $recorded_comment->comment_ID ); 542 543 // Get the comment content 444 544 $activity_content = $recorded_comment->comment_content; 445 545 546 $comment_post_type = ( 'post' == $recorded_comment->post->post_type ) ? 'comment' : $recorded_comment->post->post_type . '_comment'; 547 446 548 // Record in activity streams 447 549 bp_blogs_record_activity( array( 448 550 'user_id' => $user_id, 449 'action' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_action', array( $activity_action, &$recorded_comment, $comment_link ) ),450 'content' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $activity_content, &$recorded_comment, $comment_link ) ),451 'primary_link' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$recorded_comment ) ),452 'type' => 'new_blog_comment',551 'action' => apply_filters_ref_array( "bp_blogs_activity_new_{$comment_post_type}_action", array( $activity_action, &$recorded_comment, $comment_link ) ), 552 'content' => apply_filters_ref_array( "bp_blogs_activity_new_{$comment_post_type}_content", array( $activity_content, &$recorded_comment, $comment_link ) ), 553 'primary_link' => apply_filters_ref_array( "bp_blogs_activity_new_{$comment_post_type}_primary_link", array( $comment_link, &$recorded_comment ) ), 554 'type' => $type_comment, 453 555 'item_id' => $blog_id, 454 556 'secondary_item_id' => $comment_id, 455 557 'recorded_time' => $recorded_comment->comment_date_gmt -
bp-blogs/bp-blogs-activity.php
20 20 * @return bool|null Returns false if activity component is not active. 21 21 */ 22 22 function bp_blogs_register_activity_actions() { 23 global $bp ;23 global $bp, $_wp_post_type_features, $wp_post_types; 24 24 25 25 // Bail if activity is not active 26 26 if ( ! bp_is_active( 'activity' ) ) { … … 31 31 bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New site created', 'buddypress' ) ); 32 32 } 33 33 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' ) ); 34 foreach( $_wp_post_type_features as $key_post => $post_type ) { 36 35 36 if( empty( $post_type['bp_tracking'] ) ) 37 continue; 38 39 $type_activity_post = !empty( $wp_post_types[$key_post]->bp_tracking['type_post'] ) ? $wp_post_types[$key_post]->bp_tracking['type_post'] : 'new_blog_'. $key_post ; 40 41 $comment_prefix = ( 'post' == $key_post ) ? '' : $key_post . '_'; 42 $type_activity_comment = !empty( $wp_post_types[$key_post]->bp_tracking['comment'] ) ? $wp_post_types[$key_post]->bp_tracking['comment'] : "new_blog_{$comment_prefix}comment"; 43 44 bp_activity_set_action( $bp->blogs->id, $type_activity_post, sprintf( __( 'New %s published', 'buddypress' ), lcfirst( esc_html( $wp_post_types[$key_post]->labels->singular_name ) ) ) ); 45 bp_activity_set_action( $bp->blogs->id, $type_activity_comment, sprintf( __( 'New %s comment posted', 'buddypress' ), lcfirst( esc_html( $wp_post_types[$key_post]->labels->singular_name ) ) ) ); 46 } 47 37 48 do_action( 'bp_blogs_register_activity_actions' ); 38 49 } 39 50 add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' ); -
bp-blogs/bp-blogs-actions.php
32 32 } 33 33 } 34 34 add_action( 'bp_actions', 'bp_blogs_redirect_to_random_blog' ); 35 36 /** 37 * Early hooks bp_init to extend the post post type arguments and add to it the "bp_tracking" support 38 * 39 * @global $wp_post_types the different registered post types 40 * @uses add_post_type_support() to add the "bp_tracking" support to the post post type 41 */ 42 function bp_blogs_extend_initial_post_types() { 43 global $wp_post_types; 44 45 $wp_post_types['post']->bp_tracking = array( 46 'type_post' => 'new_blog_post', 47 'activity_permalink_post_callback' => 'bp_blogs_activity_permalink_post_callback', 48 'activity_action_post_callback' => 'bp_blogs_activity_action_post_callback', 49 'type_comment' => 'new_blog_comment', 50 'activity_action_comment_callback' => 'bp_blogs_activity_action_comment_callback', 51 ); 52 53 add_post_type_support( 'post', 'bp_tracking' ); 54 } 55 56 add_action( 'bp_init', 'bp_blogs_extend_initial_post_types', 5 );