SmartyBC.class.php (12213B)
1 <?php 2 /** 3 * Project: Smarty: the PHP compiling template engine 4 * File: SmartyBC.class.php 5 * SVN: $Id: $ 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 20 * 21 * @link http://www.smarty.net/ 22 * @copyright 2008 New Digital Group, Inc. 23 * @author Monte Ohrt <monte at ohrt dot com> 24 * @author Uwe Tews 25 * @author Rodney Rehm 26 * @package Smarty 27 */ 28 /** 29 * @ignore 30 */ 31 require_once(dirname(__FILE__) . '/Smarty.class.php'); 32 33 /** 34 * Smarty Backward Compatability Wrapper Class 35 * 36 * @package Smarty 37 */ 38 class SmartyBC extends Smarty 39 { 40 /** 41 * Smarty 2 BC 42 * 43 * @var string 44 */ 45 public $_version = self::SMARTY_VERSION; 46 47 /** 48 * Initialize new SmartyBC object 49 * 50 * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false ) 51 */ 52 public function __construct(array $options = array()) 53 { 54 parent::__construct($options); 55 } 56 57 /** 58 * wrapper for assign_by_ref 59 * 60 * @param string $tpl_var the template variable name 61 * @param mixed &$value the referenced value to assign 62 */ 63 public function assign_by_ref($tpl_var, &$value) 64 { 65 $this->assignByRef($tpl_var, $value); 66 } 67 68 /** 69 * wrapper for append_by_ref 70 * 71 * @param string $tpl_var the template variable name 72 * @param mixed &$value the referenced value to append 73 * @param boolean $merge flag if array elements shall be merged 74 */ 75 public function append_by_ref($tpl_var, &$value, $merge = false) 76 { 77 $this->appendByRef($tpl_var, $value, $merge); 78 } 79 80 /** 81 * clear the given assigned template variable. 82 * 83 * @param string $tpl_var the template variable to clear 84 */ 85 public function clear_assign($tpl_var) 86 { 87 $this->clearAssign($tpl_var); 88 } 89 90 /** 91 * Registers custom function to be used in templates 92 * 93 * @param string $function the name of the template function 94 * @param string $function_impl the name of the PHP function to register 95 * @param bool $cacheable 96 * @param mixed $cache_attrs 97 */ 98 public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null) 99 { 100 $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs); 101 } 102 103 /** 104 * Unregisters custom function 105 * 106 * @param string $function name of template function 107 */ 108 public function unregister_function($function) 109 { 110 $this->unregisterPlugin('function', $function); 111 } 112 113 /** 114 * Registers object to be used in templates 115 * 116 * @param string $object name of template object 117 * @param object $object_impl the referenced PHP object to register 118 * @param array $allowed list of allowed methods (empty = all) 119 * @param boolean $smarty_args smarty argument format, else traditional 120 * @param array $block_methods list of methods that are block format 121 * 122 * @throws SmartyException 123 * @internal param array $block_functs list of methods that are block format 124 */ 125 public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) 126 { 127 settype($allowed, 'array'); 128 settype($smarty_args, 'boolean'); 129 $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); 130 } 131 132 /** 133 * Unregisters object 134 * 135 * @param string $object name of template object 136 */ 137 public function unregister_object($object) 138 { 139 $this->unregisterObject($object); 140 } 141 142 /** 143 * Registers block function to be used in templates 144 * 145 * @param string $block name of template block 146 * @param string $block_impl PHP function to register 147 * @param bool $cacheable 148 * @param mixed $cache_attrs 149 */ 150 public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null) 151 { 152 $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs); 153 } 154 155 /** 156 * Unregisters block function 157 * 158 * @param string $block name of template function 159 */ 160 public function unregister_block($block) 161 { 162 $this->unregisterPlugin('block', $block); 163 } 164 165 /** 166 * Registers compiler function 167 * 168 * @param string $function name of template function 169 * @param string $function_impl name of PHP function to register 170 * @param bool $cacheable 171 */ 172 public function register_compiler_function($function, $function_impl, $cacheable = true) 173 { 174 $this->registerPlugin('compiler', $function, $function_impl, $cacheable); 175 } 176 177 /** 178 * Unregisters compiler function 179 * 180 * @param string $function name of template function 181 */ 182 public function unregister_compiler_function($function) 183 { 184 $this->unregisterPlugin('compiler', $function); 185 } 186 187 /** 188 * Registers modifier to be used in templates 189 * 190 * @param string $modifier name of template modifier 191 * @param string $modifier_impl name of PHP function to register 192 */ 193 public function register_modifier($modifier, $modifier_impl) 194 { 195 $this->registerPlugin('modifier', $modifier, $modifier_impl); 196 } 197 198 /** 199 * Unregisters modifier 200 * 201 * @param string $modifier name of template modifier 202 */ 203 public function unregister_modifier($modifier) 204 { 205 $this->unregisterPlugin('modifier', $modifier); 206 } 207 208 /** 209 * Registers a resource to fetch a template 210 * 211 * @param string $type name of resource 212 * @param array $functions array of functions to handle resource 213 */ 214 public function register_resource($type, $functions) 215 { 216 $this->registerResource($type, $functions); 217 } 218 219 /** 220 * Unregisters a resource 221 * 222 * @param string $type name of resource 223 */ 224 public function unregister_resource($type) 225 { 226 $this->unregisterResource($type); 227 } 228 229 /** 230 * Registers a prefilter function to apply 231 * to a template before compiling 232 * 233 * @param callable $function 234 */ 235 public function register_prefilter($function) 236 { 237 $this->registerFilter('pre', $function); 238 } 239 240 /** 241 * Unregisters a prefilter function 242 * 243 * @param callable $function 244 */ 245 public function unregister_prefilter($function) 246 { 247 $this->unregisterFilter('pre', $function); 248 } 249 250 /** 251 * Registers a postfilter function to apply 252 * to a compiled template after compilation 253 * 254 * @param callable $function 255 */ 256 public function register_postfilter($function) 257 { 258 $this->registerFilter('post', $function); 259 } 260 261 /** 262 * Unregisters a postfilter function 263 * 264 * @param callable $function 265 */ 266 public function unregister_postfilter($function) 267 { 268 $this->unregisterFilter('post', $function); 269 } 270 271 /** 272 * Registers an output filter function to apply 273 * to a template output 274 * 275 * @param callable $function 276 */ 277 public function register_outputfilter($function) 278 { 279 $this->registerFilter('output', $function); 280 } 281 282 /** 283 * Unregisters an outputfilter function 284 * 285 * @param callable $function 286 */ 287 public function unregister_outputfilter($function) 288 { 289 $this->unregisterFilter('output', $function); 290 } 291 292 /** 293 * load a filter of specified type and name 294 * 295 * @param string $type filter type 296 * @param string $name filter name 297 */ 298 public function load_filter($type, $name) 299 { 300 $this->loadFilter($type, $name); 301 } 302 303 /** 304 * clear cached content for the given template and cache id 305 * 306 * @param string $tpl_file name of template file 307 * @param string $cache_id name of cache_id 308 * @param string $compile_id name of compile_id 309 * @param string $exp_time expiration time 310 * 311 * @return boolean 312 */ 313 public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) 314 { 315 return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time); 316 } 317 318 /** 319 * clear the entire contents of cache (all templates) 320 * 321 * @param string $exp_time expire time 322 * 323 * @return boolean 324 */ 325 public function clear_all_cache($exp_time = null) 326 { 327 return $this->clearCache(null, null, null, $exp_time); 328 } 329 330 /** 331 * test to see if valid cache exists for this template 332 * 333 * @param string $tpl_file name of template file 334 * @param string $cache_id 335 * @param string $compile_id 336 * 337 * @return boolean 338 */ 339 public function is_cached($tpl_file, $cache_id = null, $compile_id = null) 340 { 341 return $this->isCached($tpl_file, $cache_id, $compile_id); 342 } 343 344 /** 345 * clear all the assigned template variables. 346 */ 347 public function clear_all_assign() 348 { 349 $this->clearAllAssign(); 350 } 351 352 /** 353 * clears compiled version of specified template resource, 354 * or all compiled template files if one is not specified. 355 * This function is for advanced use only, not normally needed. 356 * 357 * @param string $tpl_file 358 * @param string $compile_id 359 * @param string $exp_time 360 * 361 * @return boolean results of {@link smarty_core_rm_auto()} 362 */ 363 public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) 364 { 365 return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time); 366 } 367 368 /** 369 * Checks whether requested template exists. 370 * 371 * @param string $tpl_file 372 * 373 * @return boolean 374 */ 375 public function template_exists($tpl_file) 376 { 377 return $this->templateExists($tpl_file); 378 } 379 380 /** 381 * Returns an array containing template variables 382 * 383 * @param string $name 384 * 385 * @return array 386 */ 387 public function get_template_vars($name = null) 388 { 389 return $this->getTemplateVars($name); 390 } 391 392 /** 393 * Returns an array containing config variables 394 * 395 * @param string $name 396 * 397 * @return array 398 */ 399 public function get_config_vars($name = null) 400 { 401 return $this->getConfigVars($name); 402 } 403 404 /** 405 * load configuration values 406 * 407 * @param string $file 408 * @param string $section 409 * @param string $scope 410 */ 411 public function config_load($file, $section = null, $scope = 'global') 412 { 413 $this->ConfigLoad($file, $section, $scope); 414 } 415 416 /** 417 * return a reference to a registered object 418 * 419 * @param string $name 420 * 421 * @return object 422 */ 423 public function get_registered_object($name) 424 { 425 return $this->getRegisteredObject($name); 426 } 427 428 /** 429 * clear configuration values 430 * 431 * @param string $var 432 */ 433 public function clear_config($var = null) 434 { 435 $this->clearConfig($var); 436 } 437 438 /** 439 * trigger Smarty error 440 * 441 * @param string $error_msg 442 * @param integer $error_type 443 */ 444 public function trigger_error($error_msg, $error_type = E_USER_WARNING) 445 { 446 trigger_error("Smarty error: $error_msg", $error_type); 447 } 448 }