35 lines
901 B
PHP
35 lines
901 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Twig\Environment;
|
|
use Twig\Loader\FilesystemLoader;
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
$twig = new Environment(new FilesystemLoader('./templates'));
|
|
|
|
$score = realpath('./scores/' . ($_GET['score'] ?? ''));
|
|
$scoreValid = false !== $score
|
|
&& str_starts_with($score, realpath('./scores'))
|
|
&& is_file($score)
|
|
&& str_ends_with($score, '.md');
|
|
|
|
$allAvailableScores = array_map(
|
|
fn (string $filePath) => basename($filePath, '.md'),
|
|
glob('./scores/*.md')
|
|
);
|
|
|
|
if (!$scoreValid) {
|
|
echo $twig->render('index.html.twig', ['scores' => $allAvailableScores, 'title' => 'Available Scores']);
|
|
exit(0);
|
|
}
|
|
|
|
$markdown = file_get_contents($score);
|
|
$parsedown = new Parsedown();
|
|
$html = $parsedown->text($markdown);
|
|
echo $twig->render('score.html.twig', [
|
|
'score' => $html,
|
|
'scores' => $allAvailableScores,
|
|
'title' => basename($score, '.md'),
|
|
]); |