2018-05-26 22:53:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
use App\AccountLog;
|
2018-09-23 22:28:35 +00:00
|
|
|
use App\Following;
|
2019-07-12 01:53:14 +00:00
|
|
|
use App\ProfileSponsor;
|
2019-02-05 20:59:31 +00:00
|
|
|
use App\Report;
|
2018-09-23 22:28:35 +00:00
|
|
|
use App\UserFilter;
|
2021-07-23 15:47:14 +00:00
|
|
|
use App\UserSetting;
|
2019-04-22 05:39:00 +00:00
|
|
|
use Auth, Cookie, DB, Cache, Purify;
|
2021-07-21 08:00:57 +00:00
|
|
|
use Illuminate\Support\Facades\Redis;
|
2018-12-25 05:41:53 +00:00
|
|
|
use Carbon\Carbon;
|
2018-08-28 03:07:36 +00:00
|
|
|
use Illuminate\Http\Request;
|
2019-07-12 03:04:47 +00:00
|
|
|
use Illuminate\Support\Str;
|
2018-09-17 01:47:19 +00:00
|
|
|
use App\Http\Controllers\Settings\{
|
2021-05-01 18:40:32 +00:00
|
|
|
ExportSettings,
|
|
|
|
LabsSettings,
|
|
|
|
HomeSettings,
|
|
|
|
PrivacySettings,
|
|
|
|
RelationshipSettings,
|
|
|
|
SecuritySettings
|
2018-09-17 01:47:19 +00:00
|
|
|
};
|
2018-12-21 06:18:06 +00:00
|
|
|
use App\Jobs\DeletePipeline\DeleteAccountPipeline;
|
2021-07-25 04:13:14 +00:00
|
|
|
use App\Jobs\MediaPipeline\MediaSyncLicensePipeline;
|
2022-12-05 08:09:45 +00:00
|
|
|
use App\Services\AccountService;
|
2018-05-26 22:53:21 +00:00
|
|
|
|
|
|
|
class SettingsController extends Controller
|
|
|
|
{
|
2021-05-01 18:40:32 +00:00
|
|
|
use ExportSettings,
|
|
|
|
LabsSettings,
|
|
|
|
HomeSettings,
|
|
|
|
PrivacySettings,
|
|
|
|
RelationshipSettings,
|
|
|
|
SecuritySettings;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function accessibility()
|
|
|
|
{
|
|
|
|
$settings = Auth::user()->settings;
|
|
|
|
|
|
|
|
return view('settings.accessibility', compact('settings'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function accessibilityStore(Request $request)
|
|
|
|
{
|
|
|
|
$settings = Auth::user()->settings;
|
|
|
|
$fields = [
|
|
|
|
'compose_media_descriptions',
|
|
|
|
'reduce_motion',
|
|
|
|
'optimize_screen_reader',
|
|
|
|
'high_contrast_mode',
|
|
|
|
'video_autoplay',
|
|
|
|
];
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$form = $request->input($field);
|
|
|
|
if ($form == 'on') {
|
|
|
|
$settings->{$field} = true;
|
|
|
|
} else {
|
|
|
|
$settings->{$field} = false;
|
|
|
|
}
|
|
|
|
$settings->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect(route('settings.accessibility'))->with('status', 'Settings successfully updated!');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notifications()
|
|
|
|
{
|
|
|
|
return view('settings.notifications');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function applications()
|
|
|
|
{
|
|
|
|
return view('settings.applications');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataImport()
|
|
|
|
{
|
|
|
|
return view('settings.import.home');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataImportInstagram()
|
|
|
|
{
|
2023-06-12 12:08:25 +00:00
|
|
|
abort(404);
|
2021-05-01 18:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function developers()
|
|
|
|
{
|
|
|
|
return view('settings.developers');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeAccountTemporary(Request $request)
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
abort_if(!config('pixelfed.account_deletion'), 403);
|
|
|
|
abort_if($user->is_admin, 403);
|
|
|
|
|
|
|
|
return view('settings.remove.temporary');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeAccountTemporarySubmit(Request $request)
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
abort_if(!config('pixelfed.account_deletion'), 403);
|
|
|
|
abort_if($user->is_admin, 403);
|
|
|
|
$profile = $user->profile;
|
|
|
|
$user->status = 'disabled';
|
|
|
|
$profile->status = 'disabled';
|
|
|
|
$user->save();
|
|
|
|
$profile->save();
|
|
|
|
Auth::logout();
|
|
|
|
Cache::forget('profiles:private');
|
|
|
|
return redirect('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeAccountPermanent(Request $request)
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
abort_if($user->is_admin, 403);
|
|
|
|
return view('settings.remove.permanent');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeAccountPermanentSubmit(Request $request)
|
|
|
|
{
|
|
|
|
if(config('pixelfed.account_deletion') == false) {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
$user = Auth::user();
|
|
|
|
abort_if(!config('pixelfed.account_deletion'), 403);
|
|
|
|
abort_if($user->is_admin, 403);
|
|
|
|
$profile = $user->profile;
|
|
|
|
$ts = Carbon::now()->addMonth();
|
2022-12-05 08:09:45 +00:00
|
|
|
$user->email = $user->id;
|
|
|
|
$user->password = '';
|
2021-05-01 18:40:32 +00:00
|
|
|
$user->status = 'delete';
|
|
|
|
$profile->status = 'delete';
|
|
|
|
$user->delete_after = $ts;
|
|
|
|
$profile->delete_after = $ts;
|
|
|
|
$user->save();
|
|
|
|
$profile->save();
|
|
|
|
Cache::forget('profiles:private');
|
2022-12-05 08:09:45 +00:00
|
|
|
AccountService::del($profile->id);
|
2021-05-01 18:40:32 +00:00
|
|
|
Auth::logout();
|
2022-12-05 08:09:45 +00:00
|
|
|
DeleteAccountPipeline::dispatch($user)->onQueue('low');
|
2021-05-01 18:40:32 +00:00
|
|
|
return redirect('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requestFullExport(Request $request)
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
return view('settings.export.show');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function metroDarkMode(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'mode' => 'required|string|in:light,dark'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$mode = $request->input('mode');
|
|
|
|
|
|
|
|
if($mode == 'dark') {
|
2022-05-18 02:21:21 +00:00
|
|
|
$cookie = Cookie::make('dark-mode', 'true', 43800);
|
2021-05-01 18:40:32 +00:00
|
|
|
} else {
|
|
|
|
$cookie = Cookie::forget('dark-mode');
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json([200])->cookie($cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sponsor()
|
|
|
|
{
|
|
|
|
$default = [
|
|
|
|
'patreon' => null,
|
|
|
|
'liberapay' => null,
|
|
|
|
'opencollective' => null
|
|
|
|
];
|
|
|
|
$sponsors = ProfileSponsor::whereProfileId(Auth::user()->profile->id)->first();
|
|
|
|
$sponsors = $sponsors ? json_decode($sponsors->sponsors, true) : $default;
|
|
|
|
return view('settings.sponsor', compact('sponsors'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sponsorStore(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'patreon' => 'nullable|string',
|
|
|
|
'liberapay' => 'nullable|string',
|
|
|
|
'opencollective' => 'nullable|string'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$patreon = Str::startsWith($request->input('patreon'), 'https://') ?
|
|
|
|
substr($request->input('patreon'), 8) :
|
|
|
|
$request->input('patreon');
|
|
|
|
|
|
|
|
$liberapay = Str::startsWith($request->input('liberapay'), 'https://') ?
|
|
|
|
substr($request->input('liberapay'), 8) :
|
|
|
|
$request->input('liberapay');
|
|
|
|
|
|
|
|
$opencollective = Str::startsWith($request->input('opencollective'), 'https://') ?
|
|
|
|
substr($request->input('opencollective'), 8) :
|
|
|
|
$request->input('opencollective');
|
|
|
|
|
|
|
|
$patreon = Str::startsWith($patreon, 'patreon.com/') ? e($patreon) : null;
|
|
|
|
$liberapay = Str::startsWith($liberapay, 'liberapay.com/') ? e($liberapay) : null;
|
|
|
|
$opencollective = Str::startsWith($opencollective, 'opencollective.com/') ? e($opencollective) : null;
|
|
|
|
|
|
|
|
if(empty($patreon) && empty($liberapay) && empty($opencollective)) {
|
2022-05-14 09:42:07 +00:00
|
|
|
return redirect(route('settings'))->with('error', 'An error occured. Please try again later.');
|
2021-05-01 18:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$res = [
|
|
|
|
'patreon' => $patreon,
|
|
|
|
'liberapay' => $liberapay,
|
|
|
|
'opencollective' => $opencollective
|
|
|
|
];
|
|
|
|
|
|
|
|
$sponsors = ProfileSponsor::firstOrCreate([
|
|
|
|
'profile_id' => Auth::user()->profile_id ?? Auth::user()->profile->id
|
|
|
|
]);
|
|
|
|
$sponsors->sponsors = json_encode($res);
|
|
|
|
$sponsors->save();
|
|
|
|
$sponsors = $res;
|
2021-07-23 15:47:14 +00:00
|
|
|
return redirect(route('settings'))->with('status', 'Sponsor settings successfully updated!');
|
2021-05-01 18:40:32 +00:00
|
|
|
}
|
2019-07-12 03:04:47 +00:00
|
|
|
|
2021-07-21 08:00:57 +00:00
|
|
|
public function timelineSettings(Request $request)
|
|
|
|
{
|
2023-07-30 09:55:51 +00:00
|
|
|
$uid = $request->user()->id;
|
2023-07-30 12:29:12 +00:00
|
|
|
$pid = $request->user()->profile_id;
|
|
|
|
$top = Redis::zscore('pf:tl:top', $pid) != false;
|
|
|
|
$replies = Redis::zscore('pf:tl:replies', $pid) != false;
|
2023-07-30 09:55:51 +00:00
|
|
|
$userSettings = UserSetting::firstOrCreate([
|
|
|
|
'user_id' => $uid
|
|
|
|
]);
|
|
|
|
if(!$userSettings || !$userSettings->other) {
|
|
|
|
$userSettings = [
|
|
|
|
'enable_reblogs' => false,
|
2023-07-30 12:29:12 +00:00
|
|
|
'photo_reblogs_only' => false
|
2023-07-30 09:55:51 +00:00
|
|
|
];
|
|
|
|
} else {
|
2023-07-30 12:29:12 +00:00
|
|
|
$userSettings = array_merge([
|
|
|
|
'enable_reblogs' => false,
|
|
|
|
'photo_reblogs_only' => false
|
|
|
|
],
|
|
|
|
$userSettings->other);
|
2023-07-30 09:55:51 +00:00
|
|
|
}
|
2023-07-30 12:29:12 +00:00
|
|
|
return view('settings.timeline', compact('top', 'replies', 'userSettings'));
|
2021-07-21 08:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function updateTimelineSettings(Request $request)
|
|
|
|
{
|
2023-07-30 09:55:51 +00:00
|
|
|
$pid = $request->user()->profile_id;
|
2023-07-30 12:29:12 +00:00
|
|
|
$uid = $request->user()->id;
|
2023-07-30 09:55:51 +00:00
|
|
|
$this->validate($request, [
|
2023-07-30 12:29:12 +00:00
|
|
|
'enable_reblogs' => 'sometimes',
|
|
|
|
'photo_reblogs_only' => 'sometimes'
|
2023-07-30 09:55:51 +00:00
|
|
|
]);
|
2023-07-30 12:29:12 +00:00
|
|
|
Redis::zrem('pf:tl:top', $pid);
|
|
|
|
Redis::zrem('pf:tl:replies', $pid);
|
2023-07-30 09:55:51 +00:00
|
|
|
$userSettings = UserSetting::firstOrCreate([
|
|
|
|
'user_id' => $uid
|
|
|
|
]);
|
2023-07-30 12:29:12 +00:00
|
|
|
if($userSettings->other) {
|
2023-07-30 09:55:51 +00:00
|
|
|
$other = $userSettings->other;
|
|
|
|
$other['enable_reblogs'] = $request->has('enable_reblogs');
|
2023-07-30 12:29:12 +00:00
|
|
|
$other['photo_reblogs_only'] = $request->has('photo_reblogs_only');
|
2023-07-30 09:55:51 +00:00
|
|
|
} else {
|
|
|
|
$other['enable_reblogs'] = $request->has('enable_reblogs');
|
2023-07-30 12:29:12 +00:00
|
|
|
$other['photo_reblogs_only'] = $request->has('photo_reblogs_only');
|
2023-07-30 09:55:51 +00:00
|
|
|
}
|
|
|
|
$userSettings->other = $other;
|
|
|
|
$userSettings->save();
|
2023-07-30 12:29:12 +00:00
|
|
|
return redirect(route('settings'))->with('status', 'Timeline settings successfully updated!');
|
2021-07-23 15:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function mediaSettings(Request $request)
|
|
|
|
{
|
|
|
|
$setting = UserSetting::whereUserId($request->user()->id)->firstOrFail();
|
2022-02-08 10:30:05 +00:00
|
|
|
$compose = $setting->compose_settings ? (
|
|
|
|
is_string($setting->compose_settings) ? json_decode($setting->compose_settings, true) : $setting->compose_settings
|
|
|
|
) : [
|
2021-07-23 15:47:14 +00:00
|
|
|
'default_license' => null,
|
|
|
|
'media_descriptions' => false
|
|
|
|
];
|
|
|
|
return view('settings.media', compact('compose'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateMediaSettings(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'default' => 'required|int|min:1|max:16',
|
|
|
|
'sync' => 'nullable',
|
|
|
|
'media_descriptions' => 'nullable'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$license = $request->input('default');
|
|
|
|
$sync = $request->input('sync') == 'on';
|
|
|
|
$media_descriptions = $request->input('media_descriptions') == 'on';
|
2021-07-25 04:13:14 +00:00
|
|
|
$uid = $request->user()->id;
|
2021-07-23 15:47:14 +00:00
|
|
|
|
2021-07-25 04:13:14 +00:00
|
|
|
$setting = UserSetting::whereUserId($uid)->firstOrFail();
|
2022-02-08 10:35:58 +00:00
|
|
|
$compose = is_string($setting->compose_settings) ? json_decode($setting->compose_settings, true) : $setting->compose_settings;
|
2021-07-23 15:47:14 +00:00
|
|
|
$changed = false;
|
|
|
|
|
2021-07-25 04:13:14 +00:00
|
|
|
if($sync) {
|
|
|
|
$key = 'pf:settings:mls_recently:'.$uid;
|
|
|
|
if(Cache::get($key) == 2) {
|
|
|
|
$msg = 'You can only sync licenses twice per 24 hours. Try again later.';
|
|
|
|
return redirect(route('settings'))
|
|
|
|
->with('error', $msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 15:47:14 +00:00
|
|
|
if(!isset($compose['default_license']) || $compose['default_license'] !== $license) {
|
|
|
|
$compose['default_license'] = (int) $license;
|
|
|
|
$changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!isset($compose['media_descriptions']) || $compose['media_descriptions'] !== $media_descriptions) {
|
|
|
|
$compose['media_descriptions'] = $media_descriptions;
|
|
|
|
$changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($changed) {
|
2022-09-19 09:39:33 +00:00
|
|
|
$setting->compose_settings = $compose;
|
2021-07-23 15:47:14 +00:00
|
|
|
$setting->save();
|
|
|
|
Cache::forget('profile:compose:settings:' . $request->user()->id);
|
|
|
|
}
|
|
|
|
|
2021-07-25 04:13:14 +00:00
|
|
|
if($sync) {
|
|
|
|
$val = Cache::has($key) ? 2 : 1;
|
|
|
|
Cache::put($key, $val, 86400);
|
|
|
|
MediaSyncLicensePipeline::dispatch($uid, $license);
|
|
|
|
return redirect(route('settings'))->with('status', 'Media licenses successfully synced! It may take a few minutes to take effect for every post.');
|
|
|
|
}
|
|
|
|
|
2021-07-23 15:47:14 +00:00
|
|
|
return redirect(route('settings'))->with('status', 'Media settings successfully updated!');
|
2021-07-21 08:00:57 +00:00
|
|
|
}
|
|
|
|
|
2018-05-26 22:53:21 +00:00
|
|
|
}
|
2018-08-31 04:29:38 +00:00
|
|
|
|