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 |
328
|
stefan
|
$directory = $admin->strip_slashes($admin->get_get('dir'));
|
81 |
327
|
stefan
|
if($directory == '/' OR $directory == '\\') {
|
82 |
238
|
stefan
|
$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 |
282
|
stefan
|
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
|
92 |
238
|
stefan
|
$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 |
286
|
stefan
|
exit(0);
|
101 |
238
|
stefan
|
}
|
102 |
|
|
|
103 |
1041
|
Ruebenwurz
|
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 |
238
|
stefan
|
// 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 |
944
|
Ruebenwurz
|
'THEME_URL' => THEME_URL,
|
119 |
238
|
stefan
|
'CURRENT_DIR' => $directory,
|
120 |
|
|
'PARENT_DIR_LINK' => $parent_dir_link,
|
121 |
1023
|
Ruebenwurz
|
'DISPLAY_UP_ARROW' => $display_up_arrow,
|
122 |
|
|
'INCLUDE_PATH' => WB_URL.'/include'
|
123 |
238
|
stefan
|
)
|
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 |
1035
|
Ruebenwurz
|
while(false !== ($file = readdir($handle))) {
|
134 |
238
|
stefan
|
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 |
686
|
doc
|
$row_bg_color = 'FFF';
|
147 |
238
|
stefan
|
if(isset($DIR)) {
|
148 |
384
|
Ruebenwurz
|
sort($DIR);
|
149 |
238
|
stefan
|
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 |
1041
|
Ruebenwurz
|
'FT_ICON' => THEME_URL.'/images/folder_16.png',
|
160 |
1023
|
Ruebenwurz
|
'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
|
161 |
1035
|
Ruebenwurz
|
'MOUSEOVER' => '',
|
162 |
|
|
'IMAGEDETAIL' => '',
|
163 |
1023
|
Ruebenwurz
|
'SIZE' => '',
|
164 |
|
|
'DATE' => '',
|
165 |
|
|
'PREVIEW' => ''
|
166 |
238
|
stefan
|
)
|
167 |
|
|
);
|
168 |
|
|
$template->parse('list', 'list_block', true);
|
169 |
|
|
// Code to alternate row colors
|
170 |
686
|
doc
|
if($row_bg_color == 'FFF') {
|
171 |
|
|
$row_bg_color = 'ECF1F3';
|
172 |
238
|
stefan
|
} else {
|
173 |
686
|
doc
|
$row_bg_color = 'FFF';
|
174 |
238
|
stefan
|
}
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
if(isset($FILE)) {
|
178 |
384
|
Ruebenwurz
|
sort($FILE);
|
179 |
1023
|
Ruebenwurz
|
$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf');
|
180 |
238
|
stefan
|
foreach($FILE AS $name) {
|
181 |
1023
|
Ruebenwurz
|
$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 |
238
|
stefan
|
$temp_id++;
|
194 |
1035
|
Ruebenwurz
|
$imgdetail = '';
|
195 |
|
|
$icon = THEME_URL.'/images/blank.gif';
|
196 |
|
|
$tooltip = '';
|
197 |
1041
|
Ruebenwurz
|
|
198 |
|
|
|
199 |
1035
|
Ruebenwurz
|
if (!$pathsettings['global']['show_thumbs']) {
|
200 |
|
|
$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
|
201 |
|
|
if ($info[0]) {
|
202 |
1041
|
Ruebenwurz
|
$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
|
203 |
1035
|
Ruebenwurz
|
$icon = 'thumb.php?t=1&img='.$directory.'/'.$name;
|
204 |
1041
|
Ruebenwurz
|
$tooltip = ShowTip('thumb.php?t=2&img='.$directory.'/'.$name);
|
205 |
1035
|
Ruebenwurz
|
}
|
206 |
|
|
}
|
207 |
238
|
stefan
|
$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 |
1041
|
Ruebenwurz
|
'FT_ICON' => $icon,
|
215 |
1023
|
Ruebenwurz
|
'FILETYPE_ICON' => THEME_URL.'/images/files/'.$filetypeicon.'.png',
|
216 |
1035
|
Ruebenwurz
|
'MOUSEOVER' => $tooltip,
|
217 |
|
|
'IMAGEDETAIL' => $imgdetail,
|
218 |
1023
|
Ruebenwurz
|
'SIZE' => $bytes,
|
219 |
|
|
'DATE' => $date,
|
220 |
|
|
'PREVIEW' => $preview
|
221 |
238
|
stefan
|
)
|
222 |
|
|
);
|
223 |
|
|
$template->parse('list', 'list_block', true);
|
224 |
|
|
// Code to alternate row colors
|
225 |
686
|
doc
|
if($row_bg_color == 'FFF') {
|
226 |
|
|
$row_bg_color = 'ECF1F3';
|
227 |
238
|
stefan
|
} else {
|
228 |
686
|
doc
|
$row_bg_color = 'FFF';
|
229 |
238
|
stefan
|
}
|
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 |
1023
|
Ruebenwurz
|
'TEXT_SIZE' => $TEXT['SIZE'],
|
257 |
|
|
'TEXT_DATE' => $TEXT['DATE'],
|
258 |
|
|
'TEXT_NAME' => $TEXT['NAME'],
|
259 |
|
|
'TEXT_TYPE' => $TEXT['TYPE'],
|
260 |
238
|
stefan
|
'TEXT_UP' => $TEXT['UP'],
|
261 |
|
|
'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
|
262 |
1035
|
Ruebenwurz
|
'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
|
263 |
238
|
stefan
|
'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 |
1035
|
Ruebenwurz
|
function ShowTip($name,$detail='') {
|
272 |
1058
|
ruud
|
$parts = explode(".", $name);
|
273 |
|
|
$ext = strtolower(end($parts));
|
274 |
1035
|
Ruebenwurz
|
if (strpos('.gif.jpg.jpeg.png.bmp.',$ext) )
|
275 |
1041
|
Ruebenwurz
|
return 'onmouseover="overlib(\'<img src=\\\''.$name.'\\\' maxwidth=\\\'200\\\' maxheight=\\\'200\\\'>\',VAUTO, WIDTH)" onmouseout="nd()" ' ;
|
276 |
1035
|
Ruebenwurz
|
else
|
277 |
|
|
return '';
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
function fsize($size) {
|
281 |
|
|
if($size == 0) return("0 Bytes");
|
282 |
1041
|
Ruebenwurz
|
$filesizename = array(" bytes", " kB", " MB", " GB", " TB");
|
283 |
1035
|
Ruebenwurz
|
return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
|
284 |
|
|
}
|
285 |
239
|
stefan
|
?>
|