Project

General

Profile

1
<?php
2

    
3
// $Id: browse.php 915 2009-01-21 19:27:01Z 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
// 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->strip_slashes($admin->get_get('dir'));
41
if($directory == '/' OR $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.$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
	exit(0);
61
}
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
	$row_bg_color = 'FFF';
101
	if(isset($DIR)) {
102
		sort($DIR);
103
		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
			if($row_bg_color == 'FFF') {
119
				$row_bg_color = 'ECF1F3';
120
			} else {
121
				$row_bg_color = 'FFF';
122
			}
123
		}
124
	}
125
	if(isset($FILE)) {
126
		sort($FILE);
127
		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
			if($row_bg_color == 'FFF') {
142
				$row_bg_color = 'ECF1F3';
143
			} else {
144
				$row_bg_color = 'FFF';
145
			}
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
?>
(3-3/11)