Эх сурвалжийг харах

Better header reuse. Use SSL jquery when serving via HTTPS.

Zachary Kotlarek 12 жил өмнө
parent
commit
3321375463

+ 68 - 0
web/includes/header.php

@@ -0,0 +1,68 @@
+<?
+
+# Generic XHTML 1.1 header
+function printHeader($title) {
+	print <<<ENDOLA
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
+   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+	<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
+	<title>${title}</title>
+ENDOLA;
+
+	printJQuery();
+
+	echo '</head><body>';
+}
+
+# Generic XHTML 1.1 footer
+function printFooter() {
+	print <<<ENDOLA
+</body>
+</html>
+ENDOLA;
+}
+
+function printJQuery() {
+	# Determine our protocol
+	$protocol = 'http';
+	if ($_SERVER['HTTPS']) {
+		$protocol = 'https';
+	}
+
+	# Print
+	echo <<<ENDOLA
+<!-- Default JQuery -->
+<script src="${protocol}://code.jquery.com/jquery-1.9.1.min.js"></script>
+
+<!-- Provide # support in JQuery-mobile autodividers -->
+<!-- Must be loaded before JQuery-mobile  -->
+<script>
+$( document ).on( "mobileinit", function() {
+	$.mobile.listview.prototype.options.autodividersSelector = function( elt ) {
+		var text = $.trim( elt.text() ) || null;
+		if ( !text ) {
+			return null;
+		}
+		if ( !isNaN(parseFloat(text)) ) {
+			return "#";
+		} else {
+			text = text.slice( 0, 1 ).toUpperCase();
+			return text;
+		}
+	};
+});
+</script>
+
+<!-- Default JQuery-mobile -->
+<link rel="stylesheet" href="${protocol}://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
+<script src="${protocol}://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
+
+<!-- Custom code for the linkbar -->
+<script src="autodividers-linkbar.js"></script>
+<link rel="stylesheet" href="autodividers-linkbar.css">
+ENDOLA;
+}
+
+?>

+ 1 - 0
web/includes/main.php

@@ -3,6 +3,7 @@
 require 'config.php';
 
 require_once 'auth.php';
+require_once 'header.php';
 
 require_once 'util.php';
 require_once 'webloc.php';

+ 3 - 47
web/index.php

@@ -80,48 +80,7 @@ if ($series === false && isset($_POST['series_add'])) {
 
 #=========================================================================================
 
-# Generic XHTML 1.1 header
-print <<<ENDOLA
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
-   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-	<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
-	<title>UberZach TV</title>
-
-	<!-- Default JQuery -->
-	<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
-
-	<!-- Provide # support in JQuery-mobile autodividers -->
-	<!-- Must be loaded before JQuery-mobile  -->
-	<script>
-	$( document ).on( "mobileinit", function() {
-		$.mobile.listview.prototype.options.autodividersSelector = function( elt ) {
-			var text = $.trim( elt.text() ) || null;
-			if ( !text ) {
-				return null;
-			}
-			if ( !isNaN(parseFloat(text)) ) {
-				return "#";
-			} else {
-				text = text.slice( 0, 1 ).toUpperCase();
-				return text;
-			}
-		};
-	});
-	</script>
-
-	<!-- Default JQuery-mobile -->
-	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
-	<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
-
-	<!-- Custom code for the linkbar -->
-	<script src="autodividers-linkbar.js"></script>
-	<link rel="stylesheet" href="autodividers-linkbar.css">
-</head>
-<body>
-
-ENDOLA;
+printHeader('UberZach TV');
 
 if ($series === false) {
 	printAllSeries();
@@ -129,9 +88,6 @@ if ($series === false) {
 	printSeries($series);
 }
 
-# Generic XHTML 1.1 footer
-print <<<ENDOLA
-</body>
-</html>
-ENDOLA;
+printFooter();
+
 ?>

+ 3 - 48
web/login.php

@@ -23,48 +23,7 @@ if (authenticated()) {
 
 #=========================================================================================
 
-# Generic XHTML 1.1 header
-print <<<ENDOLA
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
-   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-	<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
-	<title>UberZach TV - Login</title>
-
-	<!-- Default JQuery -->
-	<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
-
-	<!-- Provide # support in JQuery-mobile autodividers -->
-	<!-- Must be loaded before JQuery-mobile  -->
-	<script>
-	$( document ).on( "mobileinit", function() {
-		$.mobile.listview.prototype.options.autodividersSelector = function( elt ) {
-			var text = $.trim( elt.text() ) || null;
-			if ( !text ) {
-				return null;
-			}
-			if ( !isNaN(parseFloat(text)) ) {
-				return "#";
-			} else {
-				text = text.slice( 0, 1 ).toUpperCase();
-				return text;
-			}
-		};
-	});
-	</script>
-
-	<!-- Default JQuery-mobile -->
-	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
-	<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
-
-	<!-- Custom code for the linkbar -->
-	<script src="autodividers-linkbar.js"></script>
-	<link rel="stylesheet" href="autodividers-linkbar.css">
-</head>
-<body>
-
-ENDOLA;
+printHeader('UberZach TV - Login');
 
 $url = $_SERVER['PHP_SELF'];
 if (isset($_GET['dest'])) {
@@ -81,12 +40,8 @@ print <<<ENDOLA
 <p><input type="submit" name="login" value="Login" /></p>
 </form>
 </div>
-
 ENDOLA;
 
-# Generic XHTML 1.1 footer
-print <<<ENDOLA
-</body>
-</html>
-ENDOLA;
+printFooter();
+
 ?>