- Patch #26391 by chx: replaced the old XML-RPC library with a smaller/better/working one.
parent
73010a5215
commit
ed3bf725bb
|
@ -11,6 +11,7 @@ Drupal x.x.x, xxxx-xx-xx (development version)
|
|||
* reworked the 'request new password' functionality.
|
||||
* reworked the node edit form.
|
||||
* added support for auto-complete forms (AJAX).
|
||||
* reorganized some settings pages.
|
||||
- profiles:
|
||||
* added a block to display author information along with posts.
|
||||
* added support for private profile fields.
|
||||
|
|
1435
includes/xmlrpc.inc
1435
includes/xmlrpc.inc
File diff suppressed because it is too large
Load Diff
|
@ -1,301 +1,285 @@
|
|||
<?php
|
||||
// by Edd Dumbill (C) 1999-2001
|
||||
// <edd@usefulinc.com>
|
||||
// $Id$
|
||||
|
||||
// Copyright (c) 1999,2000,2001 Edd Dumbill.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// * Neither the name of the "XML-RPC for PHP" nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// XML RPC Server class
|
||||
// requires: xmlrpc.inc
|
||||
|
||||
// listMethods: either a string, or nothing
|
||||
$_xmlrpcs_listMethods_sig=array(array($xmlrpcArray, $xmlrpcString),
|
||||
array($xmlrpcArray));
|
||||
$_xmlrpcs_listMethods_doc='This method lists all the methods that the XML-RPC server knows how to dispatch';
|
||||
function _xmlrpcs_listMethods($server, $m) {
|
||||
global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
|
||||
$v=new xmlrpcval();
|
||||
$dmap=$server->dmap;
|
||||
$outAr=array();
|
||||
for(reset($dmap); list($key, $val)=each($dmap); ) {
|
||||
$outAr[]=new xmlrpcval($key, "string");
|
||||
function xmlrpc_server($callbacks) {
|
||||
$xmlrpc_server = new stdClass();
|
||||
$defaults = array(
|
||||
'system.multicall' => 'xmlrpc_server_multicall',
|
||||
array(
|
||||
'system.methodSignature',
|
||||
'xmlrpc_server_method_signature',
|
||||
array('array', 'string'),
|
||||
'Returns an array describing the return type and required parameters of a method'
|
||||
),
|
||||
array(
|
||||
'system.getCapabilities',
|
||||
'xmlrpc_server_get_capabilities',
|
||||
array('struct'),
|
||||
'Returns a struct describing the XML-RPC specifications supported by this server'
|
||||
),
|
||||
array(
|
||||
'system.listMethods',
|
||||
'xmlrpc_server_list_methods',
|
||||
array('array'),
|
||||
'Returns an array of available methods on this server'),
|
||||
array(
|
||||
'system.methodHelp',
|
||||
'xmlrpc_server_method_help',
|
||||
array('string', 'string'),
|
||||
'Returns a documentation string for the specified method')
|
||||
);
|
||||
// the order matters in the next line. which is the best?
|
||||
foreach (array_merge($defaults, (array)$callbacks) as $key => $callback) {
|
||||
// we could check for is_array($callback)
|
||||
if (is_int($key)) {
|
||||
$method = $callback[0];
|
||||
$xmlrpc_server->callbacks[$method] = $callback[1];
|
||||
$xmlrpc_server->signatures[$method] = $callback[2];
|
||||
$xmlrpc_server->help[$method] = $callback[3];
|
||||
}
|
||||
else {
|
||||
$xmlrpc_server->callbacks[$key] = $callback;
|
||||
$xmlrpc_server->signatures[$key] = '';
|
||||
$xmlrpc_server->help[$key] = '';
|
||||
}
|
||||
}
|
||||
$dmap=$_xmlrpcs_dmap;
|
||||
for(reset($dmap); list($key, $val)=each($dmap); ) {
|
||||
$outAr[]=new xmlrpcval($key, "string");
|
||||
|
||||
$data = file_get_contents('php://input');
|
||||
if (!data) {
|
||||
die('XML-RPC server accepts POST requests only.');
|
||||
}
|
||||
$v->addArray($outAr);
|
||||
return new xmlrpcresp($v);
|
||||
$xmlrpc_server->message = xmlrpc_message($data);
|
||||
if (!xmlrpc_message_parse($xmlrpc_server->message)) {
|
||||
xmlrpc_server_error(-32700, t('parse error. not well formed'));
|
||||
}
|
||||
if ($xmlrpc_server->message->messagetype != 'methodCall') {
|
||||
xmlrpc_server_error(-32600, t('server error. invalid xml-rpc. not conforming to spec. Request must be a method_call'));
|
||||
}
|
||||
$result = xmlrpc_server_call($xmlrpc_server, $xmlrpc_server->message->methodname, $xmlrpc_server->message->params);
|
||||
// Is the result an error?
|
||||
if ($result->is_error) {
|
||||
xmlrpc_server_error($result);
|
||||
}
|
||||
// Encode the result
|
||||
$r = xmlrpc_value($result);
|
||||
// Create the XML
|
||||
$xml = '
|
||||
<methodResponse>
|
||||
<params>
|
||||
<param>
|
||||
<value>'.
|
||||
xmlrpc_value_get_xml($r)
|
||||
.'</value>
|
||||
</param>
|
||||
</params>
|
||||
</methodResponse>
|
||||
|
||||
';
|
||||
// Send it
|
||||
xmlrpc_server_output($xml);
|
||||
}
|
||||
|
||||
$_xmlrpcs_methodSignature_sig=array(array($xmlrpcArray, $xmlrpcString));
|
||||
$_xmlrpcs_methodSignature_doc='Returns an array of known signatures (an array of arrays) for the method name passed. If no signatures are known, returns a none-array (test for type != array to detect missing signature)';
|
||||
function _xmlrpcs_methodSignature($server, $m) {
|
||||
global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
|
||||
|
||||
$methName=$m->getParam(0);
|
||||
$methName=$methName->scalarval();
|
||||
if (ereg("^system\.", $methName)) {
|
||||
$dmap=$_xmlrpcs_dmap; $sysCall=1;
|
||||
} else {
|
||||
$dmap=$server->dmap; $sysCall=0;
|
||||
function xmlrpc_server_error($error, $message = false) {
|
||||
// Accepts either an error object or an error code and message
|
||||
if ($message && !is_object($error)) {
|
||||
$error = xmlrpc_error($error, $message);
|
||||
}
|
||||
// print "<!-- ${methName} -->\n";
|
||||
if (isset($dmap[$methName])) {
|
||||
if ($dmap[$methName]["signature"]) {
|
||||
$sigs=array();
|
||||
$thesigs=$dmap[$methName]["signature"];
|
||||
for($i=0; $i<sizeof($thesigs); $i++) {
|
||||
$cursig=array();
|
||||
$inSig=$thesigs[$i];
|
||||
for($j=0; $j<sizeof($inSig); $j++) {
|
||||
$cursig[]=new xmlrpcval($inSig[$j], "string");
|
||||
}
|
||||
$sigs[]=new xmlrpcval($cursig, "array");
|
||||
}
|
||||
$r=new xmlrpcresp(new xmlrpcval($sigs, "array"));
|
||||
xmlrpc_server_output(xmlrpc_error_get_xml($error));
|
||||
}
|
||||
|
||||
function xmlrpc_server_output($xml) {
|
||||
$xml = '<?xml version="1.0"?>'."\n". $xml;
|
||||
header('Connection: close');
|
||||
header('Content-Length: '. strlen($xml));
|
||||
header('Content-Type: text/xml');
|
||||
header('Date: '.date('r'));
|
||||
echo $xml;
|
||||
exit;
|
||||
}
|
||||
|
||||
function xmlrpc_server_list_methods() {
|
||||
$xmlrpc_server = xmlrpc_server_get();
|
||||
return array_keys($xmlrpc_server->callbacks);
|
||||
}
|
||||
|
||||
function xmlrpc_server_set($xmlrpc_server = NULL) {
|
||||
static $server;
|
||||
if (!isset($server)) {
|
||||
$server = $xmlrpc_server;
|
||||
}
|
||||
return $server;
|
||||
}
|
||||
|
||||
function xmlrpc_server_get() {
|
||||
return xmlrpc_server_set();
|
||||
}
|
||||
|
||||
function xmlrpc_server_multicall($xmlrpc_server, $methodcalls) {
|
||||
// See http://www.xmlrpc.com/discuss/msgReader$1208
|
||||
$return = array();
|
||||
foreach ($methodcalls as $call) {
|
||||
$method = $call['methodName'];
|
||||
$params = $call['params'];
|
||||
if ($method == 'system.multicall') {
|
||||
$result = xmlrpc_error(-32600, t('Recursive calls to system.multicall are forbidden'));
|
||||
} else {
|
||||
$r=new xmlrpcresp(new xmlrpcval("undef", "string"));
|
||||
$result = xmlrpc_server_call($xmlrpc_server, $method, $params);
|
||||
}
|
||||
} else {
|
||||
$r=new xmlrpcresp(0,
|
||||
$xmlrpcerr["introspect_unknown"],
|
||||
$xmlrpcstr["introspect_unknown"]);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
$_xmlrpcs_methodHelp_sig=array(array($xmlrpcString, $xmlrpcString));
|
||||
$_xmlrpcs_methodHelp_doc='Returns help text if defined for the method passed, otherwise returns an empty string';
|
||||
function _xmlrpcs_methodHelp($server, $m) {
|
||||
global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
|
||||
|
||||
$methName=$m->getParam(0);
|
||||
$methName=$methName->scalarval();
|
||||
if (ereg("^system\.", $methName)) {
|
||||
$dmap=$_xmlrpcs_dmap; $sysCall=1;
|
||||
} else {
|
||||
$dmap=$server->dmap; $sysCall=0;
|
||||
}
|
||||
// print "<!-- ${methName} -->\n";
|
||||
if (isset($dmap[$methName])) {
|
||||
if ($dmap[$methName]["docstring"]) {
|
||||
$r=new xmlrpcresp(new xmlrpcval($dmap[$methName]["docstring"]),
|
||||
"string");
|
||||
if ($result->is_error) {
|
||||
$return[] = array(
|
||||
'faultCode' => $result->code,
|
||||
'faultString' => $result->message
|
||||
);
|
||||
} else {
|
||||
$r=new xmlrpcresp(new xmlrpcval("", "string"));
|
||||
}
|
||||
} else {
|
||||
$r=new xmlrpcresp(0,
|
||||
$xmlrpcerr["introspect_unknown"],
|
||||
$xmlrpcstr["introspect_unknown"]);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
$_xmlrpcs_dmap=array(
|
||||
"system.listMethods" =>
|
||||
array("function" => "_xmlrpcs_listMethods",
|
||||
"signature" => $_xmlrpcs_listMethods_sig,
|
||||
"docstring" => $_xmlrpcs_listMethods_doc),
|
||||
"system.methodHelp" =>
|
||||
array("function" => "_xmlrpcs_methodHelp",
|
||||
"signature" => $_xmlrpcs_methodHelp_sig,
|
||||
"docstring" => $_xmlrpcs_methodHelp_doc),
|
||||
"system.methodSignature" =>
|
||||
array("function" => "_xmlrpcs_methodSignature",
|
||||
"signature" => $_xmlrpcs_methodSignature_sig,
|
||||
"docstring" => $_xmlrpcs_methodSignature_doc)
|
||||
);
|
||||
|
||||
$_xmlrpc_debuginfo="";
|
||||
function xmlrpc_debugmsg($m) {
|
||||
global $_xmlrpc_debuginfo;
|
||||
$_xmlrpc_debuginfo=$_xmlrpc_debuginfo . $m . "\n";
|
||||
}
|
||||
|
||||
class xmlrpc_server {
|
||||
var $dmap=array();
|
||||
|
||||
function xmlrpc_server($dispMap, $serviceNow=1) {
|
||||
// dispMap is a despatch array of methods
|
||||
// mapped to function names and signatures
|
||||
// if a method
|
||||
// doesn't appear in the map then an unknown
|
||||
// method error is generated
|
||||
$this->dmap=$dispMap;
|
||||
if ($serviceNow) {
|
||||
$this->service();
|
||||
$return[] = array($result);
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function serializeDebug() {
|
||||
global $_xmlrpc_debuginfo;
|
||||
if ($_xmlrpc_debuginfo!="")
|
||||
return "<!-- DEBUG INFO:\n\n" .
|
||||
$_xmlrpc_debuginfo . "\n-->\n";
|
||||
else
|
||||
return "";
|
||||
|
||||
function xmlrpc_server_get_capabilities() {
|
||||
return array(
|
||||
'xmlrpc' => array(
|
||||
'specUrl' => 'http://www.xmlrpc.com/spec',
|
||||
'specVersion' => 1
|
||||
),
|
||||
'faults_interop' => array(
|
||||
'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
|
||||
'specVersion' => 20010516
|
||||
),
|
||||
'system.multicall' => array(
|
||||
'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
|
||||
'specVersion' => 1
|
||||
),
|
||||
'introspection' => array(
|
||||
'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',
|
||||
'specVersion' => 1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function xmlrpc_server_call($xmlrpc_server, $methodname, $args) {
|
||||
// Make sure it's in an array
|
||||
if ($args && !is_array($args)) {
|
||||
$args = array($args);
|
||||
}
|
||||
|
||||
function service() {
|
||||
$r=$this->parseRequest();
|
||||
$payload="<?xml version=\"1.0\"?>\n" .
|
||||
$this->serializeDebug() .
|
||||
$r->serialize();
|
||||
Header("Content-Type: text/xml\r\nContent-Length: " .
|
||||
strlen($payload));
|
||||
print $payload;
|
||||
// Over-rides default call method, adds signature check
|
||||
if (!isset($xmlrpc_server->callbacks[$methodname])) {
|
||||
return xmlrpc_error(-32601, t('server error. requested method %methodname not specified.',array("%methodname" => $xmlrpc_server->message->methodname)));
|
||||
}
|
||||
$method = $xmlrpc_server->callbacks[$methodname];
|
||||
$signature = $xmlrpc_server->signatures[$methodname];
|
||||
|
||||
function verifySignature($in, $sig) {
|
||||
for($i=0; $i<sizeof($sig); $i++) {
|
||||
// check each possible signature in turn
|
||||
$cursig=$sig[$i];
|
||||
if (sizeof($cursig)==$in->getNumParams()+1) {
|
||||
$itsOK=1;
|
||||
for($n=0; $n<$in->getNumParams(); $n++) {
|
||||
$p=$in->getParam($n);
|
||||
// print "<!-- $p -->\n";
|
||||
if ($p->kindOf() == "scalar") {
|
||||
$pt=$p->scalartyp();
|
||||
} else {
|
||||
$pt=$p->kindOf();
|
||||
$ok = true;
|
||||
if (is_array($signature)) {
|
||||
$return_type = array_shift($signature);
|
||||
// Check the number of arguments
|
||||
if (count($args) != count($signature)) {
|
||||
return xmlrpc_error(-32602, t('server error. wrong number of method parameters'));
|
||||
}
|
||||
// Check the argument types
|
||||
foreach ($signature as $key => $type) {
|
||||
$arg = $args[$key];
|
||||
switch ($type) {
|
||||
case 'int':
|
||||
case 'i4':
|
||||
if (is_array($arg) || !is_int($arg)) {
|
||||
$ok = false;
|
||||
}
|
||||
// $n+1 as first type of sig is return type
|
||||
if ($pt != $cursig[$n+1]) {
|
||||
$itsOK=0;
|
||||
$pno=$n+1; $wanted=$cursig[$n+1]; $got=$pt;
|
||||
break;
|
||||
break;
|
||||
case 'base64':
|
||||
case 'string':
|
||||
if (!is_string($arg)) {
|
||||
$ok = false;
|
||||
}
|
||||
}
|
||||
if ($itsOK)
|
||||
return array(1);
|
||||
break;
|
||||
case 'boolean':
|
||||
if ($arg !== false && $arg !== true) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'float':
|
||||
case 'double':
|
||||
if (!is_float($arg)) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'date':
|
||||
case 'dateTime.iso8601':
|
||||
if (!$arg->is_date) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!$ok) {
|
||||
return xmlrpc_error(-32602, t('server error. invalid method parameters'));
|
||||
}
|
||||
}
|
||||
return array(0, "Wanted ${wanted}, got ${got} at param ${pno})");
|
||||
}
|
||||
// It passed the test - run the "real" method call
|
||||
if (!isset($xmlrpc_server->callbacks[$methodname])) {
|
||||
return xmlrpc_error(-32601, t('server error. requested method %methodname does not exist.',array("%methodname" => $methodname)));
|
||||
}
|
||||
|
||||
function parseRequest($data="") {
|
||||
global $_xh;
|
||||
global $xmlrpcerr, $xmlrpcstr, $xmlrpcerrxml, $_xmlrpcs_dmap;
|
||||
|
||||
|
||||
|
||||
if ($data=="") {
|
||||
$data=$GLOBALS["HTTP_RAW_POST_DATA"];
|
||||
$method = $xmlrpc_server->callbacks[$methodname];
|
||||
// Perform the callback and send the response
|
||||
/*
|
||||
if (count($args) == 1) {
|
||||
// If only one paramater just send that instead of the whole array
|
||||
$args = $args[0];
|
||||
}
|
||||
$parser = drupal_xml_parser_create($data);
|
||||
|
||||
$_xh[$parser]=array();
|
||||
$_xh[$parser]['st']="";
|
||||
$_xh[$parser]['cm']=0;
|
||||
$_xh[$parser]['isf']=0;
|
||||
$_xh[$parser]['params']=array();
|
||||
$_xh[$parser]['method']="";
|
||||
|
||||
// decompose incoming XML into request structure
|
||||
|
||||
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
|
||||
xml_set_element_handler($parser, "xmlrpc_se", "xmlrpc_ee");
|
||||
xml_set_character_data_handler($parser, "xmlrpc_cd");
|
||||
xml_set_default_handler($parser, "xmlrpc_dh");
|
||||
if (!xml_parse($parser, $data, 1)) {
|
||||
// return XML error as a faultCode
|
||||
$r=new xmlrpcresp(0,
|
||||
$xmlrpcerrxml+xml_get_error_code($parser),
|
||||
sprintf("XML error: %s at line %d",
|
||||
xml_error_string(xml_get_error_code($parser)),
|
||||
xml_get_current_line_number($parser)));
|
||||
xml_parser_free($parser);
|
||||
} else {
|
||||
xml_parser_free($parser);
|
||||
$m=new xmlrpcmsg($_xh[$parser]['method']);
|
||||
// now add parameters in
|
||||
$plist="";
|
||||
for($i=0; $i<sizeof($_xh[$parser]['params']); $i++) {
|
||||
//print "<!-- " . $_xh[$parser]['params'][$i]. "-->\n";
|
||||
$plist.="$i - " . $_xh[$parser]['params'][$i]. " \n";
|
||||
$m->addParam(eval('return '. $_xh[$parser]['params'][$i] .';'));
|
||||
}
|
||||
// uncomment this to really see what the server's getting!
|
||||
// xmlrpc_debugmsg($plist);
|
||||
// now to deal with the method
|
||||
$methName=$_xh[$parser]['method'];
|
||||
if (ereg("^system\.", $methName)) {
|
||||
$dmap=$_xmlrpcs_dmap; $sysCall=1;
|
||||
} else {
|
||||
$dmap=$this->dmap; $sysCall=0;
|
||||
}
|
||||
if (isset($dmap[$methName]['function'])) {
|
||||
// dispatch if exists
|
||||
if (isset($dmap[$methName]['signature'])) {
|
||||
$sr=$this->verifySignature($m,
|
||||
$dmap[$methName]['signature'] );
|
||||
}
|
||||
if ( (!isset($dmap[$methName]['signature']))
|
||||
|| $sr[0]) {
|
||||
$f = $dmap[$methName]['function'];
|
||||
// if no signature or correct signature
|
||||
if ($sysCall) {
|
||||
$r = $f($this, $m);
|
||||
} else {
|
||||
$r = $f($m);
|
||||
}
|
||||
} else {
|
||||
$r=new xmlrpcresp(0,
|
||||
$xmlrpcerr["incorrect_params"],
|
||||
$xmlrpcstr["incorrect_params"].": ". $sr[1]);
|
||||
}
|
||||
} else {
|
||||
// else prepare error response
|
||||
$r=new xmlrpcresp(0,
|
||||
$xmlrpcerr["unknown_method"],
|
||||
$xmlrpcstr["unknown_method"]);
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
function echoInput() {
|
||||
|
||||
// a debugging routine: just echos back the input
|
||||
// packet as a string value
|
||||
|
||||
$r=new xmlrpcresp;
|
||||
$r->xv=new xmlrpcval( "'Aha said I: '" . $GLOBALS["HTTP_RAW_POST_DATA"], "string");
|
||||
print $r->serialize();
|
||||
*/
|
||||
if (!function_exists($method)) {
|
||||
return xmlrpc_error(-32601, t('server error. requested function %method does not exist.', array("%method" => $method)));
|
||||
}
|
||||
// Call the function
|
||||
return call_user_func_array($method, $args);
|
||||
}
|
||||
|
||||
?>
|
||||
function xmlrpc_server_method_signature($xmlrpc_server, $methodname) {
|
||||
if (!isset($xmlrpc_server->callbacks[$methodname])) {
|
||||
return xmlrpc_error(-32601, t('server error. requested method %methodname not specified.', array("%methodname" => $methodname)));
|
||||
}
|
||||
if (!is_array($xmlrpc_server->signature[$methodname])) {
|
||||
return xmlrpc_error(-32601, t('server error. requested method %methodname signature not specified.', array("%methodname" => $methodname)));
|
||||
}
|
||||
// We should be returning an array of types
|
||||
$return = array();
|
||||
foreach ($xmlrpc_server->signatures[$methodname] as $type) {
|
||||
switch ($type) {
|
||||
case 'string':
|
||||
$return[] = 'string';
|
||||
break;
|
||||
case 'int':
|
||||
case 'i4':
|
||||
$return[] = 42;
|
||||
break;
|
||||
case 'double':
|
||||
$return[] = 3.1415;
|
||||
break;
|
||||
case 'dateTime.iso8601':
|
||||
$return[] = xmlrpc_date(time());
|
||||
break;
|
||||
case 'boolean':
|
||||
$return[] = true;
|
||||
break;
|
||||
case 'base64':
|
||||
$return[] =xmlrpc_base64('base64');
|
||||
break;
|
||||
case 'array':
|
||||
$return[] = array('array');
|
||||
break;
|
||||
case 'struct':
|
||||
$return[] = array('struct' => 'struct');
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function xmlrpc_server_method_help($xmlrpc_server, $method) {
|
||||
return $xmlrpc_server->help[$method];
|
||||
}
|
||||
|
||||
?>
|
|
@ -22,53 +22,123 @@ function blogapi_help($section) {
|
|||
* Implementation of hook_xmlrpc().
|
||||
*/
|
||||
function blogapi_xmlrpc() {
|
||||
$methods = array('blogger.getUsersBlogs' => array('function' => 'blogapi_get_users_blogs'),
|
||||
'blogger.getUserInfo' => array('function' => 'blogapi_get_user_info'),
|
||||
'blogger.newPost' => array('function' => 'blogapi_new_post'),
|
||||
'blogger.editPost' => array('function' => 'blogapi_edit_post'),
|
||||
'blogger.deletePost' => array('function' => 'blogapi_delete_post'),
|
||||
'blogger.getRecentPosts' => array('function' => 'blogapi_get_recent_posts'),
|
||||
'metaWeblog.newPost' => array('function' => 'blogapi_new_post'),
|
||||
'metaWeblog.editPost' => array('function' => 'blogapi_edit_post'),
|
||||
'metaWeblog.getPost' => array('function' => 'blogapi_get_post'),
|
||||
'metaWeblog.newMediaObject' => array('function' => 'blogapi_new_media_object'),
|
||||
'metaWeblog.getCategories' => array('function' => 'blogapi_get_category_list'),
|
||||
'metaWeblog.getRecentPosts' => array('function' => 'blogapi_get_recent_posts'),
|
||||
'mt.getRecentPostTitles' => array('function' => 'blogapi_get_recent_post_titles'),
|
||||
'mt.getCategoryList' => array('function' => 'blogapi_get_category_list'),
|
||||
'mt.getPostCategories' => array('function' => 'blogapi_get_post_categories'),
|
||||
'mt.setPostCategories' => array('function' => 'blogapi_set_post_categories'),
|
||||
'mt.supportedMethods' => array('function' => 'blogapi_supported_methods'),
|
||||
'mt.supportedTextFilters' => array('function' => 'blogapi_supported_text_filters'),
|
||||
'mt.getTrackbackPings' => array('function' => 'blogapi_get_trackback_pings'),
|
||||
'mt.publishPost' => array('function' => 'blogapi_publish_post')
|
||||
);
|
||||
|
||||
return $methods;
|
||||
return array(
|
||||
array(
|
||||
'blogger.getUsersBlogs',
|
||||
'blogapi_blogger_get_users_blogs',
|
||||
array('array', 'string', 'string', 'string'),
|
||||
t('Returns a list of weblogs to which an author has posting privileges.')),
|
||||
array(
|
||||
'blogger.getUserInfo',
|
||||
'blogapi_blogger_get_user_info',
|
||||
array('struct', 'string', 'string', 'string'),
|
||||
t('Returns information about an author in the system.')),
|
||||
array(
|
||||
'blogger.newPost',
|
||||
'blogapi_blogger_new_post',
|
||||
array('string', 'string', 'string', 'string', 'string', 'string', 'boolean'),
|
||||
t('Creates a new post, and optionally publishes it.')),
|
||||
array(
|
||||
'blogger.editPost',
|
||||
'blogapi_blogger_edit_post',
|
||||
array('boolean', 'string', 'string', 'string', 'string', 'string', 'boolean'),
|
||||
t('Updates the information about an existing post.')),
|
||||
array(
|
||||
'blogger.deletePost',
|
||||
'blogapi_blogger_delete_post',
|
||||
array('boolean', 'string', 'string', 'string', 'string', 'boolean'),
|
||||
t('Deletes a post.')),
|
||||
array(
|
||||
'blogger.getRecentPosts',
|
||||
'blogapi_blogger_get_recent_posts',
|
||||
array('array', 'string', 'string', 'string', 'string', 'int'),
|
||||
t('Returns a list of the most recent posts in the system.')),
|
||||
array(
|
||||
'metaWeblog.newPost',
|
||||
'blogapi_metaweblog_new_post',
|
||||
array('string', 'string', 'string', 'string', 'struct', 'boolean'),
|
||||
t('Creates a new post, and optionally publishes it.')),
|
||||
array(
|
||||
'metaWeblog.editPost',
|
||||
'blogapi_metaweblog_edit_post',
|
||||
array('boolean', 'string', 'string', 'string', 'struct', 'boolean'),
|
||||
t('Updates information about an existing post.')),
|
||||
array(
|
||||
'metaWeblog.getPost',
|
||||
'blogapi_metaweblog_get_post',
|
||||
array('struct', 'string', 'string', 'string'),
|
||||
t('Returns information about a specific post.')),
|
||||
array(
|
||||
'metaWeblog.newMediaObject',
|
||||
'blogapi_metaweblog_new_media_object',
|
||||
array('string', 'string', 'string', 'string', 'struct'),
|
||||
t('Uploads a file to your webserver.')),
|
||||
array(
|
||||
'metaWeblog.getCategories',
|
||||
'blogapi_metaweblog_get_category_list',
|
||||
array('struct', 'string', 'string', 'string'),
|
||||
t('Returns a list of all categories to which the post is assigned.')),
|
||||
array(
|
||||
'metaWeblog.getRecentPosts',
|
||||
'blogapi_metaweblog_get_recent_posts',
|
||||
array('array', 'string', 'string', 'string', 'int'),
|
||||
t('Returns a list of the most recent posts in the system.')),
|
||||
array(
|
||||
'mt.getRecentPostTitles',
|
||||
'blogapi_mt_get_recent_post_titles',
|
||||
array('array', 'string', 'string', 'string', 'int'),
|
||||
t('Returns a bandwidth-friendly list of the most recent posts in the system.')),
|
||||
array(
|
||||
'mt.getCategoryList',
|
||||
'blogapi_mt_get_category_list',
|
||||
array('array', 'string', 'string', 'string'),
|
||||
t('Returns a list of all categories defined in the weblog.')),
|
||||
array(
|
||||
'mt.getPostCategories',
|
||||
'blogapi_mt_get_post_categories',
|
||||
array('array', 'string', 'string', 'string'),
|
||||
t('Returns a list of all categories to which the post is assigned.')),
|
||||
array(
|
||||
'mt.setPostCategories',
|
||||
'blogapi_mt_set_post_categories',
|
||||
array('boolean', 'string', 'string', 'string', 'array'),
|
||||
t('Sets the categories for a post.')),
|
||||
array(
|
||||
'mt.supportedMethods',
|
||||
'xmlrpc_server_list_methods',
|
||||
array('array'),
|
||||
t('Retrieve information about the XML-RPC methods supported by the server.')),
|
||||
array(
|
||||
'mt.supportedTextFilters',
|
||||
'blogapi_mt_supported_text_filters',
|
||||
array('array'),
|
||||
t('Retrieve information about the text formatting plugins supported by the server.')),
|
||||
array(
|
||||
'mt.getTrackbackPings',
|
||||
'blogapi_mt_get_trackback_pings',
|
||||
array('array', 'string'),
|
||||
t('Retrieve the list of TrackBack pings posted to a particular entry. This could be used to programmatically retrieve the list of pings for a particular entry, then iterate through each of those pings doing the same, until one has built up a graph of the web of entries referencing one another on a particular topic.')),
|
||||
array(
|
||||
'mt.publishPost',
|
||||
'blogap_mti_publish_post',
|
||||
array('boolean', 'string', 'string', 'string'),
|
||||
t('Publish (rebuild) all of the static files related to an entry from your weblog. Equivalent to saving an entry in the system (but without the ping).')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Finds the URL of a user's blog.
|
||||
*/
|
||||
function blogapi_get_users_blogs($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
// Remove unused appkey from bloggerAPI.
|
||||
if (count($params) == 6) {
|
||||
$params = array_slice($params, 1);
|
||||
}
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_blogger_get_users_blogs() {
|
||||
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if ($user->uid) {
|
||||
$types = _blogapi_get_node_types();
|
||||
$structs = array();
|
||||
foreach ($types as $type) {
|
||||
$structs[] = new xmlrpcval(array('url' => new xmlrpcval(url('blog/' . $user->uid, NULL, NULL, true)),
|
||||
'blogid' => new xmlrpcval($type, 'string'),
|
||||
'blogName' => new xmlrpcval($user->name . ": " . $type)),
|
||||
'struct');
|
||||
$structs[] = array('url' => url('blog/' . $user->uid, NULL, NULL, true), 'blogid' => $type, 'blogName' => $user->name . ": " . $type);
|
||||
}
|
||||
$resp = new xmlrpcval($structs, 'array');
|
||||
return new xmlrpcresp($resp);
|
||||
return $structs;
|
||||
}
|
||||
else {
|
||||
return blogapi_error($user);
|
||||
|
@ -78,21 +148,18 @@ function blogapi_get_users_blogs($req_params) {
|
|||
/**
|
||||
* Blogging API callback. Returns profile information about a user.
|
||||
*/
|
||||
function blogapi_get_user_info($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_blogger_get_user_info($appkey, $username, $password) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
|
||||
if ($user->uid) {
|
||||
$name = explode(' ', $user->realname ? $user->realname : $user->name, 2);
|
||||
$struct = new xmlrpcval(array('userid' => new xmlrpcval($user->uid, 'string'),
|
||||
'lastname' => new xmlrpcval($name[1], 'string'),
|
||||
'firstname' => new xmlrpcval($name[0], 'string'),
|
||||
'nickname' => new xmlrpcval($user->name, 'string'),
|
||||
'email' => new xmlrpcval($user->mail, 'string'),
|
||||
'url' => new xmlrpcval(url('blog/' . $user->uid, NULL, NULL, true), 'string')),
|
||||
'struct');
|
||||
return new xmlrpcresp($struct);
|
||||
return array(
|
||||
'userid' => $user->uid,
|
||||
'lastname' => $name[1],
|
||||
'firstname' => $name[0],
|
||||
'nickname' => $user->name,
|
||||
'email' => $user->mail,
|
||||
'url' => url('blog/' . $user->uid, NULL, NULL, true));
|
||||
}
|
||||
else {
|
||||
return blogapi_error($user);
|
||||
|
@ -102,21 +169,14 @@ function blogapi_get_user_info($req_params) {
|
|||
/**
|
||||
* Blogging API callback. Inserts a new blog post as a node.
|
||||
*/
|
||||
function blogapi_new_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
// Remove unused appkey from bloggerAPI.
|
||||
if (count($params) == 6) {
|
||||
$params = array_slice($params, 1);
|
||||
}
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $content, $publish) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$edit = array();
|
||||
$edit['type'] = _blogapi_blogid($params[0]);
|
||||
$edit['type'] = _blogapi_blogid($blogid);
|
||||
// get the node type defaults
|
||||
$node_type_default = variable_get('node_options_'. $edit['type'], array('status', 'promote'));
|
||||
$edit['uid'] = $user->uid;
|
||||
|
@ -126,17 +186,17 @@ function blogapi_new_post($req_params) {
|
|||
$edit['moderate'] = in_array('moderate', $node_type_default);
|
||||
$edit['revision'] = in_array('revision', $node_type_default);
|
||||
$edit['format'] = FILTER_FORMAT_DEFAULT;
|
||||
$edit['status'] = $params[4];
|
||||
$edit['status'] = $publish;
|
||||
|
||||
// check for bloggerAPI vs. metaWeblogAPI
|
||||
if (is_array($params[3])) {
|
||||
$edit['title'] = $params[3]['title'];
|
||||
$edit['body'] = $params[3]['description'];
|
||||
_blogapi_mt_extra($edit, $params[3]);
|
||||
if (is_array($content)) {
|
||||
$edit['title'] = $content['title'];
|
||||
$edit['body'] = $content['description'];
|
||||
_blogapi_mt_extra($edit, $content);
|
||||
}
|
||||
else {
|
||||
$edit['title'] = blogapi_blogger_title($params[3]);
|
||||
$edit['body'] = $params[3];
|
||||
$edit['title'] = blogapi_blogger_title($content);
|
||||
$edit['body'] = $content;
|
||||
}
|
||||
|
||||
if (!valid_input_data($edit['title'], $edit['body'])) {
|
||||
|
@ -156,7 +216,7 @@ function blogapi_new_post($req_params) {
|
|||
$nid = node_save($node);
|
||||
if ($nid) {
|
||||
watchdog('content', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$nid"));
|
||||
return new xmlrpcresp(new xmlrpcval($nid, 'string'));
|
||||
return $nid;
|
||||
}
|
||||
|
||||
return blogapi_error(t('Error storing post.'));
|
||||
|
@ -165,19 +225,15 @@ function blogapi_new_post($req_params) {
|
|||
/**
|
||||
* Blogging API callback. Modifies the specified blog node.
|
||||
*/
|
||||
function blogapi_edit_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
if (count($params) == 6) {
|
||||
$params = array_slice($params, 1);
|
||||
}
|
||||
function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $content, $publish) {
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$node = node_load(array('nid' => $params[0]));
|
||||
$node = node_load(array('nid' => $postid));
|
||||
if (!$node) {
|
||||
return blogapi_error(message_na());
|
||||
}
|
||||
|
@ -188,20 +244,20 @@ function blogapi_edit_post($req_params) {
|
|||
return blogapi_error(message_access());
|
||||
}
|
||||
|
||||
$node->status = $params[4];
|
||||
$node->status = $publish;
|
||||
|
||||
// check for bloggerAPI vs. metaWeblogAPI
|
||||
if (is_array($params[3])) {
|
||||
$node->title = $params[3]['title'];
|
||||
$node->body = $params[3]['description'];
|
||||
_blogapi_mt_extra($node, $params[3]);
|
||||
if (is_array($content)) {
|
||||
$node->title = $content['title'];
|
||||
$node->body = $content['description'];
|
||||
_blogapi_mt_extra($node, $content);
|
||||
}
|
||||
else {
|
||||
$node->title = blogapi_blogger_title($params[3]);
|
||||
$node->body = $params[3];
|
||||
$node->title = blogapi_blogger_title($content);
|
||||
$node->body = $content;
|
||||
}
|
||||
|
||||
if (!valid_input_data($title, $body)) {
|
||||
if (!valid_input_data($node->title, $node->body)) {
|
||||
return blogapi_error(t('Terminated request because of suspicious input data.'));
|
||||
}
|
||||
|
||||
|
@ -218,57 +274,78 @@ function blogapi_edit_post($req_params) {
|
|||
$nid = node_save($node);
|
||||
if ($nid) {
|
||||
watchdog('content', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$nid"));
|
||||
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
|
||||
return true;
|
||||
}
|
||||
|
||||
return blogapi_error(t('Error storing post.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns a specified blog node.
|
||||
* Blogging API callback. Removes the specified blog node.
|
||||
*/
|
||||
function blogapi_get_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_blogger_delete_post($appkey, $postid, $username, $password, $content, $publish) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$node = node_load(array('nid' => $params[0]));
|
||||
|
||||
$blog = _blogapi_get_post($node, true);
|
||||
|
||||
return new xmlrpcresp($blog);
|
||||
node_delete(array('nid' => $postid, 'confirm' => 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Removes the specified blog node.
|
||||
* Blogging API callback. Returns the latest few postings in a user's blog. $bodies TRUE
|
||||
* <a href="http://movabletype.org/docs/mtmanual_programmatic.html#item_mt%2EgetRecentPostTitles">
|
||||
* returns a bandwidth-friendly list</a>.
|
||||
*/
|
||||
function blogapi_delete_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
$user = blogapi_validate_user($params[2], $params[3]);
|
||||
function blogapi_blogger_get_recent_posts($appkey, $blogid, $username, $password, $number_of_posts, $bodies = TRUE) {
|
||||
// Remove unused appkey (from bloggerAPI).
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$ret = node_delete(array('nid' => $params[1], 'confirm' => 1));
|
||||
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
|
||||
$type = _blogapi_blogid($blogid);
|
||||
$result = db_query_range('SELECT n.nid, n.title,'. ($bodies ? ' n.body,' : '') ." n.created, u.name FROM {node} n, {users} u WHERE n.uid=u.uid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $number_of_posts);
|
||||
while ($blog = db_fetch_object($result)) {
|
||||
$blogs[] = _blogapi_get_post($blog, $bodies);
|
||||
}
|
||||
return $blogs;
|
||||
}
|
||||
|
||||
function blogapi_metaweblog_new_post($blogid, $username, $password, $content, $publish) {
|
||||
return blogapi_blogger_new_post('0123456789ABCDEF', $blogid, $username, $password, $content, $publish);
|
||||
}
|
||||
|
||||
function blogapi_metaweblog_edit_post($postid, $username, $password, $content, $publish) {
|
||||
return blogapi_blogger_edit_post('0123456789ABCDEF', $postid, $username, $password, $content, $publish);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns a specified blog node.
|
||||
*/
|
||||
function blogapi_metaweblog_get_post($postid, $username, $password) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$node = node_load(array('nid' => $postid));
|
||||
|
||||
return _blogapi_get_post($node, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Inserts a file into Drupal.
|
||||
*/
|
||||
function blogapi_new_media_object($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_metaweblog_new_media_object($blogid, $username, $password, $file) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$name = basename($params[3]['name']);
|
||||
$data = $params[3]['bits'];
|
||||
$name = basename($file['name']);
|
||||
$data = $file['bits'];
|
||||
|
||||
if (!$data) {
|
||||
return blogapi_error(t('No file sent.'));
|
||||
|
@ -279,17 +356,14 @@ function blogapi_new_media_object($req_params) {
|
|||
}
|
||||
|
||||
// Return the successful result.
|
||||
$result = new xmlrpcval(array('url' => new xmlrpcval(file_create_url($file), 'string')), 'struct');
|
||||
return new xmlrpcresp($result);
|
||||
return array('url' => file_create_url($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns a list of the taxonomy terms that can be
|
||||
* associated with a blog node.
|
||||
*/
|
||||
function blogapi_get_category_list($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
$type = _blogapi_blogid($params[0]);
|
||||
function blogapi_metaweblog_get_category_list($blogid, $username, $password) {
|
||||
$type = _blogapi_blogid($blogid);
|
||||
$vocabularies = module_invoke('taxonomy', 'get_vocabularies', $type, 'vid');
|
||||
$categories = array();
|
||||
if ($vocabularies) {
|
||||
|
@ -300,140 +374,102 @@ function blogapi_get_category_list($req_params) {
|
|||
foreach (module_invoke('taxonomy', 'get_parents', $term->tid, 'tid') as $parent) {
|
||||
$term_name = $parent->name . '/' . $term_name;
|
||||
}
|
||||
$categories[] = new xmlrpcval(array('categoryName' => new xmlrpcval($term_name, 'string'),
|
||||
'categoryId' => new xmlrpcval($term->tid, 'string')),
|
||||
'struct');
|
||||
$categories[] = array('categoryName' => $term_name, 'categoryId' => $term->tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new xmlrpcresp(new xmlrpcval($categories, 'array'));
|
||||
return $categories;
|
||||
}
|
||||
|
||||
function blogai_metaweblog_get_recent_posts($blogid, $username, $password, $number_of_posts) {
|
||||
return blogapi_blogger_get_recent_posts('0123456789ABCDEF', $blogid, $username, $password, $number_of_posts, TRUE);
|
||||
}
|
||||
|
||||
// see above
|
||||
function blogapi_mt_get_recent_post_titles($blogid, $username, $password, $number_of_posts) {
|
||||
return blogapi_blogger_get_recent_posts('0123456789ABCDEF', $blogid, $username, $password, $number_of_posts, FALSE);
|
||||
}
|
||||
|
||||
/* **** */
|
||||
function blogapi_mt_get_category_list($blogid, $username, $password) {
|
||||
return blogapi_metaweblog_get_category_list($blogid, $username, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns a list of the taxonomy terms that are
|
||||
* assigned to a particular node.
|
||||
*/
|
||||
function blogapi_get_post_categories($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_mt_get_post_categories($postid, $username, $password) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$terms = module_invoke('taxonomy', 'node_get_terms', $params[0], 'tid');
|
||||
$terms = module_invoke('taxonomy', 'node_get_terms', $postid, 'tid');
|
||||
$categories = array();
|
||||
foreach ($terms as $term) {
|
||||
$term_name = $term->name;
|
||||
foreach (module_invoke('taxonomy', 'get_parents', $term->tid, 'tid') as $parent) {
|
||||
$term_name = $parent->name . '/' . $term_name;
|
||||
}
|
||||
$categories[] = new xmlrpcval(array('categoryName' => new xmlrpcval($term_name, 'string'),
|
||||
'categoryId' => new xmlrpcval($term->tid, 'string'),
|
||||
'isPrimary' => new xmlrpcval(true, 'boolean')),
|
||||
'struct');
|
||||
$categories[] = array('categoryName' => $term_name, 'categoryId' => $term->tid, 'isPrimary' => true);
|
||||
}
|
||||
return new xmlrpcresp(new xmlrpcval($categories, 'array'));
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Assigns taxonomy terms to a particular node.
|
||||
*/
|
||||
function blogapi_set_post_categories($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_mt_set_post_categories($postid, $username, $password, $categories) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$nid = $params[0];
|
||||
$nid = $postid;
|
||||
$terms = array();
|
||||
foreach ($params[3] as $category) {
|
||||
foreach ($categories as $category) {
|
||||
$terms[] = $category['categoryId']->scalarval();
|
||||
}
|
||||
module_invoke('taxonomy', 'node_save', $nid, $terms);
|
||||
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns the latest few postings in a user's blog. $bodies TRUE
|
||||
* <a href="http://movabletype.org/docs/mtmanual_programmatic.html#item_mt%2EgetRecentPostTitles">
|
||||
* returns a bandwidth-friendly list</a>.
|
||||
*/
|
||||
function blogapi_get_recent_posts($req_params, $bodies = TRUE) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
// Remove unused appkey (from bloggerAPI).
|
||||
if (count($params) == 5) {
|
||||
$params = array_slice($params, 1);
|
||||
}
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$type = _blogapi_blogid($params[0]);
|
||||
$result = db_query_range('SELECT n.nid, n.title,'. ($bodies ? ' n.body,' : '') ." n.created, u.name FROM {node} n, {users} u WHERE n.uid=u.uid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $params[3]);
|
||||
while ($blog = db_fetch_object($result)) {
|
||||
$xmlrpcval = _blogapi_get_post($blog, $bodies);
|
||||
$blogs[] = $xmlrpcval;
|
||||
}
|
||||
return new xmlrpcresp(new xmlrpcval($blogs, 'array'));
|
||||
}
|
||||
|
||||
// see above
|
||||
function blogapi_get_recent_post_titles($req_params) {
|
||||
return blogapi_get_recent_posts($req_params, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Sends a list of supported methods to the client.
|
||||
*/
|
||||
function blogapi_supported_methods($req_params) {
|
||||
$methods = array_keys(blogapi_xmlrpc());
|
||||
|
||||
$output = array();
|
||||
foreach ($methods as $method) {
|
||||
$output[] = new xmlrpcval($method, 'string');
|
||||
}
|
||||
return new xmlrpcresp(new xmlrpcval($output, 'array'));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Sends a list of available input formats.
|
||||
*/
|
||||
function blogapi_supported_text_filters($req_params) {
|
||||
global $user;
|
||||
|
||||
function blogapi_mt_supported_text_filters() {
|
||||
// NOTE: we're only using anonymous' formats because the MT spec
|
||||
// does not allow for per-user formats.
|
||||
$formats = filter_formats();
|
||||
|
||||
$filters = array();
|
||||
foreach ($formats as $format) {
|
||||
$filter['key'] = new xmlrpcval($format->format, 'string');
|
||||
$filter['label'] = new xmlrpcval($format->name, 'string');
|
||||
$filters[] = new xmlrpcval($filter, 'struct');
|
||||
$filter['key'] = $format->format;
|
||||
$filter['label'] = $format->name;
|
||||
$filters[] = $filter;
|
||||
}
|
||||
|
||||
return new xmlrpcresp(new xmlrpcval($filters, 'array'));
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Can not be implemented without support from
|
||||
* trackback module.
|
||||
*/
|
||||
function blogapi_get_trackback_pings($req_params) {
|
||||
function blogapi_mt_get_trackback_pings() {
|
||||
return blogapi_error(t('Not implemented.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Publishes the given node
|
||||
*/
|
||||
function blogapi_publish_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
$node = node_load(array('nid' => $params[0]));
|
||||
function blogap_mti_publish_post($postid, $username, $password) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
$node = node_load(array('nid' => $postid));
|
||||
if (!$node) {
|
||||
return blogapi_error(t('Invalid post.'));
|
||||
}
|
||||
|
@ -445,38 +481,21 @@ function blogapi_publish_post($req_params) {
|
|||
|
||||
node_save($node);
|
||||
|
||||
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the parameters to an XMLRPC callback, and return them as an array.
|
||||
*/
|
||||
function blogapi_convert($params) {
|
||||
$cparams = array();
|
||||
$num_params= $params->getNumParams();
|
||||
|
||||
for ($i = 0; $i < $num_params; $i++) {
|
||||
$sn = $params->getParam($i);
|
||||
$cparams[] = $sn->getval();
|
||||
}
|
||||
|
||||
return $cparams;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare an error message for returning to the XMLRPC caller.
|
||||
*/
|
||||
function blogapi_error($message) {
|
||||
global $xmlrpcusererr;
|
||||
|
||||
static $xmlrpcusererr;
|
||||
if (!is_array($message)) {
|
||||
$message = array($message);
|
||||
}
|
||||
|
||||
$message = implode(' ', $message);
|
||||
|
||||
return new xmlrpcresp(0, $xmlrpcusererr + 1, strip_tags($message));
|
||||
return xmlrpc_error($xmlrpcusererr + 1, strip_tags($message));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -651,12 +670,12 @@ function _blogapi_mt_extra(&$node, $struct) {
|
|||
|
||||
function _blogapi_get_post($node, $bodies = true) {
|
||||
$xmlrpcval = array (
|
||||
'userid' => new xmlrpcval($node->name, 'string'),
|
||||
'dateCreated' => new xmlrpcval(iso8601_encode($node->created), 'dateTime.iso8601'),
|
||||
'title' => new xmlrpcval($node->title, 'string'),
|
||||
'postid' => new xmlrpcval($node->nid, 'string'),
|
||||
'link' => new xmlrpcval(url('node/'.$node->nid, NULL, NULL, true)),
|
||||
'permaLink' => new xmlrpcval(url('node/'.$node->nid, NULL, NULL, true)),
|
||||
'userid' => $node->name,
|
||||
'dateCreated' => xmlrpc_date($node->created),
|
||||
'title' => $node->title,
|
||||
'postid' => $node->nid,
|
||||
'link' => url('node/'.$node->nid, NULL, NULL, true),
|
||||
'permaLink' => url('node/'.$node->nid, NULL, NULL, true),
|
||||
);
|
||||
if ($bodies) {
|
||||
if ($node->comment = 1) {
|
||||
|
@ -666,14 +685,14 @@ function _blogapi_get_post($node, $bodies = true) {
|
|||
$comment = 1;
|
||||
}
|
||||
|
||||
$xmlrpcval['content'] = new xmlrpcval("<title>$blog->title</title>$node->body", 'string');
|
||||
$xmlrpcval['description'] = new xmlrpcval($node->body, 'string');
|
||||
$xmlrpcval['content'] = "<title>$node->title</title>$node->body";
|
||||
$xmlrpcval['description'] = $node->body;
|
||||
// Add MT specific fields
|
||||
$xmlrpcval['mt_allow_comments'] = new xmlrpcval($comment, 'int');
|
||||
$xmlrpcval['mt_convert_breaks'] = new xmlrpcval($node->format, 'string');
|
||||
$xmlrpcval['mt_allow_comments'] = $comment;
|
||||
$xmlrpcval['mt_convert_breaks'] = $node->format;
|
||||
}
|
||||
|
||||
return new xmlrpcval($xmlrpcval, 'struct');
|
||||
return $xmlrpcval;
|
||||
}
|
||||
|
||||
function _blogapi_blogid($id) {
|
||||
|
|
|
@ -22,53 +22,123 @@ function blogapi_help($section) {
|
|||
* Implementation of hook_xmlrpc().
|
||||
*/
|
||||
function blogapi_xmlrpc() {
|
||||
$methods = array('blogger.getUsersBlogs' => array('function' => 'blogapi_get_users_blogs'),
|
||||
'blogger.getUserInfo' => array('function' => 'blogapi_get_user_info'),
|
||||
'blogger.newPost' => array('function' => 'blogapi_new_post'),
|
||||
'blogger.editPost' => array('function' => 'blogapi_edit_post'),
|
||||
'blogger.deletePost' => array('function' => 'blogapi_delete_post'),
|
||||
'blogger.getRecentPosts' => array('function' => 'blogapi_get_recent_posts'),
|
||||
'metaWeblog.newPost' => array('function' => 'blogapi_new_post'),
|
||||
'metaWeblog.editPost' => array('function' => 'blogapi_edit_post'),
|
||||
'metaWeblog.getPost' => array('function' => 'blogapi_get_post'),
|
||||
'metaWeblog.newMediaObject' => array('function' => 'blogapi_new_media_object'),
|
||||
'metaWeblog.getCategories' => array('function' => 'blogapi_get_category_list'),
|
||||
'metaWeblog.getRecentPosts' => array('function' => 'blogapi_get_recent_posts'),
|
||||
'mt.getRecentPostTitles' => array('function' => 'blogapi_get_recent_post_titles'),
|
||||
'mt.getCategoryList' => array('function' => 'blogapi_get_category_list'),
|
||||
'mt.getPostCategories' => array('function' => 'blogapi_get_post_categories'),
|
||||
'mt.setPostCategories' => array('function' => 'blogapi_set_post_categories'),
|
||||
'mt.supportedMethods' => array('function' => 'blogapi_supported_methods'),
|
||||
'mt.supportedTextFilters' => array('function' => 'blogapi_supported_text_filters'),
|
||||
'mt.getTrackbackPings' => array('function' => 'blogapi_get_trackback_pings'),
|
||||
'mt.publishPost' => array('function' => 'blogapi_publish_post')
|
||||
);
|
||||
|
||||
return $methods;
|
||||
return array(
|
||||
array(
|
||||
'blogger.getUsersBlogs',
|
||||
'blogapi_blogger_get_users_blogs',
|
||||
array('array', 'string', 'string', 'string'),
|
||||
t('Returns a list of weblogs to which an author has posting privileges.')),
|
||||
array(
|
||||
'blogger.getUserInfo',
|
||||
'blogapi_blogger_get_user_info',
|
||||
array('struct', 'string', 'string', 'string'),
|
||||
t('Returns information about an author in the system.')),
|
||||
array(
|
||||
'blogger.newPost',
|
||||
'blogapi_blogger_new_post',
|
||||
array('string', 'string', 'string', 'string', 'string', 'string', 'boolean'),
|
||||
t('Creates a new post, and optionally publishes it.')),
|
||||
array(
|
||||
'blogger.editPost',
|
||||
'blogapi_blogger_edit_post',
|
||||
array('boolean', 'string', 'string', 'string', 'string', 'string', 'boolean'),
|
||||
t('Updates the information about an existing post.')),
|
||||
array(
|
||||
'blogger.deletePost',
|
||||
'blogapi_blogger_delete_post',
|
||||
array('boolean', 'string', 'string', 'string', 'string', 'boolean'),
|
||||
t('Deletes a post.')),
|
||||
array(
|
||||
'blogger.getRecentPosts',
|
||||
'blogapi_blogger_get_recent_posts',
|
||||
array('array', 'string', 'string', 'string', 'string', 'int'),
|
||||
t('Returns a list of the most recent posts in the system.')),
|
||||
array(
|
||||
'metaWeblog.newPost',
|
||||
'blogapi_metaweblog_new_post',
|
||||
array('string', 'string', 'string', 'string', 'struct', 'boolean'),
|
||||
t('Creates a new post, and optionally publishes it.')),
|
||||
array(
|
||||
'metaWeblog.editPost',
|
||||
'blogapi_metaweblog_edit_post',
|
||||
array('boolean', 'string', 'string', 'string', 'struct', 'boolean'),
|
||||
t('Updates information about an existing post.')),
|
||||
array(
|
||||
'metaWeblog.getPost',
|
||||
'blogapi_metaweblog_get_post',
|
||||
array('struct', 'string', 'string', 'string'),
|
||||
t('Returns information about a specific post.')),
|
||||
array(
|
||||
'metaWeblog.newMediaObject',
|
||||
'blogapi_metaweblog_new_media_object',
|
||||
array('string', 'string', 'string', 'string', 'struct'),
|
||||
t('Uploads a file to your webserver.')),
|
||||
array(
|
||||
'metaWeblog.getCategories',
|
||||
'blogapi_metaweblog_get_category_list',
|
||||
array('struct', 'string', 'string', 'string'),
|
||||
t('Returns a list of all categories to which the post is assigned.')),
|
||||
array(
|
||||
'metaWeblog.getRecentPosts',
|
||||
'blogapi_metaweblog_get_recent_posts',
|
||||
array('array', 'string', 'string', 'string', 'int'),
|
||||
t('Returns a list of the most recent posts in the system.')),
|
||||
array(
|
||||
'mt.getRecentPostTitles',
|
||||
'blogapi_mt_get_recent_post_titles',
|
||||
array('array', 'string', 'string', 'string', 'int'),
|
||||
t('Returns a bandwidth-friendly list of the most recent posts in the system.')),
|
||||
array(
|
||||
'mt.getCategoryList',
|
||||
'blogapi_mt_get_category_list',
|
||||
array('array', 'string', 'string', 'string'),
|
||||
t('Returns a list of all categories defined in the weblog.')),
|
||||
array(
|
||||
'mt.getPostCategories',
|
||||
'blogapi_mt_get_post_categories',
|
||||
array('array', 'string', 'string', 'string'),
|
||||
t('Returns a list of all categories to which the post is assigned.')),
|
||||
array(
|
||||
'mt.setPostCategories',
|
||||
'blogapi_mt_set_post_categories',
|
||||
array('boolean', 'string', 'string', 'string', 'array'),
|
||||
t('Sets the categories for a post.')),
|
||||
array(
|
||||
'mt.supportedMethods',
|
||||
'xmlrpc_server_list_methods',
|
||||
array('array'),
|
||||
t('Retrieve information about the XML-RPC methods supported by the server.')),
|
||||
array(
|
||||
'mt.supportedTextFilters',
|
||||
'blogapi_mt_supported_text_filters',
|
||||
array('array'),
|
||||
t('Retrieve information about the text formatting plugins supported by the server.')),
|
||||
array(
|
||||
'mt.getTrackbackPings',
|
||||
'blogapi_mt_get_trackback_pings',
|
||||
array('array', 'string'),
|
||||
t('Retrieve the list of TrackBack pings posted to a particular entry. This could be used to programmatically retrieve the list of pings for a particular entry, then iterate through each of those pings doing the same, until one has built up a graph of the web of entries referencing one another on a particular topic.')),
|
||||
array(
|
||||
'mt.publishPost',
|
||||
'blogap_mti_publish_post',
|
||||
array('boolean', 'string', 'string', 'string'),
|
||||
t('Publish (rebuild) all of the static files related to an entry from your weblog. Equivalent to saving an entry in the system (but without the ping).')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Finds the URL of a user's blog.
|
||||
*/
|
||||
function blogapi_get_users_blogs($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
// Remove unused appkey from bloggerAPI.
|
||||
if (count($params) == 6) {
|
||||
$params = array_slice($params, 1);
|
||||
}
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_blogger_get_users_blogs() {
|
||||
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if ($user->uid) {
|
||||
$types = _blogapi_get_node_types();
|
||||
$structs = array();
|
||||
foreach ($types as $type) {
|
||||
$structs[] = new xmlrpcval(array('url' => new xmlrpcval(url('blog/' . $user->uid, NULL, NULL, true)),
|
||||
'blogid' => new xmlrpcval($type, 'string'),
|
||||
'blogName' => new xmlrpcval($user->name . ": " . $type)),
|
||||
'struct');
|
||||
$structs[] = array('url' => url('blog/' . $user->uid, NULL, NULL, true), 'blogid' => $type, 'blogName' => $user->name . ": " . $type);
|
||||
}
|
||||
$resp = new xmlrpcval($structs, 'array');
|
||||
return new xmlrpcresp($resp);
|
||||
return $structs;
|
||||
}
|
||||
else {
|
||||
return blogapi_error($user);
|
||||
|
@ -78,21 +148,18 @@ function blogapi_get_users_blogs($req_params) {
|
|||
/**
|
||||
* Blogging API callback. Returns profile information about a user.
|
||||
*/
|
||||
function blogapi_get_user_info($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_blogger_get_user_info($appkey, $username, $password) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
|
||||
if ($user->uid) {
|
||||
$name = explode(' ', $user->realname ? $user->realname : $user->name, 2);
|
||||
$struct = new xmlrpcval(array('userid' => new xmlrpcval($user->uid, 'string'),
|
||||
'lastname' => new xmlrpcval($name[1], 'string'),
|
||||
'firstname' => new xmlrpcval($name[0], 'string'),
|
||||
'nickname' => new xmlrpcval($user->name, 'string'),
|
||||
'email' => new xmlrpcval($user->mail, 'string'),
|
||||
'url' => new xmlrpcval(url('blog/' . $user->uid, NULL, NULL, true), 'string')),
|
||||
'struct');
|
||||
return new xmlrpcresp($struct);
|
||||
return array(
|
||||
'userid' => $user->uid,
|
||||
'lastname' => $name[1],
|
||||
'firstname' => $name[0],
|
||||
'nickname' => $user->name,
|
||||
'email' => $user->mail,
|
||||
'url' => url('blog/' . $user->uid, NULL, NULL, true));
|
||||
}
|
||||
else {
|
||||
return blogapi_error($user);
|
||||
|
@ -102,21 +169,14 @@ function blogapi_get_user_info($req_params) {
|
|||
/**
|
||||
* Blogging API callback. Inserts a new blog post as a node.
|
||||
*/
|
||||
function blogapi_new_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
// Remove unused appkey from bloggerAPI.
|
||||
if (count($params) == 6) {
|
||||
$params = array_slice($params, 1);
|
||||
}
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $content, $publish) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$edit = array();
|
||||
$edit['type'] = _blogapi_blogid($params[0]);
|
||||
$edit['type'] = _blogapi_blogid($blogid);
|
||||
// get the node type defaults
|
||||
$node_type_default = variable_get('node_options_'. $edit['type'], array('status', 'promote'));
|
||||
$edit['uid'] = $user->uid;
|
||||
|
@ -126,17 +186,17 @@ function blogapi_new_post($req_params) {
|
|||
$edit['moderate'] = in_array('moderate', $node_type_default);
|
||||
$edit['revision'] = in_array('revision', $node_type_default);
|
||||
$edit['format'] = FILTER_FORMAT_DEFAULT;
|
||||
$edit['status'] = $params[4];
|
||||
$edit['status'] = $publish;
|
||||
|
||||
// check for bloggerAPI vs. metaWeblogAPI
|
||||
if (is_array($params[3])) {
|
||||
$edit['title'] = $params[3]['title'];
|
||||
$edit['body'] = $params[3]['description'];
|
||||
_blogapi_mt_extra($edit, $params[3]);
|
||||
if (is_array($content)) {
|
||||
$edit['title'] = $content['title'];
|
||||
$edit['body'] = $content['description'];
|
||||
_blogapi_mt_extra($edit, $content);
|
||||
}
|
||||
else {
|
||||
$edit['title'] = blogapi_blogger_title($params[3]);
|
||||
$edit['body'] = $params[3];
|
||||
$edit['title'] = blogapi_blogger_title($content);
|
||||
$edit['body'] = $content;
|
||||
}
|
||||
|
||||
if (!valid_input_data($edit['title'], $edit['body'])) {
|
||||
|
@ -156,7 +216,7 @@ function blogapi_new_post($req_params) {
|
|||
$nid = node_save($node);
|
||||
if ($nid) {
|
||||
watchdog('content', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$nid"));
|
||||
return new xmlrpcresp(new xmlrpcval($nid, 'string'));
|
||||
return $nid;
|
||||
}
|
||||
|
||||
return blogapi_error(t('Error storing post.'));
|
||||
|
@ -165,19 +225,15 @@ function blogapi_new_post($req_params) {
|
|||
/**
|
||||
* Blogging API callback. Modifies the specified blog node.
|
||||
*/
|
||||
function blogapi_edit_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
if (count($params) == 6) {
|
||||
$params = array_slice($params, 1);
|
||||
}
|
||||
function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $content, $publish) {
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$node = node_load(array('nid' => $params[0]));
|
||||
$node = node_load(array('nid' => $postid));
|
||||
if (!$node) {
|
||||
return blogapi_error(message_na());
|
||||
}
|
||||
|
@ -188,20 +244,20 @@ function blogapi_edit_post($req_params) {
|
|||
return blogapi_error(message_access());
|
||||
}
|
||||
|
||||
$node->status = $params[4];
|
||||
$node->status = $publish;
|
||||
|
||||
// check for bloggerAPI vs. metaWeblogAPI
|
||||
if (is_array($params[3])) {
|
||||
$node->title = $params[3]['title'];
|
||||
$node->body = $params[3]['description'];
|
||||
_blogapi_mt_extra($node, $params[3]);
|
||||
if (is_array($content)) {
|
||||
$node->title = $content['title'];
|
||||
$node->body = $content['description'];
|
||||
_blogapi_mt_extra($node, $content);
|
||||
}
|
||||
else {
|
||||
$node->title = blogapi_blogger_title($params[3]);
|
||||
$node->body = $params[3];
|
||||
$node->title = blogapi_blogger_title($content);
|
||||
$node->body = $content;
|
||||
}
|
||||
|
||||
if (!valid_input_data($title, $body)) {
|
||||
if (!valid_input_data($node->title, $node->body)) {
|
||||
return blogapi_error(t('Terminated request because of suspicious input data.'));
|
||||
}
|
||||
|
||||
|
@ -218,57 +274,78 @@ function blogapi_edit_post($req_params) {
|
|||
$nid = node_save($node);
|
||||
if ($nid) {
|
||||
watchdog('content', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$nid"));
|
||||
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
|
||||
return true;
|
||||
}
|
||||
|
||||
return blogapi_error(t('Error storing post.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns a specified blog node.
|
||||
* Blogging API callback. Removes the specified blog node.
|
||||
*/
|
||||
function blogapi_get_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_blogger_delete_post($appkey, $postid, $username, $password, $content, $publish) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$node = node_load(array('nid' => $params[0]));
|
||||
|
||||
$blog = _blogapi_get_post($node, true);
|
||||
|
||||
return new xmlrpcresp($blog);
|
||||
node_delete(array('nid' => $postid, 'confirm' => 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Removes the specified blog node.
|
||||
* Blogging API callback. Returns the latest few postings in a user's blog. $bodies TRUE
|
||||
* <a href="http://movabletype.org/docs/mtmanual_programmatic.html#item_mt%2EgetRecentPostTitles">
|
||||
* returns a bandwidth-friendly list</a>.
|
||||
*/
|
||||
function blogapi_delete_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
$user = blogapi_validate_user($params[2], $params[3]);
|
||||
function blogapi_blogger_get_recent_posts($appkey, $blogid, $username, $password, $number_of_posts, $bodies = TRUE) {
|
||||
// Remove unused appkey (from bloggerAPI).
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$ret = node_delete(array('nid' => $params[1], 'confirm' => 1));
|
||||
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
|
||||
$type = _blogapi_blogid($blogid);
|
||||
$result = db_query_range('SELECT n.nid, n.title,'. ($bodies ? ' n.body,' : '') ." n.created, u.name FROM {node} n, {users} u WHERE n.uid=u.uid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $number_of_posts);
|
||||
while ($blog = db_fetch_object($result)) {
|
||||
$blogs[] = _blogapi_get_post($blog, $bodies);
|
||||
}
|
||||
return $blogs;
|
||||
}
|
||||
|
||||
function blogapi_metaweblog_new_post($blogid, $username, $password, $content, $publish) {
|
||||
return blogapi_blogger_new_post('0123456789ABCDEF', $blogid, $username, $password, $content, $publish);
|
||||
}
|
||||
|
||||
function blogapi_metaweblog_edit_post($postid, $username, $password, $content, $publish) {
|
||||
return blogapi_blogger_edit_post('0123456789ABCDEF', $postid, $username, $password, $content, $publish);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns a specified blog node.
|
||||
*/
|
||||
function blogapi_metaweblog_get_post($postid, $username, $password) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$node = node_load(array('nid' => $postid));
|
||||
|
||||
return _blogapi_get_post($node, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Inserts a file into Drupal.
|
||||
*/
|
||||
function blogapi_new_media_object($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_metaweblog_new_media_object($blogid, $username, $password, $file) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$name = basename($params[3]['name']);
|
||||
$data = $params[3]['bits'];
|
||||
$name = basename($file['name']);
|
||||
$data = $file['bits'];
|
||||
|
||||
if (!$data) {
|
||||
return blogapi_error(t('No file sent.'));
|
||||
|
@ -279,17 +356,14 @@ function blogapi_new_media_object($req_params) {
|
|||
}
|
||||
|
||||
// Return the successful result.
|
||||
$result = new xmlrpcval(array('url' => new xmlrpcval(file_create_url($file), 'string')), 'struct');
|
||||
return new xmlrpcresp($result);
|
||||
return array('url' => file_create_url($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns a list of the taxonomy terms that can be
|
||||
* associated with a blog node.
|
||||
*/
|
||||
function blogapi_get_category_list($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
$type = _blogapi_blogid($params[0]);
|
||||
function blogapi_metaweblog_get_category_list($blogid, $username, $password) {
|
||||
$type = _blogapi_blogid($blogid);
|
||||
$vocabularies = module_invoke('taxonomy', 'get_vocabularies', $type, 'vid');
|
||||
$categories = array();
|
||||
if ($vocabularies) {
|
||||
|
@ -300,140 +374,102 @@ function blogapi_get_category_list($req_params) {
|
|||
foreach (module_invoke('taxonomy', 'get_parents', $term->tid, 'tid') as $parent) {
|
||||
$term_name = $parent->name . '/' . $term_name;
|
||||
}
|
||||
$categories[] = new xmlrpcval(array('categoryName' => new xmlrpcval($term_name, 'string'),
|
||||
'categoryId' => new xmlrpcval($term->tid, 'string')),
|
||||
'struct');
|
||||
$categories[] = array('categoryName' => $term_name, 'categoryId' => $term->tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new xmlrpcresp(new xmlrpcval($categories, 'array'));
|
||||
return $categories;
|
||||
}
|
||||
|
||||
function blogai_metaweblog_get_recent_posts($blogid, $username, $password, $number_of_posts) {
|
||||
return blogapi_blogger_get_recent_posts('0123456789ABCDEF', $blogid, $username, $password, $number_of_posts, TRUE);
|
||||
}
|
||||
|
||||
// see above
|
||||
function blogapi_mt_get_recent_post_titles($blogid, $username, $password, $number_of_posts) {
|
||||
return blogapi_blogger_get_recent_posts('0123456789ABCDEF', $blogid, $username, $password, $number_of_posts, FALSE);
|
||||
}
|
||||
|
||||
/* **** */
|
||||
function blogapi_mt_get_category_list($blogid, $username, $password) {
|
||||
return blogapi_metaweblog_get_category_list($blogid, $username, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns a list of the taxonomy terms that are
|
||||
* assigned to a particular node.
|
||||
*/
|
||||
function blogapi_get_post_categories($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_mt_get_post_categories($postid, $username, $password) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$terms = module_invoke('taxonomy', 'node_get_terms', $params[0], 'tid');
|
||||
$terms = module_invoke('taxonomy', 'node_get_terms', $postid, 'tid');
|
||||
$categories = array();
|
||||
foreach ($terms as $term) {
|
||||
$term_name = $term->name;
|
||||
foreach (module_invoke('taxonomy', 'get_parents', $term->tid, 'tid') as $parent) {
|
||||
$term_name = $parent->name . '/' . $term_name;
|
||||
}
|
||||
$categories[] = new xmlrpcval(array('categoryName' => new xmlrpcval($term_name, 'string'),
|
||||
'categoryId' => new xmlrpcval($term->tid, 'string'),
|
||||
'isPrimary' => new xmlrpcval(true, 'boolean')),
|
||||
'struct');
|
||||
$categories[] = array('categoryName' => $term_name, 'categoryId' => $term->tid, 'isPrimary' => true);
|
||||
}
|
||||
return new xmlrpcresp(new xmlrpcval($categories, 'array'));
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Assigns taxonomy terms to a particular node.
|
||||
*/
|
||||
function blogapi_set_post_categories($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
function blogapi_mt_set_post_categories($postid, $username, $password, $categories) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$nid = $params[0];
|
||||
$nid = $postid;
|
||||
$terms = array();
|
||||
foreach ($params[3] as $category) {
|
||||
foreach ($categories as $category) {
|
||||
$terms[] = $category['categoryId']->scalarval();
|
||||
}
|
||||
module_invoke('taxonomy', 'node_save', $nid, $terms);
|
||||
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Returns the latest few postings in a user's blog. $bodies TRUE
|
||||
* <a href="http://movabletype.org/docs/mtmanual_programmatic.html#item_mt%2EgetRecentPostTitles">
|
||||
* returns a bandwidth-friendly list</a>.
|
||||
*/
|
||||
function blogapi_get_recent_posts($req_params, $bodies = TRUE) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
// Remove unused appkey (from bloggerAPI).
|
||||
if (count($params) == 5) {
|
||||
$params = array_slice($params, 1);
|
||||
}
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
|
||||
$type = _blogapi_blogid($params[0]);
|
||||
$result = db_query_range('SELECT n.nid, n.title,'. ($bodies ? ' n.body,' : '') ." n.created, u.name FROM {node} n, {users} u WHERE n.uid=u.uid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $params[3]);
|
||||
while ($blog = db_fetch_object($result)) {
|
||||
$xmlrpcval = _blogapi_get_post($blog, $bodies);
|
||||
$blogs[] = $xmlrpcval;
|
||||
}
|
||||
return new xmlrpcresp(new xmlrpcval($blogs, 'array'));
|
||||
}
|
||||
|
||||
// see above
|
||||
function blogapi_get_recent_post_titles($req_params) {
|
||||
return blogapi_get_recent_posts($req_params, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Sends a list of supported methods to the client.
|
||||
*/
|
||||
function blogapi_supported_methods($req_params) {
|
||||
$methods = array_keys(blogapi_xmlrpc());
|
||||
|
||||
$output = array();
|
||||
foreach ($methods as $method) {
|
||||
$output[] = new xmlrpcval($method, 'string');
|
||||
}
|
||||
return new xmlrpcresp(new xmlrpcval($output, 'array'));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Sends a list of available input formats.
|
||||
*/
|
||||
function blogapi_supported_text_filters($req_params) {
|
||||
global $user;
|
||||
|
||||
function blogapi_mt_supported_text_filters() {
|
||||
// NOTE: we're only using anonymous' formats because the MT spec
|
||||
// does not allow for per-user formats.
|
||||
$formats = filter_formats();
|
||||
|
||||
$filters = array();
|
||||
foreach ($formats as $format) {
|
||||
$filter['key'] = new xmlrpcval($format->format, 'string');
|
||||
$filter['label'] = new xmlrpcval($format->name, 'string');
|
||||
$filters[] = new xmlrpcval($filter, 'struct');
|
||||
$filter['key'] = $format->format;
|
||||
$filter['label'] = $format->name;
|
||||
$filters[] = $filter;
|
||||
}
|
||||
|
||||
return new xmlrpcresp(new xmlrpcval($filters, 'array'));
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Can not be implemented without support from
|
||||
* trackback module.
|
||||
*/
|
||||
function blogapi_get_trackback_pings($req_params) {
|
||||
function blogapi_mt_get_trackback_pings() {
|
||||
return blogapi_error(t('Not implemented.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogging API callback. Publishes the given node
|
||||
*/
|
||||
function blogapi_publish_post($req_params) {
|
||||
$params = blogapi_convert($req_params);
|
||||
|
||||
$user = blogapi_validate_user($params[1], $params[2]);
|
||||
$node = node_load(array('nid' => $params[0]));
|
||||
function blogap_mti_publish_post($postid, $username, $password) {
|
||||
$user = blogapi_validate_user($username, $password);
|
||||
if (!$user->uid) {
|
||||
return blogapi_error($user);
|
||||
}
|
||||
$node = node_load(array('nid' => $postid));
|
||||
if (!$node) {
|
||||
return blogapi_error(t('Invalid post.'));
|
||||
}
|
||||
|
@ -445,38 +481,21 @@ function blogapi_publish_post($req_params) {
|
|||
|
||||
node_save($node);
|
||||
|
||||
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the parameters to an XMLRPC callback, and return them as an array.
|
||||
*/
|
||||
function blogapi_convert($params) {
|
||||
$cparams = array();
|
||||
$num_params= $params->getNumParams();
|
||||
|
||||
for ($i = 0; $i < $num_params; $i++) {
|
||||
$sn = $params->getParam($i);
|
||||
$cparams[] = $sn->getval();
|
||||
}
|
||||
|
||||
return $cparams;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare an error message for returning to the XMLRPC caller.
|
||||
*/
|
||||
function blogapi_error($message) {
|
||||
global $xmlrpcusererr;
|
||||
|
||||
static $xmlrpcusererr;
|
||||
if (!is_array($message)) {
|
||||
$message = array($message);
|
||||
}
|
||||
|
||||
$message = implode(' ', $message);
|
||||
|
||||
return new xmlrpcresp(0, $xmlrpcusererr + 1, strip_tags($message));
|
||||
return xmlrpc_error($xmlrpcusererr + 1, strip_tags($message));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -651,12 +670,12 @@ function _blogapi_mt_extra(&$node, $struct) {
|
|||
|
||||
function _blogapi_get_post($node, $bodies = true) {
|
||||
$xmlrpcval = array (
|
||||
'userid' => new xmlrpcval($node->name, 'string'),
|
||||
'dateCreated' => new xmlrpcval(iso8601_encode($node->created), 'dateTime.iso8601'),
|
||||
'title' => new xmlrpcval($node->title, 'string'),
|
||||
'postid' => new xmlrpcval($node->nid, 'string'),
|
||||
'link' => new xmlrpcval(url('node/'.$node->nid, NULL, NULL, true)),
|
||||
'permaLink' => new xmlrpcval(url('node/'.$node->nid, NULL, NULL, true)),
|
||||
'userid' => $node->name,
|
||||
'dateCreated' => xmlrpc_date($node->created),
|
||||
'title' => $node->title,
|
||||
'postid' => $node->nid,
|
||||
'link' => url('node/'.$node->nid, NULL, NULL, true),
|
||||
'permaLink' => url('node/'.$node->nid, NULL, NULL, true),
|
||||
);
|
||||
if ($bodies) {
|
||||
if ($node->comment = 1) {
|
||||
|
@ -666,14 +685,14 @@ function _blogapi_get_post($node, $bodies = true) {
|
|||
$comment = 1;
|
||||
}
|
||||
|
||||
$xmlrpcval['content'] = new xmlrpcval("<title>$blog->title</title>$node->body", 'string');
|
||||
$xmlrpcval['description'] = new xmlrpcval($node->body, 'string');
|
||||
$xmlrpcval['content'] = "<title>$node->title</title>$node->body";
|
||||
$xmlrpcval['description'] = $node->body;
|
||||
// Add MT specific fields
|
||||
$xmlrpcval['mt_allow_comments'] = new xmlrpcval($comment, 'int');
|
||||
$xmlrpcval['mt_convert_breaks'] = new xmlrpcval($node->format, 'string');
|
||||
$xmlrpcval['mt_allow_comments'] = $comment;
|
||||
$xmlrpcval['mt_convert_breaks'] = $node->format;
|
||||
}
|
||||
|
||||
return new xmlrpcval($xmlrpcval, 'struct');
|
||||
return $xmlrpcval;
|
||||
}
|
||||
|
||||
function _blogapi_blogid($id) {
|
||||
|
|
|
@ -70,22 +70,15 @@ function drupal_cron() {
|
|||
/**
|
||||
* Callback function from drupal_xmlrpc() called when another site pings this one.
|
||||
*/
|
||||
function drupal_directory_ping($arguments) {
|
||||
function drupal_directory_ping($link, $name, $mail, $slogan, $mission) {
|
||||
|
||||
/*
|
||||
** Parse our parameters:
|
||||
*/
|
||||
|
||||
$argument = $arguments->getparam(0);
|
||||
$link = strip_tags($argument->scalarval());
|
||||
$argument = $arguments->getparam(1);
|
||||
$name = trim(strip_tags($argument->scalarval()));
|
||||
$argument = $arguments->getparam(2);
|
||||
$mail = strip_tags($argument->scalarval());
|
||||
$argument = $arguments->getparam(3);
|
||||
$slogan = strip_tags($argument->scalarval());
|
||||
$argument = $arguments->getparam(4);
|
||||
$mission = strip_tags($argument->scalarval());
|
||||
foreach (array('link', 'name', 'mail', 'slogan', 'mission') as $key) {
|
||||
$$key = strip_tags($$key);
|
||||
}
|
||||
|
||||
/*
|
||||
** Update the data in our database and send back a reply:
|
||||
|
@ -97,10 +90,10 @@ function drupal_directory_ping($arguments) {
|
|||
|
||||
watchdog('directory ping', t('Ping from %name (%link).', array('%name' => theme('placeholder', $name), '%link' => theme('placeholder', $link))), WATCHDOG_NOTICE, '<a href="'. check_url($link) .'">view</a>');
|
||||
|
||||
return new xmlrpcresp(new xmlrpcval(1, 'int'));
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return new xmlrpcresp(new xmlrpcval(0, 'int'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -127,7 +120,17 @@ function drupal_directory_page($sort = 'name') {
|
|||
* Implementation of hook_xmlrpc().
|
||||
*/
|
||||
function drupal_xmlrpc() {
|
||||
return array('drupal.site.ping' => array('function' => 'drupal_directory_ping'), 'drupal.login' => array('function' => 'drupal_login'));
|
||||
return array(
|
||||
array(
|
||||
'drupal.site.ping',
|
||||
'drupal_directory_ping',
|
||||
array('boolean', 'string', 'string', 'string', 'string', 'string'),
|
||||
t('Handling ping request')),
|
||||
array(
|
||||
'drupal.login',
|
||||
'drupal_login',
|
||||
array('int', 'string', 'string'),
|
||||
t('Logging into a drupal site')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,16 +139,10 @@ function drupal_xmlrpc() {
|
|||
function drupal_notify($server) {
|
||||
global $base_url;
|
||||
|
||||
$url = parse_url($server);
|
||||
$result = xmlrpc($server, 'drupal.site.ping', $base_url, variable_get('site_name', ''), variable_get('site_mail', ''), variable_get('site_slogan', ''), variable_get('site_mission', ''));
|
||||
|
||||
$client = new xmlrpc_client($url['path'], $url['host'], 80);
|
||||
|
||||
$message = new xmlrpcmsg('drupal.site.ping', array(new xmlrpcval($base_url, 'string'), new xmlrpcval(variable_get('site_name', ''), 'string'), new xmlrpcval(variable_get('site_mail', ''), 'string'), new xmlrpcval(variable_get('site_slogan', ''), 'string'), new xmlrpcval(variable_get('site_mission', ''), 'string')));
|
||||
|
||||
$result = $client->send($message, 5);
|
||||
|
||||
if (!$result || $result->faultCode()) {
|
||||
watchdog('directory ping', t('Failed to notify %url at %path: %error.', array('%url' => theme('placeholder', $url['host']), '%path' => theme('placeholder', $url['path']), '%error' => theme('placeholder', $result->faultString()))), WATCHDOG_WARNING);
|
||||
if ($result === FALSE) {
|
||||
watchdog('directory ping', t('Failed to notify %server, error code: %errno, error message: %error_msg.', array('%server' => theme('placeholder', $server), '%errno' => theme('placeholder', xmlrpc_errno()), '%error_msg' => theme('placeholder', xmlrpc_error_msg()))), WATCHDOG_WARNING);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -169,19 +166,13 @@ function drupal_info($field = 0) {
|
|||
* Implementation of hook_auth().
|
||||
*/
|
||||
function drupal_auth($username, $password, $server) {
|
||||
|
||||
$message = new xmlrpcmsg('drupal.login', array(new xmlrpcval($username, 'string'), new xmlrpcval($password, 'string')));
|
||||
|
||||
// TODO remove hard coded Port 80
|
||||
// TODO manage server/path such that HTTP_HOST/xml.rpc.php is not assumed
|
||||
$client = new xmlrpc_client('/xmlrpc.php', $server, 80);
|
||||
$result = $client->send($message, 5);
|
||||
if ($result && !$result->faultCode()) {
|
||||
$value = $result->value();
|
||||
$login = $value->scalarval();
|
||||
$result = xmlrpc('http://'. $server .'/xmlrpc.php', 'drupal.login', $username, $password);
|
||||
if ($result === FALSE) {
|
||||
drupal_set_message(t('Error %code : %message', array('%code' => theme('placeholder', xmlrpc_errno()), '%message' => theme('placeholder', xmlrpc_error_msg()))), 'error');
|
||||
}
|
||||
else {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $login;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,17 +200,12 @@ function drupal_page_help() {
|
|||
*
|
||||
* Remote clients are usually other Drupal instances.
|
||||
*/
|
||||
function drupal_login($arguments) {
|
||||
$argument = $arguments->getparam(0);
|
||||
$username = $argument->scalarval();
|
||||
$argument = $arguments->getparam(1);
|
||||
$password = $argument->scalarval();
|
||||
|
||||
function drupal_login($username, $password) {
|
||||
if ($user = user_load(array('name' => $username, 'pass' => $password, 'status' => 1))) {
|
||||
return new xmlrpcresp(new xmlrpcval($user->uid, 'int'));
|
||||
return $user->uid;
|
||||
}
|
||||
else {
|
||||
return new xmlrpcresp(new xmlrpcval(0, 'int'));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,22 +70,15 @@ function drupal_cron() {
|
|||
/**
|
||||
* Callback function from drupal_xmlrpc() called when another site pings this one.
|
||||
*/
|
||||
function drupal_directory_ping($arguments) {
|
||||
function drupal_directory_ping($link, $name, $mail, $slogan, $mission) {
|
||||
|
||||
/*
|
||||
** Parse our parameters:
|
||||
*/
|
||||
|
||||
$argument = $arguments->getparam(0);
|
||||
$link = strip_tags($argument->scalarval());
|
||||
$argument = $arguments->getparam(1);
|
||||
$name = trim(strip_tags($argument->scalarval()));
|
||||
$argument = $arguments->getparam(2);
|
||||
$mail = strip_tags($argument->scalarval());
|
||||
$argument = $arguments->getparam(3);
|
||||
$slogan = strip_tags($argument->scalarval());
|
||||
$argument = $arguments->getparam(4);
|
||||
$mission = strip_tags($argument->scalarval());
|
||||
foreach (array('link', 'name', 'mail', 'slogan', 'mission') as $key) {
|
||||
$$key = strip_tags($$key);
|
||||
}
|
||||
|
||||
/*
|
||||
** Update the data in our database and send back a reply:
|
||||
|
@ -97,10 +90,10 @@ function drupal_directory_ping($arguments) {
|
|||
|
||||
watchdog('directory ping', t('Ping from %name (%link).', array('%name' => theme('placeholder', $name), '%link' => theme('placeholder', $link))), WATCHDOG_NOTICE, '<a href="'. check_url($link) .'">view</a>');
|
||||
|
||||
return new xmlrpcresp(new xmlrpcval(1, 'int'));
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return new xmlrpcresp(new xmlrpcval(0, 'int'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -127,7 +120,17 @@ function drupal_directory_page($sort = 'name') {
|
|||
* Implementation of hook_xmlrpc().
|
||||
*/
|
||||
function drupal_xmlrpc() {
|
||||
return array('drupal.site.ping' => array('function' => 'drupal_directory_ping'), 'drupal.login' => array('function' => 'drupal_login'));
|
||||
return array(
|
||||
array(
|
||||
'drupal.site.ping',
|
||||
'drupal_directory_ping',
|
||||
array('boolean', 'string', 'string', 'string', 'string', 'string'),
|
||||
t('Handling ping request')),
|
||||
array(
|
||||
'drupal.login',
|
||||
'drupal_login',
|
||||
array('int', 'string', 'string'),
|
||||
t('Logging into a drupal site')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,16 +139,10 @@ function drupal_xmlrpc() {
|
|||
function drupal_notify($server) {
|
||||
global $base_url;
|
||||
|
||||
$url = parse_url($server);
|
||||
$result = xmlrpc($server, 'drupal.site.ping', $base_url, variable_get('site_name', ''), variable_get('site_mail', ''), variable_get('site_slogan', ''), variable_get('site_mission', ''));
|
||||
|
||||
$client = new xmlrpc_client($url['path'], $url['host'], 80);
|
||||
|
||||
$message = new xmlrpcmsg('drupal.site.ping', array(new xmlrpcval($base_url, 'string'), new xmlrpcval(variable_get('site_name', ''), 'string'), new xmlrpcval(variable_get('site_mail', ''), 'string'), new xmlrpcval(variable_get('site_slogan', ''), 'string'), new xmlrpcval(variable_get('site_mission', ''), 'string')));
|
||||
|
||||
$result = $client->send($message, 5);
|
||||
|
||||
if (!$result || $result->faultCode()) {
|
||||
watchdog('directory ping', t('Failed to notify %url at %path: %error.', array('%url' => theme('placeholder', $url['host']), '%path' => theme('placeholder', $url['path']), '%error' => theme('placeholder', $result->faultString()))), WATCHDOG_WARNING);
|
||||
if ($result === FALSE) {
|
||||
watchdog('directory ping', t('Failed to notify %server, error code: %errno, error message: %error_msg.', array('%server' => theme('placeholder', $server), '%errno' => theme('placeholder', xmlrpc_errno()), '%error_msg' => theme('placeholder', xmlrpc_error_msg()))), WATCHDOG_WARNING);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -169,19 +166,13 @@ function drupal_info($field = 0) {
|
|||
* Implementation of hook_auth().
|
||||
*/
|
||||
function drupal_auth($username, $password, $server) {
|
||||
|
||||
$message = new xmlrpcmsg('drupal.login', array(new xmlrpcval($username, 'string'), new xmlrpcval($password, 'string')));
|
||||
|
||||
// TODO remove hard coded Port 80
|
||||
// TODO manage server/path such that HTTP_HOST/xml.rpc.php is not assumed
|
||||
$client = new xmlrpc_client('/xmlrpc.php', $server, 80);
|
||||
$result = $client->send($message, 5);
|
||||
if ($result && !$result->faultCode()) {
|
||||
$value = $result->value();
|
||||
$login = $value->scalarval();
|
||||
$result = xmlrpc('http://'. $server .'/xmlrpc.php', 'drupal.login', $username, $password);
|
||||
if ($result === FALSE) {
|
||||
drupal_set_message(t('Error %code : %message', array('%code' => theme('placeholder', xmlrpc_errno()), '%message' => theme('placeholder', xmlrpc_error_msg()))), 'error');
|
||||
}
|
||||
else {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $login;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,17 +200,12 @@ function drupal_page_help() {
|
|||
*
|
||||
* Remote clients are usually other Drupal instances.
|
||||
*/
|
||||
function drupal_login($arguments) {
|
||||
$argument = $arguments->getparam(0);
|
||||
$username = $argument->scalarval();
|
||||
$argument = $arguments->getparam(1);
|
||||
$password = $argument->scalarval();
|
||||
|
||||
function drupal_login($username, $password) {
|
||||
if ($user = user_load(array('name' => $username, 'pass' => $password, 'status' => 1))) {
|
||||
return new xmlrpcresp(new xmlrpcval($user->uid, 'int'));
|
||||
return $user->uid;
|
||||
}
|
||||
else {
|
||||
return new xmlrpcresp(new xmlrpcval(0, 'int'));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,12 +57,9 @@ function _ping_notify($name, $url) {
|
|||
*/
|
||||
function ping_ping($name = '', $url = '') {
|
||||
|
||||
$feed = url('node/feed', NULL, NULL, TRUE);
|
||||
$client = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
|
||||
$message = new xmlrpcmsg('weblogUpdates.ping', array(new xmlrpcval($name), new xmlrpcval($url)));
|
||||
$result = $client->send($message);
|
||||
$result = xmlrpc('http://rpc.pingomatic.com', 'weblogUpdates.ping', $name, $url);
|
||||
|
||||
if (!$result || $result->faultCode()) {
|
||||
if ($result === FALSE) {
|
||||
watchdog('directory ping', t('Failed to notify pingomatic.com (site).'), WATCHDOG_WARNING);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,12 +57,9 @@ function _ping_notify($name, $url) {
|
|||
*/
|
||||
function ping_ping($name = '', $url = '') {
|
||||
|
||||
$feed = url('node/feed', NULL, NULL, TRUE);
|
||||
$client = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
|
||||
$message = new xmlrpcmsg('weblogUpdates.ping', array(new xmlrpcval($name), new xmlrpcval($url)));
|
||||
$result = $client->send($message);
|
||||
$result = xmlrpc('http://rpc.pingomatic.com', 'weblogUpdates.ping', $name, $url);
|
||||
|
||||
if (!$result || $result->faultCode()) {
|
||||
if ($result === FALSE) {
|
||||
watchdog('directory ping', t('Failed to notify pingomatic.com (site).'), WATCHDOG_WARNING);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,5 @@ include_once 'includes/bootstrap.inc';
|
|||
drupal_bootstrap('full');
|
||||
include_once 'includes/xmlrpcs.inc';
|
||||
|
||||
$functions = module_invoke_all('xmlrpc');
|
||||
|
||||
$server = new xmlrpc_server($functions);
|
||||
|
||||
xmlrpc_server(module_invoke_all('xmlrpc'));
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue