]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Smarty/internals/core.load_plugins.php
Release 6.5.0
[Github/sugarcrm.git] / include / Smarty / internals / core.load_plugins.php
1 <?php
2
3 /*
4
5 Modification information for LGPL compliance
6
7 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
8
9 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
10
11 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
12
13 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3  tags and updated the build system 
14
15 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
16
17 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
18
19 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
20
21 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
22
23
24 */
25
26
27 /**
28  * Smarty plugin
29  * @package Smarty
30  * @subpackage plugins
31  */
32
33 /**
34  * Load requested plugins
35  *
36  * @param array $plugins
37  */
38
39 // $plugins
40
41 function smarty_core_load_plugins($params, &$smarty)
42 {
43
44     foreach ($params['plugins'] as $_plugin_info) {
45         list($_type, $_name, $_tpl_file, $_tpl_line, $_delayed_loading) = $_plugin_info;
46         $_plugin = &$smarty->_plugins[$_type][$_name];
47
48         /*
49          * We do not load plugin more than once for each instance of Smarty.
50          * The following code checks for that. The plugin can also be
51          * registered dynamically at runtime, in which case template file
52          * and line number will be unknown, so we fill them in.
53          *
54          * The final element of the info array is a flag that indicates
55          * whether the dynamically registered plugin function has been
56          * checked for existence yet or not.
57          */
58         if (isset($_plugin)) {
59             if (empty($_plugin[3])) {
60                 if (!is_callable($_plugin[0])) {
61                     $smarty->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__);
62                 } else {
63                     $_plugin[1] = $_tpl_file;
64                     $_plugin[2] = $_tpl_line;
65                     $_plugin[3] = true;
66                     if (!isset($_plugin[4])) $_plugin[4] = true; /* cacheable */
67                 }
68             }
69             continue;
70         } else if ($_type == 'insert') {
71             /*
72              * For backwards compatibility, we check for insert functions in
73              * the symbol table before trying to load them as a plugin.
74              */
75             $_plugin_func = 'insert_' . $_name;
76             if (function_exists($_plugin_func)) {
77                 $_plugin = array($_plugin_func, $_tpl_file, $_tpl_line, true, false);
78                 continue;
79             }
80         }
81
82         $_plugin_file = $smarty->_get_plugin_filepath($_type, $_name);
83
84         if (! $_found = ($_plugin_file != false)) {
85             $_message = "could not load plugin file '$_type.$_name.php'\n";
86         }
87
88         /*
89          * If plugin file is found, it -must- provide the properly named
90          * plugin function. In case it doesn't, simply output the error and
91          * do not fall back on any other method.
92          */
93         if ($_found) {
94             include_once $_plugin_file;
95
96             $_plugin_func = 'smarty_' . $_type . '_' . $_name;
97             if (!function_exists($_plugin_func)) {
98                 $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", $_tpl_file, $_tpl_line, __FILE__, __LINE__);
99                 continue;
100             }
101         }
102         /*
103          * In case of insert plugins, their code may be loaded later via
104          * 'script' attribute.
105          */
106         else if ($_type == 'insert' && $_delayed_loading) {
107             $_plugin_func = 'smarty_' . $_type . '_' . $_name;
108             $_found = true;
109         }
110
111         /*
112          * Plugin specific processing and error checking.
113          */
114         if (!$_found) {
115             if ($_type == 'modifier') {
116                 /*
117                  * In case modifier falls back on using PHP functions
118                  * directly, we only allow those specified in the security
119                  * context.
120                  */
121                 if ($smarty->security && !in_array($_name, $smarty->security_settings['MODIFIER_FUNCS'])) {
122                     $_message = "(secure mode) modifier '$_name' is not allowed";
123                 } else {
124                     if (!function_exists($_name)) {
125                         $_message = "modifier '$_name' is not implemented";
126                     } else {
127                         $_plugin_func = $_name;
128                         $_found = true;
129                     }
130                 }
131             } else if ($_type == 'function') {
132                 /*
133                  * This is a catch-all situation.
134                  */
135                 $_message = "unknown tag - '$_name'";
136             }
137         }
138
139         if ($_found) {
140             $smarty->_plugins[$_type][$_name] = array($_plugin_func, $_tpl_file, $_tpl_line, true, true);
141         } else {
142             // output error
143             $smarty->_trigger_fatal_error('[plugin] ' . $_message, $_tpl_file, $_tpl_line, __FILE__, __LINE__);
144         }
145     }
146 }
147
148 /* vim: set expandtab: */
149
150 ?>