Advertisement
Guest User

Untitled

a guest
May 23rd, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. function bp_groups_record_post( $post_id, $post, $user_id = 0 ) {
  2. global $bp, $wpdb;
  3.  
  4. $post_id = (int)$post_id;
  5. $blog_id = (int)$wpdb->blogid;
  6.  
  7. //get the category ID for the new events slug
  8. $new_events_slug = 'new-events';
  9.  
  10. //get all the category ID's for the post
  11. $post_categories = wp_get_post_categories($post_id);
  12.  
  13. foreach($post_categories as $c){
  14.  
  15. //get the slug for the current category
  16. $cat = get_category($c);
  17. $cat_slug = $cat->slug;
  18. //if the slug isn't new events then
  19.  
  20. //get group slug
  21. $groupr_id = groups_get_id($cat_slug);
  22. //var_dump($cat_slug);
  23. //var_dump ($groupr_id);
  24. if ($groupr_id != 0) {
  25. $groupr_id_not_0 = $groupr_id;
  26.  
  27. }
  28. }
  29.  
  30. if ( !$user_id )
  31. $user_id = (int) $post->post_author;
  32.  
  33. // Stop infinite loops with WordPress MU Sitewide Tags.
  34. // That plugin changed the way its settings were stored at some point. Thus the dual check.
  35. if ( !empty( $bp->site_options['sitewide_tags_blog'] ) ) {
  36. $st_options = maybe_unserialize( $bp->site_options['sitewide_tags_blog'] );
  37. $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0;
  38. } else {
  39. $tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0;
  40. }
  41.  
  42. if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) )
  43. return false;
  44.  
  45. // Don't record this if it's not a post
  46. if ( !in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ) ) )
  47. return false;
  48.  
  49. $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
  50.  
  51. if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
  52. if ( $is_blog_public || !is_multisite() ) {
  53.  
  54. // Record this in activity streams
  55. $post_permalink = get_permalink( $post_id );
  56.  
  57. if ( is_multisite() )
  58. $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>' );
  59. else
  60. $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>' );
  61.  
  62. // Make sure there's not an existing entry for this post (prevent bumping)
  63. if ( bp_is_active( 'activity' ) ) {
  64. $existing = bp_activity_get( array(
  65. 'filter' => array(
  66. 'user_id' => (int) $post->post_author,
  67. 'action' => 'new_blog_post',
  68. 'primary_id' => $blog_id,
  69. 'secondary_id' => $post_id,
  70. )
  71. ) );
  72.  
  73. if ( !empty( $existing['activities'] ) ) {
  74. return;
  75. }
  76. }
  77.  
  78. $activity_content = $post->post_content;
  79.  
  80. bp_groups_record_activity( array(
  81. 'user_id' => (int) $post->post_author,
  82. 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ),
  83. 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ),
  84. 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
  85. 'type' => 'new_blog_post',
  86. 'item_id' => $groupr_id_not_0,
  87. 'secondary_item_id' => $post_id,
  88. 'recorded_time' => $post->post_modified_gmt
  89. ));
  90. }
  91.  
  92. // Update the blogs last activity
  93. bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
  94. } else {
  95. bp_blogs_remove_post( $post_id, $blog_id, $user_id );
  96. }
  97.  
  98. do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
  99. }
  100. add_action( 'save_post', 'bp_groups_record_post', 10, 2 );
  101.  
  102. /**
  103. * Record the activity to the actvity stream
  104. *
  105. * @since BuddyPress (1.0)
  106. * @package BuddyPress
  107. * @subpackage BlogsActivity
  108. * @global BuddyPress $bp
  109. * @param array $args
  110. * @return boolean
  111. */
  112. function bp_groups_record_activity( $args = '' ) {
  113. global $bp;
  114.  
  115. // Bail if activity is not active
  116. if ( ! bp_is_active( 'activity' ) )
  117. return false;
  118.  
  119. $defaults = array(
  120. 'user_id' => bp_loggedin_user_id(),
  121. 'action' => '',
  122. 'content' => '',
  123. 'primary_link' => '',
  124. 'component' => $bp->blogs->id,
  125. 'type' => false,
  126. 'item_id' => false,
  127. 'secondary_item_id' => false,
  128. 'recorded_time' => bp_core_current_time(),
  129. 'hide_sitewide' => false
  130. );
  131.  
  132. $r = wp_parse_args( $args, $defaults );
  133. extract( $r, EXTR_SKIP );
  134.  
  135. // Remove large images and replace them with just one image thumbnail
  136. if ( !empty( $content ) )
  137. $content = bp_activity_thumbnail_content_images( $content, $primary_link );
  138.  
  139. if ( !empty( $action ) )
  140. $action = apply_filters( 'bp_blogs_record_activity_action', $action );
  141.  
  142. if ( !empty( $content ) )
  143. $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );
  144.  
  145. // Check for an existing entry and update if one exists.
  146. $id = bp_activity_get_activity_id( array(
  147. 'user_id' => $user_id,
  148. 'component' => $component,
  149. 'type' => $type,
  150. 'item_id' => $item_id,
  151. 'secondary_item_id' => $secondary_item_id
  152. ) );
  153.  
  154. return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement