Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 17 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * delete a dir recursively (level=0 -> keep root)
  9. * WARNING: no tests, it will try to remove what you tell it!
  10. *
  11. * @param string $dirname
  12. * @param integer $level
  13. * @param integer $exp_time
  14. * @return boolean
  15. */
  16. // $dirname, $level = 1, $exp_time = null
  17. function smarty_core_rmdir($params, &$smarty)
  18. {
  19. if(!isset($params['level'])) { $params['level'] = 1; }
  20. if(!isset($params['exp_time'])) { $params['exp_time'] = null; }
  21. if($_handle = @opendir($params['dirname'])) {
  22. while (false !== ($_entry = readdir($_handle))) {
  23. if ($_entry != '.' && $_entry != '..') {
  24. if (@is_dir($params['dirname'] . DIRECTORY_SEPARATOR . $_entry)) {
  25. $_params = array(
  26. 'dirname' => $params['dirname'] . DIRECTORY_SEPARATOR . $_entry,
  27. 'level' => $params['level'] + 1,
  28. 'exp_time' => $params['exp_time']
  29. );
  30. smarty_core_rmdir($_params, $smarty);
  31. }
  32. else {
  33. $smarty->_unlink($params['dirname'] . DIRECTORY_SEPARATOR . $_entry, $params['exp_time']);
  34. }
  35. }
  36. }
  37. closedir($_handle);
  38. }
  39. if ($params['level']) {
  40. return @rmdir($params['dirname']);
  41. }
  42. return (bool)$_handle;
  43. }
  44. /* vim: set expandtab: */
  45. ?>