added mw.getRecentPosts, mw.getCategories, refactored the living shit out of the rest of the file
git-svn-id: https://develop.svn.wordpress.org/trunk@1565 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d69d080abc
commit
530f455bfa
214
xmlrpc.php
214
xmlrpc.php
|
@ -5,6 +5,7 @@ $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
|
||||||
|
|
||||||
include('../wp-config.php');
|
include('../wp-config.php');
|
||||||
include_once(ABSPATH . WPINC . '/class-IXR.php');
|
include_once(ABSPATH . WPINC . '/class-IXR.php');
|
||||||
|
include_once(ABSPATH . WPINC . '/functions-post.php');
|
||||||
|
|
||||||
// Turn off all warnings and errors.
|
// Turn off all warnings and errors.
|
||||||
// error_reporting(0);
|
// error_reporting(0);
|
||||||
|
@ -12,7 +13,7 @@ include_once(ABSPATH . WPINC . '/class-IXR.php');
|
||||||
$post_default_title = ""; // posts submitted via the xmlrpc interface get that title
|
$post_default_title = ""; // posts submitted via the xmlrpc interface get that title
|
||||||
$post_default_category = 1; // posts submitted via the xmlrpc interface go into that category
|
$post_default_category = 1; // posts submitted via the xmlrpc interface go into that category
|
||||||
|
|
||||||
$xmlrpc_logging = 0;
|
$xmlrpc_logging = 1;
|
||||||
|
|
||||||
function logIO($io,$msg) {
|
function logIO($io,$msg) {
|
||||||
global $xmlrpc_logging;
|
global $xmlrpc_logging;
|
||||||
|
@ -33,7 +34,18 @@ function starify($string) {
|
||||||
|
|
||||||
logIO("I", $HTTP_RAW_POST_DATA);
|
logIO("I", $HTTP_RAW_POST_DATA);
|
||||||
|
|
||||||
|
function printr ( $var, $do_not_echo = false )
|
||||||
|
{
|
||||||
|
ob_start();
|
||||||
|
print_r($var);
|
||||||
|
$code = htmlentities(ob_get_contents());
|
||||||
|
ob_clean();
|
||||||
|
if ( !$do_not_echo )
|
||||||
|
{
|
||||||
|
echo "<pre>$code</pre>";
|
||||||
|
}
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
|
||||||
class wp_xmlrpc_server extends IXR_Server {
|
class wp_xmlrpc_server extends IXR_Server {
|
||||||
|
|
||||||
|
@ -52,6 +64,8 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
'metaWeblog.newPost' => 'this:mw_newPost',
|
'metaWeblog.newPost' => 'this:mw_newPost',
|
||||||
'metaWeblog.editPost' => 'this:mw_editPost',
|
'metaWeblog.editPost' => 'this:mw_editPost',
|
||||||
'metaWeblog.getPost' => 'this:mw_getPost',
|
'metaWeblog.getPost' => 'this:mw_getPost',
|
||||||
|
'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
|
||||||
|
'metaWeblog.getCategories' => 'this:mw_getCategories',
|
||||||
|
|
||||||
'demo.sayHello' => 'this:sayHello',
|
'demo.sayHello' => 'this:sayHello',
|
||||||
'demo.addTwoNumbers' => 'this:addTwoNumbers'
|
'demo.addTwoNumbers' => 'this:addTwoNumbers'
|
||||||
|
@ -70,7 +84,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
|
|
||||||
function login_pass_ok($user_login, $user_pass) {
|
function login_pass_ok($user_login, $user_pass) {
|
||||||
if (!user_pass_ok($user_login, $user_pass)) {
|
if (!user_pass_ok($user_login, $user_pass)) {
|
||||||
$this->error = new IXR_Error(403, 'Bad login/pass combination.');
|
$this->error = new IXR_Error(403, 'Bad login/pass combination.'.$user_login);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -145,19 +159,17 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
$user_data = get_userdatabylogin($user_login);
|
$user_data = get_userdatabylogin($user_login);
|
||||||
$post_data = get_postdata($post_ID);
|
$post_data = wp_get_single_post($post_ID, ARRAY_A);
|
||||||
|
|
||||||
$post_date = mysql2date('Ymd\TH:i:s', $post_data['Date']);
|
|
||||||
|
|
||||||
$categories = implode(',', wp_get_post_cats(1, $post_ID));
|
$categories = implode(',', wp_get_post_cats(1, $post_ID));
|
||||||
|
|
||||||
$content = '<title>'.stripslashes($post_data['Title']).'</title>';
|
$content = '<title>'.stripslashes($post_data['post_title']).'</title>';
|
||||||
$content .= '<category>'.$categories.'</category>';
|
$content .= '<category>'.$categories.'</category>';
|
||||||
$content .= stripslashes($post_data['Content']);
|
$content .= stripslashes($post_data['post_content']);
|
||||||
|
|
||||||
$struct = array(
|
$struct = array(
|
||||||
'userid' => $post_data['Author_ID'],
|
'userid' => $post_data['post_author'],
|
||||||
'dateCreateed' => mysql2date('Ymd\TH:i:s', $post_data['Date']),
|
'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s\Z', $post_data['post_date_gmt'])),
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'postid' => $post_data['ID']
|
'postid' => $post_data['ID']
|
||||||
);
|
);
|
||||||
|
@ -176,77 +188,33 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
$user_pass = $args[3];
|
$user_pass = $args[3];
|
||||||
$num_posts = $args[4];
|
$num_posts = $args[4];
|
||||||
|
|
||||||
if ($num_posts > 0) {
|
|
||||||
$limit = " LIMIT $num_posts";
|
|
||||||
} else {
|
|
||||||
$limit = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->login_pass_ok($user_login, $user_pass)) {
|
if (!$this->login_pass_ok($user_login, $user_pass)) {
|
||||||
return $this->error;
|
return $this->error;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT * FROM $wpdb->posts ORDER BY post_date DESC".$limit;
|
$posts_list = wp_get_recent_posts($num_posts);
|
||||||
$result = $wpdb->get_results($sql);
|
|
||||||
|
|
||||||
if (!$result) {
|
if (!$posts_list) {
|
||||||
$this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
|
$this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
|
||||||
return $this->error;
|
return $this->error;
|
||||||
}
|
}
|
||||||
|
|
||||||
$i = 0;
|
foreach ($posts_list as $entry) {
|
||||||
foreach ($result as $row) {
|
|
||||||
$post_data = array(
|
$post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']);
|
||||||
'ID' => $row->ID,
|
$categories = implode(',', wp_get_post_cats(1, $entry['ID']));
|
||||||
'Author_ID' => $row->post_author,
|
|
||||||
'Date' => $row->post_date,
|
|
||||||
'Content' => $row->post_content,
|
|
||||||
'Title' => $row->post_title,
|
|
||||||
'Category' => $row->post_category
|
|
||||||
);
|
|
||||||
|
|
||||||
$categories = implode(',', wp_get_post_cats(1, $post_data['ID']));
|
$content = '<title>'.stripslashes($entry['post_itle']).'</title>';
|
||||||
$post_date = mysql2date("Ymd\TH:i:s", $post_data['Date']);
|
|
||||||
|
|
||||||
$content = '<title>'.stripslashes($post_data['Title']).'</title>';
|
|
||||||
$content .= '<category>'.$categories.'</category>';
|
$content .= '<category>'.$categories.'</category>';
|
||||||
$content .= stripslashes($post_data['Content']);
|
$content .= stripslashes($entry['post_content']);
|
||||||
|
|
||||||
$author_data = get_userdata($post_data['Author_ID']);
|
$struct[] = array(
|
||||||
|
'userid' => $entry['post_author'],
|
||||||
switch($author_data['user_idmode']) {
|
'dateCreated' => new IXR_Date($post_date),
|
||||||
case 'nickname':
|
|
||||||
$author_name = $author_data['user_nickname'];
|
|
||||||
case 'login':
|
|
||||||
$author_name = $author_data['user_login'];
|
|
||||||
break;
|
|
||||||
case 'firstname':
|
|
||||||
$author_name = $author_data['user_firstname'];
|
|
||||||
break;
|
|
||||||
case 'lastname':
|
|
||||||
$author_name = $author_data['user_lastname'];
|
|
||||||
break;
|
|
||||||
case 'namefl':
|
|
||||||
$author_name = $author_data['user_firstname']." ".$author_data['user_lastname'];
|
|
||||||
break;
|
|
||||||
case 'namelf':
|
|
||||||
$author_name = $author_data['user_lastname']." ".$author_data['user_firstname'];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$author_name = $author_data['user_nickname'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$struct[$i] = array(
|
|
||||||
'authorName' => $author_name,
|
|
||||||
'userid' => $post_data['Author_ID'],
|
|
||||||
'dateCreated' => $post_date,
|
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'postid' => $post_data['ID'],
|
'postid' => $entry['ID'],
|
||||||
'category' => $categories
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$recent_posts = array();
|
$recent_posts = array();
|
||||||
|
@ -285,7 +253,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
fclose($f);
|
fclose($f);
|
||||||
|
|
||||||
/* so it is actually editable with a windows/mac client */
|
/* so it is actually editable with a windows/mac client */
|
||||||
$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;
|
return $content;
|
||||||
}
|
}
|
||||||
|
@ -510,6 +478,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
|
|
||||||
$catnames = $content_struct['categories'];
|
$catnames = $content_struct['categories'];
|
||||||
// FIXME: commented until a fix to print_r is found: logio('O', 'Post cats: ' . print_r($catnames,true));
|
// FIXME: commented until a fix to print_r is found: logio('O', 'Post cats: ' . print_r($catnames,true));
|
||||||
|
//logio('O', 'Post cats: ' . printr($catnames,true));
|
||||||
$post_category = array();
|
$post_category = array();
|
||||||
|
|
||||||
if ($catnames) {
|
if ($catnames) {
|
||||||
|
@ -626,27 +595,29 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
if ($postdata['post_date'] != '') {
|
if ($postdata['post_date'] != '') {
|
||||||
|
|
||||||
$post_date = mysql2date('Ymd\TH:i:s\Z', $postdata['post_date_gmt']);
|
$post_date = mysql2date('Ymd\TH:i:s\Z', $postdata['post_date_gmt']);
|
||||||
|
|
||||||
|
$categories = array();
|
||||||
$catids = wp_get_post_cats('', $post_ID);
|
$catids = wp_get_post_cats('', $post_ID);
|
||||||
foreach($catids as $catid) {
|
foreach($catids as $catid) {
|
||||||
$catname = get_cat_name($catid);
|
$categories[] = get_cat_name($catid);
|
||||||
$catnameenc = new xmlrpcval($catname);
|
|
||||||
$catlist[] = $catnameenc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$post = get_extended($postdata['post_content']);
|
$post = get_extended($postdata['post_content']);
|
||||||
|
$link = post_permalink($entry['ID']);
|
||||||
|
|
||||||
$allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
|
$allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
|
||||||
$allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
|
$allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
|
||||||
|
|
||||||
$resp = array(
|
$resp = array(
|
||||||
'link' => post_permalink($post_ID),
|
'link' => $link,
|
||||||
'title' => $postdata['post_title'],
|
'title' => $postdata['post_title'],
|
||||||
'description' => $post['main'],
|
'description' => $post['main'],
|
||||||
'dateCreated' => new IXR_Date($post_date),
|
'dateCreated' => new IXR_Date($post_date),
|
||||||
'userid' => $postdata['post_author'],
|
'userid' => $postdata['post_author'],
|
||||||
'postid' => $postdata['ID'],
|
'postid' => $postdata['ID'],
|
||||||
'content' => $postdata['post_content'],
|
'content' => $postdata['post_content'],
|
||||||
'permalink' => post_permalink($post_ID),
|
'permalink' => $link,
|
||||||
'categories' => $catlist,
|
'categories' => $categories,
|
||||||
'mt_excerpt' => $postdata['post_excerpt'],
|
'mt_excerpt' => $postdata['post_excerpt'],
|
||||||
'mt_allow_comments' => $allow_comments,
|
'mt_allow_comments' => $allow_comments,
|
||||||
'mt_allow_pings' => $allow_pings,
|
'mt_allow_pings' => $allow_pings,
|
||||||
|
@ -658,7 +629,100 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
return new IXR_Error(404, 'Sorry, no such post.');
|
return new IXR_Error(404, 'Sorry, no such post.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* metaweblog.getRecentPosts ...returns recent posts */
|
||||||
|
function mw_getRecentPosts($args) {
|
||||||
|
|
||||||
|
$blog_ID = $args[0];
|
||||||
|
$user_login = $args[1];
|
||||||
|
$user_pass = $args[2];
|
||||||
|
$num_posts = $args[4];
|
||||||
|
|
||||||
|
if (!$this->login_pass_ok($user_login, $user_pass)) {
|
||||||
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
$posts_list = wp_get_recent_posts($num_posts);
|
||||||
|
|
||||||
|
if (!$posts_list) {
|
||||||
|
$this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
|
||||||
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($posts_list as $entry) {
|
||||||
|
|
||||||
|
$post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']);
|
||||||
|
$categories = array();
|
||||||
|
$catids = wp_get_post_cats('', $entry['ID']);
|
||||||
|
foreach($catids as $catid) {
|
||||||
|
$categories[] = get_cat_name($catid);
|
||||||
|
}
|
||||||
|
|
||||||
|
$post = get_extended($entry['post_content']);
|
||||||
|
$link = post_permalink($entry['ID']);
|
||||||
|
|
||||||
|
$allow_comments = ('open' == $entry['comment_status']) ? 1 : 0;
|
||||||
|
$allow_pings = ('open' == $entry['ping_status']) ? 1 : 0;
|
||||||
|
|
||||||
|
$struct[] = array(
|
||||||
|
'link' => $link,
|
||||||
|
'title' => $entry['post_title'],
|
||||||
|
'description' => $post['main'],
|
||||||
|
'dateCreated' => new IXR_Date($post_date),
|
||||||
|
'userid' => $entry['post_author'],
|
||||||
|
'postid' => $entry['ID'],
|
||||||
|
'content' => $entry['post_content'],
|
||||||
|
'permalink' => $link,
|
||||||
|
'categories' => $categories,
|
||||||
|
'mt_excerpt' => $entry['post_excerpt'],
|
||||||
|
'mt_allow_comments' => $allow_comments,
|
||||||
|
'mt_allow_pings' => $allow_pings,
|
||||||
|
'mt_text_more' => $post['extended']
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$recent_posts = array();
|
||||||
|
for ($j=0; $j<count($struct); $j++) {
|
||||||
|
array_push($recent_posts, $struct[$j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $recent_posts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* metaweblog.getCategories ...returns the list of categories on a given weblog */
|
||||||
|
function mw_getCategories($args) {
|
||||||
|
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$blog_ID = $args[0];
|
||||||
|
$user_login = $args[1];
|
||||||
|
$user_pass = $args[2];
|
||||||
|
|
||||||
|
if (!$this->login_pass_ok($user_login, $user_pass)) {
|
||||||
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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)) {
|
||||||
|
foreach ($cats as $cat) {
|
||||||
|
$struct['categoryId'] = $cat['cat_ID'];
|
||||||
|
$struct['description'] = $cat['cat_name'];
|
||||||
|
$struct['categoryName'] = $cat['cat_name'];
|
||||||
|
$struct['htmlUrl'] = htmlspecialchars(get_category_link(false, $cat['cat_ID'], $cat['cat_name']));
|
||||||
|
$struct['rssUrl'] = htmlspecialchars(get_category_rss_link(false, $cat['cat_ID'], $cat['cat_name']));
|
||||||
|
|
||||||
|
$categories_struct[] = $struct;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $categories_struct;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue