top.inc.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
  3. exit("This file is meant to be included.");
  4. require "inc/const.inc.php";
  5. // Functions usefull everywhere
  6. require "inc/all.inc.php";
  7. require "inc/format.inc.php";
  8. // Service-specific functions
  9. require "inc/ht.inc.php";
  10. require "inc/ns.inc.php";
  11. require "inc/reg.inc.php";
  12. require "inc/auth.inc.php";
  13. // Page titles definition
  14. require "inc/pages.inc.php";
  15. // Session initialisation (with cookies)
  16. if (
  17. isset($_COOKIE['niver']) // Resume session
  18. OR
  19. (SERVICE === "auth"
  20. AND PAGE === "login"
  21. AND isset($_POST['username']))
  22. ) {
  23. session_start([
  24. 'name' => 'niver',
  25. 'sid_length' => 64,
  26. 'sid_bits_per_character' => 6,
  27. 'cookie_secure' => true,
  28. 'cookie_httponly' => true,
  29. 'cookie_samesite' => 'Strict',
  30. 'cookie_path' => PREFIX . '/',
  31. 'cookie_lifetime' => 432000, // = 60*60*24*5 = 5 days
  32. 'gc_maxlifetime' => 10800,
  33. 'use_strict_mode' => true,
  34. 'use_cookies' => true,
  35. 'use_only_cookies' => true,
  36. ]);
  37. }
  38. // Redirect to the login page if not logged in
  39. if (SERVICE != "auth" AND !isset($_SESSION['username'])) {
  40. header('Location: ' . PREFIX . '/auth/login?redir=' . SERVICE . "/" . PAGE, true, 302);
  41. exit;
  42. }
  43. // Remove .php from URL (if any)
  44. if (substr($_SERVER['REQUEST_URI'], -4) == ".php") {
  45. header("Location: " . PREFIX . "/" . SERVICE . "/" . PAGE, true, 301); // 301 Moved Permanently
  46. exit;
  47. }
  48. // Less > CSS compilation
  49. require_once 'lessphp/lib/Less/Autoloader.php';
  50. Less_Autoloader::register();
  51. // List files in less/
  52. $relativeLessFiles = array_diff(scandir(ROOT_PATH . "/less"), array('..', '.'));
  53. // Replace keys by values, and values by keys
  54. $relativeLessFiles = array_flip($relativeLessFiles);
  55. // Change relative paths into absolute paths
  56. foreach ($relativeLessFiles as $relativeLessFile => $nothing) {
  57. $absoluteLessFiles[ROOT_PATH . "/less/" . $relativeLessFile] = "";
  58. }
  59. // Generate one minified CSS file into css/ from sources in less/
  60. $options = array(
  61. 'cache_dir' => ROOT_PATH . '/css/',
  62. 'compress' => true
  63. );
  64. $cssFileName = Less_Cache::Get($absoluteLessFiles, $options, THEME);
  65. ?>
  66. <!DOCTYPE html>
  67. <html lang="fr">
  68. <head>
  69. <meta charset="UTF-8">
  70. <title><?php
  71. if (isset($page['title']) AND $page['title'] != "Accueil")
  72. echo $page['title'] . " · ";
  73. if (isset($page['service'])) {
  74. echo $page['service'] . " · ";
  75. } ?>Niver</title>
  76. <link type="text/css" rel="stylesheet" href="<?= PREFIX ?>/css/<?= $cssFileName ?>">
  77. <meta name="viewport" content="width=device-width, initial-scale=1">
  78. </head>
  79. <body>
  80. <header>
  81. <nav>
  82. <a href="<?= PREFIX ?>">Niver</a><?php
  83. if (isset($page['service'])) {
  84. echo ' > <a href="./">' . $page['service'] . '</a>';
  85. }
  86. if (PAGE != "index")
  87. echo ' > <a href="' . PAGE . '">' . $page['title'] . "</a>";
  88. ?>
  89. </nav>
  90. <?php if (isset($page['title'])) { ?>
  91. <h1><?= $page['title'] ?></h1>
  92. <?php } ?>
  93. </header>
  94. <main>