Converting legacy (4.5.4/4.6.2 and below) XML-RPC library to new implementation
The first Drupal versions to use the new library are 4.5.5, 4.6.3 and 4.7. If you have a custom written Drupal module for an older version, then the following applies.
In hook_xmlrpc
<?php
return array('foaf.getUrl' => array('function' => 'foaf_get_url'));
?>becomes
<?php
return array('foaf.getUrl' => 'foaf_get_url');
?>Now let's see the handler function itself. It's parameters are regular PHP variables now, there is nothing to process. So now you can write things like function blogapi_blogger_get_user_info($appkey, $username, $password) instead of doing parameter processing.
Return becomes a lot simpler, too:
<?php
return new xmlrpcresp(new xmlrpcval($string, 'string'));
?>becomes
<?php
return $string;
?>Client side:
<?php
// send an xmlrpc message to the server to get a full foaf url
$message = new xmlrpcmsg('foaf.getUrl', array(new xmlrpcval($name,
'string')));
$client = new xmlrpc_client('/xmlrpc.php', $server, 80);
if ($result && !$result->faultCode()) {
$value = $result->value();
$user->foaf_url = $value->scalarval();
}
?>this becomes
<?php
$result = xmlrpc($server. '/xmlrpc.php', 'foaf.getUrl', $name);
if ($result !== FALSE) {
$user->foaf_url = $result;
}
?>Back to method handlers. All the efforts that are made to make the PHP --
XML-RPC conversations transparent can't handle date and base64 encoding.
So:
<?php
$node->created = iso8601_decode($struct['dateCreated'], 1);
?>becomes
<?php
$node->created = mktime($struct['dateCreated']->hour,
$struct['dateCreated']->minute, $struct['dateCreated']->second,
$struct['dateCreated']->month, $struct['dateCreated']->day,
$struct['dateCreated']->year);
?>And if you want to return a date (either a Unix timestamp or an ISO 8601
formatted one):
<?php
return xmlrpc_date($node->created);
?>otherwise you'd get a return type of int for Unix timestamp and string for
ISO.
Likewise, to make the distinction between base64 and string, you need to
xmlrpc_base64($binary_data) your binary data.
