From 96dd65af5dc964ca08ce511dde4202e40b852016 Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Wed, 30 Dec 2020 12:21:39 -0500 Subject: [PATCH] refactor: user controller --- app/Http/Controllers/UserController.php | 124 ++++++++++++------------ 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 0a23a4006..7df71e681 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -64,10 +64,10 @@ class UserController extends Controller $bondownload = BonTransactions::where('sender', '=', $user->id)->where([['name', 'like', '%Download%']])->sum('cost'); // With Multipliers - $his_upl_cre = History::where('user_id', '=', $user->id)->sum('uploaded'); + $hisUplCre = History::where('user_id', '=', $user->id)->sum('uploaded'); // Without Multipliers - $his_upl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); - $total = $his_upl_cre - $his_upl; + $hisUpl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); + $total = $hisUplCre - $hisUpl; $realupload = ($user->uploaded - $bonupload) - $total; $realdownload = $user->downloaded + $bondownload; @@ -89,8 +89,8 @@ class UserController extends Controller 'realupload' => $realupload, 'bondownload' => $bondownload, 'realdownload' => $realdownload, - 'his_upl_cre' => $his_upl_cre, - 'his_upl' => $his_upl, + 'his_upl_cre' => $hisUplCre, + 'his_upl' => $hisUpl, 'requested' => $requested, 'filled' => $filled, 'invitedBy' => $invitedBy, @@ -186,11 +186,11 @@ class UserController extends Controller \abort_unless($request->user()->id == $user->id, 403); // Avatar - $max_upload = \config('image.max_upload_size'); + $maxUpload = \config('image.max_upload_size'); if ($request->hasFile('image') && $request->file('image')->getError() === 0) { $image = $request->file('image'); if (\in_array($image->getClientOriginalExtension(), ['jpg', 'JPG', 'jpeg', 'bmp', 'png', 'PNG', 'tiff', 'gif']) && \preg_match('#image/*#', $image->getMimeType())) { - if ($max_upload >= $image->getSize()) { + if ($maxUpload >= $image->getSize()) { $filename = $user->username.'.'.$image->getClientOriginalExtension(); $path = \public_path('/files/img/'.$filename); if ($image->getClientOriginalExtension() !== 'gif') { @@ -209,7 +209,7 @@ class UserController extends Controller $user->image = $user->username.'.'.$image->getClientOriginalExtension(); } else { return \redirect()->route('users.show', ['username' => $user->username]) - ->withErrors('Your avatar is too large, max file size: '.($max_upload / 1_000_000).' MB'); + ->withErrors('Your avatar is too large, max file size: '.($maxUpload / 1_000_000).' MB'); } } } @@ -263,12 +263,12 @@ class UserController extends Controller // Style Settings $user->style = (int) $request->input('theme'); - $css_url = $request->input('custom_css'); - if (isset($css_url) && ! \filter_var($css_url, FILTER_VALIDATE_URL)) { + $cssUrl = $request->input('custom_css'); + if (isset($cssUrl) && ! \filter_var($cssUrl, FILTER_VALIDATE_URL)) { return \redirect()->route('users.show', ['username' => $user->username]) ->withErrors('The URL for the external CSS stylesheet is invalid, try it again with a valid URL.'); } - $user->custom_css = $css_url; + $user->custom_css = $cssUrl; $user->nav = $request->input('sidenav'); // Torrent Settings @@ -1647,10 +1647,10 @@ class UserController extends Controller { $user = User::where('username', '=', $username)->firstOrFail(); if (($request->user()->id == $user->id || $request->user()->group->is_modo)) { - $his_upl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); - $his_upl_cre = History::where('user_id', '=', $user->id)->sum('uploaded'); - $his_downl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); - $his_downl_cre = History::where('user_id', '=', $user->id)->sum('downloaded'); + $hisUpl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); + $hisUplCre = History::where('user_id', '=', $user->id)->sum('uploaded'); + $hisDownl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); + $hisDownlCre = History::where('user_id', '=', $user->id)->sum('downloaded'); $logger = 'user.private.downloads'; @@ -1673,10 +1673,10 @@ class UserController extends Controller 'route' => 'downloads', 'user' => $user, 'downloads' => $downloads, - 'his_upl' => $his_upl, - 'his_upl_cre' => $his_upl_cre, - 'his_downl' => $his_downl, - 'his_downl_cre' => $his_downl_cre, + 'his_upl' => $hisUpl, + 'his_upl_cre' => $hisUplCre, + 'his_downl' => $hisDownl, + 'his_downl_cre' => $hisDownlCre, ]); } $logger = 'user.downloads'; @@ -1749,10 +1749,10 @@ class UserController extends Controller $user = User::where('username', '=', $username)->firstOrFail(); \abort_unless($request->user()->group->is_modo || $request->user()->id == $user->id, 403); - $his_upl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); - $his_upl_cre = History::where('user_id', '=', $user->id)->sum('uploaded'); - $his_downl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); - $his_downl_cre = History::where('user_id', '=', $user->id)->sum('downloaded'); + $hisUpl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); + $hisUplCre = History::where('user_id', '=', $user->id)->sum('uploaded'); + $hisDownl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); + $hisDownlCre = History::where('user_id', '=', $user->id)->sum('downloaded'); if (\config('hitrun.enabled') == true) { $downloads = History::selectRaw('distinct(history.info_hash), max(torrents.name) as name, max(torrents.id), max(history.completed_at) as completed_at, max(history.created_at) as created_at, max(history.id) as id, max(history.user_id) as user_id, max(history.seedtime) as seedtime, max(history.seedtime) as satisfied_at, max(history.seeder) as seeder, max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed')->with(['torrent' => function ($query) { @@ -1776,10 +1776,10 @@ class UserController extends Controller 'route' => 'unsatisfieds', 'user' => $user, 'downloads' => $downloads, - 'his_upl' => $his_upl, - 'his_upl_cre' => $his_upl_cre, - 'his_downl' => $his_downl, - 'his_downl_cre' => $his_downl_cre, + 'his_upl' => $hisUpl, + 'his_upl_cre' => $hisUplCre, + 'his_downl' => $hisDownl, + 'his_downl_cre' => $hisDownlCre, ]); } @@ -1796,10 +1796,10 @@ class UserController extends Controller $user = User::where('username', '=', $username)->firstOrFail(); \abort_unless($request->user()->group->is_modo || $request->user()->id == $user->id, 403); - $his_upl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); - $his_upl_cre = History::where('user_id', '=', $user->id)->sum('uploaded'); - $his_downl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); - $his_downl_cre = History::where('user_id', '=', $user->id)->sum('downloaded'); + $hisUpl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); + $hisUplCre = History::where('user_id', '=', $user->id)->sum('uploaded'); + $hisDownl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); + $hisDownlCre = History::where('user_id', '=', $user->id)->sum('downloaded'); $history = History::with(['torrent' => function ($query) { $query->withAnyStatus(); }])->selectRaw('distinct(history.id),max(history.info_hash) as info_hash,max(history.agent) as agent,max(history.uploaded) as uploaded,max(history.downloaded) as downloaded,max(history.seeder) as seeder,max(history.active) as active,max(history.actual_uploaded) as actual_uploaded,max(history.actual_downloaded) as actual_downloaded,max(history.seedtime) as seedtime,max(history.created_at) as created_at,max(history.updated_at) as updated_at,max(history.completed_at) as completed_at,max(history.immune) as immune,max(history.hitrun) as hitrun,max(history.prewarn) as prewarn,max(torrents.moderated_at) as moderated_at,max(torrents.slug) as slug,max(torrents.user_id) as user_id,max(torrents.name) as name,max(torrents.category_id) as category_id,max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed,max(torrents.status) as status')->leftJoin('torrents', 'torrents.info_hash', '=', 'history.info_hash')->where('history.user_id', '=', $user->id)->groupBy('history.id') @@ -1809,10 +1809,10 @@ class UserController extends Controller 'route' => 'torrents', 'user' => $user, 'history' => $history, - 'his_upl' => $his_upl, - 'his_upl_cre' => $his_upl_cre, - 'his_downl' => $his_downl, - 'his_downl_cre' => $his_downl_cre, + 'his_upl' => $hisUpl, + 'his_upl_cre' => $hisUplCre, + 'his_downl' => $hisDownl, + 'his_downl_cre' => $hisDownlCre, ]); } @@ -1850,10 +1850,10 @@ class UserController extends Controller { $user = User::where('username', '=', $username)->firstOrFail(); if ($request->user()->id == $user->id || $request->user()->group->is_modo) { - $his_upl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); - $his_upl_cre = History::where('user_id', '=', $user->id)->sum('uploaded'); - $his_downl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); - $his_downl_cre = History::where('user_id', '=', $user->id)->sum('downloaded'); + $hisUpl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); + $hisUplCre = History::where('user_id', '=', $user->id)->sum('uploaded'); + $hisDownl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); + $hisDownlCre = History::where('user_id', '=', $user->id)->sum('downloaded'); $logger = 'user.private.uploads'; $uploads = Torrent::with(['tips', 'thanks', 'category'])->selectRaw('distinct(torrents.id),max(torrents.moderated_at) as moderated_at,max(torrents.slug) as slug,max(torrents.user_id) as user_id,max(torrents.name) as name,max(torrents.category_id) as category_id,max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed,max(torrents.created_at) as created_at,max(torrents.status) as status,count(distinct thanks.id) as thanked_total,max(bt.tipped_total) as tipped_total') @@ -1863,10 +1863,10 @@ class UserController extends Controller 'route' => 'uploads', 'user' => $user, 'uploads' => $uploads, - 'his_upl' => $his_upl, - 'his_upl_cre' => $his_upl_cre, - 'his_downl' => $his_downl, - 'his_downl_cre' => $his_downl_cre, + 'his_upl' => $hisUpl, + 'his_upl_cre' => $hisUplCre, + 'his_downl' => $hisDownl, + 'his_downl_cre' => $hisDownlCre, ]); } $logger = 'user.uploads'; @@ -1893,10 +1893,10 @@ class UserController extends Controller \abort_unless($request->user()->group->is_modo || $request->user()->id == $user->id, 403); - $his_upl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); - $his_upl_cre = History::where('user_id', '=', $user->id)->sum('uploaded'); - $his_downl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); - $his_downl_cre = History::where('user_id', '=', $user->id)->sum('downloaded'); + $hisUpl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); + $hisUplCre = History::where('user_id', '=', $user->id)->sum('uploaded'); + $hisDownl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); + $hisDownlCre = History::where('user_id', '=', $user->id)->sum('downloaded'); $active = Peer::with(['torrent' => function ($query) { $query->withAnyStatus(); @@ -1908,10 +1908,10 @@ class UserController extends Controller return \view('user.private.active', ['user' => $user, 'route' => 'active', 'active' => $active, - 'his_upl' => $his_upl, - 'his_upl_cre' => $his_upl_cre, - 'his_downl' => $his_downl, - 'his_downl_cre' => $his_downl_cre, + 'his_upl' => $hisUpl, + 'his_upl_cre' => $hisUplCre, + 'his_downl' => $hisDownl, + 'his_downl_cre' => $hisDownlCre, ]); } @@ -1929,10 +1929,10 @@ class UserController extends Controller \abort_unless($request->user()->group->is_modo || $request->user()->id == $user->id, 403); - $his_upl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); - $his_upl_cre = History::where('user_id', '=', $user->id)->sum('uploaded'); - $his_downl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); - $his_downl_cre = History::where('user_id', '=', $user->id)->sum('downloaded'); + $hisUpl = History::where('user_id', '=', $user->id)->sum('actual_uploaded'); + $hisUplCre = History::where('user_id', '=', $user->id)->sum('uploaded'); + $hisDownl = History::where('user_id', '=', $user->id)->sum('actual_downloaded'); + $hisDownlCre = History::where('user_id', '=', $user->id)->sum('downloaded'); $seeds = Peer::with(['torrent' => function ($query) { $query->withAnyStatus(); @@ -1943,10 +1943,10 @@ class UserController extends Controller return \view('user.private.seeds', ['user' => $user, 'route' => 'seeds', 'seeds' => $seeds, - 'his_upl' => $his_upl, - 'his_upl_cre' => $his_upl_cre, - 'his_downl' => $his_downl, - 'his_downl_cre' => $his_downl_cre, + 'his_upl' => $hisUpl, + 'his_upl_cre' => $hisUplCre, + 'his_downl' => $hisDownl, + 'his_downl_cre' => $hisDownlCre, ]); } @@ -2051,10 +2051,10 @@ class UserController extends Controller $zipArchive->close(); } - $zip_file = $path.'/'.$zipFileName; + $zipFile = $path.'/'.$zipFileName; - if (\file_exists($zip_file)) { - return \response()->download($zip_file)->deleteFileAfterSend(true); + if (\file_exists($zipFile)) { + return \response()->download($zipFile)->deleteFileAfterSend(true); } return \redirect()->back()->withErrors('Something Went Wrong!');