Example #1
0
 public function import($theme, $data = [], $sessionKey = null)
 {
     @set_time_limit(3600);
     $this->theme = $theme;
     $this->fill($data);
     try {
         $file = $this->uploaded_file()->withDeferred($sessionKey)->first();
         if (!$file) {
             throw new ApplicationException('There is no file attached to import!');
         }
         $themePath = $this->theme->getPath();
         $tempPath = temp_path() . '/' . uniqid('oc');
         $zipName = uniqid('oc');
         $zipPath = temp_path() . '/' . $zipName;
         File::put($zipPath, $file->getContents());
         if (!@mkdir($tempPath)) {
             throw new ApplicationException('Unable to create directory ' . $tempPath);
         }
         Zip::extract($zipPath, $tempPath);
         // if (File::isFile($tempPath.'/theme.yaml')) {
         //     File::copy($tempPath.'/theme.yaml', $themePath.'/theme.yaml');
         // }
         if (File::isDirectory($tempPath . '/meta')) {
             $this->copyDirectory($tempPath . '/meta', $themePath . '/meta');
         }
         foreach ($this->folders as $folder) {
             if (!array_key_exists($folder, $this->getFoldersOptions())) {
                 continue;
             }
             $this->copyDirectory($tempPath . '/' . $folder, $themePath . '/' . $folder);
         }
         File::deleteDirectory($tempPath);
         File::delete($zipPath);
         $file->delete();
     } catch (Exception $ex) {
         if (!empty($tempPath) && File::isDirectory($tempPath)) {
             File::deleteDirectory($tempPath);
         }
         if (!empty($zipPath) && File::isFile($zipPath)) {
             File::delete($zipPath);
         }
         throw $ex;
     }
 }
Example #2
0
 public function export($theme, $data = [])
 {
     $this->theme = $theme;
     $this->fill($data);
     try {
         $themePath = $this->theme->getPath();
         $tempPath = temp_path() . '/' . uniqid('oc');
         $zipName = uniqid('oc');
         $zipPath = temp_path() . '/' . $zipName;
         if (!File::makeDirectory($tempPath)) {
             throw new ApplicationException('Unable to create directory ' . $tempPath);
         }
         if (!File::makeDirectory($metaPath = $tempPath . '/meta')) {
             throw new ApplicationException('Unable to create directory ' . $metaPath);
         }
         File::copy($themePath . '/theme.yaml', $tempPath . '/theme.yaml');
         File::copyDirectory($themePath . '/meta', $metaPath);
         foreach ($this->folders as $folder) {
             if (!array_key_exists($folder, $this->getFoldersOptions())) {
                 continue;
             }
             File::copyDirectory($themePath . '/' . $folder, $tempPath . '/' . $folder);
         }
         Zip::make($zipPath, $tempPath);
         File::deleteDirectory($tempPath);
     } catch (Exception $ex) {
         if (strlen($tempPath) && File::isDirectory($tempPath)) {
             File::deleteDirectory($tempPath);
         }
         if (strlen($zipPath) && File::isFile($zipPath)) {
             File::delete($zipPath);
         }
         throw $ex;
     }
     return $zipName;
 }
Example #3
0
 /**
  * Extracts a theme after it has been downloaded.
  */
 public function extractTheme($name, $hash)
 {
     $fileCode = $name . $hash;
     $filePath = $this->getFilePath($fileCode);
     if (!Zip::extract($filePath, $this->baseDirectory . '/themes/')) {
         throw new ApplicationException(Lang::get('system::lang.zip.extract_failed', ['file' => $filePath]));
     }
     $this->themeManager->setInstalled($name);
     @unlink($filePath);
 }
Example #4
0
 /**
  * Extracts a plugin after it has been downloaded.
  */
 public function extractPlugin($name, $hash)
 {
     $fileCode = $name . $hash;
     $filePath = $this->getFilePath($fileCode);
     if (!Zip::extract($filePath, $this->baseDirectory . '/plugins/')) {
         throw new ApplicationException(Lang::get('system::lang.zip.extract_failed', ['file' => $filePath]));
     }
     @unlink($filePath);
 }