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

installTheme() public static method

Install a theme.
public static installTheme ( string $theme )
$theme string The name of the theme to be installed.
    public static function installTheme($theme)
    {
        $pathInfoXml = FRONTEND_PATH . '/Themes/' . $theme . '/info.xml';
        $infoXml = @new \SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true);
        $information = self::processThemeXml($infoXml);
        if (!$information) {
            throw new Exception('Invalid info.xml');
        }
        foreach ($information['templates'] as $template) {
            $item = array();
            $item['theme'] = $information['name'];
            $item['label'] = $template['label'];
            $item['path'] = $template['path'];
            $item['active'] = 'Y';
            $item['data']['format'] = $template['format'];
            $item['data']['image'] = $template['image'];
            // build positions
            $item['data']['names'] = array();
            $item['data']['default_extras'] = array();
            foreach ($template['positions'] as $position) {
                $item['data']['names'][] = $position['name'];
                $item['data']['default_extras'][$position['name']] = array();
                // add default widgets
                foreach ($position['widgets'] as $widget) {
                    // fetch extra_id for this extra
                    $extraId = (int) BackendModel::getContainer()->get('database')->getVar('SELECT i.id
                         FROM modules_extras AS i
                         WHERE type = ? AND module = ? AND action = ? AND data IS NULL AND hidden = ?', array('widget', $widget['module'], $widget['action'], 'N'));
                    // add extra to defaults
                    if ($extraId) {
                        $item['data']['default_extras'][$position['name']][] = $extraId;
                    }
                }
                // add default editors
                foreach ($position['editors'] as $editor) {
                    $item['data']['default_extras'][$position['name']][] = 0;
                }
            }
            $item['data'] = serialize($item['data']);
            $item['id'] = self::insertTemplate($item);
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Execute the action.
  */
 public function execute()
 {
     // get parameters
     $this->currentTheme = $this->getParameter('theme', 'string');
     // does the item exist
     if ($this->currentTheme !== null && BackendExtensionsModel::existsTheme($this->currentTheme)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // make sure this theme can be installed
         $this->validateInstall();
         try {
             // do the actual install
             BackendExtensionsModel::installTheme($this->currentTheme);
             // redirect to index with a success message
             $this->redirect(BackendModel::createURLForAction('Themes') . '&report=theme-installed&var=' . $this->currentTheme);
         } catch (Exception $e) {
             // redirect to index with a success message
             $this->redirect(BackendModel::createURLForAction('Themes') . '&report=information-file-is-empty&var=' . $this->currentTheme);
         }
     } else {
         // no item found, redirect to index, because somebody is f*****g with our url
         $this->redirect(BackendModel::createURLForAction('Themes') . '&error=non-existing');
     }
 }
All Usage Examples Of Backend\Modules\Extensions\Engine\Model::installTheme