kopia lustrzana https://github.com/jprochazka/adsb-receiver
Template system work.
rodzic
118f41ebdd
commit
69b8544b8f
|
@ -29,15 +29,21 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
|
||||
====================
|
||||
TEMPLATE ELEMENTS:
|
||||
====================
|
||||
{area:name}
|
||||
{$variable}
|
||||
{setting:name}
|
||||
{page:variable}
|
||||
{string:id}
|
||||
{* comment *}
|
||||
|
||||
====================
|
||||
*/
|
||||
|
||||
class template {
|
||||
|
||||
var $pageData;
|
||||
|
||||
// PUT THE TEMPLATE TOGETHER
|
||||
|
||||
function display($page) {
|
||||
|
@ -47,11 +53,14 @@
|
|||
// Load the template for the requested page.
|
||||
$page = $this->readTemplate($page.'.tpl.php');
|
||||
|
||||
$output = $master;
|
||||
$output = mergeAreas($output, $page);
|
||||
$output = mergeComments($output);
|
||||
$output = mergeVariables($output);
|
||||
|
||||
$output = $this->mergeAreas($master, $page);
|
||||
$output = $this->mergeSettings($output);
|
||||
$output = $this->mergeStrings($output);
|
||||
$output = $this->mergePageData($output);
|
||||
$output = $this->removeComments($output);
|
||||
|
||||
// Insert page ID mainly used to mark an active navigation link when using Bootstrap.
|
||||
$output = str_replace("{template:pageId}", $common->removeExtension($_SERVER["SCRIPT_NAME"])."-link", $output);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
@ -70,8 +79,8 @@
|
|||
$pattern = '\{area:(.*)/\}#U';
|
||||
preg_match_all($pattern, $master, $areas, PREG_PATTERN_ORDER);
|
||||
foreach ($areas[0] as $element) {
|
||||
$id = extractString($element, 'id="', '"');
|
||||
if if (strpos($template, '{area:'.$id.'/}') !== TRUE) {
|
||||
$id = extractString($element, ':', '}');
|
||||
if (strpos($template, '{area:'.$id.'/}') !== TRUE) {
|
||||
$content = extractString($template, '{area:'.$id.'}', '{/area}');
|
||||
$master = str_replace("{area:'.$id.'}", $content, $master);
|
||||
} else {
|
||||
|
@ -81,16 +90,86 @@
|
|||
return $master;
|
||||
}
|
||||
|
||||
function mergeComments($template) {
|
||||
|
||||
function mergeSettings($output) {
|
||||
$common = new Common($this);
|
||||
$pattern = '\{setting:(.*)/\}#U';
|
||||
preg_match_all($pattern, $output, $settings, PREG_PATTERN_ORDER);
|
||||
foreach ($settings[0] as $element) {
|
||||
$name = extractString($element, ':', '}');
|
||||
$value = $common->getSetting($name);
|
||||
$output = str_replace("{setting:'.$name.'}", $value, $output);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function mergeVariables($template) {
|
||||
|
||||
function mergeStrings($output) {
|
||||
|
||||
}
|
||||
|
||||
function processIfs($template) {
|
||||
function mergePageData($output) {
|
||||
$pattern = '\{page:(.*)/\}#U';
|
||||
preg_match_all($pattern, $output, $pageVariables, PREG_PATTERN_ORDER);
|
||||
foreach ($pageVariables[0] as $element) {
|
||||
$variable = extractString($element, ':', '}');
|
||||
foreach ($pageData as $key => $value) {
|
||||
if ($key == $variable) {
|
||||
$output = str_replace("{page:'.$variable.'}", $value, $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeComments($output) {
|
||||
$pattern = '\{\*:(.*)/\*\}#U';
|
||||
preg_match_all($pattern, $output, $comments, PREG_PATTERN_ORDER);
|
||||
foreach ($comments[0] as $element) {
|
||||
$output = str_replace($element, "", $output);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function processIfs($output) {
|
||||
$common = new Common($this);
|
||||
$pattern = '\{if (.*)/\*{/if}#U';
|
||||
preg_match_all($pattern, $output, $ifs, PREG_PATTERN_ORDER);
|
||||
foreach ($ifs[0] as $element) {
|
||||
|
||||
if (strpos($element, ' eq ') !== FALSE){
|
||||
$operator == "eq";
|
||||
} else {
|
||||
$operator == "neq";
|
||||
}
|
||||
|
||||
$ifThis = extractString($element, "{if ", " ");
|
||||
if (strpos($element, 'setting:') !== FALSE) {
|
||||
$ifThis = $common->getSetting(extractString($element, "{if setting:", " "));
|
||||
} elseif (strpos($element, 'page:') !== FALSE) {
|
||||
$variable = extractString($element, "{if page:", " ");
|
||||
foreach ($pageData as $key => $value) {
|
||||
if ($key == $variable) {
|
||||
$ifThis = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$that = extractString($element, " ".$operator." ", "}")
|
||||
$content = extractString($element, "}", "{/if}")
|
||||
|
||||
if ($operator == "eq") {
|
||||
if ($ifThis == $that) {
|
||||
$output = str_replace($element, $content, $output);
|
||||
} else {
|
||||
$output = str_replace($element, "", $output);
|
||||
}
|
||||
} else {
|
||||
if ($ifThis != $that) {
|
||||
$output = str_replace($element, $content, $output);
|
||||
} else {
|
||||
$output = str_replace($element, "", $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,24 +34,15 @@
|
|||
// Load the common PHP classes.
|
||||
require_once('classes/common.class.php');
|
||||
require_once('classes/template.class.php');
|
||||
|
||||
$common = new common();
|
||||
$template = new template();
|
||||
|
||||
// The title and navigation link ID of this page.
|
||||
$pageTitle = "System Information";
|
||||
$pageData = array();
|
||||
|
||||
// Get the name of the template to use from the settings.
|
||||
$siteName = $common->getSetting("siteName");
|
||||
|
||||
// Enable/disable navigation links.
|
||||
$enableBlog = $common->getSetting("enableBlog");
|
||||
$enableInfo = $common->getSetting("enableInfo");
|
||||
$enableGraphs = $common->getSetting("enableGraphs");
|
||||
$enableDump1090 = $common->getSetting("enableDump1090");
|
||||
$enableDump978 = $common->getSetting("enableDump978");
|
||||
$enablePfclient = $common->getSetting("enablePfclient");
|
||||
|
||||
$linkId = $common->removeExtension($_SERVER["SCRIPT_NAME"])."-link";
|
||||
// The title of this page.
|
||||
$pageData['title'] = "System Information";
|
||||
|
||||
$template->pageData = $pageData;
|
||||
$template->display("system");
|
||||
?>
|
||||
|
|
|
@ -5,17 +5,17 @@
|
|||
// ========================================================================== //
|
||||
// Template Set: default //
|
||||
// Template Name: master //
|
||||
// Version: 1.0.0 //
|
||||
// Release Date: //
|
||||
// Author: Joe Prochazka //
|
||||
// Version: 2.0.0 //
|
||||
// Release Date: February 5th, 2016 //
|
||||
// Author: Joseph A. Prochazka //
|
||||
// Website: https://www.swiftbyte.com //
|
||||
// ========================================================================== //
|
||||
// Copyright and Licensing Information: //
|
||||
// //
|
||||
// Copyright (c) 2015 Joseph A. Prochazka //
|
||||
// Copyright (c) 2015-2016 Joseph A. Prochazka //
|
||||
// //
|
||||
// This template set is licensed under The MIT License (MIT) //
|
||||
// A copy of the license can be found package along with these files. //
|
||||
// A copy of the license can be found packaged along with these files. //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
?>
|
||||
|
@ -23,12 +23,12 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{$siteName}: {$title}</title>
|
||||
<title>{setting:siteName}: {page:title}</title>
|
||||
<meta http-equiv="cache-control" content="no-cache" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
|
||||
<link rel="stylesheet" href="/templates/{$template}/assets/css/portal.css">
|
||||
<link rel="stylesheet" href="/templates/{setting:template}/assets/css/portal.css">
|
||||
{area:head}
|
||||
</head>
|
||||
<body>
|
||||
|
@ -42,16 +42,16 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="/">{$siteName}</title></a>
|
||||
<a class="navbar-brand" href="/">{setting:siteName}</title></a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
{if $enableBlog}<li id="blog-link"><a href="/blog/">Blog</a></li>{/if}
|
||||
{if $enableInfo}<li id="system-link"><a href="/system.php">System Information</a></li>{/if}
|
||||
{if $enableGraphs}<li id="graphs-link"><a href="/graphs.php">Performance Graphs</a></li>{/if}
|
||||
{if $enableDump1090}<li id="dump1090-link"><a href="/dump1090.php">Live Dump1090 Map</a></li>{/if}
|
||||
{if $enableDump978}<li id="dump978-link"><a href="/dump978.php">Live Dump978 Map</a></li>{/if}
|
||||
{if $enableDump978}<!-- Plane Finder ADS-B Client Link Placeholder -->{/if}
|
||||
{if setting:enableBlog eq TRUE}<li id="blog-link"><a href="/blog/">Blog</a></li>{/if}
|
||||
{if setting:enableInfo eq TRUE}<li id="system-link"><a href="/system.php">System Information</a></li>{/if}
|
||||
{if setting:enableGraphs eq TRUE}<li id="graphs-link"><a href="/graphs.php">Performance Graphs</a></li>{/if}
|
||||
{if setting:enableDump1090 eq TRUE}<li id="dump1090-link"><a href="/dump1090.php">Live Dump1090 Map</a></li>{/if}
|
||||
{if setting:enableDump978 eq TRUE}<li id="dump978-link"><a href="/dump978.php">Live Dump978 Map</a></li>{/if}
|
||||
{if setting:enablePfclient eq TRUE}<!-- Plane Finder ADS-B Client Link Placeholder -->{/if}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -69,7 +69,7 @@
|
|||
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$('#{$id}').addClass("active");
|
||||
$('#{template:pageId}').addClass("active");
|
||||
</script>
|
||||
{area:scripts}
|
||||
</body>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
{/area}
|
||||
{area:contents}
|
||||
<div class="container">
|
||||
<h1>{$comingSoon}</h1>
|
||||
<h1>System information coming soon...</h1>
|
||||
</div>
|
||||
{/area}
|
||||
{area:scripts/}
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<strings>
|
||||
<string id="comingSoon">System information coming soon...</string>
|
||||
</strings>
|
Ładowanie…
Reference in New Issue