- return $array;
- }
-
- /**
- * Formats the data according to the data type
- *
- * @param string $root_element Name of the root element
- * @param string $type Return type (atom, rss, xml, json)
- * @param array $data JSON style array
- *
- * @return array|string (string|array) XML data or JSON data
- */
- public static function formatData($root_element, string $type, array $data)
- {
- switch ($type) {
- case 'atom':
- case 'rss':
- case 'xml':
- $ret = self::createXML($data, $root_element);
- break;
- case 'json':
- default:
- $ret = $data;
- break;
- }
- return $ret;
- }
-
- /**
- * Callback function to transform the array in an array that can be transformed in a XML file
- *
- * @param mixed $item Array item value
- * @param string $key Array key
- *
- * @return boolean
- */
- public static function reformatXML(&$item, &$key)
- {
- if (is_bool($item)) {
- $item = ($item ? 'true' : 'false');
- }
-
- if (substr($key, 0, 10) == 'statusnet_') {
- $key = 'statusnet:'.substr($key, 10);
- } elseif (substr($key, 0, 10) == 'friendica_') {
- $key = 'friendica:'.substr($key, 10);
- }
- return true;
- }
-
- /**
- * Creates the XML from a JSON style array
- *
- * @param array $data JSON style array
- * @param string $root_element Name of the root element
- *
- * @return string The XML data
- */
- public static function createXML(array $data, $root_element)
- {
- $childname = key($data);
- $data2 = array_pop($data);
-
- $namespaces = ['' => 'http://api.twitter.com',
- 'statusnet' => 'http://status.net/schema/api/1/',
- 'friendica' => 'http://friendi.ca/schema/api/1/',
- 'georss' => 'http://www.georss.org/georss'];
-
- /// @todo Auto detection of needed namespaces
- if (in_array($root_element, ['ok', 'hash', 'config', 'version', 'ids', 'notes', 'photos'])) {
- $namespaces = [];
- }
-
- if (is_array($data2)) {
- $key = key($data2);
- self::walkRecursive($data2, ['Friendica\Module\BaseApi', 'reformatXML']);
-
- if ($key == '0') {
- $data4 = [];
- $i = 1;
-
- foreach ($data2 as $item) {
- $data4[$i++ . ':' . $childname] = $item;
- }