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 2098 darkviper
//if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
28
$oTrans = Translate::getInstance();
29
$oTrans->enableAddon('admin\\media');
30 238 stefan
$admin = new admin('Media', 'media', false);
31
32 1457 Luisehahne
$starttime = explode(" ", microtime());
33
$starttime = $starttime[0]+$starttime[1];
34
35 238 stefan
// Include the WB functions file
36 1824 Luisehahne
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
37 1041 Ruebenwurz
include ('parameters.php');
38 238 stefan
39 2098 darkviper
//// check if theme language file exists for the language set by the user (e.g. DE, EN)
40
//if(!file_exists(THEME_PATH .'/languages/'.LANGUAGE .'.php')) {
41
//	// no theme language file exists for the language set by the user, include default theme language file EN.php
42
//	require_once(THEME_PATH .'/languages/EN.php');
43
//} else {
44
//	// a theme language file exists for the language defined by the user, load it
45
//	require_once(THEME_PATH .'/languages/'.LANGUAGE .'.php');
46
//}
47 1082 Ruebenwurz
48 1023 Ruebenwurz
// Byte convert for filesize
49
function byte_convert($bytes) {
50 1041 Ruebenwurz
	$symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
51 1035 Ruebenwurz
	$exp = 0;
52
	$converted_value = 0;
53
	if( $bytes > 0 ) {
54
		$exp = floor( log($bytes)/log(1024) );
55
		$converted_value = ( $bytes/pow(1024,floor($exp)) );
56
	}
57
	return sprintf( '%.2f '.$symbol[$exp], $converted_value );
58 1023 Ruebenwurz
}
59
60
// Get file extension
61
function get_filetype($fname) {
62
	$pathinfo = pathinfo($fname);
63 1407 FrankH
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
64 1023 Ruebenwurz
	return $extension;
65
}
66
67
// Get file extension for icons
68
function get_filetype_icon($fname) {
69
	$pathinfo = pathinfo($fname);
70 1407 FrankH
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
71 1023 Ruebenwurz
	if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
72
		return $extension;
73
	} else {
74 1457 Luisehahne
		return 'blank_16';
75 1023 Ruebenwurz
	}
76
}
77
78 1797 Luisehahne
function ToolTip($name, $detail = '')
79
{
80
//    parse_str($name, $array);
81
//    $name = $array['img'];
82
    $parts = explode(".", $name);
83
    $ext = strtolower( end($parts));
84
    if (strpos('.gif.jpg.jpeg.png.bmp.', $ext))
85
	{
86
        $retVal = 'onmouseover="return overlib('.
87
            '\'<img src=\\\''.($name).'\\\''.
88 1799 Luisehahne
            'alt=\\\'\\\' '.
89 1797 Luisehahne
            'maxwidth=\\\'300\\\' '.
90 1799 Luisehahne
            'maxheight=\\\'300\\\' />\','.
91 1797 Luisehahne
//            '>\','.
92 1798 Luisehahne
//            'CAPTION,\''.basename($name).'\','.
93 1797 Luisehahne
            'FGCOLOR,\'#ffffff\','.
94
            'BGCOLOR,\'#557c9e\','.
95
            'BORDER,1,'.
96
            'FGCOLOR, \'#ffffff\','.
97
            'BGCOLOR,\'#557c9e\','.
98
            'CAPTIONSIZE,\'12px\','.
99
            'CLOSETEXT,\'X\','.
100
            'CLOSECOLOR,\'#ffffff\','.
101
            'CLOSESIZE,\'14px\','.
102
            'VAUTO,'.
103
            'HAUTO,'.
104
            ''.
105 1798 Luisehahne
//            'STICKY,'.
106 1797 Luisehahne
            'MOUSEOFF,'.
107
            'WRAP,'.
108
            'CELLPAD,5'.
109
            ''.
110
            ''.
111
            ''.
112
            ')" onmouseout="return nd()"';
113
        return $retVal;
114
//        return ('onmouseover="return overlib(\'<img src=\\\''.($name).'\\\' maxwidth=\\\'600\\\'  maxheight=\\\'600\\\'>\',BORDER,1,FGCOLOR, \'#ffffff\',VAUTO,WIDTH)" onmouseout="return nd()" ');
115
    } else {
116
        return '';
117
    }
118 1457 Luisehahne
}
119
120
function fsize($size) {
121
   if($size == 0) return("0 Bytes");
122
   $filesizename = array(" bytes", " kB", " MB", " GB", " TB");
123
   return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
124
}
125
126 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
127
// Create new template object
128 1625 Luisehahne
$template = new Template(dirname($admin->correct_theme_source('media_browse.htt')));
129 944 Ruebenwurz
$template->set_file('page', 'media_browse.htt');
130 238 stefan
$template->set_block('page', 'main_block', 'main');
131 2098 darkviper
$template->set_var($oTrans->getLangArray());
132 238 stefan
// Get the current dir
133 1824 Luisehahne
//$currentHome = $admin->get_home_folder();
134
$currentHome = (defined('HOME_FOLDERS') && HOME_FOLDERS) ? $admin->get_home_folder() : '';
135
136 1818 Luisehahne
// set directory if you call from menu
137 1087 Ruebenwurz
$directory =	(($currentHome) AND (!array_key_exists('dir',$_GET)))
138 1457 Luisehahne
				?
