summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2014-11-24 17:26:07 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2014-11-25 11:53:28 +0100
commitd4f107d4dd11d11c52f419d2f33abc5dc4a93573 (patch)
treec78445acdcfe38f30c0733162d09ffe07c03e2ea /lib/private
parentc503ecd54495167f97b6602e5b41c1cf95467395 (diff)
downloadnextcloud-server-d4f107d4dd11d11c52f419d2f33abc5dc4a93573.tar.gz
nextcloud-server-d4f107d4dd11d11c52f419d2f33abc5dc4a93573.zip
simplify xml parser code
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/app/infoparser.php75
1 files changed, 28 insertions, 47 deletions
diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php
index 908fcd82636..f7c3f8213a7 100644
--- a/lib/private/app/infoparser.php
+++ b/lib/private/app/infoparser.php
@@ -33,60 +33,41 @@ class InfoParser {
return null;
}
- $content = @file_get_contents($file);
- if (!$content) {
+ $xml = simplexml_load_file($file);
+ $array = json_decode(json_encode((array)$xml), TRUE);
+ if (is_null($array)) {
return null;
}
- $xml = new SimpleXMLElement($content);
- $data['info'] = array();
- $data['remote'] = array();
- $data['public'] = array();
- foreach ($xml->children() as $child) {
- /**
- * @var $child SimpleXMLElement
- */
- if ($child->getName() == 'remote') {
- foreach ($child->children() as $remote) {
- /**
- * @var $remote SimpleXMLElement
- */
- $data['remote'][$remote->getName()] = (string)$remote;
- }
- } elseif ($child->getName() == 'public') {
- foreach ($child->children() as $public) {
- /**
- * @var $public SimpleXMLElement
- */
- $data['public'][$public->getName()] = (string)$public;
- }
- } elseif ($child->getName() == 'types') {
- $data['types'] = array();
- foreach ($child->children() as $type) {
- /**
- * @var $type SimpleXMLElement
- */
- $data['types'][] = $type->getName();
+ if (!array_key_exists('info', $array)) {
+ $array['info'] = array();
+ }
+ if (!array_key_exists('remote', $array)) {
+ $array['remote'] = array();
+ }
+ if (!array_key_exists('public', $array)) {
+ $array['public'] = array();
+ }
+
+ if (array_key_exists('documentation', $array)) {
+ foreach ($array['documentation'] as $key => $url) {
+ // If it is not an absolute URL we assume it is a key
+ // i.e. admin-ldap will get converted to go.php?to=admin-ldap
+ if (!$this->httpHelper->isHTTPURL($url)) {
+ $url = $this->urlGenerator->linkToDocs($url);
}
- } elseif ($child->getName() == 'description') {
- $xml = (string)$child->asXML();
- $data[$child->getName()] = substr($xml, 13, -14); //script <description> tags
- } elseif ($child->getName() == 'documentation') {
- foreach ($child as $subChild) {
- $url = (string)$subChild;
- // If it is not an absolute URL we assume it is a key
- // i.e. admin-ldap will get converted to go.php?to=admin-ldap
- if (!$this->httpHelper->isHTTPURL($url)) {
- $url = $this->urlGenerator->linkToDocs($url);
- }
+ $array["documentation"][$key] = $url;
+
+ }
+ }
+ if (array_key_exists('types', $array)) {
+ foreach ($array['types'] as $type => $v) {
+ unset($array['types'][$type]);
+ $array['types'][] = $type;
- $data["documentation"][$subChild->getName()] = $url;
- }
- } else {
- $data[$child->getName()] = (string)$child;
}
}
- return $data;
+ return $array;
}
}