diff --git a/app/views/character.php b/app/views/character.php index 96d96e02..26ad4bc7 100644 --- a/app/views/character.php +++ b/app/views/character.php @@ -1,12 +1,12 @@ -
-
-
- -
-
-

- -

-
-
+
+
+
+ +
+
+

+ +

+
+
\ No newline at end of file diff --git a/app/views/me.php b/app/views/me.php new file mode 100644 index 00000000..508d28b4 --- /dev/null +++ b/app/views/me.php @@ -0,0 +1,25 @@ +
+
+
+

+ +
+
+ + + + + +
Location
+
+
+
+
About:
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/src/API/JsonAPI.php b/src/API/JsonAPI.php index 098db60f..af4472f6 100644 --- a/src/API/JsonAPI.php +++ b/src/API/JsonAPI.php @@ -111,6 +111,31 @@ class JsonAPI { return $organized; } + + public static function lightlyOrganizeIncludes(array $includes): array + { + $organized = []; + + foreach($includes as $item) + { + $type = $item['type']; + $id = $item['id']; + $organized[$type] = $organized[$type] ?? []; + $newItem = []; + + foreach(['attributes', 'relationships'] as $key) + { + if (array_key_exists($key, $item)) + { + $newItem[$key] = $item[$key]; + } + } + + $organized[$type][$id] = $newItem; + } + + return $organized; + } /** * Reorganize relationship mappings to make them simpler to use diff --git a/src/API/Kitsu/Model.php b/src/API/Kitsu/Model.php index 4873cba9..116dcb19 100644 --- a/src/API/Kitsu/Model.php +++ b/src/API/Kitsu/Model.php @@ -139,12 +139,18 @@ class Model { return $data; } + /** + * Get profile information for the configured user + * + * @param string $username + * @return array + */ public function getUserData(string $username): array { $userId = $this->getUserIdByUsername($username); $data = $this->getRequest("/users/{$userId}", [ 'query' => [ - 'include' => 'waifu,pinnedPost,blocks,linkedAccounts,profileLinks,mediaFollows,userRoles' + 'include' => 'waifu,pinnedPost,blocks,linkedAccounts,profileLinks,profileLinks.profileLinkSite,mediaFollows,userRoles' ] ]); // $data['included'] = JsonAPI::organizeIncludes($data['included']); diff --git a/src/Controller.php b/src/Controller.php index 45ea16ce..f2a86ff1 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -20,6 +20,7 @@ use const Aviat\AnimeClient\SESSION_SEGMENT; use function Aviat\AnimeClient\_dir; +use Aviat\AnimeClient\API\JsonAPI; use Aviat\Ion\Di\{ContainerAware, ContainerInterface}; use Aviat\Ion\View\{HtmlView, HttpView, JsonView}; use InvalidArgumentException; @@ -127,7 +128,14 @@ class Controller { { $username = $this->config->get(['kitsu_username']); $model = $this->container->get('kitsu-model'); - $this->outputJSON($model->getUserData($username)); + $data = $model->getUserData($username); + $included = JsonAPI::lightlyOrganizeIncludes($data['included']); + $this->outputHTML('me', [ + 'title' => 'About' . $this->config->get('whose_list'), + 'attributes' => $data['data']['attributes'], + 'relationships' => $data['data']['relationships'], + 'included' => $included + ]); } /** diff --git a/src/Util.php b/src/Util.php index f7a559fe..43cc92c3 100644 --- a/src/Util.php +++ b/src/Util.php @@ -39,7 +39,8 @@ class Util { 'login', 'logout', 'details', - 'character' + 'character', + 'me' ]; /** diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index 587c798a..bf3dff2b 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -234,6 +234,7 @@ class DispatcherTest extends AnimeClientTestCase { 'anime' => 'Aviat\AnimeClient\Controller\Anime', 'manga' => 'Aviat\AnimeClient\Controller\Manga', 'collection' => 'Aviat\AnimeClient\Controller\Collection', + 'character' => 'Aviat\AnimeClient\Controller\Character', ] ], 'empty_controller_list' => [ @@ -255,6 +256,7 @@ class DispatcherTest extends AnimeClientTestCase { 'anime' => 'Aviat\AnimeClient\Controller\Anime', 'manga' => 'Aviat\AnimeClient\Controller\Manga', 'collection' => 'Aviat\AnimeClient\Controller\Collection', + 'character' => 'Aviat\AnimeClient\Controller\Character', ] ] ];