/s', '', substr($xml_in, 0, 100), 1);
$HTTP_RAW_POST_DATA = trim(substr_replace($xml_in, $header, 0, 100));
if ($HTTP_RAW_POST_DATA == '') {
return FALSE;
}
// Strip DTD.
$header = preg_replace('/^]*+>/i', '', substr($HTTP_RAW_POST_DATA, 0, 200), 1);
$HTTP_RAW_POST_DATA = trim(substr_replace($HTTP_RAW_POST_DATA, $header, 0, 200));
if ($HTTP_RAW_POST_DATA == '') {
return FALSE;
}
// Confirm the XML now starts with a valid root tag. A root tag can end in [> \t\r\n]
$root_tag = substr($HTTP_RAW_POST_DATA, 0, strcspn(substr($HTTP_RAW_POST_DATA, 0, 20), "> \t\r\n"));
// Reject a second DTD.
if (strtoupper($root_tag) == 'loadXML($HTTP_RAW_POST_DATA);
if ($dom->getElementsByTagName('*')->length > 30000) {
return FALSE;
}
}
catch (Exception $e) {
return FALSE;
}
}
@define('XMLRPC_WP_COMPATIBLE', TRUE);
@define('XMLRPC_ERR_CODE_AUTHFAILED', 4);
@define('XMLRPC_ERR_CODE_NOTFOUND', 404);
@define('XMLRPC_ERR_NAME_AUTHFAILED', 'Authentication Failed');
$dispatches = array(
/* WordPress API */
'wp.getUsersBlogs' =>
array('function' => 'wp_getUsersBlogs'),
'wp.getCategories' =>
array('function' => 'wp_getCategories'),
'wp.uploadFile' =>
array('function' => 'wp_uploadFile'),
'wp.newCategory' =>
array('function' => 'wp_newCategory'),
'wp.getPostFormats' =>
array('function' => 'wp_getPostFormats'),
'wp.getComment' =>
array('function' => 'wp_getComment'),
'wp.getComments' =>
array('function' => 'wp_getComments'),
'wp.deleteComment' =>
array('function' => 'wp_deleteComment'),
'wp.editComment' =>
array('function' => 'wp_editComment'),
'wp.newComment' =>
array('function' => 'wp_newComment'),
'wp.getTags' =>
array('function' => 'wp_getTags'),
'wp.getPage' =>
array('function' => 'wp_getPage'),
'wp.getPosts' =>
array('function' => 'wp_getPosts'),
'wp.getCommentStatusList' =>
array('function' => 'wp_getCommentStatusList'),
'wp.getOptions' =>
array('function' => 'wp_getOptions'),
'wp.getPostStatusList' =>
array('function' => 'wp_getPostStatusList'),
'wp.getPageTemplates' =>
array('function' => 'wp_getPageTemplates'),
'wp.getPageStatusList' =>
array('function' => 'wp_getPageStatusList'),
'wp.getPages' =>
array('function' => 'wp_getPages'),
'wp.getPageList' =>
array('function' => 'wp_getPageList'),
'wp.editPage' =>
array('function' => 'wp_editPage'),
/* BLOGGER API */
'blogger.getUsersBlogs' =>
array('function' => 'blogger_getUsersBlogs'),
'blogger.getUserInfo' =>
array('function' => 'blogger_getUserInfo'),
'blogger.newPost' =>
array('function' => 'blogger_newPost'),
'blogger.editPost' =>
array('function' => 'blogger_editPost'),
'blogger.deletePost' =>
array('function' => 'blogger_deletePost'),
'blogger.getRecentPosts' =>
array('function' => 'blogger_getRecentPosts'),
'blogger.getPost' =>
array('function' => 'blogger_getPost'),
/* MT/metaWeblog API */
'metaWeblog.newPost' =>
array('function' => 'metaWeblog_newPost'),
'metaWeblog.editPost' =>
array('function' => 'metaWeblog_editPost'),
'metaWeblog.getPost' =>
array('function' => 'metaWeblog_getPost'),
'metaWeblog.deletePost' =>
array('function' => 'metaWeblog_deletePost'),
'metaWeblog.setPostCategories' =>
array('function' => 'metaWeblog_setPostCategories'),
'metaWeblog.getPostCategories' =>
array('function' => 'metaWeblog_getPostCategories'),
'metaWeblog.newMediaObject' =>
array('function' => 'metaWeblog_newMediaObject'),
'metaWeblog.getRecentPosts' =>
array('function' => 'metaWeblog_getRecentPosts'),
'metaWeblog.getCategories' =>
array('function' => 'metaWeblog_getCategories'),
'mt.getRecentPostTitles' =>
array('function' => 'mt_getRecentPostTitles'),
'mt.getCategoryList' =>
array('function' => 'mt_getCategoryList'),
'mt.getPostCategories' =>
array('function' => 'metaWeblog_getPostCategories'),
'mt.setPostCategories' =>
array('function' => 'metaWeblog_setPostCategories'),
'mt.supportedTextFilters' =>
array('function' => 'mt_supportedTextFilters'),
'mt.publishPost' =>
array('function' => 'metaWeblog_publishPost'),
'mt.supportedMethods' =>
array('function' => 'mt_supportedMethods')
);
function wp_getUsersBlogs($message) {
global $serendipity;
$val = $message->params[0];
$username = $val->getval();
$val = $message->params[1];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$blog1 = new XML_RPC_Value(
array('url' => new XML_RPC_Value($serendipity['baseURL'], 'string'),
'blogid' => new XML_RPC_Value('1', 'string'),
'blogName' => new XML_RPC_Value($serendipity['blogTitle'], 'string'),
'isAdmin' => new XML_RPC_Value('false', 'boolean'),
'xmlrpc' => new XML_RPC_Value($serendipity['baseURL'] . 'serendipity_xmlrpc.php', 'string')
),
'struct');
$blogs = new XML_RPC_Value(array($blog1), 'array');
#$blogs = $blog1;
$r = new XML_RPC_Response($blogs);
return($r);
}
function wp_uploadFile($message) {
universal_debug("wp_uploadFile");
return metaWeblog_newMediaObject($message);
}
function wp_getCategories($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$cats = serendipity_fetchCategories($serendipity['authorid']);
$xml_entries_vals = array();
foreach ((array) $cats as $cat ) {
if ($cat['categoryid']) {
$values = array(
'categoryId' => new XML_RPC_Value($cat['categoryid'], 'string'),
'categoryName' => new XML_RPC_Value($cat['category_name'], 'string'),
'description' => new XML_RPC_Value($cat['category_description'], 'string'),
'htmlUrl' => new XML_RPC_Value(serendipity_categoryURL($cat, 'baseURL'), 'string'),
'rssUrl' => new XML_RPC_Value(serendipity_feedCategoryURL($cat, 'baseURL'), 'string')
);
if (!empty($cat['parentid'])) {
$values['parentId'] = new XML_RPC_Value($cat['parentid'], 'string');
}
else {
$values['parentId'] = new XML_RPC_Value(0, 'string');
}
$xml_entries_vals[] = new XML_RPC_Value($values,'struct');
}
}
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
}
function wp_newCategory($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$val = $message->params[3];
if (is_object($val)) {
$cat = XML_RPC_decode($val);
$category = array();
$category['category_name'] = $cat['name'];
$category['category_description'] = $cat['description'];
if (!empty($cat['parent_id'])) {
$category['parentid'] = $cat['parent_id'];
}
if (serendipity_db_insert('category', $category)) {
$saved = serendipity_fetchCategoryInfo(0, $cat['name']);
$saved_id = $saved['categoryid'];
return new XML_RPC_Response(new XML_RPC_Value($saved_id, 'i4'));
}
}
return new XML_RPC_Response('', 99, 'Error writing category');
}
function wp_getPostFormats( $message ) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
if (count($message->params)>3) {
$val = $message->params[3];
$formats_to_show = $val->getval();
}
/*
$all_formats = new XML_RPC_Value(
array(
'aside' => new XML_RPC_Value("Aside", 'string'),
'audio' => new XML_RPC_Value("Audio", 'string'),
'chat' => new XML_RPC_Value("Chat", 'string'),
'gallery' => new XML_RPC_Value("Gallery", 'string'),
'image' => new XML_RPC_Value("Image", 'string'),
'link' => new XML_RPC_Value("Link", 'string'),
'quote' => new XML_RPC_Value("Quote", 'string'),
'standard' => new XML_RPC_Value("Article", 'string'),
'status' => new XML_RPC_Value("Status", 'string'),
'video' => new XML_RPC_Value("Video", 'string'),
),'struct'
);
return new XML_RPC_Response($all_formats);
*/
$supported_formats = new XML_RPC_Value(
array(
'standard' => new XML_RPC_Value("Article (Serendipity)", 'string'),
),'struct'
);
return new XML_RPC_Response($supported_formats);
}
function wp_getPage($message) {
global $serendipity;
$val = $message->params[2];
$username = $val->getval();
$val = $message->params[3];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$xml_entries_vals = array();
//TODO: For now this returns an empty array in order not to make the client crash. If we want to edit pages, we have to add some more code (to the static pages plugin)
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
}
// wp.getPostStatusList
function wp_getPostStatusList($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$values = new XML_RPC_Value(
array(
'draft' => new XML_RPC_Value("Draft", 'string'),
// 'pending' => new XML_RPC_Value("Pending Review", 'string'),
// 'private' => new XML_RPC_Value("Private", 'string'),
'publish' => new XML_RPC_Value("Published", 'string'),
),'struct'
);
return new XML_RPC_Response($values);
}
function wp_getPageStatusList($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$values = new XML_RPC_Value(
array(
// 'draft' => new XML_RPC_Value("Draft", 'string'),
// 'private' => new XML_RPC_Value("Private", 'string'),
// 'publish' => new XML_RPC_Value("Published", 'string'),
),'struct'
);
return new XML_RPC_Response($values);
}
function wp_getCommentStatusList($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$values = new XML_RPC_Value(
array(
'approved' => new XML_RPC_Value("Approved", 'string'),
'pending' => new XML_RPC_Value("Pending", 'string')
),'struct'
);
return new XML_RPC_Response($values);
}
function wp_getPageTemplates($message) {
global $serendipity;
universal_debug("wp.getPostStatusList");
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$values = new XML_RPC_Value(
array(
// 'Default' => new XML_RPC_Value("default", 'string'),
),'struct'
);
return new XML_RPC_Response($values);
}
function wp_getOptions($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
if (count($message->params)>3) {
$val = $message->params[3];
$filter = XML_RPC_decode($val);
}
$doFilter = !empty($filter) && is_array($filter) && count($filter) >0;
$xml_entries_vals = array();
if (empty($serendipity['xmlrpc_wpfakeversion'])) {
if (!$doFilter || in_array('software_name', $filter))
$xml_entries_vals['software_name'] = wp_getOptions_createOption('software_name', 'Serendipity');
if (!$doFilter || in_array('software_version', $filter))
$xml_entries_vals['software_version'] = wp_getOptions_createOption('software_version', $serendipity['version']);
}
else {
if (!$doFilter || in_array('software_name', $filter))
$xml_entries_vals['software_name'] = wp_getOptions_createOption('software_name', 'WordPress');
if (!$doFilter || in_array('software_version', $filter))
$xml_entries_vals['software_version'] = wp_getOptions_createOption('software_version', $serendipity['xmlrpc_wpfakeversion']);
}
if (!$doFilter || in_array('blog_url', $filter))
$xml_entries_vals['blog_url'] = wp_getOptions_createOption('blog_url', $serendipity['baseURL']);
if (!$doFilter || in_array('blog_title', $filter))
$xml_entries_vals['blog_title'] = wp_getOptions_createOption('blog_title', $serendipity['blogTitle']);
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'struct');
return new XML_RPC_Response($xml_entries);
}
/**
* Private function to create a single wpOption
* @param string $desc
* @param string $value
* @param boolean $readonly default true
*/
function wp_getOptions_createOption($desc, $value, $readonly=true) {
$values = array(
//'tag_id' => new XML_RPC_Value(0, 'int'),
'desc' => new XML_RPC_Value($desc, 'string'),
'readonly' => new XML_RPC_Value($readonly, 'boolean'),
'value' => new XML_RPC_Value($value, 'string'),
);
return new XML_RPC_Value( $values, 'struct');
}
// Get an array of all the pages on a blog.
function wp_getPages($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$xml_entries_vals = array();
//TODO: For now this returns an empty array in order not to make the client crash. If we want to edit pages, we have to add some more code (to the static pages plugin)
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
}
function wp_editPage($message) {
global $serendipity;
// TODO: stub
$return = true;
return new XML_RPC_Value($return, 'boolean');
}
// Get an array of all the pages on a blog. Just the minimum details, lighter than wp.getPages.
function wp_getPageList($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$xml_entries_vals = array();
//TODO: For now this returns an empty array in order not to make the client crash. If we want to edit pages, we have to add some more code (to the static pages plugin)
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
}
function wp_getTags($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$xml_entries_vals = array();
if (class_exists('serendipity_event_freetag')) {
$tags = serendipity_event_freetag::getAllTags();
$rsslink = $serendipity['baseURL'] . 'rss.php?serendipity%5Btag%5D=';
// Find the plugins tag http path setting
$q = "select value from {$serendipity['dbPrefix']}config WHERE name LIKE 'serendipity_plugin_freetag:%/taglink'";
$row = serendipity_db_query($q, true);
if (is_array($row)) $http_url = $row['value'];
else $http_url = $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/tag/'; // copied default from plugin
$tagid = 1;
foreach ($tags AS $tag => $count) {
$values = array(
'tag_id' => new XML_RPC_Value(0, 'string'),
'name' => new XML_RPC_Value($tag, 'string'),
'count' => new XML_RPC_Value($count, 'string'),
'slug' => new XML_RPC_Value($tag, 'string'),
'html_url' => new XML_RPC_Value($http_url . $tag, 'string'),
'rss_url' => new XML_RPC_Value($rsslink . $tag, 'string'),
);
$xml_entries_vals[] = new XML_RPC_Value( $values, 'struct');
$tagid++;
}
}
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
}
function wp_getComment($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$val = $message->params[3];
$comment_id = $val->getval();
$query = "SELECT
co.id,
co.entry_id, co.timestamp, co.title AS ctitle, co.email, co.url, co.ip, co.body, co.type, co.subscribed,
co.author,
e.title,
e.timestamp AS entrytimestamp,
e.id AS entryid,
e.authorid,
co.id AS commentid,
co.parent_id AS parent_id,
co.status
FROM
{$serendipity['dbPrefix']}comments AS co
LEFT JOIN {$serendipity['dbPrefix']}entries AS e ON (co.entry_id = e.id)
WHERE co.id=$comment_id";
$entry = serendipity_db_query($query, true, 'assoc');
if ($entry['commentid']) {
return new XML_RPC_Response(_wp_createSingleCommentResult($entry));
}
else { // not found
return new XML_RPC_Response('', XMLRPC_ERR_CODE_NOTFOUND, 'Invalid comment ID.');
}
}
function wp_getComments($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$val = $message->params[3];
$comment_filter = $val->getval();
$limit = !empty($comment_filter['number'])?$comment_filter['number']:'10'; // defaults to 10
if (!empty($comment_filter['offset'])) $limit = serendipity_db_limit($comment_filter['offset'], $limit);
if (version_compare($serendipity['version'],'1.6.1')>=0)
$order = ' co.timestamp DESC';
else
$order = ' DESC'; // old versions have a bug here producing wrong results
$showAll = $comment_filter['status'] != 'approve';
$type = 'comments_and_trackbacks';
$entries = serendipity_fetchComments($comment_filter['post_id'], $limit, $order, $showAll, $type);
$xml_entries_vals = array();
foreach ((array)$entries as $entry) {
if ($entry['commentid']) {
$xml_entries_vals[] = _wp_createSingleCommentResult($entry);
}
}
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
}
function _wp_createSingleCommentResult($entry) {
if ($entry['commentid']) {
if ($entry['type']=='TRACKBACK') $type = 'trackback';
else if ($entry['type']=='PINGBACK') $type = 'pingback';
else $type = '';
$values = array(
'date_created_gmt' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp'], 1) . 'Z', 'dateTime.iso8601'),
'userid' => new XML_RPC_Value($entry['authorid'], 'string'),
'comment_id' => new XML_RPC_Value($entry['commentid'], 'int'),
'parent' => new XML_RPC_Value($entry['parent_id'], 'int'),
'status' => new XML_RPC_Value($entry['status']=='approved'?'approved':'hold', 'string'),
'content' => new XML_RPC_Value($entry['body'], 'string'),
'link' => new XML_RPC_Value($entry['url'], 'string'),
'permaLink' => new XML_RPC_Value(serendipity_archiveURL($entry['entryid'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])) . '#c' . $entry['commentid'], 'string'),
'post_id' => new XML_RPC_Value($entry['entryid'], 'int'),
'post_title' => new XML_RPC_Value($entry['title'], 'string'),
'author' => new XML_RPC_Value($entry['author'], 'string'),
'author_url' => new XML_RPC_Value($entry['url'], 'string'),
'author_email' => new XML_RPC_Value($entry['email'], 'string'),
'author_ip' => new XML_RPC_Value($entry['ip'], 'string'),
'type' => new XML_RPC_Value($type, 'string'),
);
return new XML_RPC_Value( $values, 'struct');
}
return null;
}
function wp_deleteComment($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$val = $message->params[3];
$comment_id = $val->getval();
if (!empty($comment_id)) {
// We need the entryid, so fetch it:
$sql = serendipity_db_query("SELECT entry_id FROM {$serendipity['dbPrefix']}comments WHERE id = ". $comment_id, true);
$entry_id = $sql['entry_id'];
$result = serendipity_deleteComment($comment_id, $entry_id);
}
else {
$result = false;
}
return new XML_RPC_Response(new XML_RPC_Value($result, 'boolean'));
}
/**
* This will update the comment and approve/moderate it.
* @param unknown_type $message
*/
function wp_editComment($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$val = $message->params[3];
$comment_id = $val->getval();
$val = $message->params[4];
$rpccomment = $val->getval();
if (!empty($comment_id)) {
ob_start();
$asureEntryId = "";
if ($rpccomment['post_id']) {
$asureEntryId = " AND entry_id=" .$rpccomment['post_id'];
}
// We need the entryid, so fetch it:
$commentInfo = serendipity_db_query("SELECT c.entry_id as entry_id, c.body as content, c.email as author_email, c.author as comment_author, c.status as comment_status, c.url as author_url, e.authorid AS entry_authorid
FROM {$serendipity['dbPrefix']}comments c
LEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id)
WHERE c.id = $comment_id"// . $asureEntryId
, true);
// If we fetched a row, process it
if (is_array($commentInfo)) {
$entry_id = $commentInfo['entry_id'];
$entry_authorid = $commentInfo['entry_authorid'];
$comment_status = $commentInfo['comment_status'];
if (!empty($serendipity['xmlrpc_asureauthor']) && $serendipity['xmlrpc_asureauthor']!='default') {
$rpccomment['author'] = $serendipity[$serendipity['xmlrpc_asureauthor']];
}
// Setup new comment to save. Preserve old values, if nothing is given by the client.
$comment = array(
'author' => empty($rpccomment['author']) ? $commentInfo['comment_author']: $rpccomment['author'],
'url' => empty($rpccomment['author_url']) ? $commentInfo['author_url'] : $rpccomment['author_url'],
'email' => empty($rpccomment['author_email']) ? $commentInfo['author_email'] : $rpccomment['author_email'],
'body' => empty($rpccomment['content']) ? $commentInfo['content'] : $rpccomment['content'],
);
$result = universal_updateComment($comment_id, $entry_id, $entry_authorid, $comment);
if ($result) {
$rpc_comment_status = $rpccomment['status'];
$moderate_comment = $rpc_comment_status !== 'approve' && $rpc_comment_status !== 'approved';
$result = !serendipity_approveComment($comment_id, $entry_id, false, $moderate_comment) == $moderate_comment;
if ($result || $rpc_comment_status=='spam') {
$result = true;
$addData['id'] = $entry_id;
$addData['eid'] = $entry_id;
$addData['cid'] = $comment_id;
$event_type = "";
// Sent out plugin hooks, perhaps someone is interested?
if ($rpc_comment_status=='spam') $event_type= $serendipity['xmlrpc_event_spam'];
// dont call hooks, if we changed nothing (except for spam clicks, as Bayes is learning..)
elseif ($rpc_comment_status=='hold' && $comment_status != 'pending') $event_type= $serendipity['xmlrpc_event_pending'];
elseif ($rpc_comment_status=='approve' && $comment_status != 'approved') $event_type= $serendipity['xmlrpc_event_approved'];
if (!empty($event_type) && 'none'!=$event_type) {
serendipity_plugin_api::hook_event('xmlrpc_comment_' . $event_type, $comment, $addData);
}
}
}
} else {
$result = false;
}
$errs = ob_get_contents();
if (!empty($errs)) universal_debug("errors: $errs");
ob_clean();
}
else {
$result = false;
}
return new XML_RPC_Response(new XML_RPC_Value($result, 'boolean'));
}
function wp_newComment($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$val = $message->params[3];
$article_id = $val->getval();
$val = $message->params[4];
$comment = $val->getval();
// Setup defaults, if not given by client. The serendipity vars were setup while authenticating.
if (!empty($serendipity['xmlrpc_asureauthor']) && $serendipity['xmlrpc_asureauthor']!='default') {
$comment['author'] = $serendipity[$serendipity['xmlrpc_asureauthor']];
}
if (empty($comment['author'])) $comment['author'] = $serendipity['serendipityRealname'];
if (empty($comment['author_email'])) $comment['author_email'] = $serendipity['serendipityEmail'];
$commentInfo['comment'] = $comment['content'];
$commentInfo['name'] = $comment['author'];
$commentInfo['url'] = $comment['author_url'];
$commentInfo['email'] = $comment['author_email'];
if (!empty($commentInfo['comment_parent'])) $commentInfo['comment_parent'] = $comment['parent_id'];
universal_debug("Saving new comment: " . print_r($commentInfo, true));
$id = serendipity_insertComment($article_id, $commentInfo);
return new XML_RPC_Response(new XML_RPC_Value($id, 'int'));
}
function wp_getPosts($message) {
global $serendipity;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
$val = $message->params[3];
$filter = $val->getval();
// post_type
// post_status
// number
// offset
// orderby
// order
$numposts = $filter['number'];
$offset = $filter['offset'];
if ($offset > 1) {
$limit = $offset . ',' . $numposts;
} else {
$limit = $numposts;
}
if (!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
}
$entries = serendipity_fetchEntries('', true, $limit, true);
$xml_entries_vals = array();
foreach ((array) $entries as $entry ) {
if ($entry['id']) {
$categories = array();
foreach($entry['categories'] AS $_category_id => $_category) {
$categories[] = new XML_RPC_Value(
array(
'term_id' => new XML_RPC_Value($_category['categoryid'], 'string'),
'name' => new XML_RPC_Value($_category['category_name'], 'string'),
'slug' => new XML_RPC_Value($_category['category_name'], 'string'),
'term_group' => new XML_RPC_Value(0, 'string'),
'term_taxonomy_id' => new XML_RPC_Value($_category['categoryid'], 'string'),
'taxonomy' => new XML_RPC_Value('category', 'string'),
'description' => new XML_RPC_Value($_category['category_description'], 'string'),
'parent' => new XML_RPC_Value($_category['parentid'], 'string'),
'count' => new XML_RPC_Value('1', 'string'),
'filter' => new XML_RPC_Value('raw', 'string'),
),
'struct'
);
}
$xml_entries_vals[] = new XML_RPC_Value(
array(
'post_id' => new XML_RPC_Value($entry['id'], 'string'),
'post_title' => new XML_RPC_Value($entry['title'], 'string'),
'post_date' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp'], false), 'dateTime.iso8601'),
'post_date_gmt' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp'], true), 'dateTime.iso8601'),
'post_modified' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp'], false), 'dateTime.iso8601'),
'post_modified_gmt' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp'], true), 'dateTime.iso8601'),
'post_status' => new XML_RPC_Value('publish', 'string'),
'post_type' => new XML_RPC_Value('post', 'string'),
'post_format' => new XML_RPC_Value('standard', 'string'),
'post_name' => new XML_RPC_Value($entry['title']), // slug
'post_author' => new XML_RPC_Value($entry['authorid'], 'string'),
'post_excerpt' => new XML_RPC_Value($entry['body']),
'post_content' => new XML_RPC_Value($entry['body'] . '' . $entry['extended'], 'string'),
'post_parent' => new XML_RPC_Value(0, 'string'),
'post_mime_type' => new XML_RPC_Value('', 'string'),
'link' => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])), 'string'),
'guid' => new XML_RPC_Value(serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])), 'string'),
'menu_order' => new XML_RPC_Value(0, 'int'),
'comment_status' => new XML_RPC_Value('open', 'string'), // open/closed
'ping_status' => new XML_RPC_Value('open', 'string'), // open/closed
'sticky' => new XML_RPC_Value(0, 'boolean'),
'post_thumbnail' => new XML_RPC_Value(array(), 'array'), //
* @param string $text text to convert */ function universal_autohtml(&$text) { global $serendipity; if (empty($text)) return $text; $text = trim($text); if (!serendipity_db_bool($serendipity['xmlrpc_htmlconvert'])) return $text; // if no p or br formatting is found, add it. if (!preg_match('@
@Usi', $text) && !preg_match('@
@Usi', $text) && !preg_match('@'; $small_p = '
'; $insert = true; $i = count($text); $whiteline = false; if ($text[$i-1] == "\n") { //prevent unnexessary p-tag at the end unset($text[$i-1]); } //main operation: convert \n to big_p and small_p while ($i > 0) { if ($insert) { $i = next_nl_block($i, $text); if ($i == 0) { //prevent replacing of first character break; } if ($whiteline == true) { $text[$i] = '
' . $big_p; } else { $text[$i] = '' . $small_p; } $whiteline = false; $insert = false; } else { if ($text[$i-1] === "\n") { //newline is follower of a newline $whiteline = true; } $insert = true; } } if ($whiteline) { $start_tag = $big_p; } else { $start_tag = $small_p; } return $start_tag . implode($text) . ''; } function next_nl_block($i, $text) { $skipped = false; for ($i--; $i>0; $i-- ) { if (!$skipped){ //see if you skipped over a non-newline (heading to the next block) if (strpos($text[$i], "\n") === false) { $skipped = true; } }else if (strpos($text[$i], "\n") !== false) { break; } } return $i; } try { $server = new XML_RPC_Server($dispatches, 1, ($debug_xmlrpc === 2 ? 1 : 0)); } catch (Exception $e) { $fp = fopen(DEBUG_LOG_XMLRPC, 'a'); fwrite($fp, "[EXCEPTION]" . $e . "\n---------------------------------------\n"); fclose($fp); ob_end_flush(); } if ($debug_xmlrpc === 2) { print_r($GLOBALS['XML_RPC_Server_debuginfo']); } if ($debug_xmlrpc) { $fp = fopen(DEBUG_LOG_XMLRPC, 'a'); fwrite($fp, ob_get_contents() . "\n---------------------------------------\n"); fclose($fp); ob_end_flush(); } /* vim: set sts=4 ts=4 expandtab : */