6f412ec99ac7ed27f1d31b46276723d8d96e2887
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / core / core.load_plugins.php
1 <?php\r
2 /**\r
3  * Smarty plugin\r
4  * @package Smarty\r
5  * @subpackage plugins\r
6  */\r
7 \r
8 /**\r
9  * Load requested plugins\r
10  *\r
11  * @param array $plugins\r
12  */\r
13 \r
14 // $plugins\r
15 \r
16 function smarty_core_load_plugins($params, &$smarty)\r
17 {\r
18 \r
19     foreach ($params['plugins'] as $_plugin_info) {\r
20         list($_type, $_name, $_tpl_file, $_tpl_line, $_delayed_loading) = $_plugin_info;\r
21         $_plugin = &$smarty->_plugins[$_type][$_name];\r
22 \r
23         /*\r
24          * We do not load plugin more than once for each instance of Smarty.\r
25          * The following code checks for that. The plugin can also be\r
26          * registered dynamically at runtime, in which case template file\r
27          * and line number will be unknown, so we fill them in.\r
28          *\r
29          * The final element of the info array is a flag that indicates\r
30          * whether the dynamically registered plugin function has been\r
31          * checked for existence yet or not.\r
32          */\r
33         if (isset($_plugin)) {\r
34             if (empty($_plugin[3])) {\r
35                 if (!is_callable($_plugin[0])) {\r
36                     $smarty->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__);\r
37                 } else {\r
38                     $_plugin[1] = $_tpl_file;\r
39                     $_plugin[2] = $_tpl_line;\r
40                     $_plugin[3] = true;\r
41                     if (!isset($_plugin[4])) $_plugin[4] = true; /* cacheable */\r
42                 }\r
43             }\r
44             continue;\r
45         } else if ($_type == 'insert') {\r
46             /*\r
47              * For backwards compatibility, we check for insert functions in\r
48              * the symbol table before trying to load them as a plugin.\r
49              */\r
50             $_plugin_func = 'insert_' . $_name;\r
51             if (function_exists($_plugin_func)) {\r
52                 $_plugin = array($_plugin_func, $_tpl_file, $_tpl_line, true, false);\r
53                 continue;\r
54             }\r
55         }\r
56 \r
57         $_plugin_file = $smarty->_get_plugin_filepath($_type, $_name);\r
58 \r
59         if (! $_found = ($_plugin_file != false)) {\r
60             $_message = "could not load plugin file '$_type.$_name.php'\n";\r
61         }\r
62 \r
63         /*\r
64          * If plugin file is found, it -must- provide the properly named\r
65          * plugin function. In case it doesn't, simply output the error and\r
66          * do not fall back on any other method.\r
67          */\r
68         if ($_found) {\r
69             include_once $_plugin_file;\r
70 \r
71             $_plugin_func = 'smarty_' . $_type . '_' . $_name;\r
72             if (!function_exists($_plugin_func)) {\r
73                 $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", $_tpl_file, $_tpl_line, __FILE__, __LINE__);\r
74                 continue;\r
75             }\r
76         }\r
77         /*\r
78          * In case of insert plugins, their code may be loaded later via\r
79          * 'script' attribute.\r
80          */\r
81         else if ($_type == 'insert' && $_delayed_loading) {\r
82             $_plugin_func = 'smarty_' . $_type . '_' . $_name;\r
83             $_found = true;\r
84         }\r
85 \r
86         /*\r
87          * Plugin specific processing and error checking.\r
88          */\r
89         if (!$_found) {\r
90             if ($_type == 'modifier') {\r
91                 /*\r
92                  * In case modifier falls back on using PHP functions\r
93                  * directly, we only allow those specified in the security\r
94                  * context.\r
95                  */\r
96                 if ($smarty->security && !in_array($_name, $smarty->security_settings['MODIFIER_FUNCS'])) {\r
97                     $_message = "(secure mode) modifier '$_name' is not allowed";\r
98                 } else {\r
99                     if (!function_exists($_name)) {\r
100                         $_message = "modifier '$_name' is not implemented";\r
101                     } else {\r
102                         $_plugin_func = $_name;\r
103                         $_found = true;\r
104                     }\r
105                 }\r
106             } else if ($_type == 'function') {\r
107                 /*\r
108                  * This is a catch-all situation.\r
109                  */\r
110                 $_message = "unknown tag - '$_name'";\r
111             }\r
112         }\r
113 \r
114         if ($_found) {\r
115             $smarty->_plugins[$_type][$_name] = array($_plugin_func, $_tpl_file, $_tpl_line, true, true);\r
116         } else {\r
117             // output error\r
118             $smarty->_trigger_fatal_error('[plugin] ' . $_message, $_tpl_file, $_tpl_line, __FILE__, __LINE__);\r
119         }\r
120     }\r
121 }\r
122 \r
123 /* vim: set expandtab: */\r
124 \r
125 ?>\r