StaticMD/manager.php

92 lines
2.6 KiB
PHP
Raw Normal View History

2017-07-16 20:10:52 +00:00
<?php
require_once('Parsedown.php');
2017-07-16 23:13:10 +00:00
if(file_exists('config.php')) {
require_once('config.php');
} else {
require_once('config.example.php');
}
2017-07-16 20:10:52 +00:00
$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);
2017-07-16 23:13:10 +00:00
$outfile = !empty($_POST['outfile'])?$_POST['outfile']:DEFAULT_FILE;
file_put_contents($outfile, $out);
2017-07-16 20:10:52 +00:00
}
function showAdminPage() {
outputHTMLHeader();
2017-07-16 23:13:10 +00:00
$out = '<form action="/manager.php?f=build" method="POST">'."\n"
.' <div>'."\n"
.' <label for="filename">Output File:</label>'."\n"
.' <input name="filename" value="worship.html" placeholder="File Name" />'."\n"
.' </div>'."\n"
.' <div>'."\n"
.' <label for="filter">Filter</label>'."\n"
.' <input name="filter" value="" placeholder="Filter Files" />'."\n"
.' <table>'."\n"
.' <thead><th>File</th><th></th></thead>'."\n"
.' <tbody>'."\n";
2017-07-16 20:10:52 +00:00
foreach(glob(MD_DIR.'/*.md') as $file) {
2017-07-16 23:13:10 +00:00
$out.=' <tr>'."\n"
.' <td>'.basename($file, '.md').'</td><td><button onclick="addSong('.$filename.');">Add</button></td>'."\n"
.' </tr>'."\n";
2017-07-16 20:10:52 +00:00
}
2017-07-16 23:13:10 +00:00
$out.= ' </tbody>'."\n"
.' </table>'."\n"
.' </div>'."\n"
.' <button type="submit">Build</button>'."\n"
.'</form>'."\n"
.'<script>'."\n"
.'</script>'."\n";
2017-07-16 20:10:52 +00:00
outputHTMLFooter();
}
function outputHTMLHeader($title = TITLE, $ret = false) {
$out = '<!DOCTYPE html>'."\n"
.'<html lang="en">'."\n"
.' <head>'."\n"
.' <title>'.$title.'</title>'."\n"
2017-07-16 23:13:10 +00:00
.' <link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">'."\n"
2017-07-16 20:10:52 +00:00
.' </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;
}
?>