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