]> git.mxchange.org Git - friendica.git/blob - library/Smarty/libs/SmartyBC.class.php
Merge remote branch 'upstream/master'
[friendica.git] / library / Smarty / libs / SmartyBC.class.php
1 <?php\r
2 /**\r
3  * Project:     Smarty: the PHP compiling template engine\r
4  * File:        SmartyBC.class.php\r
5  * SVN:         $Id: $\r
6  *\r
7  * This library is free software; you can redistribute it and/or\r
8  * modify it under the terms of the GNU Lesser General Public\r
9  * License as published by the Free Software Foundation; either\r
10  * version 2.1 of the License, or (at your option) any later version.\r
11  *\r
12  * This library is distributed in the hope that it will be useful,\r
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
15  * Lesser General Public License for more details.\r
16  *\r
17  * You should have received a copy of the GNU Lesser General Public\r
18  * License along with this library; if not, write to the Free Software\r
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
20  *\r
21  * For questions, help, comments, discussion, etc., please join the\r
22  * Smarty mailing list. Send a blank e-mail to\r
23  * smarty-discussion-subscribe@googlegroups.com\r
24  *\r
25  * @link http://www.smarty.net/\r
26  * @copyright 2008 New Digital Group, Inc.\r
27  * @author Monte Ohrt <monte at ohrt dot com>\r
28  * @author Uwe Tews\r
29  * @author Rodney Rehm\r
30  * @package Smarty\r
31  */\r
32 /**\r
33  * @ignore\r
34  */\r
35 require(dirname(__FILE__) . '/Smarty.class.php');\r
36 \r
37 /**\r
38  * Smarty Backward Compatability Wrapper Class\r
39  *\r
40  * @package Smarty\r
41  */\r
42 class SmartyBC extends Smarty {\r
43 \r
44     /**\r
45      * Smarty 2 BC\r
46      * @var string\r
47      */\r
48     public $_version = self::SMARTY_VERSION;\r
49 \r
50     /**\r
51      * Initialize new SmartyBC object\r
52      *\r
53      * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )\r
54      */\r
55     public function __construct(array $options=array())\r
56     {\r
57         parent::__construct($options);\r
58         // register {php} tag\r
59         $this->registerPlugin('block', 'php', 'smarty_php_tag');\r
60     }\r
61 \r
62     /**\r
63      * wrapper for assign_by_ref\r
64      *\r
65      * @param string $tpl_var the template variable name\r
66      * @param mixed  &$value  the referenced value to assign\r
67      */\r
68     public function assign_by_ref($tpl_var, &$value)\r
69     {\r
70         $this->assignByRef($tpl_var, $value);\r
71     }\r
72 \r
73     /**\r
74      * wrapper for append_by_ref\r
75      *\r
76      * @param string  $tpl_var the template variable name\r
77      * @param mixed   &$value  the referenced value to append\r
78      * @param boolean $merge   flag if array elements shall be merged\r
79      */\r
80     public function append_by_ref($tpl_var, &$value, $merge = false)\r
81     {\r
82         $this->appendByRef($tpl_var, $value, $merge);\r
83     }\r
84 \r
85     /**\r
86      * clear the given assigned template variable.\r
87      *\r
88      * @param string $tpl_var the template variable to clear\r
89      */\r
90     public function clear_assign($tpl_var)\r
91     {\r
92         $this->clearAssign($tpl_var);\r
93     }\r
94 \r
95     /**\r
96      * Registers custom function to be used in templates\r
97      *\r
98      * @param string $function      the name of the template function\r
99      * @param string $function_impl the name of the PHP function to register\r
100      * @param bool   $cacheable\r
101      * @param mixed  $cache_attrs\r
102      */\r
103     public function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)\r
104     {\r
105         $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);\r
106     }\r
107 \r
108     /**\r
109      * Unregisters custom function\r
110      *\r
111      * @param string $function name of template function\r
112      */\r
113     public function unregister_function($function)\r
114     {\r
115         $this->unregisterPlugin('function', $function);\r
116     }\r
117 \r
118     /**\r
119      * Registers object to be used in templates\r
120      *\r
121      * @param string  $object      name of template object\r
122      * @param object  $object_impl the referenced PHP object to register\r
123      * @param array   $allowed     list of allowed methods (empty = all)\r
124      * @param boolean $smarty_args smarty argument format, else traditional\r
125      * @param array   $block_functs list of methods that are block format\r
126      */\r
127     public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())\r
128     {\r
129         settype($allowed, 'array');\r
130         settype($smarty_args, 'boolean');\r
131         $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);\r
132     }\r
133 \r
134     /**\r
135      * Unregisters object\r
136      *\r
137      * @param string $object name of template object\r
138      */\r
139     public function unregister_object($object)\r
140     {\r
141         $this->unregisterObject($object);\r
142     }\r
143 \r
144     /**\r
145      * Registers block function to be used in templates\r
146      *\r
147      * @param string $block      name of template block\r
148      * @param string $block_impl PHP function to register\r
149      * @param bool   $cacheable\r
150      * @param mixed  $cache_attrs\r
151      */\r
152     public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)\r
153     {\r
154         $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);\r
155     }\r
156 \r
157     /**\r
158      * Unregisters block function\r
159      *\r
160      * @param string $block name of template function\r
161      */\r
162     public function unregister_block($block)\r
163     {\r
164         $this->unregisterPlugin('block', $block);\r
165     }\r
166 \r
167     /**\r
168      * Registers compiler function\r
169      *\r
170      * @param string $function      name of template function\r
171      * @param string $function_impl name of PHP function to register\r
172      * @param bool   $cacheable\r
173      */\r
174     public function register_compiler_function($function, $function_impl, $cacheable=true)\r
175     {\r
176         $this->registerPlugin('compiler', $function, $function_impl, $cacheable);\r
177     }\r
178 \r
179     /**\r
180      * Unregisters compiler function\r
181      *\r
182      * @param string $function name of template function\r
183      */\r
184     public function unregister_compiler_function($function)\r
185     {\r
186         $this->unregisterPlugin('compiler', $function);\r
187     }\r
188 \r
189     /**\r
190      * Registers modifier to be used in templates\r
191      *\r
192      * @param string $modifier name of template modifier\r
193      * @param string $modifier_impl name of PHP function to register\r
194      */\r
195     public function register_modifier($modifier, $modifier_impl)\r
196     {\r
197         $this->registerPlugin('modifier', $modifier, $modifier_impl);\r
198     }\r
199 \r
200     /**\r
201      * Unregisters modifier\r
202      *\r
203      * @param string $modifier name of template modifier\r
204      */\r
205     public function unregister_modifier($modifier)\r
206     {\r
207         $this->unregisterPlugin('modifier', $modifier);\r
208     }\r
209 \r
210     /**\r
211      * Registers a resource to fetch a template\r
212      *\r
213      * @param string $type      name of resource\r
214      * @param array  $functions array of functions to handle resource\r
215      */\r
216     public function register_resource($type, $functions)\r
217     {\r
218         $this->registerResource($type, $functions);\r
219     }\r
220 \r
221     /**\r
222      * Unregisters a resource\r
223      *\r
224      * @param string $type name of resource\r
225      */\r
226     public function unregister_resource($type)\r
227     {\r
228         $this->unregisterResource($type);\r
229     }\r
230 \r
231     /**\r
232      * Registers a prefilter function to apply\r
233      * to a template before compiling\r
234      *\r
235      * @param callable $function\r
236      */\r
237     public function register_prefilter($function)\r
238     {\r
239         $this->registerFilter('pre', $function);\r
240     }\r
241 \r
242     /**\r
243      * Unregisters a prefilter function\r
244      *\r
245      * @param callable $function\r
246      */\r
247     public function unregister_prefilter($function)\r
248     {\r
249         $this->unregisterFilter('pre', $function);\r
250     }\r
251 \r
252     /**\r
253      * Registers a postfilter function to apply\r
254      * to a compiled template after compilation\r
255      *\r
256      * @param callable $function\r
257      */\r
258     public function register_postfilter($function)\r
259     {\r
260         $this->registerFilter('post', $function);\r
261     }\r
262 \r
263     /**\r
264      * Unregisters a postfilter function\r
265      *\r
266      * @param callable $function\r
267      */\r
268     public function unregister_postfilter($function)\r
269     {\r
270         $this->unregisterFilter('post', $function);\r
271     }\r
272 \r
273     /**\r
274      * Registers an output filter function to apply\r
275      * to a template output\r
276      *\r
277      * @param callable $function\r
278      */\r
279     public function register_outputfilter($function)\r
280     {\r
281         $this->registerFilter('output', $function);\r
282     }\r
283 \r
284     /**\r
285      * Unregisters an outputfilter function\r
286      *\r
287      * @param callable $function\r
288      */\r
289     public function unregister_outputfilter($function)\r
290     {\r
291         $this->unregisterFilter('output', $function);\r
292     }\r
293 \r
294     /**\r
295      * load a filter of specified type and name\r
296      *\r
297      * @param string $type filter type\r
298      * @param string $name filter name\r
299      */\r
300     public function load_filter($type, $name)\r
301     {\r
302         $this->loadFilter($type, $name);\r
303     }\r
304 \r
305     /**\r
306      * clear cached content for the given template and cache id\r
307      *\r
308      * @param string $tpl_file   name of template file\r
309      * @param string $cache_id   name of cache_id\r
310      * @param string $compile_id name of compile_id\r
311      * @param string $exp_time   expiration time\r
312      * @return boolean\r
313      */\r
314     public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)\r
315     {\r
316         return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);\r
317     }\r
318 \r
319     /**\r
320      * clear the entire contents of cache (all templates)\r
321      *\r
322      * @param string $exp_time expire time\r
323      * @return boolean\r
324      */\r
325     public function clear_all_cache($exp_time = null)\r
326     {\r
327         return $this->clearCache(null, null, null, $exp_time);\r
328     }\r
329 \r
330     /**\r
331      * test to see if valid cache exists for this template\r
332      *\r
333      * @param string $tpl_file name of template file\r
334      * @param string $cache_id\r
335      * @param string $compile_id\r
336      * @return boolean\r
337      */\r
338     public function is_cached($tpl_file, $cache_id = null, $compile_id = null)\r
339     {\r
340         return $this->isCached($tpl_file, $cache_id, $compile_id);\r
341     }\r
342 \r
343     /**\r
344      * clear all the assigned template variables.\r
345      */\r
346     public function clear_all_assign()\r
347     {\r
348         $this->clearAllAssign();\r
349     }\r
350 \r
351     /**\r
352      * clears compiled version of specified template resource,\r
353      * or all compiled template files if one is not specified.\r
354      * This function is for advanced use only, not normally needed.\r
355      *\r
356      * @param string $tpl_file\r
357      * @param string $compile_id\r
358      * @param string $exp_time\r
359      * @return boolean results of {@link smarty_core_rm_auto()}\r
360      */\r
361     public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)\r
362     {\r
363         return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);\r
364     }\r
365 \r
366     /**\r
367      * Checks whether requested template exists.\r
368      *\r
369      * @param string $tpl_file\r
370      * @return boolean\r
371      */\r
372     public function template_exists($tpl_file)\r
373     {\r
374         return $this->templateExists($tpl_file);\r
375     }\r
376 \r
377     /**\r
378      * Returns an array containing template variables\r
379      *\r
380      * @param string $name\r
381      * @return array\r
382      */\r
383     public function get_template_vars($name=null)\r
384     {\r
385         return $this->getTemplateVars($name);\r
386     }\r
387 \r
388     /**\r
389      * Returns an array containing config variables\r
390      *\r
391      * @param string $name\r
392      * @return array\r
393      */\r
394     public function get_config_vars($name=null)\r
395     {\r
396         return $this->getConfigVars($name);\r
397     }\r
398 \r
399     /**\r
400      * load configuration values\r
401      *\r
402      * @param string $file\r
403      * @param string $section\r
404      * @param string $scope\r
405      */\r
406     public function config_load($file, $section = null, $scope = 'global')\r
407     {\r
408         $this->ConfigLoad($file, $section, $scope);\r
409     }\r
410 \r
411     /**\r
412      * return a reference to a registered object\r
413      *\r
414      * @param string $name\r
415      * @return object\r
416      */\r
417     public function get_registered_object($name)\r
418     {\r
419         return $this->getRegisteredObject($name);\r
420     }\r
421 \r
422     /**\r
423      * clear configuration values\r
424      *\r
425      * @param string $var\r
426      */\r
427     public function clear_config($var = null)\r
428     {\r
429         $this->clearConfig($var);\r
430     }\r
431 \r
432     /**\r
433      * trigger Smarty error\r
434      *\r
435      * @param string $error_msg\r
436      * @param integer $error_type\r
437      */\r
438     public function trigger_error($error_msg, $error_type = E_USER_WARNING)\r
439     {\r
440         trigger_error("Smarty error: $error_msg", $error_type);\r
441     }\r
442 \r
443 }\r
444 \r
445 /**\r
446  * Smarty {php}{/php} block function\r
447  *\r
448  * @param array   $params   parameter list\r
449  * @param string  $content  contents of the block\r
450  * @param object  $template template object\r
451  * @param boolean &$repeat  repeat flag\r
452  * @return string content re-formatted\r
453  */\r
454 function smarty_php_tag($params, $content, $template, &$repeat)\r
455 {\r
456     eval($content);\r
457     return '';\r
458 }\r
459 \r
460 ?>