Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         admintools
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: delete.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/delete.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

    
42
// Get the current dir
43
$currentHome = $admin->get_home_folder();
44
// check for correct directory
45
if ($currentHome && stripos(WB_PATH.MEDIA_DIRECTORY.$rootlink,WB_PATH.MEDIA_DIRECTORY.$currentHome)===false) {
46
	$rootlink = $currentHome;
47
}
48

    
49
// Check to see if it contains ..
50
if (!check_media_path($directory)) {
51
	// $admin->print_header();
52
	$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_DOT_DOT_SLASH, $rootlink, false );
53
}
54

    
55
// Get the file id
56
$file_id = $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
$usedFiles = array();
64
// feature freeze
65
// require_once(ADMIN_PATH.'/media/dse.php');
66
/*
67

    
68
if(!empty($currentdir)) {
69
	$usedFiles = $Dse->getMatchesFromDir( $directory, DseTwo::RETURN_USED);
70
}
71
*/
72
// Figure out what folder name the temp id is
73
if(($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory))) {
74
	// Loop through the files and dirs an add to list
75
   while (false !== ($file = readdir($handle))) {
76
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
77
			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
78
				if(!isset($home_folders[$directory.'/'.$file])) {
79
					$DIR[] = $file;
80
				}
81
			} else {
82
				$FILE[] = $file;
83
			}
84
		}
85
	}
86
	$temp_id = 0;
87
	if(isset($DIR)) {
88
		sort($DIR);
89
		foreach($DIR AS $name) {
90
			$temp_id++;
91
			if(!isset($delete_file) AND $file_id == $temp_id) {
92
				$delete_file = $name;
93
				$type = 'folder';
94
			}
95
		}
96
	}
97
	if(isset($FILE)) {
98
		sort($FILE);
99
		foreach($FILE AS $name) {
100
			$temp_id++;
101
			if(!isset($delete_file) AND $file_id == $temp_id) {
102
				$delete_file = $name;
103
				$type = 'file';
104
			}
105
		}
106
	}
107
}
108

    
109
// Check to see if we could find an id to match
110
if(!isset($delete_file)) {
111
	$admin->print_error($oTrans->MESSAGE_MEDIA_FILE_NOT_FOUND, $dirlink, false);
112
}
113
$relative_path = WB_PATH.MEDIA_DIRECTORY.'/'.$directory.'/'.$delete_file;
114
// Check if the file/folder exists
115
if(!file_exists($relative_path)) {
116
	$admin->print_error($oTrans->MESSAGE_MEDIA_FILE_NOT_FOUND, $dirlink, false);
117
}
118

    
119
// Find out whether its a file or folder
120
if($type == 'folder') {
121
	// Try and delete the directory
122
	if(rm_full_dir($relative_path)) {
123
		$admin->print_success($oTrans->MESSAGE_MEDIA_DELETED_DIR, $dirlink);
124
	} else {
125
		$admin->print_error($oTrans->MESSAGE_MEDIA_CANNOT_DELETE_DIR, $dirlink, false);
126
	}
127
} else {
128
	// Try and delete the file
129
	if(unlink($relative_path)) {
130
		$admin->print_success($oTrans->MESSAGE_MEDIA_DELETED_FILE, $dirlink);
131
	} else {
132
		$admin->print_error($oTrans->MESSAGE_MEDIA_CANNOT_DELETE_FILE, $dirlink, false);
133
	}
134
}
(5-5/14)