Well, this as far as I got before I got distracted into other things.
PHP Code:
<?php
/*
* First, we define some PHP functions to expose via
* XML-RPC. Any functions that will be called by a
* XML-RPC client need to take three parameters:
* The first parameter passed is the name of the
* XML-RPC method called, the second is an array
* Containing the parameters sent by the client, and
* The third is any data sent in the app_data
* parameter of the xmlrpc_server_call_method()
* function (see below).
*/
$_debugLog = fopen('xmlrpc.log', 'a');
function newPost($method_name, $params, $app_date) {
$appkey = $params[0];
$blogid = $params[1];
$username = $params[2];
$password = md5($params[3]);
$content = $params[4];
$publish = $params[5];
$sql = "select id from pixelpost_config where admin='" . $username . "' AND password='" . $password . "';";
if (mysql_connect($pixelpost_db_host, $pixelpost_db_user, $pixelpost_db_pass) && mysql_select_db($pixelpost_db_pixelpost)) {
if ($cfgquery = mysql_query($sql)) {
$heading = "";
$body = "";
$image = "";
$category = "";
$alt_headline = "";
$alt_body = "";
$comments = "";
$exif_info = "";
$date = "";
include("includes/functions_exif.php");
$exif_info = serialize_exif($image);
$sql = "INSERT INTO pixelpost_pixelpost (datetime, headline, body, image," .
" category, alt_headline, alt_body, comments, exif_info) " .
" VALUES (" . $date . ", '" . $heading . "', '" . $body . "'," .
" '" . $image . "', '" . $category . "', '" . $alt_headline . "', '" . $alt_body . "', " .
"'" . $comments . "', '" . $exif_info . "');";
if (mysql_query($sql)) {
$sql = "select id from pixelpost_pixelpost where datetime=" . $date . ";";
$cfgquery = mysql_query($sql);
$cfgrow = mysql_fetch_assoc($cfgquery);
$id = $cfgrow['id'];
return "" . $id;
}
} else {
trigger_error("Failed to authenicate");
}
}
return "Not currently implemented";
}
function editPost($method_name, $params, $app_date) {
$appkey = $params[0];
$postid = $params[1];
$username = $params[2];
$password = md5($params[3]);
$content = $params[4];
$publish = $params[5];
return "Not currently implemented";
}
function getUsersBlogs($method_name, $params, $app_date) {
include ("includes/pixelpost.php");
$appkey = $params[0];
$username = $params[1];
$password = md5($params[2]);
$sql = "select id, siteurl, sitetitle from pixelpost_config where admin='" . $username . "' AND password='" . $password . "';";
if (mysql_connect($pixelpost_db_host, $pixelpost_db_user, $pixelpost_db_pass) && mysql_select_db($pixelpost_db_pixelpost)) {
if ($cfgquery = mysql_query($sql)) {
$cfgrow = mysql_fetch_assoc($cfgquery);
$blogid = $cfgrow['id'];
$blogName = $cfgrow['sitetitle'];
$url = $cfgrow['siteurl'];
$response = array (
"url" => $url,
"blogid" => $blogid,
"blogName" => $blogName
);
return $response;
} else {
trigger_error("xmlrpc: Query failed");
}
}
trigger_error("xmlrpc: Failed to connect to database");
}
function getUserInfo($method_name, $params, $app_date) {
include ("includes/pixelpost.php");
$appkey = $params[0];
$username = $params[1];
$password = md5($params[2]);
$sql = "select id, siteurl, email from " . $pixelpost_db_prefix . "config where admin='" . $username . "' AND password='" . $password . "';";
if (mysql_connect($pixelpost_db_host, $pixelpost_db_user, $pixelpost_db_pass) && mysql_select_db($pixelpost_db_pixelpost)) {
if ($cfgquery = mysql_query($sql)) {
$cfgrow = mysql_fetch_assoc($cfgquery);
$userid = $cfgrow['id'];
$email = $cfgrow['email'];
$url = $cfgrow['siteurl'];
$response = array (
"url" => $url,
"userid" => $userid,
"email" => $email
);
return $response;
} else {
trigger_error("xmlrpc : Query failed: " . $sql . "\n");
}
} else {
trigger_error("xmlrpc : Could not connect to database");
}
}
function getTemplate($method_name, $params, $app_date) {
$appkey = $params[0];
$blogid = $params[1];
$username = $params[2];
$password = $params[3];
$templateType = $params[4];
return "Not currently implemented";
}
function setTemplate($method_name, $params, $app_date) {
$appkey = $params[0];
$blogid = $params[1];
$username = $params[2];
$password = $params[3];
$template = $params[4];
$templateType = $params[5];
return "Not currently implemented";
}
/*
* This creates a server and sets a handle for the
* server in the variable $xmlrpc_server
*/
$xmlrpc_server = xmlrpc_server_create();
/*
* xmlrpc_server_register_method() registers a PHP
* function as an XML-RPC method. It takes three
* parameters:
* The first is the handle of a server created with
* xmlrpc_server_create(), the second is the name to
* register the server under (this is what needs to
* be in the <methodName> of a request for this
* method), and the third is the name of the PHP
* function to register.
*/
xmlrpc_server_register_method($xmlrpc_server, "greeting", "greeting_func");
xmlrpc_server_register_method($xmlrpc_server, "uptime", "uptime_func");
xmlrpc_server_register_method($xmlrpc_server, "blogger.newPost", "newPost");
xmlrpc_server_register_method($xmlrpc_server, "blogger.editPost", "editPost");
xmlrpc_server_register_method($xmlrpc_server, "blogger.getUsersBlogs", "getUsersBlogs");
xmlrpc_server_register_method($xmlrpc_server, "blogger.getUserInfo", "getUserInfo");
xmlrpc_server_register_method($xmlrpc_server, "blogger.getTemplate", "getTemplate");
xmlrpc_server_register_method($xmlrpc_server, "blogger.setTemplate", "setTemplate");
/*
* When an XML-RPC request is sent to this script, it
* can be found in the raw post data.
*/
fwrite($_debugLog, "RAW_DATA:");
$request_xml = $HTTP_RAW_POST_DATA;
fwrite($_debugLog, $request_xml . "\n");
/*
* The xmlrpc_server_call_method() sends a request to
* the server and returns the response XML. In this case,
* it sends the raw post data we got before. It requires
* 3 arguments:
* The first is the handle of a server created with
* xmlrpc_server_create(), the second is a string containing
* an XML-RPC request, and the third is for application data.
* Whatever is passed into the third parameter of this function
* is passed as the third paramater of the PHP function that the
* request is asking for.
*/
$response = xmlrpc_server_call_method($xmlrpc_server, $request_xml, '');
$response = str_replace("iso-8859-1", "UTF-8", $response);
// Now we print the response for the client to read.
//$response = str_replace( "<string>", "", $response);
//$response = str_replace( "</string>\n", "", $response);
//$response = str_replace( "<int>", "", $response);
//$response = str_replace( "</int>\n", "", $response);
fwrite($_debugLog, "RESPONSE: " . $response . "\n");
print $response;
/*
* This method frees the resources for the server specified
* It takes one argument, a handle of a server created with
* xmlrpc_server_create().
*/
xmlrpc_server_destroy($xmlrpc_server);
?>