84 lines
2.1 KiB
PHP
84 lines
2.1 KiB
PHP
|
<?php
|
||
|
require_once('Parsedown.php');
|
||
|
|
||
|
define("TITLE", "Static File Generator");
|
||
|
define("MD_DIR", "MarkdownFiles");
|
||
|
|
||
|
$func = $_GET['f'];
|
||
|
switch($func) {
|
||
|
case 'build': // Build the worship.html page
|
||
|
buildStaticPage();
|
||
|
break;
|
||
|
default:
|
||
|
showAdminPage();
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
function buildStaticPage() {
|
||
|
$pd = new Parsedown();
|
||
|
$title = !empty($_POST['title'])?$_POST['title']:TITLE;
|
||
|
$out = outputHTMLHeader($title, true);
|
||
|
$out .= '<pre>';
|
||
|
$out .= print_r($_POST, true);
|
||
|
$out .= '</pre>';
|
||
|
$out .= '======';
|
||
|
foreach($_POST['chosen_files'] as $file) {
|
||
|
if(file_exists($file)) {
|
||
|
$md = file_get_contents($file);
|
||
|
$out .= '<div class="afile">';
|
||
|
$out .= $pd->text($md);
|
||
|
$out .= "</div>";
|
||
|
}
|
||
|
}
|
||
|
$out .= outputHTMLFooter(true);
|
||
|
// For now, echo it.
|
||
|
echo $out;
|
||
|
}
|
||
|
|
||
|
function showAdminPage() {
|
||
|
outputHTMLHeader();
|
||
|
echo '<form action="/manager.php?f=build" method="POST">';
|
||
|
echo ' <div>';
|
||
|
echo ' <select multiple="multiple" name="chosen_files[]">';
|
||
|
foreach(glob(MD_DIR.'/*.md') as $file) {
|
||
|
echo ' <option value="'.$file.'">'.basename($file, '.md').'</option>';
|
||
|
echo ' <option value="'.$file.'">'.basename($file, '.md').'</option>';
|
||
|
echo ' <option value="'.$file.'">'.basename($file, '.md').'</option>';
|
||
|
echo ' <option value="'.$file.'">'.basename($file, '.md').'</option>';
|
||
|
echo ' <option value="'.$file.'">'.basename($file, '.md').'</option>';
|
||
|
}
|
||
|
echo ' </select>';
|
||
|
echo ' </div>';
|
||
|
echo ' <div>';
|
||
|
echo ' <label for="filename">Output File:</label>';
|
||
|
echo ' <input name="filename" value="" placeholder="File Name" />';
|
||
|
echo ' </div>';
|
||
|
echo ' <button type="submit">Build</button>';
|
||
|
echo '</form>';
|
||
|
outputHTMLFooter();
|
||
|
}
|
||
|
|
||
|
function outputHTMLHeader($title = TITLE, $ret = false) {
|
||
|
$out = '<!DOCTYPE html>'."\n"
|
||
|
.'<html lang="en">'."\n"
|
||
|
.' <head>'."\n"
|
||
|
.' <title>'.$title.'</title>'."\n"
|
||
|
.' </head>'."\n"
|
||
|
.' <body>'."\n";
|
||
|
if($ret) {
|
||
|
return $out;
|
||
|
}
|
||
|
echo $out;
|
||
|
}
|
||
|
|
||
|
function outputHTMLFooter($ret = false) {
|
||
|
$out = ' </body>'."\n"
|
||
|
.'</html>'."\n";
|
||
|
if($ret) {
|
||
|
return $out;
|
||
|
}
|
||
|
echo $out;
|
||
|
}
|
||
|
|
||
|
?>
|