Project

General

Profile

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 1529 2011-11-25 05:03:32Z 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
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('media_rename.htt'));
99
// Create new template object
100
$template = new Template($ThemePath);
101
$template->set_file('page', 'media_rename.htt');
102
$template->set_block('page', 'main_block', 'main');
103
//echo WB_PATH.'/media/'.$directory.'/'.$rename_file;
104
if($type == 'folder') {
105
	$template->set_var('DISPlAY_EXTENSION', 'hide');
106
	$extension = '';
107
} else {
108
	$template->set_var('DISPlAY_EXTENSION', '');
109
	$extension = strstr($rename_file, '.');
110
}
111

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

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

    
130

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

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