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