public function getList() { $thumbs = []; $themesPath = base_path('resources/views/themes'); if (is_dir($themesPath)) { foreach (Theme::all() as $databaseTheme) { $databaseThemes[$databaseTheme->theme] = $databaseTheme; } foreach (scandir($themesPath) as $themeFile) { if (!is_dir($themesPath . '/' . $themeFile) && substr($themeFile, -4) == '.zip') { Theme::unzip($themeFile); } } foreach (scandir($themesPath) as $themeFolder) { if (is_dir($themesPath . '/' . $themeFolder) && strpos($themeFolder, '.') !== 0) { $theme = new \stdClass(); $theme->name = $themeFolder; $theme->image = 'https://placeholdit.imgix.net/~text?txtsize=19&bg=efefef&txtclr=aaaaaa%26text%3Dno%2Bimage&txt=no+image&w=200&h=150'; $publicLocations = [public_path('themes/' . $themeFolder), $themesPath . '/' . $themeFolder . '/public']; foreach ($publicLocations as $k => $publicLocation) { if (is_dir($publicLocation)) { foreach (scandir($publicLocation) as $file) { if (!is_dir($publicLocation . '/' . $file)) { if (strpos($file, 'screenshot.') === 0) { if ($k == 0) { $theme->image = \Croppa::url(URL::to('themes/' . $themeFolder . '/' . $file), 252, 142); } else { $saveInCache = public_path('coaster/tmp/themes/' . $themeFolder); @mkdir($saveInCache, 0777, true); copy($publicLocation . '/' . $file, $saveInCache . '/' . $file); $theme->image = \Croppa::url(URL::to('coaster/tmp/themes/' . $themeFolder . '/' . $file), 252, 142); } } } } } } if (isset($databaseThemes[$themeFolder])) { $theme->id = $databaseThemes[$themeFolder]->id; if ($databaseThemes[$themeFolder]->id != config('coaster::frontend.theme')) { $theme->activate = 1; } else { $theme->active = 1; } } else { $theme->install = 1; } $thumbs[] = $theme; } } } $theme_auth = ['update' => Auth::action('themes.update'), 'manage' => Auth::action('themes.manage'), 'export' => Auth::action('themes.export'), 'edit' => Auth::action('themes.edit')]; $themes_installed = View::make('coaster::partials.themes.thumbs', ['thumbs' => $thumbs, 'auth' => $theme_auth]); if (!empty(self::$_error)) { $this->addAlert('danger', self::$_error); } $this->layoutData['content'] = View::make('coaster::pages.themes.list', ['themes_installed' => $themes_installed, 'can_upload' => $theme_auth['manage']]); $this->layoutData['modals'] = View::make('coaster::modals.themes.delete')->render() . View::make('coaster::modals.themes.export')->render() . View::make('coaster::modals.themes.install')->render() . View::make('coaster::modals.themes.install_confirm')->render() . View::make('coaster::modals.themes.install_error')->render(); }
public function installTheme() { $details = Request::all(); $error = false; if (!empty($details['theme'])) { if (!($error = Theme::unzip($details['theme'] . '.zip', false))) { $withPageData = !empty($details['page-data']) ? 1 : 0; $result = Theme::install($details['theme'], ['withPageData' => $withPageData]); if ($result['error']) { $error = $result['response']; } if (($usedThemeSetting = Setting::where('name', '=', 'frontend.theme')->first()) && ($theme = Theme::where('theme', '=', $details['theme'])->first())) { $usedThemeSetting->value = $theme->id; $usedThemeSetting->save(); } } } if ($error) { FormMessage::add('theme', $error); $this->setupTheme(); } else { include __DIR__ . '/../../Http/routes/admin.php'; Install::setInstallState('complete-welcome'); $this->layoutData['title'] = 'Install Complete'; $this->layoutData['content'] = View::make('coaster::pages.install', ['stage' => 'complete']); } }