예제 #1
0
 function get_comments_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 the logged in user their comments on hidden blogs, but not to anyone else.
     if (!bp_is_home()) {
         $comment_ids = $wpdb->get_results($wpdb->prepare("SELECT c.comment_id, c.blog_id FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.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 c.user_id = %d ORDER BY c.date_created ASC", $user_id));
         $total_comment_count = $wpdb->get_var($wpdb->prepare("SELECT count(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.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 c.user_id = %d", $user_id));
     } else {
         $comment_ids = $wpdb->get_results($wpdb->prepare("SELECT c.comment_id, c.blog_id FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d ORDER BY c.date_created ASC", $user_id));
         $total_comment_count = $wpdb->get_var($wpdb->prepare("SELECT count(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d", $user_id));
     }
     for ($i = 0; $i < count($comment_ids); $i++) {
         $comments[$i] = BP_Blogs_Comment::fetch_comment_content($comment_ids[$i]);
     }
     return array('comments' => $comments, 'count' => $total_comment_count);
 }
예제 #2
0
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;
}