1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category admin
|
5
|
* @package media
|
6
|
* @author Ryan Djurovich, WebsiteBaker Project
|
7
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: browse.php 1529 2011-11-25 05:03:32Z Luisehahne $
|
13
|
* @filesource $HeadURL: $
|
14
|
* @lastmodified $Date: $
|
15
|
*
|
16
|
*/
|
17
|
|
18
|
// Create admin object
|
19
|
require('../../config.php');
|
20
|
require_once(WB_PATH.'/framework/class.admin.php');
|
21
|
$admin = new admin('Media', 'media', false);
|
22
|
|
23
|
$starttime = explode(" ", microtime());
|
24
|
$starttime = $starttime[0]+$starttime[1];
|
25
|
|
26
|
// Include the WB functions file
|
27
|
require_once(WB_PATH.'/framework/functions.php');
|
28
|
include ('parameters.php');
|
29
|
|
30
|
// check if theme language file exists for the language set by the user (e.g. DE, EN)
|
31
|
if(!file_exists(THEME_PATH .'/languages/'.LANGUAGE .'.php')) {
|
32
|
// no theme language file exists for the language set by the user, include default theme language file EN.php
|
33
|
require_once(THEME_PATH .'/languages/EN.php');
|
34
|
} else {
|
35
|
// a theme language file exists for the language defined by the user, load it
|
36
|
require_once(THEME_PATH .'/languages/'.LANGUAGE .'.php');
|
37
|
}
|
38
|
|
39
|
// Byte convert for filesize
|
40
|
function byte_convert($bytes) {
|
41
|
$symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
|
42
|
$exp = 0;
|
43
|
$converted_value = 0;
|
44
|
if( $bytes > 0 ) {
|
45
|
$exp = floor( log($bytes)/log(1024) );
|
46
|
$converted_value = ( $bytes/pow(1024,floor($exp)) );
|
47
|
}
|
48
|
return sprintf( '%.2f '.$symbol[$exp], $converted_value );
|
49
|
}
|
50
|
|
51
|
// Get file extension
|
52
|
function get_filetype($fname) {
|
53
|
$pathinfo = pathinfo($fname);
|
54
|
$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
|
55
|
return $extension;
|
56
|
}
|
57
|
|
58
|
// Get file extension for icons
|
59
|
function get_filetype_icon($fname) {
|
60
|
$pathinfo = pathinfo($fname);
|
61
|
$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
|
62
|
if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
|
63
|
return $extension;
|
64
|
} else {
|
65
|
return 'blank_16';
|
66
|
}
|
67
|
}
|
68
|
|
69
|
function ShowTip($name,$detail='') {
|
70
|
$parts = explode(".", $name);
|
71
|
$ext = strtolower(end($parts));
|
72
|
if (strpos('.gif.jpg.jpeg.png.bmp.',$ext) )
|
73
|
return 'onmouseover="overlib(\'<img src=\\\''.$name.'\\\' maxwidth=\\\'200\\\' maxheight=\\\'200\\\'>\',VAUTO, WIDTH)" onmouseout="nd()" ' ;
|
74
|
else
|
75
|
return '';
|
76
|
}
|
77
|
|
78
|
function fsize($size) {
|
79
|
if($size == 0) return("0 Bytes");
|
80
|
$filesizename = array(" bytes", " kB", " MB", " GB", " TB");
|
81
|
return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
|
82
|
}
|
83
|
|
84
|
// Setup template object, parse vars to it, then parse it
|
85
|
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('media_browse.htt'));
|
86
|
// Create new template object
|
87
|
$template = new Template($ThemePath);
|
88
|
$template->set_file('page', 'media_browse.htt');
|
89
|
$template->set_block('page', 'main_block', 'main');
|
90
|
|
91
|
// Get the current dir
|
92
|
$currentHome = $admin->get_home_folder();
|
93
|
$directory = (($currentHome) AND (!array_key_exists('dir',$_GET)))
|
94
|
?
|
95
|
$currentHome
|
96
|
:
|
97
|
$admin->strip_slashes($admin->get_get('dir')) ;
|
98
|
|
99
|
if($directory == '/' OR $directory == '\\') {
|
100
|
$directory = '';
|
101
|
}
|
102
|
|
103
|
$dir_backlink = 'browse.php?dir='.$directory;
|
104
|
|
105
|
// Check to see if it contains ../
|
106
|
if (!check_media_path($directory)) {
|
107
|
// $admin->print_header();
|
108
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
|
109
|
}
|
110
|
|
111
|
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
|
112
|
// $admin->print_header();
|
113
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOES_NOT_EXIST']);
|
114
|
}
|
115
|
|
116
|
// Check to see if the user wanted to go up a directory into the parent folder
|
117
|
if($admin->get_get('up') == 1) {
|
118
|
$parent_directory = dirname($directory);
|
119
|
header("Location: browse.php?dir=$parent_directory");
|
120
|
exit(0);
|
121
|
}
|
122
|
|
123
|
if ($_SESSION['GROUP_ID'] != 1 && $pathsettings['global']['admin_only']) { // Only show admin the settings link
|
124
|
$template->set_var('DISPLAY_SETTINGS', 'hide');
|
125
|
}
|
126
|
|
127
|
// Workout the parent dir link
|
128
|
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&up=1';
|
129
|
// Workout if the up arrow should be shown
|
130
|
if(($directory == '') or ($directory==$currentHome)) {
|
131
|
$display_up_arrow = 'hide';
|
132
|
} else {
|
133
|
$display_up_arrow = '';
|
134
|
}
|
135
|
|
136
|
// Insert values
|
137
|
$template->set_var(array(
|
138
|
'THEME_URL' => THEME_URL,
|
139
|
// 'THEME_URL' => '',
|
140
|
'CURRENT_DIR' => $directory,
|
141
|
'PARENT_DIR_LINK' => $parent_dir_link,
|
142
|
'DISPLAY_UP_ARROW' => $display_up_arrow,
|
143
|
'INCLUDE_PATH' => WB_URL.'/include'
|
144
|
)
|
145
|
);
|
146
|
|
147
|
// Get home folder not to show
|
148
|
$home_folders = get_home_folders();
|
149
|
|
150
|
// Generate list
|
151
|
$template->set_block('main_block', 'list_block', 'list');
|
152
|
|
153
|
$usedFiles = array();
|
154
|
// require_once(ADMIN_PATH.'/media/dse.php');
|
155
|
// $filename = $currentdir;
|
156
|
if(!empty($currentdir)) {
|
157
|
$usedFiles = $Dse->getMatchesFromDir( $currentdir, DseTwo::RETURN_USED);
|
158
|
}
|
159
|
|
160
|
// Check for potentially malicious files
|
161
|
$forbidden_file_types = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
|
162
|
|
163
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
|
164
|
// Loop through the files and dirs an add to list
|
165
|
while (false !== ($file = readdir($handle))) {
|
166
|
$info = pathinfo($file);
|
167
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
168
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
169
|
if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
|
170
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
171
|
if(!isset($home_folders[$directory.'/'.$file])) {
|
172
|
$DIR[] = $file;
|
173
|
}
|
174
|
} else {
|
175
|
$FILE[] = $file;
|
176
|
}
|
177
|
}
|
178
|
}
|
179
|
}
|
180
|
// Now parse these values to the template
|
181
|
$temp_id = 0;
|
182
|
$row_bg_color = 'FFF';
|
183
|
if(isset($DIR)) {
|
184
|
sort($DIR);
|
185
|
foreach($DIR AS $name) {
|
186
|
$link_name = str_replace(' ', '%20', $name);
|
187
|
$temp_id++;
|
188
|
$template->set_var(array(
|
189
|
'NAME' => $name,
|
190
|
'NAME_SLASHED' => addslashes($name),
|
191
|
'TEMP_ID' => $admin->getIDKEY($temp_id),
|
192
|
// 'TEMP_ID' => $temp_id,
|
193
|
'LINK' => "browse.php?dir=$directory/$link_name",
|
194
|
'LINK_TARGET' => '_self',
|
195
|
'ROW_BG_COLOR' => $row_bg_color,
|
196
|
'FT_ICON' => THEME_URL.'/images/folder_16.png',
|
197
|
'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
|
198
|
'MOUSEOVER' => '',
|
199
|
'IMAGEDETAIL' => '',
|
200
|
'SIZE' => '',
|
201
|
'DATE' => '',
|
202
|
'PREVIEW' => '',
|
203
|
'IMAGE_TITLE' => $name,
|
204
|
'IMAGE_EXIST' => 'blank_16.gif'
|
205
|
)
|
206
|
);
|
207
|
$template->parse('list', 'list_block', true);
|
208
|
// Code to alternate row colors
|
209
|
if($row_bg_color == 'FFF') {
|
210
|
$row_bg_color = 'ECF1F3';
|
211
|
} else {
|
212
|
$row_bg_color = 'FFF';
|
213
|
}
|
214
|
}
|
215
|
}
|
216
|
if(isset($FILE)) {
|
217
|
sort($FILE);
|
218
|
$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf','pdf','zip','gz','doc');
|
219
|
foreach($FILE AS $name) {
|
220
|
$size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
|
221
|
$bytes = byte_convert($size);
|
222
|
$fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
|
223
|
$date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
|
224
|
$filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
|
225
|
$filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
|
226
|
|
227
|
if (in_array($filetype, $filepreview)) {
|
228
|
$preview = 'preview';
|
229
|
} else {
|
230
|
$preview = '';
|
231
|
}
|
232
|
$temp_id++;
|
233
|
$imgdetail = '';
|
234
|
// $icon = THEME_URL.'/images/blank_16.gif';
|
235
|
$icon = '';
|
236
|
$tooltip = '';
|
237
|
|
238
|
|
239
|
if (!$pathsettings['global']['show_thumbs']) {
|
240
|
$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
|
241
|
if ($info[0]) {
|
242
|
$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
|
243
|
$icon = 'thumb.php?t=1&img='.$directory.'/'.$name;
|
244
|
$tooltip = ShowTip('thumb.php?t=2&img='.$directory.'/'.$name);
|
245
|
}
|
246
|
}
|
247
|
|
248
|
$filetype_url = THEME_URL.'/images/files/'.$filetypeicon.'.png';
|
249
|
$template->set_var(array(
|
250
|
'NAME' => $name,
|
251
|
'NAME_SLASHED' => addslashes($name),
|
252
|
'TEMP_ID' => $admin->getIDKEY($temp_id),
|
253
|
// 'TEMP_ID' => $temp_id,
|
254
|
'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
|
255
|
'LINK_TARGET' => '_blank',
|
256
|
'ROW_BG_COLOR' => $row_bg_color,
|
257
|
'FT_ICON' => empty($icon) ? $filetype_url : $icon,
|
258
|
'FILETYPE_ICON' => $filetype_url,
|
259
|
'MOUSEOVER' => $tooltip,
|
260
|
'IMAGEDETAIL' => $imgdetail,
|
261
|
'SIZE' => $bytes,
|
262
|
'DATE' => $date,
|
263
|
'PREVIEW' => $preview,
|
264
|
'IMAGE_TITLE' => $name,
|
265
|
'IMAGE_EXIST' => 'blank_16.gif'
|
266
|
)
|
267
|
);
|
268
|
$template->parse('list', 'list_block', true);
|
269
|
// Code to alternate row colors
|
270
|
if($row_bg_color == 'FFF') {
|
271
|
$row_bg_color = 'ECF1F3';
|
272
|
} else {
|
273
|
$row_bg_color = 'FFF';
|
274
|
}
|
275
|
}
|
276
|
}
|
277
|
}
|
278
|
|
279
|
// If no files are in the media folder say so
|
280
|
if($temp_id == 0) {
|
281
|
$template->set_var('DISPLAY_LIST_TABLE', 'hide');
|
282
|
} else {
|
283
|
$template->set_var('DISPLAY_NONE_FOUND', 'hide');
|
284
|
}
|
285
|
|
286
|
// Insert permissions values
|
287
|
if($admin->get_permission('media_rename') != true) {
|
288
|
$template->set_var('DISPLAY_RENAME', 'hide');
|
289
|
}
|
290
|
if($admin->get_permission('media_delete') != true) {
|
291
|
$template->set_var('DISPLAY_DELETE', 'hide');
|
292
|
}
|
293
|
|
294
|
// Insert language text and messages
|
295
|
$template->set_var(array(
|
296
|
'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
|
297
|
'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
|
298
|
'TEXT_RELOAD' => $TEXT['RELOAD'],
|
299
|
'TEXT_RENAME' => $TEXT['RENAME'],
|
300
|
'TEXT_DELETE' => $TEXT['DELETE'],
|
301
|
'TEXT_SIZE' => $TEXT['SIZE'],
|
302
|
'TEXT_DATE' => $TEXT['DATE'],
|
303
|
'TEXT_NAME' => $TEXT['NAME'],
|
304
|
'TEXT_TYPE' => $TEXT['TYPE'],
|
305
|
'TEXT_UP' => $TEXT['UP'],
|
306
|
'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
|
307
|
'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
|
308
|
'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
|
309
|
)
|
310
|
);
|
311
|
|
312
|
// Parse template object
|
313
|
$template->parse('main', 'main_block', false);
|
314
|
$template->pparse('output', 'page');
|
315
|
/*
|
316
|
$endtime=explode(" ", microtime());
|
317
|
$endtime=$endtime[0]+$endtime[1];
|
318
|
$debugVMsg = '';
|
319
|
if($admin->ami_group_member('1') ) {
|
320
|
$debugVMsg = "<p>Mask loaded in ".round($endtime - $starttime,6)." Sec, ";
|
321
|
$debugVMsg .= "Memory in use ".number_format(memory_get_usage(true), 0, ',', '.')." Byte, ";
|
322
|
$debugVMsg .= sizeof(get_included_files())." included files</p>";
|
323
|
// $debugVMsg = print_message($debugVMsg,'#','debug',-1,false);
|
324
|
print $debugVMsg.'<br />';
|
325
|
}
|
326
|
*/
|