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 |
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php'); |
36 |
smarty_core_rmdir($_params, $smarty); |
37 |
} |
38 |
else { |
39 |
$smarty->_unlink($params['dirname'] . DIRECTORY_SEPARATOR . $_entry, $params['exp_time']); |
40 |
} |
41 |
} |
42 |
} |
43 |
closedir($_handle); |
44 |
} |
45 |
|
46 |
if ($params['level']) { |
47 |
return @rmdir($params['dirname']); |
48 |
} |
49 |
return (bool)$_handle; |
50 |
|
51 |
} |
52 |
|
53 |
/* vim: set expandtab: */ |
54 |
|
55 |
?> |