139 1087 Ruebenwurz
				$currentHome
140
				:
141
				$admin->strip_slashes($admin->get_get('dir')) ;
142 1475 Luisehahne
143 1818 Luisehahne
// check for correct directory
144
if ($currentHome && stripos(WB_PATH.MEDIA_DIRECTORY.$directory,WB_PATH.MEDIA_DIRECTORY.$currentHome)===false) {
145
	$directory = $currentHome;
146
}
147 1824 Luisehahne
if($directory == '/' OR $directory == '\\') {$directory = '';}
148 1818 Luisehahne
149 1824 Luisehahne
$sBackLink = WB_PATH.MEDIA_DIRECTORY.$directory;
150
if(!is_readable( $sBackLink )) {
151
$directory = dirname($directory);
152
// reload parent page to rebuild the dropdowns
153
echo "<script type=\"text/javascript\">
154
<!--
155
// Get the location object
156
var locationObj = document.location;
157
// Set the value of the location object
158
parent.document.location = 'index.php';
159
-->
160
</script>";
161 238 stefan
}
162
163 1475 Luisehahne
$dir_backlink = 'browse.php?dir='.$directory;
164
165 238 stefan
// Check to see if it contains ../
166 1400 FrankH
if (!check_media_path($directory)) {
167 1425 Luisehahne
	// $admin->print_header();
168 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_DOT_DOT_SLASH);
169 238 stefan
}
170
171 282 stefan
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
172 1425 Luisehahne
	// $admin->print_header();
173 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_DOES_NOT_EXIST);
174 238 stefan
}
175
176
// Check to see if the user wanted to go up a directory into the parent folder
177
if($admin->get_get('up') == 1) {
178
	$parent_directory = dirname($directory);
179 1427 Luisehahne
	header("Location: browse.php?dir=$parent_directory");
180 286 stefan
	exit(0);
181 238 stefan
}
182
183 1818 Luisehahne
if ($_SESSION['GROUP_ID'] != 1 && (isset($pathsettings['global']['admin_only']) && $pathsettings['global']['admin_only']) ) { // Only show admin the settings link
184 1041 Ruebenwurz
	$template->set_var('DISPLAY_SETTINGS', 'hide');
185
}
186
187 238 stefan
// Workout the parent dir link
188 1427 Luisehahne
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&amp;up=1';
189 238 stefan
// Workout if the up arrow should be shown
190 1087 Ruebenwurz
if(($directory == '') or ($directory==$currentHome)) {
191 238 stefan
	$display_up_arrow = 'hide';
192
} else {
193
	$display_up_arrow = '';
194
}
195
196
// Insert values
197
$template->set_var(array(
198 1457 Luisehahne
					'THEME_URL' => THEME_URL,
199 1729 Luisehahne
					'WB_URL' => WB_URL,
200 1457 Luisehahne
					'CURRENT_DIR' => $directory,
201
					'PARENT_DIR_LINK' => $parent_dir_link,
202
					'DISPLAY_UP_ARROW' => $display_up_arrow,
203 1715 Luisehahne
					'INCLUDE_PATH' => WB_REL.'/include'
204 1457 Luisehahne
				)
205
			);
