Project

General

Profile

wb-archiv283 / trunk / wb / admin / media / browse.php @ 1058

1
<?php
2

    
3
// $Id: browse.php 1058 2009-07-13 13:52:41Z ruud $
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
include ('parameters.php');
34

    
35
// Byte convert for filesize
36
function byte_convert($bytes) {
37
        $symbol = array(' bytes', ' KB', ' MB', ' GB', ' TB');
38
        $exp = 0;
39
        $converted_value = 0;
40
        if( $bytes > 0 ) {
41
                $exp = floor( log($bytes)/log(1024) );
42
                $converted_value = ( $bytes/pow(1024,floor($exp)) );
43
        }
44
        return sprintf( '%.2f '.$symbol[$exp], $converted_value );
45
}
46

    
47
// Get file extension
48
function get_filetype($fname) {
49
        $pathinfo = pathinfo($fname);
50
        $extension = strtolower($pathinfo['extension']);
51
        return $extension;
52
}
53

    
54
// Get file extension for icons
55
function get_filetype_icon($fname) {
56
        $pathinfo = pathinfo($fname);
57
        $extension = strtolower($pathinfo['extension']);
58
        if (file_exists(THEME_PATH.'/images/files/'.$extension.'.png')) {
59
                return $extension;
60
        } else {
61
                return 'unknown';
62
        }
63
}
64

    
65
// Setup template object
66
$template = new Template(THEME_PATH.'/templates');
67
$template->set_file('page', 'media_browse.htt');
68
$template->set_block('page', 'main_block', 'main');
69

    
70
// Get the current dir
71
$directory = $admin->strip_slashes($admin->get_get('dir'));
72
if($directory == '/' OR $directory == '\\') {
73
        $directory = '';
74
}
75

    
76
// Check to see if it contains ../
77
if(strstr($directory, '../')) {
78
        $admin->print_header();
79
        $admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
80
}
81

    
82
if(!file_exists(WB_PATH.MEDIA_DIRECTORY.$directory)) {
83
        $admin->print_header();
84
        $admin->print_error($MESSAGE['MEDIA']['DIR_DOES_NOT_EXIST']);
85
}
86

    
87
// Check to see if the user wanted to go up a directory into the parent folder
88
if($admin->get_get('up') == 1) {
89
        $parent_directory = dirname($directory);
90
        header("Location: browse.php?dir=$parent_directory");        
91
        exit(0);
92
}
93

    
94
if ($_SESSION['GROUP_ID'] != 1 && $pathsettings['global']['admin_only']) { // Only show admin the settings link
95
        $template->set_var('DISPLAY_SETTINGS', 'hide');
96
}
97

    
98
// Workout the parent dir link
99
$parent_dir_link = ADMIN_URL.'/media/browse.php?dir='.$directory.'&up=1';
100
// Workout if the up arrow should be shown
101
if($directory == '') {
102
        $display_up_arrow = 'hide';
103
} else {
104
        $display_up_arrow = '';
105
}
106

    
107
// Insert values
108
$template->set_var(array(
109
                                                                'THEME_URL' => THEME_URL,
110
                                                                'CURRENT_DIR' => $directory,
111
                                                                'PARENT_DIR_LINK' => $parent_dir_link,
112
                                                                'DISPLAY_UP_ARROW' => $display_up_arrow,
113
                                                                'INCLUDE_PATH' => WB_URL.'/include'
114
                                                                )
115
                                                );
116

    
117
// Get home folder not to show
118
$home_folders = get_home_folders();
119

    
120
// Generate list
121
$template->set_block('main_block', 'list_block', 'list');
122
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
123
        // Loop through the files and dirs an add to list
124
        while(false !== ($file = readdir($handle))) {
125
                if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
126
                        if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
127
                                if(!isset($home_folders[$directory.'/'.$file])) {
128
                                        $DIR[] = $file;
129
                                }
130
                        } else {
131
                                $FILE[] = $file;
132
                        }
133
                }
134
        }
135
        // Now parse these values to the template
136
        $temp_id = 0;
137
        $row_bg_color = 'FFF';
138
        if(isset($DIR)) {
139
                sort($DIR);
140
                foreach($DIR AS $name) {
141
                        $link_name = str_replace(' ', '%20', $name);
142
                        $temp_id++;
143
                        $template->set_var(array(
144
                                                                                        'NAME' => $name,
145
                                                                                        'NAME_SLASHED' => addslashes($name),
146
                                                                                        'TEMP_ID' => $temp_id,
147
                                                                                        'LINK' => "browse.php?dir=$directory/$link_name",
148
                                                                                        'LINK_TARGET' => '',
149
                                                                                        'ROW_BG_COLOR' => $row_bg_color,
150
                                                                                        'FT_ICON' => THEME_URL.'/images/folder_16.png',
151
                                                                                        'FILETYPE_ICON' => THEME_URL.'/images/folder_16.png',
152
                                                                                        'MOUSEOVER' => '',
153
                                                                                        'IMAGEDETAIL' => '',
154
                                                                                        'SIZE' => '',
155
                                                                                        'DATE' => '',
156
                                                                                        'PREVIEW' => ''
157
                                                                                        )
158
                                                                        );
159
                        $template->parse('list', 'list_block', true);
160
                        // Code to alternate row colors
161
                        if($row_bg_color == 'FFF') {
162
                                $row_bg_color = 'ECF1F3';
163
                        } else {
164
                                $row_bg_color = 'FFF';
165
                        }
166
                }
167
        }
