Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         media
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @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: browse.php 1799 2012-10-29 02:00:43Z Luisehahne $
13
 * @filesource		$HeadURL:  $
14
 * @lastmodified    $Date:  $
15
 *
16
 */
17

    
18
// Create admin object
19
require('../../config.php');
20
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
21
$admin = new admin('Media', 'media', false);
22

    
23
$starttime = explode(" ", microtime());
24
$starttime = $starttime[0]+$starttime[1];
25

    
26
// Include the WB functions file
27
require_once(WB_PATH.'/framework/functions.php');
28
include ('parameters.php');
29

    
30
// 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
// Byte convert for filesize
40
function byte_convert($bytes) {
41
	$symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
42
	$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
}
50

    
51
// Get file extension
52
function get_filetype($fname) {
53
	$pathinfo = pathinfo($fname);
54
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
55
	return $extension;
56
}
57

    
58
// Get file extension for icons
59
function get_filetype_icon($fname) {
60
	$pathinfo = pathinfo($fname);
61
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
62
	if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
63
		return $extension;
64
	} else {
65
		return 'blank_16';
66
	}
67
}
68

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

    
111
function fsize($size) {
112
   if($size == 0) return("0 Bytes");
113
   $filesizename = array(" bytes", " kB", " MB", " GB", " TB");
114
   return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
115
}
116

    
117
// Setup template object, parse vars to it, then parse it
118
// Create new template object
119
$template = new Template(dirname($admin->correct_theme_source('media_browse.htt')));
120
$template->set_file('page', 'media_browse.htt');
121
$template->set_block('page', 'main_block', 'main');
122

    
123
// Get the current dir
124
$currentHome = $admin->get_home_folder();
125
$directory =	(($currentHome) AND (!array_key_exists('dir',$_GET)))
126
				?
127
				$currentHome
128
				:
129
				$admin->strip_slashes($admin->get_get('dir')) ;
130

    
131
if($directory == '/' OR $directory == '\\') {
132
	$directory = '';
133
}
134

    
135
$dir_backlink = 'browse.php?dir='.$directory;
136

    
137
// Check to see if it contains ../
138
if (!check_media_path($directory)) {
139
	// $admin->print_header();
140
	$admin->print_error($MESSAGE['MEDIA_DIR_DOT_DOT_SLASH']);
141
}
142

    
143
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
144
	// $admin->print_header();
145
	$admin->print_error($MESSAGE['MEDIA_DIR_DOES_NOT_EXIST']);
146
}
147

    
148
// Check to see if the user wanted to go up a directory into the parent folder
149
if($admin->get_get('up') == 1) {
150
	$parent_directory = dirname($directory);
151
	header("Location: browse.php?dir=$parent_directory");
152
	exit(0);
153
}
154

    
155
if ($_SESSION['GROUP_ID'] != 1 && $pathsettings['global_admin_only']) { // Only show admin the settings link
156
	$template->set_var('DISPLAY_SETTINGS', 'hide');
157
}
158

    
159
// Workout the parent dir link
160
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&amp;up=1';
161
// Workout if the up arrow should be shown
162
if(($directory == '') or ($directory==$currentHome)) {
163
	$display_up_arrow = 'hide';
164
} else {
165
	$display_up_arrow = '';
166
}
167

    
168
// Insert values
169
$template->set_var(array(
170
					'THEME_URL' => THEME_URL,
171
					'WB_URL' => WB_URL,
172
					'CURRENT_DIR' => $directory,
173
					'PARENT_DIR_LINK' => $parent_dir_link,
174
					'DISPLAY_UP_ARROW' => $display_up_arrow,
175
					'INCLUDE_PATH' => WB_REL.'/include'
176
				)
177
			);
178

    
179
// Get home folder not to show
180
$home_folders = get_home_folders();
181

    
182
// Generate list
183
$template->set_block('main_block', 'list_block', 'list');
184

    
185
$usedFiles = array();
186
// require_once(ADMIN_PATH.'/media/dse.php');
187
// $filename =  $currentdir;
188
if(!empty($currentdir)) {
189
	$usedFiles = $Dse->getMatchesFromDir( $currentdir, DseTwo::RETURN_USED);
190
}
191

    
192
// Check for potentially malicious files
193
$forbidden_file_types  = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
194

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

    
259
			if (in_array($filetype, $filepreview)) {
260
				$preview = 'preview';
261
			} else {
262
				$preview = '';
263
			}
264
			$temp_id++;
265
			$imgdetail = '';
266
			// $icon = THEME_URL.'/images/blank_16.gif';
267
			$icon = '';
268
			$tooltip = '';
269

    
270

    
271
			if (!$pathsettings['global_show_thumbs']) {
272
				$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
273
				if ($info[0]) {
274
					$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
275
					$icon = 'thumbs.php?t=1&amp;img='.$directory.'/'.$name;
276
					$tooltip = ToolTip('thumbs.php?t=2&amp;img='.$directory.'/'.$name);
277
				}
278
			}
279

    
280
			$filetype_url = THEME_URL.'/images/files/'.$filetypeicon.'.png';
281
			$template->set_var(array(
282
								'NAME' => $name,
283
								'NAME_SLASHED' => addslashes($name),
284
								'TEMP_ID' => $admin->getIDKEY($temp_id),
285
								// 'TEMP_ID' => $temp_id,
286
								'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
287
								'LINK_TARGET' => '_blank',
288
								'ROW_BG_COLOR' => $row_bg_color,
289
								'FT_ICON' => empty($icon) ? $filetype_url : $icon,
290
								'FILETYPE_ICON' => $filetype_url,
291
								'MOUSEOVER' => $tooltip,
292
								'IMAGEDETAIL' => $imgdetail,
293
								'SIZE' => $bytes,
294
								'DATE' => $date,
295
								'PREVIEW' => $preview,
296
								'IMAGE_TITLE' => $name,
297
								'IMAGE_EXIST' =>  'blank_16.gif'
298
							)
299
						);
300
			$template->parse('list', 'list_block', true);
301
			// Code to alternate row colors
302
			if($row_bg_color == 'FFF') {
303
				$row_bg_color = 'ECF1F3';
304
			} else {
305
				$row_bg_color = 'FFF';
306
			}
307
		}
308
	}
309
}
310

    
311
// If no files are in the media folder say so
312
if($temp_id == 0) {
313
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
314
} else {
315
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
316
}
317

    
318
// Insert permissions values
319
if($admin->get_permission('media_rename') != true) {
320
	$template->set_var('DISPLAY_RENAME', 'hide');
321
}
322
if($admin->get_permission('media_delete') != true) {
323
	$template->set_var('DISPLAY_DELETE', 'hide');
324
}
325

    
326
// Insert language text and messages
327
$template->set_var(array(
328
					'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
329
					'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
330
					'TEXT_RELOAD' => $TEXT['RELOAD'],
331
					'TEXT_RENAME' => $TEXT['RENAME'],
332
					'TEXT_DELETE' => $TEXT['DELETE'],
333
					'TEXT_SIZE' => $TEXT['SIZE'],
334
					'TEXT_DATE' => $TEXT['DATE'],
335
					'TEXT_NAME' => $TEXT['NAME'],
336
					'TEXT_TYPE' => $TEXT['TYPE'],
337
					'TEXT_UP' => $TEXT['UP'],
338
					'NONE_FOUND' => $MESSAGE['MEDIA_NONE_FOUND'],
339
					'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
340
					'CONFIRM_DELETE' => $MESSAGE['MEDIA_CONFIRM_DELETE']
341
				)
342
			);
343

    
344
// Parse template object
345
$template->parse('main', 'main_block', false);
346
$template->pparse('output', 'page');
347
/*
348
$endtime=explode(" ", microtime());
349
$endtime=$endtime[0]+$endtime[1];
350
$debugVMsg = '';
351
if($admin->ami_group_member('1') ) {
352
	$debugVMsg  = "<p>Mask loaded in ".round($endtime - $starttime,6)." Sec,&nbsp;&nbsp;";
353
	$debugVMsg .= "Memory in use ".number_format(memory_get_usage(true), 0, ',', '.')."&nbsp;Byte,&nbsp;&nbsp;";
354
	$debugVMsg .= sizeof(get_included_files())."&nbsp;included files</p>";
355
	// $debugVMsg = print_message($debugVMsg,'#','debug',-1,false);
356
	print $debugVMsg.'<br />';
357
 }
358
*/
(3-3/15)