core.assemble_plugin_filepath.php 1.9 KB

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