Project

General

Profile

1 238 stefan
<?php
2 1400 FrankH
/**
3
 *
4
 * @category        admin
5
 * @package         media
6 1818 Luisehahne
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1400 FrankH
 * @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 1818 Luisehahne
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15 1400 FrankH
 *
16
 */
17 238 stefan
18
// Create admin object
19 1818 Luisehahne
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 1797 Luisehahne
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
28 1818 Luisehahne
29 238 stefan
$admin = new admin('Media', 'media', false);
30
31 1457 Luisehahne
$starttime = explode(" ", microtime());
32
$starttime = $starttime[0]+$starttime[1];
33
34 238 stefan
// Include the WB functions file
35
require_once(WB_PATH.'/framework/functions.php');
36 1041 Ruebenwurz
include ('parameters.php');
37 238 stefan
38 1082 Ruebenwurz
// 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 1023 Ruebenwurz
// Byte convert for filesize
48
function byte_convert($bytes) {
49 1041 Ruebenwurz
	$symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
50 1035 Ruebenwurz
	$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 1023 Ruebenwurz
}
58
59
// Get file extension
60
function get_filetype($fname) {
61
	$pathinfo = pathinfo($fname);
62 1407 FrankH
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
63 1023 Ruebenwurz
	return $extension;
64
}
65
66
// Get file extension for icons
67
function get_filetype_icon($fname) {
68
	$pathinfo = pathinfo($fname);
69 1407 FrankH
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
70 1023 Ruebenwurz
	if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
71
		return $extension;
72
	} else {
73 1457 Luisehahne
		return 'blank_16';
74 1023 Ruebenwurz
	}
75
}
76
77 1797 Luisehahne
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 1799 Luisehahne
            'alt=\\\'\\\' '.
88 1797 Luisehahne
            'maxwidth=\\\'300\\\' '.
89 1799 Luisehahne
            'maxheight=\\\'300\\\' />\','.
90 1797 Luisehahne
//            '>\','.
91 1798 Luisehahne
//            'CAPTION,\''.basename($name).'\','.
92 1797 Luisehahne
            '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 1798 Luisehahne
//            'STICKY,'.
105 1797 Luisehahne
            '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 1457 Luisehahne
}
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 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
126
// Create new template object
127 1625 Luisehahne
$template = new Template(dirname($admin->correct_theme_source('media_browse.htt')));
128 944 Ruebenwurz
$template->set_file('page', 'media_browse.htt');
129 238 stefan
$template->set_block('page', 'main_block', 'main');
130
131
// Get the current dir
132 1087 Ruebenwurz
$currentHome = $admin->get_home_folder();
133 1818 Luisehahne
// set directory if you call from menu
134 1087 Ruebenwurz
$directory =	(($currentHome) AND (!array_key_exists('dir',$_GET)))
135 1457 Luisehahne
				?
136 1087 Ruebenwurz
				$currentHome
137
				:
138
				$admin->strip_slashes($admin->get_get('dir')) ;
139 1475 Luisehahne
140 1818 Luisehahne
// 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 327 stefan
if($directory == '/' OR $directory == '\\') {
146 238 stefan
	$directory = '';
147
}
148
149 1475 Luisehahne
$dir_backlink = 'browse.php?dir='.$directory;
150
151 238 stefan
// Check to see if it contains ../
152 1400 FrankH
if (!check_media_path($directory)) {
153 1425 Luisehahne
	// $admin->print_header();
154 1799 Luisehahne
	$admin->print_error($MESSAGE['MEDIA_DIR_DOT_DOT_SLASH']);
155 238 stefan
}
156
157 282 stefan
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
158 1425 Luisehahne
	// $admin->print_header();
159 1799 Luisehahne
	$admin->print_error($MESSAGE['MEDIA_DIR_DOES_NOT_EXIST']);
160 238 stefan
}
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 1427 Luisehahne
	header("Location: browse.php?dir=$parent_directory");
166 286 stefan
	exit(0);
167 238 stefan
}
168
169 1818 Luisehahne
if ($_SESSION['GROUP_ID'] != 1 && (isset($pathsettings['global']['admin_only']) && $pathsettings['global']['admin_only']) ) { // Only show admin the settings link
170 1041 Ruebenwurz
	$template->set_var('DISPLAY_SETTINGS', 'hide');
171
}
172
173 238 stefan
// Workout the parent dir link
174 1427 Luisehahne
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&amp;up=1';
175 238 stefan
// Workout if the up arrow should be shown
176 1087 Ruebenwurz
if(($directory == '') or ($directory==$currentHome)) {
177 238 stefan
	$display_up_arrow = 'hide';
178
} else {
179
	$display_up_arrow = '';
180
}
181
182
// Insert values
183
$template->set_var(array(
184 1457 Luisehahne
					'THEME_URL' => THEME_URL,
185 1729 Luisehahne
					'WB_URL' => WB_URL,
186 1457 Luisehahne
					'CURRENT_DIR' => $directory,
187
					'PARENT_DIR_LINK' => $parent_dir_link,
188
					'DISPLAY_UP_ARROW' => $display_up_arrow,
189 1715 Luisehahne
					'INCLUDE_PATH' => WB_REL.'/include'
190 1457 Luisehahne
				)
191
			);
