diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-11-25 15:56:52 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-11-25 15:56:52 +0100 |
commit | 0f18274ca5a69dbc4a33712a81cb560161408d38 (patch) | |
tree | d19b24213c352d6045f742582665e59dc9d11395 /lib | |
parent | 553188273c24835b2f8e36e488208f486d674bfc (diff) | |
parent | 5ce34fbaf69538ad3338beebdfb015e94f8b6a3e (diff) | |
download | nextcloud-server-0f18274ca5a69dbc4a33712a81cb560161408d38.tar.gz nextcloud-server-0f18274ca5a69dbc4a33712a81cb560161408d38.zip |
Merge pull request #12416 from owncloud/app-info-xml-parser-2
App info xml parser 2
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/app.php | 59 | ||||
-rw-r--r-- | lib/private/app/infoparser.php | 84 | ||||
-rw-r--r-- | lib/private/helper.php | 5 | ||||
-rw-r--r-- | lib/private/urlgenerator.php | 12 | ||||
-rw-r--r-- | lib/public/iurlgenerator.php | 8 |
5 files changed, 107 insertions, 61 deletions
diff --git a/lib/private/app.php b/lib/private/app.php index bc9ca0351ea..8e36d43bfb1 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -635,63 +635,10 @@ class OC_App { } $file = self::getAppPath($appId) . '/appinfo/info.xml'; } - $data = array(); - if (!file_exists($file)) { - return null; - } - $content = @file_get_contents($file); - if (!$content) { - 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(); - } - } 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(!\OC::$server->getHTTPHelper()->isHTTPURL($url)) { - $url = OC_Helper::linkToDocs($url); - } - $data["documentation"][$subChild->getName()] = $url; - } - } else { - $data[$child->getName()] = (string)$child; - } - } + $parser = new \OC\App\InfoParser(\OC::$server->getHTTPHelper(), \OC::$server->getURLGenerator()); + $data = $parser->parse($file); + self::$appInfo[$appId] = $data; return $data; diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php new file mode 100644 index 00000000000..b4bdbea5c04 --- /dev/null +++ b/lib/private/app/infoparser.php @@ -0,0 +1,84 @@ +<?php + /** + * @author Thomas Müller + * @copyright 2014 Thomas Müller deepdiver@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\App; + +use OCP\IURLGenerator; + +class InfoParser { + /** + * @var \OC\HTTPHelper + */ + private $httpHelper; + + /** + * @var IURLGenerator + */ + private $urlGenerator; + + /** + * @param \OC\HTTPHelper $httpHelper + * @param IURLGenerator $urlGenerator + */ + public function __construct(\OC\HTTPHelper $httpHelper, IURLGenerator $urlGenerator) { + $this->httpHelper = $httpHelper; + $this->urlGenerator = $urlGenerator; + } + + /** + * @param string $file the xml file to be loaded + * @return null|array where null is an indicator for an error + */ + public function parse($file) { + if (!file_exists($file)) { + return null; + } + + $loadEntities = libxml_disable_entity_loader(false); + $xml = @simplexml_load_file($file); + libxml_disable_entity_loader($loadEntities); + if ($xml == false) { + return null; + } + $array = json_decode(json_encode((array)$xml), TRUE); + if (is_null($array)) { + return null; + } + 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); + } + + $array['documentation'][$key] = $url; + } + } + if (array_key_exists('types', $array)) { + foreach ($array['types'] as $type => $v) { + unset($array['types'][$type]); + $array['types'][] = $type; + } + } + + return $array; + } +} diff --git a/lib/private/helper.php b/lib/private/helper.php index be448b8ff9b..d43eefcdc52 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -58,12 +58,11 @@ class OC_Helper { } /** - * @param $key + * @param string $key * @return string url to the online documentation */ public static function linkToDocs($key) { - $theme = new OC_Defaults(); - return $theme->buildDocLinkToKey($key); + return OC::$server->getURLGenerator()->linkToDocs($key); } /** diff --git a/lib/private/urlgenerator.php b/lib/private/urlgenerator.php index e50e9eed6af..d263d25aeef 100644 --- a/lib/private/urlgenerator.php +++ b/lib/private/urlgenerator.php @@ -8,6 +8,7 @@ */ namespace OC; +use OC_Defaults; use OCP\IURLGenerator; use RuntimeException; @@ -156,7 +157,7 @@ class URLGenerator implements IURLGenerator { /** * Makes an URL absolute - * @param string $url the url in the owncloud host + * @param string $url the url in the ownCloud host * @return string the absolute version of the url */ public function getAbsoluteURL($url) { @@ -173,4 +174,13 @@ class URLGenerator implements IURLGenerator { return \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost(). $webRoot . $separator . $url; } + + /** + * @param string $key + * @return string url to the online documentation + */ + public function linkToDocs($key) { + $theme = new OC_Defaults(); + return $theme->buildDocLinkToKey($key); + } } diff --git a/lib/public/iurlgenerator.php b/lib/public/iurlgenerator.php index dbbd8a3bb63..fa817c10ea5 100644 --- a/lib/public/iurlgenerator.php +++ b/lib/public/iurlgenerator.php @@ -69,8 +69,14 @@ interface IURLGenerator { /** * Makes an URL absolute - * @param string $url the url in the owncloud host + * @param string $url the url in the ownCloud host * @return string the absolute version of the url */ public function getAbsoluteURL($url); + + /** + * @param string $key + * @return string url to the online documentation + */ + public function linkToDocs($key); } |