Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         media
6
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker 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: browse.php 1818 2012-11-15 22:54:21Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/media/browse.php $
14
 * @lastmodified    $Date: 2012-11-15 23:54:21 +0100 (Thu, 15 Nov 2012) $
15
 *
16
 */
17

    
18
// Create admin object
19
if(!defined('WB_URL'))
20
{
21
    $config_file = realpath('../../config.php');
22
    if(file_exists($config_file) && !defined('WB_URL'))
23
    {
24
    	require($config_file);
25
    }
26
}
27
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
28

    
29
$admin = new admin('Media', 'media', false);
30

    
31
$starttime = explode(" ", microtime());
32
$starttime = $starttime[0]+$starttime[1];
33

    
34
// Include the WB functions file
35
require_once(WB_PATH.'/framework/functions.php');
36
include ('parameters.php');
37

    
38
// check if theme language file exists for the language set by the user (e.g. DE, EN)
39
if(!file_exists(THEME_PATH .'/languages/'.LANGUAGE .'.php')) {
40
	// no theme language file exists for the language set by the user, include default theme language file EN.php
41
	require_once(THEME_PATH .'/languages/EN.php');
42
} else {
43
	// a theme language file exists for the language defined by the user, load it
44
	require_once(THEME_PATH .'/languages/'.LANGUAGE .'.php');
45
}
46

    
47
// Byte convert for filesize
48
function byte_convert($bytes) {
49
	$symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
50
	$exp = 0;
51
	$converted_value = 0;
52
	if( $bytes > 0 ) {
53
		$exp = floor( log($bytes)/log(1024) );
54
		$converted_value = ( $bytes/pow(1024,floor($exp)) );
55
	}
56
	return sprintf( '%.2f '.$symbol[$exp], $converted_value );
57
}
58

    
59
// Get file extension
60
function get_filetype($fname) {
61
	$pathinfo = pathinfo($fname);
62
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
63
	return $extension;
64
}
65

    
66
// Get file extension for icons
67
function get_filetype_icon($fname) {
68
	$pathinfo = pathinfo($fname);
69
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
70
	if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
71
		return $extension;
72
	} else {
73
		return 'blank_16';
74
	}
75
}
76

    
77
function ToolTip($name, $detail = '')
78
{
79
//    parse_str($name, $array);
80
//    $name = $array['img'];
81
    $parts = explode(".", $name);
82
    $ext = strtolower( end($parts));
83
    if (strpos('.gif.jpg.jpeg.png.bmp.', $ext))
84
	{
85
        $retVal = 'onmouseover="return overlib('.
86
            '\'<img src=\\\''.($name).'\\\''.
87
            'alt=\\\'\\\' '.
88
            'maxwidth=\\\'300\\\' '.
89
            'maxheight=\\\'300\\\' />\','.
90
//            '>\','.
91
//            'CAPTION,\''.basename($name).'\','.
92
            'FGCOLOR,\'#ffffff\','.
93
            'BGCOLOR,\'#557c9e\','.
94
            'BORDER,1,'.
95
            'FGCOLOR, \'#ffffff\','.
96
            'BGCOLOR,\'#557c9e\','.
97
            'CAPTIONSIZE,\'12px\','.
98
            'CLOSETEXT,\'X\','.
99
            'CLOSECOLOR,\'#ffffff\','.
100
            'CLOSESIZE,\'14px\','.
101
            'VAUTO,'.
102
            'HAUTO,'.
103
            ''.
104
//            'STICKY,'.
105
            'MOUSEOFF,'.
106
            'WRAP,'.
107
            'CELLPAD,5'.
108
            ''.
109
            ''.
110
            ''.
111
            ')" onmouseout="return nd()"';
112
        return $retVal;
113
//        return ('onmouseover="return overlib(\'<img src=\\\''.($name).'\\\' maxwidth=\\\'600\\\'  maxheight=\\\'600\\\'>\',BORDER,1,FGCOLOR, \'#ffffff\',VAUTO,WIDTH)" onmouseout="return nd()" ');
114
    } else {
115
        return '';
116
    }
117
}
118

    
119
function fsize($size) {
120
   if($size == 0) return("0 Bytes");
121
   $filesizename = array(" bytes", " kB", " MB", " GB", " TB");
122
   return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
123
}
124

    
125
// Setup template object, parse vars to it, then parse it
126
// Create new template object
127
$template = new Template(dirname($admin->correct_theme_source('media_browse.htt')));
128
$template->set_file('page', 'media_browse.htt');
129
$template->set_block('page', 'main_block', 'main');
130

    
131
// Get the current dir
132
$currentHome = $admin->get_home_folder();
133
// set directory if you call from menu
134
$directory =	(($currentHome) AND (!array_key_exists('dir',$_GET)))
135
				?
