public function preParse() { global $tag_dictionary; if (! array_key_exists('file', $this->attributes) || empty($this->attributes['file'])) { throw new WactException('missing required attribute', array('tag' => $this->tag, 'attribute' => 'file', 'file' => $this->source_file, 'line' => $this->starting_line_no)); } $file = $this->attributes['file']; if (!$this->resolved_source_file = resolveTemplateSourceFileName($file)) { throw new WactException('missing file', array('tag' => $this->tag, 'srcfile' => $file, 'file' => $this->source_file, 'line' => $this->starting_line_no)); } if (array_key_exists('literal', $this->attributes)) { $literal_component = new TextNode(readTemplateFile($this->resolved_source_file)); $this->addChild($literal_component); } else { $sfp = new SourceFileParser($this->resolved_source_file, $tag_dictionary); $sfp->parse($this); } return PARSER_FORBID_PARSING; }
public function preParse() { global $tag_dictionary; $file = $this->attributes['file']; if (!isset($this->attributes['file']) || !$this->attributes['file']) { throw new WactException('missing required attribute', array('tag' => $this->tag, 'attribute' => 'file', 'file' => $this->source_file, 'line' => $this->starting_line_no)); } if (!$this->resolved_source_file = resolveTemplateSourceFileName($file)) { throw new WactException('missing file', array('tag' => $this->tag, 'srcfile' => $file, 'file' => $this->source_file, 'line' => $this->starting_line_no)); } $sfp = new SourceFileParser($this->resolved_source_file, $tag_dictionary); $sfp->parse($this); return PARSER_FORBID_PARSING; }
function __construct($file, $resolve_path = true) { $this->file = $file; if($resolve_path) { if(!$srcfile = resolveTemplateSourceFileName($file)) throw new FileNotFoundException('template file not found', $file); } else $srcfile = $file; $this->codefile = resolveTemplateCompiledFileName($srcfile); if (!isset($GLOBALS['template_render'][$this->codefile])) { if (Limb :: toolkit()->getINI('common.ini')->getOption('force_compile', 'Templates')) { include_once(LIMB_DIR . '/class/template/compiler/template_compiler.inc.php'); compileTemplateFile($file, $resolve_path); } if(!file_exists($this->codefile)) { include_once(LIMB_DIR . '/class/template/compiler/template_compiler.inc.php'); compileTemplateFile($file, $resolve_path); } $errorlevel = error_reporting(); if(!defined('DONT_LOWER_TEMPLATES_ERROR_REPORTING')) { error_reporting($errorlevel &~E_WARNING); } $parse_error = include_once($this->codefile); if(!defined('SET_TEMPLATES_ERROR_REPORTING')) error_reporting($errorlevel); } $this->render_function = $GLOBALS['template_render'][$this->codefile]; $func = $GLOBALS['template_construct'][$this->codefile]; $func($this); }
public function perform($request, $response) { if (($t = $request->get('t')) && is_array($t) && sizeof($t) > 0) { $this->history = $t; $template_path = end($this->history); } else { $template_path = TEMPLATE_FOR_HACKERS; } if (substr($template_path, -5, 5) != '.html') { $template_path = TEMPLATE_FOR_HACKERS; } if (substr($template_path, -5, 5) != '.html') { $request->setStatus(Request::STATUS_FAILURE); } try { $source_file_path = resolveTemplateSourceFileName($template_path); } catch (LimbException $e) { try { $source_file_path = resolveTemplateSourceFileName(TEMPLATE_FOR_HACKERS); } catch (LimbException $final_e) { $request->setStatus(Request::STATUS_FAILURE); return; } } $template_contents = file_get_contents($source_file_path); if (sizeof($this->history) > 1) { $tmp_history = $this->history; $from_template_path = $tmp_history[sizeof($tmp_history) - 2]; $tmp_history = array_splice($tmp_history, 0, sizeof($tmp_history) - 1); $history_query = 't[]=' . implode('&t[]=', $tmp_history); $this->view->set('history_query', $history_query); $this->view->set('from_template_path', $from_template_path); } $this->view->set('template_path', $template_path); $this->view->set('template_content', $this->_processTemplateContent($template_contents)); }
/** * Compiles a template file. Uses the file scheme to location the source, * instantiates the code_writer and root_compiler_component (as the root) component then * instantiates the source_file_parser to parse the template. * Creates the initialize and render functions in the compiled template. */ function compileTemplateFile($filename, $resolve_path = true) { global $tag_dictionary; if($resolve_path) { if(!$sourcefile = resolveTemplateSourceFileName($filename)) throw new FileNotFoundException('template file not found', $filename); } else $sourcefile = $filename; $destfile = resolveTemplateCompiledFileName($sourcefile); if (empty($sourcefile)) { throw new FileNotFoundException('compiled template file not found', $filename); } $code = new Codewriter(); $code->setFunctionPrefix(md5($destfile)); $tree = new RootCompilerComponent(); $tree->setSourceFile($sourcefile); $sfp = new SourceFileParser($sourcefile, $tag_dictionary); $sfp->parse($tree); $tree->prepare(); $render_function = $code->beginFunction('($dataspace)'); $tree->generate($code); $code->endFunction(); $construct_function = $code->beginFunction('($dataspace)'); $tree->generateConstructor($code); $code->endFunction(); $code->writePhp('$GLOBALS[\'template_render\'][$this->codefile] = \'' . $render_function . '\';'); $code->writePhp('$GLOBALS[\'template_construct\'][$this->codefile] = \'' . $construct_function . '\';'); writeTemplateFile($destfile, $code->getCode()); }