168 lines
6.2 KiB
PHP
168 lines
6.2 KiB
PHP
<?php
|
|
require "../include/variables.php";
|
|
require "../include/functions.php";
|
|
|
|
if($_SESSION['role'] < 2) {
|
|
header("Location: index.php");
|
|
http_response_code(404);
|
|
die();
|
|
}
|
|
|
|
$filetypes = [
|
|
0 => "article",
|
|
1 => "page"
|
|
];
|
|
|
|
if(isset($_GET['article']) && filter_var($_GET['article'], FILTER_VALIDATE_INT)) {
|
|
if(file_exists($wwwroot . "/content/journal/" . $_GET['article'] . ".md")){
|
|
$fichier = $wwwroot . "/content/journal/" . $_GET['article'] . ".md";
|
|
$filename = $_GET['article'];
|
|
$filetype = 0;
|
|
}
|
|
}
|
|
|
|
if(isset($_GET['page']) && strpos($_GET['page'], "..") == false) {
|
|
if(file_exists($wwwroot . "/content/" . $_GET['page'] . ".md")){
|
|
$fichier = $wwwroot . "/content/" . $_GET['page'] . ".md";
|
|
$filename = $_GET['page'];
|
|
$filetype = 1;
|
|
}
|
|
}
|
|
|
|
$filename = isset($filename) ? $filename : "";
|
|
|
|
if(isset($fichier)) {
|
|
if(isset($_GET['article']) && isset($_POST['deletefile']) && $_POST['deletefile'] == "Supprimer") {
|
|
if(unlink($fichier)) {
|
|
$bdd = connect($dbhost, $dbname, $dbuser, $dbpass);
|
|
$upload = $bdd->prepare("DELETE FROM articles WHERE ID = :filename");
|
|
$upload->bindParam(':filename', $filename);
|
|
if($upload->execute()) {
|
|
header("Location: editpage.php");
|
|
echo "Fichier supprimé";
|
|
exit();
|
|
} else {
|
|
die("Erreur SQL");
|
|
}
|
|
} else {
|
|
die("Erreur : Le fichier n'a pas pu être supprimé");
|
|
}
|
|
}
|
|
if(isset($_POST['page-content'])) {
|
|
file_put_contents($fichier, nl2br($_POST['page-content']));
|
|
}
|
|
$contenu = file_get_contents($fichier);
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="stylesheet" href="./src/css/style.css">
|
|
<style>
|
|
@media (prefers-color-scheme: dark) {
|
|
.body {
|
|
<?=$theme_dark?>
|
|
}
|
|
}
|
|
@media (prefers-color-scheme: light) {
|
|
.body {
|
|
<?=$theme_light?>
|
|
}
|
|
}
|
|
</style>
|
|
<link rel="icon" href="./src/img/favicon.ico">
|
|
<title><?=$title?></title>
|
|
<style>
|
|
textarea {
|
|
width: 100%;
|
|
min-height: 50em;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="body">
|
|
<header>
|
|
<div class="pancontent">
|
|
<div class="athena-container">
|
|
<a href="<?=$root?>">
|
|
<img src="./src/img/athena-mono.png" class="athena">
|
|
</a>
|
|
</div>
|
|
<div class="content">
|
|
<div>
|
|
<div class="main-title">
|
|
<div class="title"><?=$header_title?></div>
|
|
<div class="subtitle"><?=$header_subtitle?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<nav>
|
|
<div class="pancontent">
|
|
<?php nav($nav);?>
|
|
</div>
|
|
</nav>
|
|
<main>
|
|
<div class="content">
|
|
<div>
|
|
<div>
|
|
<?php
|
|
if(isset($contenu)) {
|
|
echo '<form action="?' . $filetypes[$filetype] . '=' . $filename . '" method="post">';
|
|
echo "<div><div class='button'><a href='editpage.php'>Retour</a></div>";
|
|
echo "<div><div class='button'><a href='news.php?article=" . $filename . "'>Voir l'article</a></div>";
|
|
echo "<div><h1>" . $filename . "</h1></div>";
|
|
echo '<div><textarea name="page-content">' . $texte = str_replace("<br />", "", $contenu) . '</textarea></div>';
|
|
echo '<div><input type="submit" value="Publier"></div></form>';
|
|
} else {
|
|
echo "<div><div><h2>Pages</h2></div>";
|
|
echo "<div>";
|
|
$pages = scandir($wwwroot . "/content/");
|
|
foreach($pages as $page) {
|
|
if($page != "." && $page != "..") {
|
|
if (is_file($wwwroot . "/content/" . $page)) {
|
|
echo "<a href='?page=" . pathinfo($page, PATHINFO_FILENAME) . "'><div class='button'>" . pathinfo($page, PATHINFO_FILENAME) . "</div></a>";
|
|
}
|
|
}
|
|
}
|
|
echo "</div></div><div>";
|
|
echo "<div><h2>Articles</h2></div>";
|
|
$bdd = connect($dbhost, $dbname, $dbuser, $dbpass);
|
|
$req = $bdd->prepare("SELECT ID, titre, date FROM articles WHERE classification <= :accreditation ORDER BY date DESC LIMIT 10");
|
|
$req->bindParam(":accreditation", $_SESSION['accreditation']);
|
|
$req->execute();
|
|
$resultat = $req->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($resultat) {
|
|
foreach($resultat as $row) {
|
|
$date = strtotime($row['date']);
|
|
echo "<div class='article-preview'><hr>";
|
|
echo "<a href='?article=" . $row['ID'] . "' class='article-link'>";
|
|
echo "<div class='article-titre'>" . $row['titre'] . "</div></a>";
|
|
echo "<div class='article-date'>" . date('d/m/Y', $date) . "</div></div>";
|
|
}
|
|
}
|
|
echo "</div>";
|
|
}
|
|
?>
|
|
</div>
|
|
<?php
|
|
if(isset($contenu)) {
|
|
echo '<form action=?article=' . $filename . ' method="post"><div><input type="submit" name="deletefile" value="Supprimer"></div></form>';
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
<footer>
|
|
<div class="content">
|
|
<div>
|
|
<div><?=$copyright?></div>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|