diff --git a/build/portal/html/classes/sysinfo.class.php b/build/portal/html/classes/template.class.php similarity index 52% rename from build/portal/html/classes/sysinfo.class.php rename to build/portal/html/classes/template.class.php index e94a814..e2fced3 100644 --- a/build/portal/html/classes/sysinfo.class.php +++ b/build/portal/html/classes/template.class.php @@ -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); + } } ?> \ No newline at end of file diff --git a/build/portal/html/data/settings.xml b/build/portal/html/data/settings.xml index b4cd10d..befc135 100644 --- a/build/portal/html/data/settings.xml +++ b/build/portal/html/data/settings.xml @@ -1,47 +1,51 @@ - - - - siteName - ADS-B Feeder - - - template - default - - - defaultPage - blog - - - enableBlog - 1 - - - enableInfo - 1 - - - enableGraphs - 1 - - - enableDump1090 - 1 - - - enableDump978 - 1 - - - enablePfclient - 1 - - - measurement - imperial - - - networkInterface - eth0 - - + + + + siteName + ADS-B Feeder + + + template + default + + + defaultPage + blog + + + enableBlog + 1 + + + enableInfo + 1 + + + enableGraphs + 1 + + + enableDump1090 + 1 + + + enableDump978 + 1 + + + enablePfclient + 1 + + + measurement + imperial + + + networkInterface + eth0 + + + language + en-us + + diff --git a/build/portal/html/system.php b/build/portal/html/system.php index 94b78da..c4e1f8e 100644 --- a/build/portal/html/system.php +++ b/build/portal/html/system.php @@ -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"); ?> diff --git a/build/portal/html/templates/default/master.tpl.php b/build/portal/html/templates/default/master.tpl.php index 8209845..136bcef 100644 --- a/build/portal/html/templates/default/master.tpl.php +++ b/build/portal/html/templates/default/master.tpl.php @@ -23,15 +23,13 @@ - <?php echo $siteName ?>: <?php echo $pageTitle; ?> + {$siteName}: {$title} - - + + {area:head}
@@ -44,23 +42,21 @@ - + {$siteName}
- + {area:content}