1
0
Fork 0
chickadee/admin.php

186 lines
6.1 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";
?>
<!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}
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: ' | '}
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;border-radius: 4px;padding: 0.5em 0.5em 0}
summary {font-weight: bold;margin: -0.5em -0.5em 0;padding: 0.5em}
details[open]{padding-bottom:1em}
details[open] summary {border-bottom: 1px solid #aaa;margin-bottom: 0.5em;background:#333;color:#DDD}
thead{background: #333;color:#EEE}
</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="/logout.php" 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>File 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 (&gt; 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; ?>
<details>
<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 (markdown):<br><textarea name="post_body" required></textarea></label>
</p>
<input type="submit" value="Submit">
</form>
</details>
<hr class="small-divider">
<details class="post-list">
<summary>Posts</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 );
$del = $parts["raw"];
$out = <<<HTML
<tr>
<td>$link</td>
<td>{$parts["time"]}</td>
<td>
<ul class="inline list-style-none pipe">
<li><a href="edit.php?file=posts%2F$del">Edit</a></li>
<li><a href="delete_data.php?f=$del&k=posts">Delete</a></li>
</ul>
</td>
</tr>
HTML;
echo $out;
}
?>
</tbody>
</table>
</details>
<hr class="small-divider">
<details>
<summary>Site Actions</summary>
<ul>
<li><a href="edit.php?file=css%2Fstyle.css">Edit CSS</a></li>
</ul>
</details>
<hr class="small-divider">
<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>
<hr class="small-divider">
<details class="media-list">
<summary>Media Files</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>
<a href="delete_data.php?f=$f&k=media">Delete</a>
</td>
</tr>
HTML;
echo $out;
}
?>
</tbody>
</table>
</details>
</main>
</body>
</html>