Project

General

Profile

1
<?php
2

    
3
// $Id: browse.php 944 2009-02-22 09:39:58Z 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(THEME_PATH.'/templates');
36
$template->set_file('page', 'media_browse.htt');
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
								'THEME_URL' => THEME_URL,
75
								'CURRENT_DIR' => $directory,
76
								'PARENT_DIR_LINK' => $parent_dir_link,
77
								'DISPLAY_UP_ARROW' => $display_up_arrow
78
								)
79
						);
80

    
81
// Get home folder not to show
82
$home_folders = get_home_folders();
83

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

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

    
158
// Insert permissions values
159
if($admin->get_permission('media_rename') != true) {
160
	$template->set_var('DISPLAY_RENAME', 'hide');
161
}
162
if($admin->get_permission('media_delete') != true) {
163
	$template->set_var('DISPLAY_DELETE', 'hide');
164
}
165

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

    
179
// Parse template object
180
$template->parse('main', 'main_block', false);
181
$template->pparse('output', 'page');
182

    
183
?>
(1-1/7)