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
 * Replace cached inserts with the actual results
Chris PeBenito 696b41
 *
Chris PeBenito 696b41
 * @param string $results
Chris PeBenito 696b41
 * @return string
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
function smarty_core_process_cached_inserts($params, &$smarty)
Chris PeBenito 696b41
{
Chris PeBenito 696b41
    preg_match_all('!'.$smarty->_smarty_md5.'{insert_cache (.*)}'.$smarty->_smarty_md5.'!Uis',
Chris PeBenito 696b41
                   $params['results'], $match);
Chris PeBenito 696b41
    list($cached_inserts, $insert_args) = $match;
Chris PeBenito 696b41
Chris PeBenito 696b41
    for ($i = 0, $for_max = count($cached_inserts); $i < $for_max; $i++) {
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
            $debug_start_time = smarty_core_get_microtime($_params, $smarty);
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
Chris PeBenito 696b41
        $args = unserialize($insert_args[$i]);
Chris PeBenito 696b41
        $name = $args['name'];
Chris PeBenito 696b41
Chris PeBenito 696b41
        if (isset($args['script'])) {
Chris PeBenito 696b41
            $_params = array('resource_name' => $smarty->_dequote($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
            $resource_type = $_params['resource_type'];
Chris PeBenito 696b41
            $php_resource = $_params['php_resource'];
Chris PeBenito 696b41
Chris PeBenito 696b41
Chris PeBenito 696b41
            if ($resource_type == 'file') {
Chris PeBenito 696b41
                $smarty->_include($php_resource, true);
Chris PeBenito 696b41
            } else {
Chris PeBenito 696b41
                $smarty->_eval($php_resource);
Chris PeBenito 696b41
            }
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
Chris PeBenito 696b41
        $function_name = $smarty->_plugins['insert'][$name][0];
Chris PeBenito 696b41
        if (empty($args['assign'])) {
Chris PeBenito 696b41
            $replace = $function_name($args, $smarty);
Chris PeBenito 696b41
        } else {
Chris PeBenito 696b41
            $smarty->assign($args['assign'], $function_name($args, $smarty));
Chris PeBenito 696b41
            $replace = '';
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
Chris PeBenito 696b41
        $params['results'] = str_replace($cached_inserts[$i], $replace, $params['results']);
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_'.$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
Chris PeBenito 696b41
    return $params['results'];
Chris PeBenito 696b41
}
Chris PeBenito 696b41
Chris PeBenito 696b41
/* vim: set expandtab: */
Chris PeBenito 696b41
Chris PeBenito 696b41
?>