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;
}
?>