Consolidated things into DeveloperRoutes.
This commit is contained in:
parent
f2f5358589
commit
3dd9a21069
7 changed files with 111 additions and 217 deletions
|
@ -95,14 +95,30 @@ window.fm = (function() {
|
||||||
this.getNowListening = function(callback) {
|
this.getNowListening = function(callback) {
|
||||||
if(!callback)
|
if(!callback)
|
||||||
return;
|
return;
|
||||||
var xhr = new XMLHttpRequest;
|
|
||||||
xhr.onreadystatechange = function() {
|
const self = this;
|
||||||
if(xhr.readyState !== 4 || xhr.status !== 200)
|
|
||||||
|
$x.get('https://now.flash.moe/get.php?u=flashwave_').then(output => {
|
||||||
|
if(output.status !== 200)
|
||||||
return;
|
return;
|
||||||
callback.call(this, JSON.parse(xhr.responseText));
|
|
||||||
}.bind(this);
|
let info = output.json();
|
||||||
xhr.open('GET', '/now-listening.json');
|
if(info.length < 1)
|
||||||
xhr.send();
|
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() {
|
this.updateIndexNowListening = function() {
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Makai\Contacts;
|
|
||||||
|
|
||||||
use Index\Routing\Route;
|
|
||||||
use Index\Routing\RouteHandler;
|
|
||||||
use Sasae\SasaeEnvironment;
|
|
||||||
|
|
||||||
class ContactsRoutes extends RouteHandler {
|
|
||||||
public function __construct(
|
|
||||||
private SasaeEnvironment $templating,
|
|
||||||
private Contacts $contacts
|
|
||||||
) {}
|
|
||||||
|
|
||||||
#[Route('GET', '/contact')]
|
|
||||||
public function getContact(): string {
|
|
||||||
return $this->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);
|
|
||||||
}
|
|
||||||
}
|
|
87
src/DeveloperRoutes.php
Normal file
87
src/DeveloperRoutes.php
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
<?php
|
||||||
|
namespace Makai;
|
||||||
|
|
||||||
|
use Index\Routing\Route;
|
||||||
|
use Index\Routing\RouteHandler;
|
||||||
|
use Sasae\SasaeEnvironment;
|
||||||
|
use Makai\Contacts\Contacts;
|
||||||
|
use Makai\Projects\Projects;
|
||||||
|
|
||||||
|
class DeveloperRoutes extends RouteHandler {
|
||||||
|
public function __construct(
|
||||||
|
private SasaeEnvironment $templating,
|
||||||
|
private Contacts $contacts,
|
||||||
|
private Projects $projects
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[Route('GET', '/')]
|
||||||
|
public function getIndex($response, $request) {
|
||||||
|
$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');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,89 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Makai;
|
|
||||||
|
|
||||||
use Index\Routing\Route;
|
|
||||||
use Index\Routing\RouteHandler;
|
|
||||||
use Sasae\SasaeEnvironment;
|
|
||||||
use Makai\Contacts\Contacts;
|
|
||||||
use Makai\Projects\Projects;
|
|
||||||
|
|
||||||
class HomeRoutes extends RouteHandler {
|
|
||||||
public function __construct(
|
|
||||||
private SasaeEnvironment $templating,
|
|
||||||
private Contacts $contacts,
|
|
||||||
private Projects $projects
|
|
||||||
) {}
|
|
||||||
|
|
||||||
#[Route('GET', '/')]
|
|
||||||
public function getIndex($response, $request) {
|
|
||||||
$legacyPage = (string)$request->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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -95,16 +95,10 @@ final class MakaiContext {
|
||||||
$routingCtx = new RoutingContext($this->templating);
|
$routingCtx = new RoutingContext($this->templating);
|
||||||
$routingCtx->registerDefaultErrorPages();
|
$routingCtx->registerDefaultErrorPages();
|
||||||
|
|
||||||
$routingCtx->register(new HomeRoutes($this->templating, $this->contacts, $this->projects));
|
$routingCtx->register(new DeveloperRoutes($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 AssetsRoutes($this->siteInfo));
|
$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 Whois\WhoisRoutes($this->templating, fn() => $this->csrfp));
|
||||||
|
|
||||||
$routingCtx->register(new SSHKeys\SSHKeysRoutes($this->sshKeys));
|
$routingCtx->register(new SSHKeys\SSHKeysRoutes($this->sshKeys));
|
||||||
|
|
||||||
$routingCtx->register(new Tools\AsciiRoutes($this->templating));
|
$routingCtx->register(new Tools\AsciiRoutes($this->templating));
|
||||||
$routingCtx->register(new Tools\RandomStringRoutes);
|
$routingCtx->register(new Tools\RandomStringRoutes);
|
||||||
|
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Makai;
|
|
||||||
|
|
||||||
use Index\Routing\Route;
|
|
||||||
use Index\Routing\RouteHandler;
|
|
||||||
use Sasae\SasaeEnvironment;
|
|
||||||
|
|
||||||
class NowListeningRoutes extends RouteHandler {
|
|
||||||
public function __construct(
|
|
||||||
private SasaeEnvironment $templating
|
|
||||||
) {}
|
|
||||||
|
|
||||||
#[Route('GET', '/now-listening')]
|
|
||||||
public function getIndex($response, $request): string {
|
|
||||||
return $this->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],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Makai\Projects;
|
|
||||||
|
|
||||||
use Index\Routing\Route;
|
|
||||||
use Index\Routing\RouteHandler;
|
|
||||||
use Sasae\SasaeEnvironment;
|
|
||||||
|
|
||||||
class ProjectsRoutes extends RouteHandler {
|
|
||||||
public function __construct(
|
|
||||||
private SasaeEnvironment $templating,
|
|
||||||
private Projects $projects
|
|
||||||
) {}
|
|
||||||
|
|
||||||
#[Route('GET', '/projects')]
|
|
||||||
public function getContact(): 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', '/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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue