From 36f52b47f8dc996afcc889b1fd32fd23943103c5 Mon Sep 17 00:00:00 2001 From: marcus Date: Mon, 4 Aug 2008 13:55:15 +0000 Subject: XML-RPC helper functions suggested by Misja git-svn-id: https://code.elgg.org/elgg/trunk@1681 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/xml-rpc.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'engine') diff --git a/engine/lib/xml-rpc.php b/engine/lib/xml-rpc.php index 6e078c875..83ba17d98 100644 --- a/engine/lib/xml-rpc.php +++ b/engine/lib/xml-rpc.php @@ -415,6 +415,76 @@ END; } } + + // Helper functions /////////////////////////////////////////////////////////////////////// + + /** + * parse XMLRPCCall parameters + * + * Convert an XMLRPCCall result array into native data types + * + * @param array $parameters + * @return array + */ + function xmlrpc_parse_params($parameters) + { + $result = array(); + + foreach ($parameters as $parameter) + { + $result[] = xmlrpc_scalar_value($parameter); + } + + return $result; + } + + /** + * Extract the scalar value of an XMLObject type result array + * + * @param XMLObject $object + * @return mixed + */ + function xmlrpc_scalar_value($object) + { + if ($object->name == 'param') + { + $object = $object->children[0]->children[0]; + } + + switch ($object->name) + { + case 'string': + return $object->content; + case 'array': + foreach ($object->children[0]->children as $child) + { + $value[] = xmlrpc_scalar_value($child); + } + return $value; + case 'struct': + foreach ($object->children as $child) + { + $value[$child->children[0]->content] = xmlrpc_scalar_value($child->children[1]->children[0]); + } + return $value; + case 'boolean': + return (boolean) $object->content; + case 'int': + return (int) $object->content; + case 'double': + return (double) $object->content; + case 'dateTime.iso8601': + return (int) strtotime($object->content); + case 'base64': + return base64_decode($object->content); + case 'value': + return xmlrpc_scalar_value($object->children[0]); + default: + // TODO unsupported, throw an error + return false; + } + } + // Functions for adding handlers ////////////////////////////////////////////////////////// /** XML-RPC Handlers */ -- cgit v1.2.3