'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
'; } // Read the template file if($template = @file_get_contents("{$config['dir']['template']}/${templateFile}")) { return templateParse($template, $options, null, $templateFile); } else { throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!"); } } ?>