252 * @return type Activity ID if successful, false if not |
252 * @return type Activity ID if successful, false if not |
253 */ |
253 */ |
254 private function record_activity( $args = '' ) { |
254 private function record_activity( $args = '' ) { |
255 |
255 |
256 // Default activity args |
256 // Default activity args |
257 $defaults = array ( |
257 $activity = bbp_parse_args( $args, array( |
258 'id' => null, |
258 'id' => null, |
259 'user_id' => bbp_get_current_user_id(), |
259 'user_id' => bbp_get_current_user_id(), |
260 'type' => '', |
260 'type' => '', |
261 'action' => '', |
261 'action' => '', |
262 'item_id' => '', |
262 'item_id' => '', |
264 'content' => '', |
264 'content' => '', |
265 'primary_link' => '', |
265 'primary_link' => '', |
266 'component' => $this->component, |
266 'component' => $this->component, |
267 'recorded_time' => bp_core_current_time(), |
267 'recorded_time' => bp_core_current_time(), |
268 'hide_sitewide' => false |
268 'hide_sitewide' => false |
269 ); |
269 ), 'record_activity' ); |
270 $activity = bbp_parse_args( $args, $defaults, 'record_activity' ); |
|
271 |
270 |
272 // Add the activity |
271 // Add the activity |
273 return bp_activity_add( $activity ); |
272 return bp_activity_add( $activity ); |
274 } |
273 } |
275 |
274 |
445 |
444 |
446 // Bail if topic is not published |
445 // Bail if topic is not published |
447 if ( !bbp_is_topic_published( $topic_id ) ) |
446 if ( !bbp_is_topic_published( $topic_id ) ) |
448 return; |
447 return; |
449 |
448 |
450 // Bail if forum is not public |
|
451 if ( !bbp_is_forum_public( $forum_id, false ) ) |
|
452 return; |
|
453 |
|
454 // User link for topic author |
449 // User link for topic author |
455 $user_link = bbp_get_user_profile_link( $user_id ); |
450 $user_link = bbp_get_user_profile_link( $user_id ); |
456 |
451 |
457 // Topic |
452 // Topic |
458 $topic_permalink = bbp_get_topic_permalink( $topic_id ); |
453 $topic_permalink = bbp_get_topic_permalink( $topic_id ); |
459 $topic_title = bbp_get_topic_title ( $topic_id ); |
454 $topic_title = get_post_field( 'post_title', $topic_id, 'raw' ); |
460 $topic_content = bbp_get_topic_content ( $topic_id ); |
455 $topic_content = get_post_field( 'post_content', $topic_id, 'raw' ); |
461 $topic_link = '<a href="' . $topic_permalink . '" title="' . $topic_title . '">' . $topic_title . '</a>'; |
456 $topic_link = '<a href="' . $topic_permalink . '" title="' . $topic_title . '">' . $topic_title . '</a>'; |
462 |
457 |
463 // Forum |
458 // Forum |
464 $forum_permalink = bbp_get_forum_permalink( $forum_id ); |
459 $forum_permalink = bbp_get_forum_permalink( $forum_id ); |
465 $forum_title = bbp_get_forum_title ( $forum_id ); |
460 $forum_title = get_post_field( 'post_title', $forum_id, 'raw' ); |
466 $forum_link = '<a href="' . $forum_permalink . '" title="' . $forum_title . '">' . $forum_title . '</a>'; |
461 $forum_link = '<a href="' . $forum_permalink . '" title="' . $forum_title . '">' . $forum_title . '</a>'; |
467 |
462 |
468 // Activity action & text |
463 // Activity action & text |
469 $activity_text = sprintf( __( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link ); |
464 $activity_text = sprintf( __( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link ); |
470 $activity_action = apply_filters( 'bbp_activity_topic_create', $activity_text, $user_id, $topic_id, $forum_id ); |
465 $activity_action = apply_filters( 'bbp_activity_topic_create', $activity_text, $user_id, $topic_id, $forum_id ); |
479 'primary_link' => $topic_permalink, |
474 'primary_link' => $topic_permalink, |
480 'type' => $this->topic_create, |
475 'type' => $this->topic_create, |
481 'item_id' => $topic_id, |
476 'item_id' => $topic_id, |
482 'secondary_item_id' => $forum_id, |
477 'secondary_item_id' => $forum_id, |
483 'recorded_time' => get_post_time( 'Y-m-d H:i:s', true, $topic_id ), |
478 'recorded_time' => get_post_time( 'Y-m-d H:i:s', true, $topic_id ), |
|
479 'hide_sitewide' => ! bbp_is_forum_public( $forum_id, false ) |
484 ); |
480 ); |
485 |
481 |
486 // Record the activity |
482 // Record the activity |
487 $activity_id = $this->record_activity( $activity ); |
483 $activity_id = $this->record_activity( $activity ); |
488 |
484 |
595 |
591 |
596 // Bail if reply is not published |
592 // Bail if reply is not published |
597 if ( !bbp_is_reply_published( $reply_id ) ) |
593 if ( !bbp_is_reply_published( $reply_id ) ) |
598 return; |
594 return; |
599 |
595 |
600 // Bail if forum is not public |
|
601 if ( !bbp_is_forum_public( $forum_id, false ) ) |
|
602 return; |
|
603 |
|
604 // Setup links for activity stream |
596 // Setup links for activity stream |
605 $user_link = bbp_get_user_profile_link( $user_id ); |
597 $user_link = bbp_get_user_profile_link( $user_id ); |
606 |
598 |
607 // Reply |
599 // Reply |
608 $reply_url = bbp_get_reply_url ( $reply_id ); |
600 $reply_url = bbp_get_reply_url( $reply_id ); |
609 $reply_content = bbp_get_reply_content( $reply_id ); |
601 $reply_content = get_post_field( 'post_content', $reply_id, 'raw' ); |
610 |
602 |
611 // Topic |
603 // Topic |
612 $topic_permalink = bbp_get_topic_permalink( $topic_id ); |
604 $topic_permalink = bbp_get_topic_permalink( $topic_id ); |
613 $topic_title = bbp_get_topic_title ( $topic_id ); |
605 $topic_title = get_post_field( 'post_title', $topic_id, 'raw' ); |
614 $topic_link = '<a href="' . $topic_permalink . '" title="' . $topic_title . '">' . $topic_title . '</a>'; |
606 $topic_link = '<a href="' . $topic_permalink . '" title="' . $topic_title . '">' . $topic_title . '</a>'; |
615 |
607 |
616 // Forum |
608 // Forum |
617 $forum_permalink = bbp_get_forum_permalink( $forum_id ); |
609 $forum_permalink = bbp_get_forum_permalink( $forum_id ); |
618 $forum_title = bbp_get_forum_title ( $forum_id ); |
610 $forum_title = get_post_field( 'post_title', $forum_id, 'raw' ); |
619 $forum_link = '<a href="' . $forum_permalink . '" title="' . $forum_title . '">' . $forum_title . '</a>'; |
611 $forum_link = '<a href="' . $forum_permalink . '" title="' . $forum_title . '">' . $forum_title . '</a>'; |
620 |
612 |
621 // Activity action & text |
613 // Activity action & text |
622 $activity_text = sprintf( __( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link ); |
614 $activity_text = sprintf( __( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link ); |
623 $activity_action = apply_filters( 'bbp_activity_reply_create', $activity_text, $user_id, $reply_id, $topic_id ); |
615 $activity_action = apply_filters( 'bbp_activity_reply_create', $activity_text, $user_id, $reply_id, $topic_id ); |
632 'primary_link' => $reply_url, |
624 'primary_link' => $reply_url, |
633 'type' => $this->reply_create, |
625 'type' => $this->reply_create, |
634 'item_id' => $reply_id, |
626 'item_id' => $reply_id, |
635 'secondary_item_id' => $topic_id, |
627 'secondary_item_id' => $topic_id, |
636 'recorded_time' => get_post_time( 'Y-m-d H:i:s', true, $reply_id ), |
628 'recorded_time' => get_post_time( 'Y-m-d H:i:s', true, $reply_id ), |
|
629 'hide_sitewide' => ! bbp_is_forum_public( $forum_id, false ) |
637 ); |
630 ); |
638 |
631 |
639 // Record the activity |
632 // Record the activity |
640 $activity_id = $this->record_activity( $activity ); |
633 $activity_id = $this->record_activity( $activity ); |
641 |
634 |