192 238 stefan
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 1457 Luisehahne
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 1476 Luisehahne
// Check for potentially malicious files
207
$forbidden_file_types  = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
208 1468 Luisehahne
209 238 stefan
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
210
	// Loop through the files and dirs an add to list
211 1475 Luisehahne
   while (false !== ($file = readdir($handle))) {
212
		$info = pathinfo($file);
213
		$ext = isset($info['extension']) ? $info['extension'] : '';
214 238 stefan
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
215 1475 Luisehahne
			if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
216
				if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
217 1818 Luisehahne
//					if( !isset($home_folders[$directory.'/'.$file]) ) {
218
                	if(!isset($home_folders[$directory.'/'.$file]) || $currentHome =='' )
219
                    {
220 1475 Luisehahne
						$DIR[] = $file;
221
					}
222
				} else {
223 1468 Luisehahne
					$FILE[] = $file;
224
				}
225 238 stefan
			}
226
		}
227
	}
228
	// Now parse these values to the template
229
	$temp_id = 0;
230 686 doc
	$row_bg_color = 'FFF';
231 238 stefan
	if(isset($DIR)) {
232 384 Ruebenwurz
		sort($DIR);
233 238 stefan
		foreach($DIR AS $name) {
234
			$link_name = str_replace(' ', '%20', $name);
235
			$temp_id++;
236
			$template->set_var(array(
237 1457 Luisehahne
								'NAME' => $name,
238
								'NAME_SLASHED' => addslashes($name),
239
								'TEMP_ID' => $admin->getIDKEY($temp_id),
240 1475 Luisehahne
								// 'TEMP_ID' => $temp_id,
241 1457 Luisehahne
								'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 238 stefan
			$template->parse('list', 'list_block', true);
256
			// Code to alternate row colors
257 686 doc
			if($row_bg_color == 'FFF') {
258
				$row_bg_color = 'ECF1F3';
259 238 stefan
			} else {
260 686 doc
				$row_bg_color = 'FFF';
261 238 stefan
			}
262
		}
263
	}
264
	if(isset($FILE)) {
265 384 Ruebenwurz
		sort($FILE);
266 1457 Luisehahne
		$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf','pdf','zip','gz','doc');
267 238 stefan
		foreach($FILE AS $name) {
268 1023 Ruebenwurz
			$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 1427 Luisehahne
275 1023 Ruebenwurz
			if (in_array($filetype, $filepreview)) {
276
				$preview = 'preview';
277
			} else {
278
				$preview = '';
279
			}
280 238 stefan
			$temp_id++;
281 1035 Ruebenwurz
			$imgdetail = '';
282 1457 Luisehahne
			// $icon = THEME_URL.'/images/blank_16.gif';
283
			$icon = '';
284 1035 Ruebenwurz
			$tooltip = '';
285 1457 Luisehahne
286 1818 Luisehahne
			if ( (isset($pathsettings['global']['show_thumbs']) && ($pathsettings['global']['show_thumbs']==false) ) ) {
287 1035 Ruebenwurz
				$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
288
				if ($info[0]) {
289 1041 Ruebenwurz
					$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
290 1799 Luisehahne
					$icon = 'thumbs.php?t=1&amp;img='.$directory.'/'.$name;
291
					$tooltip = ToolTip('thumbs.php?t=2&amp;img='.$directory.'/'.$name);
292 1035 Ruebenwurz
				}
293
			}
294 1457 Luisehahne
295
			$filetype_url = THEME_URL.'/images/files/'.$filetypeicon.'.png';
296 238 stefan
			$template->set_var(array(
297 1457 Luisehahne
								'NAME' => $name,
298
								'NAME_SLASHED' => addslashes($name),
299
								'TEMP_ID' => $admin->getIDKEY($temp_id),
300 1475 Luisehahne
								// 'TEMP_ID' => $temp_id,
301 1457 Luisehahne
								'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 1460 Luisehahne
								'IMAGE_EXIST' =>  'blank_16.gif'
313 1457 Luisehahne
							)
314
						);
315 238 stefan
			$template->parse('list', 'list_block', true);
316
			// Code to alternate row colors
317 686 doc
			if($row_bg_color == 'FFF') {
318
				$row_bg_color = 'ECF1F3';
319 238 stefan
			} else {
320 686 doc
				$row_bg_color = 'FFF';
321 238 stefan
			}
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 1818 Luisehahne
if($currentHome=='') {
334 238 stefan
// Insert permissions values
335 1818 Luisehahne
    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 238 stefan
}
342
343
// Insert language text and messages
344
$template->set_var(array(
345 1457 Luisehahne
					'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 1799 Luisehahne
					'NONE_FOUND' => $MESSAGE['MEDIA_NONE_FOUND'],
356 1457 Luisehahne
					'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
357 1799 Luisehahne
					'CONFIRM_DELETE' => $MESSAGE['MEDIA_CONFIRM_DELETE']
358 1457 Luisehahne
				)
359
			);
360 238 stefan
361
// Parse template object
362
$template->parse('main', 'main_block', false);
363
$template->pparse('output', 'page');
364 1457 Luisehahne
/*
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 1715 Luisehahne
*/