public static function generateCacheableRecords() { $allRecords = Setting::all()->toArray(); $cacheableRecords = []; foreach ($allRecords as $record) { $cacheableRecords[$record['domain']] = ['theme' => $record['theme'], 'is_protected' => $record['is_protected']]; } return $cacheableRecords; }
public function boot() { $backendUri = Config::get('cms.backendUri'); $requestUrl = Request::url(); $currentHostUrl = Request::getHost(); /* * Get domain to theme bindings from cache, if it's not there, load them from database, * save to cache and use for theme selection. */ $binds = Cache::rememberForever('keios_multisite_settings', function () { try { $cacheableRecords = Setting::generateCacheableRecords(); } catch (\Illuminate\Database\QueryException $e) { if (BackendAuth::check()) { Flash::error(trans('keios.multisite:lang.flash.db-error')); } return null; } return $cacheableRecords; }); /* * Oooops something went wrong, abort. */ if ($binds === null) { return; } /* * Check if this request is in backend scope and is using domain, * that is protected from using backend */ foreach ($binds as $domain => $bind) { if (preg_match('/\\' . $backendUri . '/', $requestUrl) && preg_match('/' . $currentHostUrl . '/i', $domain) && $bind['is_protected']) { return App::abort(401, 'Unauthorized.'); } } /* * If current request is in backend scope, do not check cms themes * Allows for current theme changes in October Theme Selector */ if (preg_match('/\\' . $backendUri . '/', $requestUrl)) { return; } /* * Listen for CMS activeTheme event, change theme according to binds * If there's no match, let CMS set active theme */ Event::listen('cms.theme.getActiveTheme', function () use($binds, $currentHostUrl) { foreach ($binds as $domain => $bind) { if (preg_match('/' . $currentHostUrl . '/i', $domain)) { Config::set('app.url', $domain); return $bind['theme']; } } }); }
public function onDelete() { $selected = post('checked'); Setting::destroy($selected); return $this->listRefresh(); }