core.rm_auto.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * delete an automagically created file by name and id
  9. *
  10. * @param string $auto_base
  11. * @param string $auto_source
  12. * @param string $auto_id
  13. * @param integer $exp_time
  14. * @return boolean
  15. */
  16. // $auto_base, $auto_source = null, $auto_id = null, $exp_time = null
  17. function smarty_core_rm_auto($params, &$smarty)
  18. {
  19. if (!@is_dir($params['auto_base']))
  20. return false;
  21. if(!isset($params['auto_id']) && !isset($params['auto_source'])) {
  22. $_params = array(
  23. 'dirname' => $params['auto_base'],
  24. 'level' => 0,
  25. 'exp_time' => $params['exp_time']
  26. );
  27. require_once(SMARTY_CORE_DIR . 'core.rmdir.php');
  28. $_res = smarty_core_rmdir($_params, $smarty);
  29. } else {
  30. $_tname = $smarty->_get_auto_filename($params['auto_base'], $params['auto_source'], $params['auto_id']);
  31. if(isset($params['auto_source'])) {
  32. if (isset($params['extensions'])) {
  33. $_res = false;
  34. foreach ((array)$params['extensions'] as $_extension)
  35. $_res |= $smarty->_unlink($_tname.$_extension, $params['exp_time']);
  36. } else {
  37. $_res = $smarty->_unlink($_tname, $params['exp_time']);
  38. }
  39. } elseif ($smarty->use_sub_dirs) {
  40. $_params = array(
  41. 'dirname' => $_tname,
  42. 'level' => 1,
  43. 'exp_time' => $params['exp_time']
  44. );
  45. require_once(SMARTY_CORE_DIR . 'core.rmdir.php');
  46. $_res = smarty_core_rmdir($_params, $smarty);
  47. } else {
  48. // remove matching file names
  49. $_handle = opendir($params['auto_base']);
  50. $_res = true;
  51. while (false !== ($_filename = readdir($_handle))) {
  52. if($_filename == '.' || $_filename == '..') {
  53. continue;
  54. } elseif (substr($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, 0, strlen($_tname)) == $_tname) {
  55. $_res &= (bool)$smarty->_unlink($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, $params['exp_time']);
  56. }
  57. }
  58. }
  59. }
  60. return $_res;
  61. }
  62. /* vim: set expandtab: */
  63. ?>