Редакция 2 | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 2 | Редакция 48 | ||
---|---|---|---|
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 | * assemble filepath of requested plugin
|
9 | * assemble filepath of requested plugin
|
10 | *
|
10 | *
|
11 | * @param string $type
|
11 | * @param string $type
|
12 | * @param string $name
|
12 | * @param string $name
|
13 | * @return string|false
|
13 | * @return string|false
|
14 | */
|
14 | */
|
15 | function smarty_core_assemble_plugin_filepath($params, &$smarty) |
15 | function smarty_core_assemble_plugin_filepath($params, &$smarty) |
16 | {
|
16 | {
|
17 | static $_filepaths_cache = array(); |
17 | static $_filepaths_cache = array(); |
18 | 18 | ||
19 | $_plugin_filename = $params['type'] . '.' . $params['name'] . '.php'; |
19 | $_plugin_filename = $params['type'] . '.' . $params['name'] . '.php'; |
20 | if (isset($_filepaths_cache[$_plugin_filename])) { |
20 | if (isset($_filepaths_cache[$_plugin_filename])) { |
21 | return $_filepaths_cache[$_plugin_filename]; |
21 | return $_filepaths_cache[$_plugin_filename]; |
22 | }
|
22 | }
|
23 | $_return = false; |
23 | $_return = false; |
24 | 24 | ||
25 | foreach ((array)$smarty->plugins_dir as $_plugin_dir) { |
25 | foreach ((array)$smarty->plugins_dir as $_plugin_dir) { |
26 | 26 | ||
27 | $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename; |
27 | $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename; |
28 | 28 | ||
29 | // see if path is relative
|
29 | // see if path is relative
|
30 | if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) { |
30 | if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) { |
31 | $_relative_paths[] = $_plugin_dir; |
31 | $_relative_paths[] = $_plugin_dir; |
32 | // relative path, see if it is in the SMARTY_DIR
|
32 | // relative path, see if it is in the SMARTY_DIR
|
33 | if (@is_readable(SMARTY_DIR . $_plugin_filepath)) { |
33 | if (@is_readable(SMARTY_DIR . $_plugin_filepath)) { |
34 | $_return = SMARTY_DIR . $_plugin_filepath; |
34 | $_return = SMARTY_DIR . $_plugin_filepath; |
35 | break; |
35 | break; |
36 | }
|
36 | }
|
37 | }
|
37 | }
|
38 | // try relative to cwd (or absolute)
|
38 | // try relative to cwd (or absolute)
|
39 | if (@is_readable($_plugin_filepath)) { |
39 | if (@is_readable($_plugin_filepath)) { |
40 | $_return = $_plugin_filepath; |
40 | $_return = $_plugin_filepath; |
41 | break; |
41 | break; |
42 | }
|
42 | }
|
43 | }
|
43 | }
|
44 | 44 | ||
45 | if($_return === false) { |
45 | if($_return === false) { |
46 | // still not found, try PHP include_path
|
46 | // still not found, try PHP include_path
|
47 | if(isset($_relative_paths)) { |
47 | if(isset($_relative_paths)) { |
48 | foreach ((array)$_relative_paths as $_plugin_dir) { |
48 | foreach ((array)$_relative_paths as $_plugin_dir) { |
49 | 49 | ||
50 | $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename; |
50 | $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename; |
51 | 51 | ||
52 | $_params = array('file_path' => $_plugin_filepath); |
52 | $_params = array('file_path' => $_plugin_filepath); |
53 | require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); |
53 | require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); |
54 | if(smarty_core_get_include_path($_params, $smarty)) { |
54 | if(smarty_core_get_include_path($_params, $smarty)) { |
55 | $_return = $_params['new_file_path']; |
55 | $_return = $_params['new_file_path']; |
56 | break; |
56 | break; |
57 | }
|
57 | }
|
58 | }
|
58 | }
|
59 | }
|
59 | }
|
60 | }
|
60 | }
|
61 | $_filepaths_cache[$_plugin_filename] = $_return; |
61 | $_filepaths_cache[$_plugin_filename] = $_return; |
62 | return $_return; |
62 | return $_return; |
63 | }
|
63 | }
|
64 | 64 | ||
65 | /* vim: set expandtab: */
|
65 | /* vim: set expandtab: */
|
66 | 66 | ||
67 | ?>
|
67 | ?>
|
68 | 68 |