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 |
2098
|
darkviper
|
//if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
|
27 |
|
|
$oTrans = Translate::getInstance();
|
28 |
|
|
$oTrans->enableAddon('admin\\media');
|
29 |
238
|
stefan
|
|
30 |
1818
|
Luisehahne
|
$admin = new admin('Media', 'media', false);
|
31 |
|
|
|
32 |
238
|
stefan
|
// Include the WB functions file
|
33 |
1824
|
Luisehahne
|
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
|
34 |
238
|
stefan
|
|
35 |
|
|
// Get the current dir
|
36 |
|
|
$directory = $admin->get_get('dir');
|
37 |
1475
|
Luisehahne
|
$directory = ($directory == '/') ? '' : $directory;
|
38 |
1400
|
FrankH
|
|
39 |
1475
|
Luisehahne
|
$dirlink = 'browse.php?dir='.$directory;
|
40 |
|
|
$rootlink = 'browse.php?dir=';
|
41 |
|
|
|
42 |
1818
|
Luisehahne
|
// 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 |
1400
|
FrankH
|
// Check to see if it contains ..
|
50 |
|
|
if (!check_media_path($directory)) {
|
51 |
1414
|
Luisehahne
|
// $admin->print_header();
|
52 |
2098
|
darkviper
|
$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_DOT_DOT_SLASH, $rootlink, false );
|
53 |
238
|
stefan
|
}
|
54 |
|
|
|
55 |
1475
|
Luisehahne
|
// Get the file id
|
56 |
|
|
$file_id = $admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']);
|
57 |
1400
|
FrankH
|
if (!$file_id) {
|
58 |
2098
|
darkviper
|
$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS, $dirlink, false);
|
59 |
238
|
stefan
|
}
|
60 |
|
|
|
61 |
|
|
// Get home folder not to show
|
62 |
|
|
$home_folders = get_home_folders();
|
63 |
1457
|
Luisehahne
|
$usedFiles = array();
|
64 |
|
|
// feature freeze
|
65 |
|
|
// require_once(ADMIN_PATH.'/media/dse.php');
|
66 |
|
|
/*
|
67 |
238
|
stefan
|
|
68 |
1457
|
Luisehahne
|
if(!empty($currentdir)) {
|
69 |
|
|
$usedFiles = $Dse->getMatchesFromDir( $directory, DseTwo::RETURN_USED);
|
70 |
|
|
}
|
71 |
|
|
*/
|
72 |
238
|
stefan
|
// Figure out what folder name the temp id is
|
73 |
2098
|
darkviper
|
if(($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory))) {
|
74 |
238
|
stefan
|
// 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 |
384
|
Ruebenwurz
|
sort($DIR);
|
89 |
238
|
stefan
|
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 |
384
|
Ruebenwurz
|
sort($FILE);
|
99 |
238
|
stefan
|
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 |
2098
|
darkviper
|
$admin->print_error($oTrans->MESSAGE_MEDIA_FILE_NOT_FOUND, $dirlink, false);
|
112 |
238
|
stefan
|
}
|
113 |
|
|
$relative_path = WB_PATH.MEDIA_DIRECTORY.'/'.$directory.'/'.$delete_file;
|
114 |
|
|
// Check if the file/folder exists
|
115 |
|
|
if(!file_exists($relative_path)) {
|
116 |
2098
|
darkviper
|
$admin->print_error($oTrans->MESSAGE_MEDIA_FILE_NOT_FOUND, $dirlink, false);
|
117 |
238
|
stefan
|
}
|
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 |
2098
|
darkviper
|
$admin->print_success($oTrans->MESSAGE_MEDIA_DELETED_DIR, $dirlink);
|
124 |
238
|
stefan
|
} else {
|
125 |
2098
|
darkviper
|
$admin->print_error($oTrans->MESSAGE_MEDIA_CANNOT_DELETE_DIR, $dirlink, false);
|
126 |
238
|
stefan
|
}
|
127 |
|
|
} else {
|
128 |
|
|
// Try and delete the file
|
129 |
|
|
if(unlink($relative_path)) {
|
130 |
2098
|
darkviper
|
$admin->print_success($oTrans->MESSAGE_MEDIA_DELETED_FILE, $dirlink);
|
131 |
238
|
stefan
|
} else {
|
132 |
2098
|
darkviper
|
$admin->print_error($oTrans->MESSAGE_MEDIA_CANNOT_DELETE_FILE, $dirlink, false);
|
133 |
238
|
stefan
|
}
|
134 |
|
|
}
|