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