From 69b8544b8fa904fd736fffababdd84c9b1abda3f Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Fri, 5 Feb 2016 16:07:47 -0500 Subject: [PATCH] Template system work. --- build/portal/html/classes/template.class.php | 109 +++++++++++++++--- build/portal/html/system.php | 19 +-- .../html/templates/default/master.tpl.php | 30 ++--- .../html/templates/default/system.tpl.php | 2 +- .../portal/html/translations/en-us/system.xml | 4 - 5 files changed, 115 insertions(+), 49 deletions(-) delete mode 100644 build/portal/html/translations/en-us/system.xml diff --git a/build/portal/html/classes/template.class.php b/build/portal/html/classes/template.class.php index e2fced3..cbfc135 100644 --- a/build/portal/html/classes/template.class.php +++ b/build/portal/html/classes/template.class.php @@ -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; } diff --git a/build/portal/html/system.php b/build/portal/html/system.php index c4e1f8e..4b60954 100644 --- a/build/portal/html/system.php +++ b/build/portal/html/system.php @@ -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"); ?> diff --git a/build/portal/html/templates/default/master.tpl.php b/build/portal/html/templates/default/master.tpl.php index 1984543..c974ded 100644 --- a/build/portal/html/templates/default/master.tpl.php +++ b/build/portal/html/templates/default/master.tpl.php @@ -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 @@ - {$siteName}: {$title} + {setting:siteName}: {page:title} - + {area:head} @@ -42,16 +42,16 @@ - {$siteName} + {setting:siteName} @@ -69,7 +69,7 @@ {area:scripts} diff --git a/build/portal/html/templates/default/system.tpl.php b/build/portal/html/templates/default/system.tpl.php index a21b377..55f6fbd 100644 --- a/build/portal/html/templates/default/system.tpl.php +++ b/build/portal/html/templates/default/system.tpl.php @@ -24,7 +24,7 @@ {/area} {area:contents}
-

{$comingSoon}

+

System information coming soon...

{/area} {area:scripts/} \ No newline at end of file diff --git a/build/portal/html/translations/en-us/system.xml b/build/portal/html/translations/en-us/system.xml deleted file mode 100644 index 8a1109d..0000000 --- a/build/portal/html/translations/en-us/system.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - System information coming soon... - \ No newline at end of file