+
+ // Get the author info.
+ $author = get_userdata($page->post_author);
+
+ $page_struct = array(
+ "dateCreated" => new IXR_Date($page_date),
+ "userid" => $page->post_author,
+ "page_id" => $page->ID,
+ "page_status" => $page->post_status,
+ "description" => $full_page["main"],
+ "title" => $page->post_title,
+ "link" => $link,
+ "permaLink" => $link,
+ "categories" => $categories,
+ "excerpt" => $page->post_excerpt,
+ "text_more" => $full_page["extended"],
+ "mt_allow_comments" => $allow_comments,
+ "mt_allow_pings" => $allow_pings,
+ "wp_slug" => $page->post_name,
+ "wp_password" => $page->post_password,
+ "wp_author" => $author->display_name,
+ "wp_page_parent_id" => $page->post_parent,
+ "wp_page_parent_title" => $parent_title,
+ "wp_page_order" => $page->menu_order,
+ "wp_author_id" => $author->ID,
+ "wp_author_display_name" => $author->display_name,
+ "date_created_gmt" => new IXR_Date($page_date_gmt)
+ );
+
+ return($page_struct);
+ }
+ // If the page doesn't exist indicate that.
+ else {
+ return(new IXR_Error(404, __("Sorry, no such page.")));
+ }
+ }
+
+ /**
+ * WordPress XML-RPC API
+ * wp_getPages
+ */
+ function wp_getPages($args) {
+ $this->escape($args);
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ if(!$this->login_pass_ok($username, $password)) {
+ return($this->error);
+ }
+
+ set_current_user( 0, $username );
+ if( !current_user_can( 'edit_pages' ) )
+ return new IXR_Error( 401, __( 'Sorry, you can not edit pages.' ) );
+
+ do_action('xmlrpc_call', 'wp.getPages');
+
+ // Lookup info on pages.
+ $pages = get_pages();
+ $num_pages = count($pages);
+
+ // If we have pages, put together their info.
+ if($num_pages >= 1) {
+ $pages_struct = array();
+
+ for($i = 0; $i < $num_pages; $i++) {
+ $page = wp_xmlrpc_server::wp_getPage(array(
+ $blog_id, $pages[$i]->ID, $username, $password
+ ));
+ $pages_struct[] = $page;
+ }
+
+ return($pages_struct);
+ }
+ // If no pages were found return an error.
+ else {
+ return(array());
+ }
+ }
+
+ /**
+ * WordPress XML-RPC API
+ * wp_newPage
+ */
+ function wp_newPage($args) {
+ // Items not escaped here will be escaped in newPost.
+ $username = $this->escape($args[1]);
+ $password = $this->escape($args[2]);
+ $page = $args[3];
+ $publish = $args[4];
+
+ if(!$this->login_pass_ok($username, $password)) {
+ return($this->error);
+ }
+
+ // Set the user context and check if they are allowed
+ // to add new pages.
+ $user = set_current_user(0, $username);
+ if(!current_user_can("publish_pages")) {
+ return(new IXR_Error(401, __("Sorry, you can not add new pages.")));
+ }
+
+ // Mark this as content for a page.
+ $args[3]["post_type"] = "page";
+
+ // Let mw_newPost do all of the heavy lifting.
+ return($this->mw_newPost($args));
+ }
+
+ /**
+ * WordPress XML-RPC API
+ * wp_deletePage
+ */
+ function wp_deletePage($args) {
+ $this->escape($args);
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $page_id = (int) $args[3];
+
+ if(!$this->login_pass_ok($username, $password)) {
+ return($this->error);
+ }
+
+ // Get the current page based on the page_id and
+ // make sure it is a page and not a post.
+ $actual_page = wp_get_single_post($page_id, ARRAY_A);
+ if(
+ !$actual_page
+ || ($actual_page["post_type"] != "page")
+ ) {
+ return(new IXR_Error(404, __("Sorry, no such page.")));
+ }
+
+ // Set the user context and make sure they can delete pages.
+ set_current_user(0, $username);
+ if(!current_user_can("delete_page", $page_id)) {
+ return(new IXR_Error(401, __("Sorry, you do not have the right to delete this page.")));
+ }
+
+ // Attempt to delete the page.
+ $result = wp_delete_post($page_id);
+ if(!$result) {
+ return(new IXR_Error(500, __("Failed to delete the page.")));
+ }
+
+ return(true);
+ }
+
+ /**
+ * WordPress XML-RPC API
+ * wp_editPage
+ */
+ function wp_editPage($args) {
+ // Items not escaped here will be escaped in editPost.
+ $blog_id = (int) $args[0];
+ $page_id = (int) $this->escape($args[1]);
+ $username = $this->escape($args[2]);
+ $password = $this->escape($args[3]);
+ $content = $args[4];
+ $publish = $args[5];
+
+ if(!$this->login_pass_ok($username, $password)) {
+ return($this->error);
+ }
+
+ // Get the page data and make sure it is a page.
+ $actual_page = wp_get_single_post($page_id, ARRAY_A);
+ if(
+ !$actual_page
+ || ($actual_page["post_type"] != "page")
+ ) {
+ return(new IXR_Error(404, __("Sorry, no such page.")));
+ }
+
+ // Set the user context and make sure they are allowed to edit pages.
+ set_current_user(0, $username);
+ if(!current_user_can("edit_page", $page_id)) {
+ return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page.")));
+ }
+
+ // Mark this as content for a page.
+ $content["post_type"] = "page";
+
+ // Arrange args in the way mw_editPost understands.
+ $args = array(
+ $page_id,
+ $username,
+ $password,
+ $content,
+ $publish
+ );
+
+ // Let mw_editPost do all of the heavy lifting.
+ return($this->mw_editPost($args));
+ }
+
+ /**
+ * WordPress XML-RPC API
+ * wp_getPageList
+ */
+ function wp_getPageList($args) {
+ global $wpdb;
+
+ $this->escape($args);
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ if(!$this->login_pass_ok($username, $password)) {
+ return($this->error);
+ }
+
+ set_current_user( 0, $username );
+ if( !current_user_can( 'edit_pages' ) )
+ return new IXR_Error( 401, __( 'Sorry, you can not edit pages.' ) );
+
+ do_action('xmlrpc_call', 'wp.getPageList');
+
+ // Get list of pages ids and titles
+ $page_list = $wpdb->get_results("
+ SELECT ID page_id,
+ post_title page_title,
+ post_parent page_parent_id,
+ post_date_gmt,
+ post_date
+ FROM {$wpdb->posts}
+ WHERE post_type = 'page'
+ ORDER BY ID
+ ");
+
+ // The date needs to be formated properly.
+ $num_pages = count($page_list);
+ for($i = 0; $i < $num_pages; $i++) {
+ $post_date = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date);
+ $post_date_gmt = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date_gmt);
+
+ $page_list[$i]->dateCreated = new IXR_Date($post_date);
+ $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);
+
+ unset($page_list[$i]->post_date_gmt);
+ unset($page_list[$i]->post_date);
+ }
+
+ return($page_list);
+ }
+
+ /**
+ * WordPress XML-RPC API
+ * wp_getAuthors
+ */
+ function wp_getAuthors($args) {
+
+ $this->escape($args);
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+
+ if(!$this->login_pass_ok($username, $password)) {
+ return($this->error);
+ }
+
+ set_current_user(0, $username);
+ if(!current_user_can("edit_posts")) {
+ return(new IXR_Error(401, __("Sorry, you can not edit posts on this blog.")));
+ }
+
+ do_action('xmlrpc_call', 'wp.getAuthors');
+
+ $authors = array();
+ foreach( (array) get_users_of_blog() as $row ) {
+ $authors[] = array(
+ "user_id" => $row->user_id,
+ "user_login" => $row->user_login,
+ "display_name" => $row->display_name
+ );
+ }
+
+ return($authors);
+ }
+
+ /**
+ * WordPress XML-RPC API
+ * wp_newCategory
+ */
+ function wp_newCategory($args) {
+ $this->escape($args);
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $category = $args[3];
+
+ if(!$this->login_pass_ok($username, $password)) {
+ return($this->error);
+ }
+
+ // Set the user context and make sure they are
+ // allowed to add a category.
+ set_current_user(0, $username);
+ if(!current_user_can("manage_categories")) {
+ return(new IXR_Error(401, __("Sorry, you do not have the right to add a category.")));
+ }
+
+ // If no slug was provided make it empty so that
+ // WordPress will generate one.
+ if(empty($category["slug"])) {
+ $category["slug"] = "";