From fa27abb9546480a93f2e2669bcd44f6bd2974c97 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Tue, 30 Oct 2018 11:42:32 -0400 Subject: [PATCH] Add tabs to character page sections --- app/appConf/routes.php | 9 +- app/views/anime/details.php | 6 ++ app/views/character.php | 200 +++++++++++++++++++++++++----------- app/views/main-menu.php | 2 +- app/views/me.php | 44 +++++--- src/API/Kitsu/Model.php | 7 +- src/Controller/Index.php | 81 +++++++++++++-- 7 files changed, 252 insertions(+), 97 deletions(-) diff --git a/app/appConf/routes.php b/app/appConf/routes.php index 37e4ca70..7a8a7de6 100644 --- a/app/appConf/routes.php +++ b/app/appConf/routes.php @@ -183,10 +183,13 @@ return [ ] ], 'user_info' => [ - 'path' => '/me', - 'action' => 'me', - 'controller' => 'me', + 'path' => '/about/{user}', + 'action' => 'about', + 'controller' => DEFAULT_CONTROLLER, 'verb' => 'get', + 'tokens' => [ + 'user' => '.*?' + ] ], // --------------------------------------------------------------------- // Default / Shared routes diff --git a/app/views/anime/details.php b/app/views/anime/details.php index b31bbe5d..201f89c9 100644 --- a/app/views/anime/details.php +++ b/app/views/anime/details.php @@ -88,6 +88,12 @@ + 0 && count($staff) > 0): ?> +
+ +
+ + 0): ?>

diff --git a/app/views/character.php b/app/views/character.php index 0c406da5..fe862ede 100644 --- a/app/views/character.php +++ b/app/views/character.php @@ -31,82 +31,158 @@ use Aviat\AnimeClient\API\Kitsu;

Media

-
+
-
-

Anime

-
- $anime): ?> -
+
+ + +
- -
+ -
-

Manga

-
+ + - $manga): ?> -
+ + + +
- +
0): ?>

Castings

+ + + +

Voice Actors

+ +
+ + + $casting): ?> + type="radio" id="character-va" + name="character-vas" + /> + +
+ + + + + + $c): ?> + + + + + +
Cast MemberSeries
+
+ generate('person', ['id' => $c['person']['id']]); + ?> + + +
+ +
+
+
+
+
+ +
+ generate('anime.details', ['id' => $series['attributes']['slug']]); + $titles = Kitsu::filterTitles($series['attributes']); + ?> + + + + +
+ +
+
+
+ + +
+ + + $entries): ?>

$casting): ?> diff --git a/app/views/main-menu.php b/app/views/main-menu.php index eabd8ec0..b80bf053 100644 --- a/app/views/main-menu.php +++ b/app/views/main-menu.php @@ -51,7 +51,7 @@ $hasManga = stripos($_SERVER['REQUEST_URI'], 'manga') !== FALSE; [a( - $url->generate('user_info'), + $url->generate('user_info', ['user' => 'me']), 'About '. $config->get('whose_list') ) ?>] diff --git a/app/views/me.php b/app/views/me.php index f53030a7..65cf69f8 100644 --- a/app/views/me.php +++ b/app/views/me.php @@ -1,20 +1,15 @@ - +
-

- - - -

- " alt="" /> +


@@ -38,7 +33,7 @@ $character = $relationships['waifu']['attributes']; echo $helper->a( $url->generate('character', ['slug' => $character['slug']]), - $character['name'] + $character['canonicalName'] ); ?> @@ -47,6 +42,10 @@ User Stats + + Time spent watching anime: + + # of Posts @@ -62,19 +61,30 @@
+

+ + + +

+
-
About:
+

About:

html($attributes['about']) ?>
+ +

Favorites

-

Favorite Characters

+

Characters

$char): ?>
-

Favorite Anime

+

Anime

@@ -116,7 +126,7 @@
-

Favorite Manga

+

Manga

