1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category admin
|
5
|
* @package media
|
6
|
* @author Ryan Djurovich, WebsiteBaker Project
|
7
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: rename.php 1625 2012-02-29 00:50:57Z Luisehahne $
|
13
|
* @filesource $HeadURL: $
|
14
|
* @lastmodified $Date: $
|
15
|
*
|
16
|
*/
|
17
|
|
18
|
// Create admin object
|
19
|
require('../../config.php');
|
20
|
require_once(WB_PATH.'/framework/class.admin.php');
|
21
|
$admin = new admin('Media', 'media_rename', false);
|
22
|
|
23
|
// Include the WB functions file
|
24
|
require_once(WB_PATH.'/framework/functions.php');
|
25
|
|
26
|
// Get the current dir
|
27
|
$directory = $admin->get_get('dir');
|
28
|
$directory = ($directory == '/') ? '' : $directory;
|
29
|
|
30
|
$dirlink = 'browse.php?dir='.$directory;
|
31
|
$rootlink = 'browse.php?dir=';
|
32
|
// $file_id = intval($admin->get_get('id'));
|
33
|
|
34
|
// first Check to see if it contains ..
|
35
|
if (!check_media_path($directory)) {
|
36
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH'],$rootlink, false);
|
37
|
}
|
38
|
|
39
|
// Get the temp id
|
40
|
$file_id = intval($admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']));
|
41
|
if (!$file_id) {
|
42
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$dirlink, false);
|
43
|
}
|
44
|
|
45
|
// Get home folder not to show
|
46
|
$home_folders = get_home_folders();
|
47
|
// Check for potentially malicious files
|
48
|
$forbidden_file_types = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
|
49
|
|
50
|
// Figure out what folder name the temp id is
|
51
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
|
52
|
// Loop through the files and dirs an add to list
|
53
|
while (false !== ($file = readdir($handle))) {
|
54
|
$info = pathinfo($file);
|
55
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
56
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
57
|
if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
|
58
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
59
|
if(!isset($home_folders[$directory.'/'.$file])) {
|
60
|
$DIR[] = $file;
|
61
|
}
|
62
|
} else {
|
63
|
$FILE[] = $file;
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
}
|
68
|
|
69
|
$temp_id = 0;
|
70
|
if(isset($DIR)) {
|
71
|
sort($DIR);
|
72
|
foreach($DIR AS $name) {
|
73
|
$temp_id++;
|
74
|
if($file_id == $temp_id) {
|
75
|
$rename_file = $name;
|
76
|
$type = 'folder';
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
|
81
|
if(isset($FILE)) {
|
82
|
sort($FILE);
|
83
|
foreach($FILE AS $name) {
|
84
|
$temp_id++;
|
85
|
if($file_id == $temp_id) {
|
86
|
$rename_file = $name;
|
87
|
$type = 'file';
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
|
93
|
if(!isset($rename_file)) {
|
94
|
$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
|
95
|
}
|
96
|
|
97
|
// Setup template object, parse vars to it, then parse it
|
98
|
// Create new template object
|
99
|
$template = new Template(dirname($admin->correct_theme_source('media_rename.htt')));
|
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');
|