Project

General

Profile

1 238 stefan
<?php
2 1400 FrankH
/**
3
 *
4
 * @category        admin
5 1476 Luisehahne
 * @package         media
6 1529 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7 1400 FrankH
 * @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$
13
 * @filesource		$HeadURL:  $
14
 * @lastmodified    $Date:  $
15
 *
16
 */
17 238 stefan
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 1475 Luisehahne
$directory = ($directory == '/') ?  '' : $directory;
29 1400 FrankH
30 1475 Luisehahne
$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 1400 FrankH
if (!check_media_path($directory)) {
36 1475 Luisehahne
	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH'],$rootlink, false);
37 238 stefan
}
38
39
// Get the temp id
40 1475 Luisehahne
$file_id = intval($admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']));
41 1400 FrankH
if (!$file_id) {
42 1475 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$dirlink, false);
43 238 stefan
}
44
45
// Get home folder not to show
46
$home_folders = get_home_folders();
47 1476 Luisehahne
// Check for potentially malicious files
48
$forbidden_file_types  = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
49 238 stefan
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 1475 Luisehahne
		$info = pathinfo($file);
55
		$ext = isset($info['extension']) ? $info['extension'] : '';
56 238 stefan
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
57 1475 Luisehahne
			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 238 stefan
				}
65
			}
66
		}
67
	}
68 1475 Luisehahne
69 238 stefan
	$temp_id = 0;
70
	if(isset($DIR)) {
71 384 Ruebenwurz
		sort($DIR);
72 238 stefan
		foreach($DIR AS $name) {
73
			$temp_id++;
74
			if($file_id == $temp_id) {
75
				$rename_file = $name;
76
				$type = 'folder';
77
			}
78
		}
79
	}
80 1475 Luisehahne
81 238 stefan
	if(isset($FILE)) {
82 384 Ruebenwurz
		sort($FILE);
83 238 stefan
		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 1475 Luisehahne
	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
95 238 stefan
}
96
97 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
98
// Create new template object
99 1625 Luisehahne
$template = new Template(dirname($admin->correct_theme_source('media_rename.htt')));
100 944 Ruebenwurz
$template->set_file('page', 'media_rename.htt');
101 238 stefan
$template->set_block('page', 'main_block', 'main');
102
//echo WB_PATH.'/media/'.$directory.'/'.$rename_file;
103
if($type == 'folder') {
104
	$template->set_var('DISPlAY_EXTENSION', 'hide');
105
	$extension = '';
106
} else {
107
	$template->set_var('DISPlAY_EXTENSION', '');
108
	$extension = strstr($rename_file, '.');
109
}
110
111
if($type == 'folder') {
112
	$type = $TEXT['FOLDER'];
113
} else {
114
	$type = $TEXT['FILE'];
115
}
116
117
$template->set_var(array(
118 1457 Luisehahne
					'THEME_URL' => THEME_URL,
119
					'FILENAME' => $rename_file,
120
					'DIR' => $directory,
121
					'FILE_ID' => $admin->getIDKEY($file_id),
122 1475 Luisehahne
					// 'FILE_ID' => $file_id,
123 1457 Luisehahne
					'TYPE' => $type,
124
					'EXTENSION' => $extension,
125
					'FTAN' => $admin->getFTAN()
126
				)
127
			);
128 238 stefan
129
130
// Insert language text and messages
131
$template->set_var(array(
132 1457 Luisehahne
					'TEXT_TO' => $TEXT['TO'],
133
					'TEXT_RENAME' => $TEXT['RENAME'],
134
					'TEXT_CANCEL' => $TEXT['CANCEL'],
135
					'TEXT_UP' => $TEXT['UP'],
136
					'TEXT_OVERWRITE_EXISTING' => $TEXT['OVERWRITE_EXISTING']
137
				)
138
			);
139 238 stefan
140
// Parse template object
141
$template->parse('main', 'main_block', false);
142
$template->pparse('output', 'page');