1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: |
|
10: |
|
11: | |
12: | |
13: | |
14: | |
15: | |
16: |
|
17: | class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase
|
18: | {
|
19: | |
20: | |
21: | |
22: | |
23: |
|
24: | public $lexer_class;
|
25: |
|
26: | |
27: | |
28: | |
29: | |
30: |
|
31: | public $parser_class;
|
32: |
|
33: | |
34: | |
35: | |
36: | |
37: |
|
38: | public $local_var = array();
|
39: |
|
40: | |
41: | |
42: | |
43: | |
44: |
|
45: | public $postCompileCallbacks = array();
|
46: |
|
47: | |
48: | |
49: | |
50: | |
51: |
|
52: | public $prefixCompiledCode = '';
|
53: |
|
54: | |
55: | |
56: | |
57: | |
58: |
|
59: | public $postfixCompiledCode = '';
|
60: |
|
61: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: |
|
68: | public function __construct($lexer_class, $parser_class, Smarty $smarty)
|
69: | {
|
70: | parent::__construct($smarty);
|
71: |
|
72: | $this->lexer_class = $lexer_class;
|
73: | $this->parser_class = $parser_class;
|
74: | }
|
75: |
|
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: |
|
85: | protected function doCompile($_content, $isTemplateSource = false)
|
86: | {
|
87: | |
88: | |
89: |
|
90: |
|
91: | $this->parser =
|
92: | new $this->parser_class(
|
93: | new $this->lexer_class(
|
94: | str_replace(
|
95: | array(
|
96: | "\r\n",
|
97: | "\r"
|
98: | ),
|
99: | "\n",
|
100: | $_content
|
101: | ),
|
102: | $this
|
103: | ),
|
104: | $this
|
105: | );
|
106: | if ($isTemplateSource && $this->template->caching) {
|
107: | $this->parser->insertPhpCode("<?php\n\$_smarty_tpl->compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n");
|
108: | }
|
109: | if (function_exists('mb_internal_encoding')
|
110: | && function_exists('ini_get')
|
111: | && ((int)ini_get('mbstring.func_overload')) & 2
|
112: | ) {
|
113: | $mbEncoding = mb_internal_encoding();
|
114: | mb_internal_encoding('ASCII');
|
115: | } else {
|
116: | $mbEncoding = null;
|
117: | }
|
118: | if ($this->smarty->_parserdebug) {
|
119: | $this->parser->PrintTrace();
|
120: | $this->parser->lex->PrintTrace();
|
121: | }
|
122: |
|
123: | while ($this->parser->lex->yylex()) {
|
124: | if ($this->smarty->_parserdebug) {
|
125: | echo "<pre>Line {$this->parser->lex->line} Parsing {$this->parser->yyTokenName[$this->parser->lex->token]} Token " .
|
126: | htmlentities($this->parser->lex->value) . "</pre>";
|
127: | }
|
128: | $this->parser->doParse($this->parser->lex->token, $this->parser->lex->value);
|
129: | }
|
130: |
|
131: | $this->parser->doParse(0, 0);
|
132: | if ($mbEncoding) {
|
133: | mb_internal_encoding($mbEncoding);
|
134: | }
|
135: |
|
136: | if (count($this->_tag_stack) > 0) {
|
137: |
|
138: | list($openTag, $_data) = array_pop($this->_tag_stack);
|
139: | $this->trigger_template_error(
|
140: | "unclosed {$this->smarty->left_delimiter}" . $openTag .
|
141: | "{$this->smarty->right_delimiter} tag"
|
142: | );
|
143: | }
|
144: |
|
145: | foreach ($this->postCompileCallbacks as $cb) {
|
146: | $parameter = $cb;
|
147: | $parameter[ 0 ] = $this;
|
148: | call_user_func_array($cb[ 0 ], $parameter);
|
149: | }
|
150: |
|
151: | return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode;
|
152: | }
|
153: |
|
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: |
|
163: | public function registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false)
|
164: | {
|
165: | array_unshift($parameter, $callback);
|
166: | if (isset($key)) {
|
167: | if ($replace || !isset($this->postCompileCallbacks[ $key ])) {
|
168: | $this->postCompileCallbacks[ $key ] = $parameter;
|
169: | }
|
170: | } else {
|
171: | $this->postCompileCallbacks[] = $parameter;
|
172: | }
|
173: | }
|
174: |
|
175: | |
176: | |
177: | |
178: | |
179: |
|
180: | public function unregisterPostCompileCallback($key)
|
181: | {
|
182: | unset($this->postCompileCallbacks[ $key ]);
|
183: | }
|
184: | }
|
185: | |