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 1824 2012-11-20 17:41:22Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/media/browse.php $
14
 * @lastmodified    $Date: 2012-11-20 18:41:22 +0100 (Tue, 20 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
if(!function_exists('directory_list')) { require(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
$currentHome = (defined('HOME_FOLDERS') && HOME_FOLDERS) ? $admin->get_home_folder() : '';
134

    
135
// set directory if you call from menu
136
$directory =	(($currentHome) AND (!array_key_exists('dir',$_GET)))
137
				?
138
				$currentHome
139
				:
140
				$admin->strip_slashes($admin->get_get('dir')) ;
141

    
142
// check for correct directory
143
if ($currentHome && stripos(WB_PATH.MEDIA_DIRECTORY.$directory,WB_PATH.MEDIA_DIRECTORY.$currentHome)===false) {
144
	$directory = $currentHome;
145
}
146
if($directory == '/' OR $directory == '\\') {$directory = '';}
147

    
148
$sBackLink = WB_PATH.MEDIA_DIRECTORY.$directory;
149
if(!is_readable( $sBackLink )) {
150
$directory = dirname($directory);
151
// reload parent page to rebuild the dropdowns
152
echo "<script type=\"text/javascript\">
153
<!--
154
// Get the location object
155
var locationObj = document.location;
156
// Set the value of the location object
157
parent.document.location = 'index.php';
158
-->
159
</script>";
160
}
161

    
162
$dir_backlink = 'browse.php?dir='.$directory;
163

    
164
// Check to see if it contains ../
165
if (!check_media_path($directory)) {
166
	// $admin->print_header();
167
	$admin->print_error($MESSAGE['MEDIA_DIR_DOT_DOT_SLASH']);
168
}
169

    
170
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
171
	// $admin->print_header();
172
	$admin->print_error($MESSAGE['MEDIA_DIR_DOES_NOT_EXIST']);
173
}
174

    
175
// Check to see if the user wanted to go up a directory into the parent folder
176
if($admin->get_get('up') == 1) {
177
	$parent_directory = dirname($directory);
178
	header("Location: browse.php?dir=$parent_directory");
179
	exit(0);
180
}
181

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

    
186
// Workout the parent dir link
187
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&amp;up=1';
188
// Workout if the up arrow should be shown
189
if(($directory == '') or ($directory==$currentHome)) {
190
	$display_up_arrow = 'hide';
191
} else {
192
	$display_up_arrow = '';
193
}
194

    
195
// Insert values
196
$template->set_var(array(
197
					'THEME_URL' => THEME_URL,
198
					'WB_URL' => WB_URL,
199
					'CURRENT_DIR' => $directory,
200
					'PARENT_DIR_LINK' => $parent_dir_link,
201
					'DISPLAY_UP_ARROW' => $display_up_arrow,
202
					'INCLUDE_PATH' => WB_REL.'/include'
203
				)
204
			);
205

    
206
// Get home folder not to show
207
//$home_folders = get_home_folders();
208
$home_folders = (defined('HOME_FOLDERS') && HOME_FOLDERS) ? get_home_folders() : array();
209

    
210
// Generate list
211
$template->set_block('main_block', 'list_block', 'list');
212

    
213
$usedFiles = array();
214
// require_once(ADMIN_PATH.'/media/dse.php');
215
// $filename =  $currentdir;
216
if(!empty($currentdir)) {
217
	$usedFiles = $Dse->getMatchesFromDir( $currentdir, DseTwo::RETURN_USED);
218
}
219

    
220
// Check for potentially malicious files
221
$forbidden_file_types  = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
222

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

    
289
			if (in_array($filetype, $filepreview)) {
290
				$preview = 'preview';
291
			} else {
292
				$preview = '';
293
			}
294
			$temp_id++;
295
			$imgdetail = '';
296
			// $icon = THEME_URL.'/images/blank_16.gif';
297
			$icon = '';
298
			$tooltip = '';
299

    
300
			if ( (isset($pathsettings['global']['show_thumbs']) && ($pathsettings['global']['show_thumbs']==false) ) ) {
301
				$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
302
				if ($info[0]) {
303
					$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
304
					$icon = 'thumbs.php?t=1&amp;img='.$directory.'/'.$name;
305
					$tooltip = ToolTip('thumbs.php?t=2&amp;img='.$directory.'/'.$name);
306
				}
307
			}
308

    
309
			$filetype_url = THEME_URL.'/images/files/'.$filetypeicon.'.png';
310
			$template->set_var(array(
311
								'NAME' => $name,
312
								'NAME_SLASHED' => addslashes($name),
313
								'TEMP_ID' => $admin->getIDKEY($temp_id),
314
								// 'TEMP_ID' => $temp_id,
315
								'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
316
								'LINK_TARGET' => '_blank',
317
								'ROW_BG_COLOR' => $row_bg_color,
318
								'FT_ICON' => empty($icon) ? $filetype_url : $icon,
319
								'FILETYPE_ICON' => $filetype_url,
320
								'MOUSEOVER' => $tooltip,
321
								'IMAGEDETAIL' => $imgdetail,
322
								'SIZE' => $bytes,
323
								'DATE' => $date,
324
								'PREVIEW' => $preview,
325
								'IMAGE_TITLE' => $name,
326
								'IMAGE_EXIST' =>  'blank_16.gif'
327
							)
328
						);
329
			$template->parse('list', 'list_block', true);
330
			// Code to alternate row colors
331
			if($row_bg_color == 'FFF') {
332
				$row_bg_color = 'ECF1F3';
333
			} else {
334
				$row_bg_color = 'FFF';
335
			}
336
		}
337
	}
