Automatically exported from code.google.com/p/planningalerts
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

55 rindas
1.4 KiB

  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. ?>