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 |
2098
|
darkviper
|
//if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
|
27 |
|
|
$oTrans = Translate::getInstance();
|
28 |
|
|
$oTrans->enableAddon('admin\\media');
|
29 |
238
|
stefan
|
|
30 |
1818
|
Luisehahne
|
$admin = new admin('Media', 'media', false);
|
31 |
|
|
|
32 |
238
|
stefan
|
// Include the WB functions file
|
33 |
1824
|
Luisehahne
|
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
|
34 |
238
|
stefan
|
|
35 |
|
|
// Get the current dir
|
36 |
|
|
$directory = $admin->get_get('dir');
|
37 |
1475
|
Luisehahne
|
$directory = ($directory == '/') ? '' : $directory;
|
38 |
1400
|
FrankH
|
|
39 |
1475
|
Luisehahne
|
$dirlink = 'browse.php?dir='.$directory;
|
40 |
|
|
$rootlink = 'browse.php?dir=';
|
41 |
|
|
// $file_id = intval($admin->get_get('id'));
|
42 |
|
|
|
43 |
1818
|
Luisehahne
|
// Get the current dir
|
44 |
|
|
$currentHome = $admin->get_home_folder();
|
45 |
|
|
// check for correct directory
|
46 |
|
|
if ($currentHome && stripos(WB_PATH.MEDIA_DIRECTORY.$rootlink,WB_PATH.MEDIA_DIRECTORY.$currentHome)===false) {
|
47 |
|
|
$rootlink = $currentHome;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
1475
|
Luisehahne
|
// first Check to see if it contains ..
|
51 |
1400
|
FrankH
|
if (!check_media_path($directory)) {
|
52 |
2098
|
darkviper
|
$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_DOT_DOT_SLASH, $rootlink, false);
|
53 |
238
|
stefan
|
}
|
54 |
|
|
|
55 |
|
|
// Get the temp id
|
56 |
1475
|
Luisehahne
|
$file_id = intval($admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']));
|
57 |
1400
|
FrankH
|
if (!$file_id) {
|
58 |
2098
|
darkviper
|
$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS, $dirlink, false);
|
59 |
238
|
stefan
|
}
|
60 |
|
|
|
61 |
|
|
// Get home folder not to show
|
62 |
|
|
$home_folders = get_home_folders();
|
63 |
1476
|
Luisehahne
|
// Check for potentially malicious files
|
64 |
|
|
$forbidden_file_types = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
|
65 |
238
|
stefan
|
|
66 |
|
|
// Figure out what folder name the temp id is
|
67 |
|
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
|
68 |
|
|
// Loop through the files and dirs an add to list
|
69 |
|
|
while (false !== ($file = readdir($handle))) {
|
70 |
1475
|
Luisehahne
|
$info = pathinfo($file);
|
71 |
|
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
72 |
238
|
stefan
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
73 |
1475
|
Luisehahne
|
if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
|
74 |
|
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
75 |
|
|
if(!isset($home_folders[$directory.'/'.$file])) {
|
76 |
|
|
$DIR[] = $file;
|
77 |
|
|
}
|
78 |
|
|
} else {
|
79 |
|
|
$FILE[] = $file;
|
80 |
238
|
stefan
|
}
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
1475
|
Luisehahne
|
|
85 |
238
|
stefan
|
$temp_id = 0;
|
86 |
|
|
if(isset($DIR)) {
|
87 |
384
|
Ruebenwurz
|
sort($DIR);
|
88 |
238
|
stefan
|
foreach($DIR AS $name) {
|
89 |
|
|
$temp_id++;
|
90 |
|
|
if($file_id == $temp_id) {
|
91 |
|
|
$rename_file = $name;
|
92 |
|
|
$type = 'folder';
|
93 |
|
|
}
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
1475
|
Luisehahne
|
|
97 |
238
|
stefan
|
if(isset($FILE)) {
|
98 |
384
|
Ruebenwurz
|
sort($FILE);
|
99 |
238
|
stefan
|
foreach($FILE AS $name) {
|
100 |
|
|
$temp_id++;
|
101 |
|
|
if($file_id == $temp_id) {
|
102 |
|
|
$rename_file = $name;
|
103 |
|
|
$type = 'file';
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
if(!isset($rename_file)) {
|
110 |
2098
|
darkviper
|
$admin->print_error($oTrans->MESSAGE_MEDIA_FILE_NOT_FOUND, $dirlink, false);
|
111 |
238
|
stefan
|
}
|
112 |
|
|
|
113 |
1529
|
Luisehahne
|
// Setup template object, parse vars to it, then parse it
|
114 |
|
|
// Create new template object
|
115 |
1625
|
Luisehahne
|
$template = new Template(dirname($admin->correct_theme_source('media_rename.htt')));
|
116 |
944
|
Ruebenwurz
|
$template->set_file('page', 'media_rename.htt');
|
117 |
238
|
stefan
|
$template->set_block('page', 'main_block', 'main');
|
118 |
|
|
//echo WB_PATH.'/media/'.$directory.'/'.$rename_file;
|
119 |
2098
|
darkviper
|
$template->set_var($oTrans->getLangArray());
|
120 |
|
|
|
121 |
238
|
stefan
|
if($type == 'folder') {
|
122 |
|
|
$template->set_var('DISPlAY_EXTENSION', 'hide');
|
123 |
|
|
$extension = '';
|
124 |
|
|
} else {
|
125 |
|
|
$template->set_var('DISPlAY_EXTENSION', '');
|
126 |
|
|
$extension = strstr($rename_file, '.');
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
if($type == 'folder') {
|
130 |
|
|
$type = $TEXT['FOLDER'];
|
131 |
|
|
} else {
|
132 |
|
|
$type = $TEXT['FILE'];
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
$template->set_var(array(
|
136 |
1457
|
Luisehahne
|
'THEME_URL' => THEME_URL,
|
137 |
|
|
'FILENAME' => $rename_file,
|
138 |
|
|
'DIR' => $directory,
|
139 |
|
|
'FILE_ID' => $admin->getIDKEY($file_id),
|
140 |
1475
|
Luisehahne
|
// 'FILE_ID' => $file_id,
|
141 |
1457
|
Luisehahne
|
'TYPE' => $type,
|
142 |
|
|
'EXTENSION' => $extension,
|
143 |
|
|
'FTAN' => $admin->getFTAN()
|
144 |
|
|
)
|
145 |
|
|
);
|
146 |
238
|
stefan
|
// Parse template object
|
147 |
|
|
$template->parse('main', 'main_block', false);
|
148 |
|
|
$template->pparse('output', 'page');
|