Project

General

Profile

1
<?php
2

    
3
// $Id: browse.php 1087 2009-07-22 15:42:49Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
// Create admin object
27
require('../../config.php');
28
require_once(WB_PATH.'/framework/class.admin.php');
29
$admin = new admin('Media', 'media', false);
30

    
31
// Include the WB functions file
32
require_once(WB_PATH.'/framework/functions.php');
33
include ('parameters.php');
34

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

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

    
56
// Get file extension
57
function get_filetype($fname) {
58
	$pathinfo = pathinfo($fname);
59
	$extension = strtolower($pathinfo['extension']);
60
	return $extension;
61
}
62

    
63
// Get file extension for icons
64
function get_filetype_icon($fname) {
65
	$pathinfo = pathinfo($fname);
66
	$extension = strtolower($pathinfo['extension']);
67
	if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
68
		return $extension;
69
	} else {
70
		return 'unknown';
71
	}
72
}
73

    
74
// Setup template object
75
$template = new Template(THEME_PATH.'/templates');
76
$template->set_file('page', 'media_browse.htt');
77
$template->set_block('page', 'main_block', 'main');
78

    
79
// Get the current dir
80
$currentHome = $admin->get_home_folder();
81
$directory =	(($currentHome) AND (!array_key_exists('dir',$_GET)))
82
				? 
83
				$currentHome
84
				:
85
				$admin->strip_slashes($admin->get_get('dir')) ;
86
if($directory == '/' OR $directory == '\\') {
87
	$directory = '';
88
}
89

    
90
// Check to see if it contains ../
91
if(strstr($directory, '../')) {
92
	$admin->print_header();
93
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
94
}
95

    
96
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
97
	$admin->print_header();
98
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOES_NOT_EXIST']);
99
}
100

    
101
// Check to see if the user wanted to go up a directory into the parent folder
102
if($admin->get_get('up') == 1) {
103
	$parent_directory = dirname($directory);
104
	header("Location: browse.php?dir=$parent_directory");	
105
	exit(0);
106
}
107

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

    
112
// Workout the parent dir link
113
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&up=1';
114
// Workout if the up arrow should be shown
115
if(($directory == '') or ($directory==$currentHome)) {
116
	$display_up_arrow = 'hide';
117
} else {
118
	$display_up_arrow = '';
119
}
120

    
121
// Insert values
122
$template->set_var(array(
123
								'THEME_URL' => THEME_URL,
124
								'CURRENT_DIR' => $directory,
125
								'PARENT_DIR_LINK' => $parent_dir_link,
126
								'DISPLAY_UP_ARROW' => $display_up_arrow,
127
								'INCLUDE_PATH' => WB_URL.'/include'
128
								)
129
						);
130

    
131
// Get home folder not to show
132
$home_folders = get_home_folders();
133

    
134
// Generate list
135
$template->set_block('main_block', 'list_block', 'list');
136
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
137
	// Loop through the files and dirs an add to list
138
	while(false !== ($file = readdir($handle))) {
139
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
140
			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
141
				if(!isset($home_folders[$directory.'/'.$file])) {
142
					$DIR[] = $file;
143
				}
144
			} else {
145
				$FILE[] = $file;
146
			}
147
		}
148
	}
149
	// Now parse these values to the template
150
	$temp_id = 0;
151
	$row_bg_color = 'FFF';
152
	if(isset($DIR)) {
153
		sort($DIR);
154
		foreach($DIR AS $name) {
155
			$link_name = str_replace(' ', '%20', $name);
156
			$temp_id++;
157
			$template->set_var(array(
158
											'NAME' => $name,
159
											'NAME_SLASHED' => addslashes($name),
160
											'TEMP_ID' => $temp_id,
161
											'LINK' => "browse.php?dir=$directory/$link_name",
162
											'LINK_TARGET' => '',
163
											'ROW_BG_COLOR' => $row_bg_color,
164
											'FT_ICON' => THEME_URL.'/images/folder_16.png',
165
											'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
166
											'MOUSEOVER' => '',
167
											'IMAGEDETAIL' => '',
168
											'SIZE' => '',
169
											'DATE' => '',
170
											'PREVIEW' => ''
171
											)
172
									);
173
			$template->parse('list', 'list_block', true);
174
			// Code to alternate row colors
175
			if($row_bg_color == 'FFF') {
176
				$row_bg_color = 'ECF1F3';
177
			} else {
178
				$row_bg_color = 'FFF';
179
			}
180
		}
181
	}