206 238 stefan
207
// Get home folder not to show
208 1824 Luisehahne
//$home_folders = get_home_folders();
209
$home_folders = (defined('HOME_FOLDERS') && HOME_FOLDERS) ? get_home_folders() : array();
210 238 stefan
211
// Generate list
212
$template->set_block('main_block', 'list_block', 'list');
213 1457 Luisehahne
214
$usedFiles = array();
215
// require_once(ADMIN_PATH.'/media/dse.php');
216
// $filename =  $currentdir;
217
if(!empty($currentdir)) {
218
	$usedFiles = $Dse->getMatchesFromDir( $currentdir, DseTwo::RETURN_USED);
219
}
220
221 1476 Luisehahne
// Check for potentially malicious files
222
$forbidden_file_types  = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
223 1468 Luisehahne
224 238 stefan
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
225
	// Loop through the files and dirs an add to list
226 1475 Luisehahne
   while (false !== ($file = readdir($handle))) {
227
		$info = pathinfo($file);
228
		$ext = isset($info['extension']) ? $info['extension'] : '';
229 238 stefan
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
230 1475 Luisehahne
			if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
231
				if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
232 1818 Luisehahne
//					if( !isset($home_folders[$directory.'/'.$file]) ) {
233
                	if(!isset($home_folders[$directory.'/'.$file]) || $currentHome =='' )
234
                    {
235 1475 Luisehahne
						$DIR[] = $file;
236
					}
237
				} else {
238 1468 Luisehahne
					$FILE[] = $file;
239
				}
240 238 stefan
			}
241
		}
242
	}
243
	// Now parse these values to the template
244
	$temp_id = 0;
245 686 doc
	$row_bg_color = 'FFF';
246 238 stefan
	if(isset($DIR)) {
247 384 Ruebenwurz
		sort($DIR);
248 238 stefan
		foreach($DIR AS $name) {
249
			$link_name = str_replace(' ', '%20', $name);
250
			$temp_id++;
251
			$template->set_var(array(
252 1457 Luisehahne
								'NAME' => $name,
253
								'NAME_SLASHED' => addslashes($name),
254
								'TEMP_ID' => $admin->getIDKEY($temp_id),
255 1475 Luisehahne
								// 'TEMP_ID' => $temp_id,
256 1457 Luisehahne
								'LINK' => "browse.php?dir=$directory/$link_name",
257
								'LINK_TARGET' => '_self',
258
								'ROW_BG_COLOR' => $row_bg_color,
259
								'FT_ICON' => THEME_URL.'/images/folder_16.png',
260
								'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
261
								'MOUSEOVER' => '',
262
								'IMAGEDETAIL' => '',
263
								'SIZE' => '',
264
								'DATE' => '',
265
								'PREVIEW' => '',
266
								'IMAGE_TITLE' => $name,
267
								'IMAGE_EXIST' => 'blank_16.gif'
268
							)
269
						);
270 238 stefan
			$template->parse('list', 'list_block', true);
271
			// Code to alternate row colors
272 686 doc
			if($row_bg_color == 'FFF') {
273
				$row_bg_color = 'ECF1F3';
274 238 stefan
			} else {
275 686 doc
				$row_bg_color = 'FFF';
276 238 stefan
			}
277
		}
278
	}
