118 lines
4.4 KiB
PHP
118 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\SearchRequest;
|
|
use App\Http\Resources\MoreTitles;
|
|
use App\Models\News;
|
|
use App\Services\ApiClient;
|
|
use App\Services\TmdbClient;
|
|
use DipeshSukhia\LaravelHtmlMinify\LaravelHtmlMinifyFacade;
|
|
use Illuminate\Http\Request;
|
|
use App\Supports\Traits\Helpers;
|
|
use Illuminate\Support\Str;
|
|
|
|
use App\Supports\Traits\CleanItems;
|
|
use App\Supports\Traits\TopContent;
|
|
|
|
use Route;
|
|
use stdClass;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
use CleanItems, TopContent;
|
|
|
|
public function index(ApiClient $api, TmdbClient $tmdb)
|
|
{
|
|
$meta = [];
|
|
$meta['title'] = config('site.home.title');
|
|
$meta['description'] = Str::limit(config('site.home.description'), 150);
|
|
$meta['full_description'] = config('site.home.description');
|
|
$meta['keywords'] = config('site.home.keywords', false);
|
|
$meta['image'] = asset('images/cover.jpg');
|
|
|
|
$nowplaying = $this->formatTmdbResponse($tmdb->getNowPlayingMovies(1), false, [], 12)['data'];
|
|
$upcoming = $this->formatTmdbResponse($tmdb->getUpcomingMovies(1), false, [], 12)['data'];
|
|
$comingsoon = $this->formatTmdbResponse($tmdb->getComingSoonMovies(1), false, [], 6)['data'];
|
|
$airing = $this->formatTmdbResponse($tmdb->getAiringShows(1), false, [], 12)['data'];
|
|
|
|
$hero = $this->getHomeHeroSliderData($api->getTrendingMovies(1, 7), $tmdb);
|
|
// dd($hero);
|
|
|
|
|
|
|
|
$popular_movies = self::formatApiResponse($api->getPopularMovies(1, 12), false)['data'];
|
|
$popular_shows = self::formatApiResponse($api->getTrendingShows(1, 12), false, [], 12)['data'];
|
|
$trending_movies = self::formatApiResponse($api->getTrendingMovies(1, 12), false, [], 12)['data'];
|
|
$trending_shows = self::formatApiResponse($api->getTrendingShows(1, 12), false)['data'];
|
|
$recent_added = $trending_movies[4];
|
|
|
|
|
|
|
|
return view('home', compact('meta', 'hero', 'popular_movies', 'popular_shows', 'trending_movies', 'trending_shows', 'nowplaying', 'upcoming', 'comingsoon', 'airing', 'recent_added'));
|
|
|
|
|
|
|
|
}
|
|
public function homesearch()
|
|
{
|
|
$meta = [];
|
|
$meta['title'] = config('site.homesearch.title');
|
|
$meta['description'] = Str::limit(config('site.homesearch.description'), 150);
|
|
$meta['full_description'] = config('site.homesearch.description');
|
|
$meta['keywords'] = config('site.homesearch.keywords', false);
|
|
$meta['image'] = asset('images/cover.jpg');
|
|
$content = config('site.homesearch.content');
|
|
|
|
|
|
|
|
return view('homesearch', compact('meta', 'content'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public function search(SearchRequest $request, TmdbClient $tmdb)
|
|
{
|
|
$query = $request->validated()['search'];
|
|
$page = $request->query('page', 1);
|
|
$results = $tmdb->getSearch($query, $page);
|
|
['data' => $data, 'pagination' => $pagination] = $this->formatTmdbSearchResponse($results);
|
|
$page_text = ($page > 1)
|
|
? sprintf(' - Page %s', $page)
|
|
: '';
|
|
|
|
|
|
$meta = [];
|
|
$meta['title'] = str(config('site.search.title'))->replace(['{QUERY}'], $query)->replace(['{PAGE}'], $page_text)->apa();
|
|
$meta['page_title'] = str(config('site.search.page_title'))->replace(['{QUERY}'], $query)->replace(['{PAGE}'], $page_text)->apa();
|
|
$meta['description'] = str(config('site.search.description'))->replace(['{QUERY}'], $query)->replace(['{PAGE}'], $page_text);
|
|
$meta['keywords'] = config('site.search.keywords', false);
|
|
$meta['image'] = asset('images/cover.jpg');
|
|
$meta['route'] = Route::current();
|
|
// dd($meta['route']);
|
|
|
|
// $query = str($query)->apa();
|
|
|
|
// sleep(2);
|
|
return view('search', compact('data', 'pagination', 'meta', 'query'));
|
|
|
|
}
|
|
public function search_more(SearchRequest $request, TmdbClient $tmdb)
|
|
{
|
|
$query = $request->validated()['search'];
|
|
$page = $request->validated()['page'];
|
|
$results = $this->formatTmdbSearchResponse($tmdb->getSearch($query, $page));
|
|
// dd($results);
|
|
$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'));
|
|
|
|
}
|
|
|
|
}
|