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 2098 2014-02-11 01:37:03Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/media/rename.php $
14
 * @lastmodified    $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
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
$oTrans = Translate::getInstance();
28
$oTrans->enableAddon('admin\\media');
29

    
30
$admin = new admin('Media', 'media', false);
31

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

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

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

    
43
// 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
// first Check to see if it contains ..
51
if (!check_media_path($directory)) {
52
	$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_DOT_DOT_SLASH, $rootlink, false);
53
}
54

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

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

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

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

    
97
	if(isset($FILE)) {
98
		sort($FILE);
99
		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
	$admin->print_error($oTrans->MESSAGE_MEDIA_FILE_NOT_FOUND, $dirlink, false);
111
}
112

    
113
// Setup template object, parse vars to it, then parse it
114
// Create new template object
115
$template = new Template(dirname($admin->correct_theme_source('media_rename.htt')));
116
$template->set_file('page', 'media_rename.htt');
117
$template->set_block('page', 'main_block', 'main');
118
//echo WB_PATH.'/media/'.$directory.'/'.$rename_file;
119
$template->set_var($oTrans->getLangArray());
120

    
121
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
					'THEME_URL' => THEME_URL,
137
					'FILENAME' => $rename_file,
138
					'DIR' => $directory,
139
					'FILE_ID' => $admin->getIDKEY($file_id),
140
					// 'FILE_ID' => $file_id,
141
					'TYPE' => $type,
142
					'EXTENSION' => $extension,
143
					'FTAN' => $admin->getFTAN()
144
				)
145
			);
146
// Parse template object
147
$template->parse('main', 'main_block', false);
148
$template->pparse('output', 'page');
(10-10/14)