source: trunk/include/smarty/libs/SmartyBC.class.php @ 23384

Last change on this file since 23384 was 23384, checked in by rvelices, 11 years ago

smarty 3 - first pass for tests

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