136
				$currentHome
137
				:
138
				$admin->strip_slashes($admin->get_get('dir')) ;
139

    
140
// check for correct directory
141
if ($currentHome && stripos(WB_PATH.MEDIA_DIRECTORY.$directory,WB_PATH.MEDIA_DIRECTORY.$currentHome)===false) {
142
	$directory = $currentHome;
143
}
144

    
145
if($directory == '/' OR $directory == '\\') {
146
	$directory = '';
147
}
148

    
149
$dir_backlink = 'browse.php?dir='.$directory;
150

    
151
// Check to see if it contains ../
152
if (!check_media_path($directory)) {
153
	// $admin->print_header();
154
	$admin->print_error($MESSAGE['MEDIA_DIR_DOT_DOT_SLASH']);
155
}
156

    
157
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
158
	// $admin->print_header();
159
	$admin->print_error($MESSAGE['MEDIA_DIR_DOES_NOT_EXIST']);
160
}
161

    
162
// Check to see if the user wanted to go up a directory into the parent folder
163
if($admin->get_get('up') == 1) {
164
	$parent_directory = dirname($directory);
165
	header("Location: browse.php?dir=$parent_directory");
166
	exit(0);
167
}
168

    
169
if ($_SESSION['GROUP_ID'] != 1 && (isset($pathsettings['global']['admin_only']) && $pathsettings['global']['admin_only']) ) { // Only show admin the settings link
170
	$template->set_var('DISPLAY_SETTINGS', 'hide');
171
}
172

    
173
// Workout the parent dir link
174
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&amp;up=1';
175
// Workout if the up arrow should be shown
176
if(($directory == '') or ($directory==$currentHome)) {
177
	$display_up_arrow = 'hide';
178
} else {
179
	$display_up_arrow = '';
180
}
181

    
182
// Insert values
183
$template->set_var(array(
184
					'THEME_URL' => THEME_URL,
185
					'WB_URL' => WB_URL,
186
					'CURRENT_DIR' => $directory,
187
					'PARENT_DIR_LINK' => $parent_dir_link,
188
					'DISPLAY_UP_ARROW' => $display_up_arrow,
189
					'INCLUDE_PATH' => WB_REL.'/include'
190
				)
191
			);
192

    
193
// Get home folder not to show
194
$home_folders = get_home_folders();
195

    
196
// Generate list
197
$template->set_block('main_block', 'list_block', 'list');
198

    
199
$usedFiles = array();
200
// require_once(ADMIN_PATH.'/media/dse.php');
201
// $filename =  $currentdir;
202
if(!empty($currentdir)) {
203
	$usedFiles = $Dse->getMatchesFromDir( $currentdir, DseTwo::RETURN_USED);
204
}
205

    
206
// Check for potentially malicious files
207
$forbidden_file_types  = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
208

    
209
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
210
	// Loop through the files and dirs an add to list
211
   while (false !== ($file = readdir($handle))) {
212
		$info = pathinfo($file);
213
		$ext = isset($info['extension']) ? $info['extension'] : '';
214
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
215
			if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
216
				if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
217
//					if( !isset($home_folders[$directory.'/'.$file]) ) {
218
                	if(!isset($home_folders[$directory.'/'.$file]) || $currentHome =='' )
219
                    {
220
						$DIR[] = $file;
221
					}
222
				} else {
223
					$FILE[] = $file;
224
				}
225
			}
226
		}
227
	}
228
	// Now parse these values to the template
229
	$temp_id = 0;
230
	$row_bg_color = 'FFF';
231
	if(isset($DIR)) {
232
		sort($DIR);
233
		foreach($DIR AS $name) {
234
			$link_name = str_replace(' ', '%20', $name);
235
			$temp_id++;
236
			$template->set_var(array(
237
								'NAME' => $name,
238
								'NAME_SLASHED' => addslashes($name),
239
								'TEMP_ID' => $admin->getIDKEY($temp_id),
240
								// 'TEMP_ID' => $temp_id,
241
								'LINK' => "browse.php?dir=$directory/$link_name",
242
								'LINK_TARGET' => '_self',
243
								'ROW_BG_COLOR' => $row_bg_color,
244
								'FT_ICON' => THEME_URL.'/images/folder_16.png',
245
								'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
246
								'MOUSEOVER' => '',
247
								'IMAGEDETAIL' => '',
248
								'SIZE' => '',
249
								'DATE' => '',
250
								'PREVIEW' => '',
251
								'IMAGE_TITLE' => $name,
252
								'IMAGE_EXIST' => 'blank_16.gif'
253
							)
254
						);
255
			$template->parse('list', 'list_block', true);
256
			// Code to alternate row colors
257
			if($row_bg_color == 'FFF') {
258
				$row_bg_color = 'ECF1F3';
259
			} else {
260
				$row_bg_color = 'FFF';
261
			}
262
		}
263
	}
