216 lines
8.0 KiB
PHP
216 lines
8.0 KiB
PHP
<?php
|
|
include_once "logcheck.php";
|
|
$post_success = $_GET["success"] ?? null;
|
|
|
|
// Get the file list
|
|
$files = array_values( array_diff( scandir( "./posts" ), array('..', '.')));
|
|
rsort( $files );
|
|
$media_files = array_values ( array_diff( scandir( "./media" ), ["..", "."] ) );
|
|
sort( $media_files );
|
|
include_once "common.php";
|
|
include_once "config.php";
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Administration</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<style>
|
|
header, main{width:90%;max-width:900px;margin:2em auto}
|
|
hr.small-divider{width:25%;margin: 2em auto}
|
|
textarea{width:calc(100% - 1em);height:50vh;min-height:200px}
|
|
input[type=text]{width:calc(100% - 1em)}
|
|
table{width:calc(100% - 1em)}
|
|
.error{background:darkred;color:pink}
|
|
ul.inline li{display:inline-block; margin:0}
|
|
ul.inline.pipe li:not(:last-child)::after{content:'';margin-right:0.5em}
|
|
ul.list-style-none{list-style:none;margin:0;padding:0}
|
|
header ul.inline{position:absolute;top:0;right:2em;margin:0}
|
|
header ul.inline li{background:#333;color:#DDD;border-radius:0 0 10px 10px;padding:0.5em;margin:0 5px}
|
|
header ul.inline li a{color:#DDD;text-decoration:none}
|
|
tbody tr:nth-child(odd){background-color: #DDD}
|
|
td{padding-left:1em}
|
|
details {border: 1px solid #aaa;padding: 0.5em 0.5em 0}
|
|
summary {font-weight: bold;margin: -0.5em -0.5em 0;padding: 0.5em}
|
|
details[open]{padding-bottom:1em;background:#F7F7F7}
|
|
details[open] summary {border-bottom: 1px solid #aaa;margin-bottom: 0.5em;background:#333;color:#DDD}
|
|
thead{background: #555;color:#EEE}
|
|
fieldset{display: inline;padding: 0 2px 0 0;margin: 0 5px 0 0;border: none;vertical-align: middle}
|
|
legend{float: left;border: none;padding-inline: 0 2px}
|
|
ul:not(.inline) li {margin-bottom:0.5em;padding-left:0;margin-left:0}
|
|
.center{text-align:center;padding-left:0}
|
|
input[type="submit"] {
|
|
background-color: #333;
|
|
padding: 5px 10px;
|
|
border-radius: 5px;
|
|
box-shadow: none;
|
|
font-weight: bold;
|
|
letter-spacing: 0.5px;
|
|
color: #EEE;
|
|
}
|
|
:any-link[target]::after{content:' \2197'}
|
|
:any-link{color:blue}
|
|
.action{text-decoration:none;font-size:1.25em}
|
|
details.post-list[open]{max-height:50vh;overflow-y:scroll}
|
|
details span.counter{float:right;margin-right:1em;padding:0 1em;border-radius:15px;background-color:#EEE;color:#333;border:1px solid #333}
|
|
@media only screen and (min-width: 800px) {
|
|
.container {
|
|
column-count: 2;
|
|
}
|
|
details {
|
|
break-inside: avoid-column;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="admin">
|
|
<header>
|
|
<h1>Website Admin</h1>
|
|
<ul class="inline">
|
|
<li><a href="/">View Site</a></li>
|
|
<li><a href="admin.php">Admin Home</a></li>
|
|
<li><a href="admin.php?logout=1" class="logout">Log Out</a></li>
|
|
</ul>
|
|
</header>
|
|
<main>
|
|
<?php if ( $post_success === "0" ): ?>
|
|
<div class="error">
|
|
<h2>Error</h2>
|
|
<p>There was a server error preventing your update from succeeding. Please check with your server admin to resolve the issue.</p>
|
|
</div>
|
|
<?php elseif ( $post_success === "1" ): ?>
|
|
<p><a href="post.php?f=<?php echo $files[0]; ?>">New post</a> successfully added!</p>
|
|
<?php elseif ( $post_success === "2" ): ?>
|
|
<p>Updated successfully!</p>
|
|
<?php elseif ( $post_success === "3" ): ?>
|
|
<p>Media uploaded successfully!</p>
|
|
<?php elseif ( $post_success === "4" ): ?>
|
|
<div class="error">
|
|
<h2>Error</h2>
|
|
<p>Your media upload was too large (> 1.5mb)</p>
|
|
</div>
|
|
<?php elseif ( $post_success === "5" ): ?>
|
|
<div class="error">
|
|
<h2>Error</h2>
|
|
<p>
|
|
Your media upload was <em>not</em> a supported file type:
|
|
<ul>
|
|
<li>azw3</li>
|
|
<li>css</li>
|
|
<li>epub</li>
|
|
<li>gif</li>
|
|
<li>html</li>
|
|
<li>jpeg</li>
|
|
<li>jpg</li>
|
|
<li>mobi</li>
|
|
<li>pdf</li>
|
|
<li>png</li>
|
|
<li>svg</li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
<?php elseif ( $post_success === "6" ): ?>
|
|
<p>Deletion was successful!</p>
|
|
<?php endif; ?>
|
|
<div class="container">
|
|
<details open>
|
|
<summary>New Post</summary>
|
|
<form action="new-post.php" method="post">
|
|
<h2>New Post</h2>
|
|
<p>
|
|
<label>Title: <input type="text" name="post_title"></label>
|
|
</p>
|
|
<p>
|
|
<label>Post (<a href="https://www.markdownguide.org/basic-syntax/" target="_blank">markdown</a>):<br><textarea name="post_body" required></textarea></label>
|
|
</p>
|
|
<input type="submit" value="Submit">
|
|
</form>
|
|
</details>
|
|
<details class="post-list" open>
|
|
<summary>Posts <span class="counter"><?php echo count( $files ); ?></span></summary>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Post Title</th>
|
|
<th>Post Date</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
foreach( $files as $f ) {
|
|
$parts = split_filename( $f );
|
|
$link = make_post_link( $f );
|
|
$f = $parts["raw"];
|
|
$out = <<<HTML
|
|
<tr>
|
|
<td>$link</td>
|
|
<td>{$parts["time"]}</td>
|
|
<td class="center">
|
|
<ul class="inline list-style-none pipe">
|
|
<li><a href="edit.php?file=posts%2F$f" aria-label="edit" class="action" title="Edit">✏️</a></li>
|
|
<li><a href="delete_data.php?f=$f&k=posts" aria-label="delete" class="action" title="Delete">❌</a></li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
HTML;
|
|
echo $out;
|
|
}
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
</details>
|
|
<details>
|
|
<summary>Site Actions</summary>
|
|
<ul>
|
|
<li><a href="edit.php?file=css%2Fstyle.css">Edit CSS</a></li>
|
|
<li>
|
|
<form action="site_actions.php" method="post">
|
|
<fieldset><legend>Use <i>simple.css</i></legend>
|
|
<label><input type="radio" name="simplecss" value="1"<?php echo SIMPLE_CSS ? " checked" : "";?>> Yes</label>
|
|
<label><input type="radio" name="simplecss" value="0"<?php echo SIMPLE_CSS ? "" : " checked";?>> No</label></fieldset><input type="submit" value="update"></form></li>
|
|
</ul>
|
|
</details>
|
|
<details>
|
|
<summary>Upload Media</summary>
|
|
<form action="upload.php" method="post" enctype="multipart/form-data">
|
|
<h2>New Media</h2>
|
|
<p>
|
|
<label>File: <input type="file" name="mediaUpload"></label>
|
|
</p>
|
|
<input type="submit" value="Submit">
|
|
</form>
|
|
</details>
|
|
<details class="media-list">
|
|
<summary>Media Files <span class="counter"><?php echo count( $media_files ); ?></span></summary>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>File</th>
|
|
<th>Delete</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
foreach( $media_files as $f ) {
|
|
$link = make_post_link( $f, false );
|
|
$out = <<<HTML
|
|
<tr>
|
|
<td>$link</td>
|
|
<td class="center">
|
|
<a href="delete_data.php?f=$f&k=media" aria-label="delete" class="action" title="Delete">❌</a>
|
|
</td>
|
|
</tr>
|
|
HTML;
|
|
echo $out;
|
|
}
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
</details>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
</html>
|