Commit | Line | Data |
---|---|---|
e586807d H |
1 | <?php |
2 | /** | |
3 | * Smarty plugin | |
4 | * @package Smarty | |
5 | * @subpackage plugins | |
6 | */ | |
7 | ||
8 | /** | |
9 | * Replace cached inserts with the actual results | |
10 | * | |
11 | * @param string $results | |
12 | * @return string | |
13 | */ | |
14 | function smarty_core_process_cached_inserts($params, &$smarty) | |
15 | { | |
16 | preg_match_all('!'.$smarty->_smarty_md5.'{insert_cache (.*)}'.$smarty->_smarty_md5.'!Uis', | |
17 | $params['results'], $match); | |
18 | list($cached_inserts, $insert_args) = $match; | |
19 | ||
20 | for ($i = 0, $for_max = count($cached_inserts); $i < $for_max; $i++) { | |
21 | if ($smarty->debugging) { | |
22 | $_params = array(); | |
23 | require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); | |
24 | $debug_start_time = smarty_core_get_microtime($_params, $smarty); | |
25 | } | |
26 | ||
27 | $args = unserialize($insert_args[$i]); | |
28 | $name = $args['name']; | |
29 | ||
30 | if (isset($args['script'])) { | |
31 | $_params = array('resource_name' => $smarty->_dequote($args['script'])); | |
32 | require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php'); | |
33 | if(!smarty_core_get_php_resource($_params, $smarty)) { | |
34 | return false; | |
35 | } | |
36 | $resource_type = $_params['resource_type']; | |
37 | $php_resource = $_params['php_resource']; | |
38 | ||
39 | ||
40 | if ($resource_type == 'file') { | |
41 | $smarty->_include($php_resource, true); | |
42 | } else { | |
43 | $smarty->_eval($php_resource); | |
44 | } | |
45 | } | |
46 | ||
47 | $function_name = $smarty->_plugins['insert'][$name][0]; | |
48 | $replace = $function_name($args, $smarty); | |
49 | ||
50 | $params['results'] = str_replace($cached_inserts[$i], $replace, $params['results']); | |
51 | if ($smarty->debugging) { | |
52 | $_params = array(); | |
53 | require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); | |
54 | $smarty->_smarty_debug_info[] = array('type' => 'insert', | |
55 | 'filename' => 'insert_'.$name, | |
56 | 'depth' => $smarty->_inclusion_depth, | |
57 | 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $debug_start_time); | |
58 | } | |
59 | } | |
60 | ||
61 | return $params['results']; | |
62 | } | |
63 | ||
64 | /* vim: set expandtab: */ | |
65 | ||
66 | ?> |