mirror of
https://github.com/til-schneider/slim-wiki.git
synced 2025-10-21 19:46:08 +02:00
31 lines
1.1 KiB
PHP
31 lines
1.1 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../lib/parsedown/Parsedown.php';
|
|
|
|
class Main {
|
|
|
|
// Parameters:
|
|
// - $baseUrl: E.g. 'http://localhost/slim-wiki/'
|
|
// - $basePath: E.g. '/slim-wiki/'
|
|
// - $requestPathArray: E.g. array('myfolder', 'mypage')
|
|
public function dispatch($baseUrl, $basePath, $requestPathArray) {
|
|
$articleBaseDir = realpath(__DIR__ . '/../../articles');
|
|
$articleFilename = $articleBaseDir . '/' . implode('/', $requestPathArray);
|
|
|
|
if (is_dir($articleFilename)) {
|
|
$articleFilename = rtrim($articleFilename, '/') . '/index.md';
|
|
}
|
|
|
|
if (($articleFilename == realpath($articleFilename)) && file_exists($articleFilename) && is_readable($articleFilename)) {
|
|
$articleContent = file_get_contents($articleFilename);
|
|
$articleMarkup = Parsedown::instance()->text($articleContent);
|
|
include(__DIR__ . '/../layout/page.php');
|
|
} else {
|
|
// TODO: Show error page
|
|
echo '<p style="color:#990000">File does not exist or is not readable: '.$articleFilename.'</p>';
|
|
}
|
|
|
|
}
|
|
|
|
}
|