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 Compatibility Wrapper Class
38 class SmartyBC extends Smarty
45 public $_version = self::SMARTY_VERSION;
48 * This is an array of directories where trusted php scripts reside.
52 public $trusted_dir = array();
55 * Initialize new SmartyBC object
58 public function __construct()
60 parent::__construct();
64 * wrapper for assign_by_ref
66 * @param string $tpl_var the template variable name
67 * @param mixed &$value the referenced value to assign
69 public function assign_by_ref($tpl_var, &$value)
71 $this->assignByRef($tpl_var, $value);
75 * wrapper for append_by_ref
77 * @param string $tpl_var the template variable name
78 * @param mixed &$value the referenced value to append
79 * @param boolean $merge flag if array elements shall be merged
81 public function append_by_ref($tpl_var, &$value, $merge = false)
83 $this->appendByRef($tpl_var, $value, $merge);
87 * clear the given assigned template variable.
89 * @param string $tpl_var the template variable to clear
91 public function clear_assign($tpl_var)
93 $this->clearAssign($tpl_var);
97 * Registers custom function to be used in templates
99 * @param string $function the name of the template function
100 * @param string $function_impl the name of the PHP function to register
101 * @param bool $cacheable
102 * @param mixed $cache_attrs
104 public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
106 $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
110 * Unregister custom function
112 * @param string $function name of template function
114 public function unregister_function($function)
116 $this->unregisterPlugin('function', $function);
120 * Registers object to be used in templates
122 * @param string $object name of template object
123 * @param object $object_impl the referenced PHP object to register
124 * @param array $allowed list of allowed methods (empty = all)
125 * @param boolean $smarty_args smarty argument format, else traditional
126 * @param array $block_methods list of methods that are block format
128 * @throws SmartyException
129 * @internal param array $block_functs list of methods that are block format
131 public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true,
132 $block_methods = array())
134 settype($allowed, 'array');
135 settype($smarty_args, 'boolean');
136 $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
142 * @param string $object name of template object
144 public function unregister_object($object)
146 $this->unregisterObject($object);
150 * Registers block function to be used in templates
152 * @param string $block name of template block
153 * @param string $block_impl PHP function to register
154 * @param bool $cacheable
155 * @param mixed $cache_attrs
157 public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
159 $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
163 * Unregister block function
165 * @param string $block name of template function
167 public function unregister_block($block)
169 $this->unregisterPlugin('block', $block);
173 * Registers compiler function
175 * @param string $function name of template function
176 * @param string $function_impl name of PHP function to register
177 * @param bool $cacheable
179 public function register_compiler_function($function, $function_impl, $cacheable = true)
181 $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
185 * Unregister compiler function
187 * @param string $function name of template function
189 public function unregister_compiler_function($function)
191 $this->unregisterPlugin('compiler', $function);
195 * Registers modifier to be used in templates
197 * @param string $modifier name of template modifier
198 * @param string $modifier_impl name of PHP function to register
200 public function register_modifier($modifier, $modifier_impl)
202 $this->registerPlugin('modifier', $modifier, $modifier_impl);
206 * Unregister modifier
208 * @param string $modifier name of template modifier
210 public function unregister_modifier($modifier)
212 $this->unregisterPlugin('modifier', $modifier);
216 * Registers a resource to fetch a template
218 * @param string $type name of resource
219 * @param array $functions array of functions to handle resource
221 public function register_resource($type, $functions)
223 $this->registerResource($type, $functions);
227 * Unregister a resource
229 * @param string $type name of resource
231 public function unregister_resource($type)
233 $this->unregisterResource($type);
237 * Registers a prefilter function to apply
238 * to a template before compiling
240 * @param callable $function
242 public function register_prefilter($function)
244 $this->registerFilter('pre', $function);
248 * Unregister a prefilter function
250 * @param callable $function
252 public function unregister_prefilter($function)
254 $this->unregisterFilter('pre', $function);
258 * Registers a postfilter function to apply
259 * to a compiled template after compilation
261 * @param callable $function
263 public function register_postfilter($function)
265 $this->registerFilter('post', $function);
269 * Unregister a postfilter function
271 * @param callable $function
273 public function unregister_postfilter($function)
275 $this->unregisterFilter('post', $function);
279 * Registers an output filter function to apply
280 * to a template output
282 * @param callable $function
284 public function register_outputfilter($function)
286 $this->registerFilter('output', $function);
290 * Unregister an outputfilter function
292 * @param callable $function
294 public function unregister_outputfilter($function)
296 $this->unregisterFilter('output', $function);
300 * load a filter of specified type and name
302 * @param string $type filter type
303 * @param string $name filter name
305 public function load_filter($type, $name)
307 $this->loadFilter($type, $name);
311 * clear cached content for the given template and cache id
313 * @param string $tpl_file name of template file
314 * @param string $cache_id name of cache_id
315 * @param string $compile_id name of compile_id
316 * @param string $exp_time expiration time
320 public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
322 return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
326 * clear the entire contents of cache (all templates)
328 * @param string $exp_time expire time
332 public function clear_all_cache($exp_time = null)
334 return $this->clearCache(null, null, null, $exp_time);
338 * test to see if valid cache exists for this template
340 * @param string $tpl_file name of template file
341 * @param string $cache_id
342 * @param string $compile_id
346 public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
348 return $this->isCached($tpl_file, $cache_id, $compile_id);
352 * clear all the assigned template variables.
354 public function clear_all_assign()
356 $this->clearAllAssign();
360 * clears compiled version of specified template resource,
361 * or all compiled template files if one is not specified.
362 * This function is for advanced use only, not normally needed.
364 * @param string $tpl_file
365 * @param string $compile_id
366 * @param string $exp_time
368 * @return boolean results of {@link smarty_core_rm_auto()}
370 public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
372 return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
376 * Checks whether requested template exists.
378 * @param string $tpl_file
382 public function template_exists($tpl_file)
384 return $this->templateExists($tpl_file);
388 * Returns an array containing template variables
390 * @param string $name
394 public function get_template_vars($name = null)
396 return $this->getTemplateVars($name);
400 * Returns an array containing config variables
402 * @param string $name
406 public function get_config_vars($name = null)
408 return $this->getConfigVars($name);
412 * load configuration values
414 * @param string $file
415 * @param string $section
416 * @param string $scope
418 public function config_load($file, $section = null, $scope = 'global')
420 $this->ConfigLoad($file, $section, $scope);
424 * return a reference to a registered object
426 * @param string $name
430 public function get_registered_object($name)
432 return $this->getRegisteredObject($name);
436 * clear configuration values
440 public function clear_config($var = null)
442 $this->clearConfig($var);
446 * trigger Smarty error
448 * @param string $error_msg
449 * @param integer $error_type
451 public function trigger_error($error_msg, $error_type = E_USER_WARNING)
453 trigger_error("Smarty error: $error_msg", $error_type);