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 2098 2014-02-11 01:37:03Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/media/browse.php $
14
 * @lastmodified    $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
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
$oTrans = Translate::getInstance();
29
$oTrans->enableAddon('admin\\media');
30
$admin = new admin('Media', 'media', false);
31

    
32
$starttime = explode(" ", microtime());
33
$starttime = $starttime[0]+$starttime[1];
34

    
35
// Include the WB functions file
36
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
37
include ('parameters.php');
38

    
39
//// 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

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

    
60
// Get file extension
61
function get_filetype($fname) {
62
	$pathinfo = pathinfo($fname);
63
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
64
	return $extension;
65
}
66

    
67
// Get file extension for icons
68
function get_filetype_icon($fname) {
69
	$pathinfo = pathinfo($fname);
70
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
71
	if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
72
		return $extension;
73
	} else {
74
		return 'blank_16';
75
	}
76
}
77

    
78
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
            'alt=\\\'\\\' '.
89
            'maxwidth=\\\'300\\\' '.
90
            'maxheight=\\\'300\\\' />\','.
91
//            '>\','.
92
//            'CAPTION,\''.basename($name).'\','.
93
            '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
//            'STICKY,'.
106
            '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
}
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
// Setup template object, parse vars to it, then parse it
127
// Create new template object
128
$template = new Template(dirname($admin->correct_theme_source('media_browse.htt')));
129
$template->set_file('page', 'media_browse.htt');
130
$template->set_block('page', 'main_block', 'main');
131
$template->set_var($oTrans->getLangArray());
132
// Get the current dir
133
//$currentHome = $admin->get_home_folder();
134
$currentHome = (defined('HOME_FOLDERS') && HOME_FOLDERS) ? $admin->get_home_folder() : '';
135

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

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

    
149
$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
}
162

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

    
165
// Check to see if it contains ../
166
if (!check_media_path($directory)) {
167
	// $admin->print_header();
168
	$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_DOT_DOT_SLASH);
169
}
170

    
171
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
172
	// $admin->print_header();
173
	$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_DOES_NOT_EXIST);
174
}
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
	header("Location: browse.php?dir=$parent_directory");
180
	exit(0);
181
}
182

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

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

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

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

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

    
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
// Check for potentially malicious files
222
$forbidden_file_types  = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
223

    
224
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
225
	// Loop through the files and dirs an add to list
226
   while (false !== ($file = readdir($handle))) {
227
		$info = pathinfo($file);
228
		$ext = isset($info['extension']) ? $info['extension'] : '';
229
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
230
			if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
231
				if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
232
//					if( !isset($home_folders[$directory.'/'.$file]) ) {
233
                	if(!isset($home_folders[$directory.'/'.$file]) || $currentHome =='' )
234
                    {
235
						$DIR[] = $file;
236
					}
237
				} else {
238
					$FILE[] = $file;
239
				}
240
			}
241
		}
242
	}
243
	// Now parse these values to the template
244
	$temp_id = 0;
245
	$row_bg_color = 'FFF';
246
	if(isset($DIR)) {
247
		sort($DIR);
248
		foreach($DIR AS $name) {
249
			$link_name = str_replace(' ', '%20', $name);
250
			$temp_id++;
251
			$template->set_var(array(
252
								'NAME' => $name,
253
								'NAME_SLASHED' => addslashes($name),
254
								'TEMP_ID' => $admin->getIDKEY($temp_id),
255
								// 'TEMP_ID' => $temp_id,
256
								'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
			$template->parse('list', 'list_block', true);
271
			// Code to alternate row colors
272
			if($row_bg_color == 'FFF') {
273
				$row_bg_color = 'ECF1F3';
274
			} else {
275
				$row_bg_color = 'FFF';
276
			}
277
		}
278
	}
279
	if(isset($FILE)) {
280
		sort($FILE);
281
		$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf','pdf','zip','gz','doc');
282
		foreach($FILE AS $name) {
283
			$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

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

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

    
310
			$filetype_url = THEME_URL.'/images/files/'.$filetypeicon.'.png';
311
			$template->set_var(array(
312
								'NAME' => $name,
313
								'NAME_SLASHED' => addslashes($name),
314
								'TEMP_ID' => $admin->getIDKEY($temp_id),
315
								// 'TEMP_ID' => $temp_id,
316
								'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
								'IMAGE_EXIST' =>  'blank_16.gif'
328
							)
329
						);
330
			$template->parse('list', 'list_block', true);
331
			// Code to alternate row colors
332
			if($row_bg_color == 'FFF') {
333
				$row_bg_color = 'ECF1F3';
334
			} else {
335
				$row_bg_color = 'FFF';
336
			}
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
//if($currentHome=='') {
349
if( !in_array($admin->get_username(), explode('/',$directory)) ) {
350
// Insert permissions values
351
    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
}
358

    
359
// Insert language text and messages
360
$template->set_var(array(
361
					'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
362
					'NONE_FOUND' => $oTrans->MESSAGE_MEDIA_NONE_FOUND,
363
					'CHANGE_SETTINGS' => $oTrans->TEXT_MODIFY_SETTINGS,
364
					'CONFIRM_DELETE' => $oTrans->MESSAGE_MEDIA_CONFIRM_DELETE
365
				)
366
			);
367

    
368
// Parse template object
369
$template->parse('main', 'main_block', false);
370
$template->pparse('output', 'page');
371
/*
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
*/
(3-3/14)