diff --git a/xmlrpc.php b/xmlrpc.php index d918c2d79..e58bda195 100644 --- a/xmlrpc.php +++ b/xmlrpc.php @@ -127,6 +127,8 @@ class wp_xmlrpc_server extends IXR_Server { 'wp.getPostStatusList' => 'this:wp_getPostStatusList', 'wp.getPageStatusList' => 'this:wp_getPageStatusList', 'wp.getPageTemplates' => 'this:wp_getPageTemplates', + 'wp.getOptions' => 'this:wp_getOptions', + 'wp.setOptions' => 'this:wp_setOptions', // Blogger API 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', @@ -171,6 +173,8 @@ class wp_xmlrpc_server extends IXR_Server { 'demo.sayHello' => 'this:sayHello', 'demo.addTwoNumbers' => 'this:addTwoNumbers' ); + + $this->initialise_blog_option_info( ); $this->methods = apply_filters('xmlrpc_methods', $this->methods); $this->IXR_Server($this->methods); } @@ -255,6 +259,58 @@ class wp_xmlrpc_server extends IXR_Server { } } + function initialise_blog_option_info( ) { + global $wp_version; + + $this->blog_options = array( + // Read only options + 'software_name' => array( + 'desc' => __( 'Software Name' ), + 'readonly' => true, + 'value' => 'WordPress' + ), + 'software_version' => array( + 'desc' => __( 'Software Version' ), + 'readonly' => true, + 'value' => $wp_version + ), + 'blog_url' => array( + 'desc' => __( 'Blog URL' ), + 'readonly' => true, + 'option' => 'siteurl' + ), + + // Updatable options + 'time_zone' => array( + 'desc' => __( 'Time Zone' ), + 'readonly' => false, + 'option' => 'gmt_offset' + ), + 'blog_title' => array( + 'desc' => __( 'Blog Title' ), + 'readonly' => false, + 'option' => 'blogname' + ), + 'blog_tagline' => array( + 'desc' => __( 'Blog Tagline' ), + 'readonly' => false, + 'option' => 'blogdescription' + ), + 'date_format' => array( + 'desc' => __( 'Date Format' ), + 'readonly' => false, + 'option' => 'date_format' + ), + 'time_format' => array( + 'desc' => __( 'Time Format' ), + 'readonly' => false, + 'option' => 'time_format' + ) + ); + + $this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options ); + } + /** * WordPress XML-RPC API * wp_getUsersBlogs @@ -862,6 +918,77 @@ class wp_xmlrpc_server extends IXR_Server { return $templates; } + function wp_getOptions( $args ) { + $this->escape( $args ); + + $blog_id = (int) $args[0]; + $username = $args[1]; + $password = $args[2]; + $options = (array) $args[3]; + + if( !$this->login_pass_ok( $username, $password ) ) + return new IXR_Error( 403, __( 'Bad login/pass combination.' ) ); + + $user = set_current_user( 0, $username ); + + // 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); + } + + 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; + } + + function wp_setOptions( $args ) { + $this->escape( $args ); + + $blog_id = (int) $args[0]; + $username = $args[1]; + $password = $args[2]; + $options = (array) $args[3]; + + if( !$this->login_pass_ok( $username, $password ) ) + return new IXR_Error( 403, __( 'Bad login/pass combination.' ) ); + + $user = set_current_user( 0, $username ); + 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( empty( $o_value ) ) + continue; + + 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/