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