kopia lustrzana https://github.com/jprochazka/adsb-receiver
Began working on better template system.
rodzic
e593c06160
commit
984d1ef10d
|
@ -28,23 +28,80 @@
|
|||
// SOFTWARE. //
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class sysinfo {
|
||||
/*
|
||||
|
||||
function memoryUsage(){
|
||||
$free = shell_exec('free');
|
||||
$free = (string)trim($free);
|
||||
$free_arr = explode("\n", $free);
|
||||
$mem = explode(" ", $free_arr[1]);
|
||||
$mem = array_filter($mem);
|
||||
$mem = array_merge($mem);
|
||||
$memory_usage = $mem[2]/$mem[1]*100;
|
||||
return $memoryUsage;
|
||||
{area:name}
|
||||
{$variable}
|
||||
{* comment *}
|
||||
|
||||
*/
|
||||
|
||||
class template {
|
||||
|
||||
// PUT THE TEMPLATE TOGETHER
|
||||
|
||||
function display($page) {
|
||||
// Load the master template.
|
||||
$master = $this->readTemplate('master.tpl.php');
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function cpuUsage(){
|
||||
$load = sys_getloadavg();
|
||||
return $load[0];
|
||||
|
||||
// TEMPLATE SYSTEM FUNCTIONS
|
||||
|
||||
// Return the contents of the requested template.
|
||||
function readTemplate($template) {
|
||||
$common = new Common($this);
|
||||
return file_get_contents($_SERVER['DOCUMENT_ROOT']."/templates/".$common->getSetting('language')."/".$template, "r");
|
||||
}
|
||||
|
||||
|
||||
function mergeAreas($master, $template) {
|
||||
$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) {
|
||||
$content = extractString($template, '{area:'.$id.'}', '{/area}');
|
||||
$master = str_replace("{area:'.$id.'}", $content, $master);
|
||||
} else {
|
||||
$master = str_replace("{area:'.$id.'}", "", $master);
|
||||
}
|
||||
}
|
||||
return $master;
|
||||
}
|
||||
|
||||
function mergeComments($template) {
|
||||
|
||||
}
|
||||
|
||||
function mergeVariables($template) {
|
||||
|
||||
}
|
||||
|
||||
function processIfs($template) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Function that returns the string contained between two strings.
|
||||
function extractString($string, $start, $end) {
|
||||
$string = " ".$string;
|
||||
$ini = strpos($string, $start);
|
||||
if ($ini == 0) return "";
|
||||
$ini += strlen($start);
|
||||
$len = strpos($string, $end, $ini) - $ini;
|
||||
return substr($string, $ini, $len);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,47 +1,51 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<settings>
|
||||
<setting>
|
||||
<name>siteName</name>
|
||||
<value>ADS-B Feeder</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>template</name>
|
||||
<value>default</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>defaultPage</name>
|
||||
<value>blog</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableBlog</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableInfo</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableGraphs</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableDump1090</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableDump978</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enablePfclient</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>measurement</name>
|
||||
<value>imperial</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>networkInterface</name>
|
||||
<value>eth0</value>
|
||||
</setting>
|
||||
</settings>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<settings>
|
||||
<setting>
|
||||
<name>siteName</name>
|
||||
<value>ADS-B Feeder</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>template</name>
|
||||
<value>default</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>defaultPage</name>
|
||||
<value>blog</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableBlog</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableInfo</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableGraphs</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableDump1090</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enableDump978</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>enablePfclient</name>
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>measurement</name>
|
||||
<value>imperial</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>networkInterface</name>
|
||||
<value>eth0</value>
|
||||
</setting>
|
||||
<setting>
|
||||
<name>language</name>
|
||||
<value>en-us</value>
|
||||
</setting>
|
||||
</settings>
|
||||
|
|
|
@ -33,14 +33,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";
|
||||
|
||||
// Get the name of the template to use from the settings.
|
||||
$siteName = $common->getSetting("siteName");
|
||||
$template = $common->getSetting("template");
|
||||
|
||||
// Enable/disable navigation links.
|
||||
$enableBlog = $common->getSetting("enableBlog");
|
||||
|
@ -51,10 +52,6 @@
|
|||
$enablePfclient = $common->getSetting("enablePfclient");
|
||||
|
||||
$linkId = $common->removeExtension($_SERVER["SCRIPT_NAME"])."-link";
|
||||
|
||||
// Include the index template.
|
||||
require_once('templates/'.$template.'/system.tpl.php');
|
||||
|
||||
// Include the master template.
|
||||
require_once('templates/'.$template.'/master.tpl.php');
|
||||
$template->display("system");
|
||||
?>
|
||||
|
|
|
@ -23,15 +23,13 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><?php echo $siteName ?>: <?php echo $pageTitle; ?></title>
|
||||
<title>{$siteName}: {$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/<?php echo $template; ?>/assets/css/portal.css">
|
||||
<?php
|
||||
headContent();
|
||||
?>
|
||||
<link rel="stylesheet" href="/templates/{$template}/assets/css/portal.css">
|
||||
{area:head}
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
|
@ -44,23 +42,21 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="/"><?php echo $siteName; ?></title></a>
|
||||
<a class="navbar-brand" href="/">{$siteName}</title></a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<?php ($enableBlog == 1 ? print '<li id="blog-link"><a href="/blog/">Blog</a></li>' : ''); ?>
|
||||
<?php ($enableInfo == 1 ? print '<li id="system-link"><a href="/system.php">System Information</a></li>' : ''); ?>
|
||||
<?php ($enableGraphs == 1 ? print '<li id="graphs-link"><a href="/graphs.php">Performance Graphs</a></li>' : ''); ?>
|
||||
<?php ($enableDump1090 == 1 ? print '<li id="dump1090-link"><a href="/dump1090.php">Live Dump1090 Map</a></li>' : ''); ?>
|
||||
<?php ($enableDump978 == 1 ? print '<li id="dump978-link"><a href="/dump978.php">Live Dump978 Map</a></li>' : ''); ?>
|
||||
<?php ($enablePfclient == 1 ? print '<!-- Plane Finder ADS-B Client Link Placeholder -->' : ''); ?>
|
||||
{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}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<?php
|
||||
pageContent();
|
||||
?>
|
||||
{area:content}
|
||||
<div id="push"></div>
|
||||
</div>
|
||||
<footer id="footer">
|
||||
|
@ -73,10 +69,8 @@
|
|||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$('#<?php echo $linkId ?>').addClass("active");
|
||||
$('#{$id}').addClass("active");
|
||||
</script>
|
||||
<?php
|
||||
scriptContent();
|
||||
?>
|
||||
{area:scripts}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -18,21 +18,13 @@
|
|||
// A copy of the license can be found package along with these files. //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////
|
||||
// Additional <head> content.
|
||||
function headContent() { }
|
||||
|
||||
///////////////////
|
||||
// Page content.
|
||||
function pageContent() {
|
||||
?>
|
||||
{area:head}
|
||||
<style></style>
|
||||
{/area}
|
||||
{area:contents}
|
||||
<div class="container">
|
||||
<h1>System information coming soon...</h1>
|
||||
<h1>{$comingSoon}</h1>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Content to be added to the scripts section.
|
||||
function scriptContent() {}
|
||||
?>
|
||||
{/area}
|
||||
{area:scripts/}
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<strings>
|
||||
<string id="comingSoon">System information coming soon...</string>
|
||||
</strings>
|
Ładowanie…
Reference in New Issue