Project

General

Profile

1 238 stefan
<?php
2
3
// $Id$
4
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8 519 Ruebenwurz
 Copyright (C) 2004-2008, Ryan Djurovich
9 238 stefan
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
// Setup template object
35
$template = new Template(ADMIN_PATH.'/media');
36
$template->set_file('page', 'browse.html');
37
$template->set_block('page', 'main_block', 'main');
38
39
// Get the current dir
40 328 stefan
$directory = $admin->strip_slashes($admin->get_get('dir'));
41 327 stefan
if($directory == '/' OR $directory == '\\') {
42 238 stefan
	$directory = '';
43
}
44
45
// Check to see if it contains ../
46
if(strstr($directory, '../')) {
47
	$admin->print_header();
48
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
49
}
50
51 282 stefan
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
52 238 stefan
	$admin->print_header();
53
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOES_NOT_EXIST']);
54
}
55
56
// Check to see if the user wanted to go up a directory into the parent folder
57
if($admin->get_get('up') == 1) {
58
	$parent_directory = dirname($directory);
59
	header("Location: browse.php?dir=$parent_directory");
60 286 stefan
	exit(0);
61 238 stefan
}
62
63
// Workout the parent dir link
64
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&up=1';
65
// Workout if the up arrow should be shown
66
if($directory == '') {
67
	$display_up_arrow = 'hide';
68
} else {
69
	$display_up_arrow = '';
70
}
71
72
// Insert values
73
$template->set_var(array(
74
								'CURRENT_DIR' => $directory,
75
								'PARENT_DIR_LINK' => $parent_dir_link,
76
								'DISPLAY_UP_ARROW' => $display_up_arrow
77
								)
78
						);
79
80
// Get home folder not to show
81
$home_folders = get_home_folders();
82
83
// Generate list
84
$template->set_block('main_block', 'list_block', 'list');
85
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
86
	// Loop through the files and dirs an add to list
87
   while(false !== ($file = readdir($handle))) {
88
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
89
			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
90
				if(!isset($home_folders[$directory.'/'.$file])) {
91
					$DIR[] = $file;
92
				}
93
			} else {
94
				$FILE[] = $file;
95
			}
96
		}
97
	}
98
	// Now parse these values to the template
99
	$temp_id = 0;
100 633 doc
	$row_bg_color = 'BDD3EC';
101 238 stefan
	if(isset($DIR)) {
102 384 Ruebenwurz
		sort($DIR);
103 238 stefan
		foreach($DIR AS $name) {
104
			$link_name = str_replace(' ', '%20', $name);
105
			$temp_id++;
106
			$template->set_var(array(
107
											'NAME' => $name,
108
											'NAME_SLASHED' => addslashes($name),
109
											'TEMP_ID' => $temp_id,
110
											'LINK' => "browse.php?dir=$directory/$link_name",
111
											'LINK_TARGET' => '',
112
											'ROW_BG_COLOR' => $row_bg_color,
113
											'FILETYPE_ICON' => ADMIN_URL.'/images/folder_16.png'
114
											)
115
									);
116
			$template->parse('list', 'list_block', true);
117
			// Code to alternate row colors
118 633 doc
			if($row_bg_color == 'D2E1F2') {
119
				$row_bg_color = 'BDD3EC';
120 238 stefan
			} else {
121 633 doc
				$row_bg_color = 'D2E1F2';
122 238 stefan
			}
123
		}
124
	}
125
	if(isset($FILE)) {
126 384 Ruebenwurz
		sort($FILE);
127 238 stefan
		foreach($FILE AS $name) {
128
			$temp_id++;
129
			$template->set_var(array(
130
											'NAME' => $name,
131
											'NAME_SLASHED' => addslashes($name),
132
											'TEMP_ID' => $temp_id,
133
											'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
134
											'LINK_TARGET' => '_blank',
135
											'ROW_BG_COLOR' => $row_bg_color,
136
											'FILETYPE_ICON' => ADMIN_URL.'/images/blank.gif'
137
											)
138
									);
139
			$template->parse('list', 'list_block', true);
140
			// Code to alternate row colors
141 633 doc
			if($row_bg_color == 'D2E1F2') {
142
				$row_bg_color = 'BDD3EC';
143 238 stefan
			} else {
144 633 doc
				$row_bg_color = 'D2E1F2';
145 238 stefan
			}
146
		}
147
	}
148
}
149
150
// If no files are in the media folder say so
151
if($temp_id == 0) {
152
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
153
} else {
154
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
155
}
156
157
// Insert permissions values
158
if($admin->get_permission('media_rename') != true) {
159
	$template->set_var('DISPLAY_RENAME', 'hide');
160
}
161
if($admin->get_permission('media_delete') != true) {
162
	$template->set_var('DISPLAY_DELETE', 'hide');
163
}
164
165
// Insert language text and messages
166
$template->set_var(array(
167
								'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
168
								'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
169
								'TEXT_RELOAD' => $TEXT['RELOAD'],
170
								'TEXT_RENAME' => $TEXT['RENAME'],
171
								'TEXT_DELETE' => $TEXT['DELETE'],
172
								'TEXT_UP' => $TEXT['UP'],
173
								'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
174
								'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
175
								)
176
						);
177
178
// Parse template object
179
$template->parse('main', 'main_block', false);
180
$template->pparse('output', 'page');
181
182 239 stefan
?>