2021-04-02 21:29:46 +02:00
|
|
|
<?php declare(strict_types=1);
|
2021-04-02 21:00:09 +02:00
|
|
|
|
|
|
|
namespace htmgem\html;
|
|
|
|
|
|
|
|
mb_internal_encoding("UTF-8");
|
|
|
|
mb_regex_encoding("UTF-8");
|
|
|
|
|
2022-08-02 08:43:00 +02:00
|
|
|
define("TXT_ICON", "H͜͡m ");
|
2021-04-11 21:35:55 +02:00
|
|
|
|
|
|
|
function getHeader(\htmgem\GemtextTranslate_html $gt_html) {
|
2021-04-02 21:00:09 +02:00
|
|
|
$css = $gt_html->getCss();
|
|
|
|
$output = <<<EOL
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="">
|
|
|
|
<head>
|
|
|
|
<title>{$gt_html->getTitle()}</title>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
|
EOL;
|
|
|
|
foreach ($css as $c) {
|
|
|
|
$output .= "\n<link type='text/css' rel='StyleSheet' href='$c'>\n";
|
|
|
|
}
|
|
|
|
$output .= <<<EOL
|
|
|
|
</head>
|
2021-04-11 21:35:55 +02:00
|
|
|
|
2021-04-02 21:00:09 +02:00
|
|
|
EOL;
|
2021-04-11 21:35:55 +02:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
function array_key_last_slice($array) {
|
|
|
|
// array_key_last() only available as of php v7.3.0
|
|
|
|
return key(array_slice($array, -1));
|
|
|
|
}
|
2021-04-02 21:00:09 +02:00
|
|
|
|
2021-04-11 21:35:55 +02:00
|
|
|
/**
|
|
|
|
* @param $url the full URL to display
|
|
|
|
* @param $pageLink if not null, means no URL rewritting
|
|
|
|
*/
|
|
|
|
function getMenu(string $scheme, string $domain, string $path, string $prefix=null) {
|
|
|
|
$links = \htmgem\split_path_links($path, $prefix);
|
|
|
|
|
|
|
|
// Removes the last part, as it won't hold a link
|
|
|
|
$lastLink = array_key_last_slice($links);
|
|
|
|
if ("index.gmi"==$lastLink) {
|
|
|
|
// removes the index page
|
|
|
|
array_pop($links);
|
|
|
|
$lastLink = array_key_last_slice($links);
|
|
|
|
}
|
|
|
|
array_pop($links);
|
|
|
|
|
|
|
|
$links = array($domain => "$prefix/") + $links;
|
|
|
|
$linkList = array();
|
|
|
|
foreach ($links as $label=>$link) {
|
|
|
|
$linkList []= "<a href='$link'>$label</a>\n";
|
|
|
|
}
|
|
|
|
$linkList [] = $lastLink."\n"; // The last part holds no link
|
|
|
|
$output = "<div class='menu-line'>\n";
|
|
|
|
$output .= "<strong>$txt_icon</strong>$scheme\n";
|
|
|
|
$output .= implode(" / ", $linkList);
|
|
|
|
$output .= "</div>\n";
|
2021-04-02 21:00:09 +02:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2021-04-11 21:35:55 +02:00
|
|
|
function getFooter(\htmgem\GemtextTranslate_html $gt_html) {
|
|
|
|
return "</body>\n</html>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHtmlWithMenu($gt_html, $scheme, $domain, $path, $prefix=null) {
|
|
|
|
$menu = getMenu($scheme, $domain, $path, $prefix);
|
|
|
|
echo getHeader($gt_html);
|
|
|
|
echo "<body>\n";
|
|
|
|
echo "<div class='menu'>\n";
|
|
|
|
echo $menu;
|
|
|
|
echo "<hr>\n";
|
|
|
|
echo "</div>\n";
|
|
|
|
echo "<div id='gmi'>\n";
|
|
|
|
echo $gt_html->translatedGemtext;
|
|
|
|
echo "</div>\n";
|
|
|
|
echo "<div class='menu'>\n";
|
|
|
|
echo "<hr>\n";
|
|
|
|
echo $menu;
|
|
|
|
echo "</div>\n";
|
|
|
|
echo getFooter($gt_html);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get404Gmipage($url) {
|
2021-04-02 21:00:09 +02:00
|
|
|
return <<<EOF
|
2021-04-11 21:35:55 +02:00
|
|
|
# ⚠ $url ⚠
|
|
|
|
|
|
|
|
* **Page non trouvée**
|
|
|
|
* **Page not found**
|
2021-04-02 21:00:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
EOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|