1
0
mirror of https://tildegit.org/sbgodin/HtmGem.git synced 2023-08-25 13:53:12 +02:00
HtmGem/lib-html.inc.php

98 lines
2.3 KiB
PHP
Raw Normal View History

2021-04-02 21:29:46 +02:00
<?php declare(strict_types=1);
namespace htmgem\html;
mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8");
$txt_icon = "H͜͡m ";
function getHeader(\htmgem\GemtextTranslate_html $gt_html) {
$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>
EOL;
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));
}
/**
* @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) {
global $txt_icon;
$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";
return $output;
}
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) {
return <<<EOF
# ⚠ $url ⚠
* **Page non trouvée**
* **Page not found**
EOF;
}
?>