/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $locale = config('app.locale'); $adminLocale = config('typicms.admin_locale'); $locales = config('translatable.locales'); // If locale is present in app.locales… if (in_array(Input::get('locale'), $locales)) { // …store locale in session Session::put('locale', Input::get('locale')); } // Set app.locale config(['app.locale' => Session::get('locale', $locale)]); // Set Translator locale to typicms.admin_locale config Lang::setLocale($adminLocale); $localesForJS = []; foreach ($locales as $key => $locale) { $localesForJS[] = ['short' => $locale, 'long' => trans('global.languages.' . $locale)]; } // Set Locales to JS. JavaScript::put(['_token' => csrf_token(), 'encrypted_token' => Crypt::encrypt(csrf_token()), 'adminLocale' => $adminLocale, 'locales' => $localesForJS, 'locale' => config('app.locale')]); // set curent user preferences to Config if ($request->user()) { $prefs = $request->user()->preferences; config(['typicms.user' => $prefs]); } return $next($request); }
/** * Updates the status page settings. * * @return \Illuminate\View\View */ public function postSettings() { $redirectUrl = Session::get('redirect_to', route('dashboard.settings.setup')); if (Binput::get('remove_banner') === '1') { $setting = Setting::where('name', 'app_banner'); $setting->delete(); } if (Binput::hasFile('app_banner')) { $file = Binput::file('app_banner'); // Image Validation. // Image size in bytes. $maxSize = $file->getMaxFilesize(); if ($file->getSize() > $maxSize) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.too-big', ['size' => $maxSize])); } if (!$file->isValid() || $file->getError()) { return Redirect::to($redirectUrl)->withErrors($file->getErrorMessage()); } if (!starts_with($file->getMimeType(), 'image/')) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.images-only')); } // Store the banner. Setting::firstOrCreate(['name' => 'app_banner'])->update(['value' => base64_encode(file_get_contents($file->getRealPath()))]); // Store the banner type Setting::firstOrCreate(['name' => 'app_banner_type'])->update(['value' => $file->getMimeType()]); } try { foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) { if ($settingName === 'app_analytics_pi_url') { $settingValue = rtrim($settingValue, '/'); } Setting::firstOrCreate(['name' => $settingName])->update(['value' => $settingValue]); } } catch (Exception $e) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.edit.failure')); } if (Binput::has('app_locale')) { Lang::setLocale(Binput::get('app_locale')); } return Redirect::to($redirectUrl)->withSuccess(trans('dashboard.settings.edit.success')); }
/** * Updates the status page settings. * * @return \Illuminate\View\View */ public function postSettings() { $redirectUrl = Session::get('redirect_to', route('dashboard.settings.setup')); $setting = app('setting'); if (Binput::get('remove_banner') === '1') { $setting->set('app_banner', null); } if ($header = Binput::get('header', null, false, false)) { $setting->set('header', $header); } if ($footer = Binput::get('footer', null, false, false)) { $setting->set('footer', $footer); } if (Binput::hasFile('app_banner')) { $file = Binput::file('app_banner'); // Image Validation. // Image size in bytes. $maxSize = $file->getMaxFilesize(); if ($file->getSize() > $maxSize) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.too-big', ['size' => $maxSize])); } if (!$file->isValid() || $file->getError()) { return Redirect::to($redirectUrl)->withErrors($file->getErrorMessage()); } if (!starts_with($file->getMimeType(), 'image/')) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.images-only')); } // Store the banner. $setting->set('app_banner', base64_encode(file_get_contents($file->getRealPath()))); // Store the banner type. $setting->set('app_banner_type', $file->getMimeType()); } $excludedParams = ['_token', 'app_banner', 'remove_banner', 'header', 'footer']; try { foreach (Binput::except($excludedParams) as $settingName => $settingValue) { if ($settingName === 'app_analytics_pi_url') { $settingValue = rtrim($settingValue, '/'); } $setting->set($settingName, $settingValue); } } catch (Exception $e) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.edit.failure')); } if (Binput::has('app_locale')) { Lang::setLocale(Binput::get('app_locale')); } return Redirect::to($redirectUrl)->withSuccess(trans('dashboard.settings.edit.success')); }
/** * Updates the status page settings. * * @return \Illuminate\View\View */ public function postSettings() { $setting = app(Repository::class); if (Binput::get('remove_banner') === '1') { $setting->set('app_banner', null); } $parameters = Binput::all(); if (isset($parameters['header'])) { if ($header = Binput::get('header', null, false, false)) { $setting->set('header', $header); } else { $setting->delete('header'); } } if (isset($parameters['footer'])) { if ($footer = Binput::get('footer', null, false, false)) { $setting->set('footer', $footer); } else { $setting->delete('footer'); } } if (Binput::hasFile('app_banner')) { $this->handleUpdateBanner($setting); } $excludedParams = ['_token', 'app_banner', 'remove_banner', 'header', 'footer']; try { foreach (Binput::except($excludedParams) as $settingName => $settingValue) { if ($settingName === 'app_analytics_pi_url') { $settingValue = rtrim($settingValue, '/'); } $setting->set($settingName, $settingValue); } } catch (Exception $e) { return Redirect::back()->withErrors(trans('dashboard.settings.edit.failure')); } if (Binput::has('app_locale')) { Lang::setLocale(Binput::get('app_locale')); } return Redirect::back()->withSuccess(trans('dashboard.settings.edit.success')); }
/** * Return the mail as html. * @return string */ public function show() { // Set the email's locale: $currentLocale = Lang::getLocale(); $newLocale = $this->locale ?: Lang::getLocale(); Lang::setLocale($newLocale); // Generate HTML: $html = View::make($this->view, $this->data)->render(); $css = File::get($this->cssFile); $inliner = new CssInline($html, $css); $body = $inliner->convert(); // Return App locale to former value: Lang::setLocale($currentLocale); return $body; }