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