Хранилища 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
 * Retrieves PHP script resource
9
 * Retrieves PHP script resource
10
 *
10
 *
11
 * sets $php_resource to the returned resource
11
 * sets $php_resource to the returned resource
12
 * @param string $resource
12
 * @param string $resource
13
 * @param string $resource_type
13
 * @param string $resource_type
14
 * @param  $php_resource
14
 * @param  $php_resource
15
 * @return boolean
15
 * @return boolean
16
 */
16
 */
17
17
18
function smarty_core_get_php_resource(&$params, &$smarty)
18
function smarty_core_get_php_resource(&$params, &$smarty)
19
{
19
{
20
20
21
    $params['resource_base_path'] = $smarty->trusted_dir;
21
    $params['resource_base_path'] = $smarty->trusted_dir;
22
    $smarty->_parse_resource_name($params, $smarty);
22
    $smarty->_parse_resource_name($params, $smarty);
23
23
24
    /*
24
    /*
25
     * Find out if the resource exists.
25
     * Find out if the resource exists.
26
     */
26
     */
27
27
28
    if ($params['resource_type'] == 'file') {
28
    if ($params['resource_type'] == 'file') {
29
        $_readable = false;
29
        $_readable = false;
30
        if(file_exists($params['resource_name']) && is_readable($params['resource_name'])) {
30
        if(file_exists($params['resource_name']) && is_readable($params['resource_name'])) {
31
            $_readable = true;
31
            $_readable = true;
32
        } else {
32
        } else {
33
            // test for file in include_path
33
            // test for file in include_path
34
            $_params = array('file_path' => $params['resource_name']);
34
            $_params = array('file_path' => $params['resource_name']);
35
            require_once(SMARTY_CORE_DIR . 'core.get_include_path.php');
35
            require_once(SMARTY_CORE_DIR . 'core.get_include_path.php');
36
            if(smarty_core_get_include_path($_params, $smarty)) {
36
            if(smarty_core_get_include_path($_params, $smarty)) {
37
                $_include_path = $_params['new_file_path'];
37
                $_include_path = $_params['new_file_path'];
38
                $_readable = true;
38
                $_readable = true;
39
            }
39
            }
40
        }
40
        }
41
    } else if ($params['resource_type'] != 'file') {
41
    } else if ($params['resource_type'] != 'file') {
42
        $_template_source = null;
42
        $_template_source = null;
43
        $_readable = is_callable($smarty->_plugins['resource'][$params['resource_type']][0][0])
43
        $_readable = is_callable($smarty->_plugins['resource'][$params['resource_type']][0][0])
44
            && call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][0],
44
            && call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][0],
45
                                    array($params['resource_name'], &$_template_source, &$smarty));
45
                                    array($params['resource_name'], &$_template_source, &$smarty));
46
    }
46
    }
47
47
48
    /*
48
    /*
49
     * Set the error function, depending on which class calls us.
49
     * Set the error function, depending on which class calls us.
50
     */
50
     */
51
    if (method_exists($smarty, '_syntax_error')) {
51
    if (method_exists($smarty, '_syntax_error')) {
52
        $_error_funcc = '_syntax_error';
52
        $_error_funcc = '_syntax_error';
53
    } else {
53
    } else {
54
        $_error_funcc = 'trigger_error';
54
        $_error_funcc = 'trigger_error';
55
    }
55
    }
56
56
57
    if ($_readable) {
57
    if ($_readable) {
58
        if ($smarty->security) {
58
        if ($smarty->security) {
59
            require_once(SMARTY_CORE_DIR . 'core.is_trusted.php');
59
            require_once(SMARTY_CORE_DIR . 'core.is_trusted.php');
60
            if (!smarty_core_is_trusted($params, $smarty)) {
60
            if (!smarty_core_is_trusted($params, $smarty)) {
61
                $smarty->$_error_funcc('(secure mode) ' . $params['resource_type'] . ':' . $params['resource_name'] . ' is not trusted');
61
                $smarty->$_error_funcc('(secure mode) ' . $params['resource_type'] . ':' . $params['resource_name'] . ' is not trusted');
62
                return false;
62
                return false;
63
            }
63
            }
64
        }
64
        }
65
    } else {
65
    } else {
66
        $smarty->$_error_funcc($params['resource_type'] . ':' . $params['resource_name'] . ' is not readable');
66
        $smarty->$_error_funcc($params['resource_type'] . ':' . $params['resource_name'] . ' is not readable');
67
        return false;
67
        return false;
68
    }
68
    }
69
69
70
    if ($params['resource_type'] == 'file') {
70
    if ($params['resource_type'] == 'file') {
71
        $params['php_resource'] = $params['resource_name'];
71
        $params['php_resource'] = $params['resource_name'];
72
    } else {
72
    } else {
73
        $params['php_resource'] = $_template_source;
73
        $params['php_resource'] = $_template_source;
74
    }
74
    }
75
    return true;
75
    return true;
76
}
76
}
77
77
78
/* vim: set expandtab: */
78
/* vim: set expandtab: */
79
79
80
?>
80
?>
81
 
81