Code

Updated smarty
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_smartytemplatecompiler.php
1 <?php
3 /**
4 * Smarty Internal Plugin Smarty Template Compiler Base
5
6 * This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
7
8 * @package Smarty
9 * @subpackage Compiler
10 * @author Uwe Tews 
11 */
12 require_once("smarty_internal_parsetree.php");
13 /**
14 * Class SmartyTemplateCompiler
15 */
16 class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase {
17     /**
18     * Initialize compiler
19     */
20     public function __construct($lexer_class, $parser_class, $smarty)
21     {
22         $this->smarty = $smarty;
23         parent::__construct(); 
24         // get required plugins
25         $this->lexer_class = $lexer_class;
26         $this->parser_class = $parser_class;
27     } 
29     /**
30     * Methode to compile a Smarty template
31     * 
32     * @param  $_content template source
33     * @return bool true if compiling succeeded, false if it failed
34     */
35     protected function doCompile($_content)
36     {
37         /* here is where the compiling takes place. Smarty
38        tags in the templates are replaces with PHP code,
39        then written to compiled files. */ 
40         // init the lexer/parser to compile the template
41         $this->lex = new $this->lexer_class($_content, $this);
42         $this->parser = new $this->parser_class($this->lex, $this); 
43         if (isset($this->smarty->_parserdebug)) $this->parser->PrintTrace();
44         // get tokens from lexer and parse them
45         while ($this->lex->yylex() && !$this->abort_and_recompile) {
46             if (isset($this->smarty->_parserdebug)) echo "<pre>Line {$this->lex->line} Parsing  {$this->parser->yyTokenName[$this->lex->token]} Token ".htmlentities($this->lex->value)."</pre>";
47             $this->parser->doParse($this->lex->token, $this->lex->value);
48         } 
50         if ($this->abort_and_recompile) {
51             // exit here on abort
52             return false;
53         } 
54         // finish parsing process
55         $this->parser->doParse(0, 0); 
56         // check for unclosed tags
57         if (count($this->_tag_stack) > 0) {
58             // get stacked info
59             list($_open_tag, $_data) = array_pop($this->_tag_stack);
60             $this->trigger_template_error("unclosed {" . $_open_tag . "} tag");
61         } 
63         if (!$this->compile_error) {
64             // return compiled code
65             // return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
66             return $this->parser->retvalue;
67         } else {
68             // compilation error
69             return false;
70         } 
71     } 
72
74 ?>