1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: |
|
9: |
|
10: | |
11: | |
12: | |
13: | |
14: | |
15: |
|
16: | class Smarty_Internal_Runtime_GetIncludePath
|
17: | {
|
18: | |
19: | |
20: | |
21: | |
22: |
|
23: | public $_include_path = '';
|
24: |
|
25: | |
26: | |
27: | |
28: | |
29: |
|
30: | public $_include_dirs = array();
|
31: |
|
32: | |
33: | |
34: | |
35: | |
36: |
|
37: | public $_user_dirs = array();
|
38: |
|
39: | |
40: | |
41: | |
42: | |
43: |
|
44: | public $isFile = array();
|
45: |
|
46: | |
47: | |
48: | |
49: | |
50: |
|
51: | public $isPath = array();
|
52: |
|
53: | |
54: | |
55: | |
56: | |
57: |
|
58: | public $number = array();
|
59: |
|
60: | |
61: | |
62: | |
63: | |
64: |
|
65: | public $_has_stream_include = null;
|
66: |
|
67: | |
68: | |
69: | |
70: | |
71: |
|
72: | public $counter = 0;
|
73: |
|
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: |
|
81: | public function isNewIncludePath(Smarty $smarty)
|
82: | {
|
83: | $_i_path = get_include_path();
|
84: | if ($this->_include_path !== $_i_path) {
|
85: | $this->_include_dirs = array();
|
86: | $this->_include_path = $_i_path;
|
87: | $_dirs = (array)explode(PATH_SEPARATOR, $_i_path);
|
88: | foreach ($_dirs as $_path) {
|
89: | if (is_dir($_path)) {
|
90: | $this->_include_dirs[] = $smarty->_realpath($_path . DIRECTORY_SEPARATOR, true);
|
91: | }
|
92: | }
|
93: | return true;
|
94: | }
|
95: | return false;
|
96: | }
|
97: |
|
98: | |
99: | |
100: | |
101: | |
102: | |
103: | |
104: |
|
105: | public function getIncludePathDirs(Smarty $smarty)
|
106: | {
|
107: | $this->isNewIncludePath($smarty);
|
108: | return $this->_include_dirs;
|
109: | }
|
110: |
|
111: | |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: |
|
120: | public function getIncludePath($dirs, $file, Smarty $smarty)
|
121: | {
|
122: |
|
123: | if (!(isset($this->_has_stream_include) ? $this->_has_stream_include :
|
124: | $this->_has_stream_include = function_exists('stream_resolve_include_path'))
|
125: | ) {
|
126: | $this->isNewIncludePath($smarty);
|
127: | }
|
128: |
|
129: | foreach ($dirs as $dir) {
|
130: | $dir_n = isset($this->number[ $dir ]) ? $this->number[ $dir ] : $this->number[ $dir ] = $this->counter++;
|
131: | if (isset($this->isFile[ $dir_n ][ $file ])) {
|
132: | if ($this->isFile[ $dir_n ][ $file ]) {
|
133: | return $this->isFile[ $dir_n ][ $file ];
|
134: | } else {
|
135: | continue;
|
136: | }
|
137: | }
|
138: | if (isset($this->_user_dirs[ $dir_n ])) {
|
139: | if (false === $this->_user_dirs[ $dir_n ]) {
|
140: | continue;
|
141: | } else {
|
142: | $dir = $this->_user_dirs[ $dir_n ];
|
143: | }
|
144: | } else {
|
145: | if ($dir[ 0 ] === '/' || $dir[ 1 ] === ':') {
|
146: | $dir = str_ireplace(getcwd(), '.', $dir);
|
147: | if ($dir[ 0 ] === '/' || $dir[ 1 ] === ':') {
|
148: | $this->_user_dirs[ $dir_n ] = false;
|
149: | continue;
|
150: | }
|
151: | }
|
152: | $dir = substr($dir, 2);
|
153: | $this->_user_dirs[ $dir_n ] = $dir;
|
154: | }
|
155: | if ($this->_has_stream_include) {
|
156: | $path = stream_resolve_include_path($dir . (isset($file) ? $file : ''));
|
157: | if ($path) {
|
158: | return $this->isFile[ $dir_n ][ $file ] = $path;
|
159: | }
|
160: | } else {
|
161: | foreach ($this->_include_dirs as $key => $_i_path) {
|
162: | $path = isset($this->isPath[ $key ][ $dir_n ]) ? $this->isPath[ $key ][ $dir_n ] :
|
163: | $this->isPath[ $key ][ $dir_n ] = is_dir($_dir_path = $_i_path . $dir) ? $_dir_path : false;
|
164: | if ($path === false) {
|
165: | continue;
|
166: | }
|
167: | if (isset($file)) {
|
168: | $_file = $this->isFile[ $dir_n ][ $file ] = (is_file($path . $file)) ? $path . $file : false;
|
169: | if ($_file) {
|
170: | return $_file;
|
171: | }
|
172: | } else {
|
173: |
|
174: | return $path;
|
175: | }
|
176: | }
|
177: | }
|
178: | }
|
179: | return false;
|
180: | }
|
181: | }
|
182: | |