Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Smarty often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Smarty, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 64 | class Smarty |
||
| 65 | { |
||
| 66 | /**#@+ |
||
| 67 | * Smarty Configuration Section |
||
| 68 | */ |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The name of the directory where templates are located. |
||
| 72 | * |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | var $template_dir = 'templates'; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The directory where compiled templates are located. |
||
| 79 | * |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | var $compile_dir = 'templates_c'; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The directory where config files are located. |
||
| 86 | * |
||
| 87 | * @var string |
||
| 88 | */ |
||
| 89 | var $config_dir = 'configs'; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * An array of directories searched for plugins. |
||
| 93 | * |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | var $plugins_dir = array('plugins'); |
||
| 97 | |||
| 98 | /** |
||
| 99 | * If debugging is enabled, a debug console window will display |
||
| 100 | * when the page loads (make sure your browser allows unrequested |
||
| 101 | * popup windows) |
||
| 102 | * |
||
| 103 | * @var boolean |
||
| 104 | */ |
||
| 105 | var $debugging = false; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * When set, smarty does uses this value as error_reporting-level. |
||
| 109 | * |
||
| 110 | * @var integer |
||
| 111 | */ |
||
| 112 | var $error_reporting = null; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * This is the path to the debug console template. If not set, |
||
| 116 | * the default one will be used. |
||
| 117 | * |
||
| 118 | * @var string |
||
| 119 | */ |
||
| 120 | var $debug_tpl = ''; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * This determines if debugging is enable-able from the browser. |
||
| 124 | * <ul> |
||
| 125 | * <li>NONE => no debugging control allowed</li> |
||
| 126 | * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li> |
||
| 127 | * </ul> |
||
| 128 | * @link http://www.foo.dom/index.php?SMARTY_DEBUG |
||
| 129 | * @var string |
||
| 130 | */ |
||
| 131 | var $debugging_ctrl = 'NONE'; |
||
| 132 | |||
| 133 | /** |
||
| 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. |
||
| 136 | * Typically you enable this during development, and disable for |
||
| 137 | * production. |
||
| 138 | * |
||
| 139 | * @var boolean |
||
| 140 | */ |
||
| 141 | var $compile_check = true; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * This forces templates to compile every time. Useful for development |
||
| 145 | * or debugging. |
||
| 146 | * |
||
| 147 | * @var boolean |
||
| 148 | */ |
||
| 149 | var $force_compile = false; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * This enables template caching. |
||
| 153 | * <ul> |
||
| 154 | * <li>0 = no caching</li> |
||
| 155 | * <li>1 = use class cache_lifetime value</li> |
||
| 156 | * <li>2 = use cache_lifetime in cache file</li> |
||
| 157 | * </ul> |
||
| 158 | * @var integer |
||
| 159 | */ |
||
| 160 | var $caching = 0; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * The name of the directory for cache files. |
||
| 164 | * |
||
| 165 | * @var string |
||
| 166 | */ |
||
| 167 | var $cache_dir = 'cache'; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * This is the number of seconds cached content will persist. |
||
| 171 | * <ul> |
||
| 172 | * <li>0 = always regenerate cache</li> |
||
| 173 | * <li>-1 = never expires</li> |
||
| 174 | * </ul> |
||
| 175 | * |
||
| 176 | * @var integer |
||
| 177 | */ |
||
| 178 | var $cache_lifetime = 3600; |
||
| 179 | |||
| 180 | /** |
||
| 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. |
||
| 183 | * This way repeated hits to a cached page do not send the entire page to the |
||
| 184 | * client every time. |
||
| 185 | * |
||
| 186 | * @var boolean |
||
| 187 | */ |
||
| 188 | var $cache_modified_check = false; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * This determines how Smarty handles "<?php ... ?>" tags in templates. |
||
| 192 | * possible values: |
||
| 193 | * <ul> |
||
| 194 | * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li> |
||
| 195 | * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li> |
||
| 196 | * <li>SMARTY_PHP_REMOVE -> remove php tags</li> |
||
| 197 | * <li>SMARTY_PHP_ALLOW -> execute php tags</li> |
||
| 198 | * </ul> |
||
| 199 | * |
||
| 200 | * @var integer |
||
| 201 | */ |
||
| 202 | var $php_handling = SMARTY_PHP_PASSTHRU; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * This enables template security. When enabled, many things are restricted |
||
| 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 |
||
| 208 | * of security. (no direct execution of PHP in templates for example) |
||
| 209 | * |
||
| 210 | * @var boolean |
||
| 211 | */ |
||
| 212 | var $security = false; |
||
| 213 | |||
| 214 | /** |
||
| 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 |
||
| 217 | * element. {@link $template_dir} is in this list implicitly. |
||
| 218 | * |
||
| 219 | * @var array |
||
| 220 | */ |
||
| 221 | var $secure_dir = array(); |
||
| 222 | |||
| 223 | /** |
||
| 224 | * These are the security settings for Smarty. They are used only when |
||
| 225 | * {@link $security} is enabled. |
||
| 226 | * |
||
| 227 | * @var array |
||
| 228 | */ |
||
| 229 | var $security_settings = array( |
||
| 230 | 'PHP_HANDLING' => false, |
||
| 231 | 'IF_FUNCS' => array('array', 'list', |
||
| 232 | 'isset', 'empty', |
||
| 233 | 'count', 'sizeof', |
||
| 234 | 'in_array', 'is_array', |
||
| 235 | 'true', 'false', 'null'), |
||
| 236 | 'INCLUDE_ANY' => false, |
||
| 237 | 'PHP_TAGS' => false, |
||
| 238 | 'MODIFIER_FUNCS' => array('count'), |
||
| 239 | 'ALLOW_CONSTANTS' => false, |
||
| 240 | 'ALLOW_SUPER_GLOBALS' => true |
||
| 241 | ); |
||
| 242 | |||
| 243 | /** |
||
| 244 | * This is an array of directories where trusted php scripts reside. |
||
| 245 | * {@link $security} is disabled during their inclusion/execution. |
||
| 246 | * |
||
| 247 | * @var array |
||
| 248 | */ |
||
| 249 | var $trusted_dir = array(); |
||
| 250 | |||
| 251 | /** |
||
| 252 | * The left delimiter used for the template tags. |
||
| 253 | * |
||
| 254 | * @var string |
||
| 255 | */ |
||
| 256 | var $left_delimiter = '{'; |
||
| 257 | |||
| 258 | /** |
||
| 259 | * The right delimiter used for the template tags. |
||
| 260 | * |
||
| 261 | * @var string |
||
| 262 | */ |
||
| 263 | var $right_delimiter = '}'; |
||
| 264 | |||
| 265 | /** |
||
| 266 | * The order in which request variables are registered, similar to |
||
| 267 | * variables_order in php.ini E = Environment, G = GET, P = POST, |
||
| 268 | * C = Cookies, S = Server |
||
| 269 | * |
||
| 270 | * @var string |
||
| 271 | */ |
||
| 272 | var $request_vars_order = 'EGPCS'; |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false) |
||
| 276 | * are uses as request-vars or $_*[]-vars. note: if |
||
| 277 | * request_use_auto_globals is true, then $request_vars_order has |
||
| 278 | * no effect, but the php-ini-value "gpc_order" |
||
| 279 | * |
||
| 280 | * @var boolean |
||
| 281 | */ |
||
| 282 | var $request_use_auto_globals = true; |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Set this if you want different sets of compiled files for the same |
||
| 286 | * templates. This is useful for things like different languages. |
||
| 287 | * Instead of creating separate sets of templates per language, you |
||
| 288 | * set different compile_ids like 'en' and 'de'. |
||
| 289 | * |
||
| 290 | * @var string |
||
| 291 | */ |
||
| 292 | var $compile_id = null; |
||
| 293 | |||
| 294 | /** |
||
| 295 | * This tells Smarty whether or not to use sub dirs in the cache/ and |
||
| 296 | * templates_c/ directories. sub directories better organized, but |
||
| 297 | * may not work well with PHP safe mode enabled. |
||
| 298 | * |
||
| 299 | * @var boolean |
||
| 300 | * |
||
| 301 | */ |
||
| 302 | var $use_sub_dirs = false; |
||
| 303 | |||
| 304 | /** |
||
| 305 | * This is a list of the modifiers to apply to all template variables. |
||
| 306 | * Put each modifier in a separate array element in the order you want |
||
| 307 | * them applied. example: <code>array('escape:"htmlall"');</code> |
||
| 308 | * |
||
| 309 | * @var array |
||
| 310 | */ |
||
| 311 | var $default_modifiers = array(); |
||
| 312 | |||
| 313 | /** |
||
| 314 | * This is the resource type to be used when not specified |
||
| 315 | * at the beginning of the resource path. examples: |
||
| 316 | * $smarty->display('file:index.tpl'); |
||
| 317 | * $smarty->display('db:index.tpl'); |
||
| 318 | * $smarty->display('index.tpl'); // will use default resource type |
||
| 319 | * {include file="file:index.tpl"} |
||
| 320 | * {include file="db:index.tpl"} |
||
| 321 | * {include file="index.tpl"} {* will use default resource type *} |
||
| 322 | * |
||
| 323 | * @var array |
||
| 324 | */ |
||
| 325 | var $default_resource_type = 'file'; |
||
| 326 | |||
| 327 | /** |
||
| 328 | * The function used for cache file handling. If not set, built-in caching is used. |
||
| 329 | * |
||
| 330 | * @var null|string function name |
||
| 331 | */ |
||
| 332 | var $cache_handler_func = null; |
||
| 333 | |||
| 334 | /** |
||
| 335 | * This indicates which filters are automatically loaded into Smarty. |
||
| 336 | * |
||
| 337 | * @var array array of filter names |
||
| 338 | */ |
||
| 339 | var $autoload_filters = array(); |
||
| 340 | |||
| 341 | /**#@+ |
||
| 342 | * @var boolean |
||
| 343 | */ |
||
| 344 | /** |
||
| 345 | * This tells if config file vars of the same name overwrite each other or not. |
||
| 346 | * if disabled, same name variables are accumulated in an array. |
||
| 347 | */ |
||
| 348 | var $config_overwrite = true; |
||
| 349 | |||
| 350 | /** |
||
| 351 | * This tells whether or not to automatically booleanize config file variables. |
||
| 352 | * If enabled, then the strings "on", "true", and "yes" are treated as boolean |
||
| 353 | * true, and "off", "false" and "no" are treated as boolean false. |
||
| 354 | */ |
||
| 355 | var $config_booleanize = true; |
||
| 356 | |||
| 357 | /** |
||
| 358 | * This tells whether hidden sections [.foobar] are readable from the |
||
| 359 | * tempalates or not. Normally you would never allow this since that is |
||
| 360 | * the point behind hidden sections: the application can access them, but |
||
| 361 | * the templates cannot. |
||
| 362 | */ |
||
| 363 | var $config_read_hidden = false; |
||
| 364 | |||
| 365 | /** |
||
| 366 | * This tells whether or not automatically fix newlines in config files. |
||
| 367 | * It basically converts \r (mac) or \r\n (dos) to \n |
||
| 368 | */ |
||
| 369 | var $config_fix_newlines = true; |
||
| 370 | /**#@-*/ |
||
| 371 | |||
| 372 | /** |
||
| 373 | * If a template cannot be found, this PHP function will be executed. |
||
| 374 | * Useful for creating templates on-the-fly or other special action. |
||
| 375 | * |
||
| 376 | * @var string function name |
||
| 377 | */ |
||
| 378 | var $default_template_handler_func = ''; |
||
| 379 | |||
| 380 | /** |
||
| 381 | * The file that contains the compiler class. This can a full |
||
| 382 | * pathname, or relative to the php_include path. |
||
| 383 | * |
||
| 384 | * @var string |
||
| 385 | */ |
||
| 386 | var $compiler_file = 'Smarty_Compiler.class.php'; |
||
| 387 | |||
| 388 | /** |
||
| 389 | * The class used for compiling templates. |
||
| 390 | * |
||
| 391 | * @var string |
||
| 392 | */ |
||
| 393 | var $compiler_class = 'Smarty_Compiler'; |
||
| 394 | |||
| 395 | /** |
||
| 396 | * The class used to load config vars. |
||
| 397 | * |
||
| 398 | * @var string |
||
| 399 | */ |
||
| 400 | var $config_class = 'Config_File'; |
||
| 401 | |||
| 402 | /**#@+ |
||
| 403 | * END Smarty Configuration Section |
||
| 404 | * There should be no need to touch anything below this line. |
||
| 405 | * @access private |
||
| 406 | */ |
||
| 407 | /** |
||
| 408 | * where assigned template vars are kept |
||
| 409 | * |
||
| 410 | * @var array |
||
| 411 | */ |
||
| 412 | var $_tpl_vars = array(); |
||
| 413 | |||
| 414 | /** |
||
| 415 | * stores run-time $smarty.* vars |
||
| 416 | * |
||
| 417 | * @var null|array |
||
| 418 | */ |
||
| 419 | var $_smarty_vars = null; |
||
| 420 | |||
| 421 | /** |
||
| 422 | * keeps track of sections |
||
| 423 | * |
||
| 424 | * @var array |
||
| 425 | */ |
||
| 426 | var $_sections = array(); |
||
| 427 | |||
| 428 | /** |
||
| 429 | * keeps track of foreach blocks |
||
| 430 | * |
||
| 431 | * @var array |
||
| 432 | */ |
||
| 433 | var $_foreach = array(); |
||
| 434 | |||
| 435 | /** |
||
| 436 | * keeps track of tag hierarchy |
||
| 437 | * |
||
| 438 | * @var array |
||
| 439 | */ |
||
| 440 | var $_tag_stack = array(); |
||
| 441 | |||
| 442 | /** |
||
| 443 | * configuration object |
||
| 444 | * |
||
| 445 | * @var Config_file |
||
| 446 | */ |
||
| 447 | var $_conf_obj = null; |
||
| 448 | |||
| 449 | /** |
||
| 450 | * loaded configuration settings |
||
| 451 | * |
||
| 452 | * @var array |
||
| 453 | */ |
||
| 454 | var $_config = array(array('vars' => array(), 'files' => array())); |
||
| 455 | |||
| 456 | /** |
||
| 457 | * md5 checksum of the string 'Smarty' |
||
| 458 | * |
||
| 459 | * @var string |
||
| 460 | */ |
||
| 461 | var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Smarty version number |
||
| 465 | * |
||
| 466 | * @var string |
||
| 467 | */ |
||
| 468 | var $_version = '2.6.25-dev'; |
||
| 469 | |||
| 470 | /** |
||
| 471 | * current template inclusion depth |
||
| 472 | * |
||
| 473 | * @var integer |
||
| 474 | */ |
||
| 475 | var $_inclusion_depth = 0; |
||
| 476 | |||
| 477 | /** |
||
| 478 | * for different compiled templates |
||
| 479 | * |
||
| 480 | * @var string |
||
| 481 | */ |
||
| 482 | var $_compile_id = null; |
||
| 483 | |||
| 484 | /** |
||
| 485 | * text in URL to enable debug mode |
||
| 486 | * |
||
| 487 | * @var string |
||
| 488 | */ |
||
| 489 | var $_smarty_debug_id = 'SMARTY_DEBUG'; |
||
| 490 | |||
| 491 | /** |
||
| 492 | * debugging information for debug console |
||
| 493 | * |
||
| 494 | * @var array |
||
| 495 | */ |
||
| 496 | var $_smarty_debug_info = array(); |
||
| 497 | |||
| 498 | /** |
||
| 499 | * info that makes up a cache file |
||
| 500 | * |
||
| 501 | * @var array |
||
| 502 | */ |
||
| 503 | var $_cache_info = array(); |
||
| 504 | |||
| 505 | /** |
||
| 506 | * default file permissions |
||
| 507 | * |
||
| 508 | * @var integer |
||
| 509 | */ |
||
| 510 | var $_file_perms = 0644; |
||
| 511 | |||
| 512 | /** |
||
| 513 | * default dir permissions |
||
| 514 | * |
||
| 515 | * @var integer |
||
| 516 | */ |
||
| 517 | var $_dir_perms = 0771; |
||
| 518 | |||
| 519 | /** |
||
| 520 | * registered objects |
||
| 521 | * |
||
| 522 | * @var array |
||
| 523 | */ |
||
| 524 | var $_reg_objects = array(); |
||
| 525 | |||
| 526 | /** |
||
| 527 | * table keeping track of plugins |
||
| 528 | * |
||
| 529 | * @var array |
||
| 530 | */ |
||
| 531 | var $_plugins = array( |
||
| 532 | 'modifier' => array(), |
||
| 533 | 'function' => array(), |
||
| 534 | 'block' => array(), |
||
| 535 | 'compiler' => array(), |
||
| 536 | 'prefilter' => array(), |
||
| 537 | 'postfilter' => array(), |
||
| 538 | 'outputfilter' => array(), |
||
| 539 | 'resource' => array(), |
||
| 540 | 'insert' => array()); |
||
| 541 | |||
| 542 | |||
| 543 | /** |
||
| 544 | * cache serials |
||
| 545 | * |
||
| 546 | * @var array |
||
| 547 | */ |
||
| 548 | var $_cache_serials = array(); |
||
| 549 | |||
| 550 | /** |
||
| 551 | * name of optional cache include file |
||
| 552 | * |
||
| 553 | * @var string |
||
| 554 | */ |
||
| 555 | var $_cache_include = null; |
||
| 556 | |||
| 557 | /** |
||
| 558 | * indicate if the current code is used in a compiled |
||
| 559 | * include |
||
| 560 | * |
||
| 561 | * @var string |
||
| 562 | */ |
||
| 563 | var $_cache_including = false; |
||
| 564 | |||
| 565 | /**#@-*/ |
||
| 566 | /** |
||
| 567 | * The class constructor. |
||
| 568 | */ |
||
| 569 | function __construct() // renamed for XOOPS |
||
|
|
|||
| 570 | { |
||
| 571 | $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] |
||
| 572 | : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']); |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * assigns values to template variables |
||
| 577 | * |
||
| 578 | * @param array|string $tpl_var the template variable name(s) |
||
| 579 | * @param mixed $value the value to assign |
||
| 580 | */ |
||
| 581 | function assign($tpl_var, $value = null) |
||
| 594 | |||
| 595 | /** |
||
| 596 | * assigns values to template variables by reference |
||
| 597 | * |
||
| 598 | * @param string $tpl_var the template variable name |
||
| 599 | * @param mixed $value the referenced value to assign |
||
| 600 | */ |
||
| 601 | function assign_by_ref($tpl_var, &$value) |
||
| 606 | |||
| 607 | /** |
||
| 608 | * appends values to template variables |
||
| 609 | * |
||
| 610 | * @param array|string $tpl_var the template variable name(s) |
||
| 611 | * @param mixed $value the value to append |
||
| 612 | */ |
||
| 613 | function append($tpl_var, $value=null, $merge=false) |
||
| 646 | |||
| 647 | /** |
||
| 648 | * appends values to template variables by reference |
||
| 649 | * |
||
| 650 | * @param string $tpl_var the template variable name |
||
| 651 | * @param mixed $value the referenced value to append |
||
| 652 | */ |
||
| 653 | function append_by_ref($tpl_var, &$value, $merge=false) |
||
| 668 | |||
| 669 | |||
| 670 | /** |
||
| 671 | * clear the given assigned template variable. |
||
| 672 | * |
||
| 673 | * @param string $tpl_var the template variable to clear |
||
| 674 | */ |
||
| 675 | function clear_assign($tpl_var) |
||
| 683 | |||
| 684 | |||
| 685 | /** |
||
| 686 | * Registers custom function to be used in templates |
||
| 687 | * |
||
| 688 | * @param string $function the name of the template function |
||
| 689 | * @param string $function_impl the name of the PHP function to register |
||
| 690 | */ |
||
| 691 | function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) |
||
| 697 | |||
| 698 | /** |
||
| 699 | * Unregisters custom function |
||
| 700 | * |
||
| 701 | * @param string $function name of template function |
||
| 702 | */ |
||
| 703 | function unregister_function($function) |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Registers object to be used in templates |
||
| 710 | * |
||
| 711 | * @param string $object name of template object |
||
| 712 | * @param object &$object_impl the referenced PHP object to register |
||
| 713 | * @param null|array $allowed list of allowed methods (empty = all) |
||
| 714 | * @param boolean $smarty_args smarty argument format, else traditional |
||
| 715 | * @param null|array $block_functs list of methods that are block format |
||
| 716 | */ |
||
| 717 | function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) |
||
| 724 | |||
| 725 | /** |
||
| 726 | * Unregisters object |
||
| 727 | * |
||
| 728 | * @param string $object name of template object |
||
| 729 | */ |
||
| 730 | function unregister_object($object) |
||
| 734 | |||
| 735 | |||
| 736 | /** |
||
| 737 | * Registers block function to be used in templates |
||
| 738 | * |
||
| 739 | * @param string $block name of template block |
||
| 740 | * @param string $block_impl PHP function to register |
||
| 741 | */ |
||
| 742 | function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) |
||
| 747 | |||
| 748 | /** |
||
| 749 | * Unregisters block function |
||
| 750 | * |
||
| 751 | * @param string $block name of template function |
||
| 752 | */ |
||
| 753 | function unregister_block($block) |
||
| 757 | |||
| 758 | /** |
||
| 759 | * Registers compiler function |
||
| 760 | * |
||
| 761 | * @param string $function name of template function |
||
| 762 | * @param string $function_impl name of PHP function to register |
||
| 763 | */ |
||
| 764 | function register_compiler_function($function, $function_impl, $cacheable=true) |
||
| 769 | |||
| 770 | /** |
||
| 771 | * Unregisters compiler function |
||
| 772 | * |
||
| 773 | * @param string $function name of template function |
||
| 774 | */ |
||
| 775 | function unregister_compiler_function($function) |
||
| 779 | |||
| 780 | /** |
||
| 781 | * Registers modifier to be used in templates |
||
| 782 | * |
||
| 783 | * @param string $modifier name of template modifier |
||
| 784 | * @param string $modifier_impl name of PHP function to register |
||
| 785 | */ |
||
| 786 | function register_modifier($modifier, $modifier_impl) |
||
| 791 | |||
| 792 | /** |
||
| 793 | * Unregisters modifier |
||
| 794 | * |
||
| 795 | * @param string $modifier name of template modifier |
||
| 796 | */ |
||
| 797 | function unregister_modifier($modifier) |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Registers a resource to fetch a template |
||
| 804 | * |
||
| 805 | * @param string $type name of resource |
||
| 806 | * @param array $functions array of functions to handle resource |
||
| 807 | */ |
||
| 808 | function register_resource($type, $functions) |
||
| 827 | |||
| 828 | /** |
||
| 829 | * Unregisters a resource |
||
| 830 | * |
||
| 831 | * @param string $type name of resource |
||
| 832 | */ |
||
| 833 | function unregister_resource($type) |
||
| 837 | |||
| 838 | /** |
||
| 839 | * Registers a prefilter function to apply |
||
| 840 | * to a template before compiling |
||
| 841 | * |
||
| 842 | * @param callback $function |
||
| 843 | */ |
||
| 844 | function register_prefilter($function) |
||
| 849 | |||
| 850 | /** |
||
| 851 | * Unregisters a prefilter function |
||
| 852 | * |
||
| 853 | * @param callback $function |
||
| 854 | */ |
||
| 855 | function unregister_prefilter($function) |
||
| 859 | |||
| 860 | /** |
||
| 861 | * Registers a postfilter function to apply |
||
| 862 | * to a compiled template after compilation |
||
| 863 | * |
||
| 864 | * @param callback $function |
||
| 865 | */ |
||
| 866 | function register_postfilter($function) |
||
| 871 | |||
| 872 | /** |
||
| 873 | * Unregisters a postfilter function |
||
| 874 | * |
||
| 875 | * @param callback $function |
||
| 876 | */ |
||
| 877 | function unregister_postfilter($function) |
||
| 881 | |||
| 882 | /** |
||
| 883 | * Registers an output filter function to apply |
||
| 884 | * to a template output |
||
| 885 | * |
||
| 886 | * @param callback $function |
||
| 887 | */ |
||
| 888 | function register_outputfilter($function) |
||
| 893 | |||
| 894 | /** |
||
| 895 | * Unregisters an outputfilter function |
||
| 896 | * |
||
| 897 | * @param callback $function |
||
| 898 | */ |
||
| 899 | function unregister_outputfilter($function) |
||
| 903 | |||
| 904 | /** |
||
| 905 | * load a filter of specified type and name |
||
| 906 | * |
||
| 907 | * @param string $type filter type |
||
| 908 | * @param string $name filter name |
||
| 909 | */ |
||
| 910 | function load_filter($type, $name) |
||
| 926 | |||
| 927 | /** |
||
| 928 | * clear cached content for the given template and cache id |
||
| 929 | * |
||
| 930 | * @param string $tpl_file name of template file |
||
| 931 | * @param string $cache_id name of cache_id |
||
| 932 | * @param string $compile_id name of compile_id |
||
| 933 | * @param string $exp_time expiration time |
||
| 934 | * @return boolean |
||
| 935 | */ |
||
| 936 | function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) |
||
| 960 | |||
| 961 | |||
| 962 | /** |
||
| 963 | * clear the entire contents of cache (all templates) |
||
| 964 | * |
||
| 965 | * @param string $exp_time expire time |
||
| 966 | * @return boolean results of {@link smarty_core_rm_auto()} |
||
| 967 | */ |
||
| 968 | function clear_all_cache($exp_time = null) |
||
| 972 | |||
| 973 | |||
| 974 | /** |
||
| 975 | * test to see if valid cache exists for this template |
||
| 976 | * |
||
| 977 | * @param string $tpl_file name of template file |
||
| 978 | * @param string $cache_id |
||
| 979 | * @param string $compile_id |
||
| 980 | * @return string|false results of {@link _read_cache_file()} |
||
| 981 | */ |
||
| 982 | function is_cached($tpl_file, $cache_id = null, $compile_id = null) |
||
| 998 | |||
| 999 | |||
| 1000 | /** |
||
| 1001 | * clear all the assigned template variables. |
||
| 1002 | * |
||
| 1003 | */ |
||
| 1004 | function clear_all_assign() |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * clears compiled version of specified template resource, |
||
| 1011 | * or all compiled template files if one is not specified. |
||
| 1012 | * This function is for advanced use only, not normally needed. |
||
| 1013 | * |
||
| 1014 | * @param string $tpl_file |
||
| 1015 | * @param string $compile_id |
||
| 1016 | * @param string $exp_time |
||
| 1017 | * @return boolean results of {@link smarty_core_rm_auto()} |
||
| 1018 | */ |
||
| 1019 | function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * Checks whether requested template exists. |
||
| 1035 | * |
||
| 1036 | * @param string $tpl_file |
||
| 1037 | * @return boolean |
||
| 1038 | */ |
||
| 1039 | function template_exists($tpl_file) |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Returns an array containing template variables |
||
| 1047 | * |
||
| 1048 | * @param string $name |
||
| 1049 | * @param string $type |
||
| 1050 | * @return array |
||
| 1051 | */ |
||
| 1052 | function &get_template_vars($name=null) |
||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * Returns an array containing config variables |
||
| 1067 | * |
||
| 1068 | * @param string $name |
||
| 1069 | * @param string $type |
||
| 1070 | * @return array |
||
| 1071 | */ |
||
| 1072 | function &get_config_vars($name=null) |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * trigger Smarty error |
||
| 1087 | * |
||
| 1088 | * @param string $error_msg |
||
| 1089 | * @param integer $error_type |
||
| 1090 | */ |
||
| 1091 | function trigger_error($error_msg, $error_type = E_USER_WARNING) |
||
| 1096 | |||
| 1097 | |||
| 1098 | /** |
||
| 1099 | * executes & displays the template results |
||
| 1100 | * |
||
| 1101 | * @param string $resource_name |
||
| 1102 | * @param string $cache_id |
||
| 1103 | * @param string $compile_id |
||
| 1104 | */ |
||
| 1105 | function display($resource_name, $cache_id = null, $compile_id = null) |
||
| 1109 | |||
| 1110 | /** |
||
| 1111 | * executes & returns or displays the template results |
||
| 1112 | * |
||
| 1113 | * @param string $resource_name |
||
| 1114 | * @param string $cache_id |
||
| 1115 | * @param string $compile_id |
||
| 1116 | * @param boolean $display |
||
| 1117 | */ |
||
| 1118 | function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * load configuration values |
||
| 1315 | * |
||
| 1316 | * @param string $file |
||
| 1317 | * @param string $section |
||
| 1318 | * @param string $scope |
||
| 1319 | */ |
||
| 1320 | function config_load($file, $section = null, $scope = 'global') |
||
| 1325 | |||
| 1326 | /** |
||
| 1327 | * return a reference to a registered object |
||
| 1328 | * |
||
| 1329 | * @param string $name |
||
| 1330 | * @return object |
||
| 1331 | */ |
||
| 1332 | function &get_registered_object($name) { |
||
| 1341 | |||
| 1342 | /** |
||
| 1343 | * clear configuration values |
||
| 1344 | * |
||
| 1345 | * @param string $var |
||
| 1346 | */ |
||
| 1347 | function clear_config($var = null) |
||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * get filepath of requested plugin |
||
| 1360 | * |
||
| 1361 | * @param string $type |
||
| 1362 | * @param string $name |
||
| 1363 | * @return string|false |
||
| 1364 | */ |
||
| 1365 | function _get_plugin_filepath($type, $name) |
||
| 1371 | |||
| 1372 | /** |
||
| 1373 | * test if resource needs compiling |
||
| 1374 | * |
||
| 1375 | * @param string $resource_name |
||
| 1376 | * @param string $compile_path |
||
| 1377 | * @return boolean |
||
| 1378 | */ |
||
| 1379 | function _is_compiled($resource_name, $compile_path) |
||
| 1404 | |||
| 1405 | /** |
||
| 1406 | * compile the template |
||
| 1407 | * |
||
| 1408 | * @param string $resource_name |
||
| 1409 | * @param string $compile_path |
||
| 1410 | * @return boolean |
||
| 1411 | */ |
||
| 1412 | function _compile_resource($resource_name, $compile_path) |
||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * compile the given source |
||
| 1443 | * |
||
| 1444 | * @param string $resource_name |
||
| 1445 | * @param string $source_content |
||
| 1446 | * @param string $compiled_content |
||
| 1447 | * @return boolean |
||
| 1448 | */ |
||
| 1449 | function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null) |
||
| 1505 | |||
| 1506 | /** |
||
| 1507 | * Get the compile path for this resource |
||
| 1508 | * |
||
| 1509 | * @param string $resource_name |
||
| 1510 | * @return string results of {@link _get_auto_filename()} |
||
| 1511 | */ |
||
| 1512 | function _get_compile_path($resource_name) |
||
| 1517 | |||
| 1518 | /** |
||
| 1519 | * fetch the template info. Gets timestamp, and source |
||
| 1520 | * if get_source is true |
||
| 1521 | * |
||
| 1522 | * sets $source_content to the source of the template, and |
||
| 1523 | * $resource_timestamp to its time stamp |
||
| 1524 | * @param string $resource_name |
||
| 1525 | * @param string $source_content |
||
| 1526 | * @param integer $resource_timestamp |
||
| 1527 | * @param boolean $get_source |
||
| 1528 | * @param boolean $quiet |
||
| 1529 | * @return boolean |
||
| 1530 | */ |
||
| 1531 | |||
| 1532 | function _fetch_resource_info(&$params) |
||
| 1604 | |||
| 1605 | |||
| 1606 | /** |
||
| 1607 | * parse out the type and name from the resource |
||
| 1608 | * |
||
| 1609 | * @param string $resource_base_path |
||
| 1610 | * @param string $resource_name |
||
| 1611 | * @param string $resource_type |
||
| 1612 | * @param string $resource_name |
||
| 1613 | * @return boolean |
||
| 1614 | */ |
||
| 1615 | |||
| 1616 | function _parse_resource_name(&$params) |
||
| 1668 | |||
| 1669 | |||
| 1670 | /** |
||
| 1671 | * Handle modifiers |
||
| 1672 | * |
||
| 1673 | * @param string|null $modifier_name |
||
| 1674 | * @param array|null $map_array |
||
| 1675 | * @return string result of modifiers |
||
| 1676 | */ |
||
| 1677 | function _run_mod_handler() |
||
| 1691 | |||
| 1692 | /** |
||
| 1693 | * Remove starting and ending quotes from the string |
||
| 1694 | * |
||
| 1695 | * @param string $string |
||
| 1696 | * @return string |
||
| 1697 | */ |
||
| 1698 | function _dequote($string) |
||
| 1706 | |||
| 1707 | |||
| 1708 | /** |
||
| 1709 | * read in a file |
||
| 1710 | * |
||
| 1711 | * @param string $filename |
||
| 1712 | * @return string |
||
| 1713 | */ |
||
| 1714 | function _read_file($filename) |
||
| 1727 | |||
| 1728 | /** |
||
| 1729 | * get a concrete filename for automagically created content |
||
| 1730 | * |
||
| 1731 | * @param string $auto_base |
||
| 1732 | * @param string $auto_source |
||
| 1733 | * @param string $auto_id |
||
| 1734 | * @return string |
||
| 1735 | * @staticvar string|null |
||
| 1736 | * @staticvar string|null |
||
| 1737 | */ |
||
| 1738 | function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) |
||
| 1763 | |||
| 1764 | /** |
||
| 1765 | * unlink a file, possibly using expiration time |
||
| 1766 | * |
||
| 1767 | * @param string $resource |
||
| 1768 | * @param integer $exp_time |
||
| 1769 | */ |
||
| 1770 | function _unlink($resource, $exp_time = null) |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * returns an auto_id for auto-file-functions |
||
| 1783 | * |
||
| 1784 | * @param string $cache_id |
||
| 1785 | * @param string $compile_id |
||
| 1786 | * @return string|null |
||
| 1787 | */ |
||
| 1788 | View Code Duplication | function _get_auto_id($cache_id=null, $compile_id=null) { |
|
| 1796 | |||
| 1797 | /** |
||
| 1798 | * trigger Smarty plugin error |
||
| 1799 | * |
||
| 1800 | * @param string $error_msg |
||
| 1801 | * @param string $tpl_file |
||
| 1802 | * @param integer $tpl_line |
||
| 1803 | * @param string $file |
||
| 1804 | * @param integer $line |
||
| 1805 | * @param integer $error_type |
||
| 1806 | */ |
||
| 1807 | function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null, |
||
| 1821 | |||
| 1822 | |||
| 1823 | /** |
||
| 1824 | * callback function for preg_replace, to call a non-cacheable block |
||
| 1825 | * @return string |
||
| 1826 | */ |
||
| 1827 | function _process_compiled_include_callback($match) { |
||
| 1835 | |||
| 1836 | |||
| 1837 | /** |
||
| 1838 | * called for included templates |
||
| 1839 | * |
||
| 1840 | * @param string $_smarty_include_tpl_file |
||
| 1841 | * @param string $_smarty_include_vars |
||
| 1842 | */ |
||
| 1843 | |||
| 1844 | // $_smarty_include_tpl_file, $_smarty_include_vars |
||
| 1845 | |||
| 1846 | function _smarty_include($params) |
||
| 1889 | |||
| 1890 | |||
| 1891 | /** |
||
| 1892 | * get or set an array of cached attributes for function that is |
||
| 1893 | * not cacheable |
||
| 1894 | * @return array |
||
| 1895 | */ |
||
| 1896 | function &_smarty_cache_attrs($cache_serial, $count) { |
||
| 1913 | |||
| 1914 | |||
| 1915 | /** |
||
| 1916 | * wrapper for include() retaining $this |
||
| 1917 | * @return mixed |
||
| 1918 | */ |
||
| 1919 | function _include($filename, $once=false, $params=null) |
||
| 1927 | |||
| 1928 | |||
| 1929 | /** |
||
| 1930 | * wrapper for eval() retaining $this |
||
| 1931 | * @return mixed |
||
| 1932 | */ |
||
| 1933 | function _eval($code, $params=null) |
||
| 1937 | |||
| 1938 | /** |
||
| 1939 | * Extracts the filter name from the given callback |
||
| 1940 | * |
||
| 1941 | * @param callback $function |
||
| 1942 | * @return string |
||
| 1943 | */ |
||
| 1944 | function _get_filter_name($function) |
||
| 1955 | |||
| 1956 | /**#@-*/ |
||
| 1957 | |||
| 1958 | } |
||
| 1959 | |||
| 1963 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.