mirror of
https://github.com/til-schneider/slim-wiki.git
synced 2025-08-06 08:37:31 +02:00
Added basic markdown page rendering
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/.idea/
|
6
src/.htaccess
Normal file
6
src/.htaccess
Normal file
@@ -0,0 +1,6 @@
|
||||
RewriteEngine On
|
||||
|
||||
RewriteCond %{THE_REQUEST} !^GET\ /.*?client/(css|js|img)
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^(.*)$ index.php [L,QSA]
|
5
src/articles/index.md
Normal file
5
src/articles/index.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Example Wiki
|
||||
============
|
||||
|
||||
Place the content of you *slim wiki* into this directory. Write it using
|
||||
[GitHub flavored](https://help.github.com/articles/github-flavored-markdown) [Markdown](https://daringfireball.net/projects/markdown/).
|
40
src/index.php
Normal file
40
src/index.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Split URI example: 'http://localhost/slim-wiki/myfolder/mypage?action=bla'
|
||||
// into $appPath example: '/slim-wiki'
|
||||
// and $requestPathArray example: array('myfolder', 'mypage')
|
||||
|
||||
$uriPathArray = explode("/", parse_url($_SERVER['REQUEST_URI'])['path']);
|
||||
$scriptPathArray = explode("/", dirname($_SERVER['SCRIPT_NAME']));
|
||||
|
||||
$appPathArray = array();
|
||||
$requestPathArray = array();
|
||||
$isAppPath = true;
|
||||
foreach ($uriPathArray as $level => $uriDir) {
|
||||
$scriptDir = isset($scriptPathArray[$level]) ? $scriptPathArray[$level] : null;
|
||||
if ($isAppPath && $scriptDir != $uriDir) {
|
||||
// The URI path differs from the script path here -> We arrived at the level where the app is installed
|
||||
$isAppPath = false;
|
||||
}
|
||||
|
||||
if ($isAppPath) {
|
||||
$appPathArray[] = $uriDir;
|
||||
} else {
|
||||
$requestPathArray[] = $uriDir;
|
||||
}
|
||||
}
|
||||
$appPath = rtrim(implode('/', $appPathArray), '/');
|
||||
|
||||
$https = false;
|
||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||
$https = true;
|
||||
}
|
||||
$baseUrl = 'http' . ($https ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $appPath;
|
||||
|
||||
unset($uriPathArray, $scriptPathArray, $appPathArray, $isAppPath, $https);
|
||||
|
||||
require_once __DIR__ . '/server/logic/main.php';
|
||||
|
||||
(new Main())->dispatch($baseUrl, $appPath, $requestPathArray);
|
13
src/server/layout/page.php
Normal file
13
src/server/layout/page.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0">
|
||||
|
||||
<title>Slim Wiki</title>
|
||||
</head>
|
||||
<body>
|
||||
<article><?php echo $articleMarkup ?></article>
|
||||
</body>
|
||||
</html>
|
27
src/server/logic/Main.php
Normal file
27
src/server/logic/Main.php
Normal 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>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user