Project

General

Profile

1
<?php
2

    
3
// $Id: browse.php 239 2005-11-22 11:50:41Z stefan $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, 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
// 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
$directory = $admin->get_get('dir');
41
if($directory == '/') {
42
	$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
if(!file_exists(WB_PATH.'/media'.$directory)) {
52
	$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
}
61

    
62
// Workout the parent dir link
63
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&up=1';
64
// Workout if the up arrow should be shown
65
if($directory == '') {
66
	$display_up_arrow = 'hide';
67
} else {
68
	$display_up_arrow = '';
69
}
70

    
71
// Insert values
72
$template->set_var(array(
73
								'CURRENT_DIR' => $directory,
74
								'PARENT_DIR_LINK' => $parent_dir_link,
75
								'DISPLAY_UP_ARROW' => $display_up_arrow
76
								)
77
						);
78

    
79
// Get home folder not to show
80
$home_folders = get_home_folders();
81

    
82
// Generate list
83
$template->set_block('main_block', 'list_block', 'list');
84
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
85
	// Loop through the files and dirs an add to list
86
   while(false !== ($file = readdir($handle))) {
87
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
88
			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
89
				if(!isset($home_folders[$directory.'/'.$file])) {
90
					$DIR[] = $file;
91
				}
92
			} else {
93
				$FILE[] = $file;
94
			}
95
		}
96
	}
97
	// Now parse these values to the template
98
	$temp_id = 0;
99
	$row_bg_color = 'EEEEEE';
100
	if(isset($DIR)) {
101
		foreach($DIR AS $name) {
102
			$link_name = str_replace(' ', '%20', $name);
103
			$temp_id++;
104
			$template->set_var(array(
105
											'NAME' => $name,
106
											'NAME_SLASHED' => addslashes($name),
107
											'TEMP_ID' => $temp_id,
108
											'LINK' => "browse.php?dir=$directory/$link_name",
109
											'LINK_TARGET' => '',
110
											'ROW_BG_COLOR' => $row_bg_color,
111
											'FILETYPE_ICON' => ADMIN_URL.'/images/folder_16.png'
112
											)
113
									);
114
			$template->parse('list', 'list_block', true);
115
			// Code to alternate row colors
116
			if($row_bg_color == 'DEDEDE') {
117
				$row_bg_color = 'EEEEEE';
118
			} else {
119
				$row_bg_color = 'DEDEDE';
120
			}
121
		}
122
	}
123
	if(isset($FILE)) {
124
		foreach($FILE AS $name) {
125
			$temp_id++;
126
			$template->set_var(array(
127
											'NAME' => $name,
128
											'NAME_SLASHED' => addslashes($name),
129
											'TEMP_ID' => $temp_id,
130
											'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
131
											'LINK_TARGET' => '_blank',
132
											'ROW_BG_COLOR' => $row_bg_color,
133
											'FILETYPE_ICON' => ADMIN_URL.'/images/blank.gif'
134
											)
135
									);
136
			$template->parse('list', 'list_block', true);
137
			// Code to alternate row colors
138
			if($row_bg_color == 'DEDEDE') {
139
				$row_bg_color = 'EEEEEE';
140
			} else {
141
				$row_bg_color = 'DEDEDE';
142
			}
143
		}
144
	}
145
}
146

    
147
// If no files are in the media folder say so
148
if($temp_id == 0) {
149
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
150
} else {
151
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
152
}
153

    
154
// Insert permissions values
155
if($admin->get_permission('media_rename') != true) {
156
	$template->set_var('DISPLAY_RENAME', 'hide');
157
}
158
if($admin->get_permission('media_delete') != true) {
159
	$template->set_var('DISPLAY_DELETE', 'hide');
160
}
161

    
162
// Insert language text and messages
163
$template->set_var(array(
164
								'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
165
								'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
166
								'TEXT_RELOAD' => $TEXT['RELOAD'],
167
								'TEXT_RENAME' => $TEXT['RENAME'],
168
								'TEXT_DELETE' => $TEXT['DELETE'],
169
								'TEXT_UP' => $TEXT['UP'],
170
								'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
171
								'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
172
								)
173
						);
174

    
175
// Parse template object
176
$template->parse('main', 'main_block', false);
177
$template->pparse('output', 'page');
178

    
179
?>
(3-3/11)