Ejemplo n.º 1
0
 public static function install($themeName, $options)
 {
     $themePath = base_path() . '/resources/views/themes/' . $themeName;
     $packed = is_dir($themePath . '/views') && is_dir($themePath . '/public');
     if (!empty($options['check'])) {
         $pagesImport = $packed ? $themePath . '/views/import/pages' : $themePath . '/import/pages';
         return ['error' => 0, 'response' => is_dir($pagesImport)];
     }
     if ($packed) {
         // extract public folder, extract uploads folder, and move views to themes root
         Directory::copy($themePath . '/public', public_path() . '/themes/' . $themeName);
         Directory::remove($themePath . '/public');
         if (is_dir($themePath . '/uploads')) {
             $securePaths = [];
             $secureUploadPaths = explode(',', config('coaster::site.secure_folders'));
             foreach ($secureUploadPaths as $secureUploadPath) {
                 $securePaths[] = '/uploads/' . trim($secureUploadPath, '/');
             }
             Directory::copy($themePath . '/uploads', public_path() . '/uploads', function ($addFrom, $addTo) use($securePaths, $themePath) {
                 $uploadPath = str_replace(public_path(), '', $addTo);
                 foreach ($securePaths as $securePath) {
                     if (strpos($uploadPath, $securePath) === 0) {
                         $addTo = str_replace(public_path() . '/uploads', storage_path() . '/uploads', $addTo);
                         break;
                     }
                 }
                 return [$addFrom, $addTo];
             });
         }
         Directory::remove($themePath . '/uploads');
         Directory::copy($themePath . '/views', $themePath);
         Directory::remove($themePath . '/views');
     }
     $unpacked = is_dir($themePath . '/templates') && is_dir(public_path() . '/themes/' . $themeName);
     if (!$unpacked) {
         return ['error' => 1, 'response' => 'theme files not found for ' . $themeName];
     }
     $theme = self::where('theme', '=', $themeName)->first();
     if (empty($theme)) {
         // add theme to database
         $newTheme = new self();
         $newTheme->theme = $themeName;
         $newTheme->save();
         // install theme blocks and templates
         try {
             BlockUpdater::updateTheme($newTheme);
             Directory::remove($themePath . '/import/blocks');
         } catch (\Exception $e) {
             $newTheme->delete();
             return ['error' => 1, 'response' => $e->getMessage()];
         }
         // install pages and page block data
         if (!empty($options['withPageData'])) {
             try {
                 self::_pageImportData($newTheme);
                 Directory::remove($themePath . '/import/pages');
                 if (file_exists($themePath . '/import/pages.csv')) {
                     unlink($themePath . '/import/pages.csv');
                 }
             } catch (\Exception $e) {
                 return ['error' => 1, 'response' => $e->getMessage()];
             }
         }
         return ['error' => 0, 'response' => ''];
     } else {
         return ['error' => 0, 'response' => 'theme ' . $themeName . ' already exists in database'];
     }
 }
Ejemplo n.º 2
0
 public function postUpdate($themeId)
 {
     $blocks = Request::input('block');
     $theme = Theme::find($themeId);
     if (!empty($blocks)) {
         BlockUpdater::updateTheme($theme, $blocks);
     }
     $this->layoutData['content'] = View::make('coaster::pages.themes.update', ['theme' => $theme, 'saved' => true]);
 }