182
	if(isset($FILE)) {
183
		sort($FILE);
184
		$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf');
185
		foreach($FILE AS $name) {
186
			$size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
187
			$bytes = byte_convert($size);
188
			$fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
189
			$date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
190
			$filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
191
			$filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
192
				
193
			if (in_array($filetype, $filepreview)) {
194
				$preview = 'preview';
195
			} else {
196
				$preview = '';
197
			}
198
			$temp_id++;
199
			$imgdetail = '';
200
			$icon = THEME_URL.'/images/blank.gif';
201
			$tooltip = '';
202
			
203
			
204
			if (!$pathsettings['global']['show_thumbs']) {
205
				$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
206
				if ($info[0]) {
207
					$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
208
					$icon = 'thumb.php?t=1&img='.$directory.'/'.$name;
209
					$tooltip = ShowTip('thumb.php?t=2&img='.$directory.'/'.$name);
210
				}
211
			}
212
			$template->set_var(array(
213
											'NAME' => $name,
214
											'NAME_SLASHED' => addslashes($name),
215
											'TEMP_ID' => $temp_id,
216
											'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
217
											'LINK_TARGET' => '_blank',
218
											'ROW_BG_COLOR' => $row_bg_color,
219
											'FT_ICON' => $icon,
220
											'FILETYPE_ICON' => THEME_URL.'/images/files/'.$filetypeicon.'.png',
221
											'MOUSEOVER' => $tooltip, 
222
											'IMAGEDETAIL' => $imgdetail,
223
											'SIZE' => $bytes,
224
											'DATE' => $date,
225
											'PREVIEW' => $preview
226
											)
227
									);
228
			$template->parse('list', 'list_block', true);
229
			// Code to alternate row colors
230
			if($row_bg_color == 'FFF') {
231
				$row_bg_color = 'ECF1F3';
232
			} else {
233
				$row_bg_color = 'FFF';
234
			}
235
		}
236
	}
237
}
238

    
239
// If no files are in the media folder say so
240
if($temp_id == 0) {
241
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
242
} else {
243
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
244
}
245

    
246
// Insert permissions values
247
if($admin->get_permission('media_rename') != true) {
248
	$template->set_var('DISPLAY_RENAME', 'hide');
249
}
250
if($admin->get_permission('media_delete') != true) {
251
	$template->set_var('DISPLAY_DELETE', 'hide');
252
}
253

    
254
// Insert language text and messages
255
$template->set_var(array(
256
								'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
257
								'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
258
								'TEXT_RELOAD' => $TEXT['RELOAD'],
259
								'TEXT_RENAME' => $TEXT['RENAME'],
260
								'TEXT_DELETE' => $TEXT['DELETE'],
261
								'TEXT_SIZE' => $TEXT['SIZE'],
262
								'TEXT_DATE' => $TEXT['DATE'],
263
								'TEXT_NAME' => $TEXT['NAME'],
264
								'TEXT_TYPE' => $TEXT['TYPE'],
265
								'TEXT_UP' => $TEXT['UP'],
266
								'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
267
								'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
268
								'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
269
								)
270
						);
271

    
272
// Parse template object
273
$template->parse('main', 'main_block', false);
274
$template->pparse('output', 'page');
275

    
276
function ShowTip($name,$detail='') {
277
$parts = explode(".", $name);
278
$ext = strtolower(end($parts));
279
if (strpos('.gif.jpg.jpeg.png.bmp.',$ext) )
280
	return 'onmouseover="overlib(\'<img src=\\\''.$name.'\\\' maxwidth=\\\'200\\\' maxheight=\\\'200\\\'>\',VAUTO, WIDTH)" onmouseout="nd()" ' ;
281
else
282
	return '';
283
}
284

    
285
function fsize($size) {
286
   if($size == 0) return("0 Bytes");
287
   $filesizename = array(" bytes", " kB", " MB", " GB", " TB");
288
   return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
289
}
290
?>
(1-1/12)