From 3a4570b0fc8b3d6339bef71d17d7701554e0bbf7 Mon Sep 17 00:00:00 2001 From: donncha Date: Fri, 12 Oct 2007 16:21:15 +0000 Subject: Merge with WP 2.3 - testing use only! Move pluggable functions out of wpmu-functions and into pluggable.php, fixes #439 git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1069 7be80a69-a1ef-0310-a953-fb0f7c49ff36 --- xmlrpc.php | 191 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 109 insertions(+), 82 deletions(-) (limited to 'xmlrpc.php') diff --git a/xmlrpc.php b/xmlrpc.php index 9989a40..e82284a 100644 --- a/xmlrpc.php +++ b/xmlrpc.php @@ -5,7 +5,7 @@ define('XMLRPC_REQUEST', true); // Some browser-embedded clients send cookies. We don't want them. $_COOKIE = array(); -// A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default, +// A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default, // but we can do it ourself. if ( !isset( $HTTP_RAW_POST_DATA ) ) { $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' ); @@ -17,8 +17,8 @@ if ( isset($HTTP_RAW_POST_DATA) ) include('./wp-config.php'); -if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd -header('Content-type: text/xml; charset=' . get_option('blog_charset'), true); +if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd +header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); ?> '; ?> @@ -28,8 +28,8 @@ header('Content-type: text/xml; charset=' . get_option('blog_charset'), true); http://wordpress.org/ - - + + @@ -39,7 +39,7 @@ header('Content-type: text/xml; charset=' . get_option('blog_charset'), true); exit; } -include_once(ABSPATH . 'wp-admin/admin-functions.php'); +include_once(ABSPATH . 'wp-admin/includes/admin.php'); include_once(ABSPATH . WPINC . '/class-IXR.php'); // Turn off all warnings and errors. @@ -208,7 +208,8 @@ class wp_xmlrpc_server extends IXR_Server { $allow_pings = ("open" == $page->ping_status) ? 1 : 0; // Format page date. - $page_date = mysql2date("Ymd\TH:i:s\Z", $page->post_date_gmt); + $page_date = mysql2date("Ymd\TH:i:s", $page->post_date); + $page_date_gmt = mysql2date("Ymd\TH:i:s", $page->post_date_gmt); // Pull the categories info together. $categories = array(); @@ -240,7 +241,8 @@ class wp_xmlrpc_server extends IXR_Server { "wp_page_parent_title" => $parent_title, "wp_page_order" => $page->menu_order, "wp_author_id" => $author->ID, - "wp_author_display_name" => $author->display_name + "wp_author_display_name" => $author->display_name, + "date_created_gmt" => new IXR_Date($page_date_gmt) ); return($page_struct); @@ -429,7 +431,8 @@ class wp_xmlrpc_server extends IXR_Server { SELECT ID page_id, post_title page_title, post_parent page_parent_id, - post_date_gmt + post_date_gmt, + post_date FROM {$wpdb->posts} WHERE post_type = 'page' ORDER BY ID @@ -438,10 +441,14 @@ class wp_xmlrpc_server extends IXR_Server { // 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\Z", $page_list[$i]->post_date_gmt); + $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); @@ -490,10 +497,6 @@ class wp_xmlrpc_server extends IXR_Server { return(new IXR_Error(401, __("Sorry, you do not have the right to add a category."))); } - // We need this to make use of the wp_insert_category() - // funciton. - require_once(ABSPATH . "wp-admin/admin-db.php"); - // If no slug was provided make it empty so that // WordPress will generate one. if(empty($category["slug"])) { @@ -509,7 +512,7 @@ class wp_xmlrpc_server extends IXR_Server { if(empty($category["description"])) { $category["description"] = ""; } - + $new_category = array( "cat_name" => $category["name"], "category_nicename" => $category["slug"], @@ -544,19 +547,8 @@ class wp_xmlrpc_server extends IXR_Server { return($this->error); } - // Only set a limit if one was provided. - $limit = ""; - if(!empty($max_results)) { - $limit = "LIMIT {$max_results}"; - } - - $category_suggestions = $wpdb->get_results(" - SELECT cat_ID category_id, - cat_name category_name - FROM {$wpdb->categories} - WHERE cat_name LIKE '{$category}%' - {$limit} - "); + $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category); + $category_suggestions = get_categories($args); return($category_suggestions); } @@ -735,7 +727,7 @@ class wp_xmlrpc_server extends IXR_Server { return new IXR_Error(401, __('Sorry, this user can not edit the template.')); } - /* warning: here we make the assumption that the weblog's URL is on the same server */ + /* warning: here we make the assumption that the blog's URL is on the same server */ $filename = get_option('home') . '/'; $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); @@ -744,7 +736,7 @@ class wp_xmlrpc_server extends IXR_Server { fclose($f); /* so it is actually editable with a windows/mac client */ - // FIXME: (or delete me) do we really want to cater to bad clients at the expense of good ones by BEEPing up their line breaks? commented. $content = str_replace("\n", "\r\n", $content); + // FIXME: (or delete me) do we really want to cater to bad clients at the expense of good ones by BEEPing up their line breaks? commented. $content = str_replace("\n", "\r\n", $content); return $content; } @@ -770,7 +762,7 @@ class wp_xmlrpc_server extends IXR_Server { return new IXR_Error(401, __('Sorry, this user can not edit the template.')); } - /* warning: here we make the assumption that the weblog's URL is on the same server */ + /* warning: here we make the assumption that the blog's URL is on the same server */ $filename = get_option('home') . '/'; $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); @@ -801,11 +793,11 @@ class wp_xmlrpc_server extends IXR_Server { if (!$this->login_pass_ok($user_login, $user_pass)) { return $this->error; } - + $cap = ($publish) ? 'publish_posts' : 'edit_posts'; $user = set_current_user(0, $user_login); if ( !current_user_can($cap) ) - return new IXR_Error(401, __('Sorry, you can not post on this weblog or category.')); + return new IXR_Error(401, __('Sorry, you are not allowed to post on this blog.')); $post_status = ($publish) ? 'publish' : 'draft'; @@ -821,6 +813,8 @@ class wp_xmlrpc_server extends IXR_Server { $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status'); $post_ID = wp_insert_post($post_data); + if ( is_wp_error( $post_ID ) ) + return new IXR_Error(500, $post_ID->get_error_message()); if (!$post_ID) { return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); @@ -945,7 +939,7 @@ class wp_xmlrpc_server extends IXR_Server { $cap = ($publish) ? 'publish_posts' : 'edit_posts'; $user = set_current_user(0, $user_login); if ( !current_user_can($cap) ) - return new IXR_Error(401, __('Sorry, you can not post on this weblog or category.')); + return new IXR_Error(401, __('Sorry, you are not allowed to post on this blog.')); // The post_type defaults to post, but could also be page. $post_type = "post"; @@ -988,14 +982,12 @@ class wp_xmlrpc_server extends IXR_Server { switch($post_type) { case "post": if(!current_user_can("edit_others_posts")) { - return(new IXR_Error(401, "You are not allowed to " . - "post as this user")); + return(new IXR_Error(401, __("You are not allowed to post as this user"))); } break; case "page": if(!current_user_can("edit_others_pages")) { - return(new IXR_Error(401, "You are not allowed to " . - "create pages as this user")); + return(new IXR_Error(401, __("You are not allowed to create pages as this user"))); } break; default: @@ -1012,6 +1004,8 @@ class wp_xmlrpc_server extends IXR_Server { $post_excerpt = $content_struct['mt_excerpt']; $post_more = $content_struct['mt_text_more']; + $tags_input = $content_struct['mt_keywords']; + if(isset($content_struct["mt_allow_comments"])) { if(!is_numeric($content_struct["mt_allow_comments"])) { switch($content_struct["mt_allow_comments"]) { @@ -1046,7 +1040,7 @@ class wp_xmlrpc_server extends IXR_Server { if(isset($content_struct["mt_allow_pings"])) { if(!is_numeric($content_struct["mt_allow_pings"])) { - switch($content_struct["mt_allow_pings"]) { + switch($content_struct['mt_allow_pings']) { case "closed": $ping_status = "closed"; break; @@ -1084,16 +1078,16 @@ class wp_xmlrpc_server extends IXR_Server { if ( is_array($to_ping) ) $to_ping = implode(' ', $to_ping); - // Do some timestamp voodoo - $dateCreatedd = $content_struct['dateCreated']; - if (!empty($dateCreatedd)) { - $dateCreated = $dateCreatedd->getIso(); - $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); - $post_date_gmt = iso8601_to_datetime($dateCreated. "Z", GMT); - } else { - $post_date = current_time('mysql'); - $post_date_gmt = current_time('mysql', 1); - } + // Do some timestamp voodoo + $dateCreatedd = $content_struct['dateCreated']; + if (!empty($dateCreatedd)) { + $dateCreated = $dateCreatedd->getIso(); + $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); + $post_date_gmt = iso8601_to_datetime($dateCreated, GMT); + } else { + $post_date = current_time('mysql'); + $post_date_gmt = current_time('mysql', 1); + } $catnames = $content_struct['categories']; logIO('O', 'Post cats: ' . printr($catnames,true)); @@ -1106,9 +1100,11 @@ class wp_xmlrpc_server extends IXR_Server { } // We've got all the data -- post it: - $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order'); + $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input'); $post_ID = wp_insert_post($postdata); + if ( is_wp_error( $post_ID ) ) + return new IXR_Error(500, $post_ID->get_error_message()); if (!$post_ID) { return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); @@ -1210,14 +1206,12 @@ class wp_xmlrpc_server extends IXR_Server { switch($post_type) { case "post": if(!current_user_can("edit_others_posts")) { - return(new IXR_Error(401, "You are not allowed to " . - "change the post author as this user.")); + return(new IXR_Error(401, __("You are not allowed to change the post author as this user."))); } break; case "page": if(!current_user_can("edit_others_pages")) { - return(new IXR_Error(401, "You are not allowed to " . - "change the page author as this user.")); + return(new IXR_Error(401, __("You are not allowed to change the page author as this user."))); } break; default: @@ -1301,6 +1295,8 @@ class wp_xmlrpc_server extends IXR_Server { $post_more = $content_struct['mt_text_more']; $post_status = $publish ? 'publish' : 'draft'; + $tags_input = $content_struct['mt_keywords']; + if ( ('publish' == $post_status) ) { if ( ( 'page' == $post_type ) && !current_user_can('publish_pages') ) return new IXR_Error(401, __('Sorry, you do not have the right to publish this page.')); @@ -1328,7 +1324,7 @@ class wp_xmlrpc_server extends IXR_Server { } // We've got all the data -- post it: - $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author'); + $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input'); $result = wp_update_post($newpost); if (!$result) { @@ -1361,7 +1357,8 @@ class wp_xmlrpc_server extends IXR_Server { if ($postdata['post_date'] != '') { - $post_date = mysql2date('Ymd\TH:i:s\Z', $postdata['post_date_gmt']); + $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']); + $post_date_gmt = mysql2date('Ymd\TH:i:s', $postdata['post_date_gmt']); $categories = array(); $catids = wp_get_post_categories($post_ID); @@ -1369,6 +1366,17 @@ class wp_xmlrpc_server extends IXR_Server { $categories[] = get_cat_name($catid); } + $tagnames = array(); + $tags = wp_get_post_tags( $post_ID ); + if ( !empty( $tags ) ) { + foreach ( $tags as $tag ) { + $tagnames[] = $tag->name; + } + $tagnames = implode( ', ', $tagnames ); + } else { + $tagnames = ''; + } + $post = get_extended($postdata['post_content']); $link = post_permalink($postdata['ID']); @@ -1393,10 +1401,12 @@ class wp_xmlrpc_server extends IXR_Server { 'mt_text_more' => $post['extended'], 'mt_allow_comments' => $allow_comments, 'mt_allow_pings' => $allow_pings, + 'mt_keywords' => $tagnames, 'wp_slug' => $postdata['post_name'], 'wp_password' => $postdata['post_password'], 'wp_author_id' => $author->ID, - 'wp_author_display_name' => $author->display_name + 'wp_author_display_name' => $author->display_name, + 'date_created_gmt' => new IXR_Date($post_date_gmt) ); return $resp; @@ -1429,13 +1439,26 @@ class wp_xmlrpc_server extends IXR_Server { foreach ($posts_list as $entry) { - $post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']); + $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); + $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt']); + $categories = array(); $catids = wp_get_post_categories($entry['ID']); foreach($catids as $catid) { $categories[] = get_cat_name($catid); } + $tagnames = array(); + $tags = wp_get_post_tags( $entry['ID'] ); + if ( !empty( $tags ) ) { + foreach ( $tags as $tag ) { + $tagnames[] = $tag->name; + } + $tagnames = implode( ', ', $tagnames ); + } else { + $tagnames = ''; + } + $post = get_extended($entry['post_content']); $link = post_permalink($entry['ID']); @@ -1460,10 +1483,12 @@ class wp_xmlrpc_server extends IXR_Server { 'mt_text_more' => $post['extended'], 'mt_allow_comments' => $allow_comments, 'mt_allow_pings' => $allow_pings, + 'mt_keywords' => $tagnames, 'wp_slug' => $entry['post_name'], 'wp_password' => $entry['post_password'], 'wp_author_id' => $author->ID, - 'wp_author_display_name' => $author->display_name + 'wp_author_display_name' => $author->display_name, + 'date_created_gmt' => new IXR_Date($post_date_gmt) ); } @@ -1477,7 +1502,7 @@ class wp_xmlrpc_server extends IXR_Server { } - /* metaweblog.getCategories ...returns the list of categories on a given weblog */ + /* metaweblog.getCategories ...returns the list of categories on a given blog */ function mw_getCategories($args) { global $wpdb; @@ -1494,15 +1519,14 @@ class wp_xmlrpc_server extends IXR_Server { $categories_struct = array(); - // FIXME: can we avoid using direct SQL there? - if ($cats = $wpdb->get_results("SELECT cat_ID,cat_name,category_parent FROM $wpdb->categories", ARRAY_A)) { - foreach ($cats as $cat) { - $struct['categoryId'] = $cat['cat_ID']; - $struct['parentId'] = $cat['category_parent']; - $struct['description'] = $cat['cat_name']; - $struct['categoryName'] = $cat['cat_name']; - $struct['htmlUrl'] = wp_specialchars(get_category_link($cat['cat_ID'])); - $struct['rssUrl'] = wp_specialchars(get_category_rss_link(false, $cat['cat_ID'], $cat['cat_name'])); + if ( $cats = get_categories('get=all') ) { + foreach ( $cats as $cat ) { + $struct['categoryId'] = $cat->term_id; + $struct['parentId'] = $cat->parent; + $struct['description'] = $cat->name; + $struct['categoryName'] = $cat->name; + $struct['htmlUrl'] = wp_specialchars(get_category_link($cat->term_id)); + $struct['rssUrl'] = wp_specialchars(get_category_rss_link(false, $cat->term_id, $cat->name)); $categories_struct[] = $struct; } @@ -1563,7 +1587,7 @@ class wp_xmlrpc_server extends IXR_Server { $upload = wp_upload_bits($name, $type, $bits, $overwrite); if ( ! empty($upload['error']) ) { - $errorString = 'Could not write file ' . $name . ' (' . $upload['error'] . ')'; + $errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']); logIO('O', '(MW) ' . $errorString); return new IXR_Error(500, $errorString); } @@ -1614,13 +1638,15 @@ class wp_xmlrpc_server extends IXR_Server { foreach ($posts_list as $entry) { - $post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']); + $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); + $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt']); $struct[] = array( 'dateCreated' => new IXR_Date($post_date), 'userid' => $entry['post_author'], 'postid' => $entry['ID'], 'title' => $entry['post_title'], + 'date_created_gmt' => new IXR_Date($post_date_gmt) ); } @@ -1634,7 +1660,7 @@ class wp_xmlrpc_server extends IXR_Server { } - /* mt.getCategoryList ...returns the list of categories on a given weblog */ + /* mt.getCategoryList ...returns the list of categories on a given blog */ function mt_getCategoryList($args) { global $wpdb; @@ -1652,10 +1678,10 @@ class wp_xmlrpc_server extends IXR_Server { $categories_struct = array(); // FIXME: can we avoid using direct SQL there? - if ($cats = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories", ARRAY_A)) { + if ( $cats = get_categories('hide_empty=0&hierarchical=0') ) { foreach ($cats as $cat) { - $struct['categoryId'] = $cat['cat_ID']; - $struct['categoryName'] = $cat['cat_name']; + $struct['categoryId'] = $cat->term_id; + $struct['categoryName'] = $cat->name; $categories_struct[] = $struct; } @@ -1827,7 +1853,8 @@ class wp_xmlrpc_server extends IXR_Server { $title = ''; $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom); - $pagelinkedto = preg_replace('#&([^amp\;])#is', '&$1', $pagelinkedto); + $pagelinkedto = str_replace('&', '&', $pagelinkedto); + $pagelinkedto = str_replace('&', '&', $pagelinkedto); $error_code = -1; @@ -1874,7 +1901,7 @@ class wp_xmlrpc_server extends IXR_Server { } } else { // TODO: Attempt to extract a post ID from the given URL - return new IXR_Error(33, 'The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); + return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.')); } $post_ID = (int) $post_ID; @@ -1884,14 +1911,14 @@ class wp_xmlrpc_server extends IXR_Server { $post = get_post($post_ID); if ( !$post ) // Post_ID not found - return new IXR_Error(33, 'The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); + return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.')); if ( $post_ID == url_to_postid($pagelinkedfrom) ) return new IXR_Error(0, __('The source URL and the target URL cannot both point to the same resource.')); // Check if pings are on if ( 'closed' == $post->ping_status ) - return new IXR_Error(33, 'The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); + return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.')); // Let's check that the remote site didn't already pingback this entry $result = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post_ID' AND comment_author_url = '$pagelinkedfrom'"); @@ -1953,7 +1980,7 @@ class wp_xmlrpc_server extends IXR_Server { if ( empty($context) ) // Link to target not found return new IXR_Error(17, __('The source URL does not contain a link to the target URL, and so cannot be used as a source.')); - $pagelinkedfrom = preg_replace('#&([^amp\;])#is', '&$1', $pagelinkedfrom); + $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom); $context = '[...] ' . wp_specialchars( $excerpt ) . ' [...]'; $original_pagelinkedfrom = $pagelinkedfrom; @@ -1973,7 +2000,7 @@ class wp_xmlrpc_server extends IXR_Server { $comment_ID = wp_new_comment($commentdata); do_action('pingback_post', $comment_ID); - return "Pingback from $pagelinkedfrom to $pagelinkedto registered. Keep the web talking! :-)"; + return sprintf(__('Pingback from %1$s to %2$s registered. Keep the web talking! :-)'), $pagelinkedfrom, $pagelinkedto); } @@ -1991,7 +2018,7 @@ class wp_xmlrpc_server extends IXR_Server { $post_ID = url_to_postid($url); if (!$post_ID) { // We aren't sure that the resource is available and/or pingback enabled - return new IXR_Error(33, 'The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); + return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.')); } $actual_post = wp_get_single_post($post_ID, ARRAY_A); -- cgit