Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         media
6
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker 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 1824 2012-11-20 17:41:22Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/media/rename.php $
14
 * @lastmodified    $Date: 2012-11-20 18:41:22 +0100 (Tue, 20 Nov 2012) $
15
 *
16
 */
17

    
18
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

    
28
$admin = new admin('Media', 'media', false);
29

    
30
// Include the WB functions file
31
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
32

    
33
// Get the current dir
34
$directory = $admin->get_get('dir');
35
$directory = ($directory == '/') ?  '' : $directory;
36

    
37
$dirlink = 'browse.php?dir='.$directory;
38
$rootlink = 'browse.php?dir=';
39
// $file_id = intval($admin->get_get('id'));
40

    
41
// 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
// first Check to see if it contains ..
49
if (!check_media_path($directory)) {
50
	$admin->print_error($MESSAGE['MEDIA_DIR_DOT_DOT_SLASH'],$rootlink, false);
51
}
52

    
53
// Get the temp id
54
$file_id = intval($admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']));
55
if (!$file_id) {
56
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$dirlink, false);
57
}
58

    
59
// Get home folder not to show
60
$home_folders = get_home_folders();
61
// Check for potentially malicious files
62
$forbidden_file_types  = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
63

    
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
		$info = pathinfo($file);
69
		$ext = isset($info['extension']) ? $info['extension'] : '';
70
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
71
			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
				}
79
			}
80
		}
81
	}
82

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

    
95
	if(isset($FILE)) {
96
		sort($FILE);
97
		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
	$admin->print_error($MESSAGE['MEDIA_FILE_NOT_FOUND'], $dirlink, false);
109
}
110

    
111
// Setup template object, parse vars to it, then parse it
112
// Create new template object
113
$template = new Template(dirname($admin->correct_theme_source('media_rename.htt')));
114
$template->set_file('page', 'media_rename.htt');
115
$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
					'THEME_URL' => THEME_URL,
133
					'FILENAME' => $rename_file,
134
					'DIR' => $directory,
135
					'FILE_ID' => $admin->getIDKEY($file_id),
136
					// 'FILE_ID' => $file_id,
137
					'TYPE' => $type,
138
					'EXTENSION' => $extension,
139
					'FTAN' => $admin->getFTAN()
140
				)
141
			);
142

    
143

    
144
// Insert language text and messages
145
$template->set_var(array(
146
					'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

    
154
// Parse template object
155
$template->parse('main', 'main_block', false);
156
$template->pparse('output', 'page');
(10-10/14)