1 |
238
|
stefan
|
<?php
|
2 |
1400
|
FrankH
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
1476
|
Luisehahne
|
* @package media
|
6 |
1400
|
FrankH
|
* @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_rename', false);
|
23 |
|
|
|
24 |
|
|
// Include the WB functions file
|
25 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
26 |
|
|
|
27 |
|
|
// Get the current dir
|
28 |
|
|
$directory = $admin->get_get('dir');
|
29 |
1475
|
Luisehahne
|
$directory = ($directory == '/') ? '' : $directory;
|
30 |
1400
|
FrankH
|
|
31 |
1475
|
Luisehahne
|
$dirlink = 'browse.php?dir='.$directory;
|
32 |
|
|
$rootlink = 'browse.php?dir=';
|
33 |
|
|
// $file_id = intval($admin->get_get('id'));
|
34 |
|
|
|
35 |
|
|
// first Check to see if it contains ..
|
36 |
1400
|
FrankH
|
if (!check_media_path($directory)) {
|
37 |
1475
|
Luisehahne
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH'],$rootlink, false);
|
38 |
238
|
stefan
|
}
|
39 |
|
|
|
40 |
|
|
// Get the temp id
|
41 |
1475
|
Luisehahne
|
$file_id = intval($admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']));
|
42 |
1400
|
FrankH
|
if (!$file_id) {
|
43 |
1475
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$dirlink, false);
|
44 |
238
|
stefan
|
}
|
45 |
|
|
|
46 |
|
|
// Get home folder not to show
|
47 |
|
|
$home_folders = get_home_folders();
|
48 |
1476
|
Luisehahne
|
// Check for potentially malicious files
|
49 |
|
|
$forbidden_file_types = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
|
50 |
238
|
stefan
|
|
51 |
|
|
// Figure out what folder name the temp id is
|
52 |
|
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
|
53 |
|
|
// Loop through the files and dirs an add to list
|
54 |
|
|
while (false !== ($file = readdir($handle))) {
|
55 |
1475
|
Luisehahne
|
$info = pathinfo($file);
|
56 |
|
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
57 |
238
|
stefan
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
58 |
1475
|
Luisehahne
|
if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
|
59 |
|
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
60 |
|
|
if(!isset($home_folders[$directory.'/'.$file])) {
|
61 |
|
|
$DIR[] = $file;
|
62 |
|
|
}
|
63 |
|
|
} else {
|
64 |
|
|
$FILE[] = $file;
|
65 |
238
|
stefan
|
}
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
1475
|
Luisehahne
|
|
70 |
238
|
stefan
|
$temp_id = 0;
|
71 |
|
|
if(isset($DIR)) {
|
72 |
384
|
Ruebenwurz
|
sort($DIR);
|
73 |
238
|
stefan
|
foreach($DIR AS $name) {
|
74 |
|
|
$temp_id++;
|
75 |
|
|
if($file_id == $temp_id) {
|
76 |
|
|
$rename_file = $name;
|
77 |
|
|
$type = 'folder';
|
78 |
|
|
}
|
79 |
|
|
}
|
80 |
|
|
}
|
81 |
1475
|
Luisehahne
|
|
82 |
238
|
stefan
|
if(isset($FILE)) {
|
83 |
384
|
Ruebenwurz
|
sort($FILE);
|
84 |
238
|
stefan
|
foreach($FILE AS $name) {
|
85 |
|
|
$temp_id++;
|
86 |
|
|
if($file_id == $temp_id) {
|
87 |
|
|
$rename_file = $name;
|
88 |
|
|
$type = 'file';
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
if(!isset($rename_file)) {
|
95 |
1475
|
Luisehahne
|
$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
|
96 |
238
|
stefan
|
}
|
97 |
|
|
|
98 |
|
|
// Setup template object
|
99 |
944
|
Ruebenwurz
|
$template = new Template(THEME_PATH.'/templates');
|
100 |
|
|
$template->set_file('page', 'media_rename.htt');
|
101 |
238
|
stefan
|
$template->set_block('page', 'main_block', 'main');
|
102 |
|
|
//echo WB_PATH.'/media/'.$directory.'/'.$rename_file;
|
103 |
|
|
if($type == 'folder') {
|
104 |
|
|
$template->set_var('DISPlAY_EXTENSION', 'hide');
|
105 |
|
|
$extension = '';
|
106 |
|
|
} else {
|
107 |
|
|
$template->set_var('DISPlAY_EXTENSION', '');
|
108 |
|
|
$extension = strstr($rename_file, '.');
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
if($type == 'folder') {
|
112 |
|
|
$type = $TEXT['FOLDER'];
|
113 |
|
|
} else {
|
114 |
|
|
$type = $TEXT['FILE'];
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
$template->set_var(array(
|
118 |
1457
|
Luisehahne
|
'THEME_URL' => THEME_URL,
|
119 |
|
|
'FILENAME' => $rename_file,
|
120 |
|
|
'DIR' => $directory,
|
121 |
|
|
'FILE_ID' => $admin->getIDKEY($file_id),
|
122 |
1475
|
Luisehahne
|
// 'FILE_ID' => $file_id,
|
123 |
1457
|
Luisehahne
|
'TYPE' => $type,
|
124 |
|
|
'EXTENSION' => $extension,
|
125 |
|
|
'FTAN' => $admin->getFTAN()
|
126 |
|
|
)
|
127 |
|
|
);
|
128 |
238
|
stefan
|
|
129 |
|
|
|
130 |
|
|
// Insert language text and messages
|
131 |
|
|
$template->set_var(array(
|
132 |
1457
|
Luisehahne
|
'TEXT_TO' => $TEXT['TO'],
|
133 |
|
|
'TEXT_RENAME' => $TEXT['RENAME'],
|
134 |
|
|
'TEXT_CANCEL' => $TEXT['CANCEL'],
|
135 |
|
|
'TEXT_UP' => $TEXT['UP'],
|
136 |
|
|
'TEXT_OVERWRITE_EXISTING' => $TEXT['OVERWRITE_EXISTING']
|
137 |
|
|
)
|
138 |
|
|
);
|
139 |
238
|
stefan
|
|
140 |
|
|
// Parse template object
|
141 |
|
|
$template->parse('main', 'main_block', false);
|
142 |
|
|
$template->pparse('output', 'page');
|