Smarty   F
last analyzed

Complexity

Total Complexity 218

Size/Duplication

Total Lines 1895
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 218
eloc 629
dl 0
loc 1895
rs 1.971
c 0
b 0
f 0

59 Methods

Rating   Name   Duplication   Size   Complexity  
A register_outputfilter() 0 4 1
A display() 0 3 1
A register_prefilter() 0 4 1
A __construct() 0 4 2
A _get_filter_name() 0 9 3
A assign() 0 11 5
A is_cached() 0 15 3
F fetch() 0 192 43
A unregister_compiler_function() 0 3 1
A load_filter() 0 14 5
B _smarty_include() 0 41 6
A get_template_vars() 0 10 3
A assign_by_ref() 0 4 2
A _get_auto_id() 0 7 4
A unregister_block() 0 3 1
A unregister_object() 0 3 1
A unregister_postfilter() 0 3 1
A register_function() 0 4 1
A clear_assign() 0 7 3
A unregister_function() 0 3 1
A clear_compiled_tpl() 0 12 2
F _fetch_resource_info() 0 71 21
A unregister_outputfilter() 0 3 1
A unregister_prefilter() 0 3 1
B append_by_ref() 0 12 7
A register_resource() 0 16 3
A _is_compiled() 0 23 6
B _parse_resource_name() 0 51 10
A _dequote() 0 7 4
A _process_compiled_include_callback() 0 7 1
A config_load() 0 4 1
A register_postfilter() 0 4 1
A _compile_resource() 0 25 4
A template_exists() 0 4 1
A get_registered_object() 0 8 3
A _get_compile_path() 0 4 1
A register_block() 0 4 1
A register_object() 0 6 1
A _smarty_cache_attrs() 0 13 2
A _read_file() 0 11 5
A _eval() 0 3 1
A _include() 0 6 2
A clear_config() 0 8 2
A get_config_vars() 0 10 4
A register_modifier() 0 4 1
A clear_all_assign() 0 3 1
B _compile_source() 0 55 5
A _get_plugin_filepath() 0 5 1
A unregister_resource() 0 3 1
A clear_cache() 0 21 4
A _get_auto_filename() 0 24 4
A _run_mod_handler() 0 13 2
A clear_all_cache() 0 3 1
A unregister_modifier() 0 3 1
A _trigger_fatal_error() 0 12 5
C append() 0 29 14
A _unlink() 0 8 3
A trigger_error() 0 4 1
A register_compiler_function() 0 4 1

How to fix   Complexity   

Complex Class

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.

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
2
3
/**
4
 * Project:     Smarty: the PHP compiling template engine
5
 * File:        Smarty.class.php
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 *
21
 * For questions, help, comments, discussion, etc., please join the
22
 * Smarty mailing list. Send a blank e-mail to
23
 * [email protected]
24
 *
25
 * @link http://www.smarty.net/
26
 * @copyright 2001-2005 New Digital Group, Inc.
27
 * @author Monte Ohrt <monte at ohrt dot com>
28
 * @author Andrei Zmievski <[email protected]>
29
 * @package Smarty
30
 * @version 2.6.31-dev
31
 */
32
33
/* $Id$ */
34
35
/**
36
 * DIR_SEP isn't used anymore, but third party apps might
37
 */
38
if(!defined('DIR_SEP')) {
39
    define('DIR_SEP', DIRECTORY_SEPARATOR);
40
}
41
42
/**
43
 * set SMARTY_DIR to absolute path to Smarty library files.
44
 * if not defined, include_path will be used. Sets SMARTY_DIR only if user
45
 * application has not already defined it.
46
 */
47
48
if (!defined('SMARTY_DIR')) {
49
    define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
50
}
51
52
if (!defined('SMARTY_CORE_DIR')) {
53
    define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR);
54
}
55
56
define('SMARTY_PHP_PASSTHRU',   0);
57
define('SMARTY_PHP_QUOTE',      1);
58
define('SMARTY_PHP_REMOVE',     2);
59
define('SMARTY_PHP_ALLOW',      3);
60
61
/**
62
 * @package Smarty
63
 */
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.31';
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
     * plugin filepath cache
