SettingsController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\AccountLog;
  4. use App\Following;
  5. use App\UserFilter;
  6. use Auth;
  7. use DB;
  8. use Cache;
  9. use Purify;
  10. use Illuminate\Http\Request;
  11. use App\Http\Controllers\Settings\{
  12. HomeSettings,
  13. PrivacySettings,
  14. SecuritySettings
  15. };
  16. class SettingsController extends Controller
  17. {
  18. use HomeSettings,
  19. PrivacySettings,
  20. SecuritySettings;
  21. public function __construct()
  22. {
  23. $this->middleware('auth');
  24. }
  25. public function accessibility()
  26. {
  27. $settings = Auth::user()->settings;
  28. return view('settings.accessibility', compact('settings'));
  29. }
  30. public function accessibilityStore(Request $request)
  31. {
  32. $settings = Auth::user()->settings;
  33. $fields = [
  34. 'compose_media_descriptions',
  35. 'reduce_motion',
  36. 'optimize_screen_reader',
  37. 'high_contrast_mode',
  38. 'video_autoplay',
  39. ];
  40. foreach ($fields as $field) {
  41. $form = $request->input($field);
  42. if ($form == 'on') {
  43. $settings->{$field} = true;
  44. } else {
  45. $settings->{$field} = false;
  46. }
  47. $settings->save();
  48. }
  49. return redirect(route('settings.accessibility'))->with('status', 'Settings successfully updated!');
  50. }
  51. public function notifications()
  52. {
  53. return view('settings.notifications');
  54. }
  55. public function applications()
  56. {
  57. return view('settings.applications');
  58. }
  59. public function dataExport()
  60. {
  61. return view('settings.dataexport');
  62. }
  63. public function exportFollowing()
  64. {
  65. $data = Cache::remember('account:export:profile:following:'.Auth::user()->profile->id, 1440, function() {
  66. return Auth::user()->profile->following()->get()->map(function($i) {
  67. return $i->url();
  68. });
  69. });
  70. return response()->streamDownload(function () use($data) {
  71. echo $data;
  72. }, 'following.json');
  73. }
  74. public function exportFollowers()
  75. {
  76. $data = Cache::remember('account:export:profile:followers:'.Auth::user()->profile->id, 1440, function() {
  77. return Auth::user()->profile->followers()->get()->map(function($i) {
  78. return $i->url();
  79. });
  80. });
  81. return response()->streamDownload(function () use($data) {
  82. echo $data;
  83. }, 'followers.json');
  84. }
  85. public function exportMuteBlockList()
  86. {
  87. $profile = Auth::user()->profile;
  88. $exists = UserFilter::select('id')
  89. ->whereUserId($profile->id)
  90. ->exists();
  91. if(!$exists) {
  92. return redirect()->back();
  93. }
  94. $data = Cache::remember('account:export:profile:muteblocklist:'.Auth::user()->profile->id, 1440, function() use($profile) {
  95. return json_encode([
  96. 'muted' => $profile->mutedProfileUrls(),
  97. 'blocked' => $profile->blockedProfileUrls()
  98. ], JSON_PRETTY_PRINT);
  99. });
  100. return response()->streamDownload(function () use($data) {
  101. echo $data;
  102. }, 'muted-and-blocked-accounts.json');
  103. }
  104. public function dataImport()
  105. {
  106. return view('settings.import.home');
  107. }
  108. public function dataImportInstagram()
  109. {
  110. return view('settings.import.instagram.home');
  111. }
  112. public function developers()
  113. {
  114. return view('settings.developers');
  115. }
  116. }