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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
<?php
// $Header$
// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See below for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
namespace Bitweaver\Liberty;
require_once '../../kernel/includes/setup_inc.php';
use Bitweaver\KernelTools;
use Bitweaver\Nexus\Nexus;
$gBitSystem->verifyPermission( 'p_admin' );
$feedback = [];
$diskUsage = [
'templates_c' => [
'path' => TEMP_PKG_PATH.'templates_c',
'title' => KernelTools::tra( 'Templates' ),
],
'lang' => [
'path' => TEMP_PKG_PATH.'lang',
'title' => KernelTools::tra( 'Language Files' ),
],
'shoutbox' => [
'path' => TEMP_PKG_PATH.'shoutbox',
'title' => KernelTools::tra( 'Shoutbox' ),
],
'modules' => [
'path' => TEMP_PKG_PATH.'modules/cache',
'title' => KernelTools::tra( 'Modules' ),
'subdir' => $bitdomain,
],
'cache' => [
'path' => TEMP_PKG_PATH.'cache',
'title' => KernelTools::tra( 'System Cache' ),
'subdir' => $bitdomain,
],
'icons' => [
'path' => TEMP_PKG_PATH.'themes/biticon',
'title' => KernelTools::tra( 'Icons' ),
],
'liberty_cache' => [
'path' => TEMP_PKG_PATH.'liberty/cache',
'title' => KernelTools::tra( 'Liberty Cache' ),
],
'format_help' => [
'path' => TEMP_PKG_PATH.'liberty/help',
'title' => KernelTools::tra( 'Format Help' ),
],
'nexus' => [
'path' => TEMP_PKG_PATH.'nexus',
'title' => KernelTools::tra( 'Nexus Menus' ),
],
'rss' => [
'path' => TEMP_PKG_PATH.'rss',
'title' => KernelTools::tra( 'RSS Feed Cache' ),
],
'javascript' => [
'path' => STORAGE_PKG_PATH.'themes',
'title' => KernelTools::tra( 'Javascript and CSS files' ),
],
];
/* make sure we only display paths that exist
foreach( $diskUsage as $key => $item ) {
if( !is_dir( $item['path'] )) {
unset( $diskUsage[$key] );
}
}*/
if( !empty( $_GET['pruned'] )) {
$feedback['success'] = KernelTools::tra( 'The cache was successfully cleared.' );
}
if( !empty( $_GET['prune'] ) ) {
foreach( $diskUsage as $key => $item ) {
if( $_GET['prune'] == $key || $_GET['prune'] == 'all' ) {
$dir = $item['path'].( !empty( $item['subdir'] ) ? '/'.$item['subdir'] : '' );
$safeRoot = strpos( $item['path'], BIT_ROOT_PATH ) === 0 || strpos( $item['path'], TEMP_PKG_PATH ) === 0 || strpos( $item['path'], STORAGE_PKG_PATH ) === 0;
if( is_dir( $dir ) && $safeRoot ) {
if( KernelTools::unlink_r( $dir )) {
$reload = true;
} else {
$feedback['error'] = KernelTools::tra( 'There was a problem clearing out the cache.' );
}
}
}
}
// nexus needs to rewrite the cache right away to avoid errors
if( $gBitSystem->isPackageActive( 'nexus' ) && ( $_GET['prune'] == 'all' || $_GET['prune'] == 'nexus' )) {
$nexus = new Nexus();
$nexus->rewriteMenuCache();
}
// depending on what we've just nuked, we need to reload the page
if( !empty( $reload )) {
KernelTools::bit_redirect( KERNEL_PKG_URL."admin/admin_system.php?pruned=1" );
}
}
if( !empty( $_GET['compiletemplates'] ) ) {
cache_templates( BIT_ROOT_PATH, $gBitLanguage->getLanguage(), $_GET['compiletemplates'] );
}
foreach( $diskUsage as $key => $item ) {
$diskUsage[$key]['du'] = du( $item['path'] );
}
$gBitSmarty->assign( 'diskUsage', $diskUsage );
$languages = [];
$languages = $gBitLanguage->listLanguages();
ksort( $languages );
$templates = [];
$langdir = TEMP_PKG_PATH."templates_c/".$gBitSystem->getConfig('style')."/";
foreach( array_keys( $languages ) as $clang ) {
$templates[$clang] = is_dir( $langdir.$clang )
? [
'path' => TEMP_PKG_PATH."templates_c/".$gBitSystem->getConfig( 'style' )."/",
'title' => $languages[$clang]['full_name'],
'du' => du( $langdir.$clang ),
]
: [
'path' => TEMP_PKG_PATH."templates_c/".$gBitSystem->getConfig( 'style' )."/",
'title' => $languages[$clang]['full_name'],
'du' => [
"count" => 0,
"size" => 0,
],
];
}
$gBitSmarty->assign( 'templates', $templates );
$gBitSmarty->assign( 'feedback', $feedback );
$gBitSystem->display( 'bitpackage:kernel/admin_system.tpl', KernelTools::tra( "System Cache" ) , [ 'display_mode' => 'admin' ] );
// {{{ Functions
/**
* du
*
* @param string $pPath
* @access public
* @return array
*/
function du( $pPath ) {
$size = $count = 0;
if( !$pPath or !is_dir( $pPath ) ) {
$ret['size'] = $size;
$ret['count'] = $count;
return $ret;
}
$all = opendir( $pPath );
while( false !== ( $file = readdir( $all ) ) ) {
if( $file <> ".." and $file <> "." and $file <> "CVS" ) {
if( is_file( $pPath.'/'.$file ) ) {
$size += filesize( $pPath.'/'.$file );
$count++;
unset( $file );
} elseif( is_dir( $pPath.'/'.$file ) ) {
$du = du( $pPath.'/'.$file );
$size += $du['size'];
$count += $du['count'];
unset( $file );
}
}
}
closedir( $all );
unset( $all );
$ret['size'] = $size;
$ret['count'] = $count;
return $ret;
}
/**
* cache_templates
*
* @param string $pPath
* @param string $pOldLang
* @param string $pNewLang
* @access public
* @return bool true on success, false on failure - $this->mErrors will contain reason for failure
*/
function cache_templates( $pPath, $pOldLang, $pNewLang ) {
global $gBitLanguage, $gBitSmarty;
if( !$pPath or !is_dir( $pPath ) ) {
return false;
}
if( $dir = opendir( $pPath ) ) {
while( false !== ( $file = readdir( $dir ) ) ) {
$a = explode( ".", $file );
$ext = strtolower( end( $a ) );
if( substr( $file, 0, 1 ) == "." or $file == 'CVS' ) {
continue;
}
if( is_dir( $pPath."/".$file ) ) {
cache_templates( $pPath."/".$file, $pOldLang, $pNewLang );
/* } else {
if( $ext == "tpl" ) {
$file = str_replace( '//', '/', $pPath."/".$file );
$gBitLanguage->setLanguage( $pNewLang );
$gBitSmarty->verifyCompileDir();
$comppath = $gBitSmarty->_get_compile_path( $file );
$gBitLanguage->setLanguage( $pOldLang );
// ignore files in sudirectories of templates/ - will break stuff as in the case of phpbb
if( preg_match( "!/templates/\w*\.tpl!i", $file ) && !$gBitSmarty->_is_compiled( $file, $comppath ) ) {
$gBitSmarty->_compile_resource( $file, $comppath );
}
}
*/
}
}
closedir( $dir );
}
return true;
}
|