Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

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