Code type module improvements:
[openemr.git] / library / core / core.assemble_plugin_filepath.php
blobc0d9d8665a36d50cff42854e1c1ae388e1dc8ffb
1 <?php
2 /**
3 * Smarty plugin
4 * @package Smarty
5 * @subpackage plugins
6 */
8 /**
9 * assemble filepath of requested plugin
11 * @param string $type
12 * @param string $name
13 * @return string|false
15 function smarty_core_assemble_plugin_filepath($params, &$smarty)
17 static $_filepaths_cache = array();
19 $_plugin_filename = $params['type'] . '.' . $params['name'] . '.php';
20 if (isset($_filepaths_cache[$_plugin_filename])) {
21 return $_filepaths_cache[$_plugin_filename];
23 $_return = false;
25 foreach ((array)$smarty->plugins_dir as $_plugin_dir) {
27 $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename;
29 // see if path is relative
30 if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) {
31 $_relative_paths[] = $_plugin_dir;
32 // relative path, see if it is in the SMARTY_DIR
33 if (@is_readable(SMARTY_DIR . $_plugin_filepath)) {
34 $_return = SMARTY_DIR . $_plugin_filepath;
35 break;
38 // try relative to cwd (or absolute)
39 if (@is_readable($_plugin_filepath)) {
40 $_return = $_plugin_filepath;
41 break;
45 if($_return === false) {
46 // still not found, try PHP include_path
47 if(isset($_relative_paths)) {
48 foreach ((array)$_relative_paths as $_plugin_dir) {
50 $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename;
52 $_params = array('file_path' => $_plugin_filepath);
53 require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');
54 if(smarty_core_get_include_path($_params, $smarty)) {
55 return $_params['new_file_path'];
60 $_filepaths_cache[$_plugin_filename] = $_return;
61 return $_return;
64 /* vim: set expandtab: */