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