Project

General

Profile

1 238 stefan
<?php
2 1400 FrankH
/**
3
 *
4
 * @category        admin
5
 * @package         media
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL:  $
15
 * @lastmodified    $Date:  $
16
 *
17
 */
18 238 stefan
19
// Create admin object
20
require('../../config.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
$admin = new admin('Media', 'media', false);
23
24
// Include the WB functions file
25
require_once(WB_PATH.'/framework/functions.php');
26 1041 Ruebenwurz
include ('parameters.php');
27 238 stefan
28 1082 Ruebenwurz
// check if theme language file exists for the language set by the user (e.g. DE, EN)
29
if(!file_exists(THEME_PATH .'/languages/'.LANGUAGE .'.php')) {
30
	// no theme language file exists for the language set by the user, include default theme language file EN.php
31
	require_once(THEME_PATH .'/languages/EN.php');
32
} else {
33
	// a theme language file exists for the language defined by the user, load it
34
	require_once(THEME_PATH .'/languages/'.LANGUAGE .'.php');
35
}
36
37 1023 Ruebenwurz
// Byte convert for filesize
38
function byte_convert($bytes) {
39 1041 Ruebenwurz
	$symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
40 1035 Ruebenwurz
	$exp = 0;
41
	$converted_value = 0;
42
	if( $bytes > 0 ) {
43
		$exp = floor( log($bytes)/log(1024) );
44
		$converted_value = ( $bytes/pow(1024,floor($exp)) );
45
	}
46
	return sprintf( '%.2f '.$symbol[$exp], $converted_value );
47 1023 Ruebenwurz
}
48
49
// Get file extension
50
function get_filetype($fname) {
51
	$pathinfo = pathinfo($fname);
52 1407 FrankH
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
53 1023 Ruebenwurz
	return $extension;
54
}
55
56
// Get file extension for icons
57
function get_filetype_icon($fname) {
58
	$pathinfo = pathinfo($fname);
59 1407 FrankH
	$extension = (isset($pathinfo['extension'])) ? strtolower($pathinfo['extension']) : '';
60 1023 Ruebenwurz
	if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
61
		return $extension;
62
	} else {
63
		return 'unknown';
64
	}
65
}
66
67 238 stefan
// Setup template object
68 944 Ruebenwurz
$template = new Template(THEME_PATH.'/templates');
69
$template->set_file('page', 'media_browse.htt');
70 238 stefan
$template->set_block('page', 'main_block', 'main');
71
72
// Get the current dir
73 1087 Ruebenwurz
$currentHome = $admin->get_home_folder();
74
$directory =	(($currentHome) AND (!array_key_exists('dir',$_GET)))
75
				?
76
				$currentHome
77
				:
78
				$admin->strip_slashes($admin->get_get('dir')) ;
79 327 stefan
if($directory == '/' OR $directory == '\\') {
80 238 stefan
	$directory = '';
81
}
82
83
// Check to see if it contains ../
84 1400 FrankH
if (!check_media_path($directory)) {
85 1425 Luisehahne
	// $admin->print_header();
86 238 stefan
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
87
}
88
89 282 stefan
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
90 1425 Luisehahne
	// $admin->print_header();
91 238 stefan
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOES_NOT_EXIST']);
92
}
93
94
// Check to see if the user wanted to go up a directory into the parent folder
95
if($admin->get_get('up') == 1) {
96
	$parent_directory = dirname($directory);
97 1427 Luisehahne
	header("Location: browse.php?dir=$parent_directory");
98 286 stefan
	exit(0);
99 238 stefan
}
100
101 1041 Ruebenwurz
if ($_SESSION['GROUP_ID'] != 1 && $pathsettings['global']['admin_only']) { // Only show admin the settings link
102
	$template->set_var('DISPLAY_SETTINGS', 'hide');
103
}
104
105 238 stefan
// Workout the parent dir link
106 1427 Luisehahne
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&amp;up=1';
107 238 stefan
// Workout if the up arrow should be shown
108 1087 Ruebenwurz
if(($directory == '') or ($directory==$currentHome)) {
109 238 stefan
	$display_up_arrow = 'hide';
110
} else {
111
	$display_up_arrow = '';
112
}
113
114
// Insert values
115
$template->set_var(array(
116 944 Ruebenwurz
								'THEME_URL' => THEME_URL,
117 238 stefan
								'CURRENT_DIR' => $directory,
118
								'PARENT_DIR_LINK' => $parent_dir_link,
119 1023 Ruebenwurz
								'DISPLAY_UP_ARROW' => $display_up_arrow,
120
								'INCLUDE_PATH' => WB_URL.'/include'
121 238 stefan
								)
122
						);
