Commit d950d7e4 authored by Tino Goratsch's avatar Tino Goratsch

minor refactoring and improvements

parent 3e6886d1
......@@ -35,20 +35,16 @@ class XML
if (!empty($this->info[$path][$xpath])) {
return $this->info[$path][$xpath];
} elseif (is_file($path) === true) {
/** @var \SimpleXMLElement $xml */
$xml = simplexml_load_file($path);
$data = $xml->xpath($xpath);
if (!empty($data)) {
foreach ($data as $row) {
foreach ($row as $key => $value) {
/** @var \SimpleXMLElement $value */
if ($value->attributes()) {
foreach ($value->attributes() as $attrKey => $attrValue) {
if ($key === 'version' && $attrKey === 'core' && (string)$attrValue === 'true') {
$this->info[$path][$xpath]['version'] = Bootstrap::VERSION;
} else {
$this->info[$path][$xpath][(string)$key][(string)$attrKey] = (string)$attrValue;
}
}
$this->parseAttributes($value->attributes(), $path, $xpath, $key);
} elseif (isset($this->info[$path][$xpath][(string)$key]) && is_array($this->info[$path][$xpath][(string)$key])) {
$this->info[$path][$xpath][(string)$key][] = (string)$value;
} elseif (isset($this->info[$path][$xpath][(string)$key])) {
......@@ -66,4 +62,21 @@ class XML
}
return [];
}
/**
* @param \SimpleXMLElement $attributes
* @param string $path
* @param string $xpath
* @param string $key
*/
protected function parseAttributes(\SimpleXMLElement $attributes, $path, $xpath, $key)
{
foreach ($attributes as $attrKey => $attrValue) {
if ($key === 'version' && $attrKey === 'core' && (string)$attrValue === 'true') {
$this->info[$path][$xpath]['version'] = Bootstrap::VERSION;
} else {
$this->info[$path][$xpath][(string)$key][(string)$attrKey] = (string)$attrValue;
}
}
}
}
......@@ -47,21 +47,8 @@ class Designs extends Core\Controller\AdminAction
return $this->executePost($dir);
}
$designs = [];
$path = ACP3_ROOT_DIR . 'designs/';
$directories = Core\Filesystem::scandir($path);
$countDir = count($directories);
for ($i = 0; $i < $countDir; ++$i) {
$designInfo = $this->xml->parseXmlFile($path . $directories[$i] . '/info.xml', '/design');
if (!empty($designInfo)) {
$designs[$i] = $designInfo;
$designs[$i]['selected'] = $this->config->getSettings('system')['design'] === $directories[$i] ? 1 : 0;
$designs[$i]['dir'] = $directories[$i];
}
}
return [
'designs' => $designs
'designs' => $this->getAvailableDesigns()
];
}
......@@ -90,4 +77,28 @@ class Designs extends Core\Controller\AdminAction
return $this->redirectMessages()->setMessage($bool, $text, $this->request->getFullPath());
}
/**
* @return array
*/
protected function getAvailableDesigns()
{
$designs = [];
$path = ACP3_ROOT_DIR . 'designs/';
$directories = Core\Filesystem::scandir($path);
foreach ($directories as $directory) {
$designInfo = $this->xml->parseXmlFile($path . $directory . '/info.xml', '/design');
if (!empty($designInfo)) {
$designs[] = array_merge(
$designInfo,
[
'selected' => $this->config->getSettings('system')['design'] === $directory ? 1 : 0,
'dir' => $directory
]
);
}
}
return $designs;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment