Added editing function for pages (using tinymce).

Added editing pages for footer, banner, aside.
Added page overview.
Added public page.
Added settings page.
Added generator for embed pseudocodes.
This commit is contained in:
2018-06-13 20:07:24 +02:00
committed by Stefan Rohde-Enslin
parent 227c91963e
commit a49746ab10
114 changed files with 4422 additions and 47 deletions

View File

@ -65,4 +65,75 @@ function loadLanguage():array {
}
/**
* Function for generating caches.
*
* @return void
*/
function generateStaticPgCaches() {
// Create empty arrays
// Remove existing caches for static pages.
$targetFiles = [
"allPages" => __DIR__ . "/../../data/caches/pages.json",
"publicPages" => __DIR__ . "/../../data/caches/publicPages.json",
];
foreach ($targetFiles as $key => $file) {
$$key = [];
if (file_exists($file)) unlink($file);
}
// Read contents.
$pagesFiles = scanDirConts(__DIR__ . "/../../data/static");
foreach ($pagesFiles as $file) {
$jsonData = json_decode(file_get_contents(__DIR__ . "/../../data/static/$file"), true);
$tData = [
"id" => str_replace(".json", "", $file), //The ID equals the file name, minus the extension.
"title" => $jsonData['title'],
"higher" => $jsonData["higher"],
"public" => $jsonData["public"],
];
$allPages[$tData["id"]] = $tData;
if ($tData['public']) $publicPages[$tData["id"]] = $tData;
}
// Save to file(s)
foreach ($targetFiles as $key => $file) {
file_put_contents($file, json_encode($$key), LOCK_EX);
}
}
/**
* Function for storing a post.
*
* @param array $pages Array of pages.
* @param array $inputs Input array.
* @param integer $id ID of the currently edited entry. If it is 0, a new one will be set.
*
* @return integer
*/
function storePage(array $pages, array $inputs, int $id = 0):int {
if (!$id) {
if (count($pages) === 0) {
$id = 1;
}
else $id = max(array_keys($pages)) + 1;
}
$filename = __DIR__ . "/../../data/static/$id.json";
file_put_contents($filename, json_encode(array_merge($inputs)), LOCK_EX);
generateStaticPgCaches();
return $id;
}
?>

View File

@ -9,25 +9,36 @@
*
* @param string $page Name / ID of the current page.
* @param string $title Title of the page.
* @param string $icon The icon of the website.
*
* @return string
*/
function printBackendHead(string $page = "home", string $title = "Home"):string {
function printBackendHead(string $page = "home", string $title = "Home", string $icon = ""):string {
$output = '<!DOCTYPE html>
<html lang="en" id="' . $page . '">
<head>
<!-- Content Security policies -->
<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; script-src \'self\'; connect-src \'self\'; img-src \'self\' data: blob:; style-src \'self\' \'unsafe-inline\'; font-src \'self\';" />
<title>' . $title . '</title>
<link rel="stylesheet" type="text/css" href="themes/imports.css">
<link rel="stylesheet" type="text/css" href="themes/default/default.css">
<meta http-equiv="content-type" content="text/html;charset=utf-8">';
if ($icon) {
$output .= '
<link rel="shortcut icon" sizes="16x16 32x32" href="' . $icon . '" />
';
}
$output .= '
<meta name="robots" content="none" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript" src="./js/newToolTip.js"></script>
<script type="text/javascript" src="./js/main.js"></script>
<script type="text/javascript" src="../js/main.js"></script>
</head>
<body>
@ -59,7 +70,7 @@ function printBackendHeader(string $title = "Home", string $helpText = ""):strin
<span id="toggleNavigation"></span>
<h1>' . $title . '</h1>
<span>
<span id="toggleTextBlocks"></span>';
';
if ($helpText) $output .= '
<span class="newToolTipTag" data-for="pageHelp" id="helpText">
<span>?</span>
@ -69,6 +80,7 @@ function printBackendHeader(string $title = "Home", string $helpText = ""):strin
</span>';
$output .= '
<span id="uploadFile"></span>
<a id="logoutLink" href="./?logout"></a>
</span>
</header>
@ -100,12 +112,11 @@ function generateHelpToolTip(string $tooltipName, string $title, string $helpTex
/**
* Prints the navigation for the backend.
*
* @param string[] $translations Translation variable.
* @param integer[] $numbers Count of the given values.
* @param string[] $translations Translation variable.
*
* @return string
*/
function printBackendNav(array $translations, $numbers = []):string {
function printBackendNav(array $translations):string {
$output = '
@ -119,24 +130,41 @@ function printBackendNav(array $translations, $numbers = []):string {
<div>
<a href="pages.php">' . $translations['pages'] . '</a>
<a href="page.php"> + </a>';
if (isset($numbers['pages'])) $output .= '
<a href="users.php#listUsers">' . $numbers['pages'] . '</a>';
if (isset($GLOBALS['pages']) and is_array($GLOBALS['pages'])) $output .= '
<a href="pages.php">' . count($GLOBALS['pages']) . '</a>';
$output .= '
</div>
<div>
<a href="fileUpload.php">' . $translations['fileUpload'] . '</a>
<a href="editHTMLPage.php?id=banner">' . $translations['banner'] . '</a>
</div>
<div>
<a href="editHTMLPage.php?id=footer">' . $translations['footer'] . '</a>
</div>
<div>
<a href="editHTMLPage.php?id=aside">' . $translations['aside'] . '</a>
</div>
</div>
';
if ($_SESSION['admin']) {
$output .= '
<div>
<span>' . $translations['administration'] . '</span>
<div>
<a href="users.php#listUsers">' . $translations['users'] . '</a>
<a href="users.php#addUser"> + </a>';
if (isset($numbers['users'])) $output .= '
<a href="users.php#listUsers">' . $numbers['users'] . '</a>';
$output .= '
if (isset($GLOBALS['users']) and is_array($GLOBALS['users'])) $output .= '
<a href="users.php#listUsers">' . count($GLOBALS['users']) . '</a>';
$output .= '
</div>
<div>
<a href="settings.php">' . $translations['settings'] . '</a>
</div>
</div>
';
}
$output .= '
</nav>
';
@ -160,4 +188,5 @@ function printBackendEnd():string {
}
?>