2018-06-12 07:53:27 +02:00
|
|
|
<?PHP
|
|
|
|
/**
|
|
|
|
* This page offers the opportunity to edit static pages.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Require files and ensure environment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once __DIR__ . "/inc/functions.php";
|
|
|
|
|
|
|
|
ensureEnvironment(); // Ensure existence of system files.
|
|
|
|
$translations = loadLanguage(); // Load translations.
|
|
|
|
ensureBackendEnv(); // Ensure session is started etc.
|
2018-06-13 20:07:24 +02:00
|
|
|
$pages = loadPages(); // Load overview of pages.
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load contents
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Check for vars.
|
|
|
|
loadHttpToGlobals(["id", "task", "title", "content", "higher", "public"]);
|
|
|
|
if (isset($task) and !isset($public)) $public = false;
|
|
|
|
|
|
|
|
// Load from ID
|
|
|
|
|
|
|
|
if (isset($id) and is_numeric($id) and $id) {
|
|
|
|
|
|
|
|
$existent = json_decode(file_get_contents(__DIR__ . "/../data/static/$id.json"), true);
|
|
|
|
foreach (["title", "content", "higher", "public"] as $var) {
|
|
|
|
if (!isset($$var) and isset($existent[$var])) $$var = $existent[$var];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set page title
|
|
|
|
|
|
|
|
if (!isset($id)) $pageTitle = $translations['newPage'];
|
|
|
|
else $pageTitle = $translations['edit'] . ': ' . $title;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store if need be
|
|
|
|
*/
|
|
|
|
if (isset($task)) {
|
|
|
|
|
|
|
|
if ($task == "update") {
|
|
|
|
|
|
|
|
if (!isset($title)) $title = "";
|
|
|
|
if (!isset($content)) $content = "";
|
|
|
|
if (!isset($higher) or !is_numeric($higher)) $higher = "0";
|
|
|
|
if (!isset($id)) $id = "0";
|
|
|
|
|
|
|
|
$targetID = storePage($pages, ["title" => (string)$title, "content" => (string)$content, "higher" => $higher, "public" => (bool)$public], (int)$id);
|
|
|
|
header('Location: page.php?id=' . $targetID);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ($task == "delete") {
|
|
|
|
|
2018-06-18 10:43:22 +02:00
|
|
|
if (!isset($id)) {
|
2018-06-13 20:07:24 +02:00
|
|
|
echo printErrorPage($translations['specifyToDelete']); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unlink(__DIR__ . "/../data/static/$id.json");
|
|
|
|
generateStaticPgCaches();
|
2018-06-18 10:43:22 +02:00
|
|
|
header('Location: pages.php');
|
2018-06-13 20:07:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-12 07:53:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Output
|
|
|
|
*/
|
|
|
|
|
2018-06-13 20:07:24 +02:00
|
|
|
if (!isset($public)) $public = false;
|
|
|
|
|
|
|
|
echo printBackendHead($pageTitle, $pageTitle, $settings['logo']);
|
|
|
|
echo printBackendHeader($pageTitle, $translations['helpSinglePage']);
|
2018-06-12 07:53:27 +02:00
|
|
|
|
|
|
|
echo '
|
|
|
|
<div id="mainWrapper">
|
|
|
|
';
|
|
|
|
|
|
|
|
echo printBackendNav($translations);
|
|
|
|
|
|
|
|
echo '
|
2018-06-13 20:07:24 +02:00
|
|
|
<main class="noPadding">
|
|
|
|
<form action="" method="POST" class="withAside">
|
|
|
|
|
|
|
|
<section id="inputSection">
|
|
|
|
<input type="text" name="title" class="h1Input" placeholder="' . $translations['staticPageTitle'] . '"';
|
|
|
|
if (isset($title)) echo " value='$title'";
|
|
|
|
echo ' required />
|
|
|
|
<textarea type="text" name="content" id="pageContent" class="mceEditor" placeholder="' . $translations['staticPageTitle'] . '" required>';
|
|
|
|
if (isset($content)) echo $content;
|
|
|
|
echo '
|
|
|
|
</textarea>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<aside>
|
|
|
|
|
|
|
|
<div id="staticPageOptions">
|
|
|
|
|
|
|
|
<!-- Public or draft -->
|
|
|
|
|
|
|
|
<span class="labelLine">
|
|
|
|
<label for="public">' . $translations['staticPagePublic'] . '</label>
|
|
|
|
' . generateHelpToolTip("helpPublic", $translations['staticPagePublic'], $translations['helpStaticPagePublic']) . '
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<span>
|
|
|
|
<label class="switch">
|
|
|
|
<input name="public" id="public" type="checkbox"'; if (isset($public) and $public) echo " checked"; echo '>
|
|
|
|
<span class="slider round"></span>
|
|
|
|
</label>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<!-- Determine hierarchy -->
|
|
|
|
|
|
|
|
<span class="labelLine">
|
|
|
|
<label for="higher">' . $translations['staticPageHigher'] . '</label>
|
|
|
|
' . generateHelpToolTip("helpHigher", $translations['staticPageHigher'], $translations['helpStaticPageHigher']) . '
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<span>
|
|
|
|
<select name="higher" id="higher">
|
|
|
|
<option value="0"></option>';
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
echo '<option value="' . $page['id'] . '"';
|
|
|
|
if (isset($higher) and $page['id'] == $higher) echo " selected";
|
|
|
|
echo '>' . $page['title'] . '</option>';
|
|
|
|
}
|
|
|
|
echo '
|
|
|
|
</select>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<span>
|
|
|
|
<button type="submit">' . $translations['submit'] . '</button>
|
|
|
|
' . printHiddenInputs(["task" => "update"]) . '
|
|
|
|
</span>
|
|
|
|
|
|
|
|
</div>
|
2018-06-12 07:53:27 +02:00
|
|
|
|
2018-06-13 20:07:24 +02:00
|
|
|
<div id="pageTools">
|
2018-06-12 07:53:27 +02:00
|
|
|
|
2018-06-13 20:07:24 +02:00
|
|
|
<h3>' . $translations['tools'] . '</h3>
|
|
|
|
|
|
|
|
<div id="embedGenerator">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
';
|
|
|
|
|
|
|
|
if (isset($id)) {
|
|
|
|
echo '
|
|
|
|
<div>
|
|
|
|
<a href="../?id=' . $id . '&preview=1" class="buttonLike">' . $translations['preview'] . '</a>';
|
|
|
|
|
|
|
|
// Check if there is a page subordinate to the current one.
|
|
|
|
$hasSubordinate = false;
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
if ($page['higher'] == $id) $hasSubordinate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$hasSubordinate) echo '
|
|
|
|
<a href="page.php?id=' . $id . '&task=delete" class="buttonLike">' . $translations['delete'] . '</a>';
|
|
|
|
echo '
|
|
|
|
</div>
|
|
|
|
';
|
|
|
|
}
|
2018-06-12 07:53:27 +02:00
|
|
|
|
|
|
|
echo '
|
2018-06-13 20:07:24 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</aside>
|
|
|
|
|
|
|
|
</form>
|
2018-06-12 07:53:27 +02:00
|
|
|
</main>
|
2018-06-13 20:07:24 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<script src="./js/tinymce471/js/tinymce/tinymce.min.js"></script>
|
|
|
|
<script type="text/javascript" src="./js/runTinyMCE.js"></script>
|
|
|
|
|
|
|
|
';
|
2018-06-12 07:53:27 +02:00
|
|
|
|
|
|
|
echo printBackendEnd();
|
|
|
|
|
|
|
|
?>
|