0
|
1 |
<?php |
|
2 |
if ( ! defined( 'ABSPATH' ) ) |
|
3 |
die(); |
|
4 |
function wp_fileman_remove_directory($directory) ## Remove a directory recursively |
|
5 |
{ |
|
6 |
$list_sub = array(); |
|
7 |
$list_files = array(); |
|
8 |
|
|
9 |
if (!($open = @opendir($directory))) |
|
10 |
return FALSE; |
|
11 |
|
|
12 |
while(($index = @readdir($open)) != FALSE) |
|
13 |
{ |
|
14 |
if (is_dir($directory.$index) && $index != "." && $index != "..") |
|
15 |
$list_sub[] = $index."/"; |
|
16 |
else if (is_file($directory.$index)) |
|
17 |
$list_files[] = $index; |
|
18 |
} |
|
19 |
|
|
20 |
closedir($open); |
|
21 |
|
|
22 |
foreach($list_files as $file) |
|
23 |
if (!@unlink($directory.$file)) |
|
24 |
return FALSE; |
|
25 |
|
|
26 |
foreach($list_sub as $sub) |
|
27 |
{ |
|
28 |
wp_fileman_remove_directory($directory.$sub); |
|
29 |
if (!@rmdir($directory.$sub)) |
|
30 |
return FALSE; |
|
31 |
} |
|
32 |
|
|
33 |
return TRUE; |
|
34 |
} |
|
35 |
|
|
36 |
function wp_fileman_get_icon($filename) ## Get the icon from the filename |
|
37 |
{ |
|
38 |
global $IconArray; |
|
39 |
|
|
40 |
@reset($IconArray); |
|
41 |
|
|
42 |
$extension = strtolower(substr(strrchr($filename, "."),1)); |
|
43 |
|
|
44 |
if ($extension == "") |
|
45 |
return "unknown.gif"; |
|
46 |
|
|
47 |
while (list($icon, $types) = each($IconArray)) |
|
48 |
foreach (explode(" ", $types) as $type) |
|
49 |
if ($extension == $type) |
|
50 |
return $icon; |
|
51 |
|
|
52 |
return "unknown.gif"; |
|
53 |
} |
|
54 |
|
|
55 |
function wp_fileman_compare_filedata ($a, $b) ## Compare filedata (used to sort) |
|
56 |
{ |
|
57 |
if (is_int($a[$_GET['sortby']]) && is_int($b[$_GET['sortby']])) |
|
58 |
{ |
|
59 |
if ($a[$_GET['sortby']]==$b[$_GET['sortby']]) return 0; |
|
60 |
|
|
61 |
if ($_GET['order'] == "asc") |
|
62 |
{ |
|
63 |
if ($a[$_GET['sortby']] > $b[$_GET['sortby']]) return 1; |
|
64 |
else return -1; |
|
65 |
} |
|
66 |
else if ($_GET['order'] == "desc") |
|
67 |
{ |
|
68 |
if ($a[$_GET['sortby']] < $b[$_GET['sortby']]) return 1; |
|
69 |
else return -1; |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
else if (is_string($a[$_GET['sortby']]) && is_string($b[$_GET['sortby']]) && $_GET['order'] == "asc") |
|
74 |
return strcmp($a[$_GET['sortby']], $b[$_GET['sortby']]); |
|
75 |
else if (is_string($a[$_GET['sortby']]) && is_string($b[$_GET['sortby']]) && $_GET['order'] == "desc") |
|
76 |
return -strcmp($a[$_GET['sortby']], $b[$_GET['sortby']]); |
|
77 |
} |
|
78 |
|
|
79 |
function wp_fileman_get_opposite_order($input, $order) ## Get opposite order |
|
80 |
{ |
|
81 |
if ($_GET['sortby'] == $input) |
|
82 |
{ |
|
83 |
if ($order == "asc") |
|
84 |
return "desc"; |
|
85 |
else if ($order == "desc") |
|
86 |
return "asc"; |
|
87 |
} |
|
88 |
else |
|
89 |
return "asc"; |
|
90 |
} |
|
91 |
|
|
92 |
function wp_fileman_is_editable_file($filename) ## Checks whether a file is editable |
|
93 |
{ |
|
94 |
global $EditableFiles; |
|
95 |
|
|
96 |
$extension = strtolower(substr(strrchr($filename, "."),1)); |
|
97 |
|
|
98 |
foreach(explode(",", $EditableFiles) as $type) |
|
99 |
if ($extension == $type) |
|
100 |
return TRUE; |
|
101 |
|
|
102 |
return FALSE; |
|
103 |
} |
|
104 |
|
|
105 |
function wp_fileman_is_viewable_file($filename) ## Checks whether a file is viewable |
|
106 |
{ |
|
107 |
global $ViewableFiles; |
|
108 |
|
|
109 |
$extension = strtolower(substr(strrchr($filename, "."),1)); |
|
110 |
|
|
111 |
foreach(explode(",", $ViewableFiles) as $type) |
|
112 |
if ($extension == $type) |
|
113 |
return TRUE; |
|
114 |
|
|
115 |
return FALSE; |
|
116 |
} |
|
117 |
|
|
118 |
function wp_fileman_is_valid_name($input) ## Checks whether the directory- or filename is valid |
|
119 |
{ |
|
120 |
if (strstr($input, "\\")) |
|
121 |
return FALSE; |
|
122 |
else if (strstr($input, "/")) |
|
123 |
return FALSE; |
|
124 |
else if (strstr($input, ":")) |
|
125 |
return FALSE; |
|
126 |
else if (strstr($input, "?")) |
|
127 |
return FALSE; |
|
128 |
else if (strstr($input, "*")) |
|
129 |
return FALSE; |
|
130 |
else if (strstr($input, "\"")) |
|
131 |
return FALSE; |
|
132 |
else if (strstr($input, "<")) |
|
133 |
return FALSE; |
|
134 |
else if (strstr($input, ">")) |
|
135 |
return FALSE; |
|
136 |
else if (strstr($input, "|")) |
|
137 |
return FALSE; |
|
138 |
else |
|
139 |
return TRUE; |
|
140 |
} |
|
141 |
|
|
142 |
function wp_fileman_get_better_filesize($filesize) ## Converts filesize to KB/MB/GB/TB |
|
143 |
{ |
|
144 |
$kilobyte = 1024; |
|
145 |
$megabyte = 1048576; |
|
146 |
$gigabyte = 1073741824; |
|
147 |
$terabyte = 1099511627776; |
|
148 |
|
|
149 |
if ($filesize >= $terabyte) |
|
150 |
return number_format($filesize/$terabyte, 2, ',', '.')." TB"; |
|
151 |
else if ($filesize >= $gigabyte) |
|
152 |
return number_format($filesize/$gigabyte, 2, ',', '.')." GB"; |
|
153 |
else if ($filesize >= $megabyte) |
|
154 |
return number_format($filesize/$megabyte, 2, ',', '.')." MB"; |
|
155 |
else if ($filesize >= $kilobyte) |
|
156 |
return number_format($filesize/$kilobyte, 2, ',', '.')." KB"; |
|
157 |
else |
|
158 |
return number_format($filesize, 0, ',', '.')." B"; |
|
159 |
} |
|
160 |
|
|
161 |
function wp_fileman_get_current_zoom_level($current_zoom_level, $zoom) ## Get current zoom level |
|
162 |
{ |
|
163 |
global $ZoomArray; |
|
164 |
|
|
165 |
@reset($ZoomArray); |
|
166 |
|
|
167 |
while(list($number, $zoom_level) = each($ZoomArray)) |
|
168 |
if ($zoom_level == $current_zoom_level) |
|
169 |
if (($number+$zoom) < 0) return $number; |
|
170 |
else if (($number+$zoom) >= count($ZoomArray)) return $number; |
|
171 |
else return $number+$zoom; |
|
172 |
} |
|
173 |
|
|
174 |
function wp_fileman_validate_path($wp_fileman_path) ## Validate path |
|
175 |
{ |
|
176 |
global $StrAccessDenied; |
|
177 |
|
|
178 |
if (stristr($wp_fileman_path, "../") || stristr($wp_fileman_path, "..\\")) |
|
179 |
return TRUE; |
|
180 |
else |
|
181 |
return stripslashes($wp_fileman_path); |
|
182 |
} |
|
183 |
|
|
184 |
function wp_fileman_authenticate_user() ## Authenticate user using cookies |
|
185 |
{ |
|
186 |
global $username, $password; |
|
187 |
|
|
188 |
if (isset($_COOKIE['cookie_username']) && $_COOKIE['cookie_username'] == $username && isset($_COOKIE['cookie_password']) && $_COOKIE['cookie_password'] == md5($password)) |
|
189 |
return TRUE; |
|
190 |
else |
|
191 |
return FALSE; |
|
192 |
} |
|
193 |
|
|
194 |
function wp_fileman_is_hidden_file($wp_fileman_path) ## Checks whether the file is hidden. |
|
195 |
{ |
|
196 |
global $hide_file_extension, $hide_file_string, $hide_directory_string; |
|
197 |
|
|
198 |
$extension = strtolower(substr(strrchr($wp_fileman_path, "."),1)); |
|
199 |
|
|
200 |
if (is_array($hide_file_extension)) |
|
201 |
{ |
|
202 |
foreach ($hide_file_extension as $hidden_extension) |
|
203 |
{ |
|
204 |
if ($hidden_extension == $extension) |
|
205 |
{ |
|
206 |
return TRUE; |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
if (is_array($hide_file_string)) |
|
211 |
{ |
|
212 |
foreach ($hide_file_string as $hidden_string) |
|
213 |
{ |
|
214 |
if ($hidden_string != "" && stristr(basename($wp_fileman_path), $hidden_string)) |
|
215 |
{ |
|
216 |
return TRUE; |
|
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
return FALSE; |
|
221 |
} |
|
222 |
|
|
223 |
function wp_fileman_is_hidden_directory($wp_fileman_path) ## Checks whether the directory is hidden. |
|
224 |
{ |
|
225 |
global $hide_directory_string; |
|
226 |
|
|
227 |
if (is_array($hide_directory_string)) |
|
228 |
foreach ($hide_directory_string as $hidden_string) |
|
229 |
if ($hidden_string != "" && stristr($wp_fileman_path, $hidden_string)) |
|
230 |
return TRUE; |
|
231 |
|
|
232 |
return FALSE; |
|
233 |
} |
|
234 |
|
|
235 |
function wp_fileman_get_mimetype($filename) ## Get MIME-type for file |
|
236 |
{ |
|
237 |
global $MIMEtypes; |
|
238 |
@reset($MIMEtypes); |
|
239 |
$extension = strtolower(substr(strrchr($filename, "."),1)); |
|
240 |
if ($extension == "") |
|
241 |
return "Unknown/Unknown"; |
|
242 |
while (list($mimetype, $file_extensions) = each($MIMEtypes)) |
|
243 |
foreach (explode(" ", $file_extensions) as $file_extension) |
|
244 |
if ($extension == $file_extension) |
|
245 |
return $mimetype; |
|
246 |
|
|
247 |
return "Unknown/Unknown"; |
|
248 |
} |
|
249 |
|
|
250 |
function wp_fileman_get_linked_path($wp_fileman_path,$base_url) ## Get path with links to each folder |
|
251 |
{ |
|
252 |
$string = "<a href='$base_url'>.</a> / "; |
|
253 |
$array = explode("/",htmlentities($wp_fileman_path)); |
|
254 |
unset($array[count($array)-1]); |
|
255 |
foreach ($array as $entry) |
|
256 |
{ |
|
257 |
@$temppath .= $entry."/"; |
|
258 |
$string .= "<a href='$base_url&path=".htmlentities(rawurlencode($temppath))."'>$entry</a> / "; |
|
259 |
} |
|
260 |
|
|
261 |
return $string; |
|
262 |
} |
|
263 |
?> |