libs/sysplugins/smarty_internal_smartytemplatecompiler.php Quellcode

smarty_internal_smartytemplatecompiler.php
gehe zur Dokumentation dieser Datei
1 <?php
14 //include 'smarty_internal_parsetree.php';
15 
23 {
29  public $lexer_class;
30 
36  public $parser_class;
37 
43  public $lex;
44 
50  public $parser;
51 
57  public $local_var = array();
58 
67  {
68  $this->smarty = $smarty;
69  parent::__construct();
70  // get required plugins
71  $this->lexer_class = $lexer_class;
72  $this->parser_class = $parser_class;
73  }
74 
82  protected function doCompile($_content, $isTemplateSource = false)
83  {
84  /* here is where the compiling takes place. Smarty
85  tags in the templates are replaces with PHP code,
86  then written to compiled files. */
87  // init the lexer/parser to compile the template
88  $this->lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this);
89  $this->parser = new $this->parser_class($this->lex, $this);
90  if ($isTemplateSource) {
91  $this->parser->insertPhpCode("<?php\n\$_smarty_tpl->properties['nocache_hash'] = '{$this->nocache_hash}';\n?>\n");
92  }
93  if ($this->inheritance_child) {
94  // start state on child templates
95  $this->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
96  }
97  if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
98  $mbEncoding = mb_internal_encoding();
99  mb_internal_encoding('ASCII');
100  } else {
101  $mbEncoding = null;
102  }
103 
104  if ($this->smarty->_parserdebug) {
105  $this->parser->PrintTrace();
106  $this->lex->PrintTrace();
107  }
108  // get tokens from lexer and parse them
109  while ($this->lex->yylex() && !$this->abort_and_recompile) {
110  if ($this->smarty->_parserdebug) {
111  echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " .
112  htmlentities($this->lex->value) . "</pre>";
113  }
114  $this->parser->doParse($this->lex->token, $this->lex->value);
115  }
116 
117  if ($this->abort_and_recompile) {
118  // exit here on abort
119  return false;
120  }
121  // finish parsing process
122  $this->parser->doParse(0, 0);
123  if ($mbEncoding) {
124  mb_internal_encoding($mbEncoding);
125  }
126  // check for unclosed tags
127  if (count($this->_tag_stack) > 0) {
128  // get stacked info
129  list($openTag, $_data) = array_pop($this->_tag_stack);
130  $this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag . "{$this->smarty->right_delimiter} tag");
131  }
132  // return compiled code
133  // return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
134  return $this->parser->retvalue;
135  }
136 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.