338
}
339

    
340
// If no files are in the media folder say so
341
if($temp_id == 0) {
342
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
343
} else {
344
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
345
}
346

    
347
//if($currentHome=='') {
348
if( !in_array($admin->get_username(), explode('/',$directory)) ) {
349
// Insert permissions values
350
    if($admin->get_permission('media_rename') != true) {
351
    	$template->set_var('DISPLAY_RENAME', 'hide');
352
    }
353
    if($admin->get_permission('media_delete') != true) {
354
    	$template->set_var('DISPLAY_DELETE', 'hide');
355
    }
356
}
357

    
358
// Insert language text and messages
359
$template->set_var(array(
360
					'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
361
					'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
362
					'TEXT_RELOAD' => $TEXT['RELOAD'],
363
					'TEXT_RENAME' => $TEXT['RENAME'],
364
					'TEXT_DELETE' => $TEXT['DELETE'],
365
					'TEXT_SIZE' => $TEXT['SIZE'],
366
					'TEXT_DATE' => $TEXT['DATE'],
367
					'TEXT_NAME' => $TEXT['NAME'],
368
					'TEXT_TYPE' => $TEXT['TYPE'],
369
					'TEXT_UP' => $TEXT['UP'],
370
					'NONE_FOUND' => $MESSAGE['MEDIA_NONE_FOUND'],
371
					'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
372
					'CONFIRM_DELETE' => $MESSAGE['MEDIA_CONFIRM_DELETE']
373
				)
374
			);
375

    
376
// Parse template object
377
$template->parse('main', 'main_block', false);
378
$template->pparse('output', 'page');
379
/*
380
$endtime=explode(" ", microtime());
381
$endtime=$endtime[0]+$endtime[1];
382
$debugVMsg = '';
383
if($admin->ami_group_member('1') ) {
384
	$debugVMsg  = "<p>Mask loaded in ".round($endtime - $starttime,6)." Sec,&nbsp;&nbsp;";
385
	$debugVMsg .= "Memory in use ".number_format(memory_get_usage(true), 0, ',', '.')."&nbsp;Byte,&nbsp;&nbsp;";
386
	$debugVMsg .= sizeof(get_included_files())."&nbsp;included files</p>";
387
	// $debugVMsg = print_message($debugVMsg,'#','debug',-1,false);
388
	print $debugVMsg.'<br />';
389
 }
390
*/
(3-3/14)