-
Notifications
You must be signed in to change notification settings - Fork 19
/
clearctl.php
111 lines (90 loc) · 4.56 KB
/
clearctl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
// +--------------------------------------------------------------------------+
// | Geeklog 2.2 |
// +---------------------------------------------------------------------------+
// | clearctl.php |
// | |
// | Removed all cached templates |
// +--------------------------------------------------------------------------+
// | Copyright (C) 2008 by the following authors: |
// | |
// | Mark R. Evans mark AT glfusion DOT org |
// +--------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +--------------------------------------------------------------------------+
require_once '../lib-common.php';
$display = '';
if (!SEC_inGroup('Root') && !SEC_inGroup('Theme Admin')) {
$display .= COM_showMessageText($MESSAGE[29], $MESSAGE[30]);
$display = COM_createHTMLDocument($display, array('pagetitle' => $MESSAGE[30]));
COM_accessLog("User {$_USER['username']} tried to illegally access the clear cache.");
COM_output($display);
exit;
}
// Clean directory
function clean_directory($dir, $leave_dirs = array(), $leave_files = array()) {
foreach( glob("$dir/*") as $file ) {
if (is_dir($file)) {
if (!in_array(basename($file), $leave_dirs)) {
delete_files($file); // delete all sub directories and files in those directories
}
} elseif( !in_array(basename($file), $leave_files) ) {
unlink($file);
}
}
}
// Delete all files in a directory and any sub directory
function delete_files($dir) {
foreach(glob($dir . '/*') as $file) {
if (is_dir($file)) {
delete_files($file);
} else {
unlink($file);
}
}
rmdir($dir);
}
/*
* Main processing
*/
// Clearing Theme Template Cache
CTL_clearCache();
// Clearing Resource Cache (CSS, and Javascript concatenated and minified files)
Geeklog\Cache::clear();
// Clean out Data directory (includes things like temp uploaded plugin files, user batch files, etc...)
$leave_dirs = array('cache', 'layout_cache', 'layout_css');
$leave_files = array('cacert.pem', 'README');
clean_directory($_CONF['path_data'], $leave_dirs, $leave_files);
// File Manager Thumbnail Files
$leave_dirs = array();
$leave_files = array('index.html');
clean_directory($_CONF['path_images'] . '_thumbs/articles/', $leave_dirs, $leave_files);
$leave_dirs = array();
$leave_files = array('index.html');
clean_directory($_CONF['path_images'] . '_thumbs/userphotos/', $leave_dirs, $leave_files);
$leave_dirs = array();
$leave_files = array('index.html');
clean_directory($_CONF['path_images'] . '_thumbs/library/image/', $leave_dirs, $leave_files);
$leave_dirs = array('Image');
$leave_files = array();
clean_directory($_CONF['path_images'] . '_thumbs/library/', $leave_dirs, $leave_files);
$leave_dirs = array('articles', 'library', 'userphotos');
$leave_files = array();
clean_directory($_CONF['path_images'] . '_thumbs/', $leave_dirs, $leave_files);
// Allow Plugins to clear any cached items
PLG_clearCache();
COM_redirect($_CONF['site_admin_url'] . '/index.php?msg=500');