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