168
        if(isset($FILE)) {
169
                sort($FILE);
170
                $filepreview = array('jpg','gif','tif','tiff','png','txt','css','js','cfg','conf');
171
                foreach($FILE AS $name) {
172
                        $size = filesize('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
173
                        $bytes = byte_convert($size);
174
                        $fdate = filemtime('../../'.MEDIA_DIRECTORY.$directory.'/'.$name);
175
                        $date = gmdate(DATE_FORMAT.' '.TIME_FORMAT, $fdate);
176
                        $filetypeicon = get_filetype_icon(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
177
                        $filetype = get_filetype(WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name);
178
                                
179
                        if (in_array($filetype, $filepreview)) {
180
                                $preview = 'preview';
181
                        } else {
182
                                $preview = '';
183
                        }
184
                        $temp_id++;
185
                        $imgdetail = '';
186
                        $icon = THEME_URL.'/images/blank.gif';
187
                        $tooltip = '';
188
                        
189
                        
190
                        if (!$pathsettings['global']['show_thumbs']) {
191
                                $info = getimagesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
192
                                if ($info[0]) {
193
                                        $imgdetail = fsize(filesize(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)).'<br /> '.$info[0].' x '.$info[1].' px';
194
                                        $icon = 'thumb.php?t=1&img='.$directory.'/'.$name;
195
                                        $tooltip = ShowTip('thumb.php?t=2&img='.$directory.'/'.$name);
196
                                }
197
                        }
198
                        $template->set_var(array(
199
                                                                                        'NAME' => $name,
200
                                                                                        'NAME_SLASHED' => addslashes($name),
201
                                                                                        'TEMP_ID' => $temp_id,
202
                                                                                        'LINK' => WB_URL.MEDIA_DIRECTORY.$directory.'/'.$name,
203
                                                                                        'LINK_TARGET' => '_blank',
204
                                                                                        'ROW_BG_COLOR' => $row_bg_color,
205
                                                                                        'FT_ICON' => $icon,
206
                                                                                        'FILETYPE_ICON' => THEME_URL.'/images/files/'.$filetypeicon.'.png',
207
                                                                                        'MOUSEOVER' => $tooltip, 
208
                                                                                        'IMAGEDETAIL' => $imgdetail,
209
                                                                                        'SIZE' => $bytes,
210
                                                                                        'DATE' => $date,
211
                                                                                        'PREVIEW' => $preview
212
                                                                                        )
213
                                                                        );
214
                        $template->parse('list', 'list_block', true);
215
                        // Code to alternate row colors
216
                        if($row_bg_color == 'FFF') {
217
                                $row_bg_color = 'ECF1F3';
218
                        } else {
219
                                $row_bg_color = 'FFF';
220
                        }
221
                }
222
        }
223
}
224

    
225
// If no files are in the media folder say so
226
if($temp_id == 0) {
227
        $template->set_var('DISPLAY_LIST_TABLE', 'hide');
228
} else {
229
        $template->set_var('DISPLAY_NONE_FOUND', 'hide');
230
}
231

    
232
// Insert permissions values
233
if($admin->get_permission('media_rename') != true) {
234
        $template->set_var('DISPLAY_RENAME', 'hide');
235
}
236
if($admin->get_permission('media_delete') != true) {
237
        $template->set_var('DISPLAY_DELETE', 'hide');
238
}
239

    
240
// Insert language text and messages
241
$template->set_var(array(
242
                                                                'MEDIA_DIRECTORY' => MEDIA_DIRECTORY,
243
                                                                'TEXT_CURRENT_FOLDER' => $TEXT['CURRENT_FOLDER'],
244
                                                                'TEXT_RELOAD' => $TEXT['RELOAD'],
245
                                                                'TEXT_RENAME' => $TEXT['RENAME'],
246
                                                                'TEXT_DELETE' => $TEXT['DELETE'],
247
                                                                'TEXT_SIZE' => $TEXT['SIZE'],
248
                                                                'TEXT_DATE' => $TEXT['DATE'],
249
                                                                'TEXT_NAME' => $TEXT['NAME'],
250
                                                                'TEXT_TYPE' => $TEXT['TYPE'],
251
                                                                'TEXT_UP' => $TEXT['UP'],
252
                                                                'NONE_FOUND' => $MESSAGE['MEDIA']['NONE_FOUND'],
253
                                                                'CHANGE_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
254
                                                                'CONFIRM_DELETE' => $MESSAGE['MEDIA']['CONFIRM_DELETE']
255
                                                                )
256
                                                );
257

    
258
// Parse template object
259
$template->parse('main', 'main_block', false);
260
$template->pparse('output', 'page');
261

    
262
function ShowTip($name,$detail='') {
263
$parts = explode(".", $name);
264
$ext = strtolower(end($parts));
265
if (strpos('.gif.jpg.jpeg.png.bmp.',$ext) )
266
        return 'onmouseover="overlib(\'<img src=\\\''.$name.'\\\' maxwidth=\\\'200\\\' maxheight=\\\'200\\\'>\',VAUTO, WIDTH)" onmouseout="nd()" ' ;
267
else
268
        return '';
269
}
270

    
271
function fsize($size) {
272
   if($size == 0) return("0 Bytes");
273
   $filesizename = array(" bytes", " kB", " MB", " GB", " TB");
274
   return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i];
275
}
276
?>