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