servnest/top.inc.php

103 lines
2.7 KiB
PHP

<?php
if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
exit("This file is meant to be included.");
require "inc/const.inc.php";
// Functions usefull everywhere
require "inc/all.inc.php";
require "inc/format.inc.php";
// Service-specific functions
require "inc/ht.inc.php";
require "inc/ns.inc.php";
require "inc/reg.inc.php";
require "inc/auth.inc.php";
// Page titles definition
require "inc/pages.inc.php";
// Session initialisation (with cookies)
if (
isset($_COOKIE['niver']) // Resume session
OR
(SERVICE === "auth" // Create new session
AND PAGE === "login"
AND isset($_POST['username']))
) {
session_start([
'name' => 'niver',
'sid_length' => 64,
'sid_bits_per_character' => 6,
'cookie_secure' => true,
'cookie_httponly' => true,
'cookie_samesite' => 'Strict',
'cookie_path' => PREFIX . '/',
'cookie_lifetime' => 432000, // = 60*60*24*5 = 5 days
'gc_maxlifetime' => 10800,
'use_strict_mode' => true,
'use_cookies' => true,
'use_only_cookies' => true,
]);
}
// Remove .php from URL (if any)
if (substr($_SERVER['REQUEST_URI'], -4) == ".php") {
header("Location: " . PREFIX . "/" . SERVICE . "/" . PAGE, true, 301); // 301 Moved Permanently
exit;
}
// Less > CSS compilation
require_once 'lessphp/lib/Less/Autoloader.php';
Less_Autoloader::register();
// List files in less/
$relativeLessFiles = array_diff(scandir(ROOT_PATH . "/less"), array('..', '.'));
// Replace keys by values, and values by keys
$relativeLessFiles = array_flip($relativeLessFiles);
// Change relative paths into absolute paths
foreach ($relativeLessFiles as $relativeLessFile => $nothing) {
$absoluteLessFiles[ROOT_PATH . "/less/" . $relativeLessFile] = "";
}
// Generate one minified CSS file into css/ from sources in less/
$options = array(
'cache_dir' => ROOT_PATH . '/css/',
'compress' => true
);
$cssFileName = Less_Cache::Get($absoluteLessFiles, $options, THEME);
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title><?php
if (isset($page['title']) AND $page['title'] != "Accueil")
echo $page['title'] . " · ";
if (isset($page['service'])) {
echo $page['service'] . " · ";
} ?>Niver</title>
<link type="text/css" rel="stylesheet" href="<?= PREFIX ?>/css/<?= $cssFileName ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<header>
<nav>
<a href="<?= PREFIX ?>/">Niver</a><?php
if (isset($page['service'])) {
echo ' > <a href="./">' . $page['service'] . '</a>';
}
if (PAGE != "index")
echo ' > <a href="' . PAGE . '">' . $page['title'] . "</a>";
?>
</nav>
<?php if (isset($page['title'])) { ?>
<h1><?= $page['title'] ?></h1>
<?php } ?>
</header>
<main>