• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/internals/core.load_plugins.php

00001 <?php
00014 // $plugins
00015 
00016 function smarty_core_load_plugins($params, &$smarty)
00017 {
00018 
00019     foreach ($params['plugins'] as $_plugin_info) {
00020         list($_type, $_name, $_tpl_file, $_tpl_line, $_delayed_loading) = $_plugin_info;
00021         $_plugin = &$smarty->_plugins[$_type][$_name];
00022 
00023         /*
00024          * We do not load plugin more than once for each instance of Smarty.
00025          * The following code checks for that. The plugin can also be
00026          * registered dynamically at runtime, in which case template file
00027          * and line number will be unknown, so we fill them in.
00028          *
00029          * The final element of the info array is a flag that indicates
00030          * whether the dynamically registered plugin function has been
00031          * checked for existence yet or not.
00032          */
00033         if (isset($_plugin)) {
00034             if (empty($_plugin[3])) {
00035                 if (!is_callable($_plugin[0])) {
00036                     $smarty->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__);
00037                 } else {
00038                     $_plugin[1] = $_tpl_file;
00039                     $_plugin[2] = $_tpl_line;
00040                     $_plugin[3] = true;
00041                     if (!isset($_plugin[4])) $_plugin[4] = true; /* cacheable */
00042                 }
00043             }
00044             continue;
00045         } else if ($_type == 'insert') {
00046             /*
00047              * For backwards compatibility, we check for insert functions in
00048              * the symbol table before trying to load them as a plugin.
00049              */
00050             $_plugin_func = 'insert_' . $_name;
00051             if (function_exists($_plugin_func)) {
00052                 $_plugin = array($_plugin_func, $_tpl_file, $_tpl_line, true, false);
00053                 continue;
00054             }
00055         }
00056 
00057         $_plugin_file = $smarty->_get_plugin_filepath($_type, $_name);
00058 
00059         if (! $_found = ($_plugin_file != false)) {
00060             $_message = "could not load plugin file '$_type.$_name.php'\n";
00061         }
00062 
00063         /*
00064          * If plugin file is found, it -must- provide the properly named
00065          * plugin function. In case it doesn't, simply output the error and
00066          * do not fall back on any other method.
00067          */
00068         if ($_found) {
00069             include_once $_plugin_file;
00070 
00071             $_plugin_func = 'smarty_' . $_type . '_' . $_name;
00072             if (!function_exists($_plugin_func)) {
00073                 $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", $_tpl_file, $_tpl_line, __FILE__, __LINE__);
00074                 continue;
00075             }
00076         }
00077         /*
00078          * In case of insert plugins, their code may be loaded later via
00079          * 'script' attribute.
00080          */
00081         else if ($_type == 'insert' && $_delayed_loading) {
00082             $_plugin_func = 'smarty_' . $_type . '_' . $_name;
00083             $_found = true;
00084         }
00085 
00086         /*
00087          * Plugin specific processing and error checking.
00088          */
00089         if (!$_found) {
00090             if ($_type == 'modifier') {
00091                 /*
00092                  * In case modifier falls back on using PHP functions
00093                  * directly, we only allow those specified in the security
00094                  * context.
00095                  */
00096                 if ($smarty->security && !in_array($_name, $smarty->security_settings['MODIFIER_FUNCS'])) {
00097                     $_message = "(secure mode) modifier '$_name' is not allowed";
00098                 } else {
00099                     if (!function_exists($_name)) {
00100                         $_message = "modifier '$_name' is not implemented";
00101                     } else {
00102                         $_plugin_func = $_name;
00103                         $_found = true;
00104                     }
00105                 }
00106             } else if ($_type == 'function') {
00107                 /*
00108                  * This is a catch-all situation.
00109                  */
00110                 $_message = "unknown tag - '$_name'";
00111             }
00112         }
00113 
00114         if ($_found) {
00115             $smarty->_plugins[$_type][$_name] = array($_plugin_func, $_tpl_file, $_tpl_line, true, true);
00116         } else {
00117             // output error
00118             $smarty->_trigger_fatal_error('[plugin] ' . $_message, $_tpl_file, $_tpl_line, __FILE__, __LINE__);
00119         }
00120     }
00121 }
00122 
00123 /* vim: set expandtab: */
00124 
00125 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2