From e6b534078f6764aa395ee88e6ee750667bafa73b Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Wed, 31 Jan 2018 10:55:20 -0500 Subject: [PATCH] Add trailer videos to anime detail pages --- app/views/anime/details.php | 8 ++++- .../Kitsu/Transformer/AnimeTransformer.php | 29 ++++++++++--------- src/Controller.php | 16 +++++----- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/app/views/anime/details.php b/app/views/anime/details.php index 9e0ed3e3..eb6e333b 100644 --- a/app/views/anime/details.php +++ b/app/views/anime/details.php @@ -76,12 +76,18 @@ + +
+

Trailer

+ + 0): ?> +

Characters

-
+
$char): ?>
diff --git a/src/API/Kitsu/Transformer/AnimeTransformer.php b/src/API/Kitsu/Transformer/AnimeTransformer.php index 0b850f83..1d8a35bd 100644 --- a/src/API/Kitsu/Transformer/AnimeTransformer.php +++ b/src/API/Kitsu/Transformer/AnimeTransformer.php @@ -31,9 +31,9 @@ class AnimeTransformer extends AbstractTransformer { * @param array $item API library item * @return array */ - public function transform($item) + public function transform($item): array { - + $item['included'] = JsonAPI::organizeIncludes($item['included']); $genres = $item['included']['categories'] ?? []; $item['genres'] = array_column($genres, 'title') ?? []; @@ -42,21 +42,22 @@ class AnimeTransformer extends AbstractTransformer { $titles = Kitsu::filterTitles($item); return [ - 'id' => $item['id'], - 'slug' => $item['slug'], - 'title' => $titles[0], - 'titles' => $titles, - 'status' => Kitsu::getAiringStatus($item['startDate'], $item['endDate']), - 'cover_image' => $item['posterImage']['small'], - 'show_type' => $this->string($item['showType'])->upperCaseFirst()->__toString(), - 'episode_count' => $item['episodeCount'], - 'episode_length' => $item['episodeLength'], - 'synopsis' => $item['synopsis'], 'age_rating' => $item['ageRating'], 'age_rating_guide' => $item['ageRatingGuide'], - 'url' => "https://kitsu.io/anime/{$item['slug']}", + 'cover_image' => $item['posterImage']['small'], + 'episode_count' => $item['episodeCount'], + 'episode_length' => $item['episodeLength'], 'genres' => $item['genres'], - 'streaming_links' => Kitsu::parseStreamingLinks($item['included']) + 'id' => $item['id'], + 'show_type' => $this->string($item['showType'])->upperCaseFirst()->__toString(), + 'slug' => $item['slug'], + 'status' => Kitsu::getAiringStatus($item['startDate'], $item['endDate']), + 'streaming_links' => Kitsu::parseStreamingLinks($item['included']), + 'synopsis' => $item['synopsis'], + 'title' => $titles[0], + 'titles' => $titles, + 'trailer_id' => $item['youtubeVideoId'], + 'url' => "https://kitsu.io/anime/{$item['slug']}", ]; } } \ No newline at end of file diff --git a/src/Controller.php b/src/Controller.php index c6bb8e57..aecf7323 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -149,7 +149,7 @@ class Controller { * @throws NotFoundException * @return void */ - public function setSessionRedirect(string $url = NULL) + public function setSessionRedirect(string $url = NULL): void { $serverParams = $this->request->getServerParams(); @@ -252,13 +252,13 @@ class Controller { $csp = [ "default-src 'self'", "object-src 'none'", - "child-src 'none'", + "frame-src *.youtube.com", ]; $view->addHeader('Content-Security-Policy', implode('; ', $csp)); $view->appendOutput($this->loadPartial($view, 'header', $data)); - if (array_key_exists('message', $data) && is_array($data['message'])) + if (array_key_exists('message', $data) && \is_array($data['message'])) { $view->appendOutput($this->loadPartial($view, 'message', $data['message'])); } @@ -300,7 +300,7 @@ class Controller { * @throws \Aviat\Ion\Di\NotFoundException * @return void */ - public function errorPage(int $httpCode, string $title, string $message, string $long_message = "") + public function errorPage(int $httpCode, string $title, string $message, string $long_message = ''): void { $this->outputHTML('error', [ 'title' => $title, @@ -314,7 +314,7 @@ class Controller { * * @return void */ - public function redirectToDefaultRoute() + public function redirectToDefaultRoute(): void { $defaultType = $this->config->get(['routes', 'route_config', 'default_list']) ?? 'anime'; $this->redirect($this->urlGenerator->defaultUrl($defaultType), 303); @@ -328,7 +328,7 @@ class Controller { * @param string $type * @return void */ - public function setFlashMessage(string $message, string $type = "info") + public function setFlashMessage(string $message, string $type = 'info'): void { static $messages; @@ -406,7 +406,7 @@ class Controller { * @throws DoubleRenderException * @return void */ - protected function outputJSON($data = 'Empty response', int $code = 200) + protected function outputJSON($data = 'Empty response', int $code = 200): void { (new JsonView($this->container)) ->setStatusCode($code) @@ -421,7 +421,7 @@ class Controller { * @param int $code * @return void */ - protected function redirect(string $url, int $code) + protected function redirect(string $url, int $code): void { $http = new HttpView($this->container); $http->redirect($url, $code);