From 3d92990b1817ac20935274682764711080e8b254 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Tue, 2 Nov 2010 21:57:33 +1100 Subject: first commit --- inc/template.php | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 inc/template.php (limited to 'inc/template.php') diff --git a/inc/template.php b/inc/template.php new file mode 100644 index 00000000..95fa2ff7 --- /dev/null +++ b/inc/template.php @@ -0,0 +1,182 @@ + 'gentime', + 'template' => 'template' + ); + + // Allow {$phpvar}, etc, to be placed in the template file. This will use a (global) variable defined in PHP. + // Requires eval() to be enabled. Might be a security risk, so ensure your template files aren't writable before + // enabling this. (Prefixed with $) + $templateVariables = false; + + // End config + // ----------------------------------------------------- + + //'/\{(!?[$%]?[\w\[\]]+)(([=\?:])(([^{^}]|\{.+?\})?)?\}/s' + + + + + // Don't change this if you don't know what you're doing. + // EXTREMELY CONFUSING RECURSION! + $templateRegex = '/\{(!?[$%]?[\w\[\]]+)(([=\?:])((?>[^{^}]|\{[^{^}]+\}|(?R))+?))?\}/s'; + + function templateParse($template, array $options, $globals = null, $templateFile = null) { + global $templateGlobals, $templateGlobalsNames, $templateVariables, $templateRegex; + //For the global variable {%gentime} + if($globals == null) { + $globals = Array(); + if(isset($templateFile)) $globals['template'] = $templateFile; + $globals['gentime'] = microtime(true); + } + + // What we'll end up finishing with + $templateBody = ''; + + $previousPosition = 0; + // Find the matches + if(preg_match_all($templateRegex, $template, $templateMatch)) { + //Iterate through matches + for($matchIndex=0;$matchIndex \ No newline at end of file -- cgit v1.3