Хранилища Subversion ant

Редакция

Редакция 2 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 2 Редакция 296
1
<?php
1
<?php
2
/**
2
/**
3
 * Smarty plugin
3
 * Smarty plugin
4
 * @package Smarty
4
 * @package Smarty
5
 * @subpackage plugins
5
 * @subpackage plugins
6
 */
6
 */
7
7
8
/**
8
/**
9
 * Extract non-cacheable parts out of compiled template and write it
9
 * Extract non-cacheable parts out of compiled template and write it
10
 *
10
 *
11
 * @param string $compile_path
11
 * @param string $compile_path
12
 * @param string $template_compiled
12
 * @param string $template_compiled
13
 * @return boolean
13
 * @return boolean
14
 */
14
 */
15
15
16
function smarty_core_write_compiled_include($params, &$smarty)
16
function smarty_core_write_compiled_include($params, &$smarty)
17
{
17
{
18
    $_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; endif;';
18
    $_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; endif;';
19
    $_tag_end   = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{/nocache\:(\\2)#(\\3)\}\'; endif;';
19
    $_tag_end   = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{/nocache\:(\\2)#(\\3)\}\'; endif;';
20
20
21
    preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us',
21
    preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us',
22
                   $params['compiled_content'], $_match_source, PREG_SET_ORDER);
22
                   $params['compiled_content'], $_match_source, PREG_SET_ORDER);
23
   
23
   
24
    // no nocache-parts found: done
24
    // no nocache-parts found: done
25
    if (count($_match_source)==0) return;
25
    if (count($_match_source)==0) return;
26
26
27
    // convert the matched php-code to functions
27
    // convert the matched php-code to functions
28
    $_include_compiled =  "<?php /* Smarty version ".$smarty->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";
28
    $_include_compiled =  "<?php /* Smarty version ".$smarty->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";
29
    $_include_compiled .= "         compiled from " . strtr(urlencode($params['resource_name']), array('%2F'=>'/', '%3A'=>':')) . " */\n\n";
29
    $_include_compiled .= "         compiled from " . strtr(urlencode($params['resource_name']), array('%2F'=>'/', '%3A'=>':')) . " */\n\n";
30
30
31
    $_compile_path = $params['include_file_path'];
31
    $_compile_path = $params['include_file_path'];
32
32
33
    $smarty->_cache_serials[$_compile_path] = $params['cache_serial'];
33
    $smarty->_cache_serials[$_compile_path] = $params['cache_serial'];
34
    $_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>";
34
    $_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>";
35
35
36
    $_include_compiled .= $params['plugins_code'];
36
    $_include_compiled .= $params['plugins_code'];
37
    $_include_compiled .= "<?php";
37
    $_include_compiled .= "<?php";
38
38
39
    $this_varname = ((double)phpversion() >= 5.0) ? '_smarty' : 'this';
39
    $this_varname = ((double)phpversion() >= 5.0) ? '_smarty' : 'this';
40
    for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
40
    for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
41
        $_match =& $_match_source[$_i];
41
        $_match =& $_match_source[$_i];
42
        $source = $_match[4];
42
        $source = $_match[4];
43
        if ($this_varname == '_smarty') {
43
        if ($this_varname == '_smarty') {
44
            /* rename $this to $_smarty in the sourcecode */
44
            /* rename $this to $_smarty in the sourcecode */
45
            $tokens = token_get_all('<?php ' . $_match[4]);
45
            $tokens = token_get_all('<?php ' . $_match[4]);
46
46
47
            /* remove trailing <?php */
47
            /* remove trailing <?php */
48
            $open_tag = '';
48
            $open_tag = '';
49
            while ($tokens) {
49
            while ($tokens) {
50
                $token = array_shift($tokens);
50
                $token = array_shift($tokens);
51
                if (is_array($token)) {
51
                if (is_array($token)) {
52
                    $open_tag .= $token[1];
52
                    $open_tag .= $token[1];
53
                } else {
53
                } else {
54
                    $open_tag .= $token;
54
                    $open_tag .= $token;
55
                }
55
                }
56
                if ($open_tag == '<?php ') break;
56
                if ($open_tag == '<?php ') break;
57
            }
57
            }
58
58
59
            for ($i=0, $count = count($tokens); $i < $count; $i++) {
59
            for ($i=0, $count = count($tokens); $i < $count; $i++) {
60
                if (is_array($tokens[$i])) {
60
                if (is_array($tokens[$i])) {
61
                    if ($tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$this') {
61
                    if ($tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$this') {
62
                        $tokens[$i] = '$' . $this_varname;
62
                        $tokens[$i] = '$' . $this_varname;
63
                    } else {
63
                    } else {
64
                        $tokens[$i] = $tokens[$i][1];
64
                        $tokens[$i] = $tokens[$i][1];
65
                    }                  
65
                    }                  
66
                }
66
                }
67
            }
67
            }
68
            $source = implode('', $tokens);
68
            $source = implode('', $tokens);
69
        }
69
        }
70
70
71
        /* add function to compiled include */
71
        /* add function to compiled include */
72
        $_include_compiled .= "
72
        $_include_compiled .= "
73
function _smarty_tplfunc_$_match[2]_$_match[3](&\$$this_varname)
73
function _smarty_tplfunc_$_match[2]_$_match[3](&\$$this_varname)
74
{
74
{
75
$source
75
$source
76
}
76
}
77

77

78
";
78
";
79
    }
79
    }
80
    $_include_compiled .= "\n\n?>\n";
80
    $_include_compiled .= "\n\n?>\n";
81
81
82
    $_params = array('filename' => $_compile_path,
82
    $_params = array('filename' => $_compile_path,
83
                     'contents' => $_include_compiled, 'create_dirs' => true);
83
                     'contents' => $_include_compiled, 'create_dirs' => true);
84
84
85
    require_once(SMARTY_CORE_DIR . 'core.write_file.php');
85
    require_once(SMARTY_CORE_DIR . 'core.write_file.php');
86
    smarty_core_write_file($_params, $smarty);
86
    smarty_core_write_file($_params, $smarty);
87
    return true;
87
    return true;
88
}
88
}
89
89
90
90
91
?>
91
?>
92
 
92