264
	if(isset($FILE)) {
265
		sort($FILE);
266
		$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf','pdf','zip','gz','doc');
267
		foreach($FILE AS $name) {
268
			$size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
269
			$bytes = byte_convert($size);
270
			$fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
271
			$date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
272
			$filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
273
			$filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
274

    
275
			if (in_array($filetype, $filepreview)) {
276
				$preview = 'preview';
277
			} else {
278
				$preview = '';
279
			}
280
			$temp_id++;
281
			$imgdetail = '';
282
			// $icon = THEME_URL.'/images/blank_16.gif';
283
			$icon = '';
284
			$tooltip = '';
285

    
286
			if ( (isset($pathsettings['global']['show_thumbs']) && ($pathsettings['global']['show_thumbs']==false) ) ) {
287
				$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
288
				if ($info[0]) {
289
					$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
290
					$icon = 'thumbs.php?t=1&amp;img='.$directory.'/'.$name;
291
					$tooltip = ToolTip('thumbs.php?t=2&amp;img='.$directory.'/'.$name);
292
				}
293
			}
294

    
295
			$filetype_url = THEME_URL.'/images/files/'.$filetypeicon.'.png';
296
			$template->set_var(array(
297
								'NAME' => $name,
298
								'NAME_SLASHED' => addslashes($name),
299
								'TEMP_ID' => $admin->getIDKEY($temp_id),
300
								// 'TEMP_ID' => $temp_id,
301
								'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
302
								'LINK_TARGET' => '_blank',
303
								'ROW_BG_COLOR' => $row_bg_color,
304
								'FT_ICON' => empty($icon) ? $filetype_url : $icon,
305
								'FILETYPE_ICON' => $filetype_url,
306
								'MOUSEOVER' => $tooltip,
307
								'IMAGEDETAIL' => $imgdetail,
308
								'SIZE' => $bytes,
309
								'DATE' => $date,
310
								'PREVIEW' => $preview,
311
								'IMAGE_TITLE' => $name,
312
								'IMAGE_EXIST' =>  'blank_16.gif'
313
							)
314
						);
315
			$template->parse('list', 'list_block', true);
316
			// Code to alternate row colors
317
			if($row_bg_color == 'FFF') {
318
				$row_bg_color = 'ECF1F3';
319
			} else {
320
				$row_bg_color = 'FFF';
321
			}
322
		}
323
	}
324
}
325

    
326
// If no files are in the media folder say so
327
if($temp_id == 0) {
328
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
329
} else {
330
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
331
}
332

    
333
if($currentHome=='') {
334
// Insert permissions values
335
    if($admin->get_permission('media_rename') != true) {
336
    	$template->set_var('DISPLAY_RENAME', 'hide');
337
    }
338
    if($admin->get_permission('media_delete') != true) {
339
    	$template->set_var('DISPLAY_DELETE', 'hide');
340
    }
341
}
342

    
343
// Insert language text and messages
344
$template->set_var(array(
345
					'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
346
					'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
347
					'TEXT_RELOAD' => $TEXT['RELOAD'],
348
					'TEXT_RENAME' => $TEXT['RENAME'],
349
					'TEXT_DELETE' => $TEXT['DELETE'],
350
					'TEXT_SIZE' => $TEXT['SIZE'],
351
					'TEXT_DATE' => $TEXT['DATE'],
352
					'TEXT_NAME' => $TEXT['NAME'],
353
					'TEXT_TYPE' => $TEXT['TYPE'],
354
					'TEXT_UP' => $TEXT['UP'],
355
					'NONE_FOUND' => $MESSAGE['MEDIA_NONE_FOUND'],
356
					'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
357
					'CONFIRM_DELETE' => $MESSAGE['MEDIA_CONFIRM_DELETE']
358
				)
359
			);
360

    
361
// Parse template object
362
$template->parse('main', 'main_block', false);
363
$template->pparse('output', 'page');
364
/*
365
$endtime=explode(" ", microtime());
366
$endtime=$endtime[0]+$endtime[1];
367
$debugVMsg = '';
368
if($admin->ami_group_member('1') ) {
369
	$debugVMsg  = "<p>Mask loaded in ".round($endtime - $starttime,6)." Sec,&nbsp;&nbsp;";
370
	$debugVMsg .= "Memory in use ".number_format(memory_get_usage(true), 0, ',', '.')."&nbsp;Byte,&nbsp;&nbsp;";
371
	$debugVMsg .= sizeof(get_included_files())."&nbsp;included files</p>";
372
	// $debugVMsg = print_message($debugVMsg,'#','debug',-1,false);
373
	print $debugVMsg.'<br />';
374
 }
375
*/
(3-3/15)