-
Notifications
You must be signed in to change notification settings - Fork 2
/
managepages.php
115 lines (101 loc) · 3.56 KB
/
managepages.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
// Initialise session
session_start();
define('APP_RAN', '');
require_once('config.php');
$root = dirname(__FILE__);
$auth = file_get_contents($root . '/session.php');
if (!isset($_SESSION['hauth']) || $_SESSION['hauth'] != $auth) {
header("location: " . BASE_URL );
exit;
}
$target_dir = $root.'/pages/';
if (isset($_POST['title'])) {
$title = $_POST['title'];
$name = $_POST['name'];
$title = strtolower(str_replace(' ', '_', $title));
$name = strtolower(str_replace(' ', '_', $name));
if ($title !== $name) {
$name = strtolower(str_replace(' ', '_', $name));
$old_file = $target_dir.$name.'.md';
unlink($old_file);
}
$content = $_POST['content'];
$file = $target_dir.$title.'.md';
file_put_contents($file, $content);
if ($name == NOWNS) {
include('rss.php');
}
header("location: " . BASE_URL . '/managepages.php' );
exit;
}
?>
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Manage pages</title>
<meta name="description" content="<?php echo DESCRIPTION; ?>">
<link rel="icon" type="image/png" href="<?php echo AVATAR; ?>">
<link rel="stylesheet" href="<?php echo BASE_URL; ?>style_min.css" type="text/css" media="all">
<script src="htmx.min.js"></script>
</head>
<body>
<div id="wrapper" style="width: 100vw; position: absolute; left: 0px;">
<div id="page" class="hfeed h-feed site">
<header id="masthead" class="site-header">
<div class="site-branding">
<h1 class="site-title">
<a href="<?php echo BASE_URL; ?>" rel="home">
<span class="p-name">Manage pages</span>
</a>
</h1>
</div>
</header>
<div id="primary" class="content-area">
<main id="main" class="site-main today-container">
<div class="page-content">
<br>
<div style="margin-bottom: 50px;">
<a style="float:left;" href="addpage.php"><b>Add a page</b></a>
<a style="float:right;" href="admin/"><b>Admin</b></a>
</div>
<div style="clear: both;"></div>
<?php
if (isset($_GET['p'])) {
$page = $_GET['p'];
$title = ucfirst(str_replace('_', ' ', $page));
$file = $target_dir.$page.'.md';
$content = file_get_contents($file);
?>
<form name="form" method="post" action="managepages.php">
<input type="hidden" name="updatepage" value="updatepage">
<input type="hidden" name="name" value="<?php echo $title; ?>">
<input type="text" name="title" class="form-control" value="<?php echo $title; ?>" required>
<textarea name="content" rows="10" class="form-control" style="height: 300px; font-family: sans-serif" required><?php echo $content; ?></textarea>
<div style="width: 93%; margin: 0px auto;">
<input type="submit" style ="float: right;" value="Update page" />
</div>
</form>
<?php
} else {
if (!empty(glob($target_dir.'*.md'))) {
echo '<h2>Edit or delete pages</h2>';
echo '<br><p>';
foreach(glob($target_dir.'*.md') as $file) {
$pagename = pathinfo($file, PATHINFO_FILENAME);
$title = str_replace('_', ' ', $pagename);
echo '<li style="float: left;"><a href="managepages.php?p='.$pagename.'"><b>'.ucfirst($title).'</b></a></li><img hx-target="body" hx-get="delpage.php?p='.$pagename.'" hx-confirm="Are you sure?" title="Delete page" src="../images/red-cross.png" style="width: 16px; float: right; cursor: pointer;"><br><br>';
}
echo '</p>';
}
}
?>
</div>
</main>
</div>
<?php
$pageDesktop = "157";
$pageMobile = "207";
include('footer.php');
?>