From 3dd9a21069559d1b6ee49055fcfd5e0d22d5ae5d Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 14 Oct 2023 00:41:19 +0000 Subject: [PATCH] Consolidated things into DeveloperRoutes. --- assets/2021.js/main.js | 30 ++++++++--- src/Contacts/ContactsRoutes.php | 28 ----------- src/DeveloperRoutes.php | 87 ++++++++++++++++++++++++++++++++ src/HomeRoutes.php | 89 --------------------------------- src/MakaiContext.php | 8 +-- src/NowListeningRoutes.php | 39 --------------- src/Projects/ProjectsRoutes.php | 47 ----------------- 7 files changed, 111 insertions(+), 217 deletions(-) delete mode 100644 src/Contacts/ContactsRoutes.php create mode 100644 src/DeveloperRoutes.php delete mode 100644 src/HomeRoutes.php delete mode 100644 src/NowListeningRoutes.php delete mode 100644 src/Projects/ProjectsRoutes.php diff --git a/assets/2021.js/main.js b/assets/2021.js/main.js index 1fc815a..894f6a8 100644 --- a/assets/2021.js/main.js +++ b/assets/2021.js/main.js @@ -95,14 +95,30 @@ window.fm = (function() { this.getNowListening = function(callback) { if(!callback) return; - var xhr = new XMLHttpRequest; - xhr.onreadystatechange = function() { - if(xhr.readyState !== 4 || xhr.status !== 200) + + const self = this; + + $x.get('https://now.flash.moe/get.php?u=flashwave_').then(output => { + if(output.status !== 200) return; - callback.call(this, JSON.parse(xhr.responseText)); - }.bind(this); - xhr.open('GET', '/now-listening.json'); - xhr.send(); + + let info = output.json(); + if(info.length < 1) + return; + + info = info[0]; + + callback.call(self, { + name: info.name, + now_playing: !!info.nowplaying, + url: info.url, + cover: info.images?.large ?? '', + artist: { + name: info.artist?.name ?? '', + url: info.url.split('/_/')[0] + }, + }); + }); }; this.updateIndexNowListening = function() { diff --git a/src/Contacts/ContactsRoutes.php b/src/Contacts/ContactsRoutes.php deleted file mode 100644 index 5a98b15..0000000 --- a/src/Contacts/ContactsRoutes.php +++ /dev/null @@ -1,28 +0,0 @@ -templating->render('dev/contact', [ - 'contacts' => $this->contacts->getContacts(), - ]); - } - - #[Route('GET', '/contact.php')] - #[Route('GET', '/contact.html')] - #[Route('GET', '/nintendo')] - #[Route('GET', '/nintendo.php')] - public function getRedirect($response): void { - $response->redirect('/contact', true); - } -} diff --git a/src/DeveloperRoutes.php b/src/DeveloperRoutes.php new file mode 100644 index 0000000..9fb5bb4 --- /dev/null +++ b/src/DeveloperRoutes.php @@ -0,0 +1,87 @@ +projects->getProjects( + featuredOnly: true, + deleted: false, + take: 3, + random: true, + ); + + $projects = []; + foreach($projectInfos as $projectInfo) + $projects[] = [ + 'info' => $projectInfo, + 'colour' => $projectInfo->hasColour() ? $projectInfo->getColour() : $this->projects->getProjectColour($projectInfo), + ]; + + $contacts = $this->contacts->getContacts( + homePageOnly: true, + take: 3, + ); + + return $this->templating->render('dev/index', [ + 'projects' => $projects, + 'contacts' => $contacts, + ]); + } + + #[Route('GET', '/home')] + public function getPersonalHome(): string { + return $this->templating->render('dev/home'); + } + + #[Route('GET', '/contact')] + public function getContact(): string { + return $this->templating->render('dev/contact', [ + 'contacts' => $this->contacts->getContacts(), + ]); + } + + #[Route('GET', '/projects')] + public function getProjects(): string { + $projectInfos = $this->projects->getProjects(deleted: false); + + $items = []; + foreach($projectInfos as $projectInfo) + $items[] = [ + 'info' => $projectInfo, + 'langs' => $this->projects->getLanguages(projectInfo: $projectInfo), + 'colour' => $projectInfo->hasColour() ? $projectInfo->getColour() : $this->projects->getProjectColour($projectInfo), + ]; + + $sections = [ + 'projects' => [ + 'title' => 'Projects', + 'desc' => '', + 'items' => $items, + ], + ]; + + return $this->templating->render('dev/projects', [ + 'sections' => $sections, + ]); + } + + #[Route('GET', '/now-listening')] + public function getNowListening($response, $request): string { + return $this->templating->render('dev/np', [ + 'header_offset' => (int)$request->getParam('offset', FILTER_SANITIZE_NUMBER_INT), + ]); + } +} diff --git a/src/HomeRoutes.php b/src/HomeRoutes.php deleted file mode 100644 index e59efa9..0000000 --- a/src/HomeRoutes.php +++ /dev/null @@ -1,89 +0,0 @@ -getParam('p'); - if($request->hasParam('p')) { - $response->redirect(match($request->getParam('p')) { - 'projects' => '/projects', - 'contact' => '/contacts', - 'about' => '/', - 'etc' => '/', - 'hosted' => '/', - 'friends' => '/', - default => '/', - }, true); - return; - } - - $projectInfos = $this->projects->getProjects( - featuredOnly: true, - deleted: false, - take: 3, - random: true, - ); - - $projects = []; - foreach($projectInfos as $projectInfo) - $projects[] = [ - 'info' => $projectInfo, - 'colour' => $projectInfo->hasColour() ? $projectInfo->getColour() : $this->projects->getProjectColour($projectInfo), - ]; - - $contacts = $this->contacts->getContacts( - homePageOnly: true, - take: 3, - ); - - return $this->templating->render('dev/index', [ - 'projects' => $projects, - 'contacts' => $contacts, - ]); - } - - #[Route('GET', '/home')] - public function getPersonalHome(): string { - return $this->templating->render('dev/home'); - } - - // wow this is pretty quirky - #[Route('GET', '/about')] - #[Route('GET', '/about.html')] - #[Route('GET', '/about.php')] - #[Route('GET', '/index.php')] - #[Route('GET', '/index.html')] - #[Route('GET', '/related.php')] - #[Route('GET', '/related.html')] - #[Route('GET', '/friends')] - #[Route('GET', '/friends.php')] - #[Route('GET', '/friends.html')] - #[Route('GET', '/related')] - #[Route('GET', '/etc.php')] - #[Route('GET', '/etc.html')] - #[Route('GET', '/etcetera')] - #[Route('GET', '/etcetera.html')] - #[Route('GET', '/etcetera.php')] - #[Route('GET', '/misc')] - #[Route('GET', '/misc.html')] - #[Route('GET', '/misc.php')] - #[Route('GET', '/etc')] - #[Route('GET', '/365')] - #[Route('GET', '/donate')] - public function getRedirect($response): void { - $response->redirect('/', true); - } -} diff --git a/src/MakaiContext.php b/src/MakaiContext.php index 66ef060..ee83969 100644 --- a/src/MakaiContext.php +++ b/src/MakaiContext.php @@ -95,16 +95,10 @@ final class MakaiContext { $routingCtx = new RoutingContext($this->templating); $routingCtx->registerDefaultErrorPages(); - $routingCtx->register(new HomeRoutes($this->templating, $this->contacts, $this->projects)); - $routingCtx->register(new Contacts\ContactsRoutes($this->templating, $this->contacts)); - $routingCtx->register(new Projects\ProjectsRoutes($this->templating, $this->projects)); - + $routingCtx->register(new DeveloperRoutes($this->templating, $this->contacts, $this->projects)); $routingCtx->register(new AssetsRoutes($this->siteInfo)); - $routingCtx->register(new NowListeningRoutes($this->templating)); $routingCtx->register(new Whois\WhoisRoutes($this->templating, fn() => $this->csrfp)); - $routingCtx->register(new SSHKeys\SSHKeysRoutes($this->sshKeys)); - $routingCtx->register(new Tools\AsciiRoutes($this->templating)); $routingCtx->register(new Tools\RandomStringRoutes); diff --git a/src/NowListeningRoutes.php b/src/NowListeningRoutes.php deleted file mode 100644 index a9cbec6..0000000 --- a/src/NowListeningRoutes.php +++ /dev/null @@ -1,39 +0,0 @@ -templating->render('dev/np', [ - 'header_offset' => (int)$request->getParam('offset', FILTER_SANITIZE_NUMBER_INT), - ]); - } - - #[Route('GET', '/now-listening.json')] - public function getJson(): array { - $info = json_decode(file_get_contents('https://now.flash.moe/get.php?u=flashwave_')); - if(empty($info[0]?->name)) - return []; - - $info = $info[0]; - - return [ - 'name' => $info->name, - 'now_playing' => !empty($info->nowplaying), - 'url' => $info->url, - 'cover' => $info->images?->large ?? '', - 'artist' => [ - 'name' => $info->artist?->name ?? '', - 'url' => explode('/_/', $info->url)[0], - ], - ]; - } -} diff --git a/src/Projects/ProjectsRoutes.php b/src/Projects/ProjectsRoutes.php deleted file mode 100644 index 19fe4cf..0000000 --- a/src/Projects/ProjectsRoutes.php +++ /dev/null @@ -1,47 +0,0 @@ -projects->getProjects(deleted: false); - - $items = []; - foreach($projectInfos as $projectInfo) - $items[] = [ - 'info' => $projectInfo, - 'langs' => $this->projects->getLanguages(projectInfo: $projectInfo), - 'colour' => $projectInfo->hasColour() ? $projectInfo->getColour() : $this->projects->getProjectColour($projectInfo), - ]; - - $sections = [ - 'projects' => [ - 'title' => 'Projects', - 'desc' => '', - 'items' => $items, - ], - ]; - - return $this->templating->render('dev/projects', [ - 'sections' => $sections, - ]); - } - - #[Route('GET', '/projects.php')] - #[Route('GET', '/projects.html')] - #[Route('GET', '/utilities')] - #[Route('GET', '/utilities.php')] - #[Route('GET', '/utilities.html')] - public function getRedirect($response): void { - $response->redirect('/projects', true); - } -}