public static function processThemeXml(\SimpleXMLElement $xml)
{
$information = array();
$theme = $xml->xpath('/theme');
if (isset($theme[0])) {
$theme = $theme[0];
}
// fetch general theme info
$information['name'] = (string) $theme->name;
$information['version'] = (string) $theme->version;
$information['requirements'] = (array) $theme->requirements;
$information['thumbnail'] = (string) $theme->thumbnail;
$information['description'] = (string) $theme->description;
// authors
foreach ($xml->xpath('/theme/authors/author') as $author) {
$information['authors'][] = (array) $author;
}
// meta navigation
$meta = $theme->metanavigation->attributes();
if (isset($meta['supported'])) {
$information['meta'] = (string) $meta['supported'] && (string) $meta['supported'] !== 'false';
}
// templates
$information['templates'] = array();
foreach ($xml->xpath('/theme/templates/template') as $templateXML) {
$template = array();
// template data
$template['label'] = (string) $templateXML['label'];
$template['path'] = (string) $templateXML['path'];
$template['image'] = isset($templateXML['image']) ? (string) $templateXML['image'] && (string) $templateXML['image'] !== 'false' : false;
$template['format'] = trim(str_replace(array("\n", "\r", ' '), '', (string) $templateXML->format));
// loop positions
foreach ($templateXML->positions->position as $positionXML) {
$position = array();
$position['name'] = (string) $positionXML['name'];
// widgets
$position['widgets'] = array();
if ($positionXML->defaults->widget) {
foreach ($positionXML->defaults->widget as $widget) {
$position['widgets'][] = array('module' => (string) $widget['module'], 'action' => (string) $widget['action']);
}
}
// editor
$position['editors'] = array();
if ($positionXML->defaults->editor) {
foreach ($positionXML->defaults->editor as $editor) {
$position['editors'][] = (string) trim($editor);
}
}
$template['positions'][] = $position;
}
$information['templates'][] = $template;
}
return self::validateThemeInformation($information);
}