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)) {
         parent::execute();
         $this->loadData();
         $this->loadDataGridTemplates();
         $this->parse();
         $this->display();
     } else {
         $this->redirect(BackendModel::createURLForAction('themes') . '&error=non-existing');
     }
 }
Exemplo n.º 2
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 {
         $this->redirect(BackendModel::createURLForAction('themes') . '&error=non-existing');
     }
 }
Exemplo 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);
         }
     }
 }