This commit is contained in:
Joshua Ramon Enslin 2021-02-26 01:01:01 +01:00
commit 1d6684b394
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
14 changed files with 310 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/cache
/conf
/composer.lock
/vendor

18
.gitmodules vendored Normal file
View File

@ -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

@ -0,0 +1 @@
Subproject commit dbc7d01de4593356b3bf7239a5afc3187181d4a2

@ -0,0 +1 @@
Subproject commit 7ecd0e4a8d028b142ad9ef04c805ed49278707e3

1
classes/MDMailer Submodule

@ -0,0 +1 @@
Subproject commit f41c81a3cd9aaf21bc08e076b1a13a46fcb6fd14

1
classes/MDTlLoader Submodule

@ -0,0 +1 @@
Subproject commit 56edfcbbe9212ebb4095cd91bcf8aa0ce643e053

1
classes/MD_STD Submodule

@ -0,0 +1 @@
Subproject commit 06bbaf5f97811ec8854a4f8a964e98badce565cb

5
composer.json Normal file
View File

@ -0,0 +1,5 @@
{
"require": {
"phpmailer/phpmailer": "^6.3"
}
}

28
constants.php Normal file
View File

@ -0,0 +1,28 @@
<?PHP
/**
* Constants for the environment of the museum-digital URL shortener.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
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",
];

@ -0,0 +1 @@
Subproject commit 2243608fec438198d7843a3d1f046b1fd257c5f6

15
provide_env.php Normal file
View File

@ -0,0 +1,15 @@
<?PHP
/**
* This file collects generally, often used functions in the public frontend for museum-digital:event-types
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
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);

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

95
public/index.php Normal file
View File

@ -0,0 +1,95 @@
<?PHP
/**
* This is a simple site offering an overview over the available event types at
* museum-digital.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
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 '
<style>
body { font-family: Helvetica, Arial, Calibri; }
code { font-size: 1.4em; }
a { padding: .2em; color: #333; text-decoration: none; transition: background .4s, border .4s; }
a:hover { color: #FFF; background: #000; border-radius: .2em; }
</style>
';
foreach ($availableLangs as $tLang) {
echo '
<a href="/' . $tLang;
if (!empty($id)) echo '/' . $id;
echo '">' . $tLang . '</a> ';
}
echo '<hr />';
if (!empty($id)) {
echo '
<h1>' . $eventTypes[$id]['ereignistyp_name'] . '</h1>
<dl>
<dt>ID</dt>
<dd>' . $id . '</dd>
<dt>-</dt>
<dd>' . $eventTypes[$id]['ereignistyp_explica'] . '</dd>
<dt><label for="permalink">Permalink</label></dt>
<dd><input type="text" id="permalink" value="https://event-types.museum-digital.org/' . $id . '" /></dd>
<dl>
<hr />
<a href="/' . $lang . '">x</a>
';
return;
}
echo '
<h1>Event types</h1>';
foreach ($eventTypes as $type) {
echo '
<div>
<h2><a href="/' . $lang . '/' . $type['ereignistyp_id'] . '"><code>' . $type['ereignistyp_id'] . '</code>: ' . $type['ereignistyp_name'] . '</a></h2>
<p>' . $type['ereignistyp_explica'] . '</p>
</div>
<hr>
';
}

139
src/global_functions.php Normal file
View File

@ -0,0 +1,139 @@
<?PHP
/**
* This file collects generally, often used functions in the public frontend for museum-digital
*
* @file
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
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 = '<!DOCTYPE html>
<html id="errorPage">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Error :: URL shortener</title>
</head>
<body>
<main>
<p>' . $errorMsg . '</p>
</main>
</body>
</html>';
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 ...<br />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 (<a href='https://www.google.de/search?q=php+" . str_replace(" ", "+", $string) . "'>$string</a>) at $file: line_ $line _";
$errorMsg .= " |-- Error generating page: <a href='$errorPageFull'>$errorPage</a>";
$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;
}