3 * Project: Smarty: the PHP compiling template engine
4 * File: SmartyBC.class.php
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * For questions, help, comments, discussion, etc., please join the
18 * Smarty mailing list. Send a blank e-mail to
19 * smarty-discussion-subscribe@googlegroups.com
21 * @link http://www.smarty.net/
22 * @copyright 2008 New Digital Group, Inc.
23 * @author Monte Ohrt <monte at ohrt dot com>
31 require_once(dirname(__FILE__
) . '/Smarty.class.php');
34 * Smarty Backward Compatability Wrapper Class
38 class SmartyBC
extends Smarty
45 public $_version = self
::SMARTY_VERSION
;
48 * Initialize new SmartyBC object
50 * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
52 public function __construct(array $options = array())
54 parent
::__construct($options);
56 $this->registerPlugin('block', 'php', 'smarty_php_tag');
60 * wrapper for assign_by_ref
62 * @param string $tpl_var the template variable name
63 * @param mixed &$value the referenced value to assign
65 public function assign_by_ref($tpl_var, &$value)
67 $this->assignByRef($tpl_var, $value);
71 * wrapper for append_by_ref
73 * @param string $tpl_var the template variable name
74 * @param mixed &$value the referenced value to append
75 * @param boolean $merge flag if array elements shall be merged
77 public function append_by_ref($tpl_var, &$value, $merge = false)
79 $this->appendByRef($tpl_var, $value, $merge);
83 * clear the given assigned template variable.
85 * @param string $tpl_var the template variable to clear
87 public function clear_assign($tpl_var)
89 $this->clearAssign($tpl_var);
93 * Registers custom function to be used in templates
95 * @param string $function the name of the template function
96 * @param string $function_impl the name of the PHP function to register
97 * @param bool $cacheable
98 * @param mixed $cache_attrs
100 public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
102 $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
106 * Unregisters custom function
108 * @param string $function name of template function
110 public function unregister_function($function)
112 $this->unregisterPlugin('function', $function);
116 * Registers object to be used in templates
118 * @param string $object name of template object
119 * @param object $object_impl the referenced PHP object to register
120 * @param array $allowed list of allowed methods (empty = all)
121 * @param boolean $smarty_args smarty argument format, else traditional
122 * @param array $block_methods list of methods that are block format
124 * @throws SmartyException
125 * @internal param array $block_functs list of methods that are block format
127 public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
129 settype($allowed, 'array');
130 settype($smarty_args, 'boolean');
131 $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
137 * @param string $object name of template object
139 public function unregister_object($object)
141 $this->unregisterObject($object);
145 * Registers block function to be used in templates
147 * @param string $block name of template block
148 * @param string $block_impl PHP function to register
149 * @param bool $cacheable
150 * @param mixed $cache_attrs
152 public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
154 $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
158 * Unregisters block function
160 * @param string $block name of template function
162 public function unregister_block($block)
164 $this->unregisterPlugin('block', $block);
168 * Registers compiler function
170 * @param string $function name of template function
171 * @param string $function_impl name of PHP function to register
172 * @param bool $cacheable
174 public function register_compiler_function($function, $function_impl, $cacheable = true)
176 $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
180 * Unregisters compiler function
182 * @param string $function name of template function
184 public function unregister_compiler_function($function)
186 $this->unregisterPlugin('compiler', $function);
190 * Registers modifier to be used in templates
192 * @param string $modifier name of template modifier
193 * @param string $modifier_impl name of PHP function to register
195 public function register_modifier($modifier, $modifier_impl)
197 $this->registerPlugin('modifier', $modifier, $modifier_impl);
201 * Unregisters modifier
203 * @param string $modifier name of template modifier
205 public function unregister_modifier($modifier)
207 $this->unregisterPlugin('modifier', $modifier);
211 * Registers a resource to fetch a template
213 * @param string $type name of resource
214 * @param array $functions array of functions to handle resource
216 public function register_resource($type, $functions)
218 $this->registerResource($type, $functions);
222 * Unregisters a resource
224 * @param string $type name of resource
226 public function unregister_resource($type)
228 $this->unregisterResource($type);
232 * Registers a prefilter function to apply
233 * to a template before compiling
235 * @param callable $function
237 public function register_prefilter($function)
239 $this->registerFilter('pre', $function);
243 * Unregisters a prefilter function
245 * @param callable $function
247 public function unregister_prefilter($function)
249 $this->unregisterFilter('pre', $function);
253 * Registers a postfilter function to apply
254 * to a compiled template after compilation
256 * @param callable $function
258 public function register_postfilter($function)
260 $this->registerFilter('post', $function);
264 * Unregisters a postfilter function
266 * @param callable $function
268 public function unregister_postfilter($function)
270 $this->unregisterFilter('post', $function);
274 * Registers an output filter function to apply
275 * to a template output
277 * @param callable $function
279 public function register_outputfilter($function)
281 $this->registerFilter('output', $function);
285 * Unregisters an outputfilter function
287 * @param callable $function
289 public function unregister_outputfilter($function)
291 $this->unregisterFilter('output', $function);
295 * load a filter of specified type and name
297 * @param string $type filter type
298 * @param string $name filter name
300 public function load_filter($type, $name)
302 $this->loadFilter($type, $name);
306 * clear cached content for the given template and cache id
308 * @param string $tpl_file name of template file
309 * @param string $cache_id name of cache_id
310 * @param string $compile_id name of compile_id
311 * @param string $exp_time expiration time
315 public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
317 return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
321 * clear the entire contents of cache (all templates)
323 * @param string $exp_time expire time
327 public function clear_all_cache($exp_time = null)
329 return $this->clearCache(null, null, null, $exp_time);
333 * test to see if valid cache exists for this template
335 * @param string $tpl_file name of template file
336 * @param string $cache_id
337 * @param string $compile_id
341 public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
343 return $this->isCached($tpl_file, $cache_id, $compile_id);
347 * clear all the assigned template variables.
349 public function clear_all_assign()
351 $this->clearAllAssign();
355 * clears compiled version of specified template resource,
356 * or all compiled template files if one is not specified.
357 * This function is for advanced use only, not normally needed.
359 * @param string $tpl_file
360 * @param string $compile_id
361 * @param string $exp_time
363 * @return boolean results of {@link smarty_core_rm_auto()}
365 public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
367 return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
371 * Checks whether requested template exists.
373 * @param string $tpl_file
377 public function template_exists($tpl_file)
379 return $this->templateExists($tpl_file);
383 * Returns an array containing template variables
385 * @param string $name
389 public function get_template_vars($name = null)
391 return $this->getTemplateVars($name);
395 * Returns an array containing config variables
397 * @param string $name
401 public function get_config_vars($name = null)
403 return $this->getConfigVars($name);
407 * load configuration values
409 * @param string $file
410 * @param string $section
411 * @param string $scope
413 public function config_load($file, $section = null, $scope = 'global')
415 $this->ConfigLoad($file, $section, $scope);
419 * return a reference to a registered object
421 * @param string $name
425 public function get_registered_object($name)
427 return $this->getRegisteredObject($name);
431 * clear configuration values
435 public function clear_config($var = null)
437 $this->clearConfig($var);
441 * trigger Smarty error
443 * @param string $error_msg
444 * @param integer $error_type
446 public function trigger_error($error_msg, $error_type = E_USER_WARNING
)
448 trigger_error("Smarty error: $error_msg", $error_type);
453 * Smarty {php}{/php} block function
455 * @param array $params parameter list
456 * @param string $content contents of the block
457 * @param object $template template object
458 * @param boolean &$repeat repeat flag
460 * @return string content re-formatted
462 function smarty_php_tag($params, $content, $template, &$repeat)