123movies-seo/app/Http/Controllers/ShowController.php

188 lines
8 KiB
PHP
Raw Permalink Normal View History

2024-08-24 23:08:42 +03:00
<?php
namespace App\Http\Controllers;
2024-08-26 22:05:12 +03:00
use App\Http\Requests\ShowRequest;
2024-08-24 23:08:42 +03:00
use DipeshSukhia\LaravelHtmlMinify\LaravelHtmlMinifyFacade;
use Illuminate\Http\Request;
use App\Services\ApiClient;
use App\Services\TmdbClient;
use App\Supports\SchemaBuilder;
use App\Supports\Traits\CleanItems;
use App\Supports\Traits\TopContent;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use Illuminate\Support\Str;
2024-08-30 19:49:30 +03:00
use App\Supports\Helpers;
2024-08-24 23:08:42 +03:00
use App\Http\Requests\MoreMoviesRequest;
use App\Http\Resources\MoreTitles;
class ShowController extends Controller
{
use CleanItems, TopContent;
2024-08-26 22:05:12 +03:00
public function index(TmdbClient $tmdb, ApiClient $api, int $id, string $slug)
2024-08-24 23:08:42 +03:00
{
2024-08-26 22:05:12 +03:00
2024-08-24 23:08:42 +03:00
$airing = [];
$call = function() use($tmdb, $id, &$season, &$airing){
$id = self::decodeId($id);
2024-08-26 22:05:12 +03:00
$data = $tmdb->getShow($id);
2024-08-24 23:08:42 +03:00
$airing = $this->formatTmdbResponse($tmdb->getAiringShows(1), false, [], 12)['data'];
return $data;
};
$results = $call(); // Cache::remember(implode('__', ['show', $id, $slug, $season]),3600, $call);
// dd($results);
$data = $results;
// dd($data);
// dd($data);
$meta['image'] = $data['backdrop'];
$meta['schema'] = SchemaBuilder::getShowSchema($results);
$meta['title'] = Str::replace(['{TITLE}'], [$data['title']], config('site.shows.detail.title'));
$meta['description'] = Str::limit(Str::replace(['{OVERVIEW}'], [$data['overview']], config('site.shows.detail.description')), 150);
$meta['keywords'] = config('site.shows.detail.keywords', '');
2024-08-30 20:38:24 +03:00
$is_show_page = true;
2024-08-24 23:08:42 +03:00
$show = $data;
// dd($season);
$season = false;
$episode = false;
return view('show', compact('show', 'season', 'meta', 'is_show_page', 'airing', 'episode'));
}
2024-08-26 22:05:12 +03:00
public function season(TmdbClient $tmdb, ApiClient $api, int $id, string $slug = null, int $season = null )
2024-08-24 23:08:42 +03:00
{
$airing = [];
$is_show_page = is_null($season);
$call = function() use($tmdb, $id, &$season, &$airing){
$id = self::decodeId($id);
$show = $tmdb->getShow($id);
if (isset($season)) {
$season_number = (int)$season;
// dd($movie);
$season = $tmdb->getSeason($show['id'], $season_number);
$season = $this->formatTmdbSeason($season, $show);
}
2024-08-30 19:49:30 +03:00
// $airing = $this->formatTmdbResponse($tmdb->getAiringShows(1), false, [], 12)['data'];
return $show;
2024-08-24 23:08:42 +03:00
};
$results = $call(); // Cache::remember(implode('__', ['show', $id, $slug, $season]),3600, $call);
// dd($results);
$data = $results;
// dd($data);
// dd($data);
$meta['image'] = $data['backdrop'];
$show = $data;
$episode = false;
$meta['schema'] = SchemaBuilder::getShowSeasonSchema($results, $season);
$meta['title'] = Str::replace(['{TITLE}', '{SEASON}', '{SEASON_TITLE}'], [$data['title'], $season['season_number'], $season['name']], config('site.shows.detail_season.title'));
$meta['description'] = Str::limit(Str::replace(['{OVERVIEW}', '{SEASON}'], [ !empty($season['overview']) ? $season['overview'] : sprintf('Season %s - ', $season['season_number']) . $data['overview'], $season['season_number']], config('site.shows.detail_season.description')), 150);
$meta['keywords'] = config('site.shows.detail_season.keywords');
// dd($season);
return view('show', compact('show', 'season', 'meta', 'is_show_page', 'airing', 'episode'));
}
2024-08-30 19:49:30 +03:00
public function episode(TmdbClient $tmdb, ApiClient $api, AdsController $adsController, int $id, string $slug, int $season, int $episode)
2024-08-24 23:08:42 +03:00
{
$similar = [];
$season_number = $season;
$episode_number = $episode;
$call = function() use($tmdb, $id, &$season, &$episode, &$similar, $season_number, $episode_number){
$id = self::decodeId($id);
2024-08-30 19:49:30 +03:00
$data = $tmdb->getShow($id);
$season = $tmdb->getSeason($data['id'], $season_number);
$season = $this->formatTmdbSeason($season, $data);
$episode = $tmdb->getEpisode($data['id'], $season_number, $episode_number);
2024-08-24 23:08:42 +03:00
$episode = $this->formatTmdbEpisode($episode);
return $data;
};
2024-08-30 19:49:30 +03:00
$show = $call(); // Cache::remember(implode('__', ['show', $id, $slug, $season]),3600, $call);
2024-08-24 23:08:42 +03:00
// dd($results);
2024-08-30 19:49:30 +03:00
$meta['schema'] = SchemaBuilder::getShowEpisodeSchema($show, $season, $episode);
// load episode background path if available
$show['backdrop_path'] = $episode['still_path'] ?? $show['backdrop_path'];
$meta['title'] = Str::replace(['{TITLE}', '{SEASON}', '{EPISODE}', '{EPISODE_TITLE}'], [$show['title'], $season_number, $episode_number, $episode['name']], config('site.shows.detail_episode.title'));
2024-08-24 23:08:42 +03:00
$meta['description'] = Str::limit(Str::replace(['{OVERVIEW}', '{SEASON}', '{EPISODE}'], [$episode['overview'], $season_number, $episode_number], config('site.shows.detail_episode.description')), 150);
$meta['image'] = $episode['backdrop'];
$meta['keywords'] = config('site.shows.detail_episode.keywords');
2024-08-30 19:49:30 +03:00
$is_show_page = false;
return view('show', compact('show', 'season', 'episode', 'meta', 'is_show_page'));
2024-08-24 23:08:42 +03:00
}
public function shows( ApiClient $api, TmdbClient $tmdb, ?int $page = 1,)
{
$results = $this->formatApiResponse($api->getPopularShows($page, 36), true, ['name' => Route::current()->getName()]);
$meta['title'] = config('site.shows.list.title', 'Popular Shows');
if ($page > 1) $meta['title'] .= sprintf(' - Page %s', $page);
2024-08-28 21:40:08 +03:00
$meta['page_title'] = config('site.shows.list.page_title', 'Popular Shows');
2024-08-24 23:08:42 +03:00
$meta['description'] = config('site.shows.list.description', 'Popular Shows');
$meta['keywords'] = config('site.shows.list.keywords', false);
2024-08-28 01:03:34 +03:00
$meta['image'] = asset('images/cover.jpg');
2024-08-24 23:08:42 +03:00
$meta['type'] = 'TV Shows';
$meta['route'] = Route::current();
$pagination = $results['pagination'];
$data = $results['data'];
$type = 'show';
$genre = false;
return view('list', compact('data', 'pagination', 'meta', 'type', 'genre'));
}
public function shows_more( ApiClient $api, TmdbClient $tmdb, MoreMoviesRequest $moreMoviesRequest)
{
$results = $this->formatApiResponse($api->getPopularShows($moreMoviesRequest->validated()['page'], 36), true);
$items = MoreTitles::collection($results['data']);
$has_more_pages = $results['pagination']->hasMorePages();
$current_page = $results['pagination']->currentPage();
$html = LaravelHtmlMinifyFacade::htmlMinify(view('components.more_titles', compact('items'))->render());
return response()->json(compact('current_page', 'has_more_pages', 'html'));
}
public function genres( ApiClient $api, TmdbClient $tmdb, string $genre, ?int $page = 1)
{
$genre = Helpers::getShowGenreBySlug($genre);
if (is_null($genre)) abort(404);
$results = $this->formatApiResponse($api->getGenreShows($genre->id, $page, 36), true, ['name' => Route::current()->getName(), 'params' => ['genre' => $genre->slug]]);
$meta['title'] = sprintf(config('site.shows.genres.title', 'Genre Shows'), $genre->name);
if ($page > 1) $meta['title'] .= sprintf(' - Page %s', $page);
$meta['page_title'] = sprintf(config('site.shows.genres.title', 'Genre Shows'), $genre->name);
$meta['description'] = sprintf(config('site.shows.genres.description', 'Genre Shows'), $genre->name);
$meta['keywords'] = config('site.shows.genres.keywords');
2024-08-28 01:03:34 +03:00
$meta['image'] = asset('images/cover.jpg');
2024-08-24 23:08:42 +03:00
$meta['route'] = Route::current();
$pagination = $results['pagination'];
// dd($pagination);
$data = $results['data'];
$type = 'show';
return view('list', compact('data', 'pagination', 'meta', 'genre', 'type'));
}
}