init
[garradin.git] / include / libs / template_lite / internal / template.destroy_dir.php
1 <?php
2 /**
3 * Template Lite template_destroy_dir template internal module
4 *
5 * Type: template
6 * Name: template_destroy_dir
7 */
8
9 function template_destroy_dir($file, $id, $dir, &$object)
10 {
11 if ($file == null && $id == null)
12 {
13 if (is_dir($dir))
14 {
15 if($d = opendir($dir))
16 {
17 while(($f = readdir($d)) !== false)
18 {
19 if ($f != '.' && $f != '..')
20 {
21 template_rm_dir($dir.$f.DIRECTORY_SEPARATOR);
22 }
23 }
24 }
25 }
26 }
27 else
28 {
29 if ($id == null)
30 {
31 $object->template_dir = $object->_get_dir($object->template_dir);
32
33 $name = ($object->encode_file_name) ? md5($object->template_dir.$file).'.php' : str_replace(".", "_", str_replace("/", "_", $file)).'.php';
34 @unlink($dir.$name);
35 }
36 else
37 {
38 $_args = "";
39 foreach(explode('|', $id) as $value)
40 {
41 $_args .= $value.DIRECTORY_SEPARATOR;
42 }
43 template_rm_dir($dir.DIRECTORY_SEPARATOR.$_args);
44 }
45 }
46 }
47
48 function template_rm_dir($dir)
49 {
50 if (is_file(substr($dir, 0, -1)))
51 {
52 @unlink(substr($dir, 0, -1));
53 return;
54 }
55
56 if (!file_exists($dir))
57 return;
58
59 if ($d = opendir($dir))
60 {
61 while(($f = readdir($d)) !== false)
62 {
63 if ($f != '.' && $f != '..')
64 {
65 template_rm_dir($dir.$f.DIRECTORY_SEPARATOR);
66 }
67 }
68 @rmdir($dir.$f);
69 }
70 }
71
72 ?>