Project

General

Profile

1
<?php
2

    
3
// $Id: browse.php,v 1.4 2005/04/02 06:25:37 rdjurovich Exp $
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
// Check to see if the user wanted to go up a directory into the parent folder
52
if($admin->get_get('up') == 1) {
53
	$parent_directory = dirname($directory);
54
	header("Location: browse.php?dir=$parent_directory");	
55
}
56

    
57
// Workout the parent dir link
58
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&up=1';
59
// Workout if the up arrow should be shown
60
if($directory == '') {
61
	$display_up_arrow = 'hide';
62
} else {
63
	$display_up_arrow = '';
64
}
65

    
66
// Insert values
67
$template->set_var(array(
68
								'CURRENT_DIR' => $directory,
69
								'PARENT_DIR_LINK' => $parent_dir_link,
70
								'DISPLAY_UP_ARROW' => $display_up_arrow
71
								)
72
						);
73

    
74
// Get home folder not to show
75
$home_folders = get_home_folders();
76

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

    
142
// If no files are in the media folder say so
143
if($temp_id == 0) {
144
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
145
} else {
146
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
147
}
148

    
149
// Insert permissions values
150
if($admin->get_permission('media_rename') != true) {
151
	$template->set_var('DISPLAY_RENAME', 'hide');
152
}
153
if($admin->get_permission('media_delete') != true) {
154
	$template->set_var('DISPLAY_DELETE', 'hide');
155
}
156

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

    
170
// Parse template object
171
$template->parse('main', 'main_block', false);
172
$template->pparse('output', 'page');
173

    
174
?>
(3-3/11)