567
     *
568
     * @var array
569
     */
570
    var $_filepaths_cache = array();
571
    /**#@-*/
572
    /**
573
     * The class constructor.
574
     */
575
    public function __construct()
576
    {
577
      $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME']
578
                    : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
579
    }
580
581
    /**
582
     * assigns values to template variables
583
     *
584
     * @param array|string $tpl_var the template variable name(s)
585
     * @param mixed $value the value to assign
586
     */
587
    function assign($tpl_var, $value = null)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
588
    {
589
        if (is_array($tpl_var)){
590
            foreach ($tpl_var as $key => $val) {
591
                if ($key != '') {
592
                    $this->_tpl_vars[$key] = $val;
593
                }
594
            }
595
        } else {
596
            if ($tpl_var != '')
597
                $this->_tpl_vars[$tpl_var] = $value;
598
        }
599
    }
600
601
    /**
602
     * assigns values to template variables by reference
603
     *
604
     * @param string $tpl_var the template variable name
605
     * @param mixed $value the referenced value to assign
606
     */
607
    function assign_by_ref($tpl_var, &$value)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
608
    {
609
        if ($tpl_var != '')
610
            $this->_tpl_vars[$tpl_var] = &$value;
611
    }
612
613
    /**
614
     * appends values to template variables
615
     *
616
     * @param array|string $tpl_var the template variable name(s)
617
     * @param mixed $value the value to append
618
     */
619
    function append($tpl_var, $value=null, $merge=false)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
620
    {
621
        if (is_array($tpl_var)) {
622
            // $tpl_var is an array, ignore $value
623
            foreach ($tpl_var as $_key => $_val) {
624
                if ($_key != '') {
625
                    if([email protected]_array($this->_tpl_vars[$_key])) {
626
                        settype($this->_tpl_vars[$_key],'array');
627
                    }
628
                    if($merge && is_array($_val)) {
629
                        foreach($_val as $_mkey => $_mval) {
630
                            $this->_tpl_vars[$_key][$_mkey] = $_mval;
631
                        }
632
                    } else {
633
                        $this->_tpl_vars[$_key][] = $_val;
634
                    }
635
                }
636
            }
637
        } else {
638
            if ($tpl_var != '' && isset($value)) {
639
                if([email protected]_array($this->_tpl_vars[$tpl_var])) {
640
                    settype($this->_tpl_vars[$tpl_var],'array');
641
                }
642
                if($merge && is_array($value)) {
643
                    foreach($value as $_mkey => $_mval) {
644
                        $this->_tpl_vars[$tpl_var][$_mkey] = $_mval;
645
                    }
646
                } else {
647
                    $this->_tpl_vars[$tpl_var][] = $value;
648
                }
649
            }
650
        }
651
    }
652
653
    /**
654
     * appends values to template variables by reference
655
     *
656
     * @param string $tpl_var the template variable name
657
     * @param mixed $value the referenced value to append
658
     */
659
    function append_by_ref($tpl_var, &$value, $merge=false)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
660
    {
661
        if ($tpl_var != '' && isset($value)) {
662
            if([email protected]_array($this->_tpl_vars[$tpl_var])) {
663
             settype($this->_tpl_vars[$tpl_var],'array');
664
            }
665
            if ($merge && is_array($value)) {
666
                foreach($value as $_key => $_val) {
667
                    $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key];
668
                }
669
            } else {
670
                $this->_tpl_vars[$tpl_var][] = &$value;
671
            }
672
        }
673
    }
674
675
676
    /**
677
     * clear the given assigned template variable.
678
     *
679
     * @param string $tpl_var the template variable to clear
680
     */
681
    function clear_assign($tpl_var)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
