wiki/wiki.php

92 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
2019-07-04 16:34:33 +00:00
/*
This code is Copyright(c) 2019 by ubergeek under the GPL 3 or later.
Parsedown is licensed under the MIT license.
*/
2019-07-01 00:32:30 +00:00
include('config.php');
2019-07-04 16:34:33 +00:00
include('parsedown-1.7.3/Parsedown.php');
2019-07-01 00:32:30 +00:00
2021-03-20 16:43:07 +00:00
$page = isset($_GET['page']) ? $_GET['page'] : 'main';
2021-03-20 16:53:54 +00:00
// Sanitize page request so we don't allow to read EVERY markdown file
// for example ../../../home/foobar/mysecretdocument
if (strpos($page, "../") !== false) {
header('HTTP/1.0 403 Forbidden');
exit();
2021-03-20 16:53:54 +00:00
}
$content_file = "articles/$page.md";
2021-03-20 16:53:54 +00:00
// When you need some debugging
//echo "<br>page: $page";
//echo "<br>content file: $content_file";
2019-07-04 16:34:33 +00:00
$Parsedown = new Parsedown();
$Parsedown->setSafeMode(true);
2021-01-12 13:27:16 +00:00
if(isset($_GET['style']))
$site_style = $_GET['style'];
else
$site_style="site";
2019-07-04 16:34:33 +00:00
2021-03-20 16:36:39 +00:00
$header = file_get_contents("includes/header.md");
$sidebar = file_get_contents("includes/sidebar.md");
2021-03-20 16:43:07 +00:00
$content = file_exists($content_file) ? file_get_contents($content_file) : str_replace('$page', "$page", file_get_contents("includes/404.md"));
2021-03-20 16:36:39 +00:00
$footer = file_get_contents("includes/footer.md");
// TODO: Stylesheet URL assumes wiki is not operate in subfolder
2019-06-29 02:49:58 +00:00
print "<!DOCTYPE html>
2019-06-30 17:11:12 +00:00
<html lang='en'>
2019-06-28 15:51:05 +00:00
<head>
2019-07-01 01:01:55 +00:00
<title>$site_name - $page</title>
<link rel='stylesheet' type='text/css' href='/includes/$site_style.css'>
2019-07-01 01:05:38 +00:00
</head>
<body>
<!-- Begin Header -->
<div id='header'>";
2019-07-04 16:34:33 +00:00
print $Parsedown->text($header);
print "
</div>
<!-- End Header -->
";
2019-07-01 00:35:39 +00:00
print "<hr>
<div id='body'>
<!-- Begin Sidebar -->
<div id='sidebar'>
";
2019-07-04 16:34:33 +00:00
echo $Parsedown->text($sidebar);
print " </div>
<!-- End Sidebar -->
<!-- Begin Body -->
<div id='content'>";
2019-07-04 16:34:33 +00:00
echo $Parsedown->text($content);
print " </div>
<!-- End Body -->
2019-07-01 00:32:30 +00:00
</div>
<!-- Begin Footer -->
<div id='footer'>
2019-07-02 01:11:01 +00:00
<hr>
";
2019-07-04 16:34:33 +00:00
echo $Parsedown->text($footer);
2019-06-28 15:51:05 +00:00
print " </div>
<!-- End Footer -->
</body>
2019-06-28 15:51:05 +00:00
</html>";
?>