Installation de HtmGem
\n\n";
die();
}
######################################## /Installation page
# Removes the headling and trailling slashes, to be sure there's not any.
$filePath = rtrim($_SERVER['DOCUMENT_ROOT'], "/")."/".ltrim($url, "/");
$fileContents = @file_get_contents($filePath);
######################################## 404 page
if (empty($fileContents)) {
error_log("HtmGem: 404 $url $filePath");
http_response_code(404); ?>
$url Recharger 🔄
=> /
EOF;
echo translateGemToHtml($text404);
echo "\n";
die();
}
######################################## /404 page
# Removes the Byte Order Mark
$fileContents = preg_replace("/\xEF\xBB\xBF/", "", $fileContents);
# Gets the page title: the first occurrence with # at the line start
mb_ereg("#\s*([^\n]+)\n", $fileContents, $matches);
$page_title = @$matches[1];
###################################### CSS Management
/**
* if &style=source displays the source directly and stops.
* if there's a filename.css besides filename.gmi, use the css and stops.
* if &style= then embbed the default style, and stops.
* if &style= then use htmgem/word.css
* if &style=/… then use the … as as stylesheet.
**/
if ("source" == $style) {
$basename = basename($filePath);
header("Cache-Control: public");
header("Content-Disposition: attachment; filename=$basename");
header("Content-Type: text/plain");
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
exit();
} elseif ("pre" == $style) {
$fileContents = htmlspecialchars($fileContents, ENT_HTML5|ENT_NOQUOTES, "UTF-8", false);
echo <<$page_title
$fileContents
EOL;
} else {
$parts = pathinfo($filePath);
$localCss = $parts["filename"].".css";
$localCssFilePath = $parts["dirname"]."/".$localCss;
if (file_exists($localCssFilePath)) {
# Warning, using htmhem.php?url=… will make $localCss not found
# as the path is relative to htmgem.php and not / !
$cssContent = "";
} else {
if (empty($style)) {
$cssContent =
"\n";
} else {
if ("none" == $style) {
$cssContent = "";
} else {
if ("/" == $style[0])
$href = $style;
else
$href = "/htmgem/css/$style.css";
$cssContent = "";
}
}
}
echo <<$page_title
$cssContent
EOL;
echo "\n".translateGemToHtml($fileContents);
echo "\n\n";
}
ob_end_flush();
?>