Readied error pages for variable themes.

Fixed error in parsing pseudocode.
This commit is contained in:
Joshua Ramon Enslin 2018-06-21 13:25:38 +02:00 committed by Stefan Rohde-Enslin
parent b340c7efff
commit 4e06d0bae7
18 changed files with 84 additions and 81 deletions

View File

@ -13,12 +13,12 @@ require_once __DIR__ . "/inc/functions.php";
// Check validity of request.
if (!isset($_GET['args']) || !isset($_GET['area'])) {
echo printErrorPage("File does not exist.");
echo printErrorPage($settings, "File does not exist.");
return;
}
if (!in_array($_GET['area'], ['events', 'exhibitions'])) {
echo printErrorPage("Using a disallowed value for area.");
echo printErrorPage($settings, "Using a disallowed value for area.");
return;
}

View File

@ -13,7 +13,7 @@ require_once __DIR__ . "/inc/functions.php";
// Check validity of request.
if (!isset($_GET['id']) or !is_numeric($_GET['id'])) {
echo printErrorPage("Collection does not exist.");
echo printErrorPage($settings, "Collection does not exist.");
return;
}
@ -27,12 +27,12 @@ $pages = loadPublicPages(); // Load overview of pages.
$contents = json_decode(queryCachePage($settings['mdVersion'] . "?t=sammlung&gesusa=" . urlencode($_GET['id']) . "&output=json", "institution", $settings), true);
if (!$contents || (isset($contents[0]) and $contents[0] == "There is no collection with this ID yet.")) {
echo printErrorPage("Temporarily unavailable.");
echo printErrorPage($settings, "Temporarily unavailable.");
return;
}
if ($settings['limitToInstitutions'] != [] and !in_array($contents['collection_id'], $settings['limitToInstitutions'])) {
echo printErrorPage("This collection does not belong to an enabled institution.");
echo printErrorPage($settings, "This collection does not belong to an enabled institution.");
return;
}

View File

@ -30,11 +30,11 @@ loadHttpToGlobals(["id", "task", "content"]);
define("targetFile", __DIR__ . "/../data/$id.htm");
if (!isset($id) or !in_array($id, ['footer', 'aside', 'banner', 'welcomeMsg'])) {
echo printErrorPage($translations['specifyToEdit']); return;
echo printErrorPage($settings, $translations['specifyToEdit']); return;
}
if ($id == 'welcomeMsg' and !$_SESSION['admin']) {
echo printErrorPage($translations['accessDenied']); return;
echo printErrorPage($settings, $translations['accessDenied']); return;
}
// Read file contents if there is no new content sent by $_POST.

View File

