Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1:/tmp/cvs-serv2461
Added Files:
serendipity_xmlrpc.php
Log Message:
this is not an .inc.php but a .php
--- NEW FILE: serendipity_xmlrpc.php ---
<?php
session_start();
require_once 'serendipity_config.inc.php';
require_once 'bundled-libs/XML/RPC/Server.php';
$dispatches = array('blogger.getUsersBlogs' =>
array('function' => 'blogger_getUsersBlogs'),
'blogger.getUserInfo' =>
array('function' => 'blogger_getUserInfo'),
'blogger.newPost' =>
array('function' => 'blogger_newPost'),
'blogger.editPost' =>
array('function' => 'blogger_editPost'),
'metaWeblog.newPost' =>
array('function' => 'metaWeblog_newPost'),
'metaWeblog.editPost' =>
array('function' => 'metaWeblog_editPost'),
'metaWeblog.getPost' =>
array('function' => 'metaWeblog_getPost'),
'mt.getRecentPostTitles' =>
array('function' => 'mt_getRecentPostTitles'),
'mt.getCategoryList' =>
array('function' => 'mt_getCategoryList'),
'metaWeblog.setPostCategories' =>
array('function' => 'metaWeblog_setPostCategories'),
'metaWeblog.getPostCategories' =>
array('function' => 'metaWeblog_getPostCategories'),
'metaWeblog.newMediaObject' =>
array('function' => 'metaWeblog_newMediaObject'),
'mt.supportedTextFilters' =>
array('function' => 'mt_supportedTextFilters'));
function blogger_getUsersBlogs($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('', 4, "Authentication Failed");
}
$blog1 = new XML_RPC_Value(
array('url' => new XML_RPC_Value($serendipity['baseURL']),
'blogid' => new XML_RPC_Value('1'),
'blogName' => new XML_RPC_Value($serendipity['blogTitle'])),
'struct');
$blogs = new XML_RPC_Value( array($blog1), 'array');
$r = new XML_RPC_Response($blogs);
return($r);
}
function blogger_getUserInfo($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('', 4, "Authentication Failed");
}
$userdata = new XML_RPC_Value(
array('nickname' => new XML_RPC_Value($serendipity['serendipityUser']),
'userid' => new XML_RPC_Value($serendipity['authorid'], 'string'),
'url' => new XML_RPC_Value($serendipity['baseURL']),
'email' => new XML_RPC_Value($serendipity['serendipityEmail']),
'lastname' => new XML_RPC_Value(''),
'firstname' => new XML_RPC_Value('')),
'struct');
$r = new XML_RPC_Response($userdata);
return($r);
}
function mt_getCategoryList($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('', 4, "Authentication Failed");
}
$cats = serendipity_fetchCategories($serendipity['authorid']);
$xml_entries_vals = array();
foreach ( $cats as $cat ) {
$xml_entries_vals[] = new XML_RPC_Value(
array(
'categoryId' => new XML_RPC_Value($cat['categoryid'], 'string'),
'categoryName' => new XML_RPC_Value($cat['category_name'], 'string')), 'struct');
}
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
}
function mt_getRecentPostTitles($message)
{
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
$val = $message->params[3];
$numposts = $val->getval();
if(!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
$entries = serendipity_fetchEntries('', false, $numposts);
$xml_entries_vals = array();
foreach ( $entries as $entry ) {
$xml_entries_vals[] = new XML_RPC_Value(
array(
'postid' => new XML_RPC_Value($entry['id'], 'string'),
'title' => new XML_RPC_Value($entry['title'], 'string'),
'userid' => new XML_RPC_Value($entry['authorid'], 'string'),
'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
'postid' => new XML_RPC_Value($entry['id'], 'string')), 'struct');
}
$xml_entries = new XML_RPC_Value($xml_entries_vals, 'array');
return new XML_RPC_Response($xml_entries);
}
function mt_supportedTextFilters($message)
{
$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('', 4, "Authentication Failed");
}
return new XML_RPC_Response( new XML_RPC_Value(array(), 'array'));
}
function blogger_newPost($message)
{
$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('', 4, "Authentication Failed");
}
$val = $message->params[4];
$entry['body'] = $val->getval();
$id = serendipity_updertEntry($entry);
return new XML_RPC_Response( new XML_RPC_Value($id, 'string'));
}
function blogger_editPost($message)
{
$val = $message->params[1];
$entry['id'] = $val->getval();
$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('', 4, "Authentication Failed");
}
$val = $message->params[4];
$entry['body'] = $val->getval();
$entry['user'] = $username;
$id = serendipity_updateEntry($entry);
return new XML_RPC_Response( new XML_RPC_Value($id, 'string'));
}
function metaWeblog_newPost($message)
{
$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('', 4, "Authentication Failed");
}
$val = $message->params[3];
$post_array = $val->getval();
$entry['title'] = $post_array['title'];
$entry['body'] = $post_array['description'];
$entry['extended'] = $post_array['mt_text_more'];
$id = serendipity_updertEntry($entry);
return new XML_RPC_Response( new XML_RPC_Value($id, 'string'));
}
function metaWeblog_editPost($message)
{
$val = $message->params[0];
$postid = $val->getval();
$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('', 4, "Authentication Failed");
}
$val = $message->params[3];
$post_array = $val->getval();
$entry['title'] = $post_array['title'];
$entry['body'] = $post_array['description'];
$entry['extended'] = $post_array['mt_text_more'];
$entry['user'] = $username;
$entry['authorid'] = $serendipity['authorid'];
$entry['id'] = $postid;
$id = serendipity_updateEntry($entry);
return new XML_RPC_Response( new XML_RPC_Value($id));
}
function metaWeblog_getPost($message)
{
global $serendipity;
$val = $message->params[0];
$postid = $val->getval();
$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('', 4, "Authentication Failed");
}
$entry = serendipity_fetchEntry("id", $postid);
$tmp = array(
'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
'postid' => new XML_RPC_Value($postid, 'string'),
'userid' => new XML_RPC_Value($entry['authorid'], 'string'),
'description' => new XML_RPC_Value($entry['body'], 'string'),
'mt_text_more'=> new XML_RPC_Value($entry['extended'], 'string'),
'mt_excerpt'=> new XML_RPC_Value('', 'string'),
'mt_allow_comments' => new XML_RPC_Value(1, 'boolean'),
'mt_allow_pings' => new XML_RPC_Value(1, 'boolean'),
'mt_convert_breaks' => new XML_RPC_Value(0, 'boolean'),
'title' => new XML_RPC_Value($entry['title'],'string'),
'permalink' => new XML_RPC_Value($serendipity['baseURL']."/archives/e_$postid.html", 'string'),
'link' => new XML_RPC_Value($serendipity['baseURL']."/archives/e_$postid.html", 'string'));
$entry = new XML_RPC_Value($tmp, 'struct');
return new XML_RPC_Response($entry);
}
function metaWeblog_setPostCategories($message)
{
global $serendipity;
$val = $message->params[0];
$postid = $val->getval();
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
$val = $message->params[3];
$categories = $val->getval();
$category_ids = array();
foreach ($categories as $cat) {
$val = $cat['categoryId'];
$category_ids[] = $val->getval();
}
if(!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
serendipity_updateEntryCategories($postid, $category_ids);
return new XML_RPC_Response( new XML_RPC_Value(1, 'boolean'));
}
function metaWeblog_getPostCategories($message)
{
$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('', 4, "Authentication Failed");
}
return new XML_RPC_Response( new XML_RPC_Value(array(), 'array'));
}
function metaWeblog_newMediaObject($message)
{
global $serendipity;
$val = $message->params[0];
$postid = $val->getval();
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
$val = $message->params[3];
$struct = $val->getval();
if(!serendipity_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
$fp = fopen($serendipity["serendipityPath"].$serendipity['uploadPath'].$struct['name'], "w");
fwrite($fp, $struct['bits']);
fclose($fp);
$path = $serendipity["baseURL"].$serendipity['uploadPath'].$struct['name'];
return new XML_RPC_Response( new XML_RPC_Value(array('url' => new XML_RPC_Value($path, 'string')), 'struct'));
}
$fp = fopen("/tmp/kung-log", "a");
fwrite($fp, $HTTP_RAW_POST_DATA);
ob_start();
$server = new XML_RPC_Server($dispatches,1);
fwrite($fp, ob_get_contents());
fclose($fp);
?>
|