+ if ( isset($content_struct['content']) )
+ $comment_content = $content_struct['content'];
+
+ if ( isset($content_struct['author']) )
+ $comment_author = $content_struct['author'];
+
+ if ( isset($content_struct['author_url']) )
+ $comment_author_url = $content_struct['author_url'];
+
+ if ( isset($content_struct['author_email']) )
+ $comment_author_email = $content_struct['author_email'];
+
+ // We've got all the data -- post it:
+ $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url');
+
+ $result = wp_update_comment($comment);
+ if ( is_wp_error( $result ) )
+ return new IXR_Error(500, $result->get_error_message());
+
+ if ( !$result )
+ return new IXR_Error(500, __('Sorry, the comment could not be edited. Something wrong happened.'));
+
+ return true;
+ }
+
+ /**
+ * Create new comment.
+ *
+ * @since 2.7.0
+ *
+ * @param array $args Method parameters.
+ * @return mixed {@link wp_new_comment()}
+ */
+ function wp_newComment($args) {
+ global $wpdb;
+
+ $this->escape($args);
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $post = $args[3];
+ $content_struct = $args[4];
+
+ $allow_anon = apply_filters('xmlrpc_allow_anonymous_comments', false);
+
+ $user = $this->login($username, $password);
+
+ if ( !$user ) {
+ $logged_in = false;
+ if ( $allow_anon && get_option('comment_registration') )
+ return new IXR_Error( 403, __( 'You must be registered to comment' ) );
+ else if ( !$allow_anon )
+ return $this->error;
+ } else {
+ $logged_in = true;
+ }
+
+ if ( is_numeric($post) )
+ $post_id = absint($post);
+ else
+ $post_id = url_to_postid($post);
+
+ if ( ! $post_id )
+ return new IXR_Error( 404, __( 'Invalid post ID.' ) );
+
+ if ( ! get_post($post_id) )
+ return new IXR_Error( 404, __( 'Invalid post ID.' ) );
+
+ $comment['comment_post_ID'] = $post_id;
+
+ if ( $logged_in ) {
+ $comment['comment_author'] = $wpdb->escape( $user->display_name );
+ $comment['comment_author_email'] = $wpdb->escape( $user->user_email );
+ $comment['comment_author_url'] = $wpdb->escape( $user->user_url );
+ $comment['user_ID'] = $user->ID;
+ } else {
+ $comment['comment_author'] = '';
+ if ( isset($content_struct['author']) )
+ $comment['comment_author'] = $content_struct['author'];
+
+ $comment['comment_author_email'] = '';
+ if ( isset($content_struct['author_email']) )
+ $comment['comment_author_email'] = $content_struct['author_email'];
+
+ $comment['comment_author_url'] = '';
+ if ( isset($content_struct['author_url']) )
+ $comment['comment_author_url'] = $content_struct['author_url'];
+
+ $comment['user_ID'] = 0;
+
+ if ( get_option('require_name_email') ) {
+ if ( 6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author'] )
+ return new IXR_Error( 403, __( 'Comment author name and email are required' ) );
+ elseif ( !is_email($comment['comment_author_email']) )
+ return new IXR_Error( 403, __( 'A valid email address is required' ) );
+ }
+ }
+
+ $comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0;
+
+ $comment['comment_content'] = $content_struct['content'];
+
+ do_action('xmlrpc_call', 'wp.newComment');
+
+ return wp_new_comment($comment);
+ }
+
+ /**
+ * Retrieve all of the comment status.
+ *
+ * @since 2.7.0
+ *
+ * @param array $args Method parameters.
+ * @return array
+ */
+ function wp_getCommentStatusList($args) {
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ if ( !$user = $this->login($username, $password) )
+ return $this->error;
+
+ if ( !current_user_can( 'moderate_comments' ) )
+ return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) );
+
+ do_action('xmlrpc_call', 'wp.getCommentStatusList');
+
+ return get_comment_statuses( );
+ }
+
+ /**
+ * Retrieve comment count.
+ *
+ * @since 2.5.0
+ *
+ * @param array $args Method parameters.
+ * @return array
+ */
+ function wp_getCommentCount( $args ) {
+ $this->escape($args);
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $post_id = (int) $args[3];
+
+ if ( !$user = $this->login($username, $password) )
+ return $this->error;
+
+ if ( !current_user_can( 'edit_posts' ) )
+ return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) );
+
+ do_action('xmlrpc_call', 'wp.getCommentCount');
+
+ $count = wp_count_comments( $post_id );
+ return array(
+ "approved" => $count->approved,
+ "awaiting_moderation" => $count->moderated,
+ "spam" => $count->spam,
+ "total_comments" => $count->total_comments
+ );
+ }
+
+ /**
+ * Retrieve post statuses.
+ *
+ * @since 2.5.0
+ *
+ * @param array $args Method parameters.
+ * @return array
+ */
+ function wp_getPostStatusList( $args ) {
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ if ( !$user = $this->login($username, $password) )
+ return $this->error;
+
+ if ( !current_user_can( 'edit_posts' ) )
+ return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) );
+
+ do_action('xmlrpc_call', 'wp.getPostStatusList');
+
+ return get_post_statuses( );
+ }
+
+ /**
+ * Retrieve page statuses.
+ *
+ * @since 2.5.0
+ *
+ * @param array $args Method parameters.
+ * @return array
+ */
+ function wp_getPageStatusList( $args ) {
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ if ( !$user = $this->login($username, $password) )
+ return $this->error;
+
+ if ( !current_user_can( 'edit_pages' ) )
+ return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) );
+
+ do_action('xmlrpc_call', 'wp.getPageStatusList');
+
+ return get_page_statuses( );
+ }
+
+ /**
+ * Retrieve page templates.
+ *
+ * @since 2.6.0
+ *
+ * @param array $args Method parameters.
+ * @return array
+ */
+ function wp_getPageTemplates( $args ) {
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ if ( !$user = $this->login($username, $password) )
+ return $this->error;
+
+ if ( !current_user_can( 'edit_pages' ) )
+ return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) );
+
+ $templates = get_page_templates( );
+ $templates['Default'] = 'default';
+
+ return $templates;
+ }
+
+ /**
+ * Retrieve blog options.
+ *
+ * @since 2.6.0
+ *
+ * @param array $args Method parameters.
+ * @return array
+ */
+ function wp_getOptions( $args ) {
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $options = (array) $args[3];
+
+ if ( !$user = $this->login($username, $password) )
+ return $this->error;
+
+ // If no specific options where asked for, return all of them
+ if ( count( $options ) == 0 )
+ $options = array_keys($this->blog_options);
+
+ return $this->_getOptions($options);
+ }
+
+ /**
+ * Retrieve blog options value from list.
+ *
+ * @since 2.6.0
+ *
+ * @param array $options Options to retrieve.
+ * @return array
+ */
+ function _getOptions($options) {
+ $data = array( );
+ foreach ( $options as $option ) {
+ if ( array_key_exists( $option, $this->blog_options ) ) {
+ $data[$option] = $this->blog_options[$option];
+ //Is the value static or dynamic?
+ if ( isset( $data[$option]['option'] ) ) {
+ $data[$option]['value'] = get_option( $data[$option]['option'] );
+ unset($data[$option]['option']);
+ }
+ }
+ }
+
+ return $data;
+ }
+
+ /**
+ * Update blog options.
+ *
+ * @since 2.6.0
+ *
+ * @param array $args Method parameters.
+ * @return unknown
+ */
+ function wp_setOptions( $args ) {
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $options = (array) $args[3];
+
+ if ( !$user = $this->login($username, $password) )
+ return $this->error;
+
+ if ( !current_user_can( 'manage_options' ) )
+ return new IXR_Error( 403, __( 'You are not allowed to update options.' ) );
+
+ foreach ( $options as $o_name => $o_value ) {
+ $option_names[] = $o_name;
+ if ( !array_key_exists( $o_name, $this->blog_options ) )
+ continue;
+
+ if ( $this->blog_options[$o_name]['readonly'] == true )
+ continue;
+
+ update_option( $this->blog_options[$o_name]['option'], $o_value );
+ }
+
+ //Now return the updated values
+ return $this->_getOptions($option_names);
+ }
+
+ /* Blogger API functions.
+ * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
+ */
+
+ /**
+ * Retrieve blogs that user owns.
+ *
+ * Will make more sense once we support multiple blogs.
+ *
+ * @since 1.5.0
+ *
+ * @param array $args Method parameters.
+ * @return array
+ */
+ function blogger_getUsersBlogs($args) {
+ if ( is_multisite() )
+ return $this->_multisite_getUsersBlogs($args);
+
+ $this->escape($args);
+
+ $username = $args[1];
+ $password = $args[2];
+
+ if ( !$user = $this->login($username, $password) )
+ return $this->error;
+
+ do_action('xmlrpc_call', 'blogger.getUsersBlogs');
+
+ $is_admin = current_user_can('manage_options');