5 * @subpackage plugins
\r
9 * Load requested plugins
\r
11 * @param array $plugins
\r
16 function smarty_core_load_plugins($params, &$smarty)
\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
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
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
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
38 $_plugin[1] = $_tpl_file;
\r
39 $_plugin[2] = $_tpl_line;
\r
41 if (!isset($_plugin[4])) $_plugin[4] = true; /* cacheable */
\r
45 } else if ($_type == 'insert') {
\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
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
57 $_plugin_file = $smarty->_get_plugin_filepath($_type, $_name);
\r
59 if (! $_found = ($_plugin_file != false)) {
\r
60 $_message = "could not load plugin file '$_type.$_name.php'\n";
\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
69 include_once $_plugin_file;
\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
78 * In case of insert plugins, their code may be loaded later via
\r
79 * 'script' attribute.
\r
81 else if ($_type == 'insert' && $_delayed_loading) {
\r
82 $_plugin_func = 'smarty_' . $_type . '_' . $_name;
\r
87 * Plugin specific processing and error checking.
\r
90 if ($_type == 'modifier') {
\r
92 * In case modifier falls back on using PHP functions
\r
93 * directly, we only allow those specified in the security
\r
96 if ($smarty->security && !in_array($_name, $smarty->security_settings['MODIFIER_FUNCS'])) {
\r
97 $_message = "(secure mode) modifier '$_name' is not allowed";
\r
99 if (!function_exists($_name)) {
\r
100 $_message = "modifier '$_name' is not implemented";
\r
102 $_plugin_func = $_name;
\r
106 } else if ($_type == 'function') {
\r
108 * This is a catch-all situation.
\r
110 $_message = "unknown tag - '$_name'";
\r
115 $smarty->_plugins[$_type][$_name] = array($_plugin_func, $_tpl_file, $_tpl_line, true, true);
\r
118 $smarty->_trigger_fatal_error('[plugin] ' . $_message, $_tpl_file, $_tpl_line, __FILE__, __LINE__);
\r
123 /* vim: set expandtab: */
\r