commit 1d6684b394fb33760fdeed787884ba4e25d7f17d Author: Joshua Ramon Enslin Date: Fri Feb 26 01:01:01 2021 +0100 Initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e9b57a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/cache +/conf +/composer.lock +/vendor diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d55f51b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,18 @@ +[submodule "clases/MDAllowedValueSets"] + path = classes/MDAllowedValueSets + url = gitea:museum-digital/MDAllowedValueSets.git +[submodule "classes/MDTlLoader"] + path = classes/MDTlLoader + url = gitea:museum-digital/MDTlLoader.git +[submodule "classes/MD_STD"] + path = classes/MD_STD + url = https://gitea.armuli.eu/museum-digital/MD_STD.git +[submodule "classes/MDErrorReporter"] + path = classes/MDErrorReporter + url = gitea:museum-digital/MDErrorReporter.git +[submodule "classes/MDMailer"] + path = classes/MDMailer + url = gitea:museum-digital/MDMailer.git +[submodule "l10n/translation-musdb"] + path = l10n/translation-musdb + url = gitea:museum-digital/translation-musdb.git diff --git a/classes/MDAllowedValueSets b/classes/MDAllowedValueSets new file mode 160000 index 0000000..dbc7d01 --- /dev/null +++ b/classes/MDAllowedValueSets @@ -0,0 +1 @@ +Subproject commit dbc7d01de4593356b3bf7239a5afc3187181d4a2 diff --git a/classes/MDErrorReporter b/classes/MDErrorReporter new file mode 160000 index 0000000..7ecd0e4 --- /dev/null +++ b/classes/MDErrorReporter @@ -0,0 +1 @@ +Subproject commit 7ecd0e4a8d028b142ad9ef04c805ed49278707e3 diff --git a/classes/MDMailer b/classes/MDMailer new file mode 160000 index 0000000..f41c81a --- /dev/null +++ b/classes/MDMailer @@ -0,0 +1 @@ +Subproject commit f41c81a3cd9aaf21bc08e076b1a13a46fcb6fd14 diff --git a/classes/MDTlLoader b/classes/MDTlLoader new file mode 160000 index 0000000..56edfcb --- /dev/null +++ b/classes/MDTlLoader @@ -0,0 +1 @@ +Subproject commit 56edfcbbe9212ebb4095cd91bcf8aa0ce643e053 diff --git a/classes/MD_STD b/classes/MD_STD new file mode 160000 index 0000000..06bbaf5 --- /dev/null +++ b/classes/MD_STD @@ -0,0 +1 @@ +Subproject commit 06bbaf5f97811ec8854a4f8a964e98badce565cb diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..8f8ff09 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "phpmailer/phpmailer": "^6.3" + } +} diff --git a/constants.php b/constants.php new file mode 100644 index 0000000..e5eb1f3 --- /dev/null +++ b/constants.php @@ -0,0 +1,28 @@ + + */ +declare(strict_types = 1); + +const TL_FILE_DIRS = [ + __DIR__ . "/l10n/translation-musdb/", + __DIR__ . "/classes/MDAllowedValueSets/l18n/", +]; + +const AUTOLOAD_DIRS = [ + __DIR__ . "/src", + __DIR__ . "/classes/MD_STD", + __DIR__ . "/classes/MDAllowedValueSets/src", + __DIR__ . "/classes/MDTlLoader/src", + __DIR__ . "/classes/MDTlLoader/exceptions", + __DIR__ . "/classes/MDErrorReporter", + __DIR__ . "/classes/MDMailer/src", + __DIR__ . "/classes/MDMysqli/exceptions", + # __DIR__ . "/classes/MDTlLoader/src", + # __DIR__ . "/classes/MDTlLoader/exceptions", + __DIR__ . "/classes/MDErrorReporter/exceptions/generic", + __DIR__ . "/classes/MDErrorReporter/exceptions/page", + __DIR__ . "/classes/MDErrorReporter/exceptions/updates", +]; diff --git a/l10n/translation-musdb b/l10n/translation-musdb new file mode 160000 index 0000000..2243608 --- /dev/null +++ b/l10n/translation-musdb @@ -0,0 +1 @@ +Subproject commit 2243608fec438198d7843a3d1f046b1fd257c5f6 diff --git a/provide_env.php b/provide_env.php new file mode 100644 index 0000000..4546e58 --- /dev/null +++ b/provide_env.php @@ -0,0 +1,15 @@ + + */ +declare(strict_types = 1); + +require_once __DIR__ . '/constants.php'; +require_once __DIR__ . '/src/global_functions.php'; + +\spl_autoload_register("mdShortenerAutoloader"); +# \set_exception_handler("mdShortenerExceptionHandler"); +# \set_error_handler("mdShortenerErrorHandler", E_ALL); + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..ad12e32 Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..5fdeebf --- /dev/null +++ b/public/index.php @@ -0,0 +1,95 @@ + + */ +declare(strict_types = 1); + +require __DIR__ . '/../provide_env.php'; + +if (is_numeric($_GET['lang'])) { + header('Location: /en/' . $_GET['lang']); + return; +} + + error_reporting(E_ALL); +ini_set("display_errors", "1"); + +if (!empty($_GET['lang']) and is_string($_GET['lang']) and is_dir(__DIR__ . "/../l10n/translation-musdb/{$_GET['lang']}")) { + $lang = $_GET['lang']; +} +else $lang = "en"; + +$tlLoader = new MDTlLoader("ereignis_auswahl", $lang); + +$eventTypes = []; + +foreach (MDEventsSet::EVENT_IDS as $j) { + + $eventTypes[] = [ + 'ereignistyp_id' => $j, + 'ereignistyp_name' => $tlLoader->tl("eventtype_name", "eventname", $j), + 'ereignistyp_explica' => $tlLoader->tl("eventtype_explica", "ereignistyp_explica", $j), + ]; +} + +$availableLangs = MD_STD::scandir(__DIR__ . "/../l10n/translation-musdb"); + +if (!empty($_GET['id']) and !($id = filter_var($_GET['id'], FILTER_VALIDATE_INT))) { + echo "Error: IDs must be presented in a numeric format."; + return; +} + +echo ' + +'; + +foreach ($availableLangs as $tLang) { + echo ' + ' . $tLang . ' '; +} +echo '
'; + +if (!empty($id)) { + + echo ' +

