Update of /cvsroot/php-blog/jBlog
In directory sc8-pr-cvs1:/tmp/cvs-serv17996
Modified Files:
jBlog_functions.inc.php
Added Files:
jBlog-xmlrpc.php
Log Message:
metaWebLog/Blogger/MT XML-RPC support (kung-log works, mostly).
--- NEW FILE: jBlog-xmlrpc.php ---
<?php
session_start();
require_once 'jBlog_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'),
'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'),
'mt.supportedTextFilters' =>
array('function' => 'mt_supportedTextFilters'));
function blogger_getUsersBlogs($message)
{
global $jBlog;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if(!jBlog_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
$blog1 = new XML_RPC_Value(
array('url' => new XML_RPC_Value($jBlog['baseURL']),
'blogid' => new XML_RPC_Value('1'),
'blogName' => new XML_RPC_Value($jBlog['blogTitle'])),
'struct');
$blogs = new XML_RPC_Value( array($blog1), 'array');
$r = new XML_RPC_Response($blogs);
return($r);
}
function blogger_getUserInfo($message)
{
global $jBlog;
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if(!jBlog_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
$userdata = new XML_RPC_Value(
array('nickname' => new XML_RPC_Value($jBlog['user']),
'userid' => new XML_RPC_Value($jBlog['jBlogEmail']),
'url' => new XML_RPC_Value($jBlog['baseURL']),
'email' => new XML_RPC_Value($jBlog['jBlogEmail']),
'lastname' => new XML_RPC_Value(''),
'firstname' => new XML_RPC_Value('')),
'struct');
$r = new XML_RPC_Response($userdata);
return($r);
}
function mt_getCategoryList($message)
{
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if(!jBlog_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
return new XML_RPC_Response( new XML_RPC_Value(array(), 'array'));
// return new XML_RPC_Response( new XML_RPC_Value(array(new XML_RPC_Value(array( 'categoryId' => new XML_RPC_Value('1'), 'categoryName' => new XML_RPC_Value('default')), 'struct')), 'array'));
}
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(!jBlog_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
$entries = jBlog_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'),
'dateCreated' => new XML_RPC_Value(XML_RPC_iso8601_encode($entry['timestamp']), 'dateTime.iso8601'),
'userid' => new XML_RPC_Value($entry['authorid'], 'string'),
'title' => new XML_RPC_Value($entry['title'], '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(!jBlog_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_newPost($message)
{
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if(!jBlog_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;
$id = jBlog_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(!jBlog_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['id'] = $postid;
$id = jBlog_updertEntry($entry);
return new XML_RPC_Response( new XML_RPC_Value($id));
}
function metaWeblog_getPost($message)
{
global $jBlog;
$val = $message->params[0];
$postid = $val->getval();
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if(!jBlog_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
$entry = jBlog_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($jBlog['baseURL']."/archives/e_$postid.html", 'string'),
'link' => new XML_RPC_Value($jBlog['baseURL']."/archives/e_$postid.html", 'string'));
$entry = new XML_RPC_Value($tmp, 'struct');
return new XML_RPC_Response($entry);
}
function metaWeblog_setPostCategories($message)
{
$val = $message->params[1];
$username = $val->getval();
$val = $message->params[2];
$password = $val->getval();
if(!jBlog_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
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(!jBlog_authenticate_author($username, $password)) {
return new XML_RPC_Response('', 4, "Authentication Failed");
}
return new XML_RPC_Response( new XML_RPC_Value(array(), 'array'));
}
$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);
?>
Index: jBlog_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/jBlog/jBlog_functions.inc.php,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- jBlog_functions.inc.php 10 Mar 2003 03:54:47 -0000 1.41
+++ jBlog_functions.inc.php 10 Mar 2003 04:02:36 -0000 1.42
@@ -844,7 +844,7 @@
jBlog_purgeEntry($entry['id'], $entry['timestamp']);
- return mysql_error();
+ return $entry['id'];
}
/**
|