function bp_blogs_record_post($post_id, $post, $user_id = 0) { global $bp, $wpdb; $post_id = (int) $post_id; $blog_id = (int) $wpdb->blogid; if (!$user_id) { $user_id = (int) $post->post_author; } // This is to stop infinite loops with Donncha's sitewide tags plugin if (!empty($bp->site_options['tags_blog_id']) && (int) $blog_id == (int) $bp->site_options['tags_blog_id']) { return false; } // Don't record this if it's not a post if (!in_array($post->post_type, apply_filters('bp_blogs_record_post_post_types', array('post')))) { return false; } $is_blog_public = apply_filters('bp_is_blog_public', (int) get_blog_option($blog_id, 'blog_public')); if ('publish' == $post->post_status && empty($post->post_password)) { if ($is_blog_public || !is_multisite()) { // Record this in activity streams $post_permalink = get_permalink($post_id); if (is_multisite()) { $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>'); } else { $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>'); } $activity_content = $post->post_content; bp_blogs_record_activity(array('user_id' => (int) $post->post_author, 'action' => apply_filters('bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink), 'content' => apply_filters('bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink), 'primary_link' => apply_filters('bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id), 'type' => 'new_blog_post', 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_modified_gmt)); } // Update the blogs last activity bp_blogs_update_blogmeta($blog_id, 'last_activity', bp_core_current_time()); } else { bp_blogs_remove_post($post_id, $blog_id, $user_id); } do_action('bp_blogs_new_blog_post', $post_id, $post, $user_id); }
function bp_blogs_record_post($post_id, $post, $user_id = 0) { global $bp, $wpdb; $post_id = (int) $post_id; $blog_id = (int) $wpdb->blogid; if (!$user_id) { $user_id = (int) $post->post_author; } // Stop infinite loops with WordPress MU Sitewide Tags. // That plugin changed the way its settings were stored at some point. Thus the dual check. if (!empty($bp->site_options['sitewide_tags_blog'])) { $st_options = maybe_unserialize($bp->site_options['sitewide_tags_blog']); $tags_blog_id = isset($st_options['tags_blog_id']) ? $st_options['tags_blog_id'] : 0; } else { $tags_blog_id = isset($bp->site_options['tags_blog_id']) ? $bp->site_options['tags_blog_id'] : 0; } if ((int) $blog_id == $tags_blog_id && apply_filters('bp_blogs_block_sitewide_tags_activity', true)) { return false; } // Don't record this if it's not a post if (!in_array($post->post_type, apply_filters('bp_blogs_record_post_post_types', array('post')))) { return false; } $is_blog_public = apply_filters('bp_is_blog_public', (int) get_blog_option($blog_id, 'blog_public')); if ('publish' == $post->post_status && empty($post->post_password)) { if ($is_blog_public || !is_multisite()) { // Record this in activity streams $post_permalink = get_permalink($post_id); if (is_multisite()) { $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>'); } else { $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>'); } // Make sure there's not an existing entry for this post (prevent bumping) if (bp_is_active('activity')) { $existing = bp_activity_get(array('filter' => array('user_id' => (int) $post->post_author, 'action' => 'new_blog_post', 'primary_id' => $blog_id, 'secondary_id' => $post_id))); if (!empty($existing['activities'])) { return; } } $activity_content = $post->post_content; bp_blogs_record_activity(array('user_id' => (int) $post->post_author, 'action' => apply_filters('bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink), 'content' => apply_filters('bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink), 'primary_link' => apply_filters('bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id), 'type' => 'new_blog_post', 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_modified_gmt)); } // Update the blogs last activity bp_blogs_update_blogmeta($blog_id, 'last_activity', bp_core_current_time()); } else { bp_blogs_remove_post($post_id, $blog_id, $user_id); } do_action('bp_blogs_new_blog_post', $post_id, $post, $user_id); }
function bp_blogs_record_post($post_id, $blog_id = false, $user_id = false) { global $bp, $wpdb; $post_id = (int) $post_id; $post = get_post($post_id); if (!$user_id) { $user_id = (int) $post->post_author; } if (!$blog_id) { $blog_id = (int) $wpdb->blogid; } /* This is to stop infinate loops with Donncha's sitewide tags plugin */ if ((int) get_site_option('tags_blog_id') == (int) $blog_id) { return false; } /* Don't record this if it's not a post */ if ($post->post_type != 'post') { return false; } if (!($is_recorded = BP_Blogs_Post::is_recorded($post_id, $blog_id, $user_id))) { if ('publish' == $post->post_status && '' == $post->post_password) { $recorded_post = new BP_Blogs_Post(); $recorded_post->user_id = $user_id; $recorded_post->blog_id = $blog_id; $recorded_post->post_id = $post_id; $recorded_post->date_created = strtotime($post->post_date); $recorded_post_id = $recorded_post->save(); bp_blogs_update_blogmeta($recorded_post->blog_id, 'last_activity', time()); bp_blogs_record_activity(array('item_id' => $recorded_post->id, 'component_name' => 'blogs', 'component_action' => 'new_blog_post', 'is_private' => bp_blogs_is_blog_hidden($recorded_post->blog_id), 'user_id' => $recorded_post->user_id, 'recorded_time' => strtotime($post->post_date))); } } else { $existing_post = new BP_Blogs_Post(null, $blog_id, $post_id); /** * Delete the recorded post if: * - The status is no longer "published" * - The post is password protected */ if ('publish' != $post->post_status || '' != $post->post_password) { bp_blogs_remove_post($post_id, $blog_id); } // Check to see if the post author has changed. if ((int) $existing_post->user_id != (int) $post->post_author) { // Delete the existing recorded post bp_blogs_remove_post($post_id, $blog_id); // Re-record the post with the new author. bp_blogs_record_post($post_id); } $recorded_post = $existing_post; /* Delete and re-add the activity stream item to reflect potential content changes. */ bp_blogs_delete_activity(array('item_id' => $recorded_post->id, 'component_name' => 'blogs', 'component_action' => 'new_blog_post', 'user_id' => $recorded_post->user_id)); bp_blogs_record_activity(array('item_id' => $recorded_post->id, 'component_name' => 'blogs', 'component_action' => 'new_blog_post', 'is_private' => bp_blogs_is_blog_hidden($recorded_post->blog_id), 'user_id' => $recorded_post->user_id, 'recorded_time' => strtotime($post->post_date))); } do_action('bp_blogs_new_blog_post', $recorded_post, $is_private, $is_recorded); }