Code

dcc89c6736a473c78cc23e199d9a7e27f1164b8c
[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  */
13 require_once("smarty_internal_parsetree.php");
15 /**
16  * Class SmartyTemplateCompiler
17  */
18 class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase {
19     // array of vars which can be compiled in local scope
20     public $local_var = array();
21     /**
22      * Initialize compiler
23      */
24     public function __construct($lexer_class, $parser_class, $smarty)
25     {
26         $this->smarty = $smarty;
27         parent::__construct(); 
28         // get required plugins
29         $this->lexer_class = $lexer_class;
30         $this->parser_class = $parser_class;
31     } 
33     /**
34      * Methode to compile a Smarty template
35      * 
36      * @param  $_content template source
37      * @return bool true if compiling succeeded, false if it failed
38      */
39     protected function doCompile($_content)
40     {
41         /* here is where the compiling takes place. Smarty
42        tags in the templates are replaces with PHP code,
43        then written to compiled files. */ 
44         // init the lexer/parser to compile the template
45         $this->lex = new $this->lexer_class($_content, $this);
46         $this->parser = new $this->parser_class($this->lex, $this);
47         if (isset($this->smarty->_parserdebug)) $this->parser->PrintTrace(); 
48         // get tokens from lexer and parse them
49         while ($this->lex->yylex() && !$this->abort_and_recompile) {
50             if (isset($this->smarty->_parserdebug)) echo "<pre>Line {$this->lex->line} Parsing  {$this->parser->yyTokenName[$this->lex->token]} Token " . htmlentities($this->lex->value) . "</pre>";
51             $this->parser->doParse($this->lex->token, $this->lex->value);
52         } 
54         if ($this->abort_and_recompile) {
55             // exit here on abort
56             return false;
57         } 
58         // finish parsing process
59         $this->parser->doParse(0, 0); 
60         // check for unclosed tags
61         if (count($this->_tag_stack) > 0) {
62             // get stacked info
63             list($_open_tag, $_data) = array_pop($this->_tag_stack);
64             $this->trigger_template_error("unclosed {" . $_open_tag . "} tag");
65         } 
66         // return compiled code
67         // return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
68         return $this->parser->retvalue;
69     } 
70
72 ?>