1 |
238
|
stefan
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
915
|
Ruebenwurz
|
Copyright (C) 2004-2009, Ryan Djurovich
|
9 |
238
|
stefan
|
|
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 |
1041
|
Ruebenwurz
|
include ('parameters.php');
|
34 |
238
|
stefan
|
|
35 |
1082
|
Ruebenwurz
|
// 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 |
1023
|
Ruebenwurz
|
// Byte convert for filesize
|
45 |
|
|
function byte_convert($bytes) {
|
46 |
1041
|
Ruebenwurz
|
$symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
|
47 |
1035
|
Ruebenwurz
|
$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 |
1023
|
Ruebenwurz
|
}
|
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 |
238
|
stefan
|
// Setup template object
|
75 |
944
|
Ruebenwurz
|
$template = new Template(THEME_PATH.'/templates');
|
76 |
|
|
$template->set_file('page', 'media_browse.htt');
|
77 |
238
|
stefan
|
$template->set_block('page', 'main_block', 'main');
|
78 |
|
|
|
79 |
|
|
// Get the current dir
|
80 |
1087
|
Ruebenwurz
|
$currentHome = $admin->get_home_folder();
|
81 |
|
|
$directory = (($currentHome) AND (!array_key_exists('dir',$_GET)))
|
82 |
|
|
?
|
83 |
|
|
$currentHome
|
84 |
|
|
:
|
85 |
|
|
$admin->strip_slashes($admin->get_get('dir')) ;
|
86 |
327
|
stefan
|
if($directory == '/' OR $directory == '\\') {
|
87 |
238
|
stefan
|
$directory = '';
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
// Check to see if it contains ../
|
91 |
|
|
if(strstr($directory, '../')) {
|
92 |
|
|
$admin->print_header();
|
93 |
|
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
|
94 |
|
|
}
|
95 |
|
|
|
96 |
282
|
stefan
|
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
|
97 |
238
|
stefan
|
$admin->print_header();
|
98 |
|
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOES_NOT_EXIST']);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
// Check to see if the user wanted to go up a directory into the parent folder
|
102 |
|
|
if($admin->get_get('up') == 1) {
|
103 |
|
|
$parent_directory = dirname($directory);
|
104 |
|
|
header("Location: browse.php?dir=$parent_directory");
|
105 |
286
|
stefan
|
exit(0);
|
106 |
238
|
stefan
|
}
|
107 |
|
|
|
108 |
1041
|
Ruebenwurz
|
if ($_SESSION['GROUP_ID'] != 1 && $pathsettings['global']['admin_only']) { // Only show admin the settings link
|
109 |
|
|
$template->set_var('DISPLAY_SETTINGS', 'hide');
|
110 |
|
|
}
|
111 |
|
|
|
112 |
238
|
stefan
|
// Workout the parent dir link
|
113 |
|
|
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&up=1';
|
114 |
|
|
// Workout if the up arrow should be shown
|
115 |
1087
|
Ruebenwurz
|
if(($directory == '') or ($directory==$currentHome)) {
|
116 |
238
|
stefan
|
$display_up_arrow = 'hide';
|
117 |
|
|
} else {
|
118 |
|
|
$display_up_arrow = '';
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
// Insert values
|
122 |
|
|
$template->set_var(array(
|
123 |
944
|
Ruebenwurz
|
'THEME_URL' => THEME_URL,
|
124 |
238
|
stefan
|
'CURRENT_DIR' => $directory,
|
125 |
|
|
'PARENT_DIR_LINK' => $parent_dir_link,
|
126 |
1023
|
Ruebenwurz
|
'DISPLAY_UP_ARROW' => $display_up_arrow,
|
127 |
|
|
'INCLUDE_PATH' => WB_URL.'/include'
|
128 |
238
|
stefan
|
)
|
129 |
|
|
);
|
130 |
|
|
|
131 |
|
|
// Get home folder not to show
|
132 |
|
|
$home_folders = get_home_folders();
|
133 |
|
|
|
134 |
|
|
// Generate list
|
135 |
|
|
$template->set_block('main_block', 'list_block', 'list');
|
136 |
|
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
|
137 |
|
|
// Loop through the files and dirs an add to list
|
138 |
1035
|
Ruebenwurz
|
while(false !== ($file = readdir($handle))) {
|
139 |
238
|
stefan
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
140 |
|
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
141 |
|
|
if(!isset($home_folders[$directory.'/'.$file])) {
|
142 |
|
|
$DIR[] = $file;
|
143 |
|
|
}
|
144 |
|
|
} else {
|
145 |
|
|
$FILE[] = $file;
|
146 |
|
|
}
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
// Now parse these values to the template
|
150 |
|
|
$temp_id = 0;
|
151 |
686
|
doc
|
$row_bg_color = 'FFF';
|
152 |
238
|
stefan
|
if(isset($DIR)) {
|
153 |
384
|
Ruebenwurz
|
sort($DIR);
|
154 |
238
|
stefan
|
foreach($DIR AS $name) {
|
155 |
|
|
$link_name = str_replace(' ', '%20', $name);
|
156 |
|
|
$temp_id++;
|
157 |
|
|
$template->set_var(array(
|
158 |
|
|
'NAME' => $name,
|
159 |
|
|
'NAME_SLASHED' => addslashes($name),
|
160 |
|
|
'TEMP_ID' => $temp_id,
|
161 |
|
|
'LINK' => "browse.php?dir=$directory/$link_name",
|
162 |
|
|
'LINK_TARGET' => '',
|
163 |
|
|
'ROW_BG_COLOR' => $row_bg_color,
|
164 |
1041
|
Ruebenwurz
|
'FT_ICON' => THEME_URL.'/images/folder_16.png',
|
165 |
1023
|
Ruebenwurz
|
'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
|
166 |
1035
|
Ruebenwurz
|
'MOUSEOVER' => '',
|
167 |
|
|
'IMAGEDETAIL' => '',
|
168 |
1023
|
Ruebenwurz
|
'SIZE' => '',
|
169 |
|
|
'DATE' => '',
|
170 |
|
|
'PREVIEW' => ''
|
171 |
238
|
stefan
|
)
|
172 |
|
|
);
|
173 |
|
|
$template->parse('list', 'list_block', true);
|
174 |
|
|
// Code to alternate row colors
|
175 |
686
|
doc
|
if($row_bg_color == 'FFF') {
|
176 |
|
|
$row_bg_color = 'ECF1F3';
|
177 |
238
|
stefan
|
} else {
|
178 |
686
|
doc
|
$row_bg_color = 'FFF';
|
179 |
238
|
stefan
|
}
|
180 |
|
|
}
|
181 |
|
|
}
|
182 |
|
|
if(isset($FILE)) {
|
183 |
384
|
Ruebenwurz
|
sort($FILE);
|
184 |
1023
|
Ruebenwurz
|
$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf');
|
185 |
238
|
stefan
|
foreach($FILE AS $name) {
|
186 |
1023
|
Ruebenwurz
|
$size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
|
187 |
|
|
$bytes = byte_convert($size);
|
188 |
|
|
$fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
|
189 |
|
|
$date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
|
190 |
|
|
$filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
|
191 |
|
|
$filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
|
192 |
|
|
|
193 |
|
|
if (in_array($filetype, $filepreview)) {
|
194 |
|
|
$preview = 'preview';
|
195 |
|
|
} else {
|
196 |
|
|
$preview = '';
|
197 |
|
|
}
|
198 |
238
|
stefan
|
$temp_id++;
|
199 |
1035
|
Ruebenwurz
|
$imgdetail = '';
|
200 |
|
|
$icon = THEME_URL.'/images/blank.gif';
|
201 |
|
|
$tooltip = '';
|
202 |
1041
|
Ruebenwurz
|
|
203 |
|
|
|
204 |
1035
|
Ruebenwurz
|
if (!$pathsettings['global']['show_thumbs']) {
|
205 |
|
|
$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
|
206 |
|
|
if ($info[0]) {
|
207 |
1041
|
Ruebenwurz
|
$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
|
208 |
1035
|
Ruebenwurz
|
$icon = 'thumb.php?t=1&img='.$directory.'/'.$name;
|
209 |
1041
|
Ruebenwurz
|
$tooltip = ShowTip('thumb.php?t=2&img='.$directory.'/'.$name);
|
210 |
1035
|
Ruebenwurz
|
}
|
211 |
|
|
}
|
212 |
238
|
stefan
|
$template->set_var(array(
|
213 |
|
|
'NAME' => $name,
|
214 |
|
|
'NAME_SLASHED' => addslashes($name),
|
215 |
|
|
'TEMP_ID' => $temp_id,
|
216 |
|
|
'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
|
217 |
|
|
'LINK_TARGET' => '_blank',
|
218 |
|
|
'ROW_BG_COLOR' => $row_bg_color,
|
219 |
1041
|
Ruebenwurz
|
'FT_ICON' => $icon,
|
220 |
1023
|
Ruebenwurz
|
'FILETYPE_ICON' => THEME_URL.'/images/files/'.$filetypeicon.'.png',
|
221 |
1035
|
Ruebenwurz
|
'MOUSEOVER' => $tooltip,
|
222 |
|
|
'IMAGEDETAIL' => $imgdetail,
|
223 |
1023
|
Ruebenwurz
|
'SIZE' => $bytes,
|
224 |
|
|
'DATE' => $date,
|
225 |
|
|
'PREVIEW' => $preview
|
226 |
238
|
stefan
|
)
|
227 |
|
|
);
|
228 |
|
|
$template->parse('list', 'list_block', true);
|
229 |
|
|
// Code to alternate row colors
|
230 |
686
|
doc
|
if($row_bg_color == 'FFF') {
|
231 |
|
|
$row_bg_color = 'ECF1F3';
|
232 |
238
|
stefan
|
} else {
|
233 |
686
|
doc
|
$row_bg_color = 'FFF';
|
234 |
238
|
stefan
|
}
|
235 |
|
|
}
|
236 |
|
|
}
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
// If no files are in the media folder say so
|
240 |
|
|
if($temp_id == 0) {
|
241 |
|
|
$template->set_var('DISPLAY_LIST_TABLE', 'hide');
|
242 |
|
|
} else {
|
243 |
|
|
$template->set_var('DISPLAY_NONE_FOUND', 'hide');
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
// Insert permissions values
|
247 |
|
|
if($admin->get_permission('media_rename') != true) {
|
248 |
|
|
$template->set_var('DISPLAY_RENAME', 'hide');
|
249 |
|
|
}
|
250 |
|
|
if($admin->get_permission('media_delete') != true) {
|
251 |
|
|
$template->set_var('DISPLAY_DELETE', 'hide');
|
252 |
|
|
}
|
253 |
|
|
|
254 |
|
|
// Insert language text and messages
|
255 |
|
|
$template->set_var(array(
|
256 |
|
|
'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
|
257 |
|
|
'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
|
258 |
|
|
'TEXT_RELOAD' => $TEXT['RELOAD'],
|
259 |
|
|
'TEXT_RENAME' => $TEXT['RENAME'],
|
260 |
|
|
'TEXT_DELETE' => $TEXT['DELETE'],
|
261 |
1023
|
Ruebenwurz
|
'TEXT_SIZE' => $TEXT['SIZE'],
|
262 |
|
|
'TEXT_DATE' => $TEXT['DATE'],
|
263 |
|
|
'TEXT_NAME' => $TEXT['NAME'],
|
264 |
|
|
'TEXT_TYPE' => $TEXT['TYPE'],
|
265 |
238
|
stefan
|
'TEXT_UP' => $TEXT['UP'],
|
266 |
|
|
'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
|
267 |
1035
|
Ruebenwurz
|
'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
|
268 |
238
|
stefan
|
'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
|
269 |
|
|
)
|
270 |
|
|
);
|
271 |
|
|
|
272 |
|
|
// Parse template object
|
273 |
|
|
$template->parse('main', 'main_block', false);
|
274 |
|
|
$template->pparse('output', 'page');
|
275 |
|
|
|
276 |
1035
|
Ruebenwurz
|
function ShowTip($name,$detail='') {
|
277 |
1058
|
ruud
|
$parts = explode(".", $name);
|
278 |
|
|
$ext = strtolower(end($parts));
|
279 |
1035
|
Ruebenwurz
|
if (strpos('.gif.jpg.jpeg.png.bmp.',$ext) )
|
280 |
1041
|
Ruebenwurz
|
return 'onmouseover="overlib(\'<img src=\\\''.$name.'\\\' maxwidth=\\\'200\\\' maxheight=\\\'200\\\'>\',VAUTO, WIDTH)" onmouseout="nd()" ' ;
|
281 |
1035
|
Ruebenwurz
|
else
|
282 |
|
|
return '';
|
283 |
|
|
}
|
284 |
|
|
|
285 |
|
|
function fsize($size) {
|
286 |
|
|
if($size == 0) return("0 Bytes");
|
287 |
1041
|
Ruebenwurz
|
$filesizename = array(" bytes", " kB", " MB", " GB", " TB");
|
288 |
1035
|
Ruebenwurz
|
return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
|
289 |
|
|
}
|
290 |
239
|
stefan
|
?>
|