Initial repo created
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_wrapper.php
1 <?php
2
3 /**
4  * Project:     Smarty: the PHP compiling template engine
5  * File:        smarty_internal_wrapper.php
6  * SVN:         $Id: $
7  * 
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  * 
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  * 
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  * 
22  * For questions, help, comments, discussion, etc., please join the
23  * Smarty mailing list. Send a blank e-mail to
24  * smarty-discussion-subscribe@googlegroups.com
25  * 
26  * @link http://www.smarty.net/
27  * @copyright 2008 New Digital Group, Inc.
28  * @author Monte Ohrt <monte at ohrt dot com> 
29  * @author Uwe Tews 
30  * @package Smarty
31  * @subpackage PluginsInternal
32  * @version 3-SVN$Rev: 3286 $
33  */
34
35 /*
36  * Smarty Backward Compatability Wrapper
37  */
38
39 class Smarty_Internal_Wrapper {
40   
41     protected $smarty;
42
43     function __construct($smarty) {
44       $this->smarty = $smarty;
45     }
46     
47     /**
48      * Converts smarty2-style function call to smarty 3-style function call
49      * This is expensive, be sure to port your code to Smarty 3!
50      * 
51      * @param string $name Smarty 2 function name
52      * @param array $args Smarty 2 function args
53      */
54     function convert($name, $args) {
55        // throw notice about deprecated function
56        if($this->smarty->deprecation_notices)
57          trigger_error("function call '$name' is unknown or deprecated.",E_USER_NOTICE);
58        // get first and last part of function name
59        $name_parts = explode('_',$name,2);
60        switch($name_parts[0]) {
61          case 'register':
62          case 'unregister':
63            switch($name_parts[1]) {
64               case 'object':
65                  return call_user_func_array(array($this->smarty,"{$name_parts[0]}Object"),$args);
66               case 'compiler_function':
67                  return call_user_func_array(array($this->smarty,"{$name_parts[0]}Plugin"),array_merge(array('compiler'),$args));
68               case 'prefilter':
69                  return call_user_func_array(array($this->smarty,"{$name_parts[0]}Filter"),array_merge(array('pre'),$args));
70               case 'postfilter':
71                  return call_user_func_array(array($this->smarty,"{$name_parts[0]}Filter"),array_merge(array('post'),$args));
72               case 'outputfilter':
73                  return call_user_func_array(array($this->smarty,"{$name_parts[0]}Filter"),array_merge(array('output'),$args));
74              case 'resource':
75                  return call_user_func_array(array($this->smarty,"{$name_parts[0]}Resource"),$args);
76               default:
77                  return call_user_func_array(array($this->smarty,"{$name_parts[0]}Plugin"),array_merge(array($name_parts[1]),$args));
78            }
79            case 'get':
80            switch($name_parts[1]) {
81               case 'template_vars':
82                  return call_user_func_array(array($this->smarty,'getTemplateVars'),$args);
83               case 'config_vars':
84                  return call_user_func_array(array($this->smarty,'getConfigVars'),$args);
85               default:
86                  return call_user_func_array(array($myobj,$name_parts[1]),$args);
87            }
88            case 'clear':
89            switch($name_parts[1]) {
90               case 'all_assign':
91                  return call_user_func_array(array($this->smarty,'clearAllAssign'),$args);
92               case 'assign':
93                  return call_user_func_array(array($this->smarty,'clearAssign'),$args);
94               case 'all_cache':
95                  return call_user_func_array(array($this->smarty,'clearAllCache'),$args);
96               case 'cache':
97                  return call_user_func_array(array($this->smarty,'clearCache'),$args);
98               case 'compiled_template':
99                  return call_user_func_array(array($this->smarty,'clearCompiledTemplate'),$args);
100            }
101            case 'config':
102            switch($name_parts[1]) {
103               case 'load':
104                  return call_user_func_array(array($this->smarty,'configLoad'),$args);
105            }
106            case 'trigger':
107            switch($name_parts[1]) {
108               case 'error':
109                  return call_user_func_array('trigger_error',$args);
110            }
111            case 'load':
112            switch($name_parts[1]) {
113               case 'filter':
114                  return call_user_func_array(array($this->smarty,'loadFilter'),$args);
115            }
116        }
117        throw new SmartyException("unknown method '$name'");
118     }
119
120     /**
121      * trigger Smarty error
122      *
123      * @param string $error_msg
124      * @param integer $error_type
125      */
126     function trigger_error($error_msg, $error_type = E_USER_WARNING)
127     {
128         trigger_error("Smarty error: $error_msg", $error_type);
129     }
130 }
131 ?>