-
Notifications
You must be signed in to change notification settings - Fork 349
/
Copy pathfilemanager.php
executable file
·182 lines (141 loc) · 3.8 KB
/
filemanager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
// only for debug
// error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// ini_set('display_errors', '1');
/**
* Filemanager PHP connector
*
* filemanager.php
* use for ckeditor filemanager plug-in by Core Five - http://labs.corefive.com/Projects/FileManager/
*
* @license MIT License
* @author Riaan Los <mail (at) riaanlos (dot) nl>
* @author Simon Georget <simon (at) linea21 (dot) com>
* @copyright Authors
*/
require_once('filemanager.class.php');
// for php 5.2 compatibility
if (!function_exists('array_replace_recursive')) {
function array_replace_recursive($array, $array1) {
function recurse($array, $array1) {
foreach($array1 as $key => $value) {
// create new key in $array, if it is empty or not an array
if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key]))) {
$array[$key] = array();
}
// overwrite the value in the base array
if (is_array($value)) {
$value = recurse($array[$key], $value);
}
$array[$key] = $value;
}
return $array;
}
// handle the arguments, merge one by one
$args = func_get_args();
$array = $args[0];
if (!is_array($array)) {
return $array;
}
for ($i = 1; $i < count($args); $i++) {
if (is_array($args[$i])) {
$array = recurse($array, $args[$i]);
}
}
return $array;
}
}
// if user file is defined we include it, else we include the default file
(file_exists('user.config.php')) ? include_once('user.config.php') : include_once('default.config.php');
// auth() function is already defined
// and Filemanager is instantiated as $fm
$response = '';
if(!auth()) {
$fm->error($fm->lang('AUTHORIZATION_REQUIRED'));
}
if(!isset($_GET)) {
$fm->error($fm->lang('INVALID_ACTION'));
} else {
if(isset($_GET['mode']) && $_GET['mode']!='') {
switch($_GET['mode']) {
default:
$fm->error($fm->lang('MODE_ERROR'));
break;
case 'getinfo':
if($fm->getvar('path')) {
$response = $fm->getinfo();
}
break;
case 'getfolder':
if($fm->getvar('path')) {
$response = $fm->getfolder();
}
break;
case 'rename':
if($fm->getvar('old') && $fm->getvar('new')) {
$response = $fm->rename();
}
break;
case 'move':
// allow "../"
if($fm->getvar('old') && $fm->getvar('new') && $fm->getvar('root')) {
$response = $fm->move();
}
break;
case 'editfile':
if($fm->getvar('path')) {
$response = $fm->editfile();
}
break;
case 'delete':
if($fm->getvar('path')) {
$response = $fm->delete();
}
break;
case 'addfolder':
if($fm->getvar('path') && $fm->getvar('name')) {
$response = $fm->addfolder();
}
break;
case 'download':
if($fm->getvar('path')) {
$fm->download();
}
break;
case 'preview':
if($fm->getvar('path')) {
if(isset($_GET['thumbnail'])) {
$thumbnail = true;
} else {
$thumbnail = false;
}
$fm->preview($thumbnail);
}
break;
}
} else if(isset($_POST['mode']) && $_POST['mode']!='') {
switch($_POST['mode']) {
default:
$fm->error($fm->lang('MODE_ERROR'));
break;
case 'add':
if($fm->postvar('currentpath')) {
$fm->add();
}
break;
case 'replace':
if($fm->postvar('newfilepath')) {
$fm->replace();
}
break;
case 'savefile':
if($fm->postvar('content', false) && $fm->postvar('path')) {
$response = $fm->savefile();
}
break;
}
}
}
echo json_encode($response);
die();
?>