Backend\Modules\Extensions\Engine\Model::processThemeXml PHP Method

processThemeXml() public static method

Process the theme's information XML and return an array with the information.
public static processThemeXml ( SimpleXMLElement $xml ) : array
$xml SimpleXMLElement
return array
    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);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Load the data.
  * This will also set some warnings if needed.
  */
 private function loadData()
 {
     // inform that the theme is not installed yet
     if (!BackendExtensionsModel::isThemeInstalled($this->currentTheme)) {
         $this->warnings[] = array('message' => BL::getMessage('InformationThemeIsNotInstalled'));
     }
     // path to information file
     $pathInfoXml = FRONTEND_PATH . '/Themes/' . $this->currentTheme . '/info.xml';
     // information needs to exists
     if (is_file($pathInfoXml)) {
         try {
             // load info.xml
             $infoXml = @new \SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true);
             // convert xml to useful array
             $this->information = BackendExtensionsModel::processThemeXml($infoXml);
             // empty data (nothing useful)
             if (empty($this->information)) {
                 $this->warnings[] = array('message' => BL::getMessage('InformationFileIsEmpty'));
             }
         } catch (\Exception $e) {
             // warning that the information file is corrupt
             $this->warnings[] = array('message' => BL::getMessage('InformationFileCouldNotBeLoaded'));
         }
     } else {
         // warning that the information file is missing
         $this->warnings[] = array('message' => BL::getMessage('InformationFileIsMissing'));
     }
 }
All Usage Examples Of Backend\Modules\Extensions\Engine\Model::processThemeXml