1
0
mirror of https://github.com/til-schneider/slim-wiki.git synced 2025-10-21 11:36:05 +02:00

Added basic markdown page rendering

This commit is contained in:
til-schneider
2015-12-19 19:59:20 +01:00
parent 4d04fe0b6c
commit dbc509c004
6 changed files with 92 additions and 0 deletions

27
src/server/logic/Main.php Normal file
View File

@@ -0,0 +1,27 @@
<?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 (($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>';
}
}
}