diff --git a/apiMirror.php b/apiMirror.php index 9320c7b..df27ee9 100644 --- a/apiMirror.php +++ b/apiMirror.php @@ -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; } diff --git a/collection.php b/collection.php index 1662ce8..891ddcc 100644 --- a/collection.php +++ b/collection.php @@ -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; } diff --git a/edit/editHTMLPage.php b/edit/editHTMLPage.php index 0e3c118..2f5038c 100644 --- a/edit/editHTMLPage.php +++ b/edit/editHTMLPage.php @@ -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. diff --git a/edit/files.php b/edit/files.php index cc1ca20..db3aa06 100644 --- a/edit/files.php +++ b/edit/files.php @@ -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"); diff --git a/edit/js/main.js b/edit/js/main.js index cf54c38..e2fc898 100644 --- a/edit/js/main.js +++ b/edit/js/main.js @@ -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); diff --git a/edit/page.php b/edit/page.php index 9d8c362..353ea7e 100644 --- a/edit/page.php +++ b/edit/page.php @@ -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"); diff --git a/edit/settings.php b/edit/settings.php index af91695..6da2dd8 100644 --- a/edit/settings.php +++ b/edit/settings.php @@ -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; } /* diff --git a/edit/translations/de.php b/edit/translations/de.php index b262968..186c3e9 100644 --- a/edit/translations/de.php +++ b/edit/translations/de.php @@ -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ß'; ?> \ No newline at end of file diff --git a/edit/translations/en.php b/edit/translations/en.php index 2085890..0a5c58f 100644 --- a/edit/translations/en.php +++ b/edit/translations/en.php @@ -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.'; ?> \ No newline at end of file diff --git a/edit/users.php b/edit/users.php index 0a4cb63..0710215 100644 --- a/edit/users.php +++ b/edit/users.php @@ -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; } /* diff --git a/event.php b/event.php index 86f7a14..9e4420c 100644 --- a/event.php +++ b/event.php @@ -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; } diff --git a/exhibition.php b/exhibition.php index 5d2785b..427c39d 100644 --- a/exhibition.php +++ b/exhibition.php @@ -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; } diff --git a/inc/functions.php b/inc/functions.php index aeb0926..8b884f2 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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"; diff --git a/inc/mdEmbeds.php b/inc/mdEmbeds.php index e772dca..1b86edd 100644 --- a/inc/mdEmbeds.php +++ b/inc/mdEmbeds.php @@ -33,52 +33,56 @@ function checkForEmbeds(string $text, array $settings):string { foreach ($embedOptions as $option) { - if (strpos($text, $option) === false) continue; - $position = strpos($text, $option) - 1; + $i = 0; + while (strpos($text, $option) !== false) { + $position = strpos($text, $option) - 1; - $nextTag = $nextWhitespace = strlen($text); - if (strpos($text, "<", $position) !== false) $nextTag = strpos($text, "<", $position); - if (strpos($text, " ", $position) !== false) $nextWhitespace = strpos($text, " ", $position); + $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, " ", $position) !== false) $nextNBSP = strpos($text, " ", $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); + $pseudocode = substr($text, $position, $end - $position); - $command = substr($pseudocode, 1, strpos($pseudocode, "]") - 1); - $arguments = []; - if (strpos($pseudocode, "{") !== false) $arguments = explode("&", substr($pseudocode, strpos($pseudocode, "{") + 1, -1)); + $command = substr($pseudocode, 1, strpos($pseudocode, "]") - 1); + $arguments = []; + if (strpos($pseudocode, "{") !== false) $arguments = explode("&", substr($pseudocode, strpos($pseudocode, "{") + 1, -1)); - switch ($command) { - case "singleObjectTile": - $text = str_replace($pseudocode, embedObject($arguments, $settings), $text); - break; - case "singleObjectDetails": - $text = str_replace($pseudocode, embedObject($arguments, $settings, true), $text); - break; - case "singleCollectionTile": - $text = str_replace($pseudocode, embedCollection($arguments, $settings), $text); - break; - case "singleCollectionDetails": - $text = str_replace($pseudocode, embedCollection($arguments, $settings, true), $text); - break; - case "singleInstitutionTile": - $text = str_replace($pseudocode, embedInstitution($arguments, $settings), $text); - break; - case "singleInstitutionDetails": - $text = str_replace($pseudocode, embedInstitution($arguments, $settings, true), $text); - break; - case "exhibitionCalendar": - $text = str_replace($pseudocode, embedExhibitionCalendar($arguments), $text); - break; - case "singleExhibitionDetails": - $text = str_replace($pseudocode, embedExhibition($arguments, $settings, true), $text); - break; - case "eventCalendar": - $text = str_replace($pseudocode, embedEventCalendar($arguments), $text); - break; - case "singleEventDetails": - $text = str_replace($pseudocode, embedEvent($arguments, $settings, true), $text); - break; + switch ($command) { + case "singleObjectTile": + $text = str_replace($pseudocode, embedObject($arguments, $settings), $text); + break; + case "singleObjectDetails": + $text = str_replace($pseudocode, embedObject($arguments, $settings, true), $text); + break; + case "singleCollectionTile": + $text = str_replace($pseudocode, embedCollection($arguments, $settings), $text); + break; + case "singleCollectionDetails": + $text = str_replace($pseudocode, embedCollection($arguments, $settings, true), $text); + break; + case "singleInstitutionTile": + $text = str_replace($pseudocode, embedInstitution($arguments, $settings), $text); + break; + case "singleInstitutionDetails": + $text = str_replace($pseudocode, embedInstitution($arguments, $settings, true), $text); + break; + case "exhibitionCalendar": + $text = str_replace($pseudocode, embedExhibitionCalendar($arguments), $text); + break; + case "singleExhibitionDetails": + $text = str_replace($pseudocode, embedExhibition($arguments, $settings, true), $text); + break; + case "eventCalendar": + $text = str_replace($pseudocode, embedEventCalendar($arguments), $text); + break; + case "singleEventDetails": + $text = str_replace($pseudocode, embedEvent($arguments, $settings, true), $text); + break; + } } } diff --git a/inc/standardHTML.php b/inc/standardHTML.php index bdc7fa6..99d9a68 100644 --- a/inc/standardHTML.php +++ b/inc/standardHTML.php @@ -134,11 +134,12 @@ function printStaticPagePart(string $file, string $elem):string { /** * This function prints an error page. * - * @param string $content The error message. + * @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 = ' @@ -149,7 +150,7 @@ function printErrorPage(string $content):string { ' . $content . ' - + diff --git a/index.php b/index.php index 3a8d4f1..e5f4ed9 100644 --- a/index.php +++ b/index.php @@ -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; } diff --git a/institution.php b/institution.php index e92acbe..9d75418 100644 --- a/institution.php +++ b/institution.php @@ -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; } diff --git a/object.php b/object.php index 5845463..59b4c4e 100644 --- a/object.php +++ b/object.php @@ -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; }