Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
304 | alex-w | 1 | <?php |
2 | |||
3 | /** |
||
4 | * Smarty method Clear_Compiled_Tpl |
||
5 | * |
||
6 | * Deletes compiled template files |
||
7 | * |
||
8 | * @package Smarty |
||
9 | * @subpackage SmartyMethod |
||
10 | * @author Uwe Tews |
||
11 | */ |
||
12 | |||
13 | /** |
||
14 | * Delete compiled template file |
||
15 | * |
||
16 | * @param string $resource_name template name |
||
17 | * @param string $compile_id compile id |
||
18 | * @param integer $exp_time expiration time |
||
19 | * @return integer number of template files deleted |
||
20 | */ |
||
21 | function clear_compiled_tpl($smarty, $resource_name = null, $compile_id = null, $exp_time = null) |
||
22 | { |
||
23 | $_dir_sep = $smarty->use_sub_dirs ? DS : '^'; |
||
24 | if (isset($resource_name)) { |
||
25 | $_resource_part_1 = $resource_name . $smarty->php_ext; |
||
26 | $_resource_part_2 = $resource_name . '.cache' . $smarty->php_ext; |
||
27 | } else { |
||
28 | $_resource_part = ''; |
||
29 | } |
||
30 | $_dir = $smarty->compile_dir; |
||
31 | if ($smarty->use_sub_dirs && isset($compile_id)) { |
||
32 | $_dir .= $compile_id . $_dir_sep; |
||
33 | } |
||
34 | if (isset($compile_id)) { |
||
35 | $_compile_id_part = $smarty->compile_dir . $compile_id . $_dir_sep; |
||
36 | } |
||
37 | $_count = 0; |
||
38 | $_compileDirs = new RecursiveDirectoryIterator($_dir); |
||
39 | $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST); |
||
40 | foreach ($_compile as $_file) { |
||
41 | if (strpos($_file, '.svn') !== false) continue; |
||
42 | if ($_file->isDir()) { |
||
43 | if (!$_compile->isDot()) { |
||
44 | // delete folder if empty |
||
45 | @rmdir($_file->getPathname()); |
||
46 | } |
||
47 | } else { |
||
48 | if ((!isset($compile_id) || substr_compare((string)$_file, $_compile_id_part, 0, strlen($_compile_id_part)) == 0) && |
||
49 | (!isset($resource_name) || substr_compare((string)$_file, $_resource_part_1, - strlen($_resource_part_1), strlen($_resource_part_1)) == 0 || |
||
50 | substr_compare((string)$_file, $_resource_part_2, - strlen($_resource_part_2), strlen($_resource_part_2)) == 0)) { |
||
51 | if (isset($exp_time)) { |
||
52 | if (time() - @filemtime($_file) >= $exp_time) { |
||
53 | $_count += unlink((string) $_file) ? 1 : 0; |
||
54 | } |
||
55 | } else { |
||
56 | $_count += unlink((string) $_file) ? 1 : 0; |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | return $_count; |
||
62 | } |
||
63 | |||
64 | ?> |