123
124
// Get home folder not to show
125
$home_folders = get_home_folders();
126
127
// Generate list
128
$template->set_block('main_block', 'list_block', 'list');
129
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
130
	// Loop through the files and dirs an add to list
131 1035 Ruebenwurz
	while(false !== ($file = readdir($handle))) {
132 238 stefan
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
133
			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
134
				if(!isset($home_folders[$directory.'/'.$file])) {
135
					$DIR[] = $file;
136
				}
137
			} else {
138
				$FILE[] = $file;
139
			}
140
		}
141
	}
142
	// Now parse these values to the template
143
	$temp_id = 0;
144 686 doc
	$row_bg_color = 'FFF';
145 238 stefan
	if(isset($DIR)) {
146 384 Ruebenwurz
		sort($DIR);
147 238 stefan
		foreach($DIR AS $name) {
148
			$link_name = str_replace(' ', '%20', $name);
149
			$temp_id++;
150
			$template->set_var(array(
151
											'NAME' => $name,
152
											'NAME_SLASHED' => addslashes($name),
153 1400 FrankH
											'TEMP_ID' => $admin->getIDKEY($temp_id),
154 238 stefan
											'LINK' => "browse.php?dir=$directory/$link_name",
155 1453 Luisehahne
											'LINK_TARGET' => '_self',
156 238 stefan
											'ROW_BG_COLOR' => $row_bg_color,
157 1041 Ruebenwurz
											'FT_ICON' => THEME_URL.'/images/folder_16.png',
158 1023 Ruebenwurz
											'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
159 1035 Ruebenwurz
											'MOUSEOVER' => '',
160
											'IMAGEDETAIL' => '',
161 1023 Ruebenwurz
											'SIZE' => '',
162
											'DATE' => '',
163
											'PREVIEW' => ''
164 238 stefan
											)
165
									);
166
			$template->parse('list', 'list_block', true);
167
			// Code to alternate row colors
168 686 doc
			if($row_bg_color == 'FFF') {
169
				$row_bg_color = 'ECF1F3';
170 238 stefan
			} else {
171 686 doc
				$row_bg_color = 'FFF';
172 238 stefan
			}
173
		}
174
	}
