Просмотр исходного кода

Merge branch 'feature/maintenance-page' into develop

Alan Lam 7 лет назад
Родитель
Сommit
5df7daf8cc
5 измененных файлов с 68 добавлено и 12 удалено
  1. 3 0
      config.template.php
  2. 22 0
      engine/core.php
  3. 6 2
      router.php
  4. 2 10
      views/header.php
  5. 35 0
      views/maintenance_mode.php

+ 3 - 0
config.template.php

@@ -60,3 +60,6 @@ define("FPDF_FONTPATH", __DIR__ . "/fonts");
 
 define("TIMEZONE", "Europe/London");
 define("DEFAULT_COUNTRY", "United Kingdom");
+
+define("MAINTENANCE_MODE", false);
+define("MAINTENANCE_END_DATE", "31/12/2019");

+ 22 - 0
engine/core.php

@@ -133,4 +133,26 @@ class Core {
 		}
 	}
 
+	public static function isMaintenanceMode(): bool {
+		if(!defined("MAINTENANCE_MODE")) return false;
+		return (bool) MAINTENANCE_MODE;
+	}
+
+	public static function getMaintenanceEndDate(): string {
+		if(!defined("MAINTENANCE_END_DATE")) return "undefined";
+		return MAINTENANCE_END_DATE;
+	}
+
+	public static function isProduction(): bool {
+		return PRODUCTION;
+	}
+
+	public static function getLogo(): string {
+		return Core::isProduction() ? "img/logo.png" : "img/dev_logo.png";
+	}
+
+	public static function getIcon(): string {
+		return Core::isProduction() ? "img/icon.png" : "img/dev_icon.png";
+	}
+
 }

+ 6 - 2
router.php

@@ -4,6 +4,12 @@ try {
 
 	require "initialise.php";
 
+	if(Core::isMaintenanceMode()) {
+		http_response_code(503);
+		View::include("maintenance_mode");
+		exit;
+	}
+
 	// Load routes
 	require "routes.php";
 
@@ -127,5 +133,3 @@ catch (Exception $e) {
 	}
 
 }
-
-?>

+ 2 - 10
views/header.php

@@ -1,13 +1,5 @@
 <?php
 
-$logo = "/img/logo.png";
-$icon = "/img/icon.png";
-
-if(!PRODUCTION) {
-	$logo = "/img/dev_logo.png";
-	$icon = "/img/dev_icon.png";
-}
-
 $body_class = "";
 
 $print = http::value("print");
@@ -40,7 +32,7 @@ if($print) $body_class = "print";
 		}
 		?>
 
-		<link rel="icon" href="<?=$icon?>?<?=filemtime("public" . $icon)?>" />
+		<link rel="icon" href="/<?=Core::getIcon()?>?<?=filemtime("public/" . Core::getIcon())?>" />
 		<script type="text/javascript" src="/js/all.min.js?<?=filemtime("public/js/all.min.js")?>"></script>
 
 		<?php
@@ -65,7 +57,7 @@ if($print) $body_class = "print";
 			<nav class="navbar navbar-expand-lg navbar-light bg-light">
 				<div class="navbar-brand p-0">
 					<a href="/">
-						<img src="<?=$logo?>?<?=filemtime("public" . $logo)?>" style="height: 40px;" />
+						<img src="/<?=htmlspecialchars(Core::getLogo())?>?<?=filemtime("public/" . Core::getLogo())?>" style="height: 40px;" alt="<?=htmlspecialchars(APP_NAME)?>" />
 					</a>
 				</div>
 				<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="Toggle navigation">

+ 35 - 0
views/maintenance_mode.php

@@ -0,0 +1,35 @@
+<html>
+	<head>
+
+		<meta charset="utf-8" />
+		<meta http-equiv="x-ua-compatible" content="ie=edge" />
+		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
+		<title><?=htmlspecialchars(__("Maintenance In Progress"))?> | <?=htmlspecialchars(APP_NAME)?></title>
+
+		<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet" />
+
+		<?php
+		$stylesheets = Core::getStylesheets();
+		foreach($stylesheets as $stylesheet) {
+			HTML::stylesheet($stylesheet);
+		}
+		?>
+
+		<link rel="icon" href="/<?=Core::getIcon()?>?<?=filemtime("public/" . Core::getIcon())?>" />
+		<script type="text/javascript" src="/js/all.min.js?<?=filemtime("public/js/all.min.js")?>"></script>
+
+	</head>
+	<body class="d-flex justify-content-center" style="padding: 0; height: 100vh;">
+		<div class="card align-self-center border rounded bg-light text-dark" style="width: 50%;">
+			<div class="card-body text-center">
+				<p><img src="/<?=htmlspecialchars(Core::getLogo())?>" alt="<?=htmlspecialchars(APP_NAME)?>"></p>
+				<h3><?=htmlspecialchars(__("Maintenance In Progress"))?></h3>
+				<p><?=htmlspecialchars(__("%s is currently undergoing maintenance.", APP_NAME))?></p>
+				<p>
+					<strong><?=htmlspecialchars(__("Maintenance is expected to finish on %s.", MAINTENANCE_END_DATE))?></strong>
+				</p>
+			</div>
+
+		</div>
+	</body>
+</html>