hisma/index.php

89 lines
2.9 KiB
PHP

<?php
session_start();
require 'vendor/autoload.php';
require 'apps/apps.php';
$menu = $body = $toc = '';
/*if(testConfig() === false){
$body = '
<form method="post">
<label>Define your password</label>
<input type="password" name="FormPassword"/>
</form>';
}*/
if (!empty($_POST['FormPassword'])) {
require 'config/config.php';
$FormPassword = htmlspecialchars($_POST['FormPassword']);
if (password_verify($FormPassword, $passProtect)) {
$_SESSION['login'] = true;
} else {
$_SESSION['login'] = false;
}
}
if (empty($_SESSION['login']) or $_SESSION['login'] !== true) {
$body = '
<form method="post">
<label>Password</label>
<input type="password" name="FormPassword"/>
</form>';
} else {
$dir = $_GET['dir'] ?? '';
$file = $_GET['file'] ?? '';
$body = '';
if (!empty($dir)) {
$dir = filter_input(INPUT_GET, 'dir', FILTER_SANITIZE_STRING);
}
if (isset($file)) {
$file = filter_input(INPUT_GET, 'file', FILTER_SANITIZE_STRING);
}
if (empty($file) || !file_exists('./content/' . urldecode($dir) . '/' . urldecode($file) . '.md')) {
$dir = '';
if (file_exists('./content/index.md')) {
$file = 'index';
} else {
$file = 'default';
}
}
/*
sed -E 's/[0-9]{2}:[0-9]{2}//' new.md > test.md
sed '/^$/d' test.md > new.md
*/
$content = file_get_contents('content/' . urldecode($dir) . '/' . urldecode($file) . '.md');
$options = array('selectors' => array('h2', 'h3'), 'setBreaksEnabled' => true, 'setSafeMode' => true);
$content = preg_replace('/([0-9]{2}):([0-9]{2})/i', '', $content);
$content = preg_replace('/\[([0-9]{2})\/([0-9]{2})\/([0-9]{4}) ]/i', '', $content);
$content = preg_replace('/\[([0-9]{2})\/([0-9]{2}) ]/i', '', $content);
$content = str_replace('Morgane Mongin', '</p><p class="m">', $content);
$content = str_replace('Adrien Passos', '</p><p class="a">', $content);
$content = str_replace('morganemongin', '</p><p class="m">', $content);
$content = str_replace('knah-tsaeb', '</p><p class="a">', $content);
$Parsedown = new ExtendParsedownToc($options);
$body = $Parsedown->setMarkupEscaped(false)
->setSafeMode(false)
->setBreaksEnabled(false)
->text($content);
$toc = $Parsedown->contentsList();
#$body = str_replace("[ ]", '<input type="checkbox" disabled>', $body);
#$body = str_replace("[x]", '<input type="checkbox" checked disabled>', $body);
$body = str_replace("</h2>", ' <a href="#" class="backTop">⬆️</a></h2>', $body);
$body = str_replace("</h3>", ' <a href="#" class="backTop">⬆️</a></h3>', $body);
$menu = makeMenu($dir);
$lastMod = date("d-m-Y H:i", filemtime('content/' . urldecode($dir) . '/' . urldecode($file) . '.md'));
}
require 'tpl/header.html';
require 'tpl/aside.html';
require 'tpl/main.html';
require 'tpl/footer.html';