@ -81,17 +81,17 @@ else if ($task == "upload") {
// Whitelist of allowed types.
if (!in_array($_FILES['file']['type'], $allowedFiletypes)) {
printErrorPage($translations['filetypeNotWhitelisted']);
echo printErrorPage($settings, $translations['filetypeNotWhitelisted']);
return;
}
if (filesize($_FILES['file']['tmp_name']) > 300000) {
printErrorPage($translations['fileTooLarge']);
if (filesize($_FILES['file']['tmp_name']) > $settings['maxFileSize']) {
echo printErrorPage($settings, $translations['fileTooLarge']);
return;
}
if (!(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))) {
printErrorPage($translations['fileUploadError']);
echo printErrorPage($settings, $translations['fileUploadError']);
return;
}
@ -106,7 +106,7 @@ else if ($task == "upload") {
else if ($task == "delete") {
if (!is_file(fileDir . "/$subject")) {
printErrorPage($translations['fileDoesNotExist']); return;
echo printErrorPage($settings, $translations['fileDoesNotExist']); return;
}
unlink(fileDir . "/$subject");

View File

@ -214,11 +214,6 @@ document.addEventListener("DOMContentLoaded", function() {
uploadLabel.textContent = getTranslation(translations, "uploadFile");
uploadLabel.for = "fileUploadInput";
let uploadSize = document.createElement("input");
uploadSize.type = "hidden";
uploadSize.name = "MAX_FILE_SIZE";
uploadSize.value = "300000";
let uploadBackTo = document.createElement("input");
uploadBackTo.type = "hidden";
uploadBackTo.name = "backTo";
@ -233,13 +228,13 @@ document.addEventListener("DOMContentLoaded", function() {
uploadInput.type = "file";
uploadInput.id = "fileUploadInput";
uploadInput.name = "file";
uploadInput.value = "";
let uploadButton = document.createElement("button");
uploadButton.type = "submit";
uploadButton.textContent = getTranslation(translations, "submit");
uploadForm.appendChild(uploadLabel);
uploadForm.appendChild(uploadSize);
uploadForm.appendChild(uploadTask);
uploadForm.appendChild(uploadBackTo);
uploadForm.appendChild(uploadInput);

View File

@ -62,7 +62,7 @@ if (isset($task)) {
else if ($task == "delete") {
if (!isset($id)) {
echo printErrorPage($translations['specifyToDelete']); return;
echo printErrorPage($settings, $translations['specifyToDelete']); return;
}
unlink(__DIR__ . "/../data/static/$id.json");

View File

@ -17,7 +17,7 @@ ensureBackendEnv(); // Ensure session is sta
$pages = loadPages(); // Load overview of pages.
if (!$_SESSION['admin']) {
echo printErrorPage($translations['accessDenied']); return;
echo printErrorPage($settings, $translations['accessDenied']); return;
}
/*

View File

@ -126,4 +126,5 @@ $translations['deletedFile'] = 'Datei wurde gelöscht';
$translations['uploadedFile'] = 'Datei wurde heraufgeladen';
$translations['fileUploadError'] = 'Ein Fehler ist aufgetreten';
$translations['filetypeNotWhitelisted'] = 'Dateityp ist nicht erlaubt';
$translations['fileTooLarge'] = 'Die Datei ist zu groß';
?>

View File

@ -126,4 +126,5 @@ $translations['deletedFile'] = 'Deleted file';
$translations['uploadedFile'] = 'Uploaded file';
$translations['fileUploadError'] = 'Error uploading file';
$translations['filetypeNotWhitelisted'] = 'Filetype is not in whitelist';
$translations['fileTooLarge'] = 'The file is too large.';
?>

View File

@ -17,7 +17,7 @@ ensureBackendEnv(); // Ensure session is sta
$pages = loadPages(); // Load overview of pages.
if (!$_SESSION['admin']) {
echo printErrorPage($translations['accessDenied']); return;
echo printErrorPage($settings, $translations['accessDenied']); return;
}
/*

View File

@ -13,7 +13,7 @@ require_once __DIR__ . "/inc/functions.php";
// Check validity of request.
if (!isset($_GET['id']) or !is_numeric($_GET['id'])) {
echo printErrorPage("Exhibition does not exist.");
echo printErrorPage($settings, "Exhibition does not exist.");
return;
}
@ -25,12 +25,12 @@ $pages = loadPublicPages(); // Load overview of pages.
$contents = json_decode(queryCachePage($settings['mdVersion'] . "?t=event&id=" . urlencode($_GET['id']) . "&output=json", "event", $settings), true);
if (!$contents || (isset($contents[0]) and $contents[0] == "There is no event with this ID yet.")) {
echo printErrorPage("Temporarily unavailable.");
echo printErrorPage($settings, "Temporarily unavailable.");
return;
}
if ($settings['limitToInstitutions'] != [] and !in_array($contents['institution_id'], $settings['limitToInstitutions'])) {
echo printErrorPage("This exhibition does not belong to an enabled institution.");
echo printErrorPage($settings, "This exhibition does not belong to an enabled institution.");
return;
}

View File

@ -13,7 +13,7 @@ require_once __DIR__ . "/inc/functions.php";
// Check validity of request.
if (!isset($_GET['id']) or !is_numeric($_GET['id'])) {
echo printErrorPage("Exhibition does not exist.");
echo printErrorPage($settings, "Exhibition does not exist.");
return;
}
@ -25,12 +25,12 @@ $pages = loadPublicPages(); // Load overview of pages.
$contents = json_decode(queryCachePage($settings['mdVersion'] . "?t=exhibition&id=" . urlencode($_GET['id']) . "&output=json", "exhibition", $settings), true);
if (!$contents || (isset($contents[0]) and $contents[0] == "There is no exhibition with this ID yet.")) {
echo printErrorPage("Temporarily unavailable.");
echo printErrorPage($settings, "Temporarily unavailable.");
return;
}
if ($settings['limitToInstitutions'] != [] and !in_array($contents['institution_id'], $settings['limitToInstitutions'])) {
echo printErrorPage("This exhibition does not belong to an enabled institution.");
echo printErrorPage($settings, "This exhibition does not belong to an enabled institution.");
return;
}

View File

@ -83,7 +83,7 @@ function ensureEnvironment() {
"sendHTTPHeaders" => 1,
"CSPimageSources" => "",
"CSPobjectSources" => "",
"maxFileSize" => 300000,
"maxFileSize" => 300000000,
],
json_decode(file_get_contents(__DIR__ . "/../data/settings.json"), true)
);
@ -138,7 +138,8 @@ function queryCachePage(string $url, string $area = "", array $settings = ['cach
// Ignore caching if cacheRefreshInterval equals zero.
if ($settings['cacheRefreshInterval'] == 0) {
return file_get_contents($url);
$content = file_get_contents($url);
return $content;
}
$fileDir = __DIR__ . "/../data/caches/$area";

View File

@ -33,14 +33,17 @@ function checkForEmbeds(string $text, array $settings):string {
foreach ($embedOptions as $option) {
if (strpos($text, $option) === false) continue;
$i = 0;
while (strpos($text, $option) !== false) {
$position = strpos($text, $option) - 1;
$nextTag = $nextWhitespace = strlen($text);
$nextTag = $nextWhitespace = $nextNBSP = strlen($text);
if (strpos($text, "<", $position) !== false) $nextTag = strpos($text, "<", $position);
if (strpos($text, " ", $position) !== false) $nextWhitespace = strpos($text, " ", $position);
if (strpos($text, "&nbsp;", $position) !== false) $nextNBSP = strpos($text, "&nbsp;", $position);
$end = min($nextTag, $nextWhitespace);
// The pseudocode ends with a whitespace. No two tiles can be immediately after each other.
$end = min($nextTag, $nextWhitespace, $nextNBSP);
$pseudocode = substr($text, $position, $end - $position);
@ -80,6 +83,7 @@ function checkForEmbeds(string $text, array $settings):string {
$text = str_replace($pseudocode, embedEvent($arguments, $settings, true), $text);
break;
}
}
}

View File

@ -134,11 +134,12 @@ function printStaticPagePart(string $file, string $elem):string {
/**
* This function prints an error page.
*
* @param array $settings General site settings / including the CSS.
* @param string $content The error message.
*
* @return string
*/
function printErrorPage(string $content):string {
function printErrorPage(array $settings, string $content):string {
$output = '
<!DOCTYPE html>
@ -149,7 +150,7 @@ function printErrorPage(string $content):string {
<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" />
<link rel="stylesheet" type="text/css" href="themes/' . $settings['css'] . '/theme.css" />
</head>
<body>

View File

@ -12,7 +12,7 @@ require_once __DIR__ . "/inc/functions.php";
// Check validity of request.
if (isset($_GET['id']) and !file_exists(__DIR__ . "/data/static/" . $_GET['id'] . ".json")) {
echo printErrorPage("File does not exist.");
echo printErrorPage($settings, "File does not exist.");
return;
}
@ -35,7 +35,7 @@ else if (file_exists(__DIR__ . "/data/static/" . $settings['startPage'] . ".json
$id = $settings['startPage'];
}
else {
echo printErrorPage("This file does not exist.");
echo printErrorPage($settings, "This file does not exist.");
return;
}

View File

@ -13,7 +13,7 @@ require_once __DIR__ . "/inc/functions.php";
// Check validity of request.
if (!isset($_GET['id']) or !is_numeric($_GET['id'])) {
echo printErrorPage("Institution does not exist.");
echo printErrorPage($settings, "Institution does not exist.");
return;
}
@ -25,12 +25,12 @@ $pages = loadPublicPages(); // Load overview of pages.
$contents = json_decode(queryCachePage($settings['mdVersion'] . "?t=institution&instnr=" . urlencode($_GET['id']) . "&output=json", "institution", $settings), true);
if (!$contents || (isset($contents[0]) and $contents[0] == "There is no institution with this ID yet.")) {
echo printErrorPage("Temporarily unavailable.");
echo printErrorPage($settings, "Temporarily unavailable.");
return;
}
if ($settings['limitToInstitutions'] != [] and !in_array($_GET['id'], $settings['limitToInstitutions'])) {
echo printErrorPage("This object does not belong to an enabled institution.");
echo printErrorPage($settings, "This object does not belong to an enabled institution.");
return;
}

View File

@ -12,7 +12,7 @@ require_once __DIR__ . "/inc/functions.php";
// Check validity of request.
if (!isset($_GET['id']) or !is_numeric($_GET['id'])) {
echo printErrorPage("Object does not exist.");
echo printErrorPage($settings, "Object does not exist.");
return;
}
@ -24,12 +24,12 @@ $pages = loadPublicPages(); // Load overview of pages.
$contents = json_decode(queryCachePage($settings['mdVersion'] . "?t=objekt&oges=" . urlencode($_GET['id']) . "&output=json", "object", $settings), true);
if (!$contents || (isset($contents[0]) and $contents[0] == "There is no object with this ID yet.")) {
echo printErrorPage("Temporarily unavailable.");
echo printErrorPage($settings, "Temporarily unavailable.");
return;
}
if ($settings['limitToInstitutions'] != [] and !in_array($contents['object_institution']['institution_id'], $settings['limitToInstitutions'])) {
echo printErrorPage("This object does not belong to an enabled institution.");
echo printErrorPage($settings, "This object does not belong to an enabled institution.");
return;
}