1
|
<?php
|
2
|
|
3
|
// $Id: browse.php 1082 2009-07-18 18:01:34Z Ruebenwurzel $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2009, Ryan Djurovich
|
9
|
|
10
|
Website Baker is free software; you can redistribute it and/or modify
|
11
|
it under the terms of the GNU General Public License as published by
|
12
|
the Free Software Foundation; either version 2 of the License, or
|
13
|
(at your option) any later version.
|
14
|
|
15
|
Website Baker is distributed in the hope that it will be useful,
|
16
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
GNU General Public License for more details.
|
19
|
|
20
|
You should have received a copy of the GNU General Public License
|
21
|
along with Website Baker; if not, write to the Free Software
|
22
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
|
24
|
*/
|
25
|
|
26
|
// Create admin object
|
27
|
require('../../config.php');
|
28
|
require_once(WB_PATH.'/framework/class.admin.php');
|
29
|
$admin = new admin('Media', 'media', false);
|
30
|
|
31
|
// Include the WB functions file
|
32
|
require_once(WB_PATH.'/framework/functions.php');
|
33
|
include ('parameters.php');
|
34
|
|
35
|
// check if theme language file exists for the language set by the user (e.g. DE, EN)
|
36
|
if(!file_exists(THEME_PATH .'/languages/'.LANGUAGE .'.php')) {
|
37
|
// no theme language file exists for the language set by the user, include default theme language file EN.php
|
38
|
require_once(THEME_PATH .'/languages/EN.php');
|
39
|
} else {
|
40
|
// a theme language file exists for the language defined by the user, load it
|
41
|
require_once(THEME_PATH .'/languages/'.LANGUAGE .'.php');
|
42
|
}
|
43
|
|
44
|
// Byte convert for filesize
|
45
|
function byte_convert($bytes) {
|
46
|
$symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
|
47
|
$exp = 0;
|
48
|
$converted_value = 0;
|
49
|
if( $bytes > 0 ) {
|
50
|
$exp = floor( log($bytes)/log(1024) );
|
51
|
$converted_value = ( $bytes/pow(1024,floor($exp)) );
|
52
|
}
|
53
|
return sprintf( '%.2f '.$symbol[$exp], $converted_value );
|
54
|
}
|
55
|
|
56
|
// Get file extension
|
57
|
function get_filetype($fname) {
|
58
|
$pathinfo = pathinfo($fname);
|
59
|
$extension = strtolower($pathinfo['extension']);
|
60
|
return $extension;
|
61
|
}
|
62
|
|
63
|
// Get file extension for icons
|
64
|
function get_filetype_icon($fname) {
|
65
|
$pathinfo = pathinfo($fname);
|
66
|
$extension = strtolower($pathinfo['extension']);
|
67
|
if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
|
68
|
return $extension;
|
69
|
} else {
|
70
|
return 'unknown';
|
71
|
}
|
72
|
}
|
73
|
|
74
|
// Setup template object
|
75
|
$template = new Template(THEME_PATH.'/templates');
|
76
|
$template->set_file('page', 'media_browse.htt');
|
77
|
$template->set_block('page', 'main_block', 'main');
|
78
|
|
79
|
// Get the current dir
|
80
|
$directory = $admin->strip_slashes($admin->get_get('dir'));
|
81
|
if($directory == '/' OR $directory == '\\') {
|
82
|
$directory = '';
|
83
|
}
|
84
|
|
85
|
// Check to see if it contains ../
|
86
|
if(strstr($directory, '../')) {
|
87
|
$admin->print_header();
|
88
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
|
89
|
}
|
90
|
|
91
|
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
|
92
|
$admin->print_header();
|
93
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOES_NOT_EXIST']);
|
94
|
}
|
95
|
|
96
|
// Check to see if the user wanted to go up a directory into the parent folder
|
97
|
if($admin->get_get('up') == 1) {
|
98
|
$parent_directory = dirname($directory);
|
99
|
header("Location: browse.php?dir=$parent_directory");
|
100
|
exit(0);
|
101
|
}
|
102
|
|
103
|
if ($_SESSION['GROUP_ID'] != 1 && $pathsettings['global']['admin_only']) { // Only show admin the settings link
|
104
|
$template->set_var('DISPLAY_SETTINGS', 'hide');
|
105
|
}
|
106
|
|
107
|
// Workout the parent dir link
|
108
|
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&up=1';
|
109
|
// Workout if the up arrow should be shown
|
110
|
if($directory == '') {
|
111
|
$display_up_arrow = 'hide';
|
112
|
} else {
|
113
|
$display_up_arrow = '';
|
114
|
}
|
115
|
|
116
|
// Insert values
|
117
|
$template->set_var(array(
|
118
|
'THEME_URL' => THEME_URL,
|
119
|
'CURRENT_DIR' => $directory,
|
120
|
'PARENT_DIR_LINK' => $parent_dir_link,
|
121
|
'DISPLAY_UP_ARROW' => $display_up_arrow,
|
122
|
'INCLUDE_PATH' => WB_URL.'/include'
|
123
|
)
|
124
|
);
|
125
|
|
126
|
// Get home folder not to show
|
127
|
$home_folders = get_home_folders();
|
128
|
|
129
|
// Generate list
|
130
|
$template->set_block('main_block', 'list_block', 'list');
|
131
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
|
132
|
// Loop through the files and dirs an add to list
|
133
|
while(false !== ($file = readdir($handle))) {
|
134
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
135
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
136
|
if(!isset($home_folders[$directory.'/'.$file])) {
|
137
|
$DIR[] = $file;
|
138
|
}
|
139
|
} else {
|
140
|
$FILE[] = $file;
|
141
|
}
|
142
|
}
|
143
|
}
|
144
|
// Now parse these values to the template
|
145
|
$temp_id = 0;
|
146
|
$row_bg_color = 'FFF';
|
147
|
if(isset($DIR)) {
|
148
|
sort($DIR);
|
149
|
foreach($DIR AS $name) {
|
150
|
$link_name = str_replace(' ', '%20', $name);
|
151
|
$temp_id++;
|
152
|
$template->set_var(array(
|
153
|
'NAME' => $name,
|
154
|
'NAME_SLASHED' => addslashes($name),
|
155
|
'TEMP_ID' => $temp_id,
|
156
|
'LINK' => "browse.php?dir=$directory/$link_name",
|
157
|
'LINK_TARGET' => '',
|
158
|
'ROW_BG_COLOR' => $row_bg_color,
|
159
|
'FT_ICON' => THEME_URL.'/images/folder_16.png',
|
160
|
'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
|
161
|
'MOUSEOVER' => '',
|
162
|
'IMAGEDETAIL' => '',
|
163
|
'SIZE' => '',
|
164
|
'DATE' => '',
|
165
|
'PREVIEW' => ''
|
166
|
)
|
167
|
);
|
168
|
$template->parse('list', 'list_block', true);
|
169
|
// Code to alternate row colors
|
170
|
if($row_bg_color == 'FFF') {
|
171
|
$row_bg_color = 'ECF1F3';
|
172
|
} else {
|
173
|
$row_bg_color = 'FFF';
|
174
|
}
|
175
|
}
|
176
|
}
|
177
|
if(isset($FILE)) {
|
178
|
sort($FILE);
|
179
|
$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf');
|
180
|
foreach($FILE AS $name) {
|
181
|
$size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
|
182
|
$bytes = byte_convert($size);
|
183
|
$fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
|
184
|
$date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
|
185
|
$filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
|
186
|
$filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
|
187
|
|
188
|
if (in_array($filetype, $filepreview)) {
|
189
|
$preview = 'preview';
|
190
|
} else {
|
191
|
$preview = '';
|
192
|
}
|
193
|
$temp_id++;
|
194
|
$imgdetail = '';
|
195
|
$icon = THEME_URL.'/images/blank.gif';
|
196
|
$tooltip = '';
|
197
|
|
198
|
|
199
|
if (!$pathsettings['global']['show_thumbs']) {
|
200
|
$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
|
201
|
if ($info[0]) {
|
202
|
$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
|
203
|
$icon = 'thumb.php?t=1&img='.$directory.'/'.$name;
|
204
|
$tooltip = ShowTip('thumb.php?t=2&img='.$directory.'/'.$name);
|
205
|
}
|
206
|
}
|
207
|
$template->set_var(array(
|
208
|
'NAME' => $name,
|
209
|
'NAME_SLASHED' => addslashes($name),
|
210
|
'TEMP_ID' => $temp_id,
|
211
|
'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
|
212
|
'LINK_TARGET' => '_blank',
|
213
|
'ROW_BG_COLOR' => $row_bg_color,
|
214
|
'FT_ICON' => $icon,
|
215
|
'FILETYPE_ICON' => THEME_URL.'/images/files/'.$filetypeicon.'.png',
|
216
|
'MOUSEOVER' => $tooltip,
|
217
|
'IMAGEDETAIL' => $imgdetail,
|
218
|
'SIZE' => $bytes,
|
219
|
'DATE' => $date,
|
220
|
'PREVIEW' => $preview
|
221
|
)
|
222
|
);
|
223
|
$template->parse('list', 'list_block', true);
|
224
|
// Code to alternate row colors
|
225
|
if($row_bg_color == 'FFF') {
|
226
|
$row_bg_color = 'ECF1F3';
|
227
|
} else {
|
228
|
$row_bg_color = 'FFF';
|
229
|
}
|
230
|
}
|
231
|
}
|
232
|
}
|
233
|
|
234
|
// If no files are in the media folder say so
|
235
|
if($temp_id == 0) {
|
236
|
$template->set_var('DISPLAY_LIST_TABLE', 'hide');
|
237
|
} else {
|
238
|
$template->set_var('DISPLAY_NONE_FOUND', 'hide');
|
239
|
}
|
240
|
|
241
|
// Insert permissions values
|
242
|
if($admin->get_permission('media_rename') != true) {
|
243
|
$template->set_var('DISPLAY_RENAME', 'hide');
|
244
|
}
|
245
|
if($admin->get_permission('media_delete') != true) {
|
246
|
$template->set_var('DISPLAY_DELETE', 'hide');
|
247
|
}
|
248
|
|
249
|
// Insert language text and messages
|
250
|
$template->set_var(array(
|
251
|
'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
|
252
|
'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
|
253
|
'TEXT_RELOAD' => $TEXT['RELOAD'],
|
254
|
'TEXT_RENAME' => $TEXT['RENAME'],
|
255
|
'TEXT_DELETE' => $TEXT['DELETE'],
|
256
|
'TEXT_SIZE' => $TEXT['SIZE'],
|
257
|
'TEXT_DATE' => $TEXT['DATE'],
|
258
|
'TEXT_NAME' => $TEXT['NAME'],
|
259
|
'TEXT_TYPE' => $TEXT['TYPE'],
|
260
|
'TEXT_UP' => $TEXT['UP'],
|
261
|
'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
|
262
|
'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
|
263
|
'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
|
264
|
)
|
265
|
);
|
266
|
|
267
|
// Parse template object
|
268
|
$template->parse('main', 'main_block', false);
|
269
|
$template->pparse('output', 'page');
|
270
|
|
271
|
function ShowTip($name,$detail='') {
|
272
|
$parts = explode(".", $name);
|
273
|
$ext = strtolower(end($parts));
|
274
|
if (strpos('.gif.jpg.jpeg.png.bmp.',$ext) )
|
275
|
return 'onmouseover="overlib(\'<img src=\\\''.$name.'\\\' maxwidth=\\\'200\\\' maxheight=\\\'200\\\'>\',VAUTO, WIDTH)" onmouseout="nd()" ' ;
|
276
|
else
|
277
|
return '';
|
278
|
}
|
279
|
|
280
|
function fsize($size) {
|
281
|
if($size == 0) return("0 Bytes");
|
282
|
$filesizename = array(" bytes", " kB", " MB", " GB", " TB");
|
283
|
return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
|
284
|
}
|
285
|
?>
|