]> git.sur5r.net Git - contagged/blob - inc/smarty/internals/core.assemble_plugin_filepath.php
Upgrade smarty from 2.6.18 to 2.6.30
[contagged] / inc / smarty / internals / core.assemble_plugin_filepath.php
1 <?php
2 /**
3  * Smarty plugin
4  * @package Smarty
5  * @subpackage plugins
6  */
7
8 /**
9  * assemble filepath of requested plugin
10  *
11  * @param string $type
12  * @param string $name
13  * @return string|false
14  */
15 function smarty_core_assemble_plugin_filepath($params, &$smarty)
16 {
17     $_plugin_filename = $params['type'] . '.' . $params['name'] . '.php';
18     if (isset($smarty->_filepaths_cache[$_plugin_filename])) {
19         return $smarty->_filepaths_cache[$_plugin_filename];
20     }
21     $_return = false;
22
23     foreach ((array)$smarty->plugins_dir as $_plugin_dir) {
24
25         $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename;
26
27         // see if path is relative
28         if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) {
29             $_relative_paths[] = $_plugin_dir;
30             // relative path, see if it is in the SMARTY_DIR
31             if (@is_readable(SMARTY_DIR . $_plugin_filepath)) {
32                 $_return = SMARTY_DIR . $_plugin_filepath;
33                 break;
34             }
35         }
36         // try relative to cwd (or absolute)
37         if (@is_readable($_plugin_filepath)) {
38             $_return = $_plugin_filepath;
39             break;
40         }
41     }
42
43     if($_return === false) {
44         // still not found, try PHP include_path
45         if(isset($_relative_paths)) {
46             foreach ((array)$_relative_paths as $_plugin_dir) {
47
48                 $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename;
49
50                 $_params = array('file_path' => $_plugin_filepath);
51                 require_once(SMARTY_CORE_DIR . 'core.get_include_path.php');
52                 if(smarty_core_get_include_path($_params, $smarty)) {
53                     $_return = $_params['new_file_path'];
54                     break;
55                 }
56             }
57         }
58     }
59     $smarty->_filepaths_cache[$_plugin_filename] = $_return;
60     return $_return;
61 }
62
63 /* vim: set expandtab: */
64
65 ?>