Esempio n. 1
0
 public function processImportTheme()
 {
     $this->display = 'importtheme';
     if ($this->context->mode == Context::MODE_HOST) {
         return true;
     }
     if (isset($_FILES['themearchive']) && isset($_POST['filename']) && Tools::isSubmit('theme_archive_server')) {
         $uniqid = uniqid();
         $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR;
         mkdir($sandbox);
         $archive_uploaded = false;
         if (Tools::getValue('filename') != '') {
             $uploader = new Uploader('themearchive');
             $uploader->setCheckFileSize(false);
             $uploader->setAcceptTypes(array('zip'));
             $uploader->setSavePath($sandbox);
             $file = $uploader->process(Theme::UPLOADED_THEME_DIR_NAME . '.zip');
             if ($file[0]['error'] === 0) {
                 if (Tools::ZipTest($sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                     $archive_uploaded = true;
                 } else {
                     $this->errors[] = $this->l('Zip file seems to be broken');
                 }
             } else {
                 $this->errors[] = $file[0]['error'];
             }
         } elseif (Tools::getValue('themearchiveUrl') != '') {
             if (!Validate::isModuleUrl($url = Tools::getValue('themearchiveUrl'), $this->errors)) {
                 $this->errors[] = $this->l('Only zip files are allowed');
             } elseif (!Tools::copy($url, $sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                 $this->errors[] = $this->l('Error during the file download');
             } elseif (Tools::ZipTest($sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                 $archive_uploaded = true;
             } else {
                 $this->errors[] = $this->l('Zip file seems to be broken');
             }
         } elseif (Tools::getValue('theme_archive_server') != '') {
             $filename = _PS_ALL_THEMES_DIR_ . Tools::getValue('theme_archive_server');
             if (substr($filename, -4) != '.zip') {
                 $this->errors[] = $this->l('Only zip files are allowed');
             } elseif (!copy($filename, $sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                 $this->errors[] = $this->l('An error has occurred during the file copy.');
             } elseif (Tools::ZipTest($sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip')) {
                 $archive_uploaded = true;
             } else {
                 $this->errors[] = $this->l('Zip file seems to be broken');
             }
         } else {
             $this->errors[] = $this->l('You must upload or enter a location of your zip');
         }
         if ($archive_uploaded) {
             if ($this->extractTheme($sandbox . Theme::UPLOADED_THEME_DIR_NAME . '.zip', $sandbox)) {
                 $this->installTheme(Theme::UPLOADED_THEME_DIR_NAME, $sandbox);
             }
         }
         Tools::deleteDirectory($sandbox);
         if (count($this->errors) > 0) {
             $this->display = 'importtheme';
         } else {
             Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminThemes') . '&conf=18');
         }
     }
 }