public function getIndex() { $requests = PagePublishRequests::can_moderate(['status' => 'awaiting'], 10); if ($requests->isEmpty()) { $requests = 'No awaiting requests'; } $requests_table = View::make('coaster::partials.tabs.publish_requests.table', array('show' => ['page' => true, 'status' => false, 'requested_by' => true], 'requests' => $requests))->render(); $any_requests = config('coaster::admin.publishing') && !PagePublishRequests::can_moderate([], 1)->isEmpty(); $user_requests = PagePublishRequests::all_requests(0, ['user_id' => Auth::user()->id, 'status' => 'awaiting'], 10); if ($user_requests->isEmpty()) { $user_requests = 'No awaiting requests'; } $user_requests_table = View::make('coaster::partials.tabs.publish_requests.table', array('show' => ['page' => true, 'status' => true, 'requested_by' => false], 'requests' => $user_requests))->render(); $any_user_requests = config('coaster::admin.publishing') && !PagePublishRequests::all_requests(0, ['user_id' => Auth::user()->id], 1)->isEmpty(); $logs_data = AdminLog::with(['user', 'backup'])->orderBy('id', 'desc')->paginate(10); $logs = View::make('coaster::partials.logs.table', array('logs' => $logs_data)); $firstTimer = false; if (Install::getInstallState() == 'complete-welcome') { Install::setInstallState('complete'); $firstTimer = true; } $coasterBlog = 'https://www.coastercms.org/blog/'; $coasterBlogHttpClient = new Client(['base_uri' => $coasterBlog . 'wp-json/wp/v2/']); try { $latestPosts = $coasterBlogHttpClient->request('GET', 'posts', ['query' => ['per_page' => 3]]); $latestPosts = json_decode($latestPosts->getBody()); } catch (\Exception $e) { $latestPosts = []; } $posts = collect($latestPosts); // Search data $numbSearches = PageSearchLog::count(); if (Auth::action('search.index') && $numbSearches) { $search_data = PageSearchLog::orderBy('count', 'DESC')->orderBy('updated_at', 'DESC')->limit(6)->get(); $numbSearches = $search_data->count(); $search_view = View::make('coaster::pages.search', array('search_data' => $search_data)); } else { $search_view = ''; } $data = array('firstTimer' => $firstTimer, 'coasterPosts' => $posts, 'coasterBlog' => $coasterBlog, 'logs' => $logs, 'requests' => $requests_table, 'user_requests' => $user_requests_table, 'any_requests' => $any_requests, 'any_user_requests' => $any_user_requests); $data['searchLogNumber'] = $numbSearches; $data['searchLogs'] = $search_view; $data['canViewSettings'] = Auth::action('system'); $upgrade = new \stdClass(); $upgrade->from = config('coaster::site.version'); $upgrade->to = Setting::latestTag(); $upgrade->required = version_compare(config('coaster::site.version'), $upgrade->to, '<'); $upgrade->allowed = Auth::action('system.upgrade'); $data['upgrade'] = $upgrade; $this->layoutData['title'] = 'Admin home'; $this->layoutData['content'] = View::make('coaster::pages.dashboard', $data); }
/** * Bootstrap the application events. * * @param Router $router * @param Kernel $kernel * @return void */ public function boot(Router $router, Kernel $kernel) { // add router middleware $globalMiddleware = [UploadChecks::class]; $routerMiddleware = ['coaster.admin' => AdminAuth::class, 'coaster.guest' => GuestAuth::class]; event(new LoadMiddleware($globalMiddleware, $routerMiddleware)); foreach ($globalMiddleware as $globalMiddlewareClass) { $kernel->pushMiddleware($globalMiddlewareClass); } foreach ($routerMiddleware as $routerMiddlewareName => $routerMiddlewareClass) { $router->middleware($routerMiddlewareName, $routerMiddlewareClass); } // use coater guard and user provider $authGuard = Helpers\Cms\CoasterGuard::class; $authUserProvider = Providers\CoasterAuthUserProvider::class; event(new LoadAuth($authGuard, $authUserProvider)); if ($authGuard && $authUserProvider) { Auth::extend('coaster', function ($app) use($authGuard, $authUserProvider) { return new $authGuard('coasterguard', new $authUserProvider(), $app['session.store'], $app['request']); }); } // set cookie jar for cookies Auth::setCookieJar($this->app['cookie']); // load coaster views $adminViews = [base_path(trim(config('coaster::admin.view'), '/'))]; $frontendViews = [base_path(trim(config('coaster::frontend.view'), '/'))]; event(new SetViewPaths($adminViews, $frontendViews)); $this->loadViewsFrom($adminViews, 'coaster'); $this->loadViewsFrom($frontendViews, 'coasterCms'); // run routes if not in console $routeFile = __DIR__ . '/Http/routes.php'; event(new LoadRouteFile($routeFile)); if ($routeFile && file_exists($routeFile)) { include $routeFile; } // if in console and not installed, display notice if (App::runningInConsole() && !Install::isComplete()) { echo "Coaster Framework: CMS awaiting install, go to a web browser to complete installation\r\n"; } }
/** * Bootstrap the application events. * * @return void */ public function boot() { $db = false; try { if (Schema::hasTable('settings')) { $db = true; } } catch (\PDOException $e) { } $configFile = __DIR__ . '/../../config'; $useDatabaseSettings = $db; event(new LoadConfig($configFile, $useDatabaseSettings)); Setting::loadAll($configFile, 'coaster', $useDatabaseSettings); $overrideConfigValues = ['auth.guards.web.driver' => 'coaster', 'auth.providers.users.model' => User::class, 'croppa.src_dir' => public_path(), 'croppa.crops_dir' => public_path() . '/cache', 'croppa.path' => 'cache/(' . config('coaster::frontend.croppa_handle') . ')$']; event(new LoadedConfig($overrideConfigValues)); foreach ($overrideConfigValues as $attribute => $value) { app()->config->set($attribute, $value); } if (Install::isComplete()) { if (!$db) { abort(503, 'Database error, settings table could not be found'); } } }
} $updatesFile = storage_path(config('coaster::site.storage_path') . '/updates.json'); if (file_exists($updatesFile)) { $updateStatus = file_get_contents($updatesFile); $updateStatus = json_decode($updateStatus, true); } else { $updateStatus = []; } if (empty($updateStatus['storage']) || version_compare($updateStatus['storage'], 'v.5.2.39', '<')) { include __DIR__ . '/storageMove.php'; $updateStatus['storage'] = config('coaster::site.version'); file_put_contents($updatesFile, json_encode($updateStatus)); } if (empty($updateStatus['fileManager']) || version_compare($updateStatus['fileManager'], 'v.5.3.1', '<')) { include __DIR__ . '/fileManagerConfig.php'; $updateStatus['fileManager'] = config('coaster::site.version'); file_put_contents($updatesFile, json_encode($updateStatus)); } if (\CoasterCms\Helpers\Cms\Install::isComplete()) { if (empty($updateStatus['gallery']) || version_compare($updateStatus['gallery'], 'v.5.2.27', '<')) { include __DIR__ . '/galleryMoveFiles.php'; $updateStatus['gallery'] = config('coaster::site.version'); file_put_contents($updatesFile, json_encode($updateStatus)); } if (empty($updateStatus['migrations']) || version_compare($updateStatus['migrations'], config('coaster::site.version'), '<')) { include __DIR__ . '/databaseMigrations.php'; $updateStatus['migrations'] = config('coaster::site.version'); file_put_contents($updatesFile, json_encode($updateStatus)); } } include __DIR__ . '/publicAssets.php';
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']); } }
<?php $routeNamePrefix = 'coaster.install.'; $installController = 'CoasterCms\\Http\\Controllers\\InstallController'; Route::any('install/permissions/{next?}', ['uses' => $installController . '@checkPermissions', 'as' => $routeNamePrefix . 'permissions']); Route::any('install/database', ['uses' => $installController . '@setupDatabase', 'as' => $routeNamePrefix . 'database']); Route::any('install/database-save', ['uses' => $installController . '@saveDatabaseSettings', 'as' => $routeNamePrefix . 'databaseSave']); Route::any('install/database-migrate', ['uses' => $installController . '@runDatabaseMigrations', 'as' => $routeNamePrefix . 'databaseMigrate']); Route::any('install/admin', ['uses' => $installController . '@setupAdminUser', 'as' => $routeNamePrefix . 'admin']); Route::any('install/admin-save', ['uses' => $installController . '@saveAdminUser', 'as' => $routeNamePrefix . 'adminSave']); Route::any('install/theme', ['uses' => $installController . '@setupTheme', 'as' => $routeNamePrefix . 'theme']); Route::any('install/theme-install', ['uses' => $installController . '@installTheme', 'as' => $routeNamePrefix . 'themeInstall']); Route::any('{other?}', ['uses' => function ($other) { $installRoute = \CoasterCms\Helpers\Cms\Install::getRedirectRoute(); return redirect()->route($installRoute); }, 'as' => 'coaster.admin'])->where('other', '.*');