Редакция 2 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 2 | Редакция 58 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | 2 | ||
3 | /**
|
3 | /**
|
4 | * Project: Smarty: the PHP compiling template engine
|
4 | * Project: Smarty: the PHP compiling template engine
|
5 | * File: Smarty.class.php
|
5 | * File: Smarty.class.php
|
6 | *
|
6 | *
|
7 | * This library is free software; you can redistribute it and/or
|
7 | * This library is free software; you can redistribute it and/or
|
8 | * modify it under the terms of the GNU Lesser General Public
|
8 | * modify it under the terms of the GNU Lesser General Public
|
9 | * License as published by the Free Software Foundation; either
|
9 | * License as published by the Free Software Foundation; either
|
10 | * version 2.1 of the License, or (at your option) any later version.
|
10 | * version 2.1 of the License, or (at your option) any later version.
|
11 | *
|
11 | *
|
12 | * This library is distributed in the hope that it will be useful,
|
12 | * This library is distributed in the hope that it will be useful,
|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 | * Lesser General Public License for more details.
|
15 | * Lesser General Public License for more details.
|
16 | *
|
16 | *
|
17 | * You should have received a copy of the GNU Lesser General Public
|
17 | * You should have received a copy of the GNU Lesser General Public
|
18 | * License along with this library; if not, write to the Free Software
|
18 | * License along with this library; if not, write to the Free Software
|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20 | *
|
20 | *
|
21 | * For questions, help, comments, discussion, etc., please join the
|
21 | * For questions, help, comments, discussion, etc., please join the
|
22 | * Smarty mailing list. Send a blank e-mail to
|
22 | * Smarty mailing list. Send a blank e-mail to
|
23 | * smarty-discussion-subscribe@googlegroups.com
|
23 | * smarty-discussion-subscribe@googlegroups.com
|
24 | *
|
24 | *
|
25 | * @link http://www.smarty.net/
|
25 | * @link http://www.smarty.net/
|
26 | * @copyright 2001-2005 New Digital Group, Inc.
|
26 | * @copyright 2001-2005 New Digital Group, Inc.
|
27 | * @author Monte Ohrt <monte at ohrt dot com>
|
27 | * @author Monte Ohrt <monte at ohrt dot com>
|
28 | * @author Andrei Zmievski <andrei@php.net>
|
28 | * @author Andrei Zmievski <andrei@php.net>
|
29 | * @package Smarty
|
29 | * @package Smarty
|
30 | * @version 2.6.22
|
30 | * @version 2.6.22
|
31 | */
|
31 | */
|
32 | 32 | ||
33 | /* $Id: Smarty.class.php 2785 2008-09-18 21:04:12Z Uwe.Tews $ */
|
33 | /* $Id: Smarty.class.php 2785 2008-09-18 21:04:12Z Uwe.Tews $ */
|
34 | 34 | ||
35 | /**
|
35 | /**
|
36 | * DIR_SEP isn't used anymore, but third party apps might
|
36 | * DIR_SEP isn't used anymore, but third party apps might
|
37 | */
|
37 | */
|
38 | if(!defined('DIR_SEP')) { |
38 | if(!defined('DIR_SEP')) { |
39 | define('DIR_SEP', DIRECTORY_SEPARATOR); |
39 | define('DIR_SEP', DIRECTORY_SEPARATOR); |
40 | }
|
40 | }
|
41 | 41 | ||
42 | /**
|
42 | /**
|
43 | * set SMARTY_DIR to absolute path to Smarty library files.
|
43 | * set SMARTY_DIR to absolute path to Smarty library files.
|
44 | * if not defined, include_path will be used. Sets SMARTY_DIR only if user
|
44 | * if not defined, include_path will be used. Sets SMARTY_DIR only if user
|
45 | * application has not already defined it.
|
45 | * application has not already defined it.
|
46 | */
|
46 | */
|
47 | 47 | ||
48 | if (!defined('SMARTY_DIR')) { |
48 | if (!defined('SMARTY_DIR')) { |
49 | define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); |
49 | define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); |
50 | }
|
50 | }
|
51 | 51 | ||
52 | if (!defined('SMARTY_CORE_DIR')) { |
52 | if (!defined('SMARTY_CORE_DIR')) { |
53 | define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR); |
53 | define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR); |
54 | }
|
54 | }
|
55 | 55 | ||
56 | define('SMARTY_PHP_PASSTHRU', 0); |
56 | define('SMARTY_PHP_PASSTHRU', 0); |
57 | define('SMARTY_PHP_QUOTE', 1); |
57 | define('SMARTY_PHP_QUOTE', 1); |
58 | define('SMARTY_PHP_REMOVE', 2); |
58 | define('SMARTY_PHP_REMOVE', 2); |
59 | define('SMARTY_PHP_ALLOW', 3); |
59 | define('SMARTY_PHP_ALLOW', 3); |
60 | 60 | ||
61 | /**
|
61 | /**
|
62 | * @package Smarty
|
62 | * @package Smarty
|
63 | */
|
63 | */
|
64 | class Smarty
|
64 | class Smarty
|
65 | {
|
65 | {
|
66 | /**#@+
|
66 | /**#@+
|
67 | * Smarty Configuration Section
|
67 | * Smarty Configuration Section
|
68 | */
|
68 | */
|
69 | 69 | ||
70 | /**
|
70 | /**
|
71 | * The name of the directory where templates are located.
|
71 | * The name of the directory where templates are located.
|
72 | *
|
72 | *
|
73 | * @var string
|
73 | * @var string
|
74 | */
|
74 | */
|
75 | var $template_dir = 'templates'; |
75 | var $template_dir = 'templates'; |
76 | 76 | ||
77 | /**
|
77 | /**
|
78 | * The directory where compiled templates are located.
|
78 | * The directory where compiled templates are located.
|
79 | *
|
79 | *
|
80 | * @var string
|
80 | * @var string
|
81 | */
|
81 | */
|
82 | var $compile_dir = 'templates_c'; |
82 | var $compile_dir = 'templates_c'; |
83 | 83 | ||
84 | /**
|
84 | /**
|
85 | * The directory where config files are located.
|
85 | * The directory where config files are located.
|
86 | *
|
86 | *
|
87 | * @var string
|
87 | * @var string
|
88 | */
|
88 | */
|
89 | var $config_dir = 'configs'; |
89 | var $config_dir = 'configs'; |
90 | 90 | ||
91 | /**
|
91 | /**
|
92 | * An array of directories searched for plugins.
|
92 | * An array of directories searched for plugins.
|
93 | *
|
93 | *
|
94 | * @var array
|
94 | * @var array
|
95 | */
|
95 | */
|
96 | var $plugins_dir = array('plugins'); |
96 | var $plugins_dir = array('plugins'); |
97 | 97 | ||
98 | /**
|
98 | /**
|
99 | * If debugging is enabled, a debug console window will display
|
99 | * If debugging is enabled, a debug console window will display
|
100 | * when the page loads (make sure your browser allows unrequested
|
100 | * when the page loads (make sure your browser allows unrequested
|
101 | * popup windows)
|
101 | * popup windows)
|
102 | *
|
102 | *
|
103 | * @var boolean
|
103 | * @var boolean
|
104 | */
|
104 | */
|
105 | var $debugging = false; |
105 | var $debugging = false; |
106 | 106 | ||
107 | /**
|
107 | /**
|
108 | * When set, smarty does uses this value as error_reporting-level.
|
108 | * When set, smarty does uses this value as error_reporting-level.
|
109 | *
|
109 | *
|
110 | * @var boolean
|
110 | * @var boolean
|
111 | */
|
111 | */
|
112 | var $error_reporting = null; |
112 | var $error_reporting = null; |
113 | 113 | ||
114 | /**
|
114 | /**
|
115 | * This is the path to the debug console template. If not set,
|
115 | * This is the path to the debug console template. If not set,
|
116 | * the default one will be used.
|
116 | * the default one will be used.
|
117 | *
|
117 | *
|
118 | * @var string
|
118 | * @var string
|
119 | */
|
119 | */
|
120 | var $debug_tpl = ''; |
120 | var $debug_tpl = ''; |
121 | 121 | ||
122 | /**
|
122 | /**
|
123 | * This determines if debugging is enable-able from the browser.
|
123 | * This determines if debugging is enable-able from the browser.
|
124 | * <ul>
|
124 | * <ul>
|
125 | * <li>NONE => no debugging control allowed</li>
|
125 | * <li>NONE => no debugging control allowed</li>
|
126 | * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
|
126 | * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
|
127 | * </ul>
|
127 | * </ul>
|
128 | * @link http://www.foo.dom/index.php?SMARTY_DEBUG
|
128 | * @link http://www.foo.dom/index.php?SMARTY_DEBUG
|
129 | * @var string
|
129 | * @var string
|
130 | */
|
130 | */
|
131 | var $debugging_ctrl = 'NONE'; |
131 | var $debugging_ctrl = 'NONE'; |
132 | 132 | ||
133 | /**
|
133 | /**
|
134 | * This tells Smarty whether to check for recompiling or not. Recompiling
|
134 | * This tells Smarty whether to check for recompiling or not. Recompiling
|
135 | * does not need to happen unless a template or config file is changed.
|
135 | * does not need to happen unless a template or config file is changed.
|
136 | * Typically you enable this during development, and disable for
|
136 | * Typically you enable this during development, and disable for
|
137 | * production.
|
137 | * production.
|
138 | *
|
138 | *
|
139 | * @var boolean
|
139 | * @var boolean
|
140 | */
|
140 | */
|
141 | var $compile_check = true; |
141 | var $compile_check = true; |
142 | 142 | ||
143 | /**
|
143 | /**
|
144 | * This forces templates to compile every time. Useful for development
|
144 | * This forces templates to compile every time. Useful for development
|
145 | * or debugging.
|
145 | * or debugging.
|
146 | *
|
146 | *
|
147 | * @var boolean
|
147 | * @var boolean
|
148 | */
|
148 | */
|
149 | var $force_compile = false; |
149 | var $force_compile = false; |
150 | 150 | ||
151 | /**
|
151 | /**
|
152 | * This enables template caching.
|
152 | * This enables template caching.
|
153 | * <ul>
|
153 | * <ul>
|
154 | * <li>0 = no caching</li>
|
154 | * <li>0 = no caching</li>
|
155 | * <li>1 = use class cache_lifetime value</li>
|
155 | * <li>1 = use class cache_lifetime value</li>
|
156 | * <li>2 = use cache_lifetime in cache file</li>
|
156 | * <li>2 = use cache_lifetime in cache file</li>
|
157 | * </ul>
|
157 | * </ul>
|
158 | * @var integer
|
158 | * @var integer
|
159 | */
|
159 | */
|
160 | var $caching = 0; |
160 | var $caching = 0; |
161 | 161 | ||
162 | /**
|
162 | /**
|
163 | * The name of the directory for cache files.
|
163 | * The name of the directory for cache files.
|
164 | *
|
164 | *
|
165 | * @var string
|
165 | * @var string
|
166 | */
|
166 | */
|
167 | var $cache_dir = 'cache'; |
167 | var $cache_dir = 'cache'; |
168 | 168 | ||
169 | /**
|
169 | /**
|
170 | * This is the number of seconds cached content will persist.
|
170 | * This is the number of seconds cached content will persist.
|
171 | * <ul>
|
171 | * <ul>
|
172 | * <li>0 = always regenerate cache</li>
|
172 | * <li>0 = always regenerate cache</li>
|
173 | * <li>-1 = never expires</li>
|
173 | * <li>-1 = never expires</li>
|
174 | * </ul>
|
174 | * </ul>
|
175 | *
|
175 | *
|
176 | * @var integer
|
176 | * @var integer
|
177 | */
|
177 | */
|
178 | var $cache_lifetime = 3600; |
178 | var $cache_lifetime = 3600; |
179 | 179 | ||
180 | /**
|
180 | /**
|
181 | * Only used when $caching is enabled. If true, then If-Modified-Since headers
|
181 | * Only used when $caching is enabled. If true, then If-Modified-Since headers
|
182 | * are respected with cached content, and appropriate HTTP headers are sent.
|
182 | * are respected with cached content, and appropriate HTTP headers are sent.
|
183 | * This way repeated hits to a cached page do not send the entire page to the
|
183 | * This way repeated hits to a cached page do not send the entire page to the
|
184 | * client every time.
|
184 | * client every time.
|
185 | *
|
185 | *
|
186 | * @var boolean
|
186 | * @var boolean
|
187 | */
|
187 | */
|
188 | var $cache_modified_check = false; |
188 | var $cache_modified_check = false; |
189 | 189 | ||
190 | /**
|
190 | /**
|
191 | * This determines how Smarty handles "<?php ... ?>" tags in templates.
|
191 | * This determines how Smarty handles "<?php ... ?>" tags in templates.
|
192 | * possible values:
|
192 | * possible values:
|
193 | * <ul>
|
193 | * <ul>
|
194 | * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li>
|
194 | * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li>
|
195 | * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>
|
195 | * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>
|
196 | * <li>SMARTY_PHP_REMOVE -> remove php tags</li>
|
196 | * <li>SMARTY_PHP_REMOVE -> remove php tags</li>
|
197 | * <li>SMARTY_PHP_ALLOW -> execute php tags</li>
|
197 | * <li>SMARTY_PHP_ALLOW -> execute php tags</li>
|
198 | * </ul>
|
198 | * </ul>
|
199 | *
|
199 | *
|
200 | * @var integer
|
200 | * @var integer
|
201 | */
|
201 | */
|
202 | var $php_handling = SMARTY_PHP_PASSTHRU; |
202 | var $php_handling = SMARTY_PHP_PASSTHRU; |
203 | 203 | ||
204 | /**
|
204 | /**
|
205 | * This enables template security. When enabled, many things are restricted
|
205 | * This enables template security. When enabled, many things are restricted
|
206 | * in the templates that normally would go unchecked. This is useful when
|
206 | * in the templates that normally would go unchecked. This is useful when
|
207 | * untrusted parties are editing templates and you want a reasonable level
|
207 | * untrusted parties are editing templates and you want a reasonable level
|
208 | * of security. (no direct execution of PHP in templates for example)
|
208 | * of security. (no direct execution of PHP in templates for example)
|
209 | *
|
209 | *
|
210 | * @var boolean
|
210 | * @var boolean
|
211 | */
|
211 | */
|
212 | var $security = false; |
212 | var $security = false; |
213 | 213 | ||
214 | /**
|
214 | /**
|
215 | * This is the list of template directories that are considered secure. This
|
215 | * This is the list of template directories that are considered secure. This
|
216 | * is used only if {@link $security} is enabled. One directory per array
|
216 | * is used only if {@link $security} is enabled. One directory per array
|
217 | * element. {@link $template_dir} is in this list implicitly.
|
217 | * element. {@link $template_dir} is in this list implicitly.
|
218 | *
|
218 | *
|
219 | * @var array
|
219 | * @var array
|
220 | */
|
220 | */
|
221 | var $secure_dir = array(); |
221 | var $secure_dir = array(); |
222 | 222 | ||
223 | /**
|
223 | /**
|
224 | * These are the security settings for Smarty. They are used only when
|
224 | * These are the security settings for Smarty. They are used only when
|
225 | * {@link $security} is enabled.
|
225 | * {@link $security} is enabled.
|
226 | *
|
226 | *
|
227 | * @var array
|
227 | * @var array
|
228 | */
|
228 | */
|
229 | var $security_settings = array( |
229 | var $security_settings = array( |
230 | 'PHP_HANDLING' => false, |
230 | 'PHP_HANDLING' => false, |
231 | 'IF_FUNCS' => array('array', 'list', |
231 | 'IF_FUNCS' => array('array', 'list', |
232 | 'isset', 'empty', |
232 | 'isset', 'empty', |
233 | 'count', 'sizeof', |
233 | 'count', 'sizeof', |
234 | 'in_array', 'is_array', |
234 | 'in_array', 'is_array', |
235 | 'true', 'false', 'null'), |
235 | 'true', 'false', 'null'), |
236 | 'INCLUDE_ANY' => false, |
236 | 'INCLUDE_ANY' => false, |
237 | 'PHP_TAGS' => false, |
237 | 'PHP_TAGS' => false, |
238 | 'MODIFIER_FUNCS' => array('count'), |
238 | 'MODIFIER_FUNCS' => array('count'), |
239 | 'ALLOW_CONSTANTS' => false |
239 | 'ALLOW_CONSTANTS' => false |
240 | ); |
240 | ); |
241 | 241 | ||
242 | /**
|
242 | /**
|
243 | * This is an array of directories where trusted php scripts reside.
|
243 | * This is an array of directories where trusted php scripts reside.
|
244 | * {@link $security} is disabled during their inclusion/execution.
|
244 | * {@link $security} is disabled during their inclusion/execution.
|
245 | *
|
245 | *
|
246 | * @var array
|
246 | * @var array
|
247 | */
|
247 | */
|
248 | var $trusted_dir = array(); |
248 | var $trusted_dir = array(); |
249 | 249 | ||
250 | /**
|
250 | /**
|
251 | * The left delimiter used for the template tags.
|
251 | * The left delimiter used for the template tags.
|
252 | *
|
252 | *
|
253 | * @var string
|
253 | * @var string
|
254 | */
|
254 | */
|
255 | var $left_delimiter = '{'; |
255 | var $left_delimiter = '{'; |
256 | 256 | ||
257 | /**
|
257 | /**
|
258 | * The right delimiter used for the template tags.
|
258 | * The right delimiter used for the template tags.
|
259 | *
|
259 | *
|
260 | * @var string
|
260 | * @var string
|
261 | */
|
261 | */
|
262 | var $right_delimiter = '}'; |
262 | var $right_delimiter = '}'; |
263 | 263 | ||
264 | /**
|
264 | /**
|
265 | * The order in which request variables are registered, similar to
|
265 | * The order in which request variables are registered, similar to
|
266 | * variables_order in php.ini E = Environment, G = GET, P = POST,
|
266 | * variables_order in php.ini E = Environment, G = GET, P = POST,
|
267 | * C = Cookies, S = Server
|
267 | * C = Cookies, S = Server
|
268 | *
|
268 | *
|
269 | * @var string
|
269 | * @var string
|
270 | */
|
270 | */
|
271 | var $request_vars_order = 'EGPCS'; |
271 | var $request_vars_order = 'EGPCS'; |
272 | 272 | ||
273 | /**
|
273 | /**
|
274 | * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false)
|
274 | * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false)
|
275 | * are uses as request-vars or $_*[]-vars. note: if
|
275 | * are uses as request-vars or $_*[]-vars. note: if
|
276 | * request_use_auto_globals is true, then $request_vars_order has
|
276 | * request_use_auto_globals is true, then $request_vars_order has
|
277 | * no effect, but the php-ini-value "gpc_order"
|
277 | * no effect, but the php-ini-value "gpc_order"
|
278 | *
|
278 | *
|
279 | * @var boolean
|
279 | * @var boolean
|
280 | */
|
280 | */
|
281 | var $request_use_auto_globals = true; |
281 | var $request_use_auto_globals = true; |
282 | 282 | ||
283 | /**
|
283 | /**
|
284 | * Set this if you want different sets of compiled files for the same
|
284 | * Set this if you want different sets of compiled files for the same
|
285 | * templates. This is useful for things like different languages.
|
285 | * templates. This is useful for things like different languages.
|
286 | * Instead of creating separate sets of templates per language, you
|
286 | * Instead of creating separate sets of templates per language, you
|
287 | * set different compile_ids like 'en' and 'de'.
|
287 | * set different compile_ids like 'en' and 'de'.
|
288 | *
|
288 | *
|
289 | * @var string
|
289 | * @var string
|
290 | */
|
290 | */
|
291 | var $compile_id = null; |
291 | var $compile_id = null; |
292 | 292 | ||
293 | /**
|
293 | /**
|
294 | * This tells Smarty whether or not to use sub dirs in the cache/ and
|
294 | * This tells Smarty whether or not to use sub dirs in the cache/ and
|
295 | * templates_c/ directories. sub directories better organized, but
|
295 | * templates_c/ directories. sub directories better organized, but
|
296 | * may not work well with PHP safe mode enabled.
|
296 | * may not work well with PHP safe mode enabled.
|
297 | *
|
297 | *
|
298 | * @var boolean
|
298 | * @var boolean
|
299 | *
|
299 | *
|
300 | */
|
300 | */
|
301 | var $use_sub_dirs = false; |
301 | var $use_sub_dirs = false; |
302 | 302 | ||
303 | /**
|
303 | /**
|
304 | * This is a list of the modifiers to apply to all template variables.
|
304 | * This is a list of the modifiers to apply to all template variables.
|
305 | * Put each modifier in a separate array element in the order you want
|
305 | * Put each modifier in a separate array element in the order you want
|
306 | * them applied. example: <code>array('escape:"htmlall"');</code>
|
306 | * them applied. example: <code>array('escape:"htmlall"');</code>
|
307 | *
|
307 | *
|
308 | * @var array
|
308 | * @var array
|
309 | */
|
309 | */
|
310 | var $default_modifiers = array(); |
310 | var $default_modifiers = array(); |
311 | 311 | ||
312 | /**
|
312 | /**
|
313 | * This is the resource type to be used when not specified
|
313 | * This is the resource type to be used when not specified
|
314 | * at the beginning of the resource path. examples:
|
314 | * at the beginning of the resource path. examples:
|
315 | * $smarty->display('file:index.tpl');
|
315 | * $smarty->display('file:index.tpl');
|
316 | * $smarty->display('db:index.tpl');
|
316 | * $smarty->display('db:index.tpl');
|
317 | * $smarty->display('index.tpl'); // will use default resource type
|
317 | * $smarty->display('index.tpl'); // will use default resource type
|
318 | * {include file="file:index.tpl"}
|
318 | * {include file="file:index.tpl"}
|
319 | * {include file="db:index.tpl"}
|
319 | * {include file="db:index.tpl"}
|
320 | * {include file="index.tpl"} {* will use default resource type *}
|
320 | * {include file="index.tpl"} {* will use default resource type *}
|
321 | *
|
321 | *
|
322 | * @var array
|
322 | * @var array
|
323 | */
|
323 | */
|
324 | var $default_resource_type = 'file'; |
324 | var $default_resource_type = 'file'; |
325 | 325 | ||
326 | /**
|
326 | /**
|
327 | * The function used for cache file handling. If not set, built-in caching is used.
|
327 | * The function used for cache file handling. If not set, built-in caching is used.
|
328 | *
|
328 | *
|
329 | * @var null|string function name
|
329 | * @var null|string function name
|
330 | */
|
330 | */
|
331 | var $cache_handler_func = null; |
331 | var $cache_handler_func = null; |
332 | 332 | ||
333 | /**
|
333 | /**
|
334 | * This indicates which filters are automatically loaded into Smarty.
|
334 | * This indicates which filters are automatically loaded into Smarty.
|
335 | *
|
335 | *
|
336 | * @var array array of filter names
|
336 | * @var array array of filter names
|
337 | */
|
337 | */
|
338 | var $autoload_filters = array(); |
338 | var $autoload_filters = array(); |
339 | 339 | ||
340 | /**#@+
|
340 | /**#@+
|
341 | * @var boolean
|
341 | * @var boolean
|
342 | */
|
342 | */
|
343 | /**
|
343 | /**
|
344 | * This tells if config file vars of the same name overwrite each other or not.
|
344 | * This tells if config file vars of the same name overwrite each other or not.
|
345 | * if disabled, same name variables are accumulated in an array.
|
345 | * if disabled, same name variables are accumulated in an array.
|
346 | */
|
346 | */
|
347 | var $config_overwrite = true; |
347 | var $config_overwrite = true; |
348 | 348 | ||
349 | /**
|
349 | /**
|
350 | * This tells whether or not to automatically booleanize config file variables.
|
350 | * This tells whether or not to automatically booleanize config file variables.
|
351 | * If enabled, then the strings "on", "true", and "yes" are treated as boolean
|
351 | * If enabled, then the strings "on", "true", and "yes" are treated as boolean
|
352 | * true, and "off", "false" and "no" are treated as boolean false.
|
352 | * true, and "off", "false" and "no" are treated as boolean false.
|
353 | */
|
353 | */
|
354 | var $config_booleanize = true; |
354 | var $config_booleanize = true; |
355 | 355 | ||
356 | /**
|
356 | /**
|
357 | * This tells whether hidden sections [.foobar] are readable from the
|
357 | * This tells whether hidden sections [.foobar] are readable from the
|
358 | * tempalates or not. Normally you would never allow this since that is
|
358 | * tempalates or not. Normally you would never allow this since that is
|
359 | * the point behind hidden sections: the application can access them, but
|
359 | * the point behind hidden sections: the application can access them, but
|
360 | * the templates cannot.
|
360 | * the templates cannot.
|
361 | */
|
361 | */
|
362 | var $config_read_hidden = false; |
362 | var $config_read_hidden = false; |
363 | 363 | ||
364 | /**
|
364 | /**
|
365 | * This tells whether or not automatically fix newlines in config files.
|
365 | * This tells whether or not automatically fix newlines in config files.
|
366 | * It basically converts \r (mac) or \r\n (dos) to \n
|
366 | * It basically converts \r (mac) or \r\n (dos) to \n
|
367 | */
|
367 | */
|
368 | var $config_fix_newlines = true; |
368 | var $config_fix_newlines = true; |
369 | /**#@-*/
|
369 | /**#@-*/
|
370 | 370 | ||
371 | /**
|
371 | /**
|
372 | * If a template cannot be found, this PHP function will be executed.
|
372 | * If a template cannot be found, this PHP function will be executed.
|
373 | * Useful for creating templates on-the-fly or other special action.
|
373 | * Useful for creating templates on-the-fly or other special action.
|
374 | *
|
374 | *
|
375 | * @var string function name
|
375 | * @var string function name
|
376 | */
|
376 | */
|
377 | var $default_template_handler_func = ''; |
377 | var $default_template_handler_func = ''; |
378 | 378 | ||
379 | /**
|
379 | /**
|
380 | * The file that contains the compiler class. This can a full
|
380 | * The file that contains the compiler class. This can a full
|
381 | * pathname, or relative to the php_include path.
|
381 | * pathname, or relative to the php_include path.
|
382 | *
|
382 | *
|
383 | * @var string
|
383 | * @var string
|
384 | */
|
384 | */
|
385 | var $compiler_file = 'Smarty_Compiler.class.php'; |
385 | var $compiler_file = 'Smarty_Compiler.class.php'; |
386 | 386 | ||
387 | /**
|
387 | /**
|
388 | * The class used for compiling templates.
|
388 | * The class used for compiling templates.
|
389 | *
|
389 | *
|
390 | * @var string
|
390 | * @var string
|
391 | */
|
391 | */
|
392 | var $compiler_class = 'Smarty_Compiler'; |
392 | var $compiler_class = 'Smarty_Compiler'; |
393 | 393 | ||
394 | /**
|
394 | /**
|
395 | * The class used to load config vars.
|
395 | * The class used to load config vars.
|
396 | *
|
396 | *
|
397 | * @var string
|
397 | * @var string
|
398 | */
|
398 | */
|
399 | var $config_class = 'Config_File'; |
399 | var $config_class = 'Config_File'; |
400 | 400 | ||
401 | /**#@+
|
401 | /**#@+
|
402 | * END Smarty Configuration Section
|
402 | * END Smarty Configuration Section
|
403 | * There should be no need to touch anything below this line.
|
403 | * There should be no need to touch anything below this line.
|
404 | * @access private
|
404 | * @access private
|
405 | */
|
405 | */
|
406 | /**
|
406 | /**
|
407 | * where assigned template vars are kept
|
407 | * where assigned template vars are kept
|
408 | *
|
408 | *
|
409 | * @var array
|
409 | * @var array
|
410 | */
|
410 | */
|
411 | var $_tpl_vars = array(); |
411 | var $_tpl_vars = array(); |
412 | 412 | ||
413 | /**
|
413 | /**
|
414 | * stores run-time $smarty.* vars
|
414 | * stores run-time $smarty.* vars
|
415 | *
|
415 | *
|
416 | * @var null|array
|
416 | * @var null|array
|
417 | */
|
417 | */
|
418 | var $_smarty_vars = null; |
418 | var $_smarty_vars = null; |
419 | 419 | ||
420 | /**
|
420 | /**
|
421 | * keeps track of sections
|
421 | * keeps track of sections
|
422 | *
|
422 | *
|
423 | * @var array
|
423 | * @var array
|
424 | */
|
424 | */
|
425 | var $_sections = array(); |
425 | var $_sections = array(); |
426 | 426 | ||
427 | /**
|
427 | /**
|
428 | * keeps track of foreach blocks
|
428 | * keeps track of foreach blocks
|
429 | *
|
429 | *
|
430 | * @var array
|
430 | * @var array
|
431 | */
|
431 | */
|
432 | var $_foreach = array(); |
432 | var $_foreach = array(); |
433 | 433 | ||
434 | /**
|
434 | /**
|
435 | * keeps track of tag hierarchy
|
435 | * keeps track of tag hierarchy
|
436 | *
|
436 | *
|
437 | * @var array
|
437 | * @var array
|
438 | */
|
438 | */
|
439 | var $_tag_stack = array(); |
439 | var $_tag_stack = array(); |
440 | 440 | ||
441 | /**
|
441 | /**
|
442 | * configuration object
|
442 | * configuration object
|
443 | *
|
443 | *
|
444 | * @var Config_file
|
444 | * @var Config_file
|
445 | */
|
445 | */
|
446 | var $_conf_obj = null; |
446 | var $_conf_obj = null; |
447 | 447 | ||
448 | /**
|
448 | /**
|
449 | * loaded configuration settings
|
449 | * loaded configuration settings
|
450 | *
|
450 | *
|
451 | * @var array
|
451 | * @var array
|
452 | */
|
452 | */
|
453 | var $_config = array(array('vars' => array(), 'files' => array())); |
453 | var $_config = array(array('vars' => array(), 'files' => array())); |
454 | 454 | ||
455 | /**
|
455 | /**
|
456 | * md5 checksum of the string 'Smarty'
|
456 | * md5 checksum of the string 'Smarty'
|
457 | *
|
457 | *
|
458 | * @var string
|
458 | * @var string
|
459 | */
|
459 | */
|
460 | var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; |
460 | var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; |
461 | 461 | ||
462 | /**
|
462 | /**
|
463 | * Smarty version number
|
463 | * Smarty version number
|
464 | *
|
464 | *
|
465 | * @var string
|
465 | * @var string
|
466 | */
|
466 | */
|
467 | var $_version = '2.6.22'; |
467 | var $_version = '2.6.22'; |
468 | 468 | ||
469 | /**
|
469 | /**
|
470 | * current template inclusion depth
|
470 | * current template inclusion depth
|
471 | *
|
471 | *
|
472 | * @var integer
|
472 | * @var integer
|
473 | */
|
473 | */
|
474 | var $_inclusion_depth = 0; |
474 | var $_inclusion_depth = 0; |
475 | 475 | ||
476 | /**
|
476 | /**
|
477 | * for different compiled templates
|
477 | * for different compiled templates
|
478 | *
|
478 | *
|
479 | * @var string
|
479 | * @var string
|
480 | */
|
480 | */
|
481 | var $_compile_id = null; |
481 | var $_compile_id = null; |
482 | 482 | ||
483 | /**
|
483 | /**
|
484 | * text in URL to enable debug mode
|
484 | * text in URL to enable debug mode
|
485 | *
|
485 | *
|
486 | * @var string
|
486 | * @var string
|
487 | */
|
487 | */
|
488 | var $_smarty_debug_id = 'SMARTY_DEBUG'; |
488 | var $_smarty_debug_id = 'SMARTY_DEBUG'; |
489 | 489 | ||
490 | /**
|
490 | /**
|
491 | * debugging information for debug console
|
491 | * debugging information for debug console
|
492 | *
|
492 | *
|
493 | * @var array
|
493 | * @var array
|
494 | */
|
494 | */
|
495 | var $_smarty_debug_info = array(); |
495 | var $_smarty_debug_info = array(); |
496 | 496 | ||
497 | /**
|
497 | /**
|
498 | * info that makes up a cache file
|
498 | * info that makes up a cache file
|
499 | *
|
499 | *
|
500 | * @var array
|
500 | * @var array
|
501 | */
|
501 | */
|
502 | var $_cache_info = array(); |
502 | var $_cache_info = array(); |
503 | 503 | ||
504 | /**
|
504 | /**
|
505 | * default file permissions
|
505 | * default file permissions
|
506 | *
|
506 | *
|
507 | * @var integer
|
507 | * @var integer
|
508 | */
|
508 | */
|
509 | var $_file_perms = 0644; |
509 | var $_file_perms = 0644; |
510 | 510 | ||
511 | /**
|
511 | /**
|
512 | * default dir permissions
|
512 | * default dir permissions
|
513 | *
|
513 | *
|
514 | * @var integer
|
514 | * @var integer
|
515 | */
|
515 | */
|
516 | var $_dir_perms = 0771; |
516 | var $_dir_perms = 0771; |
517 | 517 | ||
518 | /**
|
518 | /**
|
519 | * registered objects
|
519 | * registered objects
|
520 | *
|
520 | *
|
521 | * @var array
|
521 | * @var array
|
522 | */
|
522 | */
|
523 | var $_reg_objects = array(); |
523 | var $_reg_objects = array(); |
524 | 524 | ||
525 | /**
|
525 | /**
|
526 | * table keeping track of plugins
|
526 | * table keeping track of plugins
|
527 | *
|
527 | *
|
528 | * @var array
|
528 | * @var array
|
529 | */
|
529 | */
|
530 | var $_plugins = array( |
530 | var $_plugins = array( |
531 | 'modifier' => array(), |
531 | 'modifier' => array(), |
532 | 'function' => array(), |
532 | 'function' => array(), |
533 | 'block' => array(), |
533 | 'block' => array(), |
534 | 'compiler' => array(), |
534 | 'compiler' => array(), |
535 | 'prefilter' => array(), |
535 | 'prefilter' => array(), |
536 | 'postfilter' => array(), |
536 | 'postfilter' => array(), |
537 | 'outputfilter' => array(), |
537 | 'outputfilter' => array(), |
538 | 'resource' => array(), |
538 | 'resource' => array(), |
539 | 'insert' => array()); |
539 | 'insert' => array()); |
540 | 540 | ||
541 | 541 | ||
542 | /**
|
542 | /**
|
543 | * cache serials
|
543 | * cache serials
|
544 | *
|
544 | *
|
545 | * @var array
|
545 | * @var array
|
546 | */
|
546 | */
|
547 | var $_cache_serials = array(); |
547 | var $_cache_serials = array(); |
548 | 548 | ||
549 | /**
|
549 | /**
|
550 | * name of optional cache include file
|
550 | * name of optional cache include file
|
551 | *
|
551 | *
|
552 | * @var string
|
552 | * @var string
|
553 | */
|
553 | */
|
554 | var $_cache_include = null; |
554 | var $_cache_include = null; |
555 | 555 | ||
556 | /**
|
556 | /**
|
557 | * indicate if the current code is used in a compiled
|
557 | * indicate if the current code is used in a compiled
|
558 | * include
|
558 | * include
|
559 | *
|
559 | *
|
560 | * @var string
|
560 | * @var string
|
561 | */
|
561 | */
|
562 | var $_cache_including = false; |
562 | var $_cache_including = false; |
563 | 563 | ||
564 | /**#@-*/
|
564 | /**#@-*/
|
565 | /**
|
565 | /**
|
566 | * The class constructor.
|
566 | * The class constructor.
|
567 | */
|
567 | */
|
568 | function Smarty() |
568 | function Smarty() |
569 | {
|
569 | {
|
570 | $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] |
570 | $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] |
571 | : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']); |
571 | : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']); |
572 | }
|
572 | }
|
573 | 573 | ||
574 | /**
|
574 | /**
|
575 | * assigns values to template variables
|
575 | * assigns values to template variables
|
576 | *
|
576 | *
|
577 | * @param array|string $tpl_var the template variable name(s)
|
577 | * @param array|string $tpl_var the template variable name(s)
|
578 | * @param mixed $value the value to assign
|
578 | * @param mixed $value the value to assign
|
579 | */
|
579 | */
|
580 | function assign($tpl_var, $value = null) |
580 | function assign($tpl_var, $value = null) |
581 | {
|
581 | {
|
582 | if (is_array($tpl_var)){ |
582 | if (is_array($tpl_var)){ |
583 | foreach ($tpl_var as $key => $val) { |
583 | foreach ($tpl_var as $key => $val) { |
584 | if ($key != '') { |
584 | if ($key != '') { |
585 | $this->_tpl_vars[$key] = $val; |
585 | $this->_tpl_vars[$key] = $val; |
586 | }
|
586 | }
|
587 | }
|
587 | }
|
588 | } else { |
588 | } else { |
589 | if ($tpl_var != '') |
589 | if ($tpl_var != '') |
590 | $this->_tpl_vars[$tpl_var] = $value; |
590 | $this->_tpl_vars[$tpl_var] = $value; |
591 | }
|
591 | }
|
592 | }
|
592 | }
|
593 | 593 | ||
594 | /**
|
594 | /**
|
595 | * assigns values to template variables by reference
|
595 | * assigns values to template variables by reference
|
596 | *
|
596 | *
|
597 | * @param string $tpl_var the template variable name
|
597 | * @param string $tpl_var the template variable name
|
598 | * @param mixed $value the referenced value to assign
|
598 | * @param mixed $value the referenced value to assign
|
599 | */
|
599 | */
|
600 | function assign_by_ref($tpl_var, &$value) |
600 | function assign_by_ref($tpl_var, &$value) |
601 | {
|
601 | {
|
602 | if ($tpl_var != '') |
602 | if ($tpl_var != '') |
603 | $this->_tpl_vars[$tpl_var] = &$value; |
603 | $this->_tpl_vars[$tpl_var] = &$value; |
604 | }
|
604 | }
|
605 | 605 | ||
606 | /**
|
606 | /**
|
607 | * appends values to template variables
|
607 | * appends values to template variables
|
608 | *
|
608 | *
|
609 | * @param array|string $tpl_var the template variable name(s)
|
609 | * @param array|string $tpl_var the template variable name(s)
|
610 | * @param mixed $value the value to append
|
610 | * @param mixed $value the value to append
|
611 | */
|
611 | */
|
612 | function append($tpl_var, $value=null, $merge=false) |
612 | function append($tpl_var, $value=null, $merge=false) |
613 | {
|
613 | {
|
614 | if (is_array($tpl_var)) { |
614 | if (is_array($tpl_var)) { |
615 | // $tpl_var is an array, ignore $value
|
615 | // $tpl_var is an array, ignore $value
|
616 | foreach ($tpl_var as $_key => $_val) { |
616 | foreach ($tpl_var as $_key => $_val) { |
617 | if ($_key != '') { |
617 | if ($_key != '') { |
618 | if(!@is_array($this->_tpl_vars[$_key])) { |
618 | if(!@is_array($this->_tpl_vars[$_key])) { |
619 | settype($this->_tpl_vars[$_key],'array'); |
619 | settype($this->_tpl_vars[$_key],'array'); |
620 | }
|
620 | }
|
621 | if($merge && is_array($_val)) { |
621 | if($merge && is_array($_val)) { |
622 | foreach($_val as $_mkey => $_mval) { |
622 | foreach($_val as $_mkey => $_mval) { |
623 | $this->_tpl_vars[$_key][$_mkey] = $_mval; |
623 | $this->_tpl_vars[$_key][$_mkey] = $_mval; |
624 | }
|
624 | }
|
625 | } else { |
625 | } else { |
626 | $this->_tpl_vars[$_key][] = $_val; |
626 | $this->_tpl_vars[$_key][] = $_val; |
627 | }
|
627 | }
|
628 | }
|
628 | }
|
629 | }
|
629 | }
|
630 | } else { |
630 | } else { |
631 | if ($tpl_var != '' && isset($value)) { |
631 | if ($tpl_var != '' && isset($value)) { |
632 | if(!@is_array($this->_tpl_vars[$tpl_var])) { |
632 | if(!@is_array($this->_tpl_vars[$tpl_var])) { |
633 | settype($this->_tpl_vars[$tpl_var],'array'); |
633 | settype($this->_tpl_vars[$tpl_var],'array'); |
634 | }
|
634 | }
|
635 | if($merge && is_array($value)) { |
635 | if($merge && is_array($value)) { |
636 | foreach($value as $_mkey => $_mval) { |
636 | foreach($value as $_mkey => $_mval) { |
637 | $this->_tpl_vars[$tpl_var][$_mkey] = $_mval; |
637 | $this->_tpl_vars[$tpl_var][$_mkey] = $_mval; |
638 | }
|
638 | }
|
639 | } else { |
639 | } else { |
640 | $this->_tpl_vars[$tpl_var][] = $value; |
640 | $this->_tpl_vars[$tpl_var][] = $value; |
641 | }
|
641 | }
|
642 | }
|
642 | }
|
643 | }
|
643 | }
|
644 | }
|
644 | }
|
645 | 645 | ||
646 | /**
|
646 | /**
|
647 | * appends values to template variables by reference
|
647 | * appends values to template variables by reference
|
648 | *
|
648 | *
|
649 | * @param string $tpl_var the template variable name
|
649 | * @param string $tpl_var the template variable name
|
650 | * @param mixed $value the referenced value to append
|
650 | * @param mixed $value the referenced value to append
|
651 | */
|
651 | */
|
652 | function append_by_ref($tpl_var, &$value, $merge=false) |
652 | function append_by_ref($tpl_var, &$value, $merge=false) |
653 | {
|
653 | {
|
654 | if ($tpl_var != '' && isset($value)) { |
654 | if ($tpl_var != '' && isset($value)) { |
655 | if(!@is_array($this->_tpl_vars[$tpl_var])) { |
655 | if(!@is_array($this->_tpl_vars[$tpl_var])) { |
656 | settype($this->_tpl_vars[$tpl_var],'array'); |
656 | settype($this->_tpl_vars[$tpl_var],'array'); |
657 | }
|
657 | }
|
658 | if ($merge && is_array($value)) { |
658 | if ($merge && is_array($value)) { |
659 | foreach($value as $_key => $_val) { |
659 | foreach($value as $_key => $_val) { |
660 | $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key]; |
660 | $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key]; |
661 | }
|
661 | }
|
662 | } else { |
662 | } else { |
663 | $this->_tpl_vars[$tpl_var][] = &$value; |
663 | $this->_tpl_vars[$tpl_var][] = &$value; |
664 | }
|
664 | }
|
665 | }
|
665 | }
|
666 | }
|
666 | }
|
667 | 667 | ||
668 | 668 | ||
669 | /**
|
669 | /**
|
670 | * clear the given assigned template variable.
|
670 | * clear the given assigned template variable.
|
671 | *
|
671 | *
|
672 | * @param string $tpl_var the template variable to clear
|
672 | * @param string $tpl_var the template variable to clear
|
673 | */
|
673 | */
|
674 | function clear_assign($tpl_var) |
674 | function clear_assign($tpl_var) |
675 | {
|
675 | {
|
676 | if (is_array($tpl_var)) |
676 | if (is_array($tpl_var)) |
677 | foreach ($tpl_var as $curr_var) |
677 | foreach ($tpl_var as $curr_var) |
678 | unset($this->_tpl_vars[$curr_var]); |
678 | unset($this->_tpl_vars[$curr_var]); |
679 | else
|
679 | else
|
680 | unset($this->_tpl_vars[$tpl_var]); |
680 | unset($this->_tpl_vars[$tpl_var]); |
681 | }
|
681 | }
|
682 | 682 | ||
683 | 683 | ||
684 | /**
|
684 | /**
|
685 | * Registers custom function to be used in templates
|
685 | * Registers custom function to be used in templates
|
686 | *
|
686 | *
|
687 | * @param string $function the name of the template function
|
687 | * @param string $function the name of the template function
|
688 | * @param string $function_impl the name of the PHP function to register
|
688 | * @param string $function_impl the name of the PHP function to register
|
689 | */
|
689 | */
|
690 | function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) |
690 | function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) |
691 | {
|
691 | {
|
692 | $this->_plugins['function'][$function] = |
692 | $this->_plugins['function'][$function] = |
693 | array($function_impl, null, null, false, $cacheable, $cache_attrs); |
693 | array($function_impl, null, null, false, $cacheable, $cache_attrs); |
694 | 694 | ||
695 | }
|
695 | }
|
696 | 696 | ||
697 | /**
|
697 | /**
|
698 | * Unregisters custom function
|
698 | * Unregisters custom function
|
699 | *
|
699 | *
|
700 | * @param string $function name of template function
|
700 | * @param string $function name of template function
|
701 | */
|
701 | */
|
702 | function unregister_function($function) |
702 | function unregister_function($function) |
703 | {
|
703 | {
|
704 | unset($this->_plugins['function'][$function]); |
704 | unset($this->_plugins['function'][$function]); |
705 | }
|
705 | }
|
706 | 706 | ||
707 | /**
|
707 | /**
|
708 | * Registers object to be used in templates
|
708 | * Registers object to be used in templates
|
709 | *
|
709 | *
|
710 | * @param string $object name of template object
|
710 | * @param string $object name of template object
|
711 | * @param object &$object_impl the referenced PHP object to register
|
711 | * @param object &$object_impl the referenced PHP object to register
|
712 | * @param null|array $allowed list of allowed methods (empty = all)
|
712 | * @param null|array $allowed list of allowed methods (empty = all)
|
713 | * @param boolean $smarty_args smarty argument format, else traditional
|
713 | * @param boolean $smarty_args smarty argument format, else traditional
|
714 | * @param null|array $block_functs list of methods that are block format
|
714 | * @param null|array $block_functs list of methods that are block format
|
715 | */
|
715 | */
|
716 | function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) |
716 | function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) |
717 | {
|
717 | {
|
718 | settype($allowed, 'array'); |
718 | settype($allowed, 'array'); |
719 | settype($smarty_args, 'boolean'); |
719 | settype($smarty_args, 'boolean'); |
720 | $this->_reg_objects[$object] = |
720 | $this->_reg_objects[$object] = |
721 | array(&$object_impl, $allowed, $smarty_args, $block_methods); |
721 | array(&$object_impl, $allowed, $smarty_args, $block_methods); |
722 | }
|
722 | }
|
723 | 723 | ||
724 | /**
|
724 | /**
|
725 | * Unregisters object
|
725 | * Unregisters object
|
726 | *
|
726 | *
|
727 | * @param string $object name of template object
|
727 | * @param string $object name of template object
|
728 | */
|
728 | */
|
729 | function unregister_object($object) |
729 | function unregister_object($object) |
730 | {
|
730 | {
|
731 | unset($this->_reg_objects[$object]); |
731 | unset($this->_reg_objects[$object]); |
732 | }
|
732 | }
|
733 | 733 | ||
734 | 734 | ||
735 | /**
|
735 | /**
|
736 | * Registers block function to be used in templates
|
736 | * Registers block function to be used in templates
|
737 | *
|
737 | *
|
738 | * @param string $block name of template block
|
738 | * @param string $block name of template block
|
739 | * @param string $block_impl PHP function to register
|
739 | * @param string $block_impl PHP function to register
|
740 | */
|
740 | */
|
741 | function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) |
741 | function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) |
742 | {
|
742 | {
|
743 | $this->_plugins['block'][$block] = |
743 | $this->_plugins['block'][$block] = |
744 | array($block_impl, null, null, false, $cacheable, $cache_attrs); |
744 | array($block_impl, null, null, false, $cacheable, $cache_attrs); |
745 | }
|
745 | }
|
746 | 746 | ||
747 | /**
|
747 | /**
|
748 | * Unregisters block function
|
748 | * Unregisters block function
|
749 | *
|
749 | *
|
750 | * @param string $block name of template function
|
750 | * @param string $block name of template function
|
751 | */
|
751 | */
|
752 | function unregister_block($block) |
752 | function unregister_block($block) |
753 | {
|
753 | {
|
754 | unset($this->_plugins['block'][$block]); |
754 | unset($this->_plugins['block'][$block]); |
755 | }
|
755 | }
|
756 | 756 | ||
757 | /**
|
757 | /**
|
758 | * Registers compiler function
|
758 | * Registers compiler function
|
759 | *
|
759 | *
|
760 | * @param string $function name of template function
|
760 | * @param string $function name of template function
|
761 | * @param string $function_impl name of PHP function to register
|
761 | * @param string $function_impl name of PHP function to register
|
762 | */
|
762 | */
|
763 | function register_compiler_function($function, $function_impl, $cacheable=true) |
763 | function register_compiler_function($function, $function_impl, $cacheable=true) |
764 | {
|
764 | {
|
765 | $this->_plugins['compiler'][$function] = |
765 | $this->_plugins['compiler'][$function] = |
766 | array($function_impl, null, null, false, $cacheable); |
766 | array($function_impl, null, null, false, $cacheable); |
767 | }
|
767 | }
|
768 | 768 | ||
769 | /**
|
769 | /**
|
770 | * Unregisters compiler function
|
770 | * Unregisters compiler function
|
771 | *
|
771 | *
|
772 | * @param string $function name of template function
|
772 | * @param string $function name of template function
|
773 | */
|
773 | */
|
774 | function unregister_compiler_function($function) |
774 | function unregister_compiler_function($function) |
775 | {
|
775 | {
|
776 | unset($this->_plugins['compiler'][$function]); |
776 | unset($this->_plugins['compiler'][$function]); |
777 | }
|
777 | }
|
778 | 778 | ||
779 | /**
|
779 | /**
|
780 | * Registers modifier to be used in templates
|
780 | * Registers modifier to be used in templates
|
781 | *
|
781 | *
|
782 | * @param string $modifier name of template modifier
|
782 | * @param string $modifier name of template modifier
|
783 | * @param string $modifier_impl name of PHP function to register
|
783 | * @param string $modifier_impl name of PHP function to register
|
784 | */
|
784 | */
|
785 | function register_modifier($modifier, $modifier_impl) |
785 | function register_modifier($modifier, $modifier_impl) |
786 | {
|
786 | {
|
787 | $this->_plugins['modifier'][$modifier] = |
787 | $this->_plugins['modifier'][$modifier] = |
788 | array($modifier_impl, null, null, false); |
788 | array($modifier_impl, null, null, false); |
789 | }
|
789 | }
|
790 | 790 | ||
791 | /**
|
791 | /**
|
792 | * Unregisters modifier
|
792 | * Unregisters modifier
|
793 | *
|
793 | *
|
794 | * @param string $modifier name of template modifier
|
794 | * @param string $modifier name of template modifier
|
795 | */
|
795 | */
|
796 | function unregister_modifier($modifier) |
796 | function unregister_modifier($modifier) |
797 | {
|
797 | {
|
798 | unset($this->_plugins['modifier'][$modifier]); |
798 | unset($this->_plugins['modifier'][$modifier]); |
799 | }
|
799 | }
|
800 | 800 | ||
801 | /**
|
801 | /**
|
802 | * Registers a resource to fetch a template
|
802 | * Registers a resource to fetch a template
|
803 | *
|
803 | *
|
804 | * @param string $type name of resource
|
804 | * @param string $type name of resource
|
805 | * @param array $functions array of functions to handle resource
|
805 | * @param array $functions array of functions to handle resource
|
806 | */
|
806 | */
|
807 | function register_resource($type, $functions) |
807 | function register_resource($type, $functions) |
808 | {
|
808 | {
|
809 | if (count($functions)==4) { |
809 | if (count($functions)==4) { |
810 | $this->_plugins['resource'][$type] = |
810 | $this->_plugins['resource'][$type] = |
811 | array($functions, false); |
811 | array($functions, false); |
812 | 812 | ||
813 | } elseif (count($functions)==5) { |
813 | } elseif (count($functions)==5) { |
814 | $this->_plugins['resource'][$type] = |
814 | $this->_plugins['resource'][$type] = |
815 | array(array(array(&$functions[0], $functions[1]) |
815 | array(array(array(&$functions[0], $functions[1]) |
816 | ,array(&$functions[0], $functions[2]) |
816 | ,array(&$functions[0], $functions[2]) |
817 | ,array(&$functions[0], $functions[3]) |
817 | ,array(&$functions[0], $functions[3]) |
818 | ,array(&$functions[0], $functions[4])) |
818 | ,array(&$functions[0], $functions[4])) |
819 | ,false); |
819 | ,false); |
820 | 820 | ||
821 | } else { |
821 | } else { |
822 | $this->trigger_error("malformed function-list for '$type' in register_resource"); |
822 | $this->trigger_error("malformed function-list for '$type' in register_resource"); |
823 | 823 | ||
824 | }
|
824 | }
|
825 | }
|
825 | }
|
826 | 826 | ||
827 | /**
|
827 | /**
|
828 | * Unregisters a resource
|
828 | * Unregisters a resource
|
829 | *
|
829 | *
|
830 | * @param string $type name of resource
|
830 | * @param string $type name of resource
|
831 | */
|
831 | */
|
832 | function unregister_resource($type) |
832 | function unregister_resource($type) |
833 | {
|
833 | {
|
834 | unset($this->_plugins['resource'][$type]); |
834 | unset($this->_plugins['resource'][$type]); |
835 | }
|
835 | }
|
836 | 836 | ||
837 | /**
|
837 | /**
|
838 | * Registers a prefilter function to apply
|
838 | * Registers a prefilter function to apply
|
839 | * to a template before compiling
|
839 | * to a template before compiling
|
840 | *
|
840 | *
|
841 | * @param callback $function
|
841 | * @param callback $function
|
842 | */
|
842 | */
|
843 | function register_prefilter($function) |
843 | function register_prefilter($function) |
844 | {
|
844 | {
|
845 | $this->_plugins['prefilter'][$this->_get_filter_name($function)] |
845 | $this->_plugins['prefilter'][$this->_get_filter_name($function)] |
846 | = array($function, null, null, false); |
846 | = array($function, null, null, false); |
847 | }
|
847 | }
|
848 | 848 | ||
849 | /**
|
849 | /**
|
850 | * Unregisters a prefilter function
|
850 | * Unregisters a prefilter function
|
851 | *
|
851 | *
|
852 | * @param callback $function
|
852 | * @param callback $function
|
853 | */
|
853 | */
|
854 | function unregister_prefilter($function) |
854 | function unregister_prefilter($function) |
855 | {
|
855 | {
|
856 | unset($this->_plugins['prefilter'][$this->_get_filter_name($function)]); |
856 | unset($this->_plugins['prefilter'][$this->_get_filter_name($function)]); |
857 | }
|
857 | }
|
858 | 858 | ||
859 | /**
|
859 | /**
|
860 | * Registers a postfilter function to apply
|
860 | * Registers a postfilter function to apply
|
861 | * to a compiled template after compilation
|
861 | * to a compiled template after compilation
|
862 | *
|
862 | *
|
863 | * @param callback $function
|
863 | * @param callback $function
|
864 | */
|
864 | */
|
865 | function register_postfilter($function) |
865 | function register_postfilter($function) |
866 | {
|
866 | {
|
867 | $this->_plugins['postfilter'][$this->_get_filter_name($function)] |
867 | $this->_plugins['postfilter'][$this->_get_filter_name($function)] |
868 | = array($function, null, null, false); |
868 | = array($function, null, null, false); |
869 | }
|
869 | }
|
870 | 870 | ||
871 | /**
|
871 | /**
|
872 | * Unregisters a postfilter function
|
872 | * Unregisters a postfilter function
|
873 | *
|
873 | *
|
874 | * @param callback $function
|
874 | * @param callback $function
|
875 | */
|
875 | */
|
876 | function unregister_postfilter($function) |
876 | function unregister_postfilter($function) |
877 | {
|
877 | {
|
878 | unset($this->_plugins['postfilter'][$this->_get_filter_name($function)]); |
878 | unset($this->_plugins['postfilter'][$this->_get_filter_name($function)]); |
879 | }
|
879 | }
|
880 | 880 | ||
881 | /**
|
881 | /**
|
882 | * Registers an output filter function to apply
|
882 | * Registers an output filter function to apply
|
883 | * to a template output
|
883 | * to a template output
|
884 | *
|
884 | *
|
885 | * @param callback $function
|
885 | * @param callback $function
|
886 | */
|
886 | */
|
887 | function register_outputfilter($function) |
887 | function register_outputfilter($function) |
888 | {
|
888 | {
|
889 | $this->_plugins['outputfilter'][$this->_get_filter_name($function)] |
889 | $this->_plugins['outputfilter'][$this->_get_filter_name($function)] |
890 | = array($function, null, null, false); |
890 | = array($function, null, null, false); |
891 | }
|
891 | }
|
892 | 892 | ||
893 | /**
|
893 | /**
|
894 | * Unregisters an outputfilter function
|
894 | * Unregisters an outputfilter function
|
895 | *
|
895 | *
|
896 | * @param callback $function
|
896 | * @param callback $function
|
897 | */
|
897 | */
|
898 | function unregister_outputfilter($function) |
898 | function unregister_outputfilter($function) |
899 | {
|
899 | {
|
900 | unset($this->_plugins['outputfilter'][$this->_get_filter_name($function)]); |
900 | unset($this->_plugins['outputfilter'][$this->_get_filter_name($function)]); |
901 | }
|
901 | }
|
902 | 902 | ||
903 | /**
|
903 | /**
|
904 | * load a filter of specified type and name
|
904 | * load a filter of specified type and name
|
905 | *
|
905 | *
|
906 | * @param string $type filter type
|
906 | * @param string $type filter type
|
907 | * @param string $name filter name
|
907 | * @param string $name filter name
|
908 | */
|
908 | */
|
909 | function load_filter($type, $name) |
909 | function load_filter($type, $name) |
910 | {
|
910 | {
|
911 | switch ($type) { |
911 | switch ($type) { |
912 | case 'output': |
912 | case 'output': |
913 | $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false))); |
913 | $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false))); |
914 | require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); |
914 | require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); |
915 | smarty_core_load_plugins($_params, $this); |
915 | smarty_core_load_plugins($_params, $this); |
916 | break; |
916 | break; |
917 | 917 | ||
918 | case 'pre': |
918 | case 'pre': |
919 | case 'post': |
919 | case 'post': |
920 | if (!isset($this->_plugins[$type . 'filter'][$name])) |
920 | if (!isset($this->_plugins[$type . 'filter'][$name])) |
921 | $this->_plugins[$type . 'filter'][$name] = false; |
921 | $this->_plugins[$type . 'filter'][$name] = false; |
922 | break; |
922 | break; |
923 | }
|
923 | }
|
924 | }
|
924 | }
|
925 | 925 | ||
926 | /**
|
926 | /**
|
927 | * clear cached content for the given template and cache id
|
927 | * clear cached content for the given template and cache id
|
928 | *
|
928 | *
|
929 | * @param string $tpl_file name of template file
|
929 | * @param string $tpl_file name of template file
|
930 | * @param string $cache_id name of cache_id
|
930 | * @param string $cache_id name of cache_id
|
931 | * @param string $compile_id name of compile_id
|
931 | * @param string $compile_id name of compile_id
|
932 | * @param string $exp_time expiration time
|
932 | * @param string $exp_time expiration time
|
933 | * @return boolean
|
933 | * @return boolean
|
934 | */
|
934 | */
|
935 | function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) |
935 | function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) |
936 | {
|
936 | {
|
937 | 937 | ||
938 | if (!isset($compile_id)) |
938 | if (!isset($compile_id)) |
939 | $compile_id = $this->compile_id; |
939 | $compile_id = $this->compile_id; |
940 | 940 | ||
941 | if (!isset($tpl_file)) |
941 | if (!isset($tpl_file)) |
942 | $compile_id = null; |
942 | $compile_id = null; |
943 | 943 | ||
944 | $_auto_id = $this->_get_auto_id($cache_id, $compile_id); |
944 | $_auto_id = $this->_get_auto_id($cache_id, $compile_id); |
945 | 945 | ||
946 | if (!empty($this->cache_handler_func)) { |
946 | if (!empty($this->cache_handler_func)) { |
947 | return call_user_func_array($this->cache_handler_func, |
947 | return call_user_func_array($this->cache_handler_func, |
948 | array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time)); |
948 | array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time)); |
949 | } else { |
949 | } else { |
950 | $_params = array('auto_base' => $this->cache_dir, |
950 | $_params = array('auto_base' => $this->cache_dir, |
951 | 'auto_source' => $tpl_file, |
951 | 'auto_source' => $tpl_file, |
952 | 'auto_id' => $_auto_id, |
952 | 'auto_id' => $_auto_id, |
953 | 'exp_time' => $exp_time); |
953 | 'exp_time' => $exp_time); |
954 | require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); |
954 | require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); |
955 | return smarty_core_rm_auto($_params, $this); |
955 | return smarty_core_rm_auto($_params, $this); |
956 | }
|
956 | }
|
957 | 957 | ||
958 | }
|
958 | }
|
959 | 959 | ||
960 | 960 | ||
961 | /**
|
961 | /**
|
962 | * clear the entire contents of cache (all templates)
|
962 | * clear the entire contents of cache (all templates)
|
963 | *
|
963 | *
|
964 | * @param string $exp_time expire time
|
964 | * @param string $exp_time expire time
|
965 | * @return boolean results of {@link smarty_core_rm_auto()}
|
965 | * @return boolean results of {@link smarty_core_rm_auto()}
|
966 | */
|
966 | */
|
967 | function clear_all_cache($exp_time = null) |
967 | function clear_all_cache($exp_time = null) |
968 | {
|
968 | {
|
969 | return $this->clear_cache(null, null, null, $exp_time); |
969 | return $this->clear_cache(null, null, null, $exp_time); |
970 | }
|
970 | }
|
971 | 971 | ||
972 | 972 | ||
973 | /**
|
973 | /**
|
974 | * test to see if valid cache exists for this template
|
974 | * test to see if valid cache exists for this template
|
975 | *
|
975 | *
|
976 | * @param string $tpl_file name of template file
|
976 | * @param string $tpl_file name of template file
|
977 | * @param string $cache_id
|
977 | * @param string $cache_id
|
978 | * @param string $compile_id
|
978 | * @param string $compile_id
|
979 | * @return string|false results of {@link _read_cache_file()}
|
979 | * @return string|false results of {@link _read_cache_file()}
|
980 | */
|
980 | */
|
981 | function is_cached($tpl_file, $cache_id = null, $compile_id = null) |
981 | function is_cached($tpl_file, $cache_id = null, $compile_id = null) |
982 | {
|
982 | {
|
983 | if (!$this->caching) |
983 | if (!$this->caching) |
984 | return false; |
984 | return false; |
985 | 985 | ||
986 | if (!isset($compile_id)) |
986 | if (!isset($compile_id)) |
987 | $compile_id = $this->compile_id; |
987 | $compile_id = $this->compile_id; |
988 | 988 | ||
989 | $_params = array( |
989 | $_params = array( |
990 | 'tpl_file' => $tpl_file, |
990 | 'tpl_file' => $tpl_file, |
991 | 'cache_id' => $cache_id, |
991 | 'cache_id' => $cache_id, |
992 | 'compile_id' => $compile_id |
992 | 'compile_id' => $compile_id |
993 | ); |
993 | ); |
994 | require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); |
994 | require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); |
995 | return smarty_core_read_cache_file($_params, $this); |
995 | return smarty_core_read_cache_file($_params, $this); |
996 | }
|
996 | }
|
997 | 997 | ||
998 | 998 | ||
999 | /**
|
999 | /**
|
1000 | * clear all the assigned template variables.
|
1000 | * clear all the assigned template variables.
|
1001 | *
|
1001 | *
|
1002 | */
|
1002 | */
|
1003 | function clear_all_assign() |
1003 | function clear_all_assign() |
1004 | {
|
1004 | {
|
1005 | $this->_tpl_vars = array(); |
1005 | $this->_tpl_vars = array(); |
1006 | }
|
1006 | }
|
1007 | 1007 | ||
1008 | /**
|
1008 | /**
|
1009 | * clears compiled version of specified template resource,
|
1009 | * clears compiled version of specified template resource,
|
1010 | * or all compiled template files if one is not specified.
|
1010 | * or all compiled template files if one is not specified.
|
1011 | * This function is for advanced use only, not normally needed.
|
1011 | * This function is for advanced use only, not normally needed.
|
1012 | *
|
1012 | *
|
1013 | * @param string $tpl_file
|
1013 | * @param string $tpl_file
|
1014 | * @param string $compile_id
|
1014 | * @param string $compile_id
|
1015 | * @param string $exp_time
|
1015 | * @param string $exp_time
|
1016 | * @return boolean results of {@link smarty_core_rm_auto()}
|
1016 | * @return boolean results of {@link smarty_core_rm_auto()}
|
1017 | */
|
1017 | */
|
1018 | function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) |
1018 | function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) |
1019 | {
|
1019 | {
|
1020 | if (!isset($compile_id)) { |
1020 | if (!isset($compile_id)) { |
1021 | $compile_id = $this->compile_id; |
1021 | $compile_id = $this->compile_id; |
1022 | }
|
1022 | }
|
1023 | $_params = array('auto_base' => $this->compile_dir, |
1023 | $_params = array('auto_base' => $this->compile_dir, |
1024 | 'auto_source' => $tpl_file, |
1024 | 'auto_source' => $tpl_file, |
1025 | 'auto_id' => $compile_id, |
1025 | 'auto_id' => $compile_id, |
1026 | 'exp_time' => $exp_time, |
1026 | 'exp_time' => $exp_time, |
1027 | 'extensions' => array('.inc', '.php')); |
1027 | 'extensions' => array('.inc', '.php')); |
1028 | require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); |
1028 | require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); |
1029 | return smarty_core_rm_auto($_params, $this); |
1029 | return smarty_core_rm_auto($_params, $this); |
1030 | }
|
1030 | }
|
1031 | 1031 | ||
1032 | /**
|
1032 | /**
|
1033 | * Checks whether requested template exists.
|
1033 | * Checks whether requested template exists.
|
1034 | *
|
1034 | *
|
1035 | * @param string $tpl_file
|
1035 | * @param string $tpl_file
|
1036 | * @return boolean
|
1036 | * @return boolean
|
1037 | */
|
1037 | */
|
1038 | function template_exists($tpl_file) |
1038 | function template_exists($tpl_file) |
1039 | {
|
1039 | {
|
1040 | $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false); |
1040 | $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false); |
1041 | return $this->_fetch_resource_info($_params); |
1041 | return $this->_fetch_resource_info($_params); |
1042 | }
|
1042 | }
|
1043 | 1043 | ||
1044 | /**
|
1044 | /**
|
1045 | * Returns an array containing template variables
|
1045 | * Returns an array containing template variables
|
1046 | *
|
1046 | *
|
1047 | * @param string $name
|
1047 | * @param string $name
|
1048 | * @param string $type
|
1048 | * @param string $type
|
1049 | * @return array
|
1049 | * @return array
|
1050 | */
|
1050 | */
|
1051 | function &get_template_vars($name=null) |
1051 | function &get_template_vars($name=null) |
1052 | {
|
1052 | {
|
1053 | if(!isset($name)) { |
1053 | if(!isset($name)) { |
1054 | return $this->_tpl_vars; |
1054 | return $this->_tpl_vars; |
1055 | } elseif(isset($this->_tpl_vars[$name])) { |
1055 | } elseif(isset($this->_tpl_vars[$name])) { |
1056 | return $this->_tpl_vars[$name]; |
1056 | return $this->_tpl_vars[$name]; |
1057 | } else { |
1057 | } else { |
1058 | // var non-existant, return valid reference
|
1058 | // var non-existant, return valid reference
|
1059 | $_tmp = null; |
1059 | $_tmp = null; |
1060 | return $_tmp; |
1060 | return $_tmp; |
1061 | }
|
1061 | }
|
1062 | }
|
1062 | }
|
1063 | 1063 | ||
1064 | /**
|
1064 | /**
|
1065 | * Returns an array containing config variables
|
1065 | * Returns an array containing config variables
|
1066 | *
|
1066 | *
|
1067 | * @param string $name
|
1067 | * @param string $name
|
1068 | * @param string $type
|
1068 | * @param string $type
|
1069 | * @return array
|
1069 | * @return array
|
1070 | */
|
1070 | */
|
1071 | function &get_config_vars($name=null) |
1071 | function &get_config_vars($name=null) |
1072 | {
|
1072 | {
|
1073 | if(!isset($name) && is_array($this->_config[0])) { |
1073 | if(!isset($name) && is_array($this->_config[0])) { |
1074 | return $this->_config[0]['vars']; |
1074 | return $this->_config[0]['vars']; |
1075 | } else if(isset($this->_config[0]['vars'][$name])) { |
1075 | } else if(isset($this->_config[0]['vars'][$name])) { |
1076 | return $this->_config[0]['vars'][$name]; |
1076 | return $this->_config[0]['vars'][$name]; |
1077 | } else { |
1077 | } else { |
1078 | // var non-existant, return valid reference
|
1078 | // var non-existant, return valid reference
|
1079 | $_tmp = null; |
1079 | $_tmp = null; |
1080 | return $_tmp; |
1080 | return $_tmp; |
1081 | }
|
1081 | }
|
1082 | }
|
1082 | }
|
1083 | 1083 | ||
1084 | /**
|
1084 | /**
|
1085 | * trigger Smarty error
|
1085 | * trigger Smarty error
|
1086 | *
|
1086 | *
|
1087 | * @param string $error_msg
|
1087 | * @param string $error_msg
|
1088 | * @param integer $error_type
|
1088 | * @param integer $error_type
|
1089 | */
|
1089 | */
|
1090 | function trigger_error($error_msg, $error_type = E_USER_WARNING) |
1090 | function trigger_error($error_msg, $error_type = E_USER_WARNING) |
1091 | {
|
1091 | {
|
1092 | trigger_error("Smarty error: $error_msg", $error_type); |
1092 | trigger_error("Smarty error: $error_msg", $error_type); |
1093 | }
|
1093 | }
|
1094 | 1094 | ||
1095 | 1095 | ||
1096 | /**
|
1096 | /**
|
1097 | * executes & displays the template results
|
1097 | * executes & displays the template results
|
1098 | *
|
1098 | *
|
1099 | * @param string $resource_name
|
1099 | * @param string $resource_name
|
1100 | * @param string $cache_id
|
1100 | * @param string $cache_id
|
1101 | * @param string $compile_id
|
1101 | * @param string $compile_id
|
1102 | */
|
1102 | */
|
1103 | function display($resource_name, $cache_id = null, $compile_id = null) |
1103 | function display($resource_name, $cache_id = null, $compile_id = null) |
1104 | {
|
1104 | {
|
1105 | $this->fetch($resource_name, $cache_id, $compile_id, true); |
1105 | $this->fetch($resource_name, $cache_id, $compile_id, true); |
1106 | }
|
1106 | }
|
1107 | 1107 | ||
1108 | /**
|
1108 | /**
|
1109 | * executes & returns or displays the template results
|
1109 | * executes & returns or displays the template results
|
1110 | *
|
1110 | *
|
1111 | * @param string $resource_name
|
1111 | * @param string $resource_name
|
1112 | * @param string $cache_id
|
1112 | * @param string $cache_id
|
1113 | * @param string $compile_id
|
1113 | * @param string $compile_id
|
1114 | * @param boolean $display
|
1114 | * @param boolean $display
|
1115 | */
|
1115 | */
|
1116 | function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) |
1116 | function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) |
1117 | {
|
1117 | {
|
1118 | static $_cache_info = array(); |
1118 | static $_cache_info = array(); |
1119 | 1119 | ||
1120 | $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting) |
1120 | $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting) |
1121 | ? $this->error_reporting : error_reporting() & ~E_NOTICE); |
1121 | ? $this->error_reporting : error_reporting() & ~E_NOTICE); |
1122 | 1122 | ||
1123 | if (!$this->debugging && $this->debugging_ctrl == 'URL') { |
1123 | if (!$this->debugging && $this->debugging_ctrl == 'URL') { |
1124 | $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']; |
1124 | $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']; |
1125 | if (@strstr($_query_string, $this->_smarty_debug_id)) { |
1125 | if (@strstr($_query_string, $this->_smarty_debug_id)) { |
1126 | if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) { |
1126 | if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) { |
1127 | // enable debugging for this browser session
|
1127 | // enable debugging for this browser session
|
1128 | @setcookie('SMARTY_DEBUG', true); |
1128 | @setcookie('SMARTY_DEBUG', true); |
1129 | $this->debugging = true; |
1129 | $this->debugging = true; |
1130 | } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) { |
1130 | } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) { |
1131 | // disable debugging for this browser session
|
1131 | // disable debugging for this browser session
|
1132 | @setcookie('SMARTY_DEBUG', false); |
1132 | @setcookie('SMARTY_DEBUG', false); |
1133 | $this->debugging = false; |
1133 | $this->debugging = false; |
1134 | } else { |
1134 | } else { |
1135 | // enable debugging for this page
|
1135 | // enable debugging for this page
|
1136 | $this->debugging = true; |
1136 | $this->debugging = true; |
1137 | }
|
1137 | }
|
1138 | } else { |
1138 | } else { |
1139 | $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']); |
1139 | $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']); |
1140 | }
|
1140 | }
|
1141 | }
|
1141 | }
|
1142 | 1142 | ||
1143 | if ($this->debugging) { |
1143 | if ($this->debugging) { |
1144 | // capture time for debugging info
|
1144 | // capture time for debugging info
|
1145 | $_params = array(); |
1145 | $_params = array(); |
1146 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1146 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1147 | $_debug_start_time = smarty_core_get_microtime($_params, $this); |
1147 | $_debug_start_time = smarty_core_get_microtime($_params, $this); |
1148 | $this->_smarty_debug_info[] = array('type' => 'template', |
1148 | $this->_smarty_debug_info[] = array('type' => 'template', |
1149 | 'filename' => $resource_name, |
1149 | 'filename' => $resource_name, |
1150 | 'depth' => 0); |
1150 | 'depth' => 0); |
1151 | $_included_tpls_idx = count($this->_smarty_debug_info) - 1; |
1151 | $_included_tpls_idx = count($this->_smarty_debug_info) - 1; |
1152 | }
|
1152 | }
|
1153 | 1153 | ||
1154 | if (!isset($compile_id)) { |
1154 | if (!isset($compile_id)) { |
1155 | $compile_id = $this->compile_id; |
1155 | $compile_id = $this->compile_id; |
1156 | }
|
1156 | }
|
1157 | 1157 | ||
1158 | $this->_compile_id = $compile_id; |
1158 | $this->_compile_id = $compile_id; |
1159 | $this->_inclusion_depth = 0; |
1159 | $this->_inclusion_depth = 0; |
1160 | 1160 | ||
1161 | if ($this->caching) { |
1161 | if ($this->caching) { |
1162 | // save old cache_info, initialize cache_info
|
1162 | // save old cache_info, initialize cache_info
|
1163 | array_push($_cache_info, $this->_cache_info); |
1163 | array_push($_cache_info, $this->_cache_info); |
1164 | $this->_cache_info = array(); |
1164 | $this->_cache_info = array(); |
1165 | $_params = array( |
1165 | $_params = array( |
1166 | 'tpl_file' => $resource_name, |
1166 | 'tpl_file' => $resource_name, |
1167 | 'cache_id' => $cache_id, |
1167 | 'cache_id' => $cache_id, |
1168 | 'compile_id' => $compile_id, |
1168 | 'compile_id' => $compile_id, |
1169 | 'results' => null |
1169 | 'results' => null |
1170 | ); |
1170 | ); |
1171 | require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); |
1171 | require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); |
1172 | if (smarty_core_read_cache_file($_params, $this)) { |
1172 | if (smarty_core_read_cache_file($_params, $this)) { |
1173 | $_smarty_results = $_params['results']; |
1173 | $_smarty_results = $_params['results']; |
1174 | if (!empty($this->_cache_info['insert_tags'])) { |
1174 | if (!empty($this->_cache_info['insert_tags'])) { |
1175 | $_params = array('plugins' => $this->_cache_info['insert_tags']); |
1175 | $_params = array('plugins' => $this->_cache_info['insert_tags']); |
1176 | require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); |
1176 | require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); |
1177 | smarty_core_load_plugins($_params, $this); |
1177 | smarty_core_load_plugins($_params, $this); |
1178 | $_params = array('results' => $_smarty_results); |
1178 | $_params = array('results' => $_smarty_results); |
1179 | require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); |
1179 | require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); |
1180 | $_smarty_results = smarty_core_process_cached_inserts($_params, $this); |
1180 | $_smarty_results = smarty_core_process_cached_inserts($_params, $this); |
1181 | }
|
1181 | }
|
1182 | if (!empty($this->_cache_info['cache_serials'])) { |
1182 | if (!empty($this->_cache_info['cache_serials'])) { |
1183 | $_params = array('results' => $_smarty_results); |
1183 | $_params = array('results' => $_smarty_results); |
1184 | require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php'); |
1184 | require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php'); |
1185 | $_smarty_results = smarty_core_process_compiled_include($_params, $this); |
1185 | $_smarty_results = smarty_core_process_compiled_include($_params, $this); |
1186 | }
|
1186 | }
|
1187 | 1187 | ||
1188 | 1188 | ||
1189 | if ($display) { |
1189 | if ($display) { |
1190 | if ($this->debugging) |
1190 | if ($this->debugging) |
1191 | {
|
1191 | {
|
1192 | // capture time for debugging info
|
1192 | // capture time for debugging info
|
1193 | $_params = array(); |
1193 | $_params = array(); |
1194 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1194 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1195 | $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time; |
1195 | $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time; |
1196 | require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); |
1196 | require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); |
1197 | $_smarty_results .= smarty_core_display_debug_console($_params, $this); |
1197 | $_smarty_results .= smarty_core_display_debug_console($_params, $this); |
1198 | }
|
1198 | }
|
1199 | if ($this->cache_modified_check) { |
1199 | if ($this->cache_modified_check) { |
1200 | $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; |
1200 | $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; |
1201 | $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); |
1201 | $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); |
1202 | $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT'; |
1202 | $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT'; |
1203 | if (@count($this->_cache_info['insert_tags']) == 0 |
1203 | if (@count($this->_cache_info['insert_tags']) == 0 |
1204 | && !$this->_cache_serials |
1204 | && !$this->_cache_serials |
1205 | && $_gmt_mtime == $_last_modified_date) { |
1205 | && $_gmt_mtime == $_last_modified_date) { |
1206 | if (php_sapi_name()=='cgi') |
1206 | if (php_sapi_name()=='cgi') |
1207 | header('Status: 304 Not Modified'); |
1207 | header('Status: 304 Not Modified'); |
1208 | else
|
1208 | else
|
1209 | header('HTTP/1.1 304 Not Modified'); |
1209 | header('HTTP/1.1 304 Not Modified'); |
1210 | 1210 | ||
1211 | } else { |
1211 | } else { |
1212 | header('Last-Modified: '.$_gmt_mtime); |
1212 | header('Last-Modified: '.$_gmt_mtime); |
1213 | echo $_smarty_results; |
1213 | echo $_smarty_results; |
1214 | }
|
1214 | }
|
1215 | } else { |
1215 | } else { |
1216 | echo $_smarty_results; |
1216 | echo $_smarty_results; |
1217 | }
|
1217 | }
|
1218 | error_reporting($_smarty_old_error_level); |
1218 | error_reporting($_smarty_old_error_level); |
1219 | // restore initial cache_info
|
1219 | // restore initial cache_info
|
1220 | $this->_cache_info = array_pop($_cache_info); |
1220 | $this->_cache_info = array_pop($_cache_info); |
1221 | return true; |
1221 | return true; |
1222 | } else { |
1222 | } else { |
1223 | error_reporting($_smarty_old_error_level); |
1223 | error_reporting($_smarty_old_error_level); |
1224 | // restore initial cache_info
|
1224 | // restore initial cache_info
|
1225 | $this->_cache_info = array_pop($_cache_info); |
1225 | $this->_cache_info = array_pop($_cache_info); |
1226 | return $_smarty_results; |
1226 | return $_smarty_results; |
1227 | }
|
1227 | }
|
1228 | } else { |
1228 | } else { |
1229 | $this->_cache_info['template'][$resource_name] = true; |
1229 | $this->_cache_info['template'][$resource_name] = true; |
1230 | if ($this->cache_modified_check && $display) { |
1230 | if ($this->cache_modified_check && $display) { |
1231 | header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); |
1231 | header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); |
1232 | }
|
1232 | }
|
1233 | }
|
1233 | }
|
1234 | }
|
1234 | }
|
1235 | 1235 | ||
1236 | // load filters that are marked as autoload
|
1236 | // load filters that are marked as autoload
|
1237 | if (count($this->autoload_filters)) { |
1237 | if (count($this->autoload_filters)) { |
1238 | foreach ($this->autoload_filters as $_filter_type => $_filters) { |
1238 | foreach ($this->autoload_filters as $_filter_type => $_filters) { |
1239 | foreach ($_filters as $_filter) { |
1239 | foreach ($_filters as $_filter) { |
1240 | $this->load_filter($_filter_type, $_filter); |
1240 | $this->load_filter($_filter_type, $_filter); |
1241 | }
|
1241 | }
|
1242 | }
|
1242 | }
|
1243 | }
|
1243 | }
|
1244 | 1244 | ||
1245 | $_smarty_compile_path = $this->_get_compile_path($resource_name); |
1245 | $_smarty_compile_path = $this->_get_compile_path($resource_name); |
1246 | 1246 | ||
1247 | // if we just need to display the results, don't perform output
|
1247 | // if we just need to display the results, don't perform output
|
1248 | // buffering - for speed
|
1248 | // buffering - for speed
|
1249 | $_cache_including = $this->_cache_including; |
1249 | $_cache_including = $this->_cache_including; |
1250 | $this->_cache_including = false; |
1250 | $this->_cache_including = false; |
1251 | if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) { |
1251 | if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) { |
1252 | if ($this->_is_compiled($resource_name, $_smarty_compile_path) |
1252 | if ($this->_is_compiled($resource_name, $_smarty_compile_path) |
1253 | || $this->_compile_resource($resource_name, $_smarty_compile_path)) |
1253 | || $this->_compile_resource($resource_name, $_smarty_compile_path)) |
1254 | {
|
1254 | {
|
1255 | include($_smarty_compile_path); |
1255 | include($_smarty_compile_path); |
1256 | }
|
1256 | }
|
1257 | } else { |
1257 | } else { |
1258 | ob_start(); |
1258 | ob_start(); |
1259 | if ($this->_is_compiled($resource_name, $_smarty_compile_path) |
1259 | if ($this->_is_compiled($resource_name, $_smarty_compile_path) |
1260 | || $this->_compile_resource($resource_name, $_smarty_compile_path)) |
1260 | || $this->_compile_resource($resource_name, $_smarty_compile_path)) |
1261 | {
|
1261 | {
|
1262 | include($_smarty_compile_path); |
1262 | include($_smarty_compile_path); |
1263 | }
|
1263 | }
|
1264 | $_smarty_results = ob_get_contents(); |
1264 | $_smarty_results = ob_get_contents(); |
1265 | ob_end_clean(); |
1265 | ob_end_clean(); |
1266 | 1266 | ||
1267 | foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) { |
1267 | foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) { |
1268 | $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this)); |
1268 | $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this)); |
1269 | }
|
1269 | }
|
1270 | }
|
1270 | }
|
1271 | 1271 | ||
1272 | if ($this->caching) { |
1272 | if ($this->caching) { |
1273 | $_params = array('tpl_file' => $resource_name, |
1273 | $_params = array('tpl_file' => $resource_name, |
1274 | 'cache_id' => $cache_id, |
1274 | 'cache_id' => $cache_id, |
1275 | 'compile_id' => $compile_id, |
1275 | 'compile_id' => $compile_id, |
1276 | 'results' => $_smarty_results); |
1276 | 'results' => $_smarty_results); |
1277 | require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php'); |
1277 | require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php'); |
1278 | smarty_core_write_cache_file($_params, $this); |
1278 | smarty_core_write_cache_file($_params, $this); |
1279 | require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); |
1279 | require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); |
1280 | $_smarty_results = smarty_core_process_cached_inserts($_params, $this); |
1280 | $_smarty_results = smarty_core_process_cached_inserts($_params, $this); |
1281 | 1281 | ||
1282 | if ($this->_cache_serials) { |
1282 | if ($this->_cache_serials) { |
1283 | // strip nocache-tags from output
|
1283 | // strip nocache-tags from output
|
1284 | $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s' |
1284 | $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s' |
1285 | ,'' |
1285 | ,'' |
1286 | ,$_smarty_results); |
1286 | ,$_smarty_results); |
1287 | }
|
1287 | }
|
1288 | // restore initial cache_info
|
1288 | // restore initial cache_info
|
1289 | $this->_cache_info = array_pop($_cache_info); |
1289 | $this->_cache_info = array_pop($_cache_info); |
1290 | }
|
1290 | }
|
1291 | $this->_cache_including = $_cache_including; |
1291 | $this->_cache_including = $_cache_including; |
1292 | 1292 | ||
1293 | if ($display) { |
1293 | if ($display) { |
1294 | if (isset($_smarty_results)) { echo $_smarty_results; } |
1294 | if (isset($_smarty_results)) { echo $_smarty_results; } |
1295 | if ($this->debugging) { |
1295 | if ($this->debugging) { |
1296 | // capture time for debugging info
|
1296 | // capture time for debugging info
|
1297 | $_params = array(); |
1297 | $_params = array(); |
1298 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1298 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1299 | $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time); |
1299 | $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time); |
1300 | require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); |
1300 | require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); |
1301 | echo smarty_core_display_debug_console($_params, $this); |
1301 | echo smarty_core_display_debug_console($_params, $this); |
1302 | }
|
1302 | }
|
1303 | error_reporting($_smarty_old_error_level); |
1303 | error_reporting($_smarty_old_error_level); |
1304 | return; |
1304 | return; |
1305 | } else { |
1305 | } else { |
1306 | error_reporting($_smarty_old_error_level); |
1306 | error_reporting($_smarty_old_error_level); |
1307 | if (isset($_smarty_results)) { return $_smarty_results; } |
1307 | if (isset($_smarty_results)) { return $_smarty_results; } |
1308 | }
|
1308 | }
|
1309 | }
|
1309 | }
|
1310 | 1310 | ||
1311 | /**
|
1311 | /**
|
1312 | * load configuration values
|
1312 | * load configuration values
|
1313 | *
|
1313 | *
|
1314 | * @param string $file
|
1314 | * @param string $file
|
1315 | * @param string $section
|
1315 | * @param string $section
|
1316 | * @param string $scope
|
1316 | * @param string $scope
|
1317 | */
|
1317 | */
|
1318 | function config_load($file, $section = null, $scope = 'global') |
1318 | function config_load($file, $section = null, $scope = 'global') |
1319 | {
|
1319 | {
|
1320 | require_once($this->_get_plugin_filepath('function', 'config_load')); |
1320 | require_once($this->_get_plugin_filepath('function', 'config_load')); |
1321 | smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this); |
1321 | smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this); |
1322 | }
|
1322 | }
|
1323 | 1323 | ||
1324 | /**
|
1324 | /**
|
1325 | * return a reference to a registered object
|
1325 | * return a reference to a registered object
|
1326 | *
|
1326 | *
|
1327 | * @param string $name
|
1327 | * @param string $name
|
1328 | * @return object
|
1328 | * @return object
|
1329 | */
|
1329 | */
|
1330 | function &get_registered_object($name) { |
1330 | function &get_registered_object($name) { |
1331 | if (!isset($this->_reg_objects[$name])) |
1331 | if (!isset($this->_reg_objects[$name])) |
1332 | $this->_trigger_fatal_error("'$name' is not a registered object"); |
1332 | $this->_trigger_fatal_error("'$name' is not a registered object"); |
1333 | 1333 | ||
1334 | if (!is_object($this->_reg_objects[$name][0])) |
1334 | if (!is_object($this->_reg_objects[$name][0])) |
1335 | $this->_trigger_fatal_error("registered '$name' is not an object"); |
1335 | $this->_trigger_fatal_error("registered '$name' is not an object"); |
1336 | 1336 | ||
1337 | return $this->_reg_objects[$name][0]; |
1337 | return $this->_reg_objects[$name][0]; |
1338 | }
|
1338 | }
|
1339 | 1339 | ||
1340 | /**
|
1340 | /**
|
1341 | * clear configuration values
|
1341 | * clear configuration values
|
1342 | *
|
1342 | *
|
1343 | * @param string $var
|
1343 | * @param string $var
|
1344 | */
|
1344 | */
|
1345 | function clear_config($var = null) |
1345 | function clear_config($var = null) |
1346 | {
|
1346 | {
|
1347 | if(!isset($var)) { |
1347 | if(!isset($var)) { |
1348 | // clear all values
|
1348 | // clear all values
|
1349 | $this->_config = array(array('vars' => array(), |
1349 | $this->_config = array(array('vars' => array(), |
1350 | 'files' => array())); |
1350 | 'files' => array())); |
1351 | } else { |
1351 | } else { |
1352 | unset($this->_config[0]['vars'][$var]); |
1352 | unset($this->_config[0]['vars'][$var]); |
1353 | }
|
1353 | }
|
1354 | }
|
1354 | }
|
1355 | 1355 | ||
1356 | /**
|
1356 | /**
|
1357 | * get filepath of requested plugin
|
1357 | * get filepath of requested plugin
|
1358 | *
|
1358 | *
|
1359 | * @param string $type
|
1359 | * @param string $type
|
1360 | * @param string $name
|
1360 | * @param string $name
|
1361 | * @return string|false
|
1361 | * @return string|false
|
1362 | */
|
1362 | */
|
1363 | function _get_plugin_filepath($type, $name) |
1363 | function _get_plugin_filepath($type, $name) |
1364 | {
|
1364 | {
|
1365 | $_params = array('type' => $type, 'name' => $name); |
1365 | $_params = array('type' => $type, 'name' => $name); |
1366 | require_once(SMARTY_CORE_DIR . 'core.assemble_plugin_filepath.php'); |
1366 | require_once(SMARTY_CORE_DIR . 'core.assemble_plugin_filepath.php'); |
1367 | return smarty_core_assemble_plugin_filepath($_params, $this); |
1367 | return smarty_core_assemble_plugin_filepath($_params, $this); |
1368 | }
|
1368 | }
|
1369 | 1369 | ||
1370 | /**
|
1370 | /**
|
1371 | * test if resource needs compiling
|
1371 | * test if resource needs compiling
|
1372 | *
|
1372 | *
|
1373 | * @param string $resource_name
|
1373 | * @param string $resource_name
|
1374 | * @param string $compile_path
|
1374 | * @param string $compile_path
|
1375 | * @return boolean
|
1375 | * @return boolean
|
1376 | */
|
1376 | */
|
1377 | function _is_compiled($resource_name, $compile_path) |
1377 | function _is_compiled($resource_name, $compile_path) |
1378 | {
|
1378 | {
|
1379 | if (!$this->force_compile && file_exists($compile_path)) { |
1379 | if (!$this->force_compile && file_exists($compile_path)) { |
1380 | if (!$this->compile_check) { |
1380 | if (!$this->compile_check) { |
1381 | // no need to check compiled file
|
1381 | // no need to check compiled file
|
1382 | return true; |
1382 | return true; |
1383 | } else { |
1383 | } else { |
1384 | // get file source and timestamp
|
1384 | // get file source and timestamp
|
1385 | $_params = array('resource_name' => $resource_name, 'get_source'=>false); |
1385 | $_params = array('resource_name' => $resource_name, 'get_source'=>false); |
1386 | if (!$this->_fetch_resource_info($_params)) { |
1386 | if (!$this->_fetch_resource_info($_params)) { |
1387 | return false; |
1387 | return false; |
1388 | }
|
1388 | }
|
1389 | if ($_params['resource_timestamp'] <= filemtime($compile_path)) { |
1389 | if ($_params['resource_timestamp'] <= filemtime($compile_path)) { |
1390 | // template not expired, no recompile
|
1390 | // template not expired, no recompile
|
1391 | return true; |
1391 | return true; |
1392 | } else { |
1392 | } else { |
1393 | // compile template
|
1393 | // compile template
|
1394 | return false; |
1394 | return false; |
1395 | }
|
1395 | }
|
1396 | }
|
1396 | }
|
1397 | } else { |
1397 | } else { |
1398 | // compiled template does not exist, or forced compile
|
1398 | // compiled template does not exist, or forced compile
|
1399 | return false; |
1399 | return false; |
1400 | }
|
1400 | }
|
1401 | }
|
1401 | }
|
1402 | 1402 | ||
1403 | /**
|
1403 | /**
|
1404 | * compile the template
|
1404 | * compile the template
|
1405 | *
|
1405 | *
|
1406 | * @param string $resource_name
|
1406 | * @param string $resource_name
|
1407 | * @param string $compile_path
|
1407 | * @param string $compile_path
|
1408 | * @return boolean
|
1408 | * @return boolean
|
1409 | */
|
1409 | */
|
1410 | function _compile_resource($resource_name, $compile_path) |
1410 | function _compile_resource($resource_name, $compile_path) |
1411 | {
|
1411 | {
|
1412 | 1412 | ||
1413 | $_params = array('resource_name' => $resource_name); |
1413 | $_params = array('resource_name' => $resource_name); |
1414 | if (!$this->_fetch_resource_info($_params)) { |
1414 | if (!$this->_fetch_resource_info($_params)) { |
1415 | return false; |
1415 | return false; |
1416 | }
|
1416 | }
|
1417 | 1417 | ||
1418 | $_source_content = $_params['source_content']; |
1418 | $_source_content = $_params['source_content']; |
1419 | $_cache_include = substr($compile_path, 0, -4).'.inc'; |
1419 | $_cache_include = substr($compile_path, 0, -4).'.inc'; |
1420 | 1420 | ||
1421 | if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) { |
1421 | if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) { |
1422 | // if a _cache_serial was set, we also have to write an include-file:
|
1422 | // if a _cache_serial was set, we also have to write an include-file:
|
1423 | if ($this->_cache_include_info) { |
1423 | if ($this->_cache_include_info) { |
1424 | require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php'); |
1424 | require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php'); |
1425 | smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)), $this); |
1425 | smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)), $this); |
1426 | }
|
1426 | }
|
1427 | 1427 | ||
1428 | $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content); |
1428 | $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content); |
1429 | require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php'); |
1429 | require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php'); |
1430 | smarty_core_write_compiled_resource($_params, $this); |
1430 | smarty_core_write_compiled_resource($_params, $this); |
1431 | 1431 | ||
1432 | return true; |
1432 | return true; |
1433 | } else { |
1433 | } else { |
1434 | return false; |
1434 | return false; |
1435 | }
|
1435 | }
|
1436 | 1436 | ||
1437 | }
|
1437 | }
|
1438 | 1438 | ||
1439 | /**
|
1439 | /**
|
1440 | * compile the given source
|
1440 | * compile the given source
|
1441 | *
|
1441 | *
|
1442 | * @param string $resource_name
|
1442 | * @param string $resource_name
|
1443 | * @param string $source_content
|
1443 | * @param string $source_content
|
1444 | * @param string $compiled_content
|
1444 | * @param string $compiled_content
|
1445 | * @return boolean
|
1445 | * @return boolean
|
1446 | */
|
1446 | */
|
1447 | function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null) |
1447 | function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null) |
1448 | {
|
1448 | {
|
1449 | if (file_exists(SMARTY_DIR . $this->compiler_file)) { |
1449 | if (file_exists(SMARTY_DIR . $this->compiler_file)) { |
1450 | require_once(SMARTY_DIR . $this->compiler_file); |
1450 | require_once(SMARTY_DIR . $this->compiler_file); |
1451 | } else { |
1451 | } else { |
1452 | // use include_path
|
1452 | // use include_path
|
1453 | require_once($this->compiler_file); |
1453 | require_once($this->compiler_file); |
1454 | }
|
1454 | }
|
1455 | 1455 | ||
1456 | 1456 | ||
1457 | $smarty_compiler = new $this->compiler_class; |
1457 | $smarty_compiler = new $this->compiler_class; |
1458 | 1458 | ||
1459 | $smarty_compiler->template_dir = $this->template_dir; |
1459 | $smarty_compiler->template_dir = $this->template_dir; |
1460 | $smarty_compiler->compile_dir = $this->compile_dir; |
1460 | $smarty_compiler->compile_dir = $this->compile_dir; |
1461 | $smarty_compiler->plugins_dir = $this->plugins_dir; |
1461 | $smarty_compiler->plugins_dir = $this->plugins_dir; |
1462 | $smarty_compiler->config_dir = $this->config_dir; |
1462 | $smarty_compiler->config_dir = $this->config_dir; |
1463 | $smarty_compiler->force_compile = $this->force_compile; |
1463 | $smarty_compiler->force_compile = $this->force_compile; |
1464 | $smarty_compiler->caching = $this->caching; |
1464 | $smarty_compiler->caching = $this->caching; |
1465 | $smarty_compiler->php_handling = $this->php_handling; |
1465 | $smarty_compiler->php_handling = $this->php_handling; |
1466 | $smarty_compiler->left_delimiter = $this->left_delimiter; |
1466 | $smarty_compiler->left_delimiter = $this->left_delimiter; |
1467 | $smarty_compiler->right_delimiter = $this->right_delimiter; |
1467 | $smarty_compiler->right_delimiter = $this->right_delimiter; |
1468 | $smarty_compiler->_version = $this->_version; |
1468 | $smarty_compiler->_version = $this->_version; |
1469 | $smarty_compiler->security = $this->security; |
1469 | $smarty_compiler->security = $this->security; |
1470 | $smarty_compiler->secure_dir = $this->secure_dir; |
1470 | $smarty_compiler->secure_dir = $this->secure_dir; |
1471 | $smarty_compiler->security_settings = $this->security_settings; |
1471 | $smarty_compiler->security_settings = $this->security_settings; |
1472 | $smarty_compiler->trusted_dir = $this->trusted_dir; |
1472 | $smarty_compiler->trusted_dir = $this->trusted_dir; |
1473 | $smarty_compiler->use_sub_dirs = $this->use_sub_dirs; |
1473 | $smarty_compiler->use_sub_dirs = $this->use_sub_dirs; |
1474 | $smarty_compiler->_reg_objects = &$this->_reg_objects; |
1474 | $smarty_compiler->_reg_objects = &$this->_reg_objects; |
1475 | $smarty_compiler->_plugins = &$this->_plugins; |
1475 | $smarty_compiler->_plugins = &$this->_plugins; |
1476 | $smarty_compiler->_tpl_vars = &$this->_tpl_vars; |
1476 | $smarty_compiler->_tpl_vars = &$this->_tpl_vars; |
1477 | $smarty_compiler->default_modifiers = $this->default_modifiers; |
1477 | $smarty_compiler->default_modifiers = $this->default_modifiers; |
1478 | $smarty_compiler->compile_id = $this->_compile_id; |
1478 | $smarty_compiler->compile_id = $this->_compile_id; |
1479 | $smarty_compiler->_config = $this->_config; |
1479 | $smarty_compiler->_config = $this->_config; |
1480 | $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals; |
1480 | $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals; |
1481 | 1481 | ||
1482 | if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) { |
1482 | if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) { |
1483 | $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path]; |
1483 | $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path]; |
1484 | }
|
1484 | }
|
1485 | $smarty_compiler->_cache_include = $cache_include_path; |
1485 | $smarty_compiler->_cache_include = $cache_include_path; |
1486 | 1486 | ||
1487 | 1487 | ||
1488 | $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content); |
1488 | $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content); |
1489 | 1489 | ||
1490 | if ($smarty_compiler->_cache_serial) { |
1490 | if ($smarty_compiler->_cache_serial) { |
1491 | $this->_cache_include_info = array( |
1491 | $this->_cache_include_info = array( |
1492 | 'cache_serial'=>$smarty_compiler->_cache_serial |
1492 | 'cache_serial'=>$smarty_compiler->_cache_serial |
1493 | ,'plugins_code'=>$smarty_compiler->_plugins_code |
1493 | ,'plugins_code'=>$smarty_compiler->_plugins_code |
1494 | ,'include_file_path' => $cache_include_path); |
1494 | ,'include_file_path' => $cache_include_path); |
1495 | 1495 | ||
1496 | } else { |
1496 | } else { |
1497 | $this->_cache_include_info = null; |
1497 | $this->_cache_include_info = null; |
1498 | 1498 | ||
1499 | }
|
1499 | }
|
1500 | 1500 | ||
1501 | return $_results; |
1501 | return $_results; |
1502 | }
|
1502 | }
|
1503 | 1503 | ||
1504 | /**
|
1504 | /**
|
1505 | * Get the compile path for this resource
|
1505 | * Get the compile path for this resource
|
1506 | *
|
1506 | *
|
1507 | * @param string $resource_name
|
1507 | * @param string $resource_name
|
1508 | * @return string results of {@link _get_auto_filename()}
|
1508 | * @return string results of {@link _get_auto_filename()}
|
1509 | */
|
1509 | */
|
1510 | function _get_compile_path($resource_name) |
1510 | function _get_compile_path($resource_name) |
1511 | {
|
1511 | {
|
1512 | return $this->_get_auto_filename($this->compile_dir, $resource_name, |
1512 | return $this->_get_auto_filename($this->compile_dir, $resource_name, |
1513 | $this->_compile_id) . '.php'; |
1513 | $this->_compile_id) . '.php'; |
1514 | }
|
1514 | }
|
1515 | 1515 | ||
1516 | /**
|
1516 | /**
|
1517 | * fetch the template info. Gets timestamp, and source
|
1517 | * fetch the template info. Gets timestamp, and source
|
1518 | * if get_source is true
|
1518 | * if get_source is true
|
1519 | *
|
1519 | *
|
1520 | * sets $source_content to the source of the template, and
|
1520 | * sets $source_content to the source of the template, and
|
1521 | * $resource_timestamp to its time stamp
|
1521 | * $resource_timestamp to its time stamp
|
1522 | * @param string $resource_name
|
1522 | * @param string $resource_name
|
1523 | * @param string $source_content
|
1523 | * @param string $source_content
|
1524 | * @param integer $resource_timestamp
|
1524 | * @param integer $resource_timestamp
|
1525 | * @param boolean $get_source
|
1525 | * @param boolean $get_source
|
1526 | * @param boolean $quiet
|
1526 | * @param boolean $quiet
|
1527 | * @return boolean
|
1527 | * @return boolean
|
1528 | */
|
1528 | */
|
1529 | 1529 | ||
1530 | function _fetch_resource_info(&$params) |
1530 | function _fetch_resource_info(&$params) |
1531 | {
|
1531 | {
|
1532 | if(!isset($params['get_source'])) { $params['get_source'] = true; } |
1532 | if(!isset($params['get_source'])) { $params['get_source'] = true; } |
1533 | if(!isset($params['quiet'])) { $params['quiet'] = false; } |
1533 | if(!isset($params['quiet'])) { $params['quiet'] = false; } |
1534 | 1534 | ||
1535 | $_return = false; |
1535 | $_return = false; |
1536 | $_params = array('resource_name' => $params['resource_name']) ; |
1536 | $_params = array('resource_name' => $params['resource_name']) ; |
1537 | if (isset($params['resource_base_path'])) |
1537 | if (isset($params['resource_base_path'])) |
1538 | $_params['resource_base_path'] = $params['resource_base_path']; |
1538 | $_params['resource_base_path'] = $params['resource_base_path']; |
1539 | else
|
1539 | else
|
1540 | $_params['resource_base_path'] = $this->template_dir; |
1540 | $_params['resource_base_path'] = $this->template_dir; |
1541 | 1541 | ||
1542 | if ($this->_parse_resource_name($_params)) { |
1542 | if ($this->_parse_resource_name($_params)) { |
1543 | $_resource_type = $_params['resource_type']; |
1543 | $_resource_type = $_params['resource_type']; |
1544 | $_resource_name = $_params['resource_name']; |
1544 | $_resource_name = $_params['resource_name']; |
1545 | switch ($_resource_type) { |
1545 | switch ($_resource_type) { |
1546 | case 'file': |
1546 | case 'file': |
1547 | if ($params['get_source']) { |
1547 | if ($params['get_source']) { |
1548 | $params['source_content'] = $this->_read_file($_resource_name); |
1548 | $params['source_content'] = $this->_read_file($_resource_name); |
1549 | }
|
1549 | }
|
1550 | $params['resource_timestamp'] = filemtime($_resource_name); |
1550 | $params['resource_timestamp'] = filemtime($_resource_name); |
1551 | $_return = is_file($_resource_name); |
1551 | $_return = is_file($_resource_name); |
1552 | break; |
1552 | break; |
1553 | 1553 | ||
1554 | default: |
1554 | default: |
1555 | // call resource functions to fetch the template source and timestamp
|
1555 | // call resource functions to fetch the template source and timestamp
|
1556 | if ($params['get_source']) { |
1556 | if ($params['get_source']) { |
1557 | $_source_return = isset($this->_plugins['resource'][$_resource_type]) && |
1557 | $_source_return = isset($this->_plugins['resource'][$_resource_type]) && |
1558 | call_user_func_array($this->_plugins['resource'][$_resource_type][0][0], |
1558 | call_user_func_array($this->_plugins['resource'][$_resource_type][0][0], |
1559 | array($_resource_name, &$params['source_content'], &$this)); |
1559 | array($_resource_name, &$params['source_content'], &$this)); |
1560 | } else { |
1560 | } else { |
1561 | $_source_return = true; |
1561 | $_source_return = true; |
1562 | }
|
1562 | }
|
1563 | 1563 | ||
1564 | $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) && |
1564 | $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) && |
1565 | call_user_func_array($this->_plugins['resource'][$_resource_type][0][1], |
1565 | call_user_func_array($this->_plugins['resource'][$_resource_type][0][1], |
1566 | array($_resource_name, &$params['resource_timestamp'], &$this)); |
1566 | array($_resource_name, &$params['resource_timestamp'], &$this)); |
1567 | 1567 | ||
1568 | $_return = $_source_return && $_timestamp_return; |
1568 | $_return = $_source_return && $_timestamp_return; |
1569 | break; |
1569 | break; |
1570 | }
|
1570 | }
|
1571 | }
|
1571 | }
|
1572 | 1572 | ||
1573 | if (!$_return) { |
1573 | if (!$_return) { |
1574 | // see if we can get a template with the default template handler
|
1574 | // see if we can get a template with the default template handler
|
1575 | if (!empty($this->default_template_handler_func)) { |
1575 | if (!empty($this->default_template_handler_func)) { |
1576 | if (!is_callable($this->default_template_handler_func)) { |
1576 | if (!is_callable($this->default_template_handler_func)) { |
1577 | $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist."); |
1577 | $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist."); |
1578 | } else { |
1578 | } else { |
1579 | $_return = call_user_func_array( |
1579 | $_return = call_user_func_array( |
1580 | $this->default_template_handler_func, |
1580 | $this->default_template_handler_func, |
1581 | array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this)); |
1581 | array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this)); |
1582 | }
|
1582 | }
|
1583 | }
|
1583 | }
|
1584 | }
|
1584 | }
|
1585 | 1585 | ||
1586 | if (!$_return) { |
1586 | if (!$_return) { |
1587 | if (!$params['quiet']) { |
1587 | if (!$params['quiet']) { |
1588 | $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"'); |
1588 | $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"'); |
1589 | }
|
1589 | }
|
1590 | } else if ($_return && $this->security) { |
1590 | } else if ($_return && $this->security) { |
1591 | require_once(SMARTY_CORE_DIR . 'core.is_secure.php'); |
1591 | require_once(SMARTY_CORE_DIR . 'core.is_secure.php'); |
1592 | if (!smarty_core_is_secure($_params, $this)) { |
1592 | if (!smarty_core_is_secure($_params, $this)) { |
1593 | if (!$params['quiet']) |
1593 | if (!$params['quiet']) |
1594 | $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed'); |
1594 | $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed'); |
1595 | $params['source_content'] = null; |
1595 | $params['source_content'] = null; |
1596 | $params['resource_timestamp'] = null; |
1596 | $params['resource_timestamp'] = null; |
1597 | return false; |
1597 | return false; |
1598 | }
|
1598 | }
|
1599 | }
|
1599 | }
|
1600 | return $_return; |
1600 | return $_return; |
1601 | }
|
1601 | }
|
1602 | 1602 | ||
1603 | 1603 | ||
1604 | /**
|
1604 | /**
|
1605 | * parse out the type and name from the resource
|
1605 | * parse out the type and name from the resource
|
1606 | *
|
1606 | *
|
1607 | * @param string $resource_base_path
|
1607 | * @param string $resource_base_path
|
1608 | * @param string $resource_name
|
1608 | * @param string $resource_name
|
1609 | * @param string $resource_type
|
1609 | * @param string $resource_type
|
1610 | * @param string $resource_name
|
1610 | * @param string $resource_name
|
1611 | * @return boolean
|
1611 | * @return boolean
|
1612 | */
|
1612 | */
|
1613 | 1613 | ||
1614 | function _parse_resource_name(&$params) |
1614 | function _parse_resource_name(&$params) |
1615 | {
|
1615 | {
|
1616 | 1616 | ||
1617 | // split tpl_path by the first colon
|
1617 | // split tpl_path by the first colon
|
1618 | $_resource_name_parts = explode(':', $params['resource_name'], 2); |
1618 | $_resource_name_parts = explode(':', $params['resource_name'], 2); |
1619 | 1619 | ||
1620 | if (count($_resource_name_parts) == 1) { |
1620 | if (count($_resource_name_parts) == 1) { |
1621 | // no resource type given
|
1621 | // no resource type given
|
1622 | $params['resource_type'] = $this->default_resource_type; |
1622 | $params['resource_type'] = $this->default_resource_type; |
1623 | $params['resource_name'] = $_resource_name_parts[0]; |
1623 | $params['resource_name'] = $_resource_name_parts[0]; |
1624 | } else { |
1624 | } else { |
1625 | if(strlen($_resource_name_parts[0]) == 1) { |
1625 | if(strlen($_resource_name_parts[0]) == 1) { |
1626 | // 1 char is not resource type, but part of filepath
|
1626 | // 1 char is not resource type, but part of filepath
|
1627 | $params['resource_type'] = $this->default_resource_type; |
1627 | $params['resource_type'] = $this->default_resource_type; |
1628 | $params['resource_name'] = $params['resource_name']; |
1628 | $params['resource_name'] = $params['resource_name']; |
1629 | } else { |
1629 | } else { |
1630 | $params['resource_type'] = $_resource_name_parts[0]; |
1630 | $params['resource_type'] = $_resource_name_parts[0]; |
1631 | $params['resource_name'] = $_resource_name_parts[1]; |
1631 | $params['resource_name'] = $_resource_name_parts[1]; |
1632 | }
|
1632 | }
|
1633 | }
|
1633 | }
|
1634 | 1634 | ||
1635 | if ($params['resource_type'] == 'file') { |
1635 | if ($params['resource_type'] == 'file') { |
1636 | if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $params['resource_name'])) { |
1636 | if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $params['resource_name'])) { |
1637 | // relative pathname to $params['resource_base_path']
|
1637 | // relative pathname to $params['resource_base_path']
|
1638 | // use the first directory where the file is found
|
1638 | // use the first directory where the file is found
|
1639 | foreach ((array)$params['resource_base_path'] as $_curr_path) { |
1639 | foreach ((array)$params['resource_base_path'] as $_curr_path) { |
1640 | $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name']; |
1640 | $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name']; |
1641 | if (file_exists($_fullpath) && is_file($_fullpath)) { |
1641 | if (file_exists($_fullpath) && is_file($_fullpath)) { |
1642 | $params['resource_name'] = $_fullpath; |
1642 | $params['resource_name'] = $_fullpath; |
1643 | return true; |
1643 | return true; |
1644 | }
|
1644 | }
|
1645 | // didn't find the file, try include_path
|
1645 | // didn't find the file, try include_path
|
1646 | $_params = array('file_path' => $_fullpath); |
1646 | $_params = array('file_path' => $_fullpath); |
1647 | require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); |
1647 | require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); |
1648 | if(smarty_core_get_include_path($_params, $this)) { |
1648 | if(smarty_core_get_include_path($_params, $this)) { |
1649 | $params['resource_name'] = $_params['new_file_path']; |
1649 | $params['resource_name'] = $_params['new_file_path']; |
1650 | return true; |
1650 | return true; |
1651 | }
|
1651 | }
|
1652 | }
|
1652 | }
|
1653 | return false; |
1653 | return false; |
1654 | } else { |
1654 | } else { |
1655 | /* absolute path */
|
1655 | /* absolute path */
|
1656 | return file_exists($params['resource_name']); |
1656 | return file_exists($params['resource_name']); |
1657 | }
|
1657 | }
|
1658 | } elseif (empty($this->_plugins['resource'][$params['resource_type']])) { |
1658 | } elseif (empty($this->_plugins['resource'][$params['resource_type']])) { |
1659 | $_params = array('type' => $params['resource_type']); |
1659 | $_params = array('type' => $params['resource_type']); |
1660 | require_once(SMARTY_CORE_DIR . 'core.load_resource_plugin.php'); |
1660 | require_once(SMARTY_CORE_DIR . 'core.load_resource_plugin.php'); |
1661 | smarty_core_load_resource_plugin($_params, $this); |
1661 | smarty_core_load_resource_plugin($_params, $this); |
1662 | }
|
1662 | }
|
1663 | 1663 | ||
1664 | return true; |
1664 | return true; |
1665 | }
|
1665 | }
|
1666 | 1666 | ||
1667 | 1667 | ||
1668 | /**
|
1668 | /**
|
1669 | * Handle modifiers
|
1669 | * Handle modifiers
|
1670 | *
|
1670 | *
|
1671 | * @param string|null $modifier_name
|
1671 | * @param string|null $modifier_name
|
1672 | * @param array|null $map_array
|
1672 | * @param array|null $map_array
|
1673 | * @return string result of modifiers
|
1673 | * @return string result of modifiers
|
1674 | */
|
1674 | */
|
1675 | function _run_mod_handler() |
1675 | function _run_mod_handler() |
1676 | {
|
1676 | {
|
1677 | $_args = func_get_args(); |
1677 | $_args = func_get_args(); |
1678 | list($_modifier_name, $_map_array) = array_splice($_args, 0, 2); |
1678 | list($_modifier_name, $_map_array) = array_splice($_args, 0, 2); |
1679 | list($_func_name, $_tpl_file, $_tpl_line) = |
1679 | list($_func_name, $_tpl_file, $_tpl_line) = |
1680 | $this->_plugins['modifier'][$_modifier_name]; |
1680 | $this->_plugins['modifier'][$_modifier_name]; |
1681 | 1681 | ||
1682 | $_var = $_args[0]; |
1682 | $_var = $_args[0]; |
1683 | foreach ($_var as $_key => $_val) { |
1683 | foreach ($_var as $_key => $_val) { |
1684 | $_args[0] = $_val; |
1684 | $_args[0] = $_val; |
1685 | $_var[$_key] = call_user_func_array($_func_name, $_args); |
1685 | $_var[$_key] = call_user_func_array($_func_name, $_args); |
1686 | }
|
1686 | }
|
1687 | return $_var; |
1687 | return $_var; |
1688 | }
|
1688 | }
|
1689 | 1689 | ||
1690 | /**
|
1690 | /**
|
1691 | * Remove starting and ending quotes from the string
|
1691 | * Remove starting and ending quotes from the string
|
1692 | *
|
1692 | *
|
1693 | * @param string $string
|
1693 | * @param string $string
|
1694 | * @return string
|
1694 | * @return string
|
1695 | */
|
1695 | */
|
1696 | function _dequote($string) |
1696 | function _dequote($string) |
1697 | {
|
1697 | {
|
1698 | if ((substr($string, 0, 1) == "'" || substr($string, 0, 1) == '"') && |
1698 | if ((substr($string, 0, 1) == "'" || substr($string, 0, 1) == '"') && |
1699 | substr($string, -1) == substr($string, 0, 1)) |
1699 | substr($string, -1) == substr($string, 0, 1)) |
1700 | return substr($string, 1, -1); |
1700 | return substr($string, 1, -1); |
1701 | else
|
1701 | else
|
1702 | return $string; |
1702 | return $string; |
1703 | }
|
1703 | }
|
1704 | 1704 | ||
1705 | 1705 | ||
1706 | /**
|
1706 | /**
|
1707 | * read in a file
|
1707 | * read in a file
|
1708 | *
|
1708 | *
|
1709 | * @param string $filename
|
1709 | * @param string $filename
|
1710 | * @return string
|
1710 | * @return string
|
1711 | */
|
1711 | */
|
1712 | function _read_file($filename) |
1712 | function _read_file($filename) |
1713 | {
|
1713 | {
|
1714 | if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) { |
1714 | if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) { |
1715 | $contents = ''; |
1715 | $contents = ''; |
1716 | while (!feof($fd)) { |
1716 | while (!feof($fd)) { |
1717 | $contents .= fread($fd, 8192); |
1717 | $contents .= fread($fd, 8192); |
1718 | }
|
1718 | }
|
1719 | fclose($fd); |
1719 | fclose($fd); |
1720 | return $contents; |
1720 | return $contents; |
1721 | } else { |
1721 | } else { |
1722 | return false; |
1722 | return false; |
1723 | }
|
1723 | }
|
1724 | }
|
1724 | }
|
1725 | 1725 | ||
1726 | /**
|
1726 | /**
|
1727 | * get a concrete filename for automagically created content
|
1727 | * get a concrete filename for automagically created content
|
1728 | *
|
1728 | *
|
1729 | * @param string $auto_base
|
1729 | * @param string $auto_base
|
1730 | * @param string $auto_source
|
1730 | * @param string $auto_source
|
1731 | * @param string $auto_id
|
1731 | * @param string $auto_id
|
1732 | * @return string
|
1732 | * @return string
|
1733 | * @staticvar string|null
|
1733 | * @staticvar string|null
|
1734 | * @staticvar string|null
|
1734 | * @staticvar string|null
|
1735 | */
|
1735 | */
|
1736 | function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) |
1736 | function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) |
1737 | {
|
1737 | {
|
1738 | $_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; |
1738 | $_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; |
1739 | $_return = $auto_base . DIRECTORY_SEPARATOR; |
1739 | $_return = $auto_base . DIRECTORY_SEPARATOR; |
1740 | 1740 | ||
1741 | if(isset($auto_id)) { |
1741 | if(isset($auto_id)) { |
1742 | // make auto_id safe for directory names
|
1742 | // make auto_id safe for directory names
|
1743 | $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id))); |
1743 | $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id))); |
1744 | // split into separate directories
|
1744 | // split into separate directories
|
1745 | $_return .= $auto_id . $_compile_dir_sep; |
1745 | $_return .= $auto_id . $_compile_dir_sep; |
1746 | }
|
1746 | }
|
1747 | 1747 | ||
1748 | if(isset($auto_source)) { |
1748 | if(isset($auto_source)) { |
1749 | // make source name safe for filename
|
1749 | // make source name safe for filename
|
1750 | $_filename = urlencode(basename($auto_source)); |
1750 | $_filename = urlencode(basename($auto_source)); |
1751 | $_crc32 = sprintf('%08X', crc32($auto_source)); |
1751 | $_crc32 = sprintf('%08X', crc32($auto_source)); |
1752 | // prepend %% to avoid name conflicts with
|
1752 | // prepend %% to avoid name conflicts with
|
1753 | // with $params['auto_id'] names
|
1753 | // with $params['auto_id'] names
|
1754 | $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep . |
1754 | $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep . |
1755 | substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32; |
1755 | substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32; |
1756 | $_return .= '%%' . $_crc32 . '%%' . $_filename; |
1756 | $_return .= '%%' . $_crc32 . '%%' . $_filename; |
1757 | }
|
1757 | }
|
1758 | 1758 | ||
1759 | return $_return; |
1759 | return $_return; |
1760 | }
|
1760 | }
|
1761 | 1761 | ||
1762 | /**
|
1762 | /**
|
1763 | * unlink a file, possibly using expiration time
|
1763 | * unlink a file, possibly using expiration time
|
1764 | *
|
1764 | *
|
1765 | * @param string $resource
|
1765 | * @param string $resource
|
1766 | * @param integer $exp_time
|
1766 | * @param integer $exp_time
|
1767 | */
|
1767 | */
|
1768 | function _unlink($resource, $exp_time = null) |
1768 | function _unlink($resource, $exp_time = null) |
1769 | {
|
1769 | {
|
1770 | if(isset($exp_time)) { |
1770 | if(isset($exp_time)) { |
1771 | if(time() - @filemtime($resource) >= $exp_time) { |
1771 | if(time() - @filemtime($resource) >= $exp_time) { |
1772 | return @unlink($resource); |
1772 | return @unlink($resource); |
1773 | }
|
1773 | }
|
1774 | } else { |
1774 | } else { |
1775 | return @unlink($resource); |
1775 | return @unlink($resource); |
1776 | }
|
1776 | }
|
1777 | }
|
1777 | }
|
1778 | 1778 | ||
1779 | /**
|
1779 | /**
|
1780 | * returns an auto_id for auto-file-functions
|
1780 | * returns an auto_id for auto-file-functions
|
1781 | *
|
1781 | *
|
1782 | * @param string $cache_id
|
1782 | * @param string $cache_id
|
1783 | * @param string $compile_id
|
1783 | * @param string $compile_id
|
1784 | * @return string|null
|
1784 | * @return string|null
|
1785 | */
|
1785 | */
|
1786 | function _get_auto_id($cache_id=null, $compile_id=null) { |
1786 | function _get_auto_id($cache_id=null, $compile_id=null) { |
1787 | if (isset($cache_id)) |
1787 | if (isset($cache_id)) |
1788 | return (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id; |
1788 | return (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id; |
1789 | elseif(isset($compile_id)) |
1789 | elseif(isset($compile_id)) |
1790 | return $compile_id; |
1790 | return $compile_id; |
1791 | else
|
1791 | else
|
1792 | return null; |
1792 | return null; |
1793 | }
|
1793 | }
|
1794 | 1794 | ||
1795 | /**
|
1795 | /**
|
1796 | * trigger Smarty plugin error
|
1796 | * trigger Smarty plugin error
|
1797 | *
|
1797 | *
|
1798 | * @param string $error_msg
|
1798 | * @param string $error_msg
|
1799 | * @param string $tpl_file
|
1799 | * @param string $tpl_file
|
1800 | * @param integer $tpl_line
|
1800 | * @param integer $tpl_line
|
1801 | * @param string $file
|
1801 | * @param string $file
|
1802 | * @param integer $line
|
1802 | * @param integer $line
|
1803 | * @param integer $error_type
|
1803 | * @param integer $error_type
|
1804 | */
|
1804 | */
|
1805 | function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null, |
1805 | function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null, |
1806 | $file = null, $line = null, $error_type = E_USER_ERROR) |
1806 | $file = null, $line = null, $error_type = E_USER_ERROR) |
1807 | {
|
1807 | {
|
1808 | if(isset($file) && isset($line)) { |
1808 | if(isset($file) && isset($line)) { |
1809 | $info = ' ('.basename($file).", line $line)"; |
1809 | $info = ' ('.basename($file).", line $line)"; |
1810 | } else { |
1810 | } else { |
1811 | $info = ''; |
1811 | $info = ''; |
1812 | }
|
1812 | }
|
1813 | if (isset($tpl_line) && isset($tpl_file)) { |
1813 | if (isset($tpl_line) && isset($tpl_file)) { |
1814 | $this->trigger_error('[in ' . $tpl_file . ' line ' . $tpl_line . "]: $error_msg$info", $error_type); |
1814 | $this->trigger_error('[in ' . $tpl_file . ' line ' . $tpl_line . "]: $error_msg$info", $error_type); |
1815 | } else { |
1815 | } else { |
1816 | $this->trigger_error($error_msg . $info, $error_type); |
1816 | $this->trigger_error($error_msg . $info, $error_type); |
1817 | }
|
1817 | }
|
1818 | }
|
1818 | }
|
1819 | 1819 | ||
1820 | 1820 | ||
1821 | /**
|
1821 | /**
|
1822 | * callback function for preg_replace, to call a non-cacheable block
|
1822 | * callback function for preg_replace, to call a non-cacheable block
|
1823 | * @return string
|
1823 | * @return string
|
1824 | */
|
1824 | */
|
1825 | function _process_compiled_include_callback($match) { |
1825 | function _process_compiled_include_callback($match) { |
1826 | $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3]; |
1826 | $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3]; |
1827 | ob_start(); |
1827 | ob_start(); |
1828 | $_func($this); |
1828 | $_func($this); |
1829 | $_ret = ob_get_contents(); |
1829 | $_ret = ob_get_contents(); |
1830 | ob_end_clean(); |
1830 | ob_end_clean(); |
1831 | return $_ret; |
1831 | return $_ret; |
1832 | }
|
1832 | }
|
1833 | 1833 | ||
1834 | 1834 | ||
1835 | /**
|
1835 | /**
|
1836 | * called for included templates
|
1836 | * called for included templates
|
1837 | *
|
1837 | *
|
1838 | * @param string $_smarty_include_tpl_file
|
1838 | * @param string $_smarty_include_tpl_file
|
1839 | * @param string $_smarty_include_vars
|
1839 | * @param string $_smarty_include_vars
|
1840 | */
|
1840 | */
|
1841 | 1841 | ||
1842 | // $_smarty_include_tpl_file, $_smarty_include_vars
|
1842 | // $_smarty_include_tpl_file, $_smarty_include_vars
|
1843 | 1843 | ||
1844 | function _smarty_include($params) |
1844 | function _smarty_include($params) |
1845 | {
|
1845 | {
|
1846 | if ($this->debugging) { |
1846 | if ($this->debugging) { |
1847 | $_params = array(); |
1847 | $_params = array(); |
1848 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1848 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1849 | $debug_start_time = smarty_core_get_microtime($_params, $this); |
1849 | $debug_start_time = smarty_core_get_microtime($_params, $this); |
1850 | $this->_smarty_debug_info[] = array('type' => 'template', |
1850 | $this->_smarty_debug_info[] = array('type' => 'template', |
1851 | 'filename' => $params['smarty_include_tpl_file'], |
1851 | 'filename' => $params['smarty_include_tpl_file'], |
1852 | 'depth' => ++$this->_inclusion_depth); |
1852 | 'depth' => ++$this->_inclusion_depth); |
1853 | $included_tpls_idx = count($this->_smarty_debug_info) - 1; |
1853 | $included_tpls_idx = count($this->_smarty_debug_info) - 1; |
1854 | }
|
1854 | }
|
1855 | 1855 | ||
1856 | $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']); |
1856 | $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']); |
1857 | 1857 | ||
1858 | // config vars are treated as local, so push a copy of the
|
1858 | // config vars are treated as local, so push a copy of the
|
1859 | // current ones onto the front of the stack
|
1859 | // current ones onto the front of the stack
|
1860 | array_unshift($this->_config, $this->_config[0]); |
1860 | array_unshift($this->_config, $this->_config[0]); |
1861 | 1861 | ||
1862 | $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']); |
1862 | $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']); |
1863 | 1863 | ||
1864 | 1864 | ||
1865 | if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path) |
1865 | if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path) |
1866 | || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path)) |
1866 | || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path)) |
1867 | {
|
1867 | {
|
1868 | include($_smarty_compile_path); |
1868 | include($_smarty_compile_path); |
1869 | }
|
1869 | }
|
1870 | 1870 | ||
1871 | // pop the local vars off the front of the stack
|
1871 | // pop the local vars off the front of the stack
|
1872 | array_shift($this->_config); |
1872 | array_shift($this->_config); |
1873 | 1873 | ||
1874 | $this->_inclusion_depth--; |
1874 | $this->_inclusion_depth--; |
1875 | 1875 | ||
1876 | if ($this->debugging) { |
1876 | if ($this->debugging) { |
1877 | // capture time for debugging info
|
1877 | // capture time for debugging info
|
1878 | $_params = array(); |
1878 | $_params = array(); |
1879 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1879 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
1880 | $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time; |
1880 | $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time; |
1881 | }
|
1881 | }
|
1882 | 1882 | ||
1883 | if ($this->caching) { |
1883 | if ($this->caching) { |
1884 | $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true; |
1884 | $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true; |
1885 | }
|
1885 | }
|
1886 | }
|
1886 | }
|
1887 | 1887 | ||
1888 | 1888 | ||
1889 | /**
|
1889 | /**
|
1890 | * get or set an array of cached attributes for function that is
|
1890 | * get or set an array of cached attributes for function that is
|
1891 | * not cacheable
|
1891 | * not cacheable
|
1892 | * @return array
|
1892 | * @return array
|
1893 | */
|
1893 | */
|
1894 | function &_smarty_cache_attrs($cache_serial, $count) { |
1894 | function &_smarty_cache_attrs($cache_serial, $count) { |
1895 | $_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count]; |
1895 | $_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count]; |
1896 | 1896 | ||
1897 | if ($this->_cache_including) { |
1897 | if ($this->_cache_including) { |
1898 | /* return next set of cache_attrs */
|
1898 | /* return next set of cache_attrs */
|
1899 | $_return = current($_cache_attrs); |
1899 | $_return = current($_cache_attrs); |
1900 | next($_cache_attrs); |
1900 | next($_cache_attrs); |
1901 | return $_return; |
1901 | return $_return; |
1902 | 1902 | ||
1903 | } else { |
1903 | } else { |
1904 | /* add a reference to a new set of cache_attrs */
|
1904 | /* add a reference to a new set of cache_attrs */
|
1905 | $_cache_attrs[] = array(); |
1905 | $_cache_attrs[] = array(); |
1906 | return $_cache_attrs[count($_cache_attrs)-1]; |
1906 | return $_cache_attrs[count($_cache_attrs)-1]; |
1907 | 1907 | ||
1908 | }
|
1908 | }
|
1909 | 1909 | ||
1910 | }
|
1910 | }
|
1911 | 1911 | ||
1912 | 1912 | ||
1913 | /**
|
1913 | /**
|
1914 | * wrapper for include() retaining $this
|
1914 | * wrapper for include() retaining $this
|
1915 | * @return mixed
|
1915 | * @return mixed
|
1916 | */
|
1916 | */
|
1917 | function _include($filename, $once=false, $params=null) |
1917 | function _include($filename, $once=false, $params=null) |
1918 | {
|
1918 | {
|
1919 | if ($once) { |
1919 | if ($once) { |
1920 | return include_once($filename); |
1920 | return include_once($filename); |
1921 | } else { |
1921 | } else { |
1922 | return include($filename); |
1922 | return include($filename); |
1923 | }
|
1923 | }
|
1924 | }
|
1924 | }
|
1925 | 1925 | ||
1926 | 1926 | ||
1927 | /**
|
1927 | /**
|
1928 | * wrapper for eval() retaining $this
|
1928 | * wrapper for eval() retaining $this
|
1929 | * @return mixed
|
1929 | * @return mixed
|
1930 | */
|
1930 | */
|
1931 | function _eval($code, $params=null) |
1931 | function _eval($code, $params=null) |
1932 | {
|
1932 | {
|
1933 | return eval($code); |
1933 | return eval($code); |
1934 | }
|
1934 | }
|
1935 | 1935 | ||
1936 | /**
|
1936 | /**
|
1937 | * Extracts the filter name from the given callback
|
1937 | * Extracts the filter name from the given callback
|
1938 | *
|
1938 | *
|
1939 | * @param callback $function
|
1939 | * @param callback $function
|
1940 | * @return string
|
1940 | * @return string
|
1941 | */
|
1941 | */
|
1942 | function _get_filter_name($function) |
1942 | function _get_filter_name($function) |
1943 | {
|
1943 | {
|
1944 | if (is_array($function)) { |
1944 | if (is_array($function)) { |
1945 | $_class_name = (is_object($function[0]) ? |
1945 | $_class_name = (is_object($function[0]) ? |
1946 | get_class($function[0]) : $function[0]); |
1946 | get_class($function[0]) : $function[0]); |
1947 | return $_class_name . '_' . $function[1]; |
1947 | return $_class_name . '_' . $function[1]; |
1948 | }
|
1948 | }
|
1949 | else { |
1949 | else { |
1950 | return $function; |
1950 | return $function; |
1951 | }
|
1951 | }
|
1952 | }
|
1952 | }
|
1953 | 1953 | ||
1954 | /**#@-*/
|
1954 | /**#@-*/
|
1955 | 1955 | ||
1956 | }
|
1956 | }
|
1957 | 1957 | ||
1958 | /* vim: set expandtab: */
|
1958 | /* vim: set expandtab: */
|
1959 | 1959 | ||
1960 | ?>
|
1960 | ?>
|
1961 | 1961 |