1 |
joko |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* Smarty plugin |
4 |
|
|
* @package Smarty |
5 |
|
|
* @subpackage plugins |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
/** |
9 |
|
|
* Extract non-cacheable parts out of compiled template and write it |
10 |
|
|
* |
11 |
|
|
* @param string $compile_path |
12 |
|
|
* @param string $template_compiled |
13 |
|
|
* @param integer $template_timestamp |
14 |
|
|
* @return boolean |
15 |
|
|
*/ |
16 |
|
|
|
17 |
|
|
function smarty_core_write_compiled_include($params, &$smarty) |
18 |
|
|
{ |
19 |
|
|
$_tag_start = 'if \(\$this->caching\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\';\}'; |
20 |
|
|
$_tag_end = 'if \(\$this->caching\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\';\}'; |
21 |
|
|
|
22 |
|
|
preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us', |
23 |
|
|
$params['compiled_content'], $_match_source, PREG_SET_ORDER); |
24 |
|
|
|
25 |
|
|
// no nocache-parts found: done |
26 |
|
|
if (count($_match_source)==0) return; |
27 |
|
|
|
28 |
|
|
// convert the matched php-code to functions |
29 |
|
|
$_include_compiled = "<?php /* funky header here */\n\n"; |
30 |
|
|
|
31 |
|
|
$_compile_path = $params['include_file_path']; |
32 |
|
|
|
33 |
|
|
$smarty->_cache_serials[$_compile_path] = $params['cache_serial']; |
34 |
|
|
$_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>"; |
35 |
|
|
|
36 |
|
|
$_include_compiled .= $params['plugins_code']; |
37 |
|
|
$_include_compiled .= "<?php"; |
38 |
|
|
|
39 |
|
|
$this_varname = ((double)phpversion() >= 5.0) ? '_smarty' : 'this'; |
40 |
|
|
for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) { |
41 |
|
|
$_match =& $_match_source[$_i]; |
42 |
|
|
$source = $_match[4]; |
43 |
|
|
if ($this_varname == '_smarty') { |
44 |
|
|
/* rename $this to $_smarty in the sourcecode */ |
45 |
|
|
$tokens = token_get_all('<?php ' . $_match[4]); |
46 |
|
|
array_shift($tokens); /* remove the opening <.?.php */ |
47 |
|
|
for ($i=0, $count = count($tokens); $i < $count; $i++) { |
48 |
|
|
if (is_array($tokens[$i])) { |
49 |
|
|
if ($tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$this') { |
50 |
|
|
$tokens[$i] = '$' . $this_varname; |
51 |
|
|
} else { |
52 |
|
|
$tokens[$i] = $tokens[$i][1]; |
53 |
|
|
} |
54 |
|
|
} |
55 |
|
|
} |
56 |
|
|
$source = implode('', $tokens); |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
/* add function to compiled include */ |
60 |
|
|
$_include_compiled .= " |
61 |
|
|
function _smarty_tplfunc_$_match[2]_$_match[3](&\$$this_varname) |
62 |
|
|
{ |
63 |
|
|
$source |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
"; |
67 |
|
|
} |
68 |
|
|
$_include_compiled .= "\n\n?>\n"; |
69 |
|
|
|
70 |
|
|
$_params = array('filename' => $_compile_path, |
71 |
|
|
'contents' => $_include_compiled, 'create_dirs' => true); |
72 |
|
|
|
73 |
|
|
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php'); |
74 |
|
|
smarty_core_write_file($_params, $smarty); |
75 |
|
|
return true; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
?> |