Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         admintools
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 1475 2011-07-12 23:07:10Z 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 and append 'txt' to their name
49
$rename_file_types  = str_replace(',','|',RENAME_FILES_ON_UPLOAD);
50
// hardcodet forbidden filetypes
51
$forbidden_file_types = 'phtml|php5|php4|php|cgi|pl|exe|com|bat|src|'.$rename_file_types;
52

    
53
// Figure out what folder name the temp id is
54
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
55
	// Loop through the files and dirs an add to list
56
   while (false !== ($file = readdir($handle))) {
57
		$info = pathinfo($file);
58
		$ext = isset($info['extension']) ? $info['extension'] : '';
59
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
60
			if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
61
				if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
62
					if(!isset($home_folders[$directory.'/'.$file])) {
63
						$DIR[] = $file;
64
					}
65
				} else {
66
					$FILE[] = $file;
67
				}
68
			}
69
		}
70
	}
71

    
72
	$temp_id = 0;
73
	if(isset($DIR)) {
74
		sort($DIR);
75
		foreach($DIR AS $name) {
76
			$temp_id++;
77
			if($file_id == $temp_id) {
78
				$rename_file = $name;
79
				$type = 'folder';
80
			}
81
		}
82
	}
83

    
84
	if(isset($FILE)) {
85
		sort($FILE);
86
		foreach($FILE AS $name) {
87
			$temp_id++;
88
			if($file_id == $temp_id) {
89
				$rename_file = $name;
90
				$type = 'file';
91
			}
92
		}
93
	}
94
}
95

    
96
if(!isset($rename_file)) {
97
	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
98
}
99

    
100
// Setup template object
101
$template = new Template(THEME_PATH.'/templates');
102
$template->set_file('page', 'media_rename.htt');
103
$template->set_block('page', 'main_block', 'main');
104
//echo WB_PATH.'/media/'.$directory.'/'.$rename_file;
105
if($type == 'folder') {
106
	$template->set_var('DISPlAY_EXTENSION', 'hide');
107
	$extension = '';
108
} else {
109
	$template->set_var('DISPlAY_EXTENSION', '');
110
	$extension = strstr($rename_file, '.');
111
}
112

    
113
if($type == 'folder') {
114
	$type = $TEXT['FOLDER'];
115
} else {
116
	$type = $TEXT['FILE'];
117
}
118

    
119
$template->set_var(array(
120
					'THEME_URL' => THEME_URL,
121
					'FILENAME' => $rename_file,
122
					'DIR' => $directory,
123
					'FILE_ID' => $admin->getIDKEY($file_id),
124
					// 'FILE_ID' => $file_id,
125
					'TYPE' => $type,
126
					'EXTENSION' => $extension,
127
					'FTAN' => $admin->getFTAN()
128
				)
129
			);
130

    
131

    
132
// Insert language text and messages
133
$template->set_var(array(
134
					'TEXT_TO' => $TEXT['TO'],
135
					'TEXT_RENAME' => $TEXT['RENAME'],
136
					'TEXT_CANCEL' => $TEXT['CANCEL'],
137
					'TEXT_UP' => $TEXT['UP'],
138
					'TEXT_OVERWRITE_EXISTING' => $TEXT['OVERWRITE_EXISTING']
139
				)
140
			);
141

    
142
// Parse template object
143
$template->parse('main', 'main_block', false);
144
$template->pparse('output', 'page');
(11-11/16)