3 * Project: Smarty: the PHP compiling template engine
\r
4 * File: SmartyBC.class.php
\r
7 * This library is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU Lesser General Public
\r
9 * License as published by the Free Software Foundation; either
\r
10 * version 2.1 of the License, or (at your option) any later version.
\r
12 * This library is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
15 * Lesser General Public License for more details.
\r
17 * You should have received a copy of the GNU Lesser General Public
\r
18 * License along with this library; if not, write to the Free Software
\r
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
21 * For questions, help, comments, discussion, etc., please join the
\r
22 * Smarty mailing list. Send a blank e-mail to
\r
23 * smarty-discussion-subscribe@googlegroups.com
\r
25 * @link http://www.smarty.net/
\r
26 * @copyright 2008 New Digital Group, Inc.
\r
27 * @author Monte Ohrt <monte at ohrt dot com>
\r
29 * @author Rodney Rehm
\r
35 require(dirname(__FILE__) . '/Smarty.class.php');
\r
38 * Smarty Backward Compatability Wrapper Class
\r
42 class SmartyBC extends Smarty {
\r
48 public $_version = self::SMARTY_VERSION;
\r
51 * Initialize new SmartyBC object
\r
53 * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
\r
55 public function __construct(array $options=array())
\r
57 parent::__construct($options);
\r
58 // register {php} tag
\r
59 $this->registerPlugin('block', 'php', 'smarty_php_tag');
\r
63 * wrapper for assign_by_ref
\r
65 * @param string $tpl_var the template variable name
\r
66 * @param mixed &$value the referenced value to assign
\r
68 public function assign_by_ref($tpl_var, &$value)
\r
70 $this->assignByRef($tpl_var, $value);
\r
74 * wrapper for append_by_ref
\r
76 * @param string $tpl_var the template variable name
\r
77 * @param mixed &$value the referenced value to append
\r
78 * @param boolean $merge flag if array elements shall be merged
\r
80 public function append_by_ref($tpl_var, &$value, $merge = false)
\r
82 $this->appendByRef($tpl_var, $value, $merge);
\r
86 * clear the given assigned template variable.
\r
88 * @param string $tpl_var the template variable to clear
\r
90 public function clear_assign($tpl_var)
\r
92 $this->clearAssign($tpl_var);
\r
96 * Registers custom function to be used in templates
\r
98 * @param string $function the name of the template function
\r
99 * @param string $function_impl the name of the PHP function to register
\r
100 * @param bool $cacheable
\r
101 * @param mixed $cache_attrs
\r
103 public function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)
\r
105 $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
\r
109 * Unregisters custom function
\r
111 * @param string $function name of template function
\r
113 public function unregister_function($function)
\r
115 $this->unregisterPlugin('function', $function);
\r
119 * Registers object to be used in templates
\r
121 * @param string $object name of template object
\r
122 * @param object $object_impl the referenced PHP object to register
\r
123 * @param array $allowed list of allowed methods (empty = all)
\r
124 * @param boolean $smarty_args smarty argument format, else traditional
\r
125 * @param array $block_functs list of methods that are block format
\r
127 public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
\r
129 settype($allowed, 'array');
\r
130 settype($smarty_args, 'boolean');
\r
131 $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
\r
135 * Unregisters object
\r
137 * @param string $object name of template object
\r
139 public function unregister_object($object)
\r
141 $this->unregisterObject($object);
\r
145 * Registers block function to be used in templates
\r
147 * @param string $block name of template block
\r
148 * @param string $block_impl PHP function to register
\r
149 * @param bool $cacheable
\r
150 * @param mixed $cache_attrs
\r
152 public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
\r
154 $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
\r
158 * Unregisters block function
\r
160 * @param string $block name of template function
\r
162 public function unregister_block($block)
\r
164 $this->unregisterPlugin('block', $block);
\r
168 * Registers compiler function
\r
170 * @param string $function name of template function
\r
171 * @param string $function_impl name of PHP function to register
\r
172 * @param bool $cacheable
\r
174 public function register_compiler_function($function, $function_impl, $cacheable=true)
\r
176 $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
\r
180 * Unregisters compiler function
\r
182 * @param string $function name of template function
\r
184 public function unregister_compiler_function($function)
\r
186 $this->unregisterPlugin('compiler', $function);
\r
190 * Registers modifier to be used in templates
\r
192 * @param string $modifier name of template modifier
\r
193 * @param string $modifier_impl name of PHP function to register
\r
195 public function register_modifier($modifier, $modifier_impl)
\r
197 $this->registerPlugin('modifier', $modifier, $modifier_impl);
\r
201 * Unregisters modifier
\r
203 * @param string $modifier name of template modifier
\r
205 public function unregister_modifier($modifier)
\r
207 $this->unregisterPlugin('modifier', $modifier);
\r
211 * Registers a resource to fetch a template
\r
213 * @param string $type name of resource
\r
214 * @param array $functions array of functions to handle resource
\r
216 public function register_resource($type, $functions)
\r
218 $this->registerResource($type, $functions);
\r
222 * Unregisters a resource
\r
224 * @param string $type name of resource
\r
226 public function unregister_resource($type)
\r
228 $this->unregisterResource($type);
\r
232 * Registers a prefilter function to apply
\r
233 * to a template before compiling
\r
235 * @param callable $function
\r
237 public function register_prefilter($function)
\r
239 $this->registerFilter('pre', $function);
\r
243 * Unregisters a prefilter function
\r
245 * @param callable $function
\r
247 public function unregister_prefilter($function)
\r
249 $this->unregisterFilter('pre', $function);
\r
253 * Registers a postfilter function to apply
\r
254 * to a compiled template after compilation
\r
256 * @param callable $function
\r
258 public function register_postfilter($function)
\r
260 $this->registerFilter('post', $function);
\r
264 * Unregisters a postfilter function
\r
266 * @param callable $function
\r
268 public function unregister_postfilter($function)
\r
270 $this->unregisterFilter('post', $function);
\r
274 * Registers an output filter function to apply
\r
275 * to a template output
\r
277 * @param callable $function
\r
279 public function register_outputfilter($function)
\r
281 $this->registerFilter('output', $function);
\r
285 * Unregisters an outputfilter function
\r
287 * @param callable $function
\r
289 public function unregister_outputfilter($function)
\r
291 $this->unregisterFilter('output', $function);
\r
295 * load a filter of specified type and name
\r
297 * @param string $type filter type
\r
298 * @param string $name filter name
\r
300 public function load_filter($type, $name)
\r
302 $this->loadFilter($type, $name);
\r
306 * clear cached content for the given template and cache id
\r
308 * @param string $tpl_file name of template file
\r
309 * @param string $cache_id name of cache_id
\r
310 * @param string $compile_id name of compile_id
\r
311 * @param string $exp_time expiration time
\r
314 public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
\r
316 return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
\r
320 * clear the entire contents of cache (all templates)
\r
322 * @param string $exp_time expire time
\r
325 public function clear_all_cache($exp_time = null)
\r
327 return $this->clearCache(null, null, null, $exp_time);
\r
331 * test to see if valid cache exists for this template
\r
333 * @param string $tpl_file name of template file
\r
334 * @param string $cache_id
\r
335 * @param string $compile_id
\r
338 public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
\r
340 return $this->isCached($tpl_file, $cache_id, $compile_id);
\r
344 * clear all the assigned template variables.
\r
346 public function clear_all_assign()
\r
348 $this->clearAllAssign();
\r
352 * clears compiled version of specified template resource,
\r
353 * or all compiled template files if one is not specified.
\r
354 * This function is for advanced use only, not normally needed.
\r
356 * @param string $tpl_file
\r
357 * @param string $compile_id
\r
358 * @param string $exp_time
\r
359 * @return boolean results of {@link smarty_core_rm_auto()}
\r
361 public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
\r
363 return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
\r
367 * Checks whether requested template exists.
\r
369 * @param string $tpl_file
\r
372 public function template_exists($tpl_file)
\r
374 return $this->templateExists($tpl_file);
\r
378 * Returns an array containing template variables
\r
380 * @param string $name
\r
383 public function get_template_vars($name=null)
\r
385 return $this->getTemplateVars($name);
\r
389 * Returns an array containing config variables
\r
391 * @param string $name
\r
394 public function get_config_vars($name=null)
\r
396 return $this->getConfigVars($name);
\r
400 * load configuration values
\r
402 * @param string $file
\r
403 * @param string $section
\r
404 * @param string $scope
\r
406 public function config_load($file, $section = null, $scope = 'global')
\r
408 $this->ConfigLoad($file, $section, $scope);
\r
412 * return a reference to a registered object
\r
414 * @param string $name
\r
417 public function get_registered_object($name)
\r
419 return $this->getRegisteredObject($name);
\r
423 * clear configuration values
\r
425 * @param string $var
\r
427 public function clear_config($var = null)
\r
429 $this->clearConfig($var);
\r
433 * trigger Smarty error
\r
435 * @param string $error_msg
\r
436 * @param integer $error_type
\r
438 public function trigger_error($error_msg, $error_type = E_USER_WARNING)
\r
440 trigger_error("Smarty error: $error_msg", $error_type);
\r
446 * Smarty {php}{/php} block function
\r
448 * @param array $params parameter list
\r
449 * @param string $content contents of the block
\r
450 * @param object $template template object
\r
451 * @param boolean &$repeat repeat flag
\r
452 * @return string content re-formatted
\r
454 function smarty_php_tag($params, $content, $template, &$repeat)
\r