Esempio 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 (SpoonFile::exists($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) {
             $this->warnings[] = array('message' => BL::getMessage('InformationFileCouldNotBeLoaded'));
         }
     } else {
         $this->warnings[] = array('message' => BL::getMessage('InformationFileIsMissing'));
     }
 }
Esempio n. 2
0
    /**
     * Install a theme.
     *
     * @param string $theme The name of the theme to be installed.
     */
    public static function installTheme($theme)
    {
        // set path to info.xml
        $pathInfoXml = FRONTEND_PATH . '/themes/' . $theme . '/info.xml';
        // load info.xml
        $infoXml = @new SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true);
        // convert xml to useful array
        $information = BackendExtensionsModel::processThemeXml($infoXml);
        if (!$information) {
            throw new BackendException('Invalid info.xml');
        }
        // loop templates
        foreach ($information['templates'] as $template) {
            // init var
            $item = array();
            // build array
            $item['theme'] = $information['name'];
            $item['label'] = $template['label'];
            $item['path'] = $template['path'];
            $item['active'] = 'Y';
            // set format
            $item['data']['format'] = $template['format'];
            // build positions
            $item['data']['names'] = array();
            $item['data']['default_extras'] = array();
            foreach ($template['positions'] as $position) {
                // init 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::getDB()->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;
                }
            }
            // serialize the data
            $item['data'] = serialize($item['data']);
            // insert the item
            $item['id'] = self::insertTemplate($item);
        }
    }
Esempio n. 3
0
 /**
  * Validate a submitted form and process it.
  */
 private function validateForm()
 {
     // the form is submitted
     if ($this->frm->isSubmitted()) {
         // shorten field variables
         $fileFile = $this->frm->getField('file');
         // validate the file
         if ($fileFile->isFilled(BL::err('FieldIsRequired'))) {
             // only zip files allowed
             if ($fileFile->isAllowedExtension(array('zip'), sprintf(BL::getError('ExtensionNotAllowed'), 'zip'))) {
                 // create ziparchive instance
                 $zip = new ZipArchive();
                 // try and open it
                 if ($zip->open($fileFile->getTempFileName()) === true) {
                     // zip file needs to contain some files
                     if ($zip->numFiles > 0) {
                         // get first entry (= the theme folder)
                         $file = $zip->statIndex(0);
                         // name of the module we are trying to upload
                         $themeName = trim($file['name'], '/');
                         // find info.xml
                         $infoXml = $zip->getFromName($themeName . '/info.xml');
                         // add error if info.xml is not found
                         if ($infoXml === false) {
                             $fileFile->addError(sprintf(BL::getError('NoInformationFile'), $themeName));
                         } else {
                             // parse xml
                             try {
                                 // load info.xml
                                 $infoXml = @new SimpleXMLElement($infoXml, LIBXML_NOCDATA, false);
                                 // convert xml to useful array
                                 $this->information = BackendExtensionsModel::processThemeXml($infoXml);
                                 // empty data (nothing useful)
                                 if (empty($this->information)) {
                                     $fileFile->addError(BL::getMessage('InformationFileIsEmpty'));
                                 }
                                 // check if theme name in info.xml matches folder name
                                 if ($this->information['name'] != $themeName) {
                                     $fileFile->addError(BL::err('ThemeNameDoesntMatch'));
                                 }
                             } catch (Exception $e) {
                                 $fileFile->addError(BL::getMessage('InformationFileCouldNotBeLoaded'));
                             }
                         }
                         // wow wow, you are trying to upload an already existing theme
                         if (BackendExtensionsModel::existsTheme($themeName)) {
                             $fileFile->addError(sprintf(BL::getError('ThemeAlreadyExists'), $themeName));
                         }
                         // list of validated files (these files will actually be unpacked)
                         $files = array();
                         // check every file in the zip
                         for ($i = 0; $i < $zip->numFiles; $i++) {
                             // get the file name
                             $file = $zip->statIndex($i);
                             $fileName = $file['name'];
                             // yay, in a valid directory
                             if (stripos($fileName, $themeName . '/') === 0) {
                                 // valid file, add to extraction-list
                                 $files[] = $fileName;
                             }
                         }
                     } else {
                         $fileFile->addError(BL::getError('FileIsEmpty'));
                     }
                 } else {
                     $fileFile->addError(BL::getError('CorruptedFile'));
                 }
             }
         }
         // passed all validation
         if ($this->frm->isCorrect()) {
             // unpack module files
             $zip->extractTo(FRONTEND_PATH . '/themes', $files);
             // run installer
             BackendExtensionsModel::installTheme($themeName);
             // redirect with fireworks
             $this->redirect(BackendModel::createURLForAction('themes') . '&report=theme-installed&var=' . $themeName);
         }
     }
 }