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:
@ -7,6 +7,9 @@
|
||||
* @author Joshua Ramon Enslin <joshua@jrenslin.de>
|
||||
*/
|
||||
|
||||
require __DIR__ . "/standardHTML.php";
|
||||
require __DIR__ . "/mdEmbeds.php";
|
||||
|
||||
/**
|
||||
* Function ensureDir checks if a directory exists, and creates it if it does not yet.
|
||||
*
|
||||
@ -47,7 +50,7 @@ function ensureEnvironment() {
|
||||
|
||||
// Ensure existence of directories
|
||||
|
||||
foreach ([__DIR__ . "/../data", __DIR__ . "/../data/static", __DIR__ . "/../data/caches", __DIR__ . "/../js"] as $folder) {
|
||||
foreach ([__DIR__ . "/../files", __DIR__ . "/../data", __DIR__ . "/../data/static", __DIR__ . "/../data/caches", __DIR__ . "/../js"] as $folder) {
|
||||
ensureDir($folder);
|
||||
}
|
||||
|
||||
@ -56,11 +59,54 @@ function ensureEnvironment() {
|
||||
foreach ([
|
||||
__DIR__ . "/../data/settings.json",
|
||||
__DIR__ . "/../data/caches/pages.json",
|
||||
__DIR__ . "/../data/caches/publicPages.json",
|
||||
__DIR__ . "/../data/users.json",
|
||||
] as $jsonFile) {
|
||||
ensureJson($jsonFile);
|
||||
}
|
||||
|
||||
// Load settings
|
||||
|
||||
$settings = array_merge(
|
||||
[
|
||||
"startPage" => "1",
|
||||
"pageTitle" => "md:cms",
|
||||
"logo" => "",
|
||||
"url" => "",
|
||||
"mdVersion" => "https://www.museum-digital.de/nat/",
|
||||
"maxFileSize" => 300000,
|
||||
"defaultLang" => "en"
|
||||
],
|
||||
json_decode(file_get_contents(__DIR__ . "/../data/settings.json"), true)
|
||||
);
|
||||
|
||||
$GLOBALS['settings'] = $settings;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for loading contents from cache.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function loadPages() {
|
||||
|
||||
$pages = json_decode(file_get_contents(__DIR__ . "/../data/caches/pages.json"), true);
|
||||
return $pages;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for loading contents from cache.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function loadPublicPages() {
|
||||
|
||||
$pages = json_decode(file_get_contents(__DIR__ . "/../data/caches/publicPages.json"), true);
|
||||
return $pages;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,6 +262,62 @@ function write_common_vars(array $input):string {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for e.g. printing the navigation.
|
||||
*
|
||||
* @param array $pages Array of all pages to list.
|
||||
* @param function $start Function to run on the called pages in case a new level is entered.
|
||||
* @param function $end Function to run on the called pages in case a new level is entered.
|
||||
* @param function $callbackSameLevel Function to run on the called pages of the current level.
|
||||
* @param integer $higher Run the callback function on those entries where higher equals the given.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function buildPageOrder(
|
||||
array $pages,
|
||||
$start,
|
||||
$end,
|
||||
$callbackSameLevel,
|
||||
int $higher = 0
|
||||
):string {
|
||||
|
||||
$output = "";
|
||||
|
||||
$thisLevel = [];
|
||||
foreach ($pages as $page) {
|
||||
if ($page["higher"] != $higher) continue;
|
||||
|
||||
$output .= $callbackSameLevel($page, buildPageOrder($pages, $start, $end, $callbackSameLevel, $page["id"]));
|
||||
|
||||
}
|
||||
|
||||
if ($output) $output = $start() . $output . $end();
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for checking access to previews.
|
||||
*
|
||||
* @param bool $sessionStarted Optional parameter depending on the status of the session.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function checkPreviewAccess($sessionStarted = false) {
|
||||
|
||||
if (!$sessionStarted) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if (isset($_SESSION['username'])) $output = true;
|
||||
else $output = false;
|
||||
|
||||
if (!$sessionStarted) {
|
||||
session_abort();
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
43
inc/mdEmbeds.php
Normal file
43
inc/mdEmbeds.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?PHP
|
||||
/**
|
||||
* For embedding from museum-digital functions.
|
||||
*
|
||||
* @file
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@jrenslin.de>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function for checking a text for the existence of pseudocode
|
||||
* for embedding from museum-digital.
|
||||
*
|
||||
* @param string $text Input string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function checkForEmbeds(string $text):string {
|
||||
|
||||
$embedOptions = [
|
||||
"eventCalendar"
|
||||
];
|
||||
|
||||
foreach ($embedOptions as $option) {
|
||||
|
||||
if (strpos($text, $option) === false) continue;
|
||||
$position = strpos($text, $option) - 1;
|
||||
|
||||
$nextTag = strpos($text, "<", $position);
|
||||
$nextWhitespace = strpos($text, " ", $position);
|
||||
|
||||
$end = min($nextTag, $nextWhitespace, strlen($text));
|
||||
|
||||
$pseudocode = substr($text, $position, $position + $end);
|
||||
echo $pseudocode;
|
||||
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
}
|
||||
|
||||
?>
|
154
inc/standardHTML.php
Normal file
154
inc/standardHTML.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?PHP
|
||||
/**
|
||||
* File for collecting functions building common HTML parts of the public page
|
||||
*
|
||||
* @file
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@jrenslin.de>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prints the head element of an HTML page in the public frontend.
|
||||
*
|
||||
* @param string $page ID of the current page.
|
||||
* @param string $title Title of the page.
|
||||
* @param string $icon The icon of the website.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function printPublicHead(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\'; style-src \'self\' \'unsafe-inline\'; font-src \'self\';" />
|
||||
|
||||
<title>' . $title . '</title>
|
||||
<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="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<script type="text/javascript" src="./js/main.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
';
|
||||
|
||||
if (isset($_SESSION['editHistory'])) {
|
||||
$output .= "<p class='editLine ".$_SESSION['editHistory'][0]."'>".$_SESSION['editHistory'][1]."</p>";
|
||||
unset($_SESSION['editHistory']);
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the header element of an HTML page.
|
||||
*
|
||||
* @param string $title Title of the page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function printPublicHeader(string $title = "Home"):string {
|
||||
|
||||
$output = '
|
||||
|
||||
<header id="mainHeader">
|
||||
|
||||
<h1>' . $title . '</h1>
|
||||
|
||||
</header>
|
||||
';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the finishing elements of public HTML pages.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function printPublicEnd():string {
|
||||
|
||||
$output = '
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function prints a file (the sidebar, the banner, or the footer) if it is not empty.
|
||||
*
|
||||
* @param string $file File name. Must be either aside, banner or footer.
|
||||
* @param string $elem Encapsulating HTML element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function printStaticPagePart(string $file, string $elem):string {
|
||||
|
||||
if (!in_array($file, ['footer', 'aside', 'banner'])) {
|
||||
echo "Trying to access disallowed file.";
|
||||
}
|
||||
|
||||
if (!file_exists(__DIR__ . "/../data/$file.htm") || !filesize(__DIR__ . "/../data/$file.htm") > 5) return "";
|
||||
$content = file_get_contents(__DIR__ . "/../data/$file.htm");
|
||||
|
||||
$output = "
|
||||
<$elem>
|
||||
$content
|
||||
</$elem>";
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function prints an error page.
|
||||
*
|
||||
* @param string $content The error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function printErrorPage(string $content):string {
|
||||
|
||||
$output = '
|
||||
<!DOCTYPE html>
|
||||
<html id="errorPage">
|
||||
<head>
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; script-src \'none\'; connect-src \'none\'; style-src \'self\'; font-src \'self\';" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
||||
<meta charset="UTF-8" />
|
||||
<title>' . $content . '</title>
|
||||
<link rel="stylesheet" type="text/css" href="themes/default/default.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div>
|
||||
' . $content . '
|
||||
<div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user