1
0
Fork 0
chickadee/edit.php

151 lines
4.7 KiB
PHP

<?php
include_once "logcheck.php";
include_once "config.php";
include_once "common.php";
$update = $_POST["data"] ?? null;
$f = $_POST["file"] ?? null;
$title = "";
$css = false;
if ( $update && $f ) {
$success = file_put_contents( $f, $update );
if ( $success ) {
header("Location: admin.php?success=2");
die();
} else {
header("Location: admin.php?success=0");
die();
}
}
if ( !$f ) {
$f = $_GET["file"] ?? null;
}
if ( $f ) {
// Set up update
if ( $f == "css/style.css" ) {
$title = "CSS";
} else {
$fn = split_filename( $f );
$title = $fn["title"];
}
$update = file_get_contents( $f );
if ( !$update ) {
header("Location: admin.php?success=0");
die();
}
} else {
header("Location: admin.php?success=0");
die();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Administration - Edit</title>
<meta charset="utf-8">
<style>
header, main{width:90%;max-width:900px;margin:2em auto}
hr.small-divider{width:25%;margin: 2em auto}
textarea{width:100%;height:50vh}
input[type=text]{width:100%}
table{width:100%}
.error{background:darkred;color:pink}
ul.inline li{display:inline-block; margin:0}
ul.inline 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}
header ul.inline li::after{content:'' !important}
.post-list tbody tr:nth-child(odd){background-color: #DDD}
td{padding-left:1em}
details {border: 1px solid #aaa;padding: 0.5em 0.5em 0;margin-top:3em}
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: #333;color:#EEE}
pre{background:#333;color:white;padding:1em;width:calc(90% - 2em);margin:1em auto;border-radius:5px}
</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">Log Out</a></li>
</ul>
</header>
<main>
<form action="edit.php" method="post">
<h2>Editing - <?php echo $title; ?></h2>
<p>
<label><br><textarea name="data" required><?php echo $update ?: "" ;?></textarea></label>
</p>
<input type="hidden" name="file" value="<?php echo $f; ?>">
<input type="submit" value="Submit">
</form>
<?php if ( $f == "css/style.css" && SIMPLE_CSS ): ?>
<details>
<summary>Guide to simple.css variables</summary>
<p>The following are the default variable values for the active <i>simple.css</i> css theming. You can override any of them you like.</p>
<p>For example, to override the border color for both the light and dark modes you could do something like the following:</p>
<pre><code>:root, ::backdrop {
--border: darkred;
}
@media (prefers-color-scheme: dark) {
:root, ::backdrop {
--border: red;
}
}</code></pre>
<p>That would change the color everywhere on your site. You can override any other css (things not set by variables) by just writing your own css that overrides the things you want to change.</p>
<h2>Default Value Guide</h2>
<pre><code>:root,
::backdrop {
/* Set sans-serif &amp; mono fonts */
--sans-font: -apple-system, BlinkMacSystemFont, "Avenir Next", Avenir,
"Nimbus Sans L", Roboto, "Noto Sans", "Segoe UI", Arial, Helvetica,
"Helvetica Neue", sans-serif;
--mono-font: Consolas, Menlo, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
--standard-border-radius: 5px;
/* Default (light) theme */
--bg: #fff;
--accent-bg: #f5f7ff;
--text: #212121;
--text-light: #585858;
--border: #898EA4;
--accent: #0d47a1;
--accent-text: var(--bg);
--code: #d81b60;
--preformatted: #444;
--marked: #ffdd33;
--disabled: #efefef;
}
/* Dark theme */
@media (prefers-color-scheme: dark) {
:root,
::backdrop {
color-scheme: dark;
--bg: #212121;
--accent-bg: #2b2b2b;
--text: #dcdcdc;
--text-light: #ababab;
--accent: #ffb300;
--accent-text: var(--bg);
--code: #f06292;
--preformatted: #ccc;
--disabled: #111;
}
}</code></pre>
</details>
<?php endif; ?>
</main>
</body>
</html>