1
0
mirror of https://github.com/til-schneider/slim-wiki.git synced 2025-10-21 11:36:05 +02:00
Files
php-slim-wiki/src/server/logic/Main.php
2015-12-20 11:00:08 +01:00

31 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/../lib/parsedown/Parsedown.php';
class Main {
// Parameters:
// - $baseUrl: E.g. 'http://localhost/slim-wiki/'
// - $appPath: E.g. '/slim-wiki'
// - $requestPathArray: E.g. array('myfolder', 'mypage')
public function dispatch($baseUrl, $appPath, $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>';
}
}
}