682
    {
683
        if (is_array($tpl_var))
0 ignored issues
show
introduced by geekwright
The condition is_array($tpl_var) is always false.
Loading history...
684
            foreach ($tpl_var as $curr_var)
685
                unset($this->_tpl_vars[$curr_var]);
686
        else
687
            unset($this->_tpl_vars[$tpl_var]);
688
    }
689
690
691
    /**
692
     * Registers custom function to be used in templates
693
     *
694
     * @param string $function the name of the template function
695
     * @param string $function_impl the name of the PHP function to register
696
     */
697
    function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
698
    {
699
        $this->_plugins['function'][$function] =
700
            array($function_impl, null, null, false, $cacheable, $cache_attrs);
701
702
    }
703
704
    /**
705
     * Unregisters custom function
706
     *
707
     * @param string $function name of template function
708
     */
709
    function unregister_function($function)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
710
    {
711
        unset($this->_plugins['function'][$function]);
712
    }
713
714
    /**
715
     * Registers object to be used in templates
716
     *
717
     * @param string $object name of template object
718
     * @param object &$object_impl the referenced PHP object to register
719
     * @param null|array $allowed list of allowed methods (empty = all)
720
     * @param boolean $smarty_args smarty argument format, else traditional
721
     * @param null|array $block_functs list of methods that are block format
722
     */
723
    function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
724
    {
725
        settype($allowed, 'array');
726
        settype($smarty_args, 'boolean');
727
        $this->_reg_objects[$object] =
728
            array(&$object_impl, $allowed, $smarty_args, $block_methods);
729
    }
730
731
    /**
732
     * Unregisters object
733
     *
734
     * @param string $object name of template object
735
     */
736
    function unregister_object($object)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
737
    {
738
        unset($this->_reg_objects[$object]);
739
    }
740
741
742
    /**
743
     * Registers block function to be used in templates
744
     *
745
     * @param string $block name of template block
746
     * @param string $block_impl PHP function to register
747
     */
748
    function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
749
    {
750
        $this->_plugins['block'][$block] =
751
            array($block_impl, null, null, false, $cacheable, $cache_attrs);
752
    }
753
754
    /**
755
     * Unregisters block function
756
     *
757
     * @param string $block name of template function
758
     */
759
    function unregister_block($block)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
760
    {
761
        unset($this->_plugins['block'][$block]);
762
    }
763
764
    /**
765
     * Registers compiler function
766
     *
767
     * @param string $function name of template function
768
     * @param string $function_impl name of PHP function to register
769
     */
770
    function register_compiler_function($function, $function_impl, $cacheable=true)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
771
    {
772
        $this->_plugins['compiler'][$function] =
773
            array($function_impl, null, null, false, $cacheable);
774
    }
775
776
    /**
777
     * Unregisters compiler function
778
     *
779
     * @param string $function name of template function
780
     */
781
    function unregister_compiler_function($function)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
782
    {
783
        unset($this->_plugins['compiler'][$function]);
784
    }
785
786
    /**
787
     * Registers modifier to be used in templates
788
     *
789
     * @param string $modifier name of template modifier
790
     * @param string $modifier_impl name of PHP function to register
791
     */
792
    function register_modifier($modifier, $modifier_impl)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
793
    {
794
        $this->_plugins['modifier'][$modifier] =
795
            array($modifier_impl, null, null, false);
796
    }
797
798
    /**
799
     * Unregisters modifier
800
     *
801
     * @param string $modifier name of template modifier
802
     */
803
    function unregister_modifier($modifier)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
804
    {
805
        unset($this->_plugins['modifier'][$modifier]);
806
    }
807
808
    /**
809
     * Registers a resource to fetch a template
810
     *
811
     * @param string $type name of resource
812
     * @param array $functions array of functions to handle resource
813
     */
814
    function register_resource($type, $functions)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
815
    {
816
        if (count($functions)==4) {
817
            $this->_plugins['resource'][$type] =
818
                array($functions, false);
819
820
        } elseif (count($functions)==5) {
821
            $this->_plugins['resource'][$type] =
822
                array(array(array(&$functions[0], $functions[1])
823
                            ,array(&$functions[0], $functions[2])
824
                            ,array(&$functions[0], $functions[3])
825
                            ,array(&$functions[0], $functions[4]))
826
                      ,false);
827
828
        } else {
829
            $this->trigger_error("malformed function-list for '$type' in register_resource");
830
831
        }
832
    }
