Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         media
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: browse.php 1460 2011-06-29 19:14:48Z Luisehahne $
14
 * @filesource		$HeadURL:  $
15
 * @lastmodified    $Date:  $
16
 *
17
 */
18

    
19
// Create admin object
20
require('../../config.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
$admin = new admin('Media', 'media', false);
23

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

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

    
31
// check if theme language file exists for the language set by the user (e.g. DE, EN)
32
if(!file_exists(THEME_PATH .'/languages/'.LANGUAGE .'.php')) {
33
	// no theme language file exists for the language set by the user, include default theme language file EN.php
34
	require_once(THEME_PATH .'/languages/EN.php');
35
} else {
36
	// a theme language file exists for the language defined by the user, load it
37
	require_once(THEME_PATH .'/languages/'.LANGUAGE .'.php');
38
}
39

    
40
// Byte convert for filesize
41
function byte_convert($bytes) {
42
	$symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
43
	$exp = 0;
44
	$converted_value = 0;
45
	if( $bytes > 0 ) {
46
		$exp = floor( log($bytes)/log(1024) );
47
		$converted_value = ( $bytes/pow(1024,floor($exp)) );
48
	}
49
	return sprintf( '%.2f '.$symbol[$exp], $converted_value );
50
}
51

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

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

    
70
function ShowTip($name,$detail='') {
71
$parts = explode(".", $name);
72
$ext = strtolower(end($parts));
73
if (strpos('.gif.jpg.jpeg.png.bmp.',$ext) )
74
	return 'onmouseover="overlib(\'<img src=\\\''.$name.'\\\' maxwidth=\\\'200\\\' maxheight=\\\'200\\\'>\',VAUTO, WIDTH)" onmouseout="nd()" ' ;
75
else
76
	return '';
77
}
78

    
79
function fsize($size) {
80
   if($size == 0) return("0 Bytes");
81
   $filesizename = array(" bytes", " kB", " MB", " GB", " TB");
82
   return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
83
}
84

    
85
// Setup template object
86
$template = new Template(THEME_PATH.'/templates');
87
$template->set_file('page', 'media_browse.htt');
88
$template->set_block('page', 'main_block', 'main');
89

    
90
// Get the current dir
91
$currentHome = $admin->get_home_folder();
92
$directory =	(($currentHome) AND (!array_key_exists('dir',$_GET)))
93
				?
94
				$currentHome
95
				:
96
				$admin->strip_slashes($admin->get_get('dir')) ;
97
if($directory == '/' OR $directory == '\\') {
98
	$directory = '';
99
}
100

    
101
// Check to see if it contains ../
102
if (!check_media_path($directory)) {
103
	// $admin->print_header();
104
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
105
}
106

    
107
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
108
	// $admin->print_header();
109
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOES_NOT_EXIST']);
110
}
111

    
112
// Check to see if the user wanted to go up a directory into the parent folder
113
if($admin->get_get('up') == 1) {
114
	$parent_directory = dirname($directory);
115
	header("Location: browse.php?dir=$parent_directory");
116
	exit(0);
117
}
118

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

    
123
// Workout the parent dir link
124
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&amp;up=1';
125
// Workout if the up arrow should be shown
126
if(($directory == '') or ($directory==$currentHome)) {
127
	$display_up_arrow = 'hide';
128
} else {
129
	$display_up_arrow = '';
130
}
131

    
132
// Insert values
133
$template->set_var(array(
134
					'THEME_URL' => THEME_URL,
135
					// 'THEME_URL' => '',
136
					'CURRENT_DIR' => $directory,
137
					'PARENT_DIR_LINK' => $parent_dir_link,
138
					'DISPLAY_UP_ARROW' => $display_up_arrow,
139
					'INCLUDE_PATH' => WB_URL.'/include'
140
				)
141
			);
142

    
143
// Get home folder not to show
144
$home_folders = get_home_folders();
145

    
146
// Generate list
147
$template->set_block('main_block', 'list_block', 'list');
148

    
149
$usedFiles = array();
150
// require_once(ADMIN_PATH.'/media/dse.php');
151
// $filename =  $currentdir;
152
if(!empty($currentdir)) {
153
	$usedFiles = $Dse->getMatchesFromDir( $currentdir, DseTwo::RETURN_USED);
154
/*
155
print '<pre><strong>function '.__FUNCTION__.'();</strong>  basename: '.basename(__FILE__).'  line: '.__LINE__.' -> <br />';
156
print_r( $usedFiles ); print '</pre>'; // flush ();sleep(10); die();
157
*/
158
}
159

    
160
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
161
	// Loop through the files and dirs an add to list
162
	while(false !== ($file = readdir($handle))) {
163
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
164
			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
165
				if(!isset($home_folders[$directory.'/'.$file])) {
166
					$DIR[] = $file;
167
				}
168
			} else {
169
				$FILE[] = $file;
170
			}
171
		}
172
	}
173
	// Now parse these values to the template
174
	$temp_id = 0;
175
	$row_bg_color = 'FFF';
