1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-29 11:15:09 +00:00
pixelfed/app/Http/Controllers/Settings/LabsSettings.php

97 lines
1.9 KiB
PHP
Raw Normal View History

2019-04-28 22:39:26 +00:00
<?php
namespace App\Http\Controllers\Settings;
use Illuminate\Http\Request;
2019-12-11 06:04:03 +00:00
use Cookie;
use Illuminate\Support\Facades\Redis;
2019-04-28 22:39:26 +00:00
use App\Services\SuggestionService;
trait LabsSettings {
public function __constructor()
{
$this->middleware('auth');
}
public function labs(Request $request)
{
$profile = $request->user()->profile;
return view('settings.labs', compact('profile'));
}
public function labsStore(Request $request)
{
$this->validate($request, [
'profile_layout' => 'nullable',
'dark_mode' => 'nullable',
2019-05-05 00:15:34 +00:00
'profile_suggestions' => 'nullable',
'moment_bg' => 'nullable'
2019-04-28 22:39:26 +00:00
]);
$changes = false;
$profile = $request->user()->profile;
$cookie = Cookie::forget('dark-mode');
2019-04-29 03:32:22 +00:00
if($request->has('dark_mode')) {
2019-04-28 22:39:26 +00:00
if($request->dark_mode == 'on') {
2022-05-18 02:18:16 +00:00
$cookie = Cookie::make('dark-mode', 'true', 43800);
2019-04-28 22:39:26 +00:00
}
}
if($request->has('profile_layout')) {
2019-04-28 22:39:26 +00:00
} else {
2019-04-29 03:32:22 +00:00
$profile->profile_layout = null;
$changes = true;
2019-04-28 22:39:26 +00:00
}
if($request->has('profile_suggestions')) {
if($profile->is_suggestable == false) {
$profile->is_suggestable = true;
$changes = true;
2019-05-13 04:19:18 +00:00
if($profile->statuses->count() > 0) {
SuggestionService::set($profile->id);
}
2019-04-29 03:32:22 +00:00
}
2019-04-28 22:39:26 +00:00
} else {
2019-04-29 03:32:22 +00:00
$profile->is_suggestable = false;
$changes = true;
SuggestionService::del($profile->id);
2019-04-28 22:39:26 +00:00
}
2019-05-05 00:15:34 +00:00
if($request->has('moment_bg') && $profile->profile_layout == 'moment') {
$bg = in_array($request->input('moment_bg'), $this->momentBackgrounds()) ? $request->input('moment_bg') : 'default';
$profile->header_bg = $bg;
$changes = true;
}
2019-04-28 22:39:26 +00:00
if($changes == true) {
$profile->save();
}
return redirect(route('settings.labs'))
->with('status', 'Labs preferences successfully updated!')
->cookie($cookie);
}
2019-05-05 00:15:34 +00:00
protected function momentBackgrounds()
{
return [
'default',
'azure',
'passion',
'reef',
'lush',
'neon',
'flare',
'morning',
'tranquil',
'mauve',
'argon',
'royal'
];
}
2022-05-18 02:18:16 +00:00
}