core.is_trusted.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * determines if a resource is trusted or not
  9. *
  10. * @param string $resource_type
  11. * @param string $resource_name
  12. * @return boolean
  13. */
  14. // $resource_type, $resource_name
  15. function smarty_core_is_trusted($params, &$smarty)
  16. {
  17. $_smarty_trusted = false;
  18. if ($params['resource_type'] == 'file') {
  19. if (!empty($smarty->trusted_dir)) {
  20. $_rp = realpath($params['resource_name']);
  21. foreach ((array)$smarty->trusted_dir as $curr_dir) {
  22. if (!empty($curr_dir) && is_readable ($curr_dir)) {
  23. $_cd = realpath($curr_dir);
  24. if (strncmp($_rp, $_cd, strlen($_cd)) == 0
  25. && substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) {
  26. $_smarty_trusted = true;
  27. break;
  28. }
  29. }
  30. }
  31. }
  32. } else {
  33. // resource is not on local file system
  34. $_smarty_trusted = call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][3],
  35. array($params['resource_name'], $smarty));
  36. }
  37. return $_smarty_trusted;
  38. }
  39. /* vim: set expandtab: */
  40. ?>