176
	if(isset($DIR)) {
177
		sort($DIR);
178
		foreach($DIR AS $name) {
179
			$link_name = str_replace(' ', '%20', $name);
180
			$temp_id++;
181
			$template->set_var(array(
182
								'NAME' => $name,
183
								'NAME_SLASHED' => addslashes($name),
184
								'TEMP_ID' => $admin->getIDKEY($temp_id),
185
								'LINK' => "browse.php?dir=$directory/$link_name",
186
								'LINK_TARGET' => '_self',
187
								'ROW_BG_COLOR' => $row_bg_color,
188
								'FT_ICON' => THEME_URL.'/images/folder_16.png',
189
								'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
190
								'MOUSEOVER' => '',
191
								'IMAGEDETAIL' => '',
192
								'SIZE' => '',
193
								'DATE' => '',
194
								'PREVIEW' => '',
195
								'IMAGE_TITLE' => $name,
196
								'IMAGE_EXIST' => 'blank_16.gif'
197
							)
198
						);
199
			$template->parse('list', 'list_block', true);
200
			// Code to alternate row colors
201
			if($row_bg_color == 'FFF') {
202
				$row_bg_color = 'ECF1F3';
203
			} else {
204
				$row_bg_color = 'FFF';
205
			}
206
		}
207
	}
208
	if(isset($FILE)) {
209
		sort($FILE);
210
		$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf','pdf','zip','gz','doc');
211
		foreach($FILE AS $name) {
212
			$size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
213
			$bytes = byte_convert($size);
214
			$fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
215
			$date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
216
			$filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
217
			$filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
218

    
219
			if (in_array($filetype, $filepreview)) {
220
				$preview = 'preview';
221
			} else {
222
				$preview = '';
223
			}
224
			$temp_id++;
225
			$imgdetail = '';
226
			// $icon = THEME_URL.'/images/blank_16.gif';
227
			$icon = '';
228
			$tooltip = '';
229

    
230

    
231
			if (!$pathsettings['global']['show_thumbs']) {
232
				$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
233
				if ($info[0]) {
234
					$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
235
					$icon = 'thumb.php?t=1&amp;img='.$directory.'/'.$name;
236
					$tooltip = ShowTip('thumb.php?t=2&amp;img='.$directory.'/'.$name);
237
				}
238
			}
239

    
240
			$filetype_url = THEME_URL.'/images/files/'.$filetypeicon.'.png';
241
			$template->set_var(array(
242
								'NAME' => $name,
243
								'NAME_SLASHED' => addslashes($name),
244
								'TEMP_ID' => $admin->getIDKEY($temp_id),
245
								'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
246
								'LINK_TARGET' => '_blank',
247
								'ROW_BG_COLOR' => $row_bg_color,
248
								'FT_ICON' => empty($icon) ? $filetype_url : $icon,
249
								'FILETYPE_ICON' => $filetype_url,
250
								'MOUSEOVER' => $tooltip,
251
								'IMAGEDETAIL' => $imgdetail,
252
								'SIZE' => $bytes,
253
								'DATE' => $date,
254
								'PREVIEW' => $preview,
255
								'IMAGE_TITLE' => $name,
256
								'IMAGE_EXIST' =>  'blank_16.gif'
257
							)
258
						);
259
			$template->parse('list', 'list_block', true);
260
			// Code to alternate row colors
261
			if($row_bg_color == 'FFF') {
262
				$row_bg_color = 'ECF1F3';
263
			} else {
264
				$row_bg_color = 'FFF';
265
			}
266
		}
267
	}
268
}
269

    
270
// If no files are in the media folder say so
271
if($temp_id == 0) {
272
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
273
} else {
274
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
275
}
276

    
277
// Insert permissions values
278
if($admin->get_permission('media_rename') != true) {
279
	$template->set_var('DISPLAY_RENAME', 'hide');
280
}
281
if($admin->get_permission('media_delete') != true) {
282
	$template->set_var('DISPLAY_DELETE', 'hide');
283
}
284

    
285
// Insert language text and messages
286
$template->set_var(array(
287
					'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
288
					'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
289
					'TEXT_RELOAD' => $TEXT['RELOAD'],
290
					'TEXT_RENAME' => $TEXT['RENAME'],
291
					'TEXT_DELETE' => $TEXT['DELETE'],
292
					'TEXT_SIZE' => $TEXT['SIZE'],
293
					'TEXT_DATE' => $TEXT['DATE'],
294
					'TEXT_NAME' => $TEXT['NAME'],
295
					'TEXT_TYPE' => $TEXT['TYPE'],
296
					'TEXT_UP' => $TEXT['UP'],
297
					'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
298
					'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
299
					'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
300
				)
301
			);
302

    
303
// Parse template object
304
$template->parse('main', 'main_block', false);
305
$template->pparse('output', 'page');
306
/*
307
$endtime=explode(" ", microtime());
308
$endtime=$endtime[0]+$endtime[1];
309
$debugVMsg = '';
310
if($admin->ami_group_member('1') ) {
311
	$debugVMsg  = "<p>Mask loaded in ".round($endtime - $starttime,6)." Sec,&nbsp;&nbsp;";
312
	$debugVMsg .= "Memory in use ".number_format(memory_get_usage(true), 0, ',', '.')."&nbsp;Byte,&nbsp;&nbsp;";
313
	$debugVMsg .= sizeof(get_included_files())."&nbsp;included files</p>";
314
	// $debugVMsg = print_message($debugVMsg,'#','debug',-1,false);
315
	print $debugVMsg.'<br />';
316
 }
317
*/ 
(3-3/15)