diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 45979e3f69596a2017c89406738673c6b68f1b5e..03b6629eb018cc996e9a76f2feee5cfde7fdb0fb 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -209,23 +209,32 @@ class SettingsController extends Controller $fokus = $request->input('fokus', ''); $url = $request->input('url', ''); // Currently only the setting for quotes is supported + $quotes = $request->input('zitate', ''); - if (empty($fokus) || empty($quotes)) { - abort(404); + if(!empty($quotes)){ + if($quotes === "off"){ + $path = \Request::path(); + $cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5); + Cookie::queue($fokus . "_setting_zitate", "off", 0, $cookiePath, null, false, false); + }elseif($quotes === "on") { + $path = \Request::path(); + $cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5); + Cookie::queue($fokus . "_setting_zitate", "", 0, $cookiePath, null, false, false); + } } - if($quotes === "off"){ - $path = \Request::path(); - $cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5); - Cookie::queue($fokus . "_setting_zitate", "off", 0, $cookiePath, null, false, false); - }elseif($quotes === "on") { - $path = \Request::path(); - $cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5); - Cookie::queue($fokus . "_setting_zitate", "", 0, $cookiePath, null, false, false); - }else{ - abort(404); + $darkmode = $request->input('dm'); + if(!empty($darkmode)){ + if($darkmode === "off"){ + Cookie::queue('dark_mode', '1', 0, '/', null, false, false); + }elseif($darkmode === "on") { + Cookie::queue('dark_mode', '2', 0, '/', null, false, false); + }elseif($darkmode === "system"){ + Cookie::queue('dark_mode', '', 0, '/', null, false, false); + } } + return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url]))); } @@ -408,34 +417,4 @@ class SettingsController extends Controller return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), url('/'))); } - - public function darkmode(Request $request) - { - $fokus = $request->input('fokus', ''); - $url = $request->input('url', ''); - - $path = \Request::path(); - $cookiePath = "/"; - - $cookies = Cookie::get(); - $setCookie = true; - - $darkmode = "0"; - - if(!empty($cookies)){ - foreach($cookies as $key => $value){ - if($key === 'dark_mode'){ - if($value === "0" || $value == "1"){ - $darkmode = "2"; - }elseif($value === "2"){ - $darkmode = "1"; - } - Cookie::queue('dark_mode', $darkmode, 0, $cookiePath, null, false, false); - $setCookie = false; - } - } - }else{ - Cookie::queue('dark_mode', "2", 0, $cookiePath, null, false, false); - } - return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url]))); } } diff --git a/resources/lang/de/settings.php b/resources/lang/de/settings.php index ae113833a52c9c9ae8759aa8c0739571f6933597..fd04c613f6837ffa14b90f818f9dc9b67aad8b0c 100644 --- a/resources/lang/de/settings.php +++ b/resources/lang/de/settings.php @@ -25,7 +25,11 @@ return [ 'add' => 'Hinzufügen', 'clear' => 'Blacklist leeren', 'copy' => 'Kopieren', + 'darkmode' => 'Dunklen Modus umschalten', + 'system' => 'Systemstandard', + 'dark' => 'Dunkel', + 'light' => 'Hell', // Translations from the settings overview 'noSettings' => 'Aktuell sind keine Einstellungen gesetzt!', diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index bbb9dd8fdc693cb4e8555fa586314d640f43c021..fe734139b1bdb7fba9a2d3a2c313f1a52d96a77e 100644 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -25,7 +25,11 @@ return [ 'add' => 'Add', 'clear' => 'Clear black list', 'copy' => 'Copy', + 'darkmode' => 'Toggle dark mode', + 'system' => 'System Default', + 'dark' => 'Dark', + 'light' => 'Light', // Translations from the settings overview 'noSettings' => "Currently no settings are set!", diff --git a/resources/views/settings/index.blade.php b/resources/views/settings/index.blade.php index 59ec7ad3401978b364de1ebbf8f03d674562261a..a33037dfe81f10dd75e370cf8f2c10f525dce4f6 100644 --- a/resources/views/settings/index.blade.php +++ b/resources/views/settings/index.blade.php @@ -125,10 +125,18 @@ <div class="card-light"> <h2>Weitere Einstellungen</h2> - @if(LaravelLocalization::getCurrentLocale() === "de") <form id="setting-form" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('enableSetting')) }}" method="post" class="form"> <input type="hidden" name="fokus" value="{{ $fokus }}"> <input type="hidden" name="url" value="{{ $url }}"> + <div class="form-group"> + <label for="dm">@lang('settings.darkmode')</label> + <select name="dm" id="dm" class="form-control"> + <option value="system" {{ !Cookie::has('dark_mode') ? "disabled selected" : "" }}>@lang('settings.system')</option> + <option value="off" {{ Cookie::get('dark_mode') === "1" ? "disabled selected" : "" }}>@lang('settings.light')</option> + <option value="on" {{ Cookie::get('dark_mode') === "2" ? "disabled selected" : "" }}>@lang('settings.dark')</option> + </select> + </div> + @if(LaravelLocalization::getCurrentLocale() === "de") <div class="form-group"> <label for="zitate">Zitate</label> <select name="zitate" id="zitate" class="form-control"> @@ -136,12 +144,9 @@ <option value="off" {{ Cookie::get($fokus . "_setting_zitate") === "off" ? "disabled selected" : "" }}>Nicht Anzeigen</option> </select> </div> + @endif <button type="submit" class="btn btn-default">@lang('settings.save')</button> </form> - @endif - <form id="darkmode" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('darkmode', ["fokus" => $fokus, "url" => $url])) }}" method="post" class="form"> - <button type="submit" class="btn btn-default">@lang('settings.darkmode')</button> - </form> </div> <div class="card-light" id="actions"> @if($settingActive) diff --git a/routes/cookie.php b/routes/cookie.php index babef196fcd6cc498fab2e3185741e3aec5a4222..515dd0ca82b6995d51ad7da0bdab21c300024fdd 100644 --- a/routes/cookie.php +++ b/routes/cookie.php @@ -29,7 +29,6 @@ Route::group( Route::post('all-settings/removeOne', 'SettingsController@removeOneSetting')->name('removeOneSetting'); Route::post('all-settings/removeAll', 'SettingsController@removeAllSettings')->name('removeAllSettings'); Route::get('load-settings', 'SettingsController@loadSettings')->name('loadSettings'); - Route::post('darkmode', 'SettingsController@darkmode')->name('darkmode'); }); } );