Project

General

Profile

1 238 stefan
<?php
2 1400 FrankH
/**
3
 *
4
 * @category        admin
5
 * @package         admintools
6 1818 Luisehahne
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1400 FrankH
 * @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 1818 Luisehahne
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15 1400 FrankH
 *
16
 */
17 238 stefan
18 1818 Luisehahne
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 238 stefan
28 1818 Luisehahne
$admin = new admin('Media', 'media', false);
29
30 238 stefan
// Include the WB functions file
31 1824 Luisehahne
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
32 238 stefan
33
// Get the current dir
34
$directory = $admin->get_get('dir');
35 1475 Luisehahne
$directory = ($directory == '/') ?  '' : $directory;
36 1400 FrankH
37 1475 Luisehahne
$dirlink = 'browse.php?dir='.$directory;
38
$rootlink = 'browse.php?dir=';
39
40 1818 Luisehahne
// Get the current dir
41
$currentHome = $admin->get_home_folder();
42
// check for correct directory
43
if ($currentHome && stripos(WB_PATH.MEDIA_DIRECTORY.$rootlink,WB_PATH.MEDIA_DIRECTORY.$currentHome)===false) {
44
	$rootlink = $currentHome;
45
}
46
47 1400 FrankH
// Check to see if it contains ..
48
if (!check_media_path($directory)) {
49 1414 Luisehahne
	// $admin->print_header();
50 1818 Luisehahne
	$admin->print_error($MESSAGE['MEDIA_DIR_DOT_DOT_SLASH'],$rootlink,false );
51 238 stefan
}
52
53 1475 Luisehahne
// Get the file id
54
$file_id = $admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']);
55 1400 FrankH
if (!$file_id) {
56 1475 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $dirlink,false);
57 238 stefan
}
58
59
// Get home folder not to show
60
$home_folders = get_home_folders();
61 1457 Luisehahne
$usedFiles = array();
62
// feature freeze
63
// require_once(ADMIN_PATH.'/media/dse.php');
64
/*
65 238 stefan
66 1457 Luisehahne
if(!empty($currentdir)) {
67
	$usedFiles = $Dse->getMatchesFromDir( $directory, DseTwo::RETURN_USED);
68
}
69
*/
70 238 stefan
// Figure out what folder name the temp id is
71
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
72
	// Loop through the files and dirs an add to list
73
   while (false !== ($file = readdir($handle))) {
74
		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
75
			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
76
				if(!isset($home_folders[$directory.'/'.$file])) {
77
					$DIR[] = $file;
78
				}
79
			} else {
80
				$FILE[] = $file;
81
			}
82
		}
83
	}
84
	$temp_id = 0;
85
	if(isset($DIR)) {
86 384 Ruebenwurz
		sort($DIR);
87 238 stefan
		foreach($DIR AS $name) {
88
			$temp_id++;
89
			if(!isset($delete_file) AND $file_id == $temp_id) {
90
				$delete_file = $name;
91
				$type = 'folder';
92
			}
93
		}
94
	}
95
	if(isset($FILE)) {
96 384 Ruebenwurz
		sort($FILE);
97 238 stefan
		foreach($FILE AS $name) {
98
			$temp_id++;
99
			if(!isset($delete_file) AND $file_id == $temp_id) {
100
				$delete_file = $name;
101
				$type = 'file';
102
			}
103
		}
104
	}
105
}
106
107
// Check to see if we could find an id to match
108
if(!isset($delete_file)) {
109 1818 Luisehahne
	$admin->print_error($MESSAGE['MEDIA_FILE_NOT_FOUND'], $dirlink, false);
110 238 stefan
}
111
$relative_path = WB_PATH.MEDIA_DIRECTORY.'/'.$directory.'/'.$delete_file;
112
// Check if the file/folder exists
113
if(!file_exists($relative_path)) {
114 1818 Luisehahne
	$admin->print_error($MESSAGE['MEDIA_FILE_NOT_FOUND'], $dirlink, false);
115 238 stefan
}
116
117
// Find out whether its a file or folder
118
if($type == 'folder') {
119
	// Try and delete the directory
120
	if(rm_full_dir($relative_path)) {
121 1818 Luisehahne
		$admin->print_success($MESSAGE['MEDIA_DELETED_DIR'], $dirlink);
122 238 stefan
	} else {
123 1818 Luisehahne
		$admin->print_error($MESSAGE['MEDIA_CANNOT_DELETE_DIR'], $dirlink, false);
124 238 stefan
	}
125
} else {
126
	// Try and delete the file
127
	if(unlink($relative_path)) {
128 1818 Luisehahne
		$admin->print_success($MESSAGE['MEDIA_DELETED_FILE'], $dirlink);
129 238 stefan
	} else {
130 1818 Luisehahne
		$admin->print_error($MESSAGE['MEDIA_CANNOT_DELETE_FILE'], $dirlink, false);
131 238 stefan
	}
132
}