1: <?php
2: /**
3: * Project: Smarty: the PHP compiling template engine
4: * File: SmartyBC.class.php
5: * SVN: $Id: $
6: * This library is free software; you can redistribute it and/or
7: * modify it under the terms of the GNU Lesser General Public
8: * License as published by the Free Software Foundation; either
9: * version 2.1 of the License, or (at your option) any later version.
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: * For questions, help, comments, discussion, etc., please join the
18: * Smarty mailing list. Send a blank e-mail to
19: * smarty-discussion-subscribe@googlegroups.com
20: *
21: * @link http://www.smarty.net/
22: * @copyright 2008 New Digital Group, Inc.
23: * @author Monte Ohrt <monte at ohrt dot com>
24: * @author Uwe Tews
25: * @author Rodney Rehm
26: * @package Smarty
27: */
28: /**
29: * @ignore
30: */
31: require_once(dirname(__FILE__) . '/Smarty.class.php');
32:
33: /**
34: * Smarty Backward Compatability Wrapper Class
35: *
36: * @package Smarty
37: */
38: class SmartyBC extends Smarty
39: {
40: /**
41: * Smarty 2 BC
42: *
43: * @var string
44: */
45: public $_version = self::SMARTY_VERSION;
46:
47: /**
48: * Initialize new SmartyBC object
49: *
50: * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
51: */
52: public function __construct(array $options = array())
53: {
54: parent::__construct($options);
55: // register {php} tag
56: $this->registerPlugin('block', 'php', 'smarty_php_tag');
57: }
58:
59: /**
60: * wrapper for assign_by_ref
61: *
62: * @param string $tpl_var the template variable name
63: * @param mixed &$value the referenced value to assign
64: */
65: public function assign_by_ref($tpl_var, &$value)
66: {
67: $this->assignByRef($tpl_var, $value);
68: }
69:
70: /**
71: * wrapper for append_by_ref
72: *
73: * @param string $tpl_var the template variable name
74: * @param mixed &$value the referenced value to append
75: * @param boolean $merge flag if array elements shall be merged
76: */
77: public function append_by_ref($tpl_var, &$value, $merge = false)
78: {
79: $this->appendByRef($tpl_var, $value, $merge);
80: }
81:
82: /**
83: * clear the given assigned template variable.
84: *
85: * @param string $tpl_var the template variable to clear
86: */
87: public function clear_assign($tpl_var)
88: {
89: $this->clearAssign($tpl_var);
90: }
91:
92: /**
93: * Registers custom function to be used in templates
94: *
95: * @param string $function the name of the template function
96: * @param string $function_impl the name of the PHP function to register
97: * @param bool $cacheable
98: * @param mixed $cache_attrs
99: */
100: public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
101: {
102: $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
103: }
104:
105: /**
106: * Unregisters custom function
107: *
108: * @param string $function name of template function
109: */
110: public function unregister_function($function)
111: {
112: $this->unregisterPlugin('function', $function);
113: }
114:
115: /**
116: * Registers object to be used in templates
117: *
118: * @param string $object name of template object
119: * @param object $object_impl the referenced PHP object to register
120: * @param array $allowed list of allowed methods (empty = all)
121: * @param boolean $smarty_args smarty argument format, else traditional
122: * @param array $block_methods list of methods that are block format
123: *
124: * @throws SmartyException
125: * @internal 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: *
313: * @return boolean
314: */
315: public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
316: {
317: return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
318: }
319:
320: /**
321: * clear the entire contents of cache (all templates)
322: *
323: * @param string $exp_time expire time
324: *
325: * @return boolean
326: */
327: public function clear_all_cache($exp_time = null)
328: {
329: return $this->clearCache(null, null, null, $exp_time);
330: }
331:
332: /**
333: * test to see if valid cache exists for this template
334: *
335: * @param string $tpl_file name of template file
336: * @param string $cache_id
337: * @param string $compile_id
338: *
339: * @return boolean
340: */
341: public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
342: {
343: return $this->isCached($tpl_file, $cache_id, $compile_id);
344: }
345:
346: /**
347: * clear all the assigned template variables.
348: */
349: public function clear_all_assign()
350: {
351: $this->clearAllAssign();
352: }
353:
354: /**
355: * clears compiled version of specified template resource,
356: * or all compiled template files if one is not specified.
357: * This function is for advanced use only, not normally needed.
358: *
359: * @param string $tpl_file
360: * @param string $compile_id
361: * @param string $exp_time
362: *
363: * @return boolean results of {@link smarty_core_rm_auto()}
364: */
365: public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
366: {
367: return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
368: }
369:
370: /**
371: * Checks whether requested template exists.
372: *
373: * @param string $tpl_file
374: *
375: * @return boolean
376: */
377: public function template_exists($tpl_file)
378: {
379: return $this->templateExists($tpl_file);
380: }
381:
382: /**
383: * Returns an array containing template variables
384: *
385: * @param string $name
386: *
387: * @return array
388: */
389: public function get_template_vars($name = null)
390: {
391: return $this->getTemplateVars($name);
392: }
393:
394: /**
395: * Returns an array containing config variables
396: *
397: * @param string $name
398: *
399: * @return array
400: */
401: public function get_config_vars($name = null)
402: {
403: return $this->getConfigVars($name);
404: }
405:
406: /**
407: * load configuration values
408: *
409: * @param string $file
410: * @param string $section
411: * @param string $scope
412: */
413: public function config_load($file, $section = null, $scope = 'global')
414: {
415: $this->ConfigLoad($file, $section, $scope);
416: }
417:
418: /**
419: * return a reference to a registered object
420: *
421: * @param string $name
422: *
423: * @return object
424: */
425: public function get_registered_object($name)
426: {
427: return $this->getRegisteredObject($name);
428: }
429:
430: /**
431: * clear configuration values
432: *
433: * @param string $var
434: */
435: public function clear_config($var = null)
436: {
437: $this->clearConfig($var);
438: }
439:
440: /**
441: * trigger Smarty error
442: *
443: * @param string $error_msg
444: * @param integer $error_type
445: */
446: public function trigger_error($error_msg, $error_type = E_USER_WARNING)
447: {
448: trigger_error("Smarty error: $error_msg", $error_type);
449: }
450: }
451:
452: /**
453: * Smarty {php}{/php} block function
454: *
455: * @param array $params parameter list
456: * @param string $content contents of the block
457: * @param object $template template object
458: * @param boolean &$repeat repeat flag
459: *
460: * @return string content re-formatted
461: */
462: function smarty_php_tag($params, $content, $template, &$repeat)
463: {
464: eval($content);
465:
466: return '';
467: }
468: