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 1798 2012-10-28 09:43:11Z 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
            'maxwidth=\\\'300\\\' '.
80
            'maxheight=\\\'300\\\'>\','.
81
//            '>\','.
82
//            'CAPTION,\''.basename($name).'\','.
83
            'FGCOLOR,\'#ffffff\','.
84
            'BGCOLOR,\'#557c9e\','.
85
            'BORDER,1,'.
86
            'FGCOLOR, \'#ffffff\','.
87
            'BGCOLOR,\'#557c9e\','.
88
            'CAPTIONSIZE,\'12px\','.
89
            'CLOSETEXT,\'X\','.
90
            'CLOSECOLOR,\'#ffffff\','.
91
            'CLOSESIZE,\'14px\','.
92
            'VAUTO,'.
93
            'HAUTO,'.
94
            ''.
95
//            'STICKY,'.
96
            'MOUSEOFF,'.
97
            'WRAP,'.
98
            'CELLPAD,5'.
99
            ''.
100
            ''.
101
            ''.
102
            ')" onmouseout="return nd()"';
103
        return $retVal;
104
//        return ('onmouseover="return overlib(\'<img src=\\\''.($name).'\\\' maxwidth=\\\'600\\\'  maxheight=\\\'600\\\'>\',BORDER,1,FGCOLOR, \'#ffffff\',VAUTO,WIDTH)" onmouseout="return nd()" ');
105
    } else {
106
        return '';
107
    }
108
}
109

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
269

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

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

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

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

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

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