diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 6f370a5fa..91158318f 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -153,6 +153,53 @@ function get_lastcommentmodified($timezone = 'server') { } +function get_comment_count( $post_id = 0 ) { + global $wpdb; + + $post_id = (int) $post_id; + + $where = ''; + if ( $post_id > 0 ) { + $where = "WHERE comment_post_ID = {$post_id}"; + } + + $totals = (array) $wpdb->get_results(" + SELECT comment_approved, COUNT( * ) AS total + FROM {$wpdb->comments} + {$where} + GROUP BY comment_approved + ", ARRAY_A); + + $comment_count = array( + "approved" => 0, + "awaiting_moderation" => 0, + "spam" => 0, + "total_comments" => 0 + ); + + foreach ( $totals as $i => $row ) { + switch ( $row['comment_approved'] ) { + case 'spam': + $comment_count['spam'] = $row['total']; + $comment_count["total_comments"] += $row['total']; + break; + case 1: + $comment_count['approved'] = $row['total']; + $comment_count['total_comments'] += $row['total']; + break; + case 0: + $comment_count['awaiting_moderation'] = $row['total']; + $comment_count['total_comments'] += $row['total']; + break; + default: + break; + } + } + + return $comment_count; +} + + function sanitize_comment_cookies() { if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]); diff --git a/xmlrpc.php b/xmlrpc.php index 67219909d..ac0afbf1b 100644 --- a/xmlrpc.php +++ b/xmlrpc.php @@ -87,6 +87,7 @@ class wp_xmlrpc_server extends IXR_Server { 'wp.deleteCategory' => 'this:wp_deleteCategory', 'wp.suggestCategories' => 'this:wp_suggestCategories', 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias + 'wp.getCommentCount' => 'this:wp_getCommentCount', // Blogger API 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', @@ -676,6 +677,26 @@ class wp_xmlrpc_server extends IXR_Server { return($category_suggestions); } + function wp_getCommentCount( $args ) { + $this->escape($args); + + $blog_id = (int) $args[0]; + $username = $args[1]; + $password = $args[2]; + $post_id = (int) $args[3]; + + if( !$this->login_pass_ok( $username, $password ) ) { + return new IXR_Error( 403, __( 'Bad login/pass combination.' ) ); + } + + set_current_user( 0, $username ); + if( !current_user_can( 'edit_posts' ) ) { + return new IXR_Error( 403, __( 'You are not allowed details about comments.' ) ); + } + + return get_comment_count( $post_id ); + } + /* Blogger API functions * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/