Project

General

Profile

1
<?php
2

    
3
// $Id: browse.php 1023 2009-07-01 06:25:32Z 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
											'SIZE' => '',
147
											'DATE' => '',
148
											'PREVIEW' => ''
149
											)
150
									);
151
			$template->parse('list', 'list_block', true);
152
			// Code to alternate row colors
153
			if($row_bg_color == 'FFF') {
154
				$row_bg_color = 'ECF1F3';
155
			} else {
156
				$row_bg_color = 'FFF';
157
			}
158
		}
159
	}
160
	if(isset($FILE)) {
161
		sort($FILE);
162
		$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf');
163
		foreach($FILE AS $name) {
164
			$size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
165
			$bytes = byte_convert($size);
166
			$fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
167
			$date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
168
			$filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
169
			$filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
170
				
171
			if (in_array($filetype, $filepreview)) {
172
				$preview = 'preview';
173
			} else {
174
				$preview = '';
175
			}
176
			$temp_id++;
177
			$template->set_var(array(
178
											'NAME' => $name,
179
											'NAME_SLASHED' => addslashes($name),
180
											'TEMP_ID' => $temp_id,
181
											'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
182
											'LINK_TARGET' => '_blank',
183
											'ROW_BG_COLOR' => $row_bg_color,
184
											'FILETYPE_ICON' => THEME_URL.'/images/files/'.$filetypeicon.'.png',
185
											'SIZE' => $bytes,
186
											'DATE' => $date,
187
											'PREVIEW' => $preview
188
											)
189
									);
190
			$template->parse('list', 'list_block', true);
191
			// Code to alternate row colors
192
			if($row_bg_color == 'FFF') {
193
				$row_bg_color = 'ECF1F3';
194
			} else {
195
				$row_bg_color = 'FFF';
196
			}
197
		}
198
	}
199
}
200

    
201
// If no files are in the media folder say so
202
if($temp_id == 0) {
203
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
204
} else {
205
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
206
}
207

    
208
// Insert permissions values
209
if($admin->get_permission('media_rename') != true) {
210
	$template->set_var('DISPLAY_RENAME', 'hide');
211
}
212
if($admin->get_permission('media_delete') != true) {
213
	$template->set_var('DISPLAY_DELETE', 'hide');
214
}
215

    
216
// Insert language text and messages
217
$template->set_var(array(
218
								'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
219
								'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
220
								'TEXT_RELOAD' => $TEXT['RELOAD'],
221
								'TEXT_RENAME' => $TEXT['RENAME'],
222
								'TEXT_DELETE' => $TEXT['DELETE'],
223
								'TEXT_SIZE' => $TEXT['SIZE'],
224
								'TEXT_DATE' => $TEXT['DATE'],
225
								'TEXT_NAME' => $TEXT['NAME'],
226
								'TEXT_TYPE' => $TEXT['TYPE'],
227
								'TEXT_UP' => $TEXT['UP'],
228
								'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
229
								'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
230
								)
231
						);
232

    
233
// Parse template object
234
$template->parse('main', 'main_block', false);
235
$template->pparse('output', 'page');
236

    
237
?>
(1-1/7)