diff --git a/src/API/Kitsu/Model.php b/src/API/Kitsu/Model.php index b8905775..bca83c9c 100644 --- a/src/API/Kitsu/Model.php +++ b/src/API/Kitsu/Model.php @@ -266,10 +266,11 @@ final class Model { 'name' => $username, ], 'fields' => [ - // 'anime' => 'slug,name,canonicalTitle', - 'characters' => 'slug,name,image' + 'anime' => 'slug,canonicalTitle,posterImage', + 'manga' => 'slug,canonicalTitle,posterImage', + 'characters' => 'slug,canonicalName,image' ], - 'include' => 'waifu,pinnedPost,blocks,linkedAccounts,profileLinks,profileLinks.profileLinkSite,userRoles,favorites.item' + 'include' => 'waifu,favorites.item,stats' ] ]); diff --git a/src/Controller/Index.php b/src/Controller/Index.php index 34e11da3..056ed41c 100644 --- a/src/Controller/Index.php +++ b/src/Controller/Index.php @@ -186,22 +186,32 @@ final class Index extends BaseController { * * @return void */ - public function me() + public function about($username = 'me') { - $username = $this->config->get(['kitsu_username']); + $isMainUser = $username === 'me'; + + $username = $isMainUser + ? $this->config->get(['kitsu_username']) + : $username; $model = $this->container->get('kitsu-model'); $data = $model->getUserData($username); $orgData = JsonAPI::organizeData($data)[0]; $rels = $orgData['relationships'] ?? []; $favorites = array_key_exists('favorites', $rels) ? $rels['favorites'] : []; + $timeOnAnime = $this->formatAnimeTime($orgData['attributes']['lifeSpentOnAnime']); + + $whom = $isMainUser + ? $this->config->get('whose_list') + : $username; $this->outputHTML('me', [ - 'title' => 'About ' . $this->config->get('whose_list'), + 'title' => 'About ' . $whom, 'data' => $orgData, 'attributes' => $orgData['attributes'], 'relationships' => $rels, 'favorites' => $this->organizeFavorites($favorites), + 'timeOnAnime' => $timeOnAnime, ]); } @@ -330,19 +340,26 @@ final class Index extends BaseController { $gdImg = imagecreatefromstring($data); $resizedImg = imagescale($gdImg, $width ?? $origWidth); - // save the webp versions - imagewebp($gdImg, "{$filePrefix}-original.webp"); - imagewebp($resizedImg, "{$filePrefix}.webp"); + if ($ext === 'gif') + { + file_put_contents("{$filePrefix}.gif", $data); + } + else + { + // save the webp versions + imagewebp($gdImg, "{$filePrefix}-original.webp"); + imagewebp($resizedImg, "{$filePrefix}.webp"); - // save the scaled jpeg file - imagejpeg($resizedImg, "{$filePrefix}.jpg"); + // save the scaled jpeg file + imagejpeg($resizedImg, "{$filePrefix}.jpg"); + + // And the original + file_put_contents("{$filePrefix}-original.jpg", $data); + } imagedestroy($gdImg); imagedestroy($resizedImg); - // And the original - file_put_contents("{$filePrefix}-original.jpg", $data); - if ($display) { $contentType = ($ext === 'webp') @@ -388,6 +405,13 @@ final class Index extends BaseController { return $output; } + /** + * Get a placeholder for a missing image + * + * @param string $path + * @param int|null $width + * @param int|null $height + */ private function getPlaceholder (string $path, ?int $width = 200, ?int $height = NULL): void { $height = $height ?? $width; @@ -402,4 +426,39 @@ final class Index extends BaseController { header('Content-Type: image/png'); echo file_get_contents($filename); } + + /** + * Format the time spent on anime in a more readable format + * + * @param int $minutes + * @return string + */ + private function formatAnimeTime (int $minutes): string + { + $minutesPerDay = 1440; + $minutesPerYear = $minutesPerDay * 365; + + // Minutes short of a year + $years = (int)floor($minutes / $minutesPerYear); + $minutes %= $minutesPerYear; + + // Minutes short of a day + $extraMinutes = $minutes % $minutesPerDay; + + $days = ($minutes - $extraMinutes) / $minutesPerDay; + + // Minutes short of an hour + $remMinutes = $extraMinutes % 60; + + $hours = ($extraMinutes - $remMinutes) / 60; + + $output = "{$days} days, {$hours} hours, and {$remMinutes} minutes."; + + if ($years > 0) + { + $output = "{$years} year(s),{$output}"; + } + + return $output; + } } \ No newline at end of file