1
|
<?php
|
2
|
/**
|
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: rename.php 1476 2011-07-13 15:46:19Z Luisehahne $
|
14
|
* @filesource $HeadURL: $
|
15
|
* @lastmodified $Date: $
|
16
|
*
|
17
|
*/
|
18
|
|
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
|
$directory = ($directory == '/') ? '' : $directory;
|
30
|
|
31
|
$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
|
if (!check_media_path($directory)) {
|
37
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH'],$rootlink, false);
|
38
|
}
|
39
|
|
40
|
// Get the temp id
|
41
|
$file_id = intval($admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']));
|
42
|
if (!$file_id) {
|
43
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$dirlink, false);
|
44
|
}
|
45
|
|
46
|
// Get home folder not to show
|
47
|
$home_folders = get_home_folders();
|
48
|
// Check for potentially malicious files
|
49
|
$forbidden_file_types = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
|
50
|
|
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
|
$info = pathinfo($file);
|
56
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
57
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
58
|
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
|
}
|
66
|
}
|
67
|
}
|
68
|
}
|
69
|
|
70
|
$temp_id = 0;
|
71
|
if(isset($DIR)) {
|
72
|
sort($DIR);
|
73
|
foreach($DIR AS $name) {
|
74
|
$temp_id++;
|
75
|
if($file_id == $temp_id) {
|
76
|
$rename_file = $name;
|
77
|
$type = 'folder';
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
|
82
|
if(isset($FILE)) {
|
83
|
sort($FILE);
|
84
|
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
|
$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
|
96
|
}
|
97
|
|
98
|
// Setup template object
|
99
|
$template = new Template(THEME_PATH.'/templates');
|
100
|
$template->set_file('page', 'media_rename.htt');
|
101
|
$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
|
'THEME_URL' => THEME_URL,
|
119
|
'FILENAME' => $rename_file,
|
120
|
'DIR' => $directory,
|
121
|
'FILE_ID' => $admin->getIDKEY($file_id),
|
122
|
// 'FILE_ID' => $file_id,
|
123
|
'TYPE' => $type,
|
124
|
'EXTENSION' => $extension,
|
125
|
'FTAN' => $admin->getFTAN()
|
126
|
)
|
127
|
);
|
128
|
|
129
|
|
130
|
// Insert language text and messages
|
131
|
$template->set_var(array(
|
132
|
'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
|
|
140
|
// Parse template object
|
141
|
$template->parse('main', 'main_block', false);
|
142
|
$template->pparse('output', 'page');
|