addParam($pars[$i]);
- }
- }
-
- function xml_header() {
- return "\n\n";
- }
-
- function xml_footer() {
- return "\n";
- }
-
- function createPayload() {
- $this->payload=$this->xml_header();
- $this->payload.="" . $this->methodname . "\n";
- // if (sizeof($this->params)) {
- $this->payload.="\n";
- for($i=0; $iparams); $i++) {
- $p=$this->params[$i];
- $this->payload.="\n" . $p->serialize() .
- "\n";
- }
- $this->payload.="\n";
- // }
- $this->payload.=$this->xml_footer();
- $this->payload=str_replace("\n", "\r\n", $this->payload);
- }
-
- function method($meth="") {
- if ($meth!="") {
- $this->methodname=$meth;
- }
- return $this->methodname;
- }
-
- function serialize() {
- $this->createPayload();
- return $this->payload;
- }
-
- function addParam($par) { $this->params[]=$par; }
- function getParam($i) { return $this->params[$i]; }
- function getNumParams() { return sizeof($this->params); }
-
- function parseResponseFile($fp) {
- $ipd="";
-
- while($data=fread($fp, 32768)) {
- $ipd.=$data;
- }
- return $this->parseResponse($ipd);
- }
-
- function parseResponse($data="") {
- global $_xh,$xmlrpcerr,$xmlrpcstr;
-
-
- $xmlparser = drupal_xml_parser_create($data);
- $parser = (int)$xmlparser;
-
- $_xh[$parser]=array();
-
- $_xh[$parser]['st']="";
- $_xh[$parser]['cm']=0;
- $_xh[$parser]['isf']=0;
- $_xh[$parser]['ac']="";
- $_xh[$parser]['qt']="";
- $_xh[$parser]['ha']="";
- $_xh[$parser]['ac']="";
-
- xml_parser_set_option($xmlparser, XML_OPTION_CASE_FOLDING, true);
- xml_set_element_handler($xmlparser, "xmlrpc_se", "xmlrpc_ee");
- xml_set_character_data_handler($xmlparser, "xmlrpc_cd");
- xml_set_default_handler($xmlparser, "xmlrpc_dh");
- $xmlrpc_value=new xmlrpcval;
-
- if ($this->debug)
-##print "---GOT---\n" . htmlspecialchars($data) . "\n---END---\n
";
-##print "---GOT---\n" . nl2br(htmlspecialchars($data)) . "\n---END---\n
";
- print "---GOT---\n" . nl2br($data) . "\n---END---\n
";
- if ($data=="") {
- error_log("No response received from server.");
- $r=new xmlrpcresp(0, $xmlrpcerr["no_data"],
- $xmlrpcstr["no_data"]);
- xml_parser_free($xmlparser);
- return $r;
- }
- // see if we got an HTTP 200 OK, else bomb
- // but only do this if we're using the HTTP protocol.
- if (ereg("^HTTP",$data) &&
- !ereg("^HTTP/[0-9\.]+ 200 ", $data)) {
- $errstr= substr($data, 0, strpos($data, "\n")-1);
- error_log("HTTP error, got response: " .$errstr);
- $r=new xmlrpcresp(0, $xmlrpcerr["http_error"],
- $xmlrpcstr["http_error"]. " (" . $errstr . ")");
- xml_parser_free($xmlparser);
- return $r;
- }
-
- // if using HTTP, then gotta get rid of HTTP headers here
- // and we store them in the 'ha' bit of our data array
- if (ereg("^HTTP", $data)) {
- $ar=explode("\r\n", $data);
- $newdata="";
- $hdrfnd=0;
- for ($i=0; $i0) {
- $_xh[$parser]['ha'].=$ar[$i]. "\r\n";
- } else {
- $hdrfnd=1;
- }
- } else {
- $newdata.=$ar[$i] . "\r\n";
- }
- }
- $data=$newdata;
- }
-
- if (!xml_parse($xmlparser, $data, sizeof($data))) {
- // thanks to Peter Kocks
- if((xml_get_current_line_number($xmlparser)) == 1)
- $errstr = "XML error at line 1, check URL";
- else
- $errstr = sprintf("XML error: %s at line %d",
- xml_error_string(xml_get_error_code($xmlparser)),
- xml_get_current_line_number($xmlparser));
- error_log($errstr);
- $r=new xmlrpcresp(0, $xmlrpcerr["invalid_return"],
- $xmlrpcstr["invalid_return"]);
- xml_parser_free($xmlparser);
- return $r;
- }
- xml_parser_free($xmlparser);
- if ($this->debug) {
- print "---EVALING---[" .
- strlen($_xh[$parser]['st']) . " chars]---\n" .
- htmlspecialchars($_xh[$parser]['st']) . ";\n---END---
";
- }
- if (strlen($_xh[$parser]['st'])==0) {
- // then something odd has happened
- // and it's time to generate a client side error
- // indicating something odd went on
- $r=new xmlrpcresp(0, $xmlrpcerr["invalid_return"],
- $xmlrpcstr["invalid_return"]);
- } else {
- eval('$v=' . $_xh[$parser]['st'] . '; $allOK=1;');
- if ($_xh[$parser]['isf']) {
- $f=$v->structmem("faultCode");
- $fs=$v->structmem("faultString");
- $r=new xmlrpcresp($v, $f->scalarval(),
- $fs->scalarval());
- } else {
- $r=new xmlrpcresp($v);
- }
- }
- $r->hdrs=split("\r?\n", $_xh[$parser]['ha']);
- return $r;
- }
-
+/**
+ * Returns the last XML-RPC client error message
+ */
+function xmlrpc_error_msg() {
+ $error = xmlrpc_error();
+ return $error->message;
}
-
-class xmlrpcval {
- var $me=array();
- var $mytype=0;
-
- function xmlrpcval($val=-1, $type="") {
- global $xmlrpcTypes;
- $this->me=array();
- $this->mytype=0;
- if ($val!=-1 || $type!="") {
- if ($type=="") $type="string";
- if ($xmlrpcTypes[$type]==1) {
- $this->addScalar($val,$type);
- }
- else if ($xmlrpcTypes[$type]==2)
- $this->addArray($val);
- else if ($xmlrpcTypes[$type]==3)
- $this->addStruct($val);
- }
- }
-
- function addScalar($val, $type="string") {
- global $xmlrpcTypes, $xmlrpcBoolean;
-
- if ($this->mytype==1) {
- echo "xmlrpcval: scalar can have only one value
";
- return 0;
- }
- $typeof=$xmlrpcTypes[$type];
- if ($typeof!=1) {
- echo "xmlrpcval: not a scalar type (${typeof})
";
- return 0;
- }
-
- if ($type==$xmlrpcBoolean) {
- if (strcasecmp($val,"true")==0 ||
- $val==1 || ($val==true &&
- strcasecmp($val,"false"))) {
- $val=1;
- } else {
- $val=0;
- }
- }
-
- if ($this->mytype==2) {
- // we're adding to an array here
- $ar=$this->me["array"];
- $ar[]=new xmlrpcval($val, $type);
- $this->me["array"]=$ar;
- } else {
- // a scalar, so set the value and remember we're scalar
- $this->me[$type]=$val;
- $this->mytype=$typeof;
- }
- return 1;
- }
-
- function addArray($vals) {
- global $xmlrpcTypes;
- if ($this->mytype!=0) {
- echo "xmlrpcval: already initialized as a [" .
- $this->kindOf() . "]
";
- return 0;
- }
-
- $this->mytype=$xmlrpcTypes["array"];
- $this->me["array"]=$vals;
- return 1;
- }
-
- function addStruct($vals) {
- global $xmlrpcTypes;
- if ($this->mytype!=0) {
- echo "xmlrpcval: already initialized as a [" .
- $this->kindOf() . "]
";
- return 0;
- }
- $this->mytype=$xmlrpcTypes["struct"];
- $this->me["struct"]=$vals;
- return 1;
- }
-
- function dump($ar) {
- reset($ar);
- while ( list( $key, $val ) = each( $ar ) ) {
- echo "$key => $val
";
- if ($key == 'array')
- while ( list( $key2, $val2 ) = each( $val ) ) {
- echo "-- $key2 => $val2
";
- }
- }
- }
-
- function kindOf() {
- switch($this->mytype) {
- case 3:
- return "struct";
- break;
- case 2:
- return "array";
- break;
- case 1:
- return "scalar";
- break;
- default:
- return "undef";
- }
- }
-
- function serializedata($typ, $val) {
- $rs="";
- global $xmlrpcTypes, $xmlrpcBase64, $xmlrpcString,
- $xmlrpcBoolean;
- switch($xmlrpcTypes[$typ]) {
- case 3:
- // struct
- $rs.="\n";
- reset($val);
- while(list($key2, $val2)=each($val)) {
- $rs.="${key2}\n";
- $rs.=$this->serializeval($val2);
- $rs.="\n";
- }
- $rs.="";
- break;
- case 2:
- // array
- $rs.="\n\n";
- for($i=0; $iserializeval($val[$i]);
- }
- $rs.="\n";
- break;
- case 1:
- switch ($typ) {
- case $xmlrpcBase64:
- $rs.="<${typ}>" . base64_encode($val) . "${typ}>";
- break;
- case $xmlrpcBoolean:
- $rs.="<${typ}>" . ($val ? "1" : "0") . "${typ}>";
- break;
- case $xmlrpcString:
- $rs.="<${typ}>" . htmlspecialchars($val). "${typ}>";
- break;
- default:
- $rs.="<${typ}>${val}${typ}>";
- }
- break;
- default:
- break;
- }
- return $rs;
- }
-
- function serialize() {
- return $this->serializeval($this);
- }
-
- function serializeval($o) {
- global $xmlrpcTypes;
- $rs="";
- $ar=$o->me;
- reset($ar);
- list($typ, $val) = each($ar);
- $rs.="";
- $rs.=$this->serializedata($typ, $val);
- $rs.="\n";
- return $rs;
- }
-
- function structmem($m) {
- $nv=$this->me["struct"][$m];
- return $nv;
- }
-
- function structreset() {
- reset($this->me["struct"]);
- }
-
- function structeach() {
- return each($this->me["struct"]);
- }
-
- function getval() {
- // UNSTABLE
- global $xmlrpcBoolean, $xmlrpcBase64;
- reset($this->me);
- list($a,$b)=each($this->me);
- // contributed by I Sofer, 2001-03-24
- // add support for nested arrays to scalarval
- // I've created a new method here, so as to
- // preserve back compatibility
-
- if (is_array($b)) {
- foreach ($b as $id => $cont) {
- $b[$id] = $cont->scalarval();
- }
- }
-
- // add support for structures directly encoding php objects
- if (is_object($b)) {
- $t = get_object_vars($b);
- foreach ($t as $id => $cont) {
- $t[$id] = $cont->scalarval();
- }
- foreach ($t as $id => $cont) {
- eval('$b->'.$id.' = $cont;');
- }
- }
- // end contrib
- return $b;
- }
-
- function scalarval() {
- global $xmlrpcBoolean, $xmlrpcBase64;
- reset($this->me);
- list($a,$b)=each($this->me);
- return $b;
- }
-
- function scalartyp() {
- global $xmlrpcI4, $xmlrpcInt;
- reset($this->me);
- list($a,$b)=each($this->me);
- if ($a==$xmlrpcI4)
- $a=$xmlrpcInt;
- return $a;
- }
-
- function arraymem($m) {
- $nv=$this->me["array"][$m];
- return $nv;
- }
-
- function arraysize() {
- reset($this->me);
- list($a,$b)=each($this->me);
- return sizeof($b);
- }
-}
-
-// date helpers
-function iso8601_encode($timet, $utc=0) {
- // return an ISO8601 encoded string
- // really, timezones ought to be supported
- // but the XML-RPC spec says:
- //
- // "Don't assume a timezone. It should be specified by the server in its
- // documentation what assumptions it makes about timezones."
- //
- // these routines always assume localtime unless
- // $utc is set to 1, in which case UTC is assumed
- // and an adjustment for locale is made when encoding
- if (!$utc) {
- $t=strftime("%Y%m%dT%H:%M:%S", $timet);
- } else {
- if (function_exists("gmstrftime"))
- // gmstrftime doesn't exist in some versions
- // of PHP
- $t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
- else {
- $t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z"));
- }
- }
- return $t;
-}
-
-function iso8601_decode($idate, $utc=0) {
- // return a timet in the localtime, or UTC
- $t=0;
- if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})",
- $idate, $regs)) {
- if ($utc) {
- $t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
- } else {
- $t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
- }
- }
- return $t;
-}
-
-/*****************************************************************
- * _xmlrpc_decode takes a message in PHP xmlrpc object format and *
- * translates it into native PHP types. *
- * *
- * author: Dan Libby (dan@libby.com) *
- *****************************************************************/
-function _xmlrpc_decode($xmlrpc_val) {
- $kind = $xmlrpc_val->kindOf();
-
- if($kind == "scalar") {
- return $xmlrpc_val->scalarval();
- }
- else if($kind == "array") {
- $size = $xmlrpc_val->arraysize();
- $arr = array();
-
- for($i = 0; $i < $size; $i++) {
- $arr[]=_xmlrpc_decode($xmlrpc_val->arraymem($i));
- }
- return $arr;
- }
- else if($kind == "struct") {
- $xmlrpc_val->structreset();
- $arr = array();
-
- while(list($key,$value)=$xmlrpc_val->structeach()) {
- $arr[$key] = _xmlrpc_decode($value);
- }
- return $arr;
- }
-}
-
-/****************************************************************
- * _xmlrpc_encode takes native php types and encodes them into *
- * xmlrpc PHP object format. *
- * BUG: All sequential arrays are turned into structs. I don't *
- * know of a good way to determine if an array is sequential *
- * only. *
- * *
- * feature creep -- could support more types via optional type *
- * argument. *
- * *
- * author: Dan Libby (dan@libby.com) *
- ****************************************************************/
-function _xmlrpc_encode($php_val) {
- global $xmlrpcInt;
- global $xmlrpcDouble;
- global $xmlrpcString;
- global $xmlrpcArray;
- global $xmlrpcStruct;
- global $xmlrpcBoolean;
-
- $type = gettype($php_val);
- $xmlrpc_val = new xmlrpcval;
-
- switch($type) {
- case "array":
- case "object":
- $arr = array();
- while (list($k,$v) = each($php_val)) {
- $arr[$k] = _xmlrpc_encode($v);
- }
- $xmlrpc_val->addStruct($arr);
- break;
- case "integer":
- $xmlrpc_val->addScalar($php_val, $xmlrpcInt);
- break;
- case "double":
- $xmlrpc_val->addScalar($php_val, $xmlrpcDouble);
- break;
- case "string":
- $xmlrpc_val->addScalar($php_val, $xmlrpcString);
- break;
- //
- // Add support for encoding/decoding of booleans, since they are supported in PHP
- case "boolean":
- $xmlrpc_val->addScalar($php_val, $xmlrpcBoolean);
- break;
- //
- case "unknown type":
- default:
- // giancarlo pinerolo
- // it has to return
- // an empty object in case (which is already
- // at this point), not a boolean.
- break;
- }
- return $xmlrpc_val;
-}
-
?>
diff --git a/includes/xmlrpcs.inc b/includes/xmlrpcs.inc
index 6c1fe80aa84..f50b3d78821 100644
--- a/includes/xmlrpcs.inc
+++ b/includes/xmlrpcs.inc
@@ -1,301 +1,285 @@
-// $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 = '
+
+
+
+ '.
+ xmlrpc_value_get_xml($r)
+ .'
+
+
+
+
+';
+ // 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 "\n";
- if (isset($dmap[$methName])) {
- if ($dmap[$methName]["signature"]) {
- $sigs=array();
- $thesigs=$dmap[$methName]["signature"];
- for($i=0; $i'."\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 "\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 "\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="\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; $igetNumParams()+1) {
- $itsOK=1;
- for($n=0; $n<$in->getNumParams(); $n++) {
- $p=$in->getParam($n);
- // print "\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\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];
+}
+
+?>
\ No newline at end of file
diff --git a/modules/blogapi.module b/modules/blogapi.module
index a6c73a0d793..3fe48489ea6 100644
--- a/modules/blogapi.module
+++ b/modules/blogapi.module
@@ -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' => ''. t($node->type) .'', '%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' => ''. t($node->type) .'', '%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
+ *
+ * returns a bandwidth-friendly list.
*/
-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
- *
- * returns a bandwidth-friendly list.
- */
-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("$blog->title$node->body", 'string');
- $xmlrpcval['description'] = new xmlrpcval($node->body, 'string');
+ $xmlrpcval['content'] = "$node->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) {
diff --git a/modules/blogapi/blogapi.module b/modules/blogapi/blogapi.module
index a6c73a0d793..3fe48489ea6 100644
--- a/modules/blogapi/blogapi.module
+++ b/modules/blogapi/blogapi.module
@@ -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' => ''. t($node->type) .'', '%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' => ''. t($node->type) .'', '%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
+ *
+ * returns a bandwidth-friendly list.
*/
-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
- *
- * returns a bandwidth-friendly list.
- */
-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("$blog->title$node->body", 'string');
- $xmlrpcval['description'] = new xmlrpcval($node->body, 'string');
+ $xmlrpcval['content'] = "$node->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) {
diff --git a/modules/drupal.module b/modules/drupal.module
index 90cccf0285d..de2e32fa864 100644
--- a/modules/drupal.module
+++ b/modules/drupal.module
@@ -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, 'view');
- 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;
}
}
diff --git a/modules/drupal/drupal.module b/modules/drupal/drupal.module
index 90cccf0285d..de2e32fa864 100644
--- a/modules/drupal/drupal.module
+++ b/modules/drupal/drupal.module
@@ -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, 'view');
- 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;
}
}
diff --git a/modules/ping.module b/modules/ping.module
index bf392c586a0..4b88e861cd6 100644
--- a/modules/ping.module
+++ b/modules/ping.module
@@ -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);
}
}
diff --git a/modules/ping/ping.module b/modules/ping/ping.module
index bf392c586a0..4b88e861cd6 100644
--- a/modules/ping/ping.module
+++ b/modules/ping/ping.module
@@ -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);
}
}
diff --git a/xmlrpc.php b/xmlrpc.php
index d93055075c7..408f4406205 100644
--- a/xmlrpc.php
+++ b/xmlrpc.php
@@ -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'));
?>