Code

Updated smarty
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_wrapper.php
1 <?php
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 */
35 /*
36  * Smarty Backward Compatability Wrapper
37  */
39 class Smarty_Internal_Wrapper {
40   
41     protected $smarty;
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            $myobj = $name_parts[0] == 'register' ? $this->smarty->register : $this->smarty->unregister;
64            switch($name_parts[1]) {
65               case 'function':
66                  return call_user_func_array(array($myobj,'templateFunction'),$args);
67                  break;
68               case 'object':
69                  return call_user_func_array(array($myobj,'templateObject'),$args);
70                  break;
71               case 'compiler_function':
72                  return call_user_func_array(array($myobj,'compilerFunction'),$args);
73                  break;
74               default:
75                  return call_user_func_array(array($myobj,$name_parts[1]),$args);
76                  break;
77            }
78            break;
79            case 'get':
80            switch($name_parts[1]) {
81               case 'template_vars':
82                  return call_user_func_array(array($this->smarty,'getTemplateVars'),$args);
83                  break;
84               case 'config_vars':
85                  return call_user_func_array(array($this->smarty,'getConfigVars'),$args);
86                  break;
87               default:
88                  return call_user_func_array(array($myobj,$name_parts[1]),$args);
89                  break;
90            }
91            break;
92            case 'clear':
93            switch($name_parts[1]) {
94               case 'all_assign':
95                  return call_user_func_array(array($this->smarty,'clearAllAssign'),$args);
96                  break;
97            }
98            break;
99            case 'config':
100            switch($name_parts[1]) {
101               case 'load':
102                  return call_user_func_array(array($this->smarty,'configLoad'),$args);
103                  break;
104            }
105            break;
106            default:
107              // convert foo_bar_baz to fooBarBaz style names
108              $name_parts = explode('_',$name);
109              foreach($name_parts as $idx=>$part) {
110                 if($idx==0)
111                   $name_parts[$idx] = strtolower($part);
112                 else
113                   $name_parts[$idx] = ucfirst($part);
114              }
115              $func_name = implode('',$name_parts);
116              if(!method_exists($this->smarty,$func_name)) {
117                 throw new Exception("unknown method '$name'");
118                 return false;
119              }
120              return call_user_func_array(array($this->smarty,$func_name),$args);
121            break;
122        }
123        return false;
124     }
127 ?>