keyoxide-web/index.php

86 lines
3.2 KiB
PHP
Raw Normal View History

2020-06-26 09:00:22 -06:00
<?php
include_once __DIR__ . '/vendor/autoload.php';
use Pagerange\Markdown\MetaParsedown;
// Init router
$router = new AltoRouter();
// Router mapping
$router->map('GET', '/', function() {}, 'index');
$router->map('GET', '/verify', function() {}, 'verify');
$router->map('GET', '/encrypt', function() {}, 'encrypt');
$router->map('GET', '/proofs', function() {}, 'proofs');
$router->map('GET', '/verify/[:uid]', function() {}, 'verifyUid');
$router->map('GET', '/encrypt/[:uid]', function() {}, 'encryptUid');
$router->map('GET', '/proofs/[:uid]', function() {}, 'proofsUid');
2020-06-28 12:14:31 -06:00
$router->map('GET', '/guides', function() {}, 'guides');
$router->map('GET', '/guides/[:id]', function() {}, 'guideId');
2020-06-26 09:00:22 -06:00
$router->map('GET', '/faq', function() {}, 'faq');
2020-06-26 09:33:39 -06:00
$router->map('GET', '/[:uid]', function() {}, 'profile');
2020-06-26 09:00:22 -06:00
// Router matching
$match = $router->match();
// Render the appropriate route
if(is_array($match) && is_callable($match['target'])) {
switch ($match['name']) {
case 'index':
readfile('pages/index.html');
break;
case 'verify':
case 'verifyUid':
$content = file_get_contents('pages/verify.html');
$content = str_replace('%UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ""), $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
2020-06-26 09:00:22 -06:00
break;
case 'encrypt':
case 'encryptUid':
$content = file_get_contents('pages/encrypt.html');
$content = str_replace('%UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ""), $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
2020-06-26 09:00:22 -06:00
break;
case 'proofs':
case 'proofsUid':
$content = file_get_contents('pages/proofs.html');
$content = str_replace('%UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ""), $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
2020-06-26 09:00:22 -06:00
break;
2020-06-26 09:33:39 -06:00
case 'profile':
2020-06-26 10:01:39 -06:00
$content = file_get_contents('pages/profile.html');
2020-06-26 10:04:31 -06:00
$content = str_replace('%UID%', $match['params']['uid'], $content);
2020-06-26 10:01:39 -06:00
header('Content-Type: text/html; charset=utf-8');
2020-06-26 10:04:31 -06:00
echo($content);
2020-06-26 09:33:39 -06:00
break;
2020-06-28 12:14:31 -06:00
case 'guides':
readfile('pages/guides.html');
break;
case 'guideId':
$id = $match['params']['id'];
$content = file_get_contents("pages/template.html");
$guideTitle = file_get_contents("pages/guides/$id.title.html");
$guideContent = file_get_contents("pages/guides/$id.content.html");
$guideContent = "<p><a href='/guides'>Back to guides</a></p>".$guideContent;
$content = str_replace('%TITLE%', $guideTitle, $content);
$content = str_replace('%CONTENT%', $guideContent, $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
break;
case 'faq':
readfile('pages/faq.html');
break;
2020-06-26 09:00:22 -06:00
}
} else {
// No route was matched
}