175
	if(isset($FILE)) {
176 384 Ruebenwurz
		sort($FILE);
177 1023 Ruebenwurz
		$filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf');
178 238 stefan
		foreach($FILE AS $name) {
179 1023 Ruebenwurz
			$size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
180
			$bytes = byte_convert($size);
181
			$fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
182
			$date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
183
			$filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
184
			$filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
185 1427 Luisehahne
186 1023 Ruebenwurz
			if (in_array($filetype, $filepreview)) {
187
				$preview = 'preview';
188
			} else {
189
				$preview = '';
190
			}
191 238 stefan
			$temp_id++;
192 1035 Ruebenwurz
			$imgdetail = '';
193
			$icon = THEME_URL.'/images/blank.gif';
194
			$tooltip = '';
195 1041 Ruebenwurz
196
197 1035 Ruebenwurz
			if (!$pathsettings['global']['show_thumbs']) {
198
				$info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
199
				if ($info[0]) {
200 1041 Ruebenwurz
					$imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
201 1427 Luisehahne
					$icon = 'thumb.php?t=1&amp;img='.$directory.'/'.$name;
202
					$tooltip = ShowTip('thumb.php?t=2&amp;img='.$directory.'/'.$name);
203 1035 Ruebenwurz
				}
204
			}
205 238 stefan
			$template->set_var(array(
206
											'NAME' => $name,
207
											'NAME_SLASHED' => addslashes($name),
208 1400 FrankH
											'TEMP_ID' => $admin->getIDKEY($temp_id),
209 238 stefan
											'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
210
											'LINK_TARGET' => '_blank',
211
											'ROW_BG_COLOR' => $row_bg_color,
212 1041 Ruebenwurz
											'FT_ICON' => $icon,
213 1023 Ruebenwurz
											'FILETYPE_ICON' => THEME_URL.'/images/files/'.$filetypeicon.'.png',
214 1035 Ruebenwurz
											'MOUSEOVER' => $tooltip,
215
											'IMAGEDETAIL' => $imgdetail,
216 1023 Ruebenwurz
											'SIZE' => $bytes,
217
											'DATE' => $date,
218
											'PREVIEW' => $preview
219 238 stefan
											)
220
									);
221
			$template->parse('list', 'list_block', true);
222
			// Code to alternate row colors
223 686 doc
			if($row_bg_color == 'FFF') {
224
				$row_bg_color = 'ECF1F3';
225 238 stefan
			} else {
226 686 doc
				$row_bg_color = 'FFF';
227 238 stefan
			}
228
		}
229
	}
230
}
231
232
// If no files are in the media folder say so
233
if($temp_id == 0) {
234
	$template->set_var('DISPLAY_LIST_TABLE', 'hide');
235
} else {
236
	$template->set_var('DISPLAY_NONE_FOUND', 'hide');
237
}
238
239
// Insert permissions values
240
if($admin->get_permission('media_rename') != true) {
241
	$template->set_var('DISPLAY_RENAME', 'hide');
242
}
243
if($admin->get_permission('media_delete') != true) {
244
	$template->set_var('DISPLAY_DELETE', 'hide');
245
}
246
247
// Insert language text and messages
248
$template->set_var(array(
249
								'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
250
								'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
251
								'TEXT_RELOAD' => $TEXT['RELOAD'],
252
								'TEXT_RENAME' => $TEXT['RENAME'],
253
								'TEXT_DELETE' => $TEXT['DELETE'],
254 1023 Ruebenwurz
								'TEXT_SIZE' => $TEXT['SIZE'],
255
								'TEXT_DATE' => $TEXT['DATE'],
256
								'TEXT_NAME' => $TEXT['NAME'],
257
								'TEXT_TYPE' => $TEXT['TYPE'],
258 238 stefan
								'TEXT_UP' => $TEXT['UP'],
259
								'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
260 1035 Ruebenwurz
								'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
261 238 stefan
								'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
262
								)
263
						);
264
265
// Parse template object
266
$template->parse('main', 'main_block', false);
267
$template->pparse('output', 'page');
268
269 1035 Ruebenwurz
function ShowTip($name,$detail='') {
270 1058 ruud
$parts = explode(".", $name);
271
$ext = strtolower(end($parts));
272 1035 Ruebenwurz
if (strpos('.gif.jpg.jpeg.png.bmp.',$ext) )
273 1041 Ruebenwurz
	return 'onmouseover="overlib(\'<img src=\\\''.$name.'\\\' maxwidth=\\\'200\\\' maxheight=\\\'200\\\'>\',VAUTO, WIDTH)" onmouseout="nd()" ' ;
274 1035 Ruebenwurz
else
275
	return '';
276
}
277
278
function fsize($size) {
279
   if($size == 0) return("0 Bytes");
280 1041 Ruebenwurz
   $filesizename = array(" bytes", " kB", " MB", " GB", " TB");
281 1035 Ruebenwurz
   return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
282
}
283 239 stefan
?>