From 1b136555d279bf2cfb28f5661225c010426754f5 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 5 Oct 2011 15:22:53 +1100 Subject: transition to Twig --- inc/template.php | 180 ++++--------------------------------------------------- 1 file changed, 12 insertions(+), 168 deletions(-) (limited to 'inc/template.php') diff --git a/inc/template.php b/inc/template.php index 0c4268d6..5bee41ca 100644 --- a/inc/template.php +++ b/inc/template.php @@ -5,175 +5,14 @@ exit; } - // ----------------------------------------------------- - // Standard configuration - // - // Enable global things like %gentime, etc. - $templateGlobals = true; + require 'contrib/Twig/Autoloader.php'; + Twig_Autoloader::register(); - // If $templateGlobals is enabled. - // Do not change the keys, but the values (if you must), or it will not work. (Prefixed with %) - $templateGlobalsNames = Array( - 'gentime' => '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
'; } + $twig = new Twig_Environment($loader, Array( + 'autoescape' => false, + 'cache' => 'cache', + 'debug' => ($config['debug'] ? true : false), + )); + // Read the template file - if($template = @file_get_contents("{$config['dir']['template']}/${templateFile}")) { - return templateParse($template, $options, null, $templateFile); + if(@file_get_contents("{$config['dir']['template']}/${templateFile}")) { + return $twig->render($templateFile, $options); } else { throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!"); } } - ?> -- cgit v1.3