Project

General

Profile

1
<?php
2

    
3
// $Id: browse.php 1035 2009-07-06 22:34:35Z 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

    
34
// Byte convert for filesize
35
function byte_convert($bytes) {
36
	$symbol = array('B', 'KB', 'MB', 'GB', 'TB');
37
	$exp = 0;
38
	$converted_value = 0;
39
	if( $bytes > 0 ) {
40
		$exp = floor( log($bytes)/log(1024) );
41
		$converted_value = ( $bytes/pow(1024,floor($exp)) );
42
	}
43
	return sprintf( '%.2f '.$symbol[$exp], $converted_value );
44
}
45

    
46
// Get file extension
47
function get_filetype($fname) {
48
	$pathinfo = pathinfo($fname);
49
	$extension = strtolower($pathinfo['extension']);
50
	return $extension;
51
}
52

    
53
// Get file extension for icons
54
function get_filetype_icon($fname) {
55
	$pathinfo = pathinfo($fname);
56
	$extension = strtolower($pathinfo['extension']);
57
	if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
58
		return $extension;
59
	} else {
60
		return 'unknown';
61
	}
62
}
63

    
64
// Setup template object
65
$template = new Template(THEME_PATH.'/templates');
66
$template->set_file('page', 'media_browse.htt');
67
$template->set_block('page', 'main_block', 'main');
68

    
69
// Get the current dir
70
$directory = $admin->strip_slashes($admin->get_get('dir'));
71
if($directory == '/' OR $directory == '\\') {
72
	$directory = '';
73
}
74

    
75
// Check to see if it contains ../
76
if(strstr($directory, '../')) {
77
	$admin->print_header();
78
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
79
}
80

    
81
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
82
	$admin->print_header();
83
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOES_NOT_EXIST']);
84
}
85

    
86
// Check to see if the user wanted to go up a directory into the parent folder
87
if($admin->get_get('up') == 1) {
88
	$parent_directory = dirname($directory);
89
	header("Location: browse.php?dir=$parent_directory");	
90
	exit(0);
91
}
92

    
93
// Workout the parent dir link
94
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&up=1';
95
// Workout if the up arrow should be shown
96
if($directory == '') {
97
	$display_up_arrow = 'hide';
98
} else {
99
	$display_up_arrow = '';
100
}
101

    
102
// Insert values
103
$template->set_var(array(
104
								'THEME_URL' => THEME_URL,
105
								'CURRENT_DIR' => $directory,
106
								'PARENT_DIR_LINK' => $parent_dir_link,
107
								'DISPLAY_UP_ARROW' => $display_up_arrow,
108
								'INCLUDE_PATH' => WB_URL.'/include'
109
								)
110
						);
111

    
112
// Get home folder not to show
113
$home_folders = get_home_folders();
114

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

    
218
// If no files are in the media folder say so
219
if($temp_id == 0) {
220
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
221
} else {
222
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
223
}
224

    
225
// Insert permissions values
226
if($admin->get_permission('media_rename') != true) {
227
	$template->set_var('DISPLAY_RENAME', 'hide');
228
}
229
if($admin->get_permission('media_delete') != true) {
230
	$template->set_var('DISPLAY_DELETE', 'hide');
231
}
232

    
233
// Insert language text and messages
234
$template->set_var(array(
235
								'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
236
								'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
237
								'TEXT_RELOAD' => $TEXT['RELOAD'],
238
								'TEXT_RENAME' => $TEXT['RENAME'],
239
								'TEXT_DELETE' => $TEXT['DELETE'],
240
								'TEXT_SIZE' => $TEXT['SIZE'],
241
								'TEXT_DATE' => $TEXT['DATE'],
242
								'TEXT_NAME' => $TEXT['NAME'],
243
								'TEXT_TYPE' => $TEXT['TYPE'],
244
								'TEXT_UP' => $TEXT['UP'],
245
								'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
246
								'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
247
								'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
248
								)
249
						);
250

    
251
// Parse template object
252
$template->parse('main', 'main_block', false);
253
$template->pparse('output', 'page');
254

    
255
function ShowTip($name,$detail='') {
256
$ext = strtolower(end(explode(".", $name)));
257
if (strpos('.gif.jpg.jpeg.png.bmp.',$ext) )
258
	return 'onmouseover="overlib(\'<img src=\\\''.$name.'\\\' width=\\\'200\\\'><br/><center>'.$detail.'</center>\',VAUTO, WIDTH, 200)" onmouseout="nd()" ' ;
259
else
260
	return '';
261
}
262

    
263
function fsize($size) {
264
   if($size == 0) return("0 Bytes");
265
   $filesizename = array(" Bytes", "kB", "MB", "GB", "TB");
266
   return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
267
}
268
?>
(1-1/12)