Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty plugin
Chris PeBenito 696b41
 * @package Smarty
Chris PeBenito 696b41
 * @subpackage plugins
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Handle insert tags
Chris PeBenito 696b41
 *
Chris PeBenito 696b41
 * @param array $args
Chris PeBenito 696b41
 * @return string
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
function smarty_core_run_insert_handler($params, &$smarty)
Chris PeBenito 696b41
{
Chris PeBenito 696b41
Chris PeBenito 696b41
    require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
Chris PeBenito 696b41
    if ($smarty->debugging) {
Chris PeBenito 696b41
        $_params = array();
Chris PeBenito 696b41
        $_debug_start_time = smarty_core_get_microtime($_params, $smarty);
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
Chris PeBenito 696b41
    if ($smarty->caching) {
Chris PeBenito 696b41
        $_arg_string = serialize($params['args']);
Chris PeBenito 696b41
        $_name = $params['args']['name'];
Chris PeBenito 696b41
        if (!isset($smarty->_cache_info['insert_tags'][$_name])) {
Chris PeBenito 696b41
            $smarty->_cache_info['insert_tags'][$_name] = array('insert',
Chris PeBenito 696b41
                                                             $_name,
Chris PeBenito 696b41
                                                             $smarty->_plugins['insert'][$_name][1],
Chris PeBenito 696b41
                                                             $smarty->_plugins['insert'][$_name][2],
Chris PeBenito 696b41
                                                             !empty($params['args']['script']) ? true : false);
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
        return $smarty->_smarty_md5."{insert_cache $_arg_string}".$smarty->_smarty_md5;
Chris PeBenito 696b41
    } else {
Chris PeBenito 696b41
        if (isset($params['args']['script'])) {
Chris PeBenito 696b41
            $_params = array('resource_name' => $smarty->_dequote($params['args']['script']));
Chris PeBenito 696b41
            require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php');
Chris PeBenito 696b41
            if(!smarty_core_get_php_resource($_params, $smarty)) {
Chris PeBenito 696b41
                return false;
Chris PeBenito 696b41
            }
Chris PeBenito 696b41
Chris PeBenito 696b41
            if ($_params['resource_type'] == 'file') {
Chris PeBenito 696b41
                $smarty->_include($_params['php_resource'], true);
Chris PeBenito 696b41
            } else {
Chris PeBenito 696b41
                $smarty->_eval($_params['php_resource']);
Chris PeBenito 696b41
            }
Chris PeBenito 696b41
            unset($params['args']['script']);
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
Chris PeBenito 696b41
        $_funcname = $smarty->_plugins['insert'][$params['args']['name']][0];
Chris PeBenito 696b41
        $_content = $_funcname($params['args'], $smarty);
Chris PeBenito 696b41
        if ($smarty->debugging) {
Chris PeBenito 696b41
            $_params = array();
Chris PeBenito 696b41
            require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
Chris PeBenito 696b41
            $smarty->_smarty_debug_info[] = array('type'      => 'insert',
Chris PeBenito 696b41
                                                'filename'  => 'insert_'.$params['args']['name'],
Chris PeBenito 696b41
                                                'depth'     => $smarty->_inclusion_depth,
Chris PeBenito 696b41
                                                'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
Chris PeBenito 696b41
        if (!empty($params['args']["assign"])) {
Chris PeBenito 696b41
            $smarty->assign($params['args']["assign"], $_content);
Chris PeBenito 696b41
        } else {
Chris PeBenito 696b41
            return $_content;
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
}
Chris PeBenito 696b41
Chris PeBenito 696b41
/* vim: set expandtab: */
Chris PeBenito 696b41
Chris PeBenito 696b41
?>