event-types/scripts/compile.php

138 lines
3.7 KiB
PHP

<?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';
function generateStyle():string {
return '<!doctype html>
<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>';
}
/**
* Generates the links to other available langauges.
*
* @param int|null $id ID of the current page.
*
* @return string
*/
function generateHeader(?int $id = null):string {
$output = '';
foreach (AVAILABLE_LANGS as $tLang) {
$output .= '
<a href="/' . $tLang;
if (!empty($id)) $output .= '/' . $id;
$output .= '">' . $tLang . '</a> ';
}
$output .= '<hr />';
return $output;
}
/**
* Generates a list page.
*
* @param string $lang Currently used language.
* @param array<array{ereignistyp_id: int, ereignistyp_name: string, ereignistyp_explica: string}> $eventTypes List of available event types.
*
* @return string
*/
function generateListPage(string $lang, array $eventTypes):string {
$output = generateStyle();
$output .= generateHeader();
$output .= '
<h1>Event types</h1>';
foreach ($eventTypes as $type) {
$output .= '
<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>
';
}
return $output;
}
/**
* Generates a list page.
*
* @param string $lang Currently used language.
* @param array{ereignistyp_id: int, ereignistyp_name: string, ereignistyp_explica: string} $eventType List of available event types.
*
* @return string
*/
function generateEventTypePage(string $lang, array $eventType):string {
$output = generateStyle();
$output .= generateHeader($eventType['ereignistyp_id']);
$output .= '
<h1>' . $eventType['ereignistyp_name'] . '</h1>
<dl>
<dt>ID</dt>
<dd>' . $eventType['ereignistyp_id'] . '</dd>
<dt>-</dt>
<dd>' . $eventType['ereignistyp_explica'] . '</dd>
<dt><label for="permalink">Permalink</label></dt>
<dd><input type="text" id="permalink" value="https://event-types.museum-digital.org/' . $eventType['ereignistyp_id'] . '" /></dd>
<dl>
<hr />
<a href="/' . $lang . '">x</a>
';
return $output;
}
// Bootstrap
define('AVAILABLE_LANGS', MD_STD::scandir(__DIR__ . "/../l10n/translation-musdb"));
if (!is_dir(__DIR__ . '/../public')) {
mkdir(__DIR__ . '/../public');
}
foreach (AVAILABLE_LANGS as $lang) {
$tlLoader = new MDTlLoader("ereignis_auswahl", $lang);
$eventTypes = [];
foreach (MDEventsSet::EVENT_IDS as $j) {
$eventTypes[$j] = [
'ereignistyp_id' => (int)$j,
'ereignistyp_name' => $tlLoader->tl("eventtype_name", "eventname", $j),
'ereignistyp_explica' => $tlLoader->tl("eventtype_explica", "ereignistyp_explica", $j),
];
}
$langDir = __DIR__ . '/../public/' . $lang;
if (!is_dir($langDir)) mkdir($langDir);
file_put_contents($langDir . '/index.htm', generateListPage($lang, $eventTypes));
foreach ($eventTypes as $id => $eventType) {
file_put_contents($langDir . '/' . $id . '.htm', generateEventTypePage($lang, $eventType));
}
}