refactor: reduce temporary variables passed to views

This commit is contained in:
Roardom
2023-06-19 21:17:10 +00:00
parent 1fa4a3e506
commit d2e36c368e
70 changed files with 1179 additions and 1321 deletions
+6 -6
View File
@@ -25,9 +25,9 @@ class ArticleController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$articles = Article::latest()->paginate(6);
return view('article.index', ['articles' => $articles]);
return view('article.index', [
'articles' => Article::latest()->paginate(6),
]);
}
/**
@@ -35,8 +35,8 @@ class ArticleController extends Controller
*/
public function show(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$article = Article::with(['user', 'comments'])->findOrFail($id);
return view('article.show', ['article' => $article]);
return view('article.show', [
'article' => Article::with(['user', 'comments'])->findOrFail($id),
]);
}
}
+1 -1
View File
@@ -89,7 +89,7 @@ class BountyController extends Controller
$requester->notify(new NewRequestBounty('torrent', $sender, $request->input('bonus_value'), $tr));
}
return to_route('requests.show', ['id' => $request->input('request_id')])
return to_route('requests.show', ['id' => $request->integer('request_id')])
->withSuccess(trans('request.added-bonus'));
}
}
+11 -22
View File
@@ -28,29 +28,18 @@ class ForumController extends Controller
*/
public function index(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
$categories = Forum::query()
->with(['forums' => fn ($query) => $query
->whereRelation('permissions', [['show_forum', '=', 1], ['group_id', '=', $user->group_id]])
])
->where('parent_id', '=', 0)
->whereRelation('permissions', [['show_forum', '=', 1], ['group_id', '=', $user->group_id]])
->orderBy('position')
->get();
// Total Forums Count
$numForums = Forum::count();
// Total Posts Count
$numPosts = Post::count();
// Total Topics Count
$numTopics = Topic::count();
return view('forum.index', [
'categories' => $categories,
'num_posts' => $numPosts,
'num_forums' => $numForums,
'num_topics' => $numTopics,
'categories' => Forum::query()
->with(['forums' => fn ($query) => $query
->whereRelation('permissions', [['show_forum', '=', 1], ['group_id', '=', $request->user()->group_id]])
])
->where('parent_id', '=', 0)
->whereRelation('permissions', [['show_forum', '=', 1], ['group_id', '=', $request->user()->group_id]])
->orderBy('position')
->get(),
'num_posts' => Post::count(),
'num_forums' => Forum::count(),
'num_topics' => Topic::count(),
]);
}
+388 -377
View File
@@ -27,7 +27,6 @@ use App\Models\Tv;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Exception;
@@ -44,394 +43,406 @@ class HomeController extends Controller
public function index(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// For Cache
$current = Carbon::now();
$expiresAt = $current->addMinutes(1);
$expiresAt = now()->addMinutes(1);
// Authorized User
$user = $request->user();
// Latest Articles/News Block
$articles = cache()->remember('latest_article', $expiresAt, fn () => Article::latest()->take(1)->get());
foreach ($articles as $article) {
$article->newNews = ($user->last_login->subDays(3)->getTimestamp() < $article->created_at->getTimestamp()) ? 1 : 0;
}
// Latest Torrents Block
$personalFreeleech = cache()->get('personal_freeleech:'.$user->id);
$newest = cache()->remember('newest_torrents', $expiresAt, function () use ($user) {
$newest = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->latest()
->take(5)
->get();
$movieIds = $newest->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $newest->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $newest->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$newest = $newest->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $newest;
});
$seeded = cache()->remember('seeded_torrents', $expiresAt, function () use ($user) {
$seeded = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->latest('seeders')
->take(5)
->get();
$movieIds = $seeded->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $seeded->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $seeded->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$seeded = $seeded->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $seeded;
});
$leeched = cache()->remember('leeched_torrents', $expiresAt, function () use ($user) {
$leeched = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->latest('leechers')
->take(5)
->get();
$movieIds = $leeched->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $leeched->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $leeched->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$leeched = $leeched->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $leeched;
});
$dying = cache()->remember('dying_torrents', $expiresAt, function () use ($user) {
$dying = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->where('seeders', '=', 1)
->where('times_completed', '>=', 1)
->latest('leechers')
->take(5)
->get();
$movieIds = $dying->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $dying->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $dying->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$dying = $dying->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $dying;
});
$dead = cache()->remember('dead_torrents', $expiresAt, function () use ($user) {
$dead = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->where('seeders', '=', 0)
->latest('leechers')
->take(5)
->get();
$movieIds = $dead->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $dead->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $dead->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$dead = $dead->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $dead;
});
// Latest Topics Block
$topics = cache()->remember('latest_topics', $expiresAt, fn () => Topic::with('forum')->latest()->take(5)->get());
// Latest Posts Block
$posts = cache()->remember(
'latest_posts',
$expiresAt,
fn () => Post::with('topic', 'user')
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
->latest()
->take(5)
->get()
);
// Online Block
$users = cache()->remember('online_users', $expiresAt, fn () => User::with('group', 'privacy')
->withCount([
'warnings' => function (Builder $query): void {
$query->whereNotNull('torrent')->where('active', '1');
},
])
->where('last_action', '>', now()->subMinutes(60))
->get());
$groups = cache()->remember('user-groups', $expiresAt, fn () => Group::select(['name', 'color', 'effect', 'icon'])->oldest('position')->get());
// Featured Torrents Block
$featured = cache()->remember('latest_featured', $expiresAt, fn () => FeaturedTorrent::with('torrent', 'torrent.resolution', 'torrent.type', 'torrent.category', 'user', 'user.group')->get());
// Latest Poll Block
$poll = cache()->remember('latest_poll', $expiresAt, fn () => Poll::latest()->first());
// Top Uploaders Block
$uploaders = cache()->remember('top_uploaders', $expiresAt, fn () => Torrent::with(['user', 'user.group'])
->select(DB::raw('user_id, count(*) as value'))
->groupBy('user_id')
->latest('value')
->take(10)
->get());
$pastUploaders = cache()->remember('month_uploaders', $expiresAt, fn () => Torrent::with(['user', 'user.group'])
->where('created_at', '>', $current->copy()->subDays(30)->toDateTimeString())
->select(DB::raw('user_id, count(*) as value'))
->groupBy('user_id')
->latest('value')
->take(10)
->get());
$freeleechTokens = FreeleechToken::where('user_id', $user->id)->get();
$bookmarks = Bookmark::where('user_id', $user->id)->get();
return view('home.index', [
'user' => $user,
'personal_freeleech' => $personalFreeleech,
'users' => $users,
'groups' => $groups,
'articles' => $articles,
'newest' => $newest,
'seeded' => $seeded,
'dying' => $dying,
'leeched' => $leeched,
'dead' => $dead,
'topics' => $topics,
'posts' => $posts,
'featured' => $featured,
'poll' => $poll,
'uploaders' => $uploaders,
'past_uploaders' => $pastUploaders,
'freeleech_tokens' => $freeleechTokens,
'bookmarks' => $bookmarks,
'personal_freeleech' => cache()->get('personal_freeleech:'.$user->id),
'users' => cache()->remember(
'online_users',
$expiresAt,
fn () => User::with('group', 'privacy')
->withCount([
'warnings' => function (Builder $query): void {
$query->whereNotNull('torrent')->where('active', '1');
},
])
->where('last_action', '>', now()->subMinutes(5))
->get()
),
'groups' => cache()->remember(
'user-groups',
$expiresAt,
fn () => Group::select([
'name',
'color',
'effect',
'icon'
])
->oldest('position')
->get()
),
'articles' => $articles,
'newest' => cache()->remember(
'newest_torrents',
$expiresAt,
function () use ($user) {
$newest = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->latest()
->take(5)
->get();
$movieIds = $newest->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $newest->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $newest->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$newest = $newest->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $newest;
}
),
'seeded' => cache()->remember(
'seeded_torrents',
$expiresAt,
function () use ($user) {
$seeded = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->latest('seeders')
->take(5)
->get();
$movieIds = $seeded->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $seeded->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $seeded->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$seeded = $seeded->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $seeded;
}
),
'dying' => cache()->remember(
'dying_torrents',
$expiresAt,
function () use ($user) {
$dying = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->where('seeders', '=', 1)
->where('times_completed', '>=', 1)
->latest('leechers')
->take(5)
->get();
$movieIds = $dying->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $dying->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $dying->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$dying = $dying->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $dying;
}
),
'leeched' => cache()->remember(
'leeched_torrents',
$expiresAt,
function () use ($user) {
$leeched = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->latest('leechers')
->take(5)
->get();
$movieIds = $leeched->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $leeched->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $leeched->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$leeched = $leeched->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $leeched;
}
),
'dead' => cache()->remember(
'dead_torrents',
$expiresAt,
function () use ($user) {
$dead = Torrent::with(['user', 'category', 'type', 'resolution'])
->withExists([
'bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id),
'freeleechTokens' => fn ($query) => $query->where('user_id', '=', $user->id),
'history as seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 1),
'history as leeching' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 1)
->where('seeder', '=', 0),
'history as not_completed' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNull('completed_at'),
'history as not_seeding' => fn ($query) => $query->where('user_id', '=', $user->id)
->where('active', '=', 0)
->where('seeder', '=', 1)
->whereNotNull('completed_at'),
])
->selectRaw("
CASE
WHEN category_id IN (SELECT `id` from `categories` where `movie_meta` = 1) THEN 'movie'
WHEN category_id IN (SELECT `id` from `categories` where `tv_meta` = 1) THEN 'tv'
WHEN category_id IN (SELECT `id` from `categories` where `game_meta` = 1) THEN 'game'
WHEN category_id IN (SELECT `id` from `categories` where `music_meta` = 1) THEN 'music'
WHEN category_id IN (SELECT `id` from `categories` where `no_meta` = 1) THEN 'no'
END as meta
")
->withCount(['thanks', 'comments'])
->where('seeders', '=', 0)
->latest('leechers')
->take(5)
->get();
$movieIds = $dead->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $dead->where('meta', '=', 'tv')->pluck('tmdb');
$gameIds = $dead->where('meta', '=', 'game')->pluck('igdb');
$movies = Movie::with('genres')->whereIntegerInRaw('id', $movieIds)->get()->keyBy('id');
$tv = Tv::with('genres')->whereIntegerInRaw('id', $tvIds)->get()->keyBy('id');
$games = [];
foreach ($gameIds as $gameId) {
$games[$gameId] = \MarcReichel\IGDBLaravel\Models\Game::with(['cover' => ['url', 'image_id']])->find($gameId);
}
$dead = $dead->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
return $torrent;
});
return $dead;
}
),
'topics' => cache()->remember(
'latest_topics',
$expiresAt,
fn () => Topic::with('forum')->latest()->take(5)->get()
),
'posts' => cache()->remember(
'latest_posts',
$expiresAt,
fn () => Post::with('topic', 'user')
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
->latest()
->take(5)
->get()
),
'featured' => cache()->remember(
'latest_featured',
$expiresAt,
fn () => FeaturedTorrent::with([
'torrent',
'torrent.resolution',
'torrent.type',
'torrent.category',
'user',
'user.group'
])->get()
),
'poll' => cache()->remember('latest_poll', $expiresAt, fn () => Poll::latest()->first()),
'uploaders' => cache()->remember('top_uploaders', $expiresAt, fn () => Torrent::with(['user', 'user.group'])
->select(DB::raw('user_id, count(*) as value'))
->groupBy('user_id')
->latest('value')
->take(10)
->get()),
'past_uploaders' => cache()->remember('month_uploaders', $expiresAt, fn () => Torrent::with(['user', 'user.group'])
->where('created_at', '>', now()->subDays(30)->toDateTimeString())
->select(DB::raw('user_id, count(*) as value'))
->groupBy('user_id')
->latest('value')
->take(10)
->get()),
'freeleech_tokens' => FreeleechToken::where('user_id', $user->id)->get(),
'bookmarks' => Bookmark::where('user_id', $user->id)->get(),
]);
}
}
@@ -31,10 +31,8 @@ class CollectionController extends Controller
*/
public function show(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$collection = Collection::with(['movie' => fn ($query) => $query->has('torrents'), 'comments'])->findOrFail($id);
return view('mediahub.collection.show', [
'collection' => $collection,
'collection' => Collection::with(['movie' => fn ($query) => $query->has('torrents'), 'comments'])->findOrFail($id),
]);
}
}
@@ -23,8 +23,8 @@ class GenreController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$genres = Genre::withCount(['tv', 'movie'])->orderBy('name')->get();
return view('mediahub.genre.index', ['genres' => $genres]);
return view('mediahub.genre.index', [
'genres' => Genre::withCount(['tv', 'movie'])->orderBy('name')->get(),
]);
}
}
@@ -30,25 +30,15 @@ class HomeController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$tv = Tv::count();
$movies = Movie::count();
$collections = Collection::count();
$persons = Person::whereNotNull('still')->count();
$genres = Genre::count();
$networks = Network::count();
$companies = Company::count();
$movieCategoryIds = Category::where('movie_meta', '=', 1)->pluck('id')->toArray();
return view('mediahub.index', [
'tv' => $tv,
'movies' => $movies,
'movieCategoryIds' => $movieCategoryIds,
'collections' => $collections,
'persons' => $persons,
'genres' => $genres,
'networks' => $networks,
'companies' => $companies,
'tv' => Tv::count(),
'movies' => Movie::count(),
'movieCategoryIds' => Category::where('movie_meta', '=', 1)->pluck('id')->toArray(),
'collections' => Collection::count(),
'persons' => Person::whereNotNull('still')->count(),
'genres' => Genre::count(),
'networks' => Network::count(),
'companies' => Company::count(),
]);
}
}
@@ -32,21 +32,15 @@ class PersonController extends Controller
*/
public function show(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$person = Person::with([
'tv' => fn ($query) => $query->has('torrents'),
'tv.genres',
'movie' => fn ($query) => $query->has('torrents'),
'movie.genres'
])->findOrFail($id);
$movieCategoryIds = Category::where('movie_meta', '=', 1)->pluck('id')->toArray();
$tvCategoryIds = Category::where('tv_meta', '=', 1)->pluck('id')->toArray();
return view('mediahub.person.show', [
'person' => $person,
'movieCategoryIds' => $movieCategoryIds,
'tvCategoryIds' => $tvCategoryIds
'person' => Person::with([
'tv' => fn ($query) => $query->has('torrents'),
'tv.genres',
'movie' => fn ($query) => $query->has('torrents'),
'movie.genres'
])->findOrFail($id),
'movieCategoryIds' => Category::where('movie_meta', '=', 1)->pluck('id')->toArray(),
'tvCategoryIds' => Category::where('tv_meta', '=', 1)->pluck('id')->toArray()
]);
}
}
@@ -25,11 +25,10 @@ class TvSeasonController extends Controller
public function show(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$season = Season::with(['episodes', 'torrents'])->findOrFail($id);
$show = Tv::find($season->tv_id);
return view('mediahub.tv.season.show', [
'season' => $season,
'show' => $show,
'show' => Tv::find($season->tv_id),
]);
}
}
@@ -31,10 +31,10 @@ class TvShowController extends Controller
*/
public function show(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$show = Tv::with(['seasons', 'genres', 'networks', 'companies', 'torrents'])->withCount('torrents')->findOrFail($id);
return view('mediahub.tv.show', [
'show' => $show,
'show' => Tv::with(['seasons', 'genres', 'networks', 'companies', 'torrents'])
->withCount('torrents')
->findOrFail($id),
]);
}
}
+23 -24
View File
@@ -13,7 +13,6 @@
namespace App\Http\Controllers;
use App\Models\BlacklistClient;
use App\Models\Group;
use App\Models\Internal;
use App\Models\Page;
@@ -28,9 +27,9 @@ class PageController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$pages = Page::all();
return view('page.index', ['pages' => $pages]);
return view('page.index', [
'pages' => Page::all(),
]);
}
/**
@@ -38,9 +37,9 @@ class PageController extends Controller
*/
public function show(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$page = Page::findOrFail($id);
return view('page.page', ['page' => $page]);
return view('page.page', [
'page' => Page::findOrFail($id),
]);
}
/**
@@ -48,14 +47,14 @@ class PageController extends Controller
*/
public function staff(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$staff = Group::query()
->with('users:id,username,group_id,title')
->where('is_modo', '=', 1)
->orWhere('is_admin', '=', 1)
->get()
->sortByDesc('position');
return view('page.staff', ['staff' => $staff]);
return view('page.staff', [
'staff' => Group::query()
->with('users:id,username,group_id,title')
->where('is_modo', '=', 1)
->orWhere('is_admin', '=', 1)
->get()
->sortByDesc('position'),
]);
}
/**
@@ -63,12 +62,12 @@ class PageController extends Controller
*/
public function internal(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$internals = Internal::query()
->with('users')
->orderBy('name')
->get();
return view('page.internal', ['internals' => $internals]);
return view('page.internal', [
'internals' => Internal::query()
->with('users')
->orderBy('name')
->get(),
]);
}
/**
@@ -76,9 +75,9 @@ class PageController extends Controller
*/
public function clientblacklist(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$clients = BlacklistClient::all();
return view('page.blacklist.client', ['clients' => $clients]);
return view('page.blacklist.client', [
'clients' => BlacklistClient::all(),
]);
}
/**
+32 -23
View File
@@ -43,14 +43,21 @@ class PlaylistController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$playlists = Playlist::with(['user:id,username,group_id,image', 'user.group'])->withCount('torrents')->where(function ($query): void {
$query->where('is_private', '=', 0)
->orWhere(function ($query): void {
$query->where('is_private', '=', 1)->where('user_id', '=', auth()->id());
});
})->oldest('name')->paginate(24);
return view('playlist.index', ['playlists' => $playlists]);
return view('playlist.index', [
'playlists' => Playlist::with([
'user:id,username,group_id,image',
'user.group'
])
->withCount('torrents')
->where(function ($query): void {
$query->where('is_private', '=', 0)
->orWhere(function ($query): void {
$query->where('is_private', '=', 1)->where('user_id', '=', auth()->id());
});
})
->oldest('name')
->paginate(24),
]);
}
/**
@@ -142,19 +149,21 @@ class PlaylistController extends Controller
}
}
$torrents = PlaylistTorrent::with(['torrent:id,name,category_id,resolution_id,type_id,tmdb,seeders,leechers,times_completed,size,anon,created_at'])
->where('playlist_id', '=', $playlist->id)
->whereHas('torrent')
->orderBy(function ($query): void {
$query->select('name')
->from('torrents')
->whereColumn('id', 'playlist_torrents.torrent_id')
->latest()
->limit(1);
})
->paginate(26);
return view('playlist.show', ['playlist' => $playlist, 'meta' => $meta, 'torrents' => $torrents]);
return view('playlist.show', [
'playlist' => $playlist,
'meta' => $meta,
'torrents' => PlaylistTorrent::with(['torrent:id,name,category_id,resolution_id,type_id,tmdb,seeders,leechers,times_completed,size,anon,created_at'])
->where('playlist_id', '=', $playlist->id)
->whereHas('torrent')
->orderBy(function ($query): void {
$query->select('name')
->from('torrents')
->whereColumn('id', 'playlist_torrents.torrent_id')
->latest()
->limit(1);
})
->paginate(26),
]);
}
/**
@@ -202,14 +211,14 @@ class PlaylistController extends Controller
]);
if ($v->fails()) {
return to_route('playlists.edit', ['id' => $playlist->id])
return to_route('playlists.edit', ['id' => $id])
->withInput()
->withErrors($v->errors());
}
$playlist->save();
return to_route('playlists.show', ['id' => $playlist->id])
return to_route('playlists.show', ['id' => $id])
->withSuccess(trans('playlist.update-success'));
}
+7 -9
View File
@@ -37,9 +37,9 @@ class PollController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$polls = Poll::latest()->paginate(15);
return view('poll.latest', ['polls' => $polls]);
return view('poll.latest', [
'polls' => Poll::latest()->paginate(15),
]);
}
/**
@@ -48,8 +48,7 @@ class PollController extends Controller
public function show(Request $request, int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Illuminate\Http\RedirectResponse
{
$poll = Poll::findOrFail($id);
$user = $request->user();
$userHasVoted = $poll->voters->where('user_id', '=', $user->id)->isNotEmpty();
$userHasVoted = $poll->voters->where('user_id', '=', $request->user()->id)->isNotEmpty();
if ($userHasVoted) {
return to_route('poll_results', ['id' => $poll->id])
@@ -102,11 +101,10 @@ class PollController extends Controller
public function result(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$poll = Poll::findOrFail($id);
$map = [
return view('poll.result', [
'poll' => $poll,
'total_votes' => $poll->totalVotes(),
];
return view('poll.result', $map);
]);
}
}
+5 -11
View File
@@ -117,13 +117,11 @@ class RequestController extends Controller
*/
public function create(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
return view('requests.create', [
'categories' => Category::orderBy('position')->get(),
'types' => Type::orderBy('position')->get(),
'resolutions' => Resolution::orderBy('position')->get(),
'user' => $user,
'user' => $request->user(),
'category_id' => $request->category_id,
'title' => urldecode($request->title),
'imdb' => $request->imdb,
@@ -225,15 +223,13 @@ class RequestController extends Controller
*/
public function edit(Request $request, int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
$torrentRequest = TorrentRequest::findOrFail($id);
return view('requests.edit', [
'categories' => Category::orderBy('position')->get(),
'types' => Type::orderBy('position')->get(),
'resolutions' => Resolution::orderBy('position')->get(),
'user' => $user,
'torrentRequest' => $torrentRequest, ]);
'user' => $request->user(),
'torrentRequest' => TorrentRequest::findOrFail($id),
]);
}
/**
@@ -452,9 +448,7 @@ class RequestController extends Controller
*/
public function reset(Request $request, int $id): \Illuminate\Http\RedirectResponse
{
$user = $request->user();
abort_unless($user->group->is_modo, 403);
abort_unless($request->user()->group->is_modo, 403);
TorrentRequest::whereKey($id)->update([
'filled_by' => null,
+7 -17
View File
@@ -34,16 +34,11 @@ class RssController extends Controller
*/
public function index(Request $request, $hash = null): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
$publicRss = Rss::where('is_private', '=', 0)->oldest('position')->get();
$privateRss = Rss::where('is_private', '=', 1)->where('user_id', '=', $user->id)->latest()->get();
return view('rss.index', [
'hash' => $hash,
'public_rss' => $publicRss,
'private_rss' => $privateRss,
'user' => $user,
'public_rss' => Rss::where('is_private', '=', 0)->oldest('position')->get(),
'private_rss' => Rss::where('is_private', '=', 1)->where('user_id', '=', $request->user()->id)->latest()->get(),
'user' => $request->user(),
]);
}
@@ -52,14 +47,12 @@ class RssController extends Controller
*/
public function create(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
return view('rss.create', [
'categories' => Category::select(['id', 'name', 'position'])->orderBy('position')->get(),
'types' => Type::select(['id', 'name', 'position'])->orderBy('position')->get(),
'resolutions' => Resolution::select(['id', 'name', 'position'])->orderBy('position')->get(),
'genres' => Genre::orderBy('name')->get(),
'user' => $user,
'user' => $request->user(),
]);
}
@@ -68,8 +61,6 @@ class RssController extends Controller
*/
public function store(Request $request): \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
{
$user = $request->user();
$v = validator($request->all(), [
'name' => 'required|min:3|max:255',
'search' => 'max:255',
@@ -113,13 +104,12 @@ class RssController extends Controller
'dead',
]);
$error = null;
$success = null;
if ($v->passes()) {
$rss = new Rss();
$rss->name = $request->input('name');
$rss->user_id = $user->id;
$rss->user_id = $request->user()->id;
$expected = $rss->expected_fields;
$rss->json_torrent = array_merge($expected, $params);
$rss->is_private = 1;
@@ -212,6 +202,7 @@ class RssController extends Controller
{
$user = $request->user();
$rss = Rss::where('is_private', '=', 1)->findOrFail($id);
abort_unless($user->group->is_modo || $user->id === $rss->user_id, 403);
return view('rss.edit', [
@@ -272,9 +263,8 @@ class RssController extends Controller
'dead',
]);
$error = null;
$success = null;
$redirect = null;
if ($v->passes()) {
$expected = $rss->expected_fields;
$push = array_merge($expected, $params);
@@ -35,12 +35,12 @@ class ApplicationController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$applications = Application::withAnyStatus()
->with(['user', 'moderated', 'imageProofs', 'urlProofs'])
->latest()
->paginate(25);
return view('Staff.application.index', ['applications' => $applications]);
return view('Staff.application.index', [
'applications' => Application::withAnyStatus()
->with(['user', 'moderated', 'imageProofs', 'urlProofs'])
->latest()
->paginate(25),
]);
}
/**
@@ -48,9 +48,9 @@ class ApplicationController extends Controller
*/
public function show(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$application = Application::withAnyStatus()->with(['user', 'moderated', 'imageProofs', 'urlProofs'])->findOrFail($id);
return view('Staff.application.show', ['application' => $application]);
return view('Staff.application.show', [
'application' => Application::withAnyStatus()->with(['user', 'moderated', 'imageProofs', 'urlProofs'])->findOrFail($id)
]);
}
/**
@@ -30,9 +30,9 @@ class ArticleController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$articles = Article::latest()->paginate(25);
return view('Staff.article.index', ['articles' => $articles]);
return view('Staff.article.index', [
'articles' => $articles = Article::latest()->paginate(25),
]);
}
/**
@@ -66,9 +66,9 @@ class ArticleController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$article = Article::findOrFail($id);
return view('Staff.article.edit', ['article' => $article]);
return view('Staff.article.edit', [
'article' => Article::findOrFail($id)
]);
}
/**
+4 -4
View File
@@ -35,9 +35,9 @@ class BanController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$bans = Ban::latest()->paginate(25);
return view('Staff.ban.index', ['bans' => $bans]);
return view('Staff.ban.index', [
'bans' => Ban::latest()->paginate(25),
]);
}
/**
@@ -75,7 +75,7 @@ class BanController extends Controller
// Send Notifications
$user->notify(new UserBan($ban));
return to_route('users.show', ['username' => $user->username])
return to_route('users.show', ['username' => $username])
->withSuccess('User Is Now Banned!');
}
@@ -29,9 +29,9 @@ class BlacklistClientController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$clients = BlacklistClient::latest()->get();
return view('Staff.blacklist.clients.index', ['clients' => $clients]);
return view('Staff.blacklist.clients.index', [
'clients' => BlacklistClient::latest()->get(),
]);
}
/**
@@ -39,9 +39,9 @@ class BlacklistClientController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
$client = BlacklistClient::findOrFail($id);
return view('Staff.blacklist.clients.edit', ['client' => $client]);
return view('Staff.blacklist.clients.edit', [
'client' => BlacklistClient::findOrFail($id),
]);
}
/**
@@ -26,9 +26,9 @@ class BonExchangeController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$bonExchanges = BonExchange::orderBy('position')->get();
return view('Staff.bon_exchange.index', ['bonExchanges' => $bonExchanges]);
return view('Staff.bon_exchange.index', [
'bonExchanges' => BonExchange::orderBy('position')->get(),
]);
}
/**
@@ -61,9 +61,9 @@ class BonExchangeController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$bonExchange = BonExchange::findOrFail($id);
return view('Staff.bon_exchange.edit', ['bonExchange' => $bonExchange]);
return view('Staff.bon_exchange.edit', [
'bonExchange' => BonExchange::findOrFail($id),
]);
}
/**
@@ -30,9 +30,9 @@ class CategoryController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$categories = Category::orderBy('position')->get();
return view('Staff.category.index', ['categories' => $categories]);
return view('Staff.category.index', [
'categories' => Category::orderBy('position')->get(),
]);
}
/**
@@ -73,9 +73,9 @@ class CategoryController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$category = Category::findOrFail($id);
return view('Staff.category.edit', ['category' => $category]);
return view('Staff.category.edit', [
'category' => Category::findOrFail($id),
]);
}
/**
@@ -29,10 +29,8 @@ class ChatBotController extends Controller
*/
public function index($hash = null): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
$bots = Bot::oldest('position')->get();
return view('Staff.chat.bot.index', [
'bots' => $bots,
'bots' => Bot::oldest('position')->get(),
]);
}
@@ -41,12 +39,9 @@ class ChatBotController extends Controller
*/
public function edit(Request $request, int $id): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
$user = $request->user();
$bot = Bot::findOrFail($id);
return view('Staff.chat.bot.edit', [
'user' => $user,
'bot' => $bot,
'user' => $request->user(),
'bot' => Bot::findOrFail($id),
]);
}
@@ -38,10 +38,8 @@ class ChatRoomController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$chatrooms = $this->chatRepository->rooms();
return view('Staff.chat.room.index', [
'chatrooms' => $chatrooms,
'chatrooms' => $this->chatRepository->rooms(),
]);
}
@@ -69,9 +67,9 @@ class ChatRoomController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$chatroom = Chatroom::findOrFail($id);
return view('Staff.chat.room.edit', ['chatroom' => $chatroom]);
return view('Staff.chat.room.edit', [
'chatroom' => Chatroom::findOrFail($id),
]);
}
/**
@@ -37,10 +37,8 @@ class ChatStatusController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$chatstatuses = $this->chatRepository->statuses();
return view('Staff.chat.status.index', [
'chatstatuses' => $chatstatuses,
'chatstatuses' => $this->chatRepository->statuses(),
]);
}
@@ -15,7 +15,6 @@ namespace App\Http\Controllers\Staff;
use App\Http\Controllers\Controller;
use App\Models\Torrent;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class CheatedTorrentController extends Controller
@@ -25,41 +24,41 @@ class CheatedTorrentController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$cheatedTorrents = Torrent::query()
->select([
'torrents.id',
'torrents.name',
'torrents.seeders',
'torrents.leechers',
'torrents.times_completed',
'torrents.size',
'torrents.balance',
'torrents.balance_offset',
'torrents.created_at',
])
->selectRaw('MAX(history.completed_at) as last_completed')
->selectRaw('MAX(history.created_at) as last_started')
->selectRaw('balance + COALESCE(balance_offset, 0) AS current_balance')
->selectRaw('(CAST((balance + COALESCE(balance_offset, 0)) AS float) / CAST((size + 1) AS float)) AS times_cheated')
->join('history', 'history.torrent_id', '=', 'torrents.id')
->groupBy([
'torrents.id',
'torrents.name',
'torrents.seeders',
'torrents.leechers',
'torrents.times_completed',
'torrents.size',
'torrents.balance',
'torrents.balance_offset',
'torrents.created_at',
])
->having('current_balance', '<>', '0')
->having('last_completed', '<', Carbon::now()->subHours(2))
->having('last_started', '<', Carbon::now()->subHours(2))
->orderByDesc('times_cheated')
->paginate(25);
return view('Staff.cheated_torrent.index', ['torrents' => $cheatedTorrents]);
return view('Staff.cheated_torrent.index', [
'torrents' => Torrent::query()
->select([
'torrents.id',
'torrents.name',
'torrents.seeders',
'torrents.leechers',
'torrents.times_completed',
'torrents.size',
'torrents.balance',
'torrents.balance_offset',
'torrents.created_at',
])
->selectRaw('MAX(history.completed_at) as last_completed')
->selectRaw('MAX(history.created_at) as last_started')
->selectRaw('balance + COALESCE(balance_offset, 0) AS current_balance')
->selectRaw('(CAST((balance + COALESCE(balance_offset, 0)) AS float) / CAST((size + 1) AS float)) AS times_cheated')
->join('history', 'history.torrent_id', '=', 'torrents.id')
->groupBy([
'torrents.id',
'torrents.name',
'torrents.seeders',
'torrents.leechers',
'torrents.times_completed',
'torrents.size',
'torrents.balance',
'torrents.balance_offset',
'torrents.created_at',
])
->having('current_balance', '<>', '0')
->having('last_completed', '<', now()->subHours(2))
->having('last_started', '<', now()->subHours(2))
->orderByDesc('times_cheated')
->paginate(25),
]);
}
/**
@@ -29,20 +29,20 @@ class CheaterController extends Controller
{
$bannedGroup = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));
$cheaters = User::query()
->whereHas('history', function ($query): void {
$query->where('seeder', '=', 0);
$query->where('active', '=', 0);
$query->where('seedtime', '=', 0);
$query->where('actual_downloaded', '=', 0);
$query->where('actual_uploaded', '=', 0);
$query->whereNull('completed_at');
})
->where('group_id', '!=', $bannedGroup[0]) // Banned Users
->where('id', '!=', 1) // System
->latest()
->paginate(25);
return view('Staff.cheater.index', ['cheaters' => $cheaters]);
return view('Staff.cheater.index', [
'cheaters' => User::query()
->whereHas('history', function ($query): void {
$query->where('seeder', '=', 0);
$query->where('active', '=', 0);
$query->where('seedtime', '=', 0);
$query->where('actual_downloaded', '=', 0);
$query->where('actual_uploaded', '=', 0);
$query->whereNull('completed_at');
})
->where('group_id', '!=', $bannedGroup[0]) // Banned Users
->where('id', '!=', 1) // System
->latest()
->paginate(25),
]);
}
}
@@ -28,9 +28,9 @@ class DistributorController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$distributors = Distributor::orderBy('position')->get();
return view('Staff.distributor.index', ['distributors' => $distributors]);
return view('Staff.distributor.index', [
'distributors' => Distributor::orderBy('position')->get(),
]);
}
/**
@@ -57,9 +57,9 @@ class DistributorController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$distributor = Distributor::findOrFail($id);
return view('Staff.distributor.edit', ['distributor' => $distributor]);
return view('Staff.distributor.edit', [
'distributor' => Distributor::findOrFail($id),
]);
}
/**
@@ -78,10 +78,10 @@ class DistributorController extends Controller
*/
public function delete(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$distributors = Distributor::orderBy('position')->get();
$distributor = Distributor::findOrFail($id);
return view('Staff.distributor.delete', ['distributors' => $distributors, 'distributor' => $distributor]);
return view('Staff.distributor.delete', [
'distributors' => Distributor::orderBy('position')->get(),
'distributor' => Distributor::findOrFail($id),
]);
}
/**
+10 -14
View File
@@ -32,9 +32,9 @@ class ForumController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$categories = Forum::orderBy('position')->where('parent_id', '=', 0)->get();
return view('Staff.forum.index', ['categories' => $categories]);
return view('Staff.forum.index', [
'categories' => Forum::orderBy('position')->where('parent_id', '=', 0)->get(),
]);
}
/**
@@ -42,10 +42,10 @@ class ForumController extends Controller
*/
public function create(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$categories = Forum::where('parent_id', '=', 0)->get();
$groups = Group::all();
return view('Staff.forum.create', ['categories' => $categories, 'groups' => $groups]);
return view('Staff.forum.create', [
'categories' => Forum::where('parent_id', '=', 0)->get(),
'groups' => Group::all(),
]);
}
/**
@@ -100,14 +100,10 @@ class ForumController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$forum = Forum::findOrFail($id);
$categories = Forum::where('parent_id', '=', 0)->get();
$groups = Group::all();
return view('Staff.forum.edit', [
'categories' => $categories,
'groups' => $groups,
'forum' => $forum,
'categories' => Forum::where('parent_id', '=', 0)->get(),
'groups' => Group::all(),
'forum' => Forum::findOrFail($id),
]);
}
@@ -33,9 +33,9 @@ class GroupController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$groups = Group::orderBy('position')->get();
return view('Staff.group.index', ['groups' => $groups]);
return view('Staff.group.index', [
'groups' => Group::orderBy('position')->get(),
]);
}
/**
@@ -73,9 +73,9 @@ class GroupController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$group = Group::findOrFail($id);
return view('Staff.group.edit', ['group' => $group]);
return view('Staff.group.edit', [
'group' => Group::findOrFail($id),
]);
}
/**
+34 -55
View File
@@ -36,42 +36,6 @@ class HomeController extends Controller
// User Info
$bannedGroup = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));
$validatingGroup = cache()->rememberForever('validating_group', fn () => Group::where('slug', '=', 'validating')->pluck('id'));
$users = cache()->remember('dashboard_users', 300, function () use ($bannedGroup, $validatingGroup) {
return DB::table('users')
->selectRaw('count(*) as total')
->selectRaw(sprintf('count(case when group_id = %s then 1 end) as banned', $bannedGroup[0]))
->selectRaw(sprintf('count(case when group_id = %s then 1 end) as validating', $validatingGroup[0]))
->first();
});
// Torrent Info
$torrents = cache()->remember('dashboard_torrents', 300, function () {
return DB::table('torrents')
->selectRaw('count(*) as total')
->selectRaw('count(case when status = 0 then 1 end) as pending')
->selectRaw('count(case when status = 2 then 1 end) as rejected')
->selectRaw('count(case when status = 3 then 1 end) as postponed')
->first();
});
// Peers Info
$peers = cache()->remember('dashboard_peers', 300, function () {
return DB::table('peers')
->selectRaw('count(*) as total')
->selectRaw('count(case when seeder = 0 then 1 end) as leechers')
->selectRaw('count(case when seeder = 1 then 1 end) as seeders')
->first();
});
// Reports Info
$reports = DB::table('reports')
->selectRaw('count(case when solved = 0 then 1 end) as unsolved')
->first();
// Pending Applications Count
$apps = DB::table('applications')
->selectRaw('count(case when status = 0 then 1 end) as pending')
->first();
// SSL Info
try {
@@ -82,28 +46,43 @@ class HomeController extends Controller
// System Information
$systemInformation = new SystemInformation();
$uptime = $systemInformation->uptime();
$ram = $systemInformation->memory();
$disk = $systemInformation->disk();
$avg = $systemInformation->avg();
$basic = $systemInformation->basic();
// Directory Permissions
$filePermissions = $systemInformation->directoryPermissions();
return view('Staff.dashboard.index', [
'users' => $users,
'torrents' => $torrents,
'peers' => $peers,
'reports' => $reports,
'apps' => $apps,
'users' => cache()->remember('dashboard_users', 300, function () use ($bannedGroup, $validatingGroup) {
return DB::table('users')
->selectRaw('count(*) as total')
->selectRaw(sprintf('count(case when group_id = %s then 1 end) as banned', $bannedGroup[0]))
->selectRaw(sprintf('count(case when group_id = %s then 1 end) as validating', $validatingGroup[0]))
->first();
}),
'torrents' => cache()->remember('dashboard_torrents', 300, function () {
return DB::table('torrents')
->selectRaw('count(*) as total')
->selectRaw('count(case when status = 0 then 1 end) as pending')
->selectRaw('count(case when status = 2 then 1 end) as rejected')
->selectRaw('count(case when status = 3 then 1 end) as postponed')
->first();
}),
'peers' => cache()->remember('dashboard_peers', 300, function () {
return DB::table('peers')
->selectRaw('count(*) as total')
->selectRaw('count(case when seeder = 0 then 1 end) as leechers')
->selectRaw('count(case when seeder = 1 then 1 end) as seeders')
->first();
}),
'reports' => DB::table('reports')
->selectRaw('count(case when solved = 0 then 1 end) as unsolved')
->first(),
'apps' => DB::table('applications')
->selectRaw('count(case when status = 0 then 1 end) as pending')
->first(),
'certificate' => $certificate,
'uptime' => $uptime,
'ram' => $ram,
'disk' => $disk,
'avg' => $avg,
'basic' => $basic,
'file_permissions' => $filePermissions,
'uptime' => $systemInformation->uptime(),
'ram' => $systemInformation->memory(),
'disk' => $systemInformation->disk(),
'avg' => $systemInformation->avg(),
'basic' => $systemInformation->basic(),
'file_permissions' => $systemInformation->directoryPermissions(),
]);
}
}
@@ -28,9 +28,9 @@ class InternalController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$internals = Internal::orderBy('name')->get();
return view('Staff.internals.index', ['internals' => $internals]);
return view('Staff.internals.index', [
'internals' => Internal::orderBy('name')->get(),
]);
}
/**
@@ -38,9 +38,9 @@ class InternalController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
$internal = Internal::findOrFail($id);
return view('Staff.internals.edit', ['internal' => $internal]);
return view('Staff.internals.edit', [
'internal' => Internal::findOrFail($id),
]);
}
/**
@@ -26,9 +26,9 @@ class MediaLanguageController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$mediaLanguages = MediaLanguage::orderBy('name')->get();
return view('Staff.media_language.index', ['media_languages' => $mediaLanguages]);
return view('Staff.media_language.index', [
'media_languages' => MediaLanguage::orderBy('name')->get(),
]);
}
/**
@@ -55,9 +55,9 @@ class MediaLanguageController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$mediaLanguage = MediaLanguage::findOrFail($id);
return view('Staff.media_language.edit', ['media_language' => $mediaLanguage]);
return view('Staff.media_language.edit', [
'media_language' => MediaLanguage::findOrFail($id),
]);
}
/**
@@ -20,7 +20,6 @@ use App\Models\PrivateMessage;
use App\Models\Torrent;
use App\Repositories\ChatRepository;
use App\Services\Unit3dAnnounce;
use Illuminate\Support\Carbon;
/**
* @see \Tests\Todo\Feature\Http\Controllers\Staff\ModerationControllerTest
@@ -39,16 +38,11 @@ class ModerationController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$current = Carbon::now();
$pending = Torrent::with(['user:id,username,group_id', 'user.group', 'category', 'type'])->pending()->get();
$postponed = Torrent::with(['user:id,username,group_id', 'user.group', 'category', 'type'])->postponed()->get();
$rejected = Torrent::with(['user:id,username,group_id', 'user.group', 'category', 'type'])->rejected()->get();
return view('Staff.moderation.index', [
'current' => $current,
'pending' => $pending,
'postponed' => $postponed,
'rejected' => $rejected,
'current' => now(),
'pending' => Torrent::with(['user:id,username,group_id', 'user.group', 'category', 'type'])->pending()->get(),
'postponed' => Torrent::with(['user:id,username,group_id', 'user.group', 'category', 'type'])->postponed()->get(),
'rejected' => Torrent::with(['user:id,username,group_id', 'user.group', 'category', 'type'])->rejected()->get(),
]);
}
@@ -29,9 +29,9 @@ class PageController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$pages = Page::all();
return view('Staff.page.index', ['pages' => $pages]);
return view('Staff.page.index', [
'pages' => Page::all(),
]);
}
/**
@@ -58,9 +58,9 @@ class PageController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$page = Page::findOrFail($id);
return view('Staff.page.edit', ['page' => $page]);
return view('Staff.page.edit', [
'page' => Page::findOrFail($id),
]);
}
/**
@@ -37,9 +37,9 @@ class PollController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$polls = Poll::latest()->paginate(25);
return view('Staff.poll.index', ['polls' => $polls]);
return view('Staff.poll.index', [
'polls' => Poll::latest()->paginate(25),
]);
}
/**
@@ -47,9 +47,9 @@ class PollController extends Controller
*/
public function show(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$poll = Poll::findOrFail($id);
return view('Staff.poll.show', ['poll' => $poll]);
return view('Staff.poll.show', [
'poll' => Poll::findOrFail($id),
]);
}
/**
@@ -87,9 +87,9 @@ class PollController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$poll = Poll::findOrFail($id);
return view('Staff.poll.edit', ['poll' => $poll]);
return view('Staff.poll.edit', [
'poll' => Poll::findOrFail($id),
]);
}
/**
@@ -28,9 +28,9 @@ class RegionController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$regions = Region::orderBy('position')->get();
return view('Staff.region.index', ['regions' => $regions]);
return view('Staff.region.index', [
'regions' => Region::orderBy('position')->get(),
]);
}
/**
@@ -57,9 +57,9 @@ class RegionController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$region = Region::findOrFail($id);
return view('Staff.region.edit', ['region' => $region]);
return view('Staff.region.edit', [
'region' => Region::findOrFail($id),
]);
}
/**
@@ -28,9 +28,9 @@ class ReportController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$reports = Report::orderBy('solved')->latest()->paginate(25);
return view('Staff.report.index', ['reports' => $reports]);
return view('Staff.report.index', [
'reports' => Report::orderBy('solved')->latest()->paginate(25)
]);
}
/**
@@ -26,9 +26,9 @@ class ResolutionController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$resolutions = Resolution::orderBy('position')->get();
return view('Staff.resolution.index', ['resolutions' => $resolutions]);
return view('Staff.resolution.index', [
'resolutions' => Resolution::orderBy('position')->get(),
]);
}
/**
@@ -55,9 +55,9 @@ class ResolutionController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$resolution = Resolution::findOrFail($id);
return view('Staff.resolution.edit', ['resolution' => $resolution]);
return view('Staff.resolution.edit', [
'resolution' => Resolution::findOrFail($id),
]);
}
/**
+5 -14
View File
@@ -34,11 +34,9 @@ class RssController extends Controller
*/
public function index($hash = null): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
$publicRss = Rss::where('is_private', '=', 0)->oldest('position')->get();
return view('Staff.rss.index', [
'hash' => $hash,
'public_rss' => $publicRss,
'public_rss' => Rss::where('is_private', '=', 0)->oldest('position')->get(),
]);
}
@@ -47,14 +45,12 @@ class RssController extends Controller
*/
public function create(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
return view('Staff.rss.create', [
'categories' => Category::select(['id', 'name', 'position'])->orderBy('position')->get(),
'types' => Type::select(['id', 'name', 'position'])->orderBy('position')->get(),
'resolutions' => Resolution::select(['id', 'name', 'position'])->orderBy('position')->get(),
'genres' => Genre::orderBy('name')->get(),
'user' => $user,
'user' => $request->user(),
]);
}
@@ -63,11 +59,9 @@ class RssController extends Controller
*/
public function store(StoreRssRequest $request): \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
{
$user = $request->user();
$rss = new Rss();
$rss->name = $request->name;
$rss->user_id = $user->id;
$rss->user_id = $request->user()->id;
$rss->json_torrent = array_merge($rss->expected_fields, $request->validated());
$rss->is_private = 0;
$rss->position = $request->position;
@@ -82,16 +76,13 @@ class RssController extends Controller
*/
public function edit(Request $request, int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
$rss = Rss::where('is_private', '=', 0)->findOrFail($id);
return view('Staff.rss.edit', [
'categories' => Category::select(['id', 'name', 'position'])->orderBy('position')->get(),
'types' => Type::select(['id', 'name', 'position'])->orderBy('position')->get(),
'resolutions' => Resolution::select(['id', 'name', 'position'])->orderBy('position')->get(),
'genres' => Genre::orderBy('name')->get(),
'user' => $user,
'rss' => $rss,
'user' => $request->user(),
'rss' => Rss::where('is_private', '=', 0)->findOrFail($id),
]);
}
@@ -27,9 +27,9 @@ class SeedboxController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$seedboxes = Seedbox::with('user')->latest()->paginate(50);
return view('Staff.seedbox.index', ['seedboxes' => $seedboxes]);
return view('Staff.seedbox.index', [
'seedboxes' => Seedbox::with('user')->latest()->paginate(50),
]);
}
/**
@@ -29,9 +29,9 @@ class TypeController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$types = Type::orderBy('position')->get();
return view('Staff.type.index', ['types' => $types]);
return view('Staff.type.index', [
'types' => $types = Type::orderBy('position')->get(),
]);
}
/**
@@ -58,9 +58,9 @@ class TypeController extends Controller
*/
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$type = Type::findOrFail($id);
return view('Staff.type.edit', ['type' => $type]);
return view('Staff.type.edit', [
'type' => Type::findOrFail($id),
]);
}
/**
+6 -10
View File
@@ -54,14 +54,10 @@ class UserController extends Controller
*/
public function settings(string $username): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = User::withTrashed()->where('username', '=', $username)->sole();
$groups = Group::all();
$internals = Internal::all();
return view('Staff.user.edit', [
'user' => $user,
'groups' => $groups,
'internals' => $internals,
'user' => User::withTrashed()->where('username', '=', $username)->sole(),
'groups' => Group::all(),
'internals' => Internal::all(),
]);
}
@@ -81,7 +77,7 @@ class UserController extends Controller
cache()->forget('user:'.$user->passkey);
Unit3dAnnounce::addUser($user);
return to_route('users.show', ['username' => $user->username])
return to_route('users.show', ['username' => $username])
->withSuccess('Account Was Updated Successfully!');
}
@@ -102,7 +98,7 @@ class UserController extends Controller
cache()->forget('user:'.$user->passkey);
Unit3dAnnounce::addUser($user);
return to_route('users.show', ['username' => $user->username])
return to_route('users.show', ['username' => $username])
->withSuccess('Account Permissions Successfully Edited');
}
@@ -245,7 +241,7 @@ class UserController extends Controller
$pm->message = 'You have received a [b]warning[/b]. Reason: '.$request->input('message');
$pm->save();
return to_route('users.show', ['username' => $user->username])
return to_route('users.show', ['username' => $username])
->withSuccess('Warning issued successfully!');
}
}
@@ -14,7 +14,7 @@
namespace App\Http\Controllers\Staff;
use App\Http\Controllers\Controller;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Http;
use JsonException;
/**
@@ -37,13 +37,11 @@ class VersionController extends Controller
*/
public function checkVersion(): \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
{
$client = new Client();
$response = json_decode((string) $client->get('//api.github.com/repos/HDInnovations/UNIT3D/releases')->getBody(), true, 512, JSON_THROW_ON_ERROR);
$lastestVersion = $response[0]['tag_name'];
$latestVersion = Http::get('//api.github.com/repos/HDInnovations/UNIT3D/releases')[0]['tag_name'];
return response([
'updated' => ! version_compare($this->versionController, $lastestVersion, '<'),
'latestversion' => $lastestVersion,
'updated' => ! version_compare($this->versionController, $latestVersion, '<'),
'latestversion' => $latestVersion,
]);
}
}
+144 -139
View File
@@ -47,64 +47,18 @@ class StatsController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Total Members Count (All Groups)
$allUser = cache()->remember('all_user', $this->carbon, fn () => User::withTrashed()->count());
// Total Active Members Count (Not Validating, Banned, Disabled, Pruned)
$activeUser = cache()->remember('active_user', $this->carbon, function () {
$bannedGroup = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));
$validatingGroup = cache()->rememberForever('validating_group', fn () => Group::where('slug', '=', 'validating')->pluck('id'));
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
$prunedGroup = cache()->rememberForever('pruned_group', fn () => Group::where('slug', '=', 'pruned')->pluck('id'));
return User::whereIntegerNotInRaw('group_id', [$validatingGroup[0], $bannedGroup[0], $disabledGroup[0], $prunedGroup[0]])->count();
});
// Total Disabled Members Count
$disabledUser = cache()->remember('disabled_user', $this->carbon, function () {
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
return User::where('group_id', '=', $disabledGroup[0])->count();
});
// Total Pruned Members Count
$prunedUser = cache()->remember('pruned_user', $this->carbon, function () {
$prunedGroup = cache()->rememberForever('pruned_group', fn () => Group::where('slug', '=', 'pruned')->pluck('id'));
return User::onlyTrashed()->where('group_id', '=', $prunedGroup[0])->count();
});
// Total Banned Members Count
$bannedUser = cache()->remember('banned_user', $this->carbon, function () {
$bannedGroup = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));
return User::where('group_id', '=', $bannedGroup[0])->count();
});
// Total Torrents Count
$numTorrent = cache()->remember('num_torrent', $this->carbon, fn () => Torrent::count());
// Total Categories With Torrent Count
$categories = Category::withCount('torrents')->orderBy('position')->get();
// Total HD Count
$numHd = cache()->remember('num_hd', $this->carbon, fn () => Torrent::where('sd', '=', 0)->count());
// Total SD Count
$numSd = cache()->remember('num_sd', $this->carbon, fn () => Torrent::where('sd', '=', 1)->count());
// Total Torrent Size
$torrentSize = cache()->remember('torrent_size', $this->carbon, fn () => Torrent::sum('size'));
// Total Seeders
$numSeeders = cache()->remember('num_seeders', $this->carbon, fn () => Peer::where('seeder', '=', 1)->count());
// Total Leechers
$numLeechers = cache()->remember('num_leechers', $this->carbon, fn () => Peer::where('seeder', '=', 0)->count());
// Total Peers
$numPeers = cache()->remember('num_peers', $this->carbon, fn () => Peer::count());
//Total Upload Traffic Without Double Upload
$actualUpload = cache()->remember('actual_upload', $this->carbon, fn () => History::sum('actual_uploaded'));
@@ -117,32 +71,51 @@ class StatsController extends Controller
//Total Download Traffic With Freeleech
$creditedDownload = cache()->remember('credited_download', $this->carbon, fn () => History::sum('downloaded'));
//Total Up/Down Traffic without perks
$actualUpDown = $actualUpload + $actualDownload;
//Total Up/Down Traffic with perks
$creditedUpDown = $creditedUpload + $creditedDownload;
$bannedGroup = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));
$validatingGroup = cache()->rememberForever('validating_group', fn () => Group::where('slug', '=', 'validating')->pluck('id'));
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
$prunedGroup = cache()->rememberForever('pruned_group', fn () => Group::where('slug', '=', 'pruned')->pluck('id'));
return view('stats.index', [
'all_user' => $allUser,
'active_user' => $activeUser,
'disabled_user' => $disabledUser,
'pruned_user' => $prunedUser,
'banned_user' => $bannedUser,
'all_user' => cache()->remember(
'all_user',
$this->carbon,
fn () => User::withTrashed()->count()
),
'active_user' => cache()->remember(
'active_user',
$this->carbon,
fn () => User::whereIntegerNotInRaw('group_id', [$validatingGroup[0], $bannedGroup[0], $disabledGroup[0], $prunedGroup[0]])->count()
),
'disabled_user' => cache()->remember(
'disabled_user',
$this->carbon,
fn () => User::where('group_id', '=', $disabledGroup[0])->count()
),
'pruned_user' => cache()->remember(
'pruned_user',
$this->carbon,
fn () => User::onlyTrashed()->where('group_id', '=', $prunedGroup[0])->count()
),
'banned_user' => cache()->remember(
'banned_user',
$this->carbon,
fn () => User::where('group_id', '=', $bannedGroup[0])->count()
),
'num_torrent' => $numTorrent,
'categories' => $categories,
'num_hd' => $numHd,
'categories' => Category::withCount('torrents')->orderBy('position')->get(),
'num_hd' => $numTorrent - $numSd,
'num_sd' => $numSd,
'torrent_size' => $torrentSize,
'torrent_size' => cache()->remember('torrent_size', $this->carbon, fn () => Torrent::sum('size')),
'num_seeders' => $numSeeders,
'num_leechers' => $numLeechers,
'num_peers' => $numPeers,
'num_peers' => $numSeeders + $numLeechers,
'actual_upload' => $actualUpload,
'actual_download' => $actualDownload,
'actual_up_down' => $actualUpDown,
'actual_up_down' => $actualUpload + $actualDownload,
'credited_upload' => $creditedUpload,
'credited_download' => $creditedDownload,
'credited_up_down' => $creditedUpDown,
'credited_up_down' => $creditedUpload + $creditedDownload,
]);
}
@@ -158,10 +131,12 @@ class StatsController extends Controller
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
$prunedGroup = cache()->rememberForever('pruned_group', fn () => Group::where('slug', '=', 'pruned')->pluck('id'));
// Fetch Top Uploaders
$uploaded = User::latest('uploaded')->whereIntegerNotInRaw('group_id', [$validatingGroup[0], $bannedGroup[0], $disabledGroup[0], $prunedGroup[0]])->take(100)->get();
return view('stats.users.uploaded', ['uploaded' => $uploaded]);
return view('stats.users.uploaded', [
'uploaded' => User::orderByDesc('uploaded')
->whereIntegerNotInRaw('group_id', [$validatingGroup[0], $bannedGroup[0], $disabledGroup[0], $prunedGroup[0]])
->take(100)
->get(),
]);
}
/**
@@ -176,10 +151,12 @@ class StatsController extends Controller
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
$prunedGroup = cache()->rememberForever('pruned_group', fn () => Group::where('slug', '=', 'pruned')->pluck('id'));
// Fetch Top Downloaders
$downloaded = User::latest('downloaded')->whereIntegerNotInRaw('group_id', [$validatingGroup[0], $bannedGroup[0], $disabledGroup[0], $prunedGroup[0]])->take(100)->get();
return view('stats.users.downloaded', ['downloaded' => $downloaded]);
return view('stats.users.downloaded', [
'downloaded' => User::orderByDesc('downloaded')
->whereIntegerNotInRaw('group_id', [$validatingGroup[0], $bannedGroup[0], $disabledGroup[0], $prunedGroup[0]])
->take(100)
->get(),
]);
}
/**
@@ -187,10 +164,15 @@ class StatsController extends Controller
*/
public function seeders(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Seeders
$seeders = Peer::with('user')->select(DB::raw('user_id, count(distinct torrent_id) as value'))->where('seeder', '=', 1)->groupBy('user_id')->latest('value')->take(100)->get();
return view('stats.users.seeders', ['seeders' => $seeders]);
return view('stats.users.seeders', [
'seeders' => Peer::with('user')
->select(DB::raw('user_id, count(distinct torrent_id) as value'))
->where('seeder', '=', 1)
->groupBy('user_id')
->orderByDesc('value')
->take(100)
->get(),
]);
}
/**
@@ -198,10 +180,15 @@ class StatsController extends Controller
*/
public function leechers(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Leechers
$leechers = Peer::with('user')->select(DB::raw('user_id, count(*) as value'))->where('seeder', '=', 0)->groupBy('user_id')->latest('value')->take(100)->get();
return view('stats.users.leechers', ['leechers' => $leechers]);
return view('stats.users.leechers', [
'leechers' => Peer::with('user')
->select(DB::raw('user_id, count(*) as value'))
->where('seeder', '=', 0)
->groupBy('user_id')
->orderByDesc('value')
->take(100)
->get(),
]);
}
/**
@@ -209,10 +196,15 @@ class StatsController extends Controller
*/
public function uploaders(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Uploaders
$uploaders = Torrent::with('user')->where('anon', '=', 0)->select(DB::raw('user_id, count(*) as value'))->groupBy('user_id')->latest('value')->take(100)->get();
return view('stats.users.uploaders', ['uploaders' => $uploaders]);
return view('stats.users.uploaders', [
'uploaders' => Torrent::with('user')
->where('anon', '=', 0)
->select(DB::raw('user_id, count(*) as value'))
->groupBy('user_id')
->orderByDesc('value')
->take(100)
->get(),
]);
}
/**
@@ -227,10 +219,12 @@ class StatsController extends Controller
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
$prunedGroup = cache()->rememberForever('pruned_group', fn () => Group::where('slug', '=', 'pruned')->pluck('id'));
// Fetch Top Bankers
$bankers = User::latest('seedbonus')->whereIntegerNotInRaw('group_id', [$validatingGroup[0], $bannedGroup[0], $disabledGroup[0], $prunedGroup[0]])->take(100)->get();
return view('stats.users.bankers', ['bankers' => $bankers]);
return view('stats.users.bankers', [
'bankers' => User::orderByDesc('seedbonus')
->whereIntegerNotInRaw('group_id', [$validatingGroup[0], $bannedGroup[0], $disabledGroup[0], $prunedGroup[0]])
->take(100)
->get(),
]);
}
/**
@@ -238,10 +232,12 @@ class StatsController extends Controller
*/
public function seedtime(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Total Seedtime
$users = User::withSum('history as seedtime', 'seedtime')->orderByDesc('seedtime')->take(100)->get();
return view('stats.users.seedtime', ['users' => $users]);
return view('stats.users.seedtime', [
'users' => User::withSum('history as seedtime', 'seedtime')
->orderByDesc('seedtime')
->take(100)
->get(),
]);
}
/**
@@ -249,10 +245,12 @@ class StatsController extends Controller
*/
public function seedsize(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Total Seedsize Users
$users = User::withSum('seedingTorrents as seedsize', 'size')->orderByDesc('seedsize')->take(100)->get();
return view('stats.users.seedsize', ['users' => $users]);
return view('stats.users.seedsize', [
'users' => User::withSum('seedingTorrents as seedsize', 'size')
->orderByDesc('seedsize')
->take(100)
->get(),
]);
}
/**
@@ -260,10 +258,9 @@ class StatsController extends Controller
*/
public function seeded(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Seeded
$seeded = Torrent::latest('seeders')->take(100)->get();
return view('stats.torrents.seeded', ['seeded' => $seeded]);
return view('stats.torrents.seeded', [
'seeded' => Torrent::orderByDesc('seeders')->take(100)->get(),
]);
}
/**
@@ -271,10 +268,9 @@ class StatsController extends Controller
*/
public function leeched(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Leeched
$leeched = Torrent::latest('leechers')->take(100)->get();
return view('stats.torrents.leeched', ['leeched' => $leeched]);
return view('stats.torrents.leeched', [
'leeched' => Torrent::orderByDesc('leechers')->take(100)->get(),
]);
}
/**
@@ -282,10 +278,9 @@ class StatsController extends Controller
*/
public function completed(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Completed
$completed = Torrent::latest('times_completed')->take(100)->get();
return view('stats.torrents.completed', ['completed' => $completed]);
return view('stats.torrents.completed', [
'completed' => Torrent::orderByDesc('times_completed')->take(100)->get(),
]);
}
/**
@@ -293,10 +288,13 @@ class StatsController extends Controller
*/
public function dying(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Dying
$dying = Torrent::where('seeders', '=', 1)->where('times_completed', '>=', '1')->latest('leechers')->take(100)->get();
return view('stats.torrents.dying', ['dying' => $dying]);
return view('stats.torrents.dying', [
'dying' => Torrent::where('seeders', '=', 1)
->where('times_completed', '>=', '1')
->orderByDesc('leechers')
->take(100)
->get(),
]);
}
/**
@@ -304,10 +302,12 @@ class StatsController extends Controller
*/
public function dead(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Dead
$dead = Torrent::where('seeders', '=', 0)->latest('leechers')->take(100)->get();
return view('stats.torrents.dead', ['dead' => $dead]);
return view('stats.torrents.dead', [
'dead' => Torrent::where('seeders', '=', 0)
->orderByDesc('leechers')
->take(100)
->get(),
]);
}
/**
@@ -315,10 +315,9 @@ class StatsController extends Controller
*/
public function bountied(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Top Bountied
$bountied = TorrentRequest::latest('bounty')->take(100)->get();
return view('stats.requests.bountied', ['bountied' => $bountied]);
return view('stats.requests.bountied', [
'bountied' => TorrentRequest::orderByDesc('bounty')->take(100)->get(),
]);
}
/**
@@ -326,10 +325,9 @@ class StatsController extends Controller
*/
public function groups(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Groups User Counts
$groups = Group::oldest('position')->get();
return view('stats.groups.groups', ['groups' => $groups]);
return view('stats.groups.groups', [
'groups' => Group::orderBy('position')->get(),
]);
}
/**
@@ -337,11 +335,12 @@ class StatsController extends Controller
*/
public function group(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch Users In Group
$group = Group::findOrFail($id);
$users = User::withTrashed()->where('group_id', '=', $group->id)->latest()->paginate(100);
return view('stats.groups.group', ['users' => $users, 'group' => $group]);
return view('stats.groups.group', [
'users' => User::withTrashed()->where('group_id', '=', $group->id)->latest()->paginate(100),
'group' => $group,
]);
}
/**
@@ -349,10 +348,9 @@ class StatsController extends Controller
*/
public function languages(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
// Fetch All Languages
$languages = Language::allowed();
return view('stats.languages.languages', ['languages' => $languages]);
return view('stats.languages.languages', [
'languages' => Language::allowed(),
]);
}
/**
@@ -366,7 +364,9 @@ class StatsController extends Controller
$clients = cache()->get('stats:clients');
}
return view('stats.clients.clients', ['clients' => $clients]);
return view('stats.clients.clients', [
'clients' => $clients,
]);
}
/**
@@ -374,16 +374,21 @@ class StatsController extends Controller
*/
public function themes(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$siteThemes = User::select(DB::raw('style, count(*) as value'))->groupBy('style')->latest('value')->get();
$customThemes = User::where('custom_css', '!=', '')->select(DB::raw('custom_css, count(*) as value'))->groupBy('custom_css')->latest('value')->get();
$standaloneThemes = User::whereNotNull('standalone_css')->select(DB::raw('standalone_css, count(*) as value'))->groupBy('standalone_css')->latest('value')->get();
return view('stats.themes.index', [
'siteThemes' => $siteThemes,
'customThemes' => $customThemes,
'standaloneThemes' => $standaloneThemes,
'siteThemes' => User::select(DB::raw('style, count(*) as value'))
->groupBy('style')
->orderByDesc('value')
->get(),
'customThemes' => User::where('custom_css', '!=', '')
->select(DB::raw('custom_css, count(*) as value'))
->groupBy('custom_css')
->orderByDesc('value')
->get(),
'standaloneThemes' => User::whereNotNull('standalone_css')
->select(DB::raw('standalone_css, count(*) as value'))
->groupBy('standalone_css')
->orderByDesc('value')
->get(),
]);
}
}
+5 -5
View File
@@ -56,10 +56,10 @@ class SubtitleController extends Controller
*/
public function create(int $torrentId): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$torrent = Torrent::withAnyStatus()->findOrFail($torrentId);
$mediaLanguages = MediaLanguage::orderBy('name')->get();
return view('subtitle.create', ['torrent' => $torrent, 'media_languages' => $mediaLanguages]);
return view('subtitle.create', [
'torrent' => Torrent::withAnyStatus()->findOrFail($torrentId),
'media_languages' => MediaLanguage::orderBy('name')->get(),
]);
}
/**
@@ -184,7 +184,7 @@ class SubtitleController extends Controller
$subtitle->delete();
return to_route('torrent', ['id' => $request->input('torrent_id')])
return to_route('torrent', ['id' => $request->integer('torrent_id')])
->withSuccess('Subtitle Successfully Deleted');
}
+2 -5
View File
@@ -34,12 +34,9 @@ class TicketController extends Controller
*/
final public function create(): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
$categories = TicketCategory::orderBy('position')->get();
$priorities = TicketPriority::orderBy('position')->get();
return view('ticket.create', [
'categories' => $categories,
'priorities' => $priorities,
'categories' => TicketCategory::orderBy('position')->get(),
'priorities' => TicketPriority::orderBy('position')->get(),
]);
}
+34 -45
View File
@@ -81,22 +81,15 @@ class TorrentController extends Controller
*/
public function show(Request $request, int|string $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
$torrent = Torrent::withAnyStatus()
->with(['user', 'comments', 'category', 'type', 'resolution', 'subtitles', 'playlists'])
->withExists(['bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id)])
->withExists(['bookmarks' => fn ($query) => $query->where('user_id', '=', $request->user()->id)])
->findOrFail($id);
$freeleechToken = cache()->get('freeleech_token:'.$user->id.':'.$torrent->id);
$personalFreeleech = cache()->get('personal_freeleech:'.$user->id);
$totalTips = BonTransactions::where('torrent_id', '=', $id)->sum('cost');
$userTips = BonTransactions::where('torrent_id', '=', $id)->where('sender', '=', $user->id)->sum('cost');
$lastSeedActivity = History::where('torrent_id', '=', $torrent->id)->where('seeder', '=', 1)->latest('updated_at')->first();
$audits = Audit::with('user')->where('model_entry_id', '=', $torrent->id)->where('model_name', '=', 'Torrent')->latest()->get();
$meta = null;
$trailer = null;
$platforms = null;
if ($torrent->category->tv_meta && $torrent->tmdb && $torrent->tmdb != 0) {
$meta = Tv::with([
'genres',
@@ -135,30 +128,21 @@ class TorrentController extends Controller
$platforms = PlatformLogo::whereIn('id', collect($meta->platforms)->pluck('platform_logo')->toArray())->get();
}
$featured = $torrent->featured == 1 ? FeaturedTorrent::where('torrent_id', '=', $id)->first() : null;
$mediaInfo = null;
if ($torrent->mediainfo !== null) {
$mediaInfo = (new MediaInfo())->parse($torrent->mediainfo);
}
$playlists = $user->playlists;
return view('torrent.show', [
'torrent' => $torrent,
'user' => $user,
'personal_freeleech' => $personalFreeleech,
'freeleech_token' => $freeleechToken,
'personal_freeleech' => cache()->get('personal_freeleech:'.$user->id),
'freeleech_token' => cache()->get('freeleech_token:'.$user->id.':'.$torrent->id),
'meta' => $meta,
'trailer' => $trailer,
'platforms' => $platforms,
'total_tips' => $totalTips,
'user_tips' => $userTips,
'featured' => $featured,
'mediaInfo' => $mediaInfo,
'last_seed_activity' => $lastSeedActivity,
'playlists' => $playlists,
'audits' => $audits,
'total_tips' => BonTransactions::where('torrent_id', '=', $id)->sum('cost'),
'user_tips' => BonTransactions::where('torrent_id', '=', $id)->where('sender', '=', $user->id)->sum('cost'),
'featured' => $torrent->featured == 1 ? FeaturedTorrent::where('torrent_id', '=', $id)->first() : null,
'mediaInfo' => $torrent->mediainfo !== null ? (new MediaInfo())->parse($torrent->mediainfo) : null,
'last_seed_activity' => History::where('torrent_id', '=', $torrent->id)->where('seeder', '=', 1)->latest('updated_at')->first(),
'playlists' => $user->playlists,
'audits' => Audit::with('user')->where('model_entry_id', '=', $torrent->id)->where('model_name', '=', 'Torrent')->latest()->get(),
]);
}
@@ -169,28 +153,26 @@ class TorrentController extends Controller
{
$user = $request->user();
$torrent = Torrent::withAnyStatus()->findOrFail($id);
$categories = Category::query()
->orderBy('position')
->get()
->mapWithKeys(fn ($cat) => [
$cat['id'] => [
'name' => $cat['name'],
'type' => match (1) {
$cat->movie_meta => 'movie',
$cat->tv_meta => 'tv',
$cat->game_meta => 'game',
$cat->music_meta => 'music',
$cat->no_meta => 'no'
},
]
]);
$types = Type::orderBy('position')->get()->mapWithKeys(fn ($type) => [$type['id'] => ['name' => $type['name']]]);
abort_unless($user->group->is_modo || $user->id === $torrent->user_id, 403);
return view('torrent.edit', [
'categories' => $categories,
'types' => $types,
'categories' => Category::query()
->orderBy('position')
->get()
->mapWithKeys(fn ($cat) => [
$cat['id'] => [
'name' => $cat['name'],
'type' => match (1) {
$cat->movie_meta => 'movie',
$cat->tv_meta => 'tv',
$cat->game_meta => 'game',
$cat->music_meta => 'music',
$cat->no_meta => 'no'
},
]
]),
'types' => Type::orderBy('position')->get()->mapWithKeys(fn ($type) => [$type['id'] => ['name' => $type['name']]]),
'resolutions' => Resolution::orderBy('position')->get(),
'regions' => Region::orderBy('position')->get(),
'distributors' => Distributor::orderBy('position')->get(),
@@ -403,6 +385,7 @@ class TorrentController extends Controller
{
$user = $request->user();
$categories = [];
foreach (Category::orderBy('position')->get() as $cat) {
$temp = [
'name' => $cat->name,
@@ -446,6 +429,7 @@ class TorrentController extends Controller
$category = Category::withCount('torrents')->findOrFail($request->input('category_id'));
$requestFile = $request->file('torrent');
if (! $request->hasFile('torrent')) {
return to_route('upload_form', ['category_id' => $category->id])
->withErrors('You Must Provide A Torrent File For Upload!')->withInput();
@@ -461,6 +445,7 @@ class TorrentController extends Controller
$infohash = Bencode::get_infohash($decodedTorrent);
$v2 = Bencode::is_v2_or_hybrid($decodedTorrent);
if ($v2) {
return to_route('upload_form', ['category_id' => $category->id])
->withErrors('BitTorrent v2 (BEP 52) is not supported!')->withInput();
@@ -519,16 +504,19 @@ class TorrentController extends Controller
$torrent->refundable = $user->group->is_modo || $user->group->is_internal ? $request->input('refundable') : 0;
$resolutionRule = 'nullable|exists:resolutions,id';
if ($category->movie_meta || $category->tv_meta) {
$resolutionRule = 'required|exists:resolutions,id';
}
$episodeRule = 'nullable|numeric';
if ($category->tv_meta) {
$episodeRule = 'required|numeric';
}
$seasonRule = 'nullable|numeric';
if ($category->tv_meta) {
$seasonRule = 'required|numeric';
}
@@ -590,6 +578,7 @@ class TorrentController extends Controller
// TMDB Meta
$tmdbScraper = new TMDBScraper();
if ($torrent->category->tv_meta !== 0 && ($torrent->tmdb || $torrent->tmdb != 0)) {
$tmdbScraper->tv($torrent->tmdb);
}
@@ -26,10 +26,10 @@ class TorrentDownloadController extends Controller
*/
public function show(Request $request, int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$torrent = Torrent::withAnyStatus()->findOrFail($id);
$user = $request->user();
return view('torrent.download_check', ['torrent' => $torrent, 'user' => $user]);
return view('torrent.download_check', [
'torrent' => Torrent::withAnyStatus()->findOrFail($id),
'user' => $request->user(),
]);
}
/**
@@ -23,9 +23,9 @@ class TorrentHistoryController extends Controller
*/
public function index(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$torrent = Torrent::withAnyStatus()->findOrFail($id);
$history = History::with(['user'])->where('torrent_id', '=', $id)->latest()->get();
return view('torrent.history', ['torrent' => $torrent, 'history' => $history]);
return view('torrent.history', [
'torrent' => Torrent::withAnyStatus()->findOrFail($id),
'history' => History::with(['user'])->where('torrent_id', '=', $id)->latest()->get(),
]);
}
}
+19 -17
View File
@@ -24,24 +24,26 @@ class TorrentPeerController extends Controller
public function index(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$torrent = Torrent::withAnyStatus()->findOrFail($id);
$peers = Peer::query()
->with('user')
->select(['torrent_id', 'user_id', 'uploaded', 'downloaded', 'left', 'port', 'agent', 'created_at', 'updated_at', 'seeder'])
->selectRaw('INET6_NTOA(ip) as ip')
->where('torrent_id', '=', $id)
->latest('seeder')
->get()
->map(function ($peer) use ($torrent) {
$progress = 100 * (1 - $peer->left / $torrent->size);
$peer['progress'] = match (true) {
0 < $progress && $progress < 1 => 1,
99 < $progress && $progress < 100 => 99,
default => round($progress),
};
return $peer;
});
return view('torrent.peers', [
'torrent' => $torrent,
'peers' => Peer::query()
->with('user')
->select(['torrent_id', 'user_id', 'uploaded', 'downloaded', 'left', 'port', 'agent', 'created_at', 'updated_at', 'seeder'])
->selectRaw('INET6_NTOA(ip) as ip')
->where('torrent_id', '=', $id)
->latest('seeder')
->get()
->map(function ($peer) use ($torrent) {
$progress = 100 * (1 - $peer->left / $torrent->size);
$peer['progress'] = match (true) {
0 < $progress && $progress < 1 => 1,
99 < $progress && $progress < 100 => 99,
default => round($progress),
};
return view('torrent.peers', ['torrent' => $torrent, 'peers' => $peers]);
return $peer;
}),
]);
}
}
@@ -26,14 +26,11 @@ class AchievementsController extends Controller
*/
public function index(User $user): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$achievements = $user->unlockedAchievements();
$pending = $user->inProgressAchievements();
return view('user.achievement.index', [
'route' => 'achievement',
'user' => $user,
'achievements' => $achievements,
'pending' => $pending,
'achievements' => $user->unlockedAchievements(),
'pending' => $user->inProgressAchievements(),
]);
}
}
+1 -3
View File
@@ -26,10 +26,8 @@ class BanController extends Controller
{
abort_unless($request->user()->group->is_modo, 403);
$bans = $user->userban()->latest()->get();
return view('user.ban.index', [
'bans' => $bans,
'bans' => $user->userban()->latest()->get(),
'user' => $user,
]);
}
@@ -29,10 +29,8 @@ class FollowController extends Controller
*/
public function index(User $user): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$followers = $user->followers()->orderByPivot('created_at', 'desc')->paginate(25);
return view('user.follower.index', [
'followers' => $followers,
'followers' => $user->followers()->orderByPivot('created_at', 'desc')->paginate(25),
'user' => $user,
]);
}
@@ -23,10 +23,8 @@ class FollowingController extends Controller
*/
public function index(User $user): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$followings = $user->following()->orderByPivot('created_at', 'desc')->paginate(25);
return view('user.following.index', [
'followings' => $followings,
'followings' => $user->following()->orderByPivot('created_at', 'desc')->paginate(25),
'user' => $user,
]);
}
+20 -30
View File
@@ -39,35 +39,27 @@ class GiftController extends Controller
abort_unless($request->user()->id === $user->id || $request->user()->group->is_modo, 403);
$userbon = $user->getSeedbonus();
$gifttransactions = BonTransactions::query()
->with(['senderObj', 'receiverObj'])
->where(
fn ($query) => $query
->where('sender', '=', $user->id)
->orwhere('receiver', '=', $user->id)
)
->where('name', '=', 'gift')
->latest('date_actioned')
->paginate(25);
$giftsSent = BonTransactions::query()
->where('sender', '=', $user->id)
->where('name', '=', 'gift')
->sum('cost');
$giftsReceived = BonTransactions::query()
->where('receiver', '=', $user->id)
->where('name', '=', 'gift')
->sum('cost');
return view('user.gift.index', [
'user' => $user,
'gifttransactions' => $gifttransactions,
'userbon' => $userbon,
'gifts_sent' => $giftsSent,
'gifts_received' => $giftsReceived,
'gifttransactions' => BonTransactions::query()
->with(['senderObj', 'receiverObj'])
->where(
fn ($query) => $query
->where('sender', '=', $user->id)
->orwhere('receiver', '=', $user->id)
)
->where('name', '=', 'gift')
->latest('date_actioned')
->paginate(25),
'userbon' => $user->getSeedbonus(),
'gifts_sent' => BonTransactions::query()
->where('sender', '=', $user->id)
->where('name', '=', 'gift')
->sum('cost'),
'gifts_received' => BonTransactions::query()
->where('receiver', '=', $user->id)
->where('name', '=', 'gift')
->sum('cost'),
]);
}
@@ -80,11 +72,9 @@ class GiftController extends Controller
abort_unless($request->user()->id === $user->id, 403);
$userbon = $user->getSeedbonus();
return view('user.gift.create', [
'user' => $user,
'userbon' => $userbon,
'userbon' => $user->getSeedbonus(),
]);
}
@@ -27,18 +27,16 @@ class HistoryController extends Controller
{
abort_unless($request->user()->group->is_modo || $request->user()->id == $user->id, 403);
$history = DB::table('history')
->where('user_id', '=', $user->id)
->where('created_at', '>', $user->created_at)
->selectRaw('sum(actual_uploaded) as upload')
->selectRaw('sum(uploaded) as credited_upload')
->selectRaw('sum(actual_downloaded) as download')
->selectRaw('sum(downloaded) as credited_download')
->first();
return view('user.history.index', [
'user' => $user,
'history' => $history,
'history' => DB::table('history')
->where('user_id', '=', $user->id)
->where('created_at', '>', $user->created_at)
->selectRaw('sum(actual_uploaded) as upload')
->selectRaw('sum(uploaded) as credited_upload')
->selectRaw('sum(actual_downloaded) as download')
->selectRaw('sum(downloaded) as credited_download')
->first(),
]);
}
}
@@ -36,11 +36,13 @@ class InviteController extends Controller
{
$user = $request->user();
$owner = User::where('username', '=', $username)->sole();
abort_unless($user->group->is_modo || $user->id === $owner->id, 403);
$invites = Invite::withTrashed()->with(['sender', 'receiver'])->where('user_id', '=', $owner->id)->latest()->paginate(25);
return view('user.invite.index', ['user' => $owner, 'invites' => $invites, 'route' => 'invite']);
return view('user.invite.index', [
'user' => $owner,
'invites' => Invite::withTrashed()->with(['sender', 'receiver'])->where('user_id', '=', $owner->id)->latest()->paginate(25),
]);
}
/**
@@ -65,7 +67,7 @@ class InviteController extends Controller
->withErrors(trans('user.invites-disabled-group'));
}
return view('user.invite.create', ['user' => $user, 'route' => 'invite']);
return view('user.invite.create', ['user' => $user]);
}
/**
@@ -133,16 +133,17 @@ class NotificationSettingController extends Controller
{
abort_unless($request->user()->id == $user->id, 403);
$groups = Group::query()
->where('is_modo', '=', '0')
->where('is_admin', '=', '0')
->where('id', '!=', UserGroups::VALIDATING)
->where('id', '!=', UserGroups::PRUNED)
->where('id', '!=', UserGroups::BANNED)
->where('id', '!=', UserGroups::DISABLED)
->latest('level')
->get();
return view('user.notification_setting.edit', ['user' => $user, 'groups' => $groups]);
return view('user.notification_setting.edit', [
'user' => $user,
'groups' => Group::query()
->where('is_modo', '=', '0')
->where('is_admin', '=', '0')
->where('id', '!=', UserGroups::VALIDATING)
->where('id', '!=', UserGroups::PRUNED)
->where('id', '!=', UserGroups::BANNED)
->where('id', '!=', UserGroups::DISABLED)
->latest('level')
->get(),
]);
}
}
+8 -10
View File
@@ -28,18 +28,16 @@ class PeerController extends Controller
{
abort_unless($request->user()->group->is_modo || $request->user()->id == $user->id, 403);
$history = DB::table('history')
->where('user_id', '=', $user->id)
->where('created_at', '>', $user->created_at)
->selectRaw('sum(actual_uploaded) as upload')
->selectRaw('sum(uploaded) as credited_upload')
->selectRaw('sum(actual_downloaded) as download')
->selectRaw('sum(downloaded) as credited_download')
->first();
return view('user.peer.index', [
'user' => $user,
'history' => $history,
'history' => DB::table('history')
->where('user_id', '=', $user->id)
->where('created_at', '>', $user->created_at)
->selectRaw('sum(actual_uploaded) as upload')
->selectRaw('sum(uploaded) as credited_upload')
->selectRaw('sum(actual_downloaded) as download')
->selectRaw('sum(downloaded) as credited_download')
->first(),
]);
}
+21 -23
View File
@@ -24,31 +24,29 @@ class PostController extends Controller
*/
public function index(User $user): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$posts = $user->posts()
->with('user', 'user.group', 'topic:id,name')
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
->withSum('tips', 'cost')
->whereNotIn(
'topic_id',
Topic::query()
->whereRelation(
'forumPermissions',
fn ($query) => $query
->where('group_id', '=', auth()->user()->group_id)
->where(
fn ($query) => $query
->where('show_forum', '!=', 1)
->orWhere('read_topic', '!=', 1)
)
)
->select('id')
)
->latest()
->paginate(25);
return view('user.post.index', [
'posts' => $posts,
'user' => $user,
'posts' => $user->posts()
->with('user', 'user.group', 'topic:id,name')
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
->withSum('tips', 'cost')
->whereNotIn(
'topic_id',
Topic::query()
->whereRelation(
'forumPermissions',
fn ($query) => $query
->where('group_id', '=', auth()->user()->group_id)
->where(
fn ($query) => $query
->where('show_forum', '!=', 1)
->orWhere('read_topic', '!=', 1)
)
)
->select('id')
)
->latest()
->paginate(25),
]);
}
}
@@ -148,16 +148,17 @@ class PrivacySettingController extends Controller
{
abort_unless($request->user()->id == $user->id, 403);
$groups = Group::query()
->where('is_modo', '=', '0')
->where('is_admin', '=', '0')
->where('id', '!=', UserGroups::VALIDATING)
->where('id', '!=', UserGroups::PRUNED)
->where('id', '!=', UserGroups::BANNED)
->where('id', '!=', UserGroups::DISABLED)
->latest('level')
->get();
return view('user.privacy_setting.edit', ['user' => $user, 'groups' => $groups]);
return view('user.privacy_setting.edit', [
'user' => $user,
'groups' => Group::query()
->where('is_modo', '=', '0')
->where('is_admin', '=', '0')
->where('id', '!=', UserGroups::VALIDATING)
->where('id', '!=', UserGroups::PRUNED)
->where('id', '!=', UserGroups::BANNED)
->where('id', '!=', UserGroups::DISABLED)
->latest('level')
->get(),
]);
}
}
@@ -29,12 +29,14 @@ class PrivateMessageController extends Controller
*/
public function searchPMInbox(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
$pms = PrivateMessage::where('receiver_id', '=', $user->id)->where([
['subject', 'like', '%'.$request->input('subject').'%'],
])->latest()->paginate(20);
return view('user.pm.index', ['pms' => $pms, 'user' => $user]);
return view('user.pm.index', [
'user' => $request->user(),
'pms' => $request->user()
->pm_receiver()
->where('subject', 'like', '%'.$request->string('subject').'%')
->latest()
->paginate(20),
]);
}
/**
@@ -42,12 +44,14 @@ class PrivateMessageController extends Controller
*/
public function searchPMOutbox(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
$pms = PrivateMessage::where('sender_id', '=', $user->id)->where([
['subject', 'like', '%'.$request->input('subject').'%'],
])->latest()->paginate(20);
return view('user.pm.outbox', ['pms' => $pms, 'user' => $user]);
return view('user.pm.outbox', [
'user' => $request->user(),
'pms' => $request->user()
->pm_sender()
->where('subject', 'like', '%'.$request->string('subject').'%')
->latest()
->paginate(20),
]);
}
/**
@@ -55,10 +59,10 @@ class PrivateMessageController extends Controller
*/
public function getPrivateMessages(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
$pms = PrivateMessage::where('receiver_id', '=', $user->id)->latest()->paginate(25);
return view('user.pm.index', ['pms' => $pms, 'user' => $user]);
return view('user.pm.index', [
'user' => $request->user(),
'pms' => $request->user()->pm_receiver()->latest()->paginate(25),
]);
}
/**
@@ -66,10 +70,10 @@ class PrivateMessageController extends Controller
*/
public function getPrivateMessagesSent(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
$pms = PrivateMessage::where('sender_id', '=', $user->id)->latest()->paginate(20);
return view('user.pm.outbox', ['pms' => $pms, 'user' => $user]);
return view('user.pm.outbox', [
'user' => $request->user(),
'pms' => $request->user()->pm_sender()->latest()->paginate(25),
]);
}
/**
@@ -86,7 +90,10 @@ class PrivateMessageController extends Controller
$pm->save();
}
return view('user.pm.show', ['pm' => $pm, 'user' => $user]);
return view('user.pm.show', [
'pm' => $pm,
'user' => $user
]);
}
return to_route('inbox')
@@ -98,9 +105,11 @@ class PrivateMessageController extends Controller
*/
public function makePrivateMessage(Request $request, string $receiverId = '', string $username = ''): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
return view('user.pm.create', ['user' => $user, 'receiver_id' => $receiverId, 'username' => $username]);
return view('user.pm.create', [
'user' => $request->user(),
'receiver_id' => $receiverId,
'username' => $username
]);
}
/**
@@ -34,9 +34,10 @@ class SeedboxController extends Controller
abort_unless(($request->user()->group->is_modo || $request->user()->id == $user->id), 403);
$seedboxes = Seedbox::where('user_id', '=', $user->id)->paginate(25);
return view('user.seedbox.index', ['user' => $user, 'seedboxes' => $seedboxes]);
return view('user.seedbox.index', [
'user' => $user,
'seedboxes' => Seedbox::where('user_id', '=', $user->id)->paginate(25),
]);
}
/**
+19 -26
View File
@@ -37,34 +37,27 @@ class TipController extends Controller
abort_unless($request->user()->id === $user->id || $request->user()->group->is_modo, 403);
$userbon = $user->getSeedbonus();
$bontransactions = BonTransactions::query()
->with(['senderObj', 'receiverObj'])
->where(
fn ($query) => $query
->where('sender', '=', $user->id)
->orwhere('receiver', '=', $user->id)
)
->where('name', '=', 'tip')
->latest('date_actioned')
->paginate(25);
$tipsSent = BonTransactions::query()
->where('sender', '=', $user->id)
->where('name', '=', 'tip')
->sum('cost');
$tipsReceived = BonTransactions::query()
->where('receiver', '=', $user->id)
->where('name', '=', 'tip')
->sum('cost');
return view('user.tip.index', [
'user' => $user,
'bontransactions' => $bontransactions,
'userbon' => $userbon,
'tips_sent' => $tipsSent,
'tips_received' => $tipsReceived,
'bontransactions' => BonTransactions::query()
->with(['senderObj', 'receiverObj'])
->where(
fn ($query) => $query
->where('sender', '=', $user->id)
->orwhere('receiver', '=', $user->id)
)
->where('name', '=', 'tip')
->latest('date_actioned')
->paginate(25),
'userbon' => $user->getSeedbonus,
'tips_sent' => BonTransactions::query()
->where('sender', '=', $user->id)
->where('name', '=', 'tip')
->sum('cost'),
'tips_received' => BonTransactions::query()
->where('receiver', '=', $user->id)
->where('name', '=', 'tip')
->sum('cost'),
]);
}
@@ -23,14 +23,12 @@ class TopicController extends Controller
*/
public function index(User $user): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$topics = $user->topics()
->whereRelation('forumPermissions', [['show_forum', '=', 1], ['group_id', '=', auth()->user()->group_id]])
->latest()
->paginate(25);
return view('user.topic.index', [
'topics' => $topics,
'user' => $user,
'topics' => $user->topics()
->whereRelation('forumPermissions', [['show_forum', '=', 1], ['group_id', '=', auth()->user()->group_id]])
->latest()
->paginate(25),
]);
}
}
@@ -27,18 +27,16 @@ class TorrentController extends Controller
{
abort_unless($request->user()->group->is_modo || $request->user()->id == $user->id, 403);
$history = DB::table('history')
->where('user_id', '=', $user->id)
->where('created_at', '>', $user->created_at)
->selectRaw('sum(actual_uploaded) as upload')
->selectRaw('sum(uploaded) as credited_upload')
->selectRaw('sum(actual_downloaded) as download')
->selectRaw('sum(downloaded) as credited_download')
->first();
return view('user.torrent.index', [
'user' => $user,
'history' => $history,
'history' => DB::table('history')
->where('user_id', '=', $user->id)
->where('created_at', '>', $user->created_at)
->selectRaw('sum(actual_uploaded) as upload')
->selectRaw('sum(uploaded) as credited_upload')
->selectRaw('sum(actual_downloaded) as download')
->selectRaw('sum(downloaded) as credited_download')
->first(),
]);
}
}
@@ -46,15 +46,11 @@ class TransactionController extends Controller
abort_unless($request->user()->id === $user->id, 403);
$userbon = $user->getSeedbonus();
$activefl = $user->personalFreeleeches()->exists();
$items = BonExchange::all();
return view('user.transaction.create', [
'user' => $user,
'userbon' => $userbon,
'activefl' => $activefl,
'items' => $items,
'userbon' => $user->getSeedbonus(),
'activefl' => $user->personalFreeleeches()->exists(),
'items' => BonExchange::all(),
]);
}
@@ -109,7 +105,7 @@ class TransactionController extends Controller
$user->decrement('seedbonus', $item->cost);
return to_route('transactions.create', ['username' => $user->username])
return to_route('transactions.create', ['username' => $username])
->withSuccess(trans('bon.success'));
}
}
+46 -65
View File
@@ -50,70 +50,49 @@ class UserController extends Controller
->when(auth()->user()->group->is_modo == true, fn ($query) => $query->withTrashed())
->sole();
$followers = $user->followers()->latest()->limit(25)->get();
$warnings = $user
->userwarning()
->latest()
->paginate(2, ['*'], 'warningsPage');
$softDeletedWarnings = $user
->userwarning()
->with(['torrenttitle', 'warneduser'])
->latest('created_at')
->onlyTrashed()
->paginate(2, ['*'], 'deletedWarningsPage');
$watch = $user->watchlist;
$boughtUpload = BonTransactions::where('sender', '=', $user->id)->where([['name', 'like', '%Upload%']])->sum('cost');
//$boughtDownload = BonTransactions::where('sender', '=', $user->id)->where([['name', 'like', '%Download%']])->sum('cost');
$history = DB::table('history')
->where('user_id', '=', $user->id)
->where('created_at', '>', $user->created_at)
->selectRaw('SUM(actual_uploaded) as upload_sum')
->selectRaw('SUM(uploaded) as credited_upload_sum')
->selectRaw('SUM(actual_downloaded) as download_sum')
->selectRaw('SUM(downloaded) as credited_download_sum')
->selectRaw('SUM(refunded_download) as refunded_download_sum')
->selectRaw('SUM(seedtime) as seedtime_sum')
->selectRaw('SUM(actual_downloaded > 0) as download_count')
->selectRaw('COUNT(*) as count')
->first();
$peers = Peer::query()
->selectRaw('SUM(seeder = 0) as leeching')
->selectRaw('SUM(seeder = 1) as seeding')
->where('user_id', '=', $user->id)
->first();
$invitedBy = Invite::where('accepted_by', '=', $user->id)->first();
$clients = $user->peers()
->select('agent', 'port')
->selectRaw('INET6_NTOA(ip) as ip, MIN(created_at) as created_at, MAX(updated_at) as updated_at, COUNT(*) as num_peers')
->groupBy(['ip', 'port', 'agent'])
->get();
$achievements = AchievementProgress::with('details')
->where('achiever_id', '=', $user->id)
->whereNotNull('unlocked_at')
->get();
return view('user.profile.show', [
'user' => $user,
'followers' => $followers,
'history' => $history,
'warnings' => $warnings,
'softDeletedWarnings' => $softDeletedWarnings,
'boughtUpload' => $boughtUpload,
// 'boughtDownload' => $boughtDownload,
'invitedBy' => $invitedBy,
'clients' => $clients,
'achievements' => $achievements,
'peers' => $peers,
'watch' => $watch,
'user' => $user,
'followers' => $user->followers()->latest()->limit(25)->get(),
'history' => DB::table('history')
->where('user_id', '=', $user->id)
->where('created_at', '>', $user->created_at)
->selectRaw('SUM(actual_uploaded) as upload_sum')
->selectRaw('SUM(uploaded) as credited_upload_sum')
->selectRaw('SUM(actual_downloaded) as download_sum')
->selectRaw('SUM(downloaded) as credited_download_sum')
->selectRaw('SUM(refunded_download) as refunded_download_sum')
->selectRaw('SUM(seedtime) as seedtime_sum')
->selectRaw('SUM(actual_downloaded > 0) as download_count')
->selectRaw('COUNT(*) as count')
->first(),
'warnings' => $user
->userwarning()
->latest()
->paginate(2, ['*'], 'warningsPage'),
'softDeletedWarnings' => $user
->userwarning()
->with(['torrenttitle', 'warneduser'])
->latest('created_at')
->onlyTrashed()
->paginate(2, ['*'], 'deletedWarningsPage'),
'boughtUpload' => BonTransactions::where('sender', '=', $user->id)->where([['name', 'like', '%Upload%']])->sum('cost'),
// 'boughtDownload' => BonTransactions::where('sender', '=', $user->id)->where([['name', 'like', '%Download%']])->sum('cost'),
'invitedBy' => Invite::where('accepted_by', '=', $user->id)->first(),
'clients' => $user->peers()
->select('agent', 'port')
->selectRaw('INET6_NTOA(ip) as ip, MIN(created_at) as created_at, MAX(updated_at) as updated_at, COUNT(*) as num_peers')
->groupBy(['ip', 'port', 'agent'])
->get(),
'achievements' => AchievementProgress::with('details')
->where('achiever_id', '=', $user->id)
->whereNotNull('unlocked_at')
->get(),
'peers' => Peer::query()
->selectRaw('SUM(seeder = 0) as leeching')
->selectRaw('SUM(seeder = 1) as seeding')
->where('user_id', '=', $user->id)
->first(),
'watch' => $user->watchlist,
]);
}
@@ -126,7 +105,9 @@ class UserController extends Controller
abort_unless($request->user()->id == $user->id, 403);
return view('user.profile.edit', ['user' => $user, 'route' => 'edit']);
return view('user.profile.edit', [
'user' => $user,
]);
}
/**
@@ -181,7 +162,7 @@ class UserController extends Controller
$user->signature = $request->input('signature');
$user->save();
return to_route('user_edit_profile_form', ['username' => $user->username])
return to_route('user_edit_profile_form', ['username' => $username])
->withSuccess('Your Account Was Updated Successfully!');
}
+2 -6
View File
@@ -41,11 +41,9 @@ class WishController extends Controller
abort_unless(($request->user()->group->is_modo || $request->user()->id == $user->id), 403);
$wishes = $user->wishes()->latest()->paginate(25);
return view('user.wish.index', [
'user' => $user,
'wishes' => $wishes,
'wishes' => $user->wishes()->latest()->paginate(25),
'route' => 'wish',
]);
}
@@ -96,11 +94,9 @@ class WishController extends Controller
*/
public function destroy(Request $request, int $id): \Illuminate\Http\RedirectResponse
{
$user = $request->user();
$this->wish->delete($id);
return to_route('wishes.index', ['username' => $user->username])
return to_route('wishes.index', ['username' => $request->user()->username])
->withSuccess('Wish Successfully Removed!');
}
}
+26 -27
View File
@@ -16,35 +16,34 @@ class QuickSearchDropdown extends Component
public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
$search = '%'.str_replace(' ', '%', $this->quicksearchText).'%';
$search_results = $this->quicksearchText === '' ? [] : match ($this->quicksearchRadio) {
'movies' => Movie::query()
->select(['id', 'poster', 'title', 'release_date'])
->selectRaw("concat(title, ' ', release_date) as title_and_year")
->having('title_and_year', 'LIKE', $search)
->has('torrents')
->oldest('title')
->take(10)
->get(),
'series' => Tv::query()
->select(['id', 'poster', 'name', 'first_air_date'])
->selectRaw("concat(name, ' ', first_air_date) as title_and_year")
->having('title_and_year', 'LIKE', $search)
->has('torrents')
->oldest('name')
->take(10)
->get(),
'persons' => Person::query()
->select(['id', 'still', 'name'])
->whereNotNull('still')
->where('name', 'LIKE', $search)
->oldest('name')
->take(10)
->get(),
default => [],
};
return view('livewire.quick-search-dropdown', [
'search_results' => $search_results,
'search_results' => $this->quicksearchText === '' ? [] : match ($this->quicksearchRadio) {
'movies' => Movie::query()
->select(['id', 'poster', 'title', 'release_date'])
->selectRaw("concat(title, ' ', release_date) as title_and_year")
->having('title_and_year', 'LIKE', $search)
->has('torrents')
->oldest('title')
->take(10)
->get(),
'series' => Tv::query()
->select(['id', 'poster', 'name', 'first_air_date'])
->selectRaw("concat(name, ' ', first_air_date) as title_and_year")
->having('title_and_year', 'LIKE', $search)
->has('torrents')
->oldest('name')
->take(10)
->get(),
'persons' => Person::query()
->select(['id', 'still', 'name'])
->whereNotNull('still')
->where('name', 'LIKE', $search)
->oldest('name')
->take(10)
->get(),
default => [],
},
]);
}
}