279
	if(isset($FILE)) {
280 384 Ruebenwurz
		sort($FILE);
281 1457 Luisehahne
		$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf','pdf','zip','gz','doc');
282 238 stefan
		foreach($FILE AS $name) {
283 1023 Ruebenwurz
			$size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
284
			$bytes = byte_convert($size);
285
			$fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
286
			$date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
287
			$filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
288
			$filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
289 1427 Luisehahne
290 1023 Ruebenwurz
			if (in_array($filetype, $filepreview)) {
291
				$preview = 'preview';
292
			} else {
293
				$preview = '';
294
			}
295 238 stefan
			$temp_id++;
296 1035 Ruebenwurz
			$imgdetail = '';
297 1457 Luisehahne
			// $icon = THEME_URL.'/images/blank_16.gif';
298
			$icon = '';
299 1035 Ruebenwurz
			$tooltip = '';
300 1457 Luisehahne
301 1818 Luisehahne
			if ( (isset($pathsettings['global']['show_thumbs']) && ($pathsettings['global']['show_thumbs']==false) ) ) {
302 1035 Ruebenwurz
				$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
303
				if ($info[0]) {
304 1041 Ruebenwurz
					$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
305 1799 Luisehahne
					$icon = 'thumbs.php?t=1&amp;img='.$directory.'/'.$name;
306
					$tooltip = ToolTip('thumbs.php?t=2&amp;img='.$directory.'/'.$name);
307 1035 Ruebenwurz
				}
308
			}
309 1457 Luisehahne
310
			$filetype_url = THEME_URL.'/images/files/'.$filetypeicon.'.png';
311 238 stefan
			$template->set_var(array(
312 1457 Luisehahne
								'NAME' => $name,
313
								'NAME_SLASHED' => addslashes($name),
314
								'TEMP_ID' => $admin->getIDKEY($temp_id),
315 1475 Luisehahne
								// 'TEMP_ID' => $temp_id,
316 1457 Luisehahne
								'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
317
								'LINK_TARGET' => '_blank',
318
								'ROW_BG_COLOR' => $row_bg_color,
319
								'FT_ICON' => empty($icon) ? $filetype_url : $icon,
320
								'FILETYPE_ICON' => $filetype_url,
321
								'MOUSEOVER' => $tooltip,
322
								'IMAGEDETAIL' => $imgdetail,
323
								'SIZE' => $bytes,
324
								'DATE' => $date,
325
								'PREVIEW' => $preview,
326
								'IMAGE_TITLE' => $name,
327 1460 Luisehahne
								'IMAGE_EXIST' =>  'blank_16.gif'
328 1457 Luisehahne
							)
329
						);
330 238 stefan
			$template->parse('list', 'list_block', true);
331
			// Code to alternate row colors
332 686 doc
			if($row_bg_color == 'FFF') {
333
				$row_bg_color = 'ECF1F3';
334 238 stefan
			} else {
335 686 doc
				$row_bg_color = 'FFF';
336 238 stefan
			}
337
		}
338
	}
339
}
340
341
// If no files are in the media folder say so
342
if($temp_id == 0) {
343
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
344
} else {
345
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
346
}
347
348 1824 Luisehahne
//if($currentHome=='') {
349
if( !in_array($admin->get_username(), explode('/',$directory)) ) {
350 238 stefan
// Insert permissions values
351 1818 Luisehahne
    if($admin->get_permission('media_rename') != true) {
352
    	$template->set_var('DISPLAY_RENAME', 'hide');
353
    }
354
    if($admin->get_permission('media_delete') != true) {
355
    	$template->set_var('DISPLAY_DELETE', 'hide');
356
    }
357 238 stefan
}
358
359
// Insert language text and messages
360
$template->set_var(array(
361 1457 Luisehahne
					'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
362 2098 darkviper
					'NONE_FOUND' => $oTrans->MESSAGE_MEDIA_NONE_FOUND,
363
					'CHANGE_SETTINGS' => $oTrans->TEXT_MODIFY_SETTINGS,
364
					'CONFIRM_DELETE' => $oTrans->MESSAGE_MEDIA_CONFIRM_DELETE
365 1457 Luisehahne
				)
366
			);
367 238 stefan
368
// Parse template object
369
$template->parse('main', 'main_block', false);
370
$template->pparse('output', 'page');
371 1457 Luisehahne
/*
372
$endtime=explode(" ", microtime());
373
$endtime=$endtime[0]+$endtime[1];
374
$debugVMsg = '';
375
if($admin->ami_group_member('1') ) {
376
	$debugVMsg  = "<p>Mask loaded in ".round($endtime - $starttime,6)." Sec,&nbsp;&nbsp;";
377
	$debugVMsg .= "Memory in use ".number_format(memory_get_usage(true), 0, ',', '.')."&nbsp;Byte,&nbsp;&nbsp;";
378
	$debugVMsg .= sizeof(get_included_files())."&nbsp;included files</p>";
379
	// $debugVMsg = print_message($debugVMsg,'#','debug',-1,false);
380
	print $debugVMsg.'<br />';
381
 }
382 1715 Luisehahne
*/