aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-08-04 13:55:15 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-08-04 13:55:15 +0000
commit36f52b47f8dc996afcc889b1fd32fd23943103c5 (patch)
tree721a320b33da4d3b1d49aeb2e09a3f0d848f8412 /engine
parenta87b19e32bf493b05d440092e05c258f7975c3ce (diff)
downloadelgg-36f52b47f8dc996afcc889b1fd32fd23943103c5.tar.gz
elgg-36f52b47f8dc996afcc889b1fd32fd23943103c5.tar.bz2
XML-RPC helper functions suggested by Misja
git-svn-id: https://code.elgg.org/elgg/trunk@1681 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/xml-rpc.php70
1 files changed, 70 insertions, 0 deletions
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 */