' . $eventTypes[$id]['ereignistyp_name'] . '

+
+
ID
+
' . $id . '
+
-
+
' . $eventTypes[$id]['ereignistyp_explica'] . '
+
+
+
+
+x +'; + return; + +} + + +echo ' +

Event types

'; + +foreach ($eventTypes as $type) { + + echo ' +
+

' . $type['ereignistyp_id'] . ': ' . $type['ereignistyp_name'] . '

+

' . $type['ereignistyp_explica'] . '

+
+
+'; + +} diff --git a/src/global_functions.php b/src/global_functions.php new file mode 100644 index 0000000..d040de9 --- /dev/null +++ b/src/global_functions.php @@ -0,0 +1,139 @@ + + */ +declare(strict_types = 1); + +/** + * Autoloader for museum-digital.org. + * + * @param string $className Name of the class to load. + * + * @return void + */ +function mdShortenerAutoloader(string $className):void { + + if ($className === 'MDMailerHelper') { + include_once __DIR__ . '/../vendor/autoload.php'; + } + + $classDirs = AUTOLOAD_DIRS; + + foreach ($classDirs as $classDir) { + if (\file_exists("$classDir/$className.php")) { + include "$classDir/$className.php"; + return; + } + } + +} + +/** + * Exception handler to also be able to handle custom exceptions. + * + * @param Throwable $exception Exception. + * + * @return void + */ +function mdShortenerExceptionHandler(Throwable $exception):void { + + $formatErrorPage = function(string $errorMsg = "") :string { + + if (PHP_SAPI === "cli") { + return $errorMsg . PHP_EOL; + } + + $output = ' + + + + + Error :: URL shortener + + + +
+

' . $errorMsg . '

+
+ + +'; + + return $output; + }; + + $errorReporter = new MDErrorReporter("md:frontend", "bugs-frontend@museum-digital.de"); + $errorCategory = MDErrorReporter::categorizeError($exception); + + http_response_code(404); + + switch ($errorCategory) { + case MDErrorReporter::MD_ERROR_KNOWN: + + if (isset($_GET["output"]) and $_GET['output'] === "json") { + header('Content-type: application/json'); + $output = [ + "status" => "Error", + "msg" => $exception->getMessage(), + ]; + echo MD_STD::json_encode($output); + exit; + } + + echo $formatErrorPage($exception->getMessage()); + exit; + + default: + $errorReporter->sendErrorReport($exception, "joshua@museum-digital.de"); + echo $formatErrorPage("Uncaught exception ...
Our team has been notified and will get to fixing this error shortly."); + exit; + } + +} + +/** + * Own error handler: Set to enforce exit on any error. + * + * @param integer $errno Error number. + * @param string $string Error message. + * @param string $file File in which the error occured. + * @param integer $line Line number. + * + * @return boolean + */ +function mdShortenerErrorHandler(int $errno, string $string, string $file, int $line):bool { + + $getStr = []; + foreach ($_GET as $key => $value) { + if (is_array($value)) continue; + $getStr[] = $key . "=" . $value; + } + # print_r(debug_backtrace()); + # exit; + + $errorMsg = ""; + + if (!empty($_SERVER) && !empty($_SERVER["HTTP_HOST"])) { + + $errorPage = $_SERVER['PHP_SELF'] . "?" . implode("&", $getStr); + $errorPageFull = "https://" . $_SERVER["HTTP_HOST"] . $errorPage; + + $errorMsg = "*$errno ($string) at $file: line_ $line _"; + $errorMsg .= " |-- Error generating page: $errorPage"; + $errorMsg .= " |-- Used RAM / Peak RAM / Allowed: " . MD_STD::human_filesize(memory_get_usage()) . " / " . MD_STD::human_filesize(memory_get_peak_usage()) . " / " . ini_get("memory_limit"); + + $errorMsg = str_replace(PHP_EOL, " ", $errorMsg); + + error_log($errorMsg); + + } + + if ($errno == E_ERROR) exit; + return false; + +} +