833
834
    /**
835
     * Unregisters a resource
836
     *
837
     * @param string $type name of resource
838
     */
839
    function unregister_resource($type)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
840
    {
841
        unset($this->_plugins['resource'][$type]);
842
    }
843
844
    /**
845
     * Registers a prefilter function to apply
846
     * to a template before compiling
847
     *
848
     * @param callback $function
849
     */
850
    function register_prefilter($function)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
851
    {
852
        $this->_plugins['prefilter'][$this->_get_filter_name($function)]
853
            = array($function, null, null, false);
854
    }
855
856
    /**
857
     * Unregisters a prefilter function
858
     *
859
     * @param callback $function
860
     */
861
    function unregister_prefilter($function)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
862
    {
863
        unset($this->_plugins['prefilter'][$this->_get_filter_name($function)]);
864
    }
865
866
    /**
867
     * Registers a postfilter function to apply
868
     * to a compiled template after compilation
869
     *
870
     * @param callback $function
871
     */
872
    function register_postfilter($function)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
873
    {
874
        $this->_plugins['postfilter'][$this->_get_filter_name($function)]
875
            = array($function, null, null, false);
876
    }
877
878
    /**
879
     * Unregisters a postfilter function
880
     *
881
     * @param callback $function
882
     */
883
    function unregister_postfilter($function)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
884
    {
885
        unset($this->_plugins['postfilter'][$this->_get_filter_name($function)]);
886
    }
887
888
    /**
889
     * Registers an output filter function to apply
890
     * to a template output
891
     *
892
     * @param callback $function
893
     */
894
    function register_outputfilter($function)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
895
    {
896
        $this->_plugins['outputfilter'][$this->_get_filter_name($function)]
897
            = array($function, null, null, false);
898
    }
899
900
    /**
901
     * Unregisters an outputfilter function
902
     *
903
     * @param callback $function
904
     */
905
    function unregister_outputfilter($function)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
906
    {
907
        unset($this->_plugins['outputfilter'][$this->_get_filter_name($function)]);
908
    }
909
910
    /**
911
     * load a filter of specified type and name
912
     *
913
     * @param string $type filter type
914
     * @param string $name filter name
915
     */
916
    function load_filter($type, $name)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
917
    {
918
        switch ($type) {
919
            case 'output':
920
                $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false)));
921
                require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
922
                smarty_core_load_plugins($_params, $this);
923
                break;
924
925
            case 'pre':
926
            case 'post':
927
                if (!isset($this->_plugins[$type . 'filter'][$name]))
928
                    $this->_plugins[$type . 'filter'][$name] = false;
929
                break;
930
        }
931
    }
932
933
    /**
934
     * clear cached content for the given template and cache id
935
     *
936
     * @param string $tpl_file name of template file
937
     * @param string $cache_id name of cache_id
938
     * @param string $compile_id name of compile_id
939
     * @param string $exp_time expiration time
940
     * @return boolean
941
     */
942
    function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
0 ignored issues
show
Best Practice introduced by geekwright
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
943
    {
944
945
        if (!isset($compile_id))
946
            $compile_id = $this->compile_id;
947
948
        if (!isset($tpl_file))
949
            $compile_id = null;
950
951
        $_auto_id = $this->_get_auto_id($cache_id, $compile_id);
952
953
        if (!empty($this->cache_handler_func)) {
954
            return call_user_func_array($this->cache_handler_func,
955
                                  array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time));
0 ignored issues
show
Comprehensibility Best Practice introduced by geekwright
The variable $dummy seems to be never defined.
Loading history...
956
        } else {
957
            $_params = array('auto_base' => $this->cache_dir,
958
                            'auto_source' => $tpl_file,
959
                            'auto_id' => $_auto_id,