605
|
1 |
<?php
|
|
2 |
|
|
3 |
/*
|
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
|
685
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
diff
changeset
|
5 |
* Version 1.1.5 (Caoineag alpha 5)
|
605
|
6 |
* Copyright (C) 2006-2008 Dan Fuhry
|
|
7 |
*
|
|
8 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
|
|
9 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
12 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
|
|
13 |
*/
|
|
14 |
|
|
15 |
// Cache manager - regenerate and clear various cached values
|
|
16 |
|
|
17 |
function page_Admin_CacheManager()
|
|
18 |
{
|
|
19 |
global $db, $session, $paths, $template, $plugins; // Common objects
|
|
20 |
global $lang;
|
613
|
21 |
global $cache;
|
605
|
22 |
if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
|
|
23 |
{
|
|
24 |
$login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
|
|
25 |
echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
|
|
26 |
echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
|
|
27 |
return;
|
|
28 |
}
|
|
29 |
|
613
|
30 |
// validation/actions
|
|
31 |
if ( isset($_POST['refresh']) || isset($_POST['clear']) )
|
|
32 |
{
|
|
33 |
$success = false;
|
|
34 |
|
|
35 |
$target = ( isset($_POST['refresh']) ) ? $_POST['refresh'] : $_POST['clear'];
|
|
36 |
$do_refresh = isset($_POST['refresh']);
|
|
37 |
switch ( $target )
|
|
38 |
{
|
|
39 |
case 'page':
|
|
40 |
$success = $cache->purge('page_meta');
|
|
41 |
if ( $do_refresh && $success )
|
|
42 |
$success = $paths->update_metadata_cache();
|
|
43 |
break;
|
|
44 |
case 'ranks':
|
|
45 |
$success = $cache->purge('ranks');
|
|
46 |
if ( $do_refresh && $success )
|
|
47 |
$success = generate_cache_userranks();
|
|
48 |
break;
|
|
49 |
case 'sidebar':
|
|
50 |
$success = $cache->purge('anon_sidebar');
|
|
51 |
break;
|
|
52 |
case 'plugins':
|
|
53 |
$success = $cache->purge('plugins');
|
|
54 |
if ( $do_refresh && $success )
|
|
55 |
$success = $plugins->generate_plugins_cache();
|
|
56 |
break;
|
|
57 |
case 'template':
|
|
58 |
if ( $dh = opendir(ENANO_ROOT . '/cache') )
|
|
59 |
{
|
|
60 |
while ( $file = @readdir($dh) )
|
|
61 |
{
|
|
62 |
$fullpath = ENANO_ROOT . "/cache/$file";
|
|
63 |
// we don't want to mess with directories
|
|
64 |
if ( !is_file($fullpath) )
|
|
65 |
continue;
|
|
66 |
|
|
67 |
if ( preg_match('/\.(?:tpl|css)\.php$/', $file) )
|
|
68 |
{
|
|
69 |
unlink($fullpath);
|
|
70 |
}
|
|
71 |
}
|
|
72 |
$success = true;
|
|
73 |
}
|
|
74 |
break;
|
|
75 |
case 'aes':
|
|
76 |
$success = @unlink(ENANO_ROOT . '/cache/aes_decrypt.php');
|
|
77 |
break;
|
|
78 |
case 'lang':
|
|
79 |
if ( $dh = opendir(ENANO_ROOT . '/cache') )
|
|
80 |
{
|
|
81 |
while ( $file = @readdir($dh) )
|
|
82 |
{
|
|
83 |
$fullpath = ENANO_ROOT . "/cache/$file";
|
|
84 |
// we don't want to mess with directories
|
|
85 |
if ( !is_file($fullpath) )
|
|
86 |
continue;
|
|
87 |
|
|
88 |
if ( preg_match('/^lang_json_(?:[a-f0-9]+?)\.php$/', $file) || preg_match('/^(?:cache_)?lang_(?:[0-9]+?)\.php$/', $file) )
|
|
89 |
unlink($fullpath);
|
|
90 |
}
|
|
91 |
$success = true;
|
|
92 |
}
|
|
93 |
if ( $do_refresh && $success )
|
|
94 |
{
|
|
95 |
// for each language in the database, call regen_caches()
|
|
96 |
$q = $db->sql_query('SELECT lang_id FROM ' . table_prefix . 'language;');
|
|
97 |
if ( !$q )
|
|
98 |
$db->_die();
|
|
99 |
while ( $row = $db->fetchrow($q) )
|
|
100 |
{
|
|
101 |
$lang_local = ( $row['lang_id'] == $lang->lang_id ) ? $lang : new Language($row['lang_id']);
|
|
102 |
$success = $lang_local->regen_caches();
|
|
103 |
if ( !$success )
|
|
104 |
break 2;
|
|
105 |
}
|
|
106 |
}
|
|
107 |
break;
|
|
108 |
case 'js':
|
|
109 |
if ( $dh = opendir(ENANO_ROOT . '/cache') )
|
|
110 |
{
|
|
111 |
while ( $file = @readdir($dh) )
|
|
112 |
{
|
|
113 |
$fullpath = ENANO_ROOT . "/cache/$file";
|
|
114 |
// we don't want to mess with directories
|
|
115 |
if ( !is_file($fullpath) )
|
|
116 |
continue;
|
|
117 |
|
|
118 |
// compressed javascript
|
|
119 |
if ( preg_match('/^jsres_(?:[A-z0-9_-]+)\.js\.json$/', $file) )
|
|
120 |
unlink($fullpath);
|
|
121 |
// tinymce stuff
|
|
122 |
else if ( preg_match('/^tiny_mce_(?:[a-f0-9]+)\.gz$/', $file) )
|
|
123 |
unlink($fullpath);
|
|
124 |
}
|
|
125 |
$success = true;
|
|
126 |
}
|
|
127 |
break;
|
|
128 |
case 'thumbs':
|
|
129 |
if ( $dh = opendir(ENANO_ROOT . '/cache') )
|
|
130 |
{
|
|
131 |
while ( $file = @readdir($dh) )
|
|
132 |
{
|
|
133 |
$fullpath = ENANO_ROOT . "/cache/$file";
|
|
134 |
// we don't want to mess with directories
|
|
135 |
if ( !is_file($fullpath) )
|
|
136 |
continue;
|
|
137 |
|
|
138 |
if ( preg_match('/^(?:[a-z0-9\._,-]+)-(?:[0-9]{10})-[0-9]+x[0-9]+\.([a-z0-9_-]+)$/i', $file) )
|
|
139 |
unlink($fullpath);
|
|
140 |
}
|
|
141 |
$success = true;
|
|
142 |
}
|
|
143 |
break;
|
|
144 |
case 'all':
|
|
145 |
$success = purge_all_caches();
|
|
146 |
if ( $do_refresh )
|
|
147 |
{
|
|
148 |
//
|
|
149 |
// refresh all static (non-incremental) caches
|
|
150 |
//
|
|
151 |
|
|
152 |
// pages
|
|
153 |
$success = $paths->update_metadata_cache();
|
|
154 |
if ( !$success )
|
|
155 |
break;
|
|
156 |
|
|
157 |
// user ranks
|
|
158 |
$success = generate_cache_userranks();
|
|
159 |
if ( !$success )
|
|
160 |
break;
|
|
161 |
|
|
162 |
// plugins
|
|
163 |
$success = $plugins->generate_plugins_cache();
|
|
164 |
if ( !$success )
|
|
165 |
break;
|
|
166 |
|
|
167 |
// languages
|
|
168 |
$q = $db->sql_query('SELECT lang_id FROM ' . table_prefix . 'language;');
|
|
169 |
if ( !$q )
|
|
170 |
$db->_die();
|
|
171 |
while ( $row = $db->fetchrow($q) )
|
|
172 |
{
|
|
173 |
$lang_local = ( $row['lang_id'] == $lang->lang_id ) ? $lang : new Language($row['lang_id']);
|
|
174 |
$success = $lang_local->regen_caches();
|
|
175 |
if ( !$success )
|
|
176 |
break 2;
|
|
177 |
}
|
|
178 |
}
|
|
179 |
break;
|
|
180 |
default:
|
|
181 |
$code = $plugins->setHook('acp_cache_manager_action');
|
|
182 |
foreach ( $code as $cmd )
|
|
183 |
{
|
|
184 |
eval($cmd);
|
|
185 |
}
|
|
186 |
break;
|
|
187 |
}
|
|
188 |
if ( $success )
|
|
189 |
{
|
|
190 |
echo '<div class="info-box">' . $lang->get('acpcm_msg_action_success') . '</div>';
|
|
191 |
}
|
|
192 |
else
|
|
193 |
{
|
|
194 |
echo '<div class="error-box">' . $lang->get('acpcm_err_action_failed') . '</div>';
|
|
195 |
}
|
|
196 |
}
|
|
197 |
else if ( isset($_POST['save']) )
|
|
198 |
{
|
|
199 |
$config_value = ( isset($_POST['cache_thumbs']) ) ? '1' : '0';
|
|
200 |
setConfig('cache_thumbs', $config_value);
|
|
201 |
echo '<div class="info-box">' . $lang->get('acpcm_msg_action_success') . '</div>';
|
|
202 |
}
|
|
203 |
|
605
|
204 |
echo '<h3><img alt=" " src="' . scriptPath . '/images/icons/applets/cachemanager.png" /> ' . $lang->get('acpcm_heading_main') . '</h3>';
|
|
205 |
echo '<p>' . $lang->get('acpcm_intro') . '</p>';
|
|
206 |
|
613
|
207 |
echo '<div class="warning-box">' . $lang->get('acpcm_msg_refresh_warning') . '</div>';
|
|
208 |
|
605
|
209 |
acp_start_form();
|
|
210 |
?>
|
|
211 |
<div class="tblholder">
|
|
212 |
<table border="0" cellspacing="1" cellpadding="4">
|
|
213 |
<!-- HEADER -->
|
|
214 |
<tr>
|
|
215 |
<th colspan="2">
|
|
216 |
<?php echo $lang->get('acpcm_table_header'); ?>
|
|
217 |
</th>
|
|
218 |
</tr>
|
|
219 |
|
|
220 |
<!-- ENABLE CACHE -->
|
|
221 |
<tr>
|
|
222 |
<td class="row1" colspan="2">
|
|
223 |
<label>
|
|
224 |
<input type="checkbox" name="cache_thumbs"<?php if ( getConfig('cache_thumbs') == '1' ) echo ' checked="checked"'; ?> />
|
|
225 |
<?php echo $lang->get('acpcm_lbl_enable_cache'); ?>
|
|
226 |
</label>
|
|
227 |
<br />
|
|
228 |
<small>
|
|
229 |
<?php echo $lang->get('acpcm_hint_enable_cache'); ?>
|
|
230 |
</small>
|
|
231 |
</td>
|
|
232 |
</tr>
|
|
233 |
|
|
234 |
<!-- CLEAR ALL -->
|
|
235 |
<tr>
|
613
|
236 |
<td class="row2" style="width: 120px; text-align: center;">
|
|
237 |
<button name="clear" value="all"><?php echo $lang->get('acpcm_btn_clear_all'); ?></button>
|
605
|
238 |
</td>
|
|
239 |
<td class="row2">
|
|
240 |
<?php echo $lang->get('acpcm_hint_clear_all'); ?>
|
|
241 |
</td>
|
|
242 |
</tr>
|
|
243 |
|
613
|
244 |
<?php
|
|
245 |
// if caching is disabled, might as well break off here
|
|
246 |
if ( getConfig('cache_thumbs') == '1' ):
|
|
247 |
?>
|
|
248 |
|
605
|
249 |
<!-- REFRESH ALL -->
|
|
250 |
<tr>
|
613
|
251 |
<td class="row1" style="text-align: center;">
|
|
252 |
<button name="refresh" value="all"><?php echo $lang->get('acpcm_btn_refresh_all'); ?></button>
|
605
|
253 |
</td>
|
|
254 |
<td class="row1">
|
|
255 |
<?php echo $lang->get('acpcm_hint_refresh_all'); ?>
|
|
256 |
</td>
|
|
257 |
</tr>
|
|
258 |
|
613
|
259 |
<!-- INDIVIDUAL CACHES -->
|
|
260 |
<tr>
|
|
261 |
<th class="subhead" colspan="2">
|
|
262 |
<?php echo $lang->get('acpcm_th_individual_caches'); ?>
|
|
263 |
</th>
|
|
264 |
</tr>
|
|
265 |
|
|
266 |
<?php
|
|
267 |
$class = 'row2';
|
|
268 |
$cache_list = array('page', 'ranks', 'sidebar', 'plugins', 'template', 'aes', 'lang', 'js', 'thumbs');
|
|
269 |
$code = $plugins->setHook('acp_cache_manager_list_caches');
|
|
270 |
foreach ( $code as $cmd )
|
|
271 |
{
|
|
272 |
eval($cmd);
|
|
273 |
}
|
|
274 |
foreach ( $cache_list as $target )
|
|
275 |
{
|
|
276 |
$class = ( $class == 'row1' ) ? 'row2' : 'row1';
|
|
277 |
?><tr>
|
|
278 |
<td class="<?php echo $class; ?>" style="text-align: center;">
|
|
279 |
<button name="refresh" value="<?php echo $target; ?>"<?php if ( in_array($target, array('template', 'sidebar', 'aes', 'js', 'thumbs')) ) echo ' disabled="disabled"'; ?>>
|
|
280 |
<?php echo $lang->get('acpcm_btn_refresh'); ?>
|
|
281 |
</button>
|
|
282 |
<button name="clear" value="<?php echo $target; ?>">
|
|
283 |
<?php echo $lang->get('acpcm_btn_clear'); ?>
|
|
284 |
</button>
|
|
285 |
</td>
|
|
286 |
<td class="<?php echo $class; ?>">
|
|
287 |
<b><?php echo $lang->get("acpcm_cache_{$target}_desc_title"); ?></b> –
|
|
288 |
<?php echo $lang->get("acpcm_cache_{$target}_desc_body"); ?>
|
|
289 |
</td>
|
|
290 |
</tr>
|
|
291 |
<?php
|
|
292 |
}
|
|
293 |
|
|
294 |
// getConfig('cache_thumbs') == '1'
|
|
295 |
endif;
|
|
296 |
?>
|
|
297 |
|
605
|
298 |
<!-- SAVE CHANGES -->
|
|
299 |
<tr>
|
|
300 |
<th colspan="2" class="subhead">
|
|
301 |
<input type="submit" name="save" value="<?php echo $lang->get('etc_save_changes'); ?>" style="font-weight: bold;" />
|
|
302 |
<input type="submit" name="cancel" value="<?php echo $lang->get('etc_cancel'); ?>" />
|
|
303 |
</th>
|
|
304 |
</tr>
|
|
305 |
</table>
|
|
306 |
</div>
|
|
307 |
<?php
|
|
308 |
echo '</form>';
|
|
309 |
}
|
|
310 |
|
|
311 |
?>
|