function get_posts_for_user($user_id = null) { global $bp, $wpdb; if (!$bp->blogs) { bp_blogs_setup_globals(); } if (!$user_id) { $user_id = $bp->displayed_user->id; } // Show a logged in user their posts on private blogs, but not anyone else. if (!bp_is_home()) { $post_ids = $wpdb->get_results($wpdb->prepare("SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d ORDER BY p.date_created DESC", $user_id)); $total_post_count = $wpdb->get_var($wpdb->prepare("SELECT count(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id)); } else { $post_ids = $wpdb->get_results($wpdb->prepare("SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d ORDER BY p.date_created DESC", $user_id)); $total_post_count = $wpdb->get_var($wpdb->prepare("SELECT count(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id)); } for ($i = 0; $i < count($post_ids); $i++) { $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]); } return array('posts' => $posts, 'count' => $total_post_count); }
function bp_blogs_format_activity($item_id, $user_id, $action, $secondary_item_id = false, $for_secondary_user = false) { global $bp; switch ($action) { case 'new_blog': $blog = new BP_Blogs_Blog($item_id); if (!$blog) { return false; } if (!$user_id) { return false; } $blog_url = get_blog_option($blog->blog_id, 'siteurl'); $user_link = bp_core_get_userlink($user_id); $blog_name = get_blog_option($blog->blog_id, 'blogname'); return array('primary_link' => $blog_url, 'content' => apply_filters('bp_blogs_new_blog_activity', sprintf(__('%s created a new blog: %s', 'buddypress'), $user_link, '<a href="' . $blog_url . '">' . $blog_name . '</a>') . ' <span class="time-since">%s</span>', $user_link, $blog_url, $blog_name)); break; case 'new_blog_post': $post = new BP_Blogs_Post($item_id); if (!$post) { return false; } $post = BP_Blogs_Post::fetch_post_content($post); if (!$post || $post->post_type != 'post') { return false; } $post_link = bp_post_get_permalink($post, $post->blog_id); $user_link = bp_core_get_userlink($user_id); $content = sprintf(__('%s wrote a new blog post: %s', 'buddypress'), $user_link, '<a href="' . $post_link . '">' . $post->post_title . '</a>') . ' <span class="time-since">%s</span>'; $content .= '<blockquote>' . bp_create_excerpt($post->post_content) . '</blockquote>'; $content = apply_filters('bp_blogs_new_post_activity', $content, $user_link, $post); return array('primary_link' => $post_link, 'content' => $content); break; case 'new_blog_comment': if (!is_user_logged_in()) { return false; } $comment = new BP_Blogs_Comment($secondary_item_id); if (!$comment) { return false; } $comment = BP_Blogs_Comment::fetch_comment_content($comment); if (!$comment) { return false; } $comment_link = bp_post_get_permalink($comment->post, $comment->blog_id); $user_link = bp_core_get_userlink($user_id); $content = sprintf(__('%s commented on the blog post %s', 'buddypress'), $user_link, '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>') . ' <span class="time-since">%s</span>'; $content .= '<blockquote>' . bp_create_excerpt($comment->comment_content) . '</blockquote>'; $content = apply_filters('bp_blogs_new_comment_activity', $content, $user_link, $comment); return array('primary_link' => $post_link . '#comment-' . $comment->comment_ID, 'content' => $content); break; } do_action('bp_blogs_format_activity', $action, $item_id, $user_id, $action, $secondary_item_id, $for_secondary_user); return false; }