keyoxide-web/index.php
Yarmo Mackenbach caa43ce8af Add guides
2020-06-28 20:14:31 +02:00

85 lines
3.2 KiB
PHP

<?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');
$router->map('GET', '/guides', function() {}, 'guides');
$router->map('GET', '/guides/[:id]', function() {}, 'guideId');
$router->map('GET', '/faq', function() {}, 'faq');
$router->map('GET', '/[:uid]', function() {}, 'profile');
// 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);
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);
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);
break;
case 'profile':
$content = file_get_contents('pages/profile.html');
$content = str_replace('%UID%', $match['params']['uid'], $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
break;
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;
}
} else {
// No route was matched
}