· 6 years ago · Aug 28, 2019, 06:18 AM
1<?php
2/**
3 * File Manager Script
4 */
5
6// Default language ('en' and other from 'filemanager-l10n.php')
7$lang = 'en';
8
9// Auth with login/password (set true/false to enable/disable it)
10$use_auth = true;
11
12// Users: array('Username' => 'Password', 'Username2' => 'Password2', ...), Password has to encripted into MD5
13$auth_users = array(
14 'admin' => '21232f297a57a5a743894a0e4a801fc3', //admin
15 'user' => '353f8d8384ab459346cbfa13b366b74d', //12345
16);
17
18// Readonly users (usernames array)
19$readonly_users = array(
20 'user'
21);
22
23// Show or hide files and folders that starts with a dot
24$show_hidden_files = true;
25
26// Enable highlight.js (https://highlightjs.org/) on view's page
27$use_highlightjs = true;
28
29// highlight.js style
30$highlightjs_style = 'vs';
31
32// Enable ace.js (https://ace.c9.io/) on view's page
33$edit_files = true;
34
35// Send files though mail
36$send_mail = false;
37
38// Send files though mail
39$toMailId = ""; //yourmailid@mail.com
40
41// Default timezone for date() and time() - http://php.net/manual/en/timezones.php
42$default_timezone = 'Etc/GMT+8'; // UTC
43
44// Root url for links in file manager.Relative to $http_host. Variants: '', 'path/to/subfolder'
45// Will not working if $root_path will be outside of server document root
46$root_url = 'img-hosting';
47
48// Root path for file manager
49$root_path = $_SERVER['DOCUMENT_ROOT'] . '/' . $root_url;
50
51// Server hostname. Can set manually if wrong
52$http_host = $_SERVER['HTTP_HOST'];
53
54// input encoding for iconv
55$iconv_input_encoding = 'UTF-8';
56
57// date() format for file modification date
58$datetime_format = 'd.m.y H:i';
59
60// include user config php file
61if (defined('FM_CONFIG') && is_file(FM_CONFIG) ) {
62 include(FM_CONFIG);
63}
64
65//--- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL
66
67// if fm included
68if (defined('FM_EMBED')) {
69 $use_auth = false;
70} else {
71 @set_time_limit(600);
72
73 date_default_timezone_set($default_timezone);
74
75 ini_set('default_charset', 'UTF-8');
76 if (version_compare(PHP_VERSION, '5.6.0', '<') && function_exists('mb_internal_encoding')) {
77 mb_internal_encoding('UTF-8');
78 }
79 if (function_exists('mb_regex_encoding')) {
80 mb_regex_encoding('UTF-8');
81 }
82
83 session_cache_limiter('');
84 session_name('filemanager');
85 session_start();
86}
87
88if (empty($auth_users)) {
89 $use_auth = false;
90}
91
92$is_https = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1)
93 || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
94
95// clean and check $root_path
96$root_path = rtrim($root_path, '\\/');
97$root_path = str_replace('\\', '/', $root_path);
98if (!@is_dir($root_path)) {
99 echo "<h1>Root path \"{$root_path}\" not found!</h1>";
100 exit;
101}
102
103// clean $root_url
104$root_url = fm_clean_path($root_url);
105
106// abs path for site
107defined('FM_SHOW_HIDDEN') || define('FM_SHOW_HIDDEN', $show_hidden_files);
108defined('FM_ROOT_PATH') || define('FM_ROOT_PATH', $root_path);
109defined('FM_ROOT_URL') || define('FM_ROOT_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . (!empty($root_url) ? '/' . $root_url : ''));
110defined('FM_SELF_URL') || define('FM_SELF_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . $_SERVER['PHP_SELF']);
111
112$languages = fm_get_available_langs();
113
114// logout
115if (isset($_GET['logout'])) {
116 unset($_SESSION['logged']);
117 fm_redirect(FM_SELF_URL);
118}
119
120// Show image here
121if (isset($_GET['img'])) {
122 fm_show_image($_GET['img']);
123}
124
125// Auth
126if ($use_auth) {
127 if (isset($_SESSION['logged'], $auth_users[$_SESSION['logged']])) {
128 // Logged
129 } elseif (isset($_POST['fm_usr'], $_POST['fm_pwd'])) {
130 // Logging In
131 sleep(1);
132 if (isset($auth_users[$_POST['fm_usr']]) && md5($_POST['fm_pwd']) === $auth_users[$_POST['fm_usr']]) {
133 $_SESSION['logged'] = $_POST['fm_usr'];
134 fm_set_msg('You are logged in');
135 fm_redirect(FM_SELF_URL . '?p=');
136 } else {
137 unset($_SESSION['logged']);
138 fm_set_msg('Wrong password', 'error');
139 fm_redirect(FM_SELF_URL);
140 }
141 } else {
142 // Form
143 unset($_SESSION['logged']);
144 fm_show_header();
145 fm_show_message();
146 ?>
147 <div class="path login-form">
148 <form action="" method="post">
149 <label for="fm_usr"><?php echo fm_t('Username', $lang) ?></label><input type="text" id="fm_usr" name="fm_usr" value="" placeholder="<?php echo fm_t('Username', $lang) ?>" required><br>
150 <label for="fm_pwd"><?php echo fm_t('Password', $lang) ?></label><input type="password" id="fm_pwd" name="fm_pwd" value="" placeholder="<?php echo fm_t('Password', $lang) ?>" required><br>
151 <select name="lang" title="Language" class="hidden">
152 <?php foreach ($languages as $l): ?>
153 <option value="<?php echo $l ?>"<?php echo $l == $lang ? ' selected' : '' ?>><?php echo $l ?></option>
154 <?php endforeach; ?>
155 </select>
156 <input type="submit" value="<?php echo fm_t('Login', $lang) ?>">
157 </form>
158 </div>
159 <?php
160 fm_show_footer();
161 exit;
162 }
163}
164
165defined('FM_LANG') || define('FM_LANG', $lang);
166define('FM_READONLY', $use_auth && !empty($readonly_users) && isset($_SESSION['logged']) && in_array($_SESSION['logged'], $readonly_users));
167define('FM_IS_WIN', DIRECTORY_SEPARATOR == '\\');
168
169// always use ?p=
170if (!isset($_GET['p'])) {
171 fm_redirect(FM_SELF_URL . '?p=');
172}
173
174// get path
175$p = isset($_GET['p']) ? $_GET['p'] : (isset($_POST['p']) ? $_POST['p'] : '');
176
177// clean path
178$p = fm_clean_path($p);
179
180// instead globals vars
181define('FM_PATH', $p);
182define('FM_USE_AUTH', $use_auth);
183defined('FM_ICONV_INPUT_ENC') || define('FM_ICONV_INPUT_ENC', $iconv_input_encoding);
184defined('FM_USE_HIGHLIGHTJS') || define('FM_USE_HIGHLIGHTJS', $use_highlightjs);
185defined('FM_HIGHLIGHTJS_STYLE') || define('FM_HIGHLIGHTJS_STYLE', $highlightjs_style);
186defined('FM_DATETIME_FORMAT') || define('FM_DATETIME_FORMAT', $datetime_format);
187
188unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style);
189
190/*************************** ACTIONS ***************************/
191
192//AJAX Request
193if (isset($_POST['ajax']) && !FM_READONLY) {
194
195 //search : get list of files from the current folder
196 if(isset($_POST['type']) && $_POST['type']=="search") {
197 $dir = $_POST['path'];
198 $response = scan($dir);
199 echo json_encode($response);
200 }
201
202 //Send file to mail
203 if (isset($_POST['type']) && $_POST['type']=="mail") {
204 $isSend = send_mail($_POST['path'],$_POST['file'], $toMailId, 'File attached');
205 echo $isSend;
206 }
207
208 //backup files
209 if(isset($_POST['type']) && $_POST['type']=="backup") {
210 $file = $_POST['file'];
211 $path = $_POST['path'];
212 $date = date("dMy-His");
213 $newFile = $file.'-'.$date.'.bak';
214 copy($path.'/'.$file, $path.'/'.$newFile) or die("Unable to backup");
215 echo "Backup $newFile Created";
216 }
217
218 exit;
219}
220
221// Delete file / folder
222if (isset($_GET['del']) && !FM_READONLY) {
223 $del = $_GET['del'];
224 $del = fm_clean_path($del);
225 $del = str_replace('/', '', $del);
226 if ($del != '' && $del != '..' && $del != '.') {
227 $path = FM_ROOT_PATH;
228 if (FM_PATH != '') {
229 $path .= '/' . FM_PATH;
230 }
231 $is_dir = is_dir($path . '/' . $del);
232 if (fm_rdelete($path . '/' . $del)) {
233 $msg = $is_dir ? 'Folder <b>%s</b> deleted' : 'File <b>%s</b> deleted';
234 fm_set_msg(sprintf($msg, $del));
235 } else {
236 $msg = $is_dir ? 'Folder <b>%s</b> not deleted' : 'File <b>%s</b> not deleted';
237 fm_set_msg(sprintf($msg, $del), 'error');
238 }
239 } else {
240 fm_set_msg('Wrong file or folder name', 'error');
241 }
242 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
243}
244
245// Create folder
246if (isset($_GET['new']) && isset($_GET['type']) && !FM_READONLY) {
247 $new = $_GET['new'];
248 $type = $_GET['type'];
249 $new = fm_clean_path($new);
250 $new = str_replace('/', '', $new);
251 if ($new != '' && $new != '..' && $new != '.') {
252 $path = FM_ROOT_PATH;
253 if (FM_PATH != '') {
254 $path .= '/' . FM_PATH;
255 }
256 if($_GET['type']=="file") {
257 if(!file_exists($path . '/' . $new)) {
258 @fopen($path . '/' . $new, 'w') or die('Cannot open file: '.$new);
259 fm_set_msg(sprintf(fm_t('File <b>%s</b> created'), $new));
260 } else {
261 fm_set_msg(sprintf(fm_t('File <b>%s</b> already exists'), $new), 'alert');
262 }
263 } else {
264 if (fm_mkdir($path . '/' . $new, false) === true) {
265 fm_set_msg(sprintf(fm_t('Folder <b>%s</b> created'), $new));
266 } elseif (fm_mkdir($path . '/' . $new, false) === $path . '/' . $new) {
267 fm_set_msg(sprintf(fm_t('Folder <b>%s</b> already exists'), $new), 'alert');
268 } else {
269 fm_set_msg(sprintf(fm_t('Folder <b>%s</b> not created'), $new), 'error');
270 }
271 }
272 } else {
273 fm_set_msg('Wrong folder name', 'error');
274 }
275 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
276}
277
278// Copy folder / file
279if (isset($_GET['copy'], $_GET['finish']) && !FM_READONLY) {
280 // from
281 $copy = $_GET['copy'];
282 $copy = fm_clean_path($copy);
283 // empty path
284 if ($copy == '') {
285 fm_set_msg('Source path not defined', 'error');
286 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
287 }
288 // abs path from
289 $from = FM_ROOT_PATH . '/' . $copy;
290 // abs path to
291 $dest = FM_ROOT_PATH;
292 if (FM_PATH != '') {
293 $dest .= '/' . FM_PATH;
294 }
295 $dest .= '/' . basename($from);
296 // move?
297 $move = isset($_GET['move']);
298 // copy/move
299 if ($from != $dest) {
300 $msg_from = trim(FM_PATH . '/' . basename($from), '/');
301 if ($move) {
302 $rename = fm_rename($from, $dest);
303 if ($rename) {
304 fm_set_msg(sprintf('Moved from <b>%s</b> to <b>%s</b>', $copy, $msg_from));
305 } elseif ($rename === null) {
306 fm_set_msg('File or folder with this path already exists', 'alert');
307 } else {
308 fm_set_msg(sprintf('Error while moving from <b>%s</b> to <b>%s</b>', $copy, $msg_from), 'error');
309 }
310 } else {
311 if (fm_rcopy($from, $dest)) {
312 fm_set_msg(sprintf('Copyied from <b>%s</b> to <b>%s</b>', $copy, $msg_from));
313 } else {
314 fm_set_msg(sprintf('Error while copying from <b>%s</b> to <b>%s</b>', $copy, $msg_from), 'error');
315 }
316 }
317 } else {
318 fm_set_msg('Paths must be not equal', 'alert');
319 }
320 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
321}
322
323// Mass copy files/ folders
324if (isset($_POST['file'], $_POST['copy_to'], $_POST['finish']) && !FM_READONLY) {
325 // from
326 $path = FM_ROOT_PATH;
327 if (FM_PATH != '') {
328 $path .= '/' . FM_PATH;
329 }
330 // to
331 $copy_to_path = FM_ROOT_PATH;
332 $copy_to = fm_clean_path($_POST['copy_to']);
333 if ($copy_to != '') {
334 $copy_to_path .= '/' . $copy_to;
335 }
336 if ($path == $copy_to_path) {
337 fm_set_msg('Paths must be not equal', 'alert');
338 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
339 }
340 if (!is_dir($copy_to_path)) {
341 if (!fm_mkdir($copy_to_path, true)) {
342 fm_set_msg('Unable to create destination folder', 'error');
343 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
344 }
345 }
346 // move?
347 $move = isset($_POST['move']);
348 // copy/move
349 $errors = 0;
350 $files = $_POST['file'];
351 if (is_array($files) && count($files)) {
352 foreach ($files as $f) {
353 if ($f != '') {
354 // abs path from
355 $from = $path . '/' . $f;
356 // abs path to
357 $dest = $copy_to_path . '/' . $f;
358 // do
359 if ($move) {
360 $rename = fm_rename($from, $dest);
361 if ($rename === false) {
362 $errors++;
363 }
364 } else {
365 if (!fm_rcopy($from, $dest)) {
366 $errors++;
367 }
368 }
369 }
370 }
371 if ($errors == 0) {
372 $msg = $move ? 'Selected files and folders moved' : 'Selected files and folders copied';
373 fm_set_msg($msg);
374 } else {
375 $msg = $move ? 'Error while moving items' : 'Error while copying items';
376 fm_set_msg($msg, 'error');
377 }
378 } else {
379 fm_set_msg('Nothing selected', 'alert');
380 }
381 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
382}
383
384// Rename
385if (isset($_GET['ren'], $_GET['to']) && !FM_READONLY) {
386 // old name
387 $old = $_GET['ren'];
388 $old = fm_clean_path($old);
389 $old = str_replace('/', '', $old);
390 // new name
391 $new = $_GET['to'];
392 $new = fm_clean_path($new);
393 $new = str_replace('/', '', $new);
394 // path
395 $path = FM_ROOT_PATH;
396 if (FM_PATH != '') {
397 $path .= '/' . FM_PATH;
398 }
399 // rename
400 if ($old != '' && $new != '') {
401 if (fm_rename($path . '/' . $old, $path . '/' . $new)) {
402 fm_set_msg(sprintf('Renamed from <b>%s</b> to <b>%s</b>', $old, $new));
403 } else {
404 fm_set_msg(sprintf('Error while renaming from <b>%s</b> to <b>%s</b>', $old, $new), 'error');
405 }
406 } else {
407 fm_set_msg('Names not set', 'error');
408 }
409 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
410}
411
412// Download
413if (isset($_GET['dl'])) {
414 $dl = $_GET['dl'];
415 $dl = fm_clean_path($dl);
416 $dl = str_replace('/', '', $dl);
417 $path = FM_ROOT_PATH;
418 if (FM_PATH != '') {
419 $path .= '/' . FM_PATH;
420 }
421 if ($dl != '' && is_file($path . '/' . $dl)) {
422 header('Content-Description: File Transfer');
423 header('Content-Type: application/octet-stream');
424 header('Content-Disposition: attachment; filename="' . basename($path . '/' . $dl) . '"');
425 header('Content-Transfer-Encoding: binary');
426 header('Connection: Keep-Alive');
427 header('Expires: 0');
428 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
429 header('Pragma: public');
430 header('Content-Length: ' . filesize($path . '/' . $dl));
431 readfile($path . '/' . $dl);
432 exit;
433 } else {
434 fm_set_msg('File not found', 'error');
435 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
436 }
437}
438
439// Upload
440if (isset($_POST['upl']) && !FM_READONLY) {
441 $path = FM_ROOT_PATH;
442 if (FM_PATH != '') {
443 $path .= '/' . FM_PATH;
444 }
445
446 $errors = 0;
447 $uploads = 0;
448 $total = count($_FILES['upload']['name']);
449
450 for ($i = 0; $i < $total; $i++) {
451 $tmp_name = $_FILES['upload']['tmp_name'][$i];
452 if (empty($_FILES['upload']['error'][$i]) && !empty($tmp_name) && $tmp_name != 'none') {
453 if (move_uploaded_file($tmp_name, $path . '/' . $_FILES['upload']['name'][$i])) {
454 $uploads++;
455 } else {
456 $errors++;
457 }
458 }
459 }
460
461 if ($errors == 0 && $uploads > 0) {
462 fm_set_msg(sprintf('All files uploaded to <b>%s</b>', $path));
463 } elseif ($errors == 0 && $uploads == 0) {
464 fm_set_msg('Nothing uploaded', 'alert');
465 } else {
466 fm_set_msg(sprintf('Error while uploading files. Uploaded files: %s', $uploads), 'error');
467 }
468
469 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
470}
471
472// Mass deleting
473if (isset($_POST['group'], $_POST['delete']) && !FM_READONLY) {
474 $path = FM_ROOT_PATH;
475 if (FM_PATH != '') {
476 $path .= '/' . FM_PATH;
477 }
478
479 $errors = 0;
480 $files = $_POST['file'];
481 if (is_array($files) && count($files)) {
482 foreach ($files as $f) {
483 if ($f != '') {
484 $new_path = $path . '/' . $f;
485 if (!fm_rdelete($new_path)) {
486 $errors++;
487 }
488 }
489 }
490 if ($errors == 0) {
491 fm_set_msg('Selected files and folder deleted');
492 } else {
493 fm_set_msg('Error while deleting items', 'error');
494 }
495 } else {
496 fm_set_msg('Nothing selected', 'alert');
497 }
498
499 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
500}
501
502// Pack files
503if (isset($_POST['group'], $_POST['zip']) && !FM_READONLY) {
504 $path = FM_ROOT_PATH;
505 if (FM_PATH != '') {
506 $path .= '/' . FM_PATH;
507 }
508
509 if (!class_exists('ZipArchive')) {
510 fm_set_msg('Operations with archives are not available', 'error');
511 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
512 }
513
514 $files = $_POST['file'];
515 if (!empty($files)) {
516 chdir($path);
517
518 if (count($files) == 1) {
519 $one_file = reset($files);
520 $one_file = basename($one_file);
521 $zipname = $one_file . '_' . date('ymd_His') . '.zip';
522 } else {
523 $zipname = 'archive_' . date('ymd_His') . '.zip';
524 }
525
526 $zipper = new FM_Zipper();
527 $res = $zipper->create($zipname, $files);
528
529 if ($res) {
530 fm_set_msg(sprintf('Archive <b>%s</b> created', $zipname));
531 } else {
532 fm_set_msg('Archive not created', 'error');
533 }
534 } else {
535 fm_set_msg('Nothing selected', 'alert');
536 }
537
538 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
539}
540
541// Unpack
542if (isset($_GET['unzip']) && !FM_READONLY) {
543 $unzip = $_GET['unzip'];
544 $unzip = fm_clean_path($unzip);
545 $unzip = str_replace('/', '', $unzip);
546
547 $path = FM_ROOT_PATH;
548 if (FM_PATH != '') {
549 $path .= '/' . FM_PATH;
550 }
551
552 if (!class_exists('ZipArchive')) {
553 fm_set_msg('Operations with archives are not available', 'error');
554 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
555 }
556
557 if ($unzip != '' && is_file($path . '/' . $unzip)) {
558 $zip_path = $path . '/' . $unzip;
559
560 //to folder
561 $tofolder = '';
562 if (isset($_GET['tofolder'])) {
563 $tofolder = pathinfo($zip_path, PATHINFO_FILENAME);
564 if (fm_mkdir($path . '/' . $tofolder, true)) {
565 $path .= '/' . $tofolder;
566 }
567 }
568
569 $zipper = new FM_Zipper();
570 $res = $zipper->unzip($zip_path, $path);
571
572 if ($res) {
573 fm_set_msg('Archive unpacked');
574 } else {
575 fm_set_msg('Archive not unpacked', 'error');
576 }
577
578 } else {
579 fm_set_msg('File not found', 'error');
580 }
581 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
582}
583
584// Change Perms (not for Windows)
585if (isset($_POST['chmod']) && !FM_READONLY && !FM_IS_WIN) {
586 $path = FM_ROOT_PATH;
587 if (FM_PATH != '') {
588 $path .= '/' . FM_PATH;
589 }
590
591 $file = $_POST['chmod'];
592 $file = fm_clean_path($file);
593 $file = str_replace('/', '', $file);
594 if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
595 fm_set_msg('File not found', 'error');
596 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
597 }
598
599 $mode = 0;
600 if (!empty($_POST['ur'])) {
601 $mode |= 0400;
602 }
603 if (!empty($_POST['uw'])) {
604 $mode |= 0200;
605 }
606 if (!empty($_POST['ux'])) {
607 $mode |= 0100;
608 }
609 if (!empty($_POST['gr'])) {
610 $mode |= 0040;
611 }
612 if (!empty($_POST['gw'])) {
613 $mode |= 0020;
614 }
615 if (!empty($_POST['gx'])) {
616 $mode |= 0010;
617 }
618 if (!empty($_POST['or'])) {
619 $mode |= 0004;
620 }
621 if (!empty($_POST['ow'])) {
622 $mode |= 0002;
623 }
624 if (!empty($_POST['ox'])) {
625 $mode |= 0001;
626 }
627
628 if (@chmod($path . '/' . $file, $mode)) {
629 fm_set_msg('Permissions changed');
630 } else {
631 fm_set_msg('Permissions not changed', 'error');
632 }
633
634 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
635}
636
637/*************************** /ACTIONS ***************************/
638
639// get current path
640$path = FM_ROOT_PATH;
641if (FM_PATH != '') {
642 $path .= '/' . FM_PATH;
643}
644
645// check path
646if (!is_dir($path)) {
647 fm_redirect(FM_SELF_URL . '?p=');
648}
649
650// get parent folder
651$parent = fm_get_parent_path(FM_PATH);
652
653$objects = is_readable($path) ? scandir($path) : array();
654$folders = array();
655$files = array();
656if (is_array($objects)) {
657 foreach ($objects as $file) {
658 if ($file == '.' || $file == '..') {
659 continue;
660 }
661 if (!FM_SHOW_HIDDEN && substr($file, 0, 1) === '.') {
662 continue;
663 }
664 $new_path = $path . '/' . $file;
665 if (is_file($new_path)) {
666 $files[] = $file;
667 } elseif (is_dir($new_path) && $file != '.' && $file != '..') {
668 $folders[] = $file;
669 }
670 }
671}
672
673if (!empty($files)) {
674 natcasesort($files);
675}
676if (!empty($folders)) {
677 natcasesort($folders);
678}
679
680// upload form
681if (isset($_GET['upload']) && !FM_READONLY) {
682 fm_show_header(); // HEADER
683 fm_show_nav_path(FM_PATH); // current path
684 ?>
685 <div class="path">
686 <p><b><?php echo fm_t('Uploading files') ?></b></p>
687 <p class="break-word"><?php echo fm_t('Destination folder:') ?> <?php echo fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH) ?></p>
688 <form action="" method="post" enctype="multipart/form-data">
689 <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
690 <input type="hidden" name="upl" value="1">
691 <input type="file" name="upload[]"><br>
692 <input type="file" name="upload[]"><br>
693 <input type="file" name="upload[]"><br>
694 <input type="file" name="upload[]"><br>
695 <input type="file" name="upload[]"><br>
696 <br>
697 <p>
698 <button type="submit" class="btn"><i class="fa fa-check-circle"></i> <?php echo fm_t('Upload', $lang) ?></button>
699 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-times-circle"></i> <?php echo fm_t('Cancel', $lang) ?></a></b>
700 </p>
701 </form>
702 </div>
703 <?php
704 fm_show_footer();
705 exit;
706}
707
708// copy form POST
709if (isset($_POST['copy']) && !FM_READONLY) {
710 $copy_files = $_POST['file'];
711 if (!is_array($copy_files) || empty($copy_files)) {
712 fm_set_msg('Nothing selected', 'alert');
713 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
714 }
715
716 fm_show_header(); // HEADER
717 fm_show_nav_path(FM_PATH); // current path
718 ?>
719 <div class="path">
720 <p><b>Copying</b></p>
721 <form action="" method="post">
722 <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
723 <input type="hidden" name="finish" value="1">
724 <?php
725 foreach ($copy_files as $cf) {
726 echo '<input type="hidden" name="file[]" value="' . fm_enc($cf) . '">' . PHP_EOL;
727 }
728 ?>
729 <p class="break-word"><?php echo fm_t('Files:') ?> <b><?php echo implode('</b>, <b>', $copy_files) ?></b></p>
730 <p class="break-word"><?php echo fm_t('Source folder:') ?> <?php echo fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH) ?><br>
731 <label for="inp_copy_to"><?php echo fm_t('Destination folder:') ?></label>
732 <?php echo FM_ROOT_PATH ?>/<input type="text" name="copy_to" id="inp_copy_to" value="<?php echo fm_enc(FM_PATH) ?>">
733 </p>
734 <p><label><input type="checkbox" name="move" value="1"> <?php echo fm_t('Move', $lang) ?></label></p>
735 <p>
736 <button type="submit" class="btn"><i class="fa fa-check-circle"></i> <?php echo fm_t('Copy', $lang) ?></button>
737 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-times-circle"></i> <?php echo fm_t('Cancel', $lang) ?></a></b>
738 </p>
739 </form>
740 </div>
741 <?php
742 fm_show_footer();
743 exit;
744}
745
746// copy form
747if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
748 $copy = $_GET['copy'];
749 $copy = fm_clean_path($copy);
750 if ($copy == '' || !file_exists(FM_ROOT_PATH . '/' . $copy)) {
751 fm_set_msg('File not found', 'error');
752 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
753 }
754
755 fm_show_header(); // HEADER
756 fm_show_nav_path(FM_PATH); // current path
757 ?>
758 <div class="path">
759 <p><b><?php echo fm_t('Copying', $lang) ?></b></p>
760 <p class="break-word">
761 <?php echo fm_t('Source path:', $lang) ?> <?php echo fm_convert_win(FM_ROOT_PATH . '/' . $copy) ?><br>
762 <?php echo fm_t('Destination folder:', $lang) ?> <?php echo fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH) ?>
763 </p>
764 <p>
765 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&copy=<?php echo urlencode($copy) ?>&finish=1"><i class="fa fa-check-circle"></i> <?php echo fm_t('Copy', $lang) ?></a></b>
766 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&copy=<?php echo urlencode($copy) ?>&finish=1&move=1"><i class="fa fa-check-circle"></i> <?php echo fm_t('Move', $lang) ?></a></b>
767 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-times-circle"></i> <?php echo fm_t('Cancel', $lang) ?></a></b>
768 </p>
769 <p><i><?php echo fm_t('Select folder:') ?></i></p>
770 <ul class="folders break-word">
771 <?php
772 if ($parent !== false) {
773 ?>
774 <li><a href="?p=<?php echo urlencode($parent) ?>&copy=<?php echo urlencode($copy) ?>"><i class="fa fa-chevron-circle-left"></i> ..</a></li>
775 <?php
776 }
777 foreach ($folders as $f) {
778 ?>
779 <li><a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>&copy=<?php echo urlencode($copy) ?>"><i class="fa fa-folder-o"></i> <?php echo fm_convert_win($f) ?></a></li>
780 <?php
781 }
782 ?>
783 </ul>
784 </div>
785 <?php
786 fm_show_footer();
787 exit;
788}
789
790// file viewer
791if (isset($_GET['view'])) {
792 $file = $_GET['view'];
793 $file = fm_clean_path($file);
794 $file = str_replace('/', '', $file);
795 if ($file == '' || !is_file($path . '/' . $file)) {
796 fm_set_msg('File not found', 'error');
797 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
798 }
799
800 fm_show_header(); // HEADER
801 fm_show_nav_path(FM_PATH); // current path
802
803 $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
804 $file_path = $path . '/' . $file;
805
806 $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
807 $mime_type = fm_get_mime_type($file_path);
808 $filesize = filesize($file_path);
809
810 $is_zip = false;
811 $is_image = false;
812 $is_audio = false;
813 $is_video = false;
814 $is_text = false;
815
816 $view_title = 'File';
817 $filenames = false; // for zip
818 $content = ''; // for text
819
820 if ($ext == 'zip') {
821 $is_zip = true;
822 $view_title = 'Archive';
823 $filenames = fm_get_zif_info($file_path);
824 } elseif (in_array($ext, fm_get_image_exts())) {
825 $is_image = true;
826 $view_title = 'Image';
827 } elseif (in_array($ext, fm_get_audio_exts())) {
828 $is_audio = true;
829 $view_title = 'Audio';
830 } elseif (in_array($ext, fm_get_video_exts())) {
831 $is_video = true;
832 $view_title = 'Video';
833 } elseif (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
834 $is_text = true;
835 $content = file_get_contents($file_path);
836 }
837
838 ?>
839 <div class="path">
840 <p class="break-word"><b><?php echo $view_title ?> "<?php echo fm_convert_win($file) ?>"</b></p>
841 <p class="break-word">
842 <?php echo fm_t('Full path:', $lang) ?> <?php echo fm_convert_win($file_path) ?><br>
843 <?php echo fm_t('File size:', $lang) ?> <?php echo fm_get_filesize($filesize) ?><?php if ($filesize >= 1000): ?> (<?php echo sprintf('%s bytes', $filesize) ?>)<?php endif; ?><br>
844 <?php echo fm_t('MIME-type:', $lang) ?> <?php echo $mime_type ?><br>
845 <?php
846 // ZIP info
847 if ($is_zip && $filenames !== false) {
848 $total_files = 0;
849 $total_comp = 0;
850 $total_uncomp = 0;
851 foreach ($filenames as $fn) {
852 if (!$fn['folder']) {
853 $total_files++;
854 }
855 $total_comp += $fn['compressed_size'];
856 $total_uncomp += $fn['filesize'];
857 }
858 ?>
859 Files in archive: <?php echo $total_files ?><br>
860 Total size: <?php echo fm_get_filesize($total_uncomp) ?><br>
861 Size in archive: <?php echo fm_get_filesize($total_comp) ?><br>
862 Compression: <?php echo round(($total_comp / $total_uncomp) * 100) ?>%<br>
863 <?php
864 }
865 // Image info
866 if ($is_image) {
867 $image_size = getimagesize($file_path);
868 echo 'Image sizes: ' . (isset($image_size[0]) ? $image_size[0] : '0') . ' x ' . (isset($image_size[1]) ? $image_size[1] : '0') . '<br>';
869 }
870 // Text info
871 if ($is_text) {
872 $is_utf8 = fm_is_utf8($content);
873 if (function_exists('iconv')) {
874 if (!$is_utf8) {
875 $content = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $content);
876 }
877 }
878 echo 'Charset: ' . ($is_utf8 ? 'utf-8' : '8 bit') . '<br>';
879 }
880 ?>
881 </p>
882 <p>
883 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&dl=<?php echo urlencode($file) ?>"><i class="fa fa-cloud-download"></i> <?php echo fm_t('Download', $lang) ?></a></b>
884 <b><a href="<?php echo $file_url ?>" target="_blank"><i class="fa fa-external-link-square"></i> <?php echo fm_t('Open', $lang) ?></a></b>
885 <?php
886 // ZIP actions
887 if (!FM_READONLY && $is_zip && $filenames !== false) {
888 $zip_name = pathinfo($file_path, PATHINFO_FILENAME);
889 ?>
890 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&unzip=<?php echo urlencode($file) ?>"><i class="fa fa-check-circle"></i> <?php echo fm_t('UnZip', $lang) ?></a></b>
891 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&unzip=<?php echo urlencode($file) ?>&tofolder=1" title="<?php echo fm_t('UnZip to', $lang) ?> <?php echo fm_enc($zip_name) ?>"><i class="fa fa-check-circle"></i>
892 <?php echo fm_t('UnZip to folder', $lang) ?></a></b>
893 <?php
894 }
895 if($is_text && !FM_READONLY) {
896 ?>
897 <b><a href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>" class="edit-file"><i class="fa fa-pencil-square"></i> <?php echo fm_t('Edit', $lang) ?></a></b>
898 <b><a href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>&env=ace" class="edit-file"><i class="fa fa-pencil-square"></i> <?php echo fm_t('Advanced Edit', $lang) ?></a></b>
899 <?php }
900 if($send_mail && !FM_READONLY) {
901 ?>
902 <b><a href="javascript:mailto('<?php echo urlencode(trim(FM_ROOT_PATH.'/'.FM_PATH)) ?>','<?php echo urlencode($file) ?>')"><i class="fa fa-pencil-square"></i> <?php echo fm_t('Mail', $lang) ?></a></b>
903 <?php } ?>
904 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-chevron-circle-left"></i> <?php echo fm_t('Back', $lang) ?></a></b>
905 </p>
906 <?php
907 if ($is_zip) {
908 // ZIP content
909 if ($filenames !== false) {
910 echo '<code class="maxheight">';
911 foreach ($filenames as $fn) {
912 if ($fn['folder']) {
913 echo '<b>' . $fn['name'] . '</b><br>';
914 } else {
915 echo $fn['name'] . ' (' . fm_get_filesize($fn['filesize']) . ')<br>';
916 }
917 }
918 echo '</code>';
919 } else {
920 echo '<p>Error while fetching archive info</p>';
921 }
922 } elseif ($is_image) {
923 // Image content
924 if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico'))) {
925 echo '<p><img src="' . $file_url . '" alt="" class="preview-img"></p>';
926 }
927 } elseif ($is_audio) {
928 // Audio content
929 echo '<p><audio src="' . $file_url . '" controls preload="metadata"></audio></p>';
930 } elseif ($is_video) {
931 // Video content
932 echo '<div class="preview-video"><video src="' . $file_url . '" width="640" height="360" controls preload="metadata"></video></div>';
933 } elseif ($is_text) {
934 if (FM_USE_HIGHLIGHTJS) {
935 // highlight
936 $hljs_classes = array(
937 'shtml' => 'xml',
938 'htaccess' => 'apache',
939 'phtml' => 'php',
940 'lock' => 'json',
941 'svg' => 'xml',
942 );
943 $hljs_class = isset($hljs_classes[$ext]) ? 'lang-' . $hljs_classes[$ext] : 'lang-' . $ext;
944 if (empty($ext) || in_array(strtolower($file), fm_get_text_names()) || preg_match('#\.min\.(css|js)$#i', $file)) {
945 $hljs_class = 'nohighlight';
946 }
947 $content = '<pre class="with-hljs"><code class="' . $hljs_class . '">' . fm_enc($content) . '</code></pre>';
948 } elseif (in_array($ext, array('php', 'php4', 'php5', 'phtml', 'phps'))) {
949 // php highlight
950 $content = highlight_string($content, true);
951 } else {
952 $content = '<pre>' . fm_enc($content) . '</pre>';
953 }
954 echo $content;
955 }
956 ?>
957 </div>
958 <?php
959 fm_show_footer();
960 exit;
961}
962
963// file editor
964if (isset($_GET['edit'])) {
965 $file = $_GET['edit'];
966 $file = fm_clean_path($file);
967 $file = str_replace('/', '', $file);
968 if ($file == '' || !is_file($path . '/' . $file)) {
969 fm_set_msg(fm_t('File not found', $lang), 'error');
970 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
971 }
972
973 fm_show_header(); // HEADER
974 fm_show_nav_path(FM_PATH); // current path
975
976 $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
977 $file_path = $path . '/' . $file;
978
979 //normal editer
980 $isNormalEditor = true;
981 if(isset($_GET['env'])) {
982 if($_GET['env'] == "ace") {
983 $isNormalEditor = false;
984 }
985 }
986
987 //Save File
988 if(isset($_POST['savedata'])) {
989 $writedata = $_POST['savedata'];
990 $fd=fopen($file_path,"w");
991 @fwrite($fd, $writedata);
992 fclose($fd);
993 fm_set_msg(fm_t('File Saved Successfully', $lang), 'alert');
994 }
995
996 $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
997 $mime_type = fm_get_mime_type($file_path);
998 $filesize = filesize($file_path);
999 $is_text = false;
1000 $content = ''; // for text
1001
1002 if (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
1003 $is_text = true;
1004 $content = file_get_contents($file_path);
1005 }
1006
1007 ?>
1008 <div class="path">
1009 <div class="edit-file-actions">
1010 <a title="<?php echo fm_t('Cancel', $lang) ?>" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&view=<?php echo urlencode($file) ?>"><i class="fa fa-reply-all"></i> <?php echo fm_t('Cancel', $lang) ?></a>
1011 <a title="<?php echo fm_t('Backup', $lang) ?>" href="javascript:backup('<?php echo urlencode($path) ?>','<?php echo urlencode($file) ?>')"><i class="fa fa-database"></i> <?php echo fm_t('Backup', $lang) ?></a>
1012 <?php if($is_text) { ?>
1013 <?php if($isNormalEditor) { ?>
1014 <a title="<?php echo fm_t('Advanced', $lang) ?>" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>&env=ace"><i class="fa fa-paper-plane"></i> <?php echo fm_t('Advanced Editor', $lang) ?></a>
1015 <button type="button" name="<?php echo fm_t('Save', $lang) ?>" data-url="<?php echo $file_url ?>" onclick="edit_save(this,'nrl')"><i class="fa fa-floppy-o"></i> <?php echo fm_t('Save', $lang) ?></button>
1016 <?php } else { ?>
1017 <a title="<?php echo fm_t('Plain Editor', $lang) ?>" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>"><i class="fa fa-text-height"></i> <?php echo fm_t('Plain Editor', $lang) ?></a>
1018 <button type="button" name="Save" data-url="<?php echo $file_url ?>" onclick="edit_save(this,'ace')"><i class="fa fa-floppy-o"></i> <?php echo fm_t('Save', $lang) ?></button>
1019 <?php } ?>
1020 <?php } ?>
1021 </div>
1022 <?php
1023 if ($is_text && $isNormalEditor) {
1024 echo '<textarea id="normal-editor" rows="33" cols="120" style="width: 99.5%;">'. htmlspecialchars($content) .'</textarea>';
1025 } elseif ($is_text) {
1026 echo '<div id="editor" contenteditable="true">'. htmlspecialchars($content) .'</div>';
1027 } else {
1028 fm_set_msg(fm_t('FILE EXTENSION HAS NOT SUPPORTED', $lang), 'error');
1029 }
1030 ?>
1031 </div>
1032 <?php
1033 fm_show_footer();
1034 exit;
1035}
1036
1037// chmod (not for Windows)
1038if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
1039 $file = $_GET['chmod'];
1040 $file = fm_clean_path($file);
1041 $file = str_replace('/', '', $file);
1042 if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
1043 fm_set_msg('File not found', 'error');
1044 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
1045 }
1046
1047 fm_show_header(); // HEADER
1048 fm_show_nav_path(FM_PATH); // current path
1049
1050 $file_url = FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file;
1051 $file_path = $path . '/' . $file;
1052
1053 $mode = fileperms($path . '/' . $file);
1054
1055 ?>
1056 <div class="path">
1057 <p><b><?php echo fm_t('Change Permissions', $lang) ?></b></p>
1058 <p>
1059 <?php echo fm_t('Full path:', $lang) ?> <?php echo $file_path ?><br>
1060 </p>
1061 <form action="" method="post">
1062 <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
1063 <input type="hidden" name="chmod" value="<?php echo fm_enc($file) ?>">
1064
1065 <table class="compact-table">
1066 <tr>
1067 <td></td>
1068 <td><b><?php echo fm_t('Owner', $lang) ?></b></td>
1069 <td><b><?php echo fm_t('Group', $lang) ?></b></td>
1070 <td><b><?php echo fm_t('Other', $lang) ?></b></td>
1071 </tr>
1072 <tr>
1073 <td style="text-align: right"><b><?php echo fm_t('Read', $lang) ?></b></td>
1074 <td><label><input type="checkbox" name="ur" value="1"<?php echo ($mode & 00400) ? ' checked' : '' ?>></label></td>
1075 <td><label><input type="checkbox" name="gr" value="1"<?php echo ($mode & 00040) ? ' checked' : '' ?>></label></td>
1076 <td><label><input type="checkbox" name="or" value="1"<?php echo ($mode & 00004) ? ' checked' : '' ?>></label></td>
1077 </tr>
1078 <tr>
1079 <td style="text-align: right"><b><?php echo fm_t('Write', $lang) ?></b></td>
1080 <td><label><input type="checkbox" name="uw" value="1"<?php echo ($mode & 00200) ? ' checked' : '' ?>></label></td>
1081 <td><label><input type="checkbox" name="gw" value="1"<?php echo ($mode & 00020) ? ' checked' : '' ?>></label></td>
1082 <td><label><input type="checkbox" name="ow" value="1"<?php echo ($mode & 00002) ? ' checked' : '' ?>></label></td>
1083 </tr>
1084 <tr>
1085 <td style="text-align: right"><b><?php echo fm_t('Execute', $lang) ?></b></td>
1086 <td><label><input type="checkbox" name="ux" value="1"<?php echo ($mode & 00100) ? ' checked' : '' ?>></label></td>
1087 <td><label><input type="checkbox" name="gx" value="1"<?php echo ($mode & 00010) ? ' checked' : '' ?>></label></td>
1088 <td><label><input type="checkbox" name="ox" value="1"<?php echo ($mode & 00001) ? ' checked' : '' ?>></label></td>
1089 </tr>
1090 </table>
1091
1092 <p>
1093 <button type="submit" class="btn"><i class="fa fa-check-circle"></i> <?php echo fm_t('Change', $lang) ?></button>
1094 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-times-circle"></i> <?php echo fm_t('Cancel', $lang) ?></a></b>
1095 </p>
1096
1097 </form>
1098
1099 </div>
1100 <?php
1101 fm_show_footer();
1102 exit;
1103}
1104
1105//--- FILEMANAGER MAIN
1106fm_show_header(); // HEADER
1107fm_show_nav_path(FM_PATH); // current path
1108
1109// messages
1110fm_show_message();
1111
1112$num_files = count($files);
1113$num_folders = count($folders);
1114$all_files_size = 0;
1115?>
1116<form action="" method="post">
1117<input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
1118<input type="hidden" name="group" value="1">
1119<table class="table"><thead><tr>
1120<?php if (!FM_READONLY): ?><th style="width:3%"><label><input type="checkbox" title="<?php echo fm_t('Invert selection', $lang) ?>" onclick="checkbox_toggle()"></label></th><?php endif; ?>
1121<th><?php echo fm_t('Name', $lang) ?></th><th style="width:10%"><?php echo fm_t('Size', $lang) ?></th>
1122<th style="width:12%"><?php echo fm_t('Modified', $lang) ?></th>
1123<?php if (!FM_IS_WIN): ?><th style="width:6%"><?php echo fm_t('Perms', $lang) ?></th><th style="width:10%"><?php echo fm_t('Owner', $lang) ?></th><?php endif; ?>
1124<th style="width:<?php if (!FM_READONLY): ?>13<?php else: ?>6.5<?php endif; ?>%"><?php echo fm_t('Actions', $lang) ?></th></tr></thead>
1125<?php
1126// link to parent folder
1127if ($parent !== false) {
1128 ?>
1129<tr><?php if (!FM_READONLY): ?><td></td><?php endif; ?><td colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>"><a href="?p=<?php echo urlencode($parent) ?>"><i class="fa fa-chevron-circle-left"></i> ..</a></td></tr>
1130<?php
1131}
1132foreach ($folders as $f) {
1133 $is_link = is_link($path . '/' . $f);
1134 $img = $is_link ? 'icon-link_folder' : 'icon-folder';
1135 $modif = date(FM_DATETIME_FORMAT, filemtime($path . '/' . $f));
1136 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
1137 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
1138 $owner = posix_getpwuid(fileowner($path . '/' . $f));
1139 $group = posix_getgrgid(filegroup($path . '/' . $f));
1140 } else {
1141 $owner = array('name' => '?');
1142 $group = array('name' => '?');
1143 }
1144 ?>
1145<tr>
1146<?php if (!FM_READONLY): ?><td><label><input type="checkbox" name="file[]" value="<?php echo fm_enc($f) ?>"></label></td><?php endif; ?>
1147<td><div class="filename"><a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win($f) ?></a><?php echo ($is_link ? ' → <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div></td>
1148<td><?php echo fm_t('Folder', $lang) ?></td><td><?php echo $modif ?></td>
1149<?php if (!FM_IS_WIN): ?>
1150<td><?php if (!FM_READONLY): ?><a title="<?php echo fm_t('Change Permissions', $lang) ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?></td>
1151<td><?php echo $owner['name'] . ':' . $group['name'] ?></td>
1152<?php endif; ?>
1153<td class="inline-actions"><?php if (!FM_READONLY): ?>
1154<a title="<?php echo fm_t('Delete', $lang) ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&del=<?php echo urlencode($f) ?>" onclick="return confirm('<?php echo fm_t('Delete folder?') ?>');"><i class="fa fa-trash-o" style="background:#FF4136" aria-hidden="true"></i></a>
1155<a title="<?php echo fm_t('Rename', $lang) ?>" href="#" onclick="rename('<?php echo fm_enc(FM_PATH) ?>', '<?php echo fm_enc($f) ?>');return false;"><i class="fa fa-pencil-square-o" style="background:#FF851B" aria-hidden="true"></i></a>
1156<a title="<?php echo fm_t('Copy to...') ?>" href="?p=&copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o" aria-hidden="true"></i></a>
1157<?php endif; ?>
1158<a title="<?php echo fm_t('Direct link', $lang) ?>" href="<?php echo FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f . '/' ?>" target="_blank"><i class="fa fa-link" style="background:#001f3f" aria-hidden="true"></i></a>
1159</td></tr>
1160 <?php
1161 flush();
1162}
1163
1164foreach ($files as $f) {
1165 $is_link = is_link($path . '/' . $f);
1166 $img = $is_link ? 'fa fa-file-text-o' : fm_get_file_icon_class($path . '/' . $f);
1167 $modif = date("d.m.y H:i", filemtime($path . '/' . $f));
1168 $filesize_raw = filesize($path . '/' . $f);
1169 $filesize = fm_get_filesize($filesize_raw);
1170 $filelink = '?p=' . urlencode(FM_PATH) . '&view=' . urlencode($f);
1171 $all_files_size += $filesize_raw;
1172 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
1173 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
1174 $owner = posix_getpwuid(fileowner($path . '/' . $f));
1175 $group = posix_getgrgid(filegroup($path . '/' . $f));
1176 } else {
1177 $owner = array('name' => '?');
1178 $group = array('name' => '?');
1179 }
1180 ?>
1181<tr>
1182<?php if (!FM_READONLY): ?><td><label><input type="checkbox" name="file[]" value="<?php echo fm_enc($f) ?>"></label></td><?php endif; ?>
1183<td><div class="filename"><a href="<?php echo $filelink ?>" title="<?php echo fm_t('File info', $lang) ?>"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win($f) ?></a><?php echo ($is_link ? ' → <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div></td>
1184<td><span title="<?php printf(fm_t('%s bytes'), $filesize_raw) ?>"><?php echo $filesize ?></span></td>
1185<td><?php echo $modif ?></td>
1186<?php if (!FM_IS_WIN): ?>
1187<td><?php if (!FM_READONLY): ?><a title="<?php echo fm_t('Change Permissions', $lang) ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?></td>
1188<td><?php echo $owner['name'] . ':' . $group['name'] ?></td>
1189<?php endif; ?>
1190<td class="inline-actions">
1191<?php if (!FM_READONLY): ?>
1192<a title="<?php echo fm_t('Delete', $lang) ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&del=<?php echo urlencode($f) ?>" onclick="return confirm('<?php echo fm_t('Delete file?') ?>');"><i class="fa fa-trash-o" style="background:#FF4136"></i></a>
1193<a title="<?php echo fm_t('Rename', $lang) ?>" href="#" onclick="rename('<?php echo fm_enc(FM_PATH) ?>', '<?php echo fm_enc($f) ?>');return false;"><i class="fa fa-pencil-square-o" style="background:#FF851B"></i></a>
1194<a title="<?php echo fm_t('Copy to...') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o"></i></a>
1195<?php endif; ?>
1196<a title="<?php echo fm_t('Direct link', $lang) ?>" href="<?php echo FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f ?>" target="_blank"><i class="fa fa-link" style="background:#001f3f"></i></a>
1197<a title="<?php echo fm_t('Download', $lang) ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&dl=<?php echo urlencode($f) ?>"><i class="fa fa-download" style="background:#2ECC40"></i></a>
1198</td></tr>
1199 <?php
1200 flush();
1201}
1202
1203if (empty($folders) && empty($files)) {
1204 ?>
1205<tr><?php if (!FM_READONLY): ?><td></td><?php endif; ?><td colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>"><em><?php echo fm_t('Folder is empty', $lang) ?></em></td></tr>
1206<?php
1207} else {
1208 ?>
1209<tr><?php if (!FM_READONLY): ?><td class="gray"></td><?php endif; ?><td class="gray" colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>">
1210<?php echo fm_t('Full size:', $lang) ?> <span title="<?php printf(fm_t('%s bytes'), $all_files_size) ?>"><?php echo fm_get_filesize($all_files_size) ?></span>,
1211<?php echo fm_t('files:', $lang) ?> <?php echo $num_files ?>,
1212<?php echo fm_t('folders:', $lang) ?> <?php echo $num_folders ?>
1213</td></tr>
1214<?php
1215}
1216?>
1217</table>
1218<?php if (!FM_READONLY): ?>
1219<p class="path footer-links"><a href="#/select-all" class="group-btn" onclick="select_all();return false;"><i class="fa fa-check-square"></i> <?php echo fm_t('Select all', $lang) ?></a>
1220<a href="#/unselect-all" class="group-btn" onclick="unselect_all();return false;"><i class="fa fa-window-close"></i> <?php echo fm_t('Unselect all', $lang) ?></a>
1221<a href="#/invert-all" class="group-btn" onclick="invert_all();return false;"><i class="fa fa-th-list"></i> <?php echo fm_t('Invert selection', $lang) ?></a>
1222<input type="submit" class="hidden" name="delete" id="a-delete" value="<?php echo fm_t('Delete', $lang) ?>" onclick="return confirm('<?php echo fm_t('Delete selected files and folders?') ?>')">
1223<a href="javascript:document.getElementById('a-delete').click();" class="group-btn"><i class="fa fa-trash"></i> <?php echo fm_t('Delete', $lang) ?> </a>
1224<input type="submit" class="hidden" name="zip" id="a-zip" value="<?php echo fm_t('Zip', $lang) ?>" onclick="return confirm('<?php echo fm_t('Create archive?') ?>')">
1225<a href="javascript:document.getElementById('a-zip').click();" class="group-btn"><i class="fa fa-file-archive-o"></i> <?php echo fm_t('Zip', $lang) ?> </a>
1226<input type="submit" class="hidden" name="copy" id="a-copy" value="<?php echo fm_t('Copy', $lang) ?>">
1227<a href="javascript:document.getElementById('a-copy').click();" class="group-btn"><i class="fa fa-files-o"></i> <?php echo fm_t('Copy', $lang) ?> </a>
1228</p>
1229<?php endif; ?>
1230</form>
1231
1232<?php
1233fm_show_footer();
1234
1235//--- END
1236
1237// Functions
1238
1239/**
1240 * Delete file or folder (recursively)
1241 * @param string $path
1242 * @return bool
1243 */
1244function fm_rdelete($path)
1245{
1246 if (is_link($path)) {
1247 return unlink($path);
1248 } elseif (is_dir($path)) {
1249 $objects = scandir($path);
1250 $ok = true;
1251 if (is_array($objects)) {
1252 foreach ($objects as $file) {
1253 if ($file != '.' && $file != '..') {
1254 if (!fm_rdelete($path . '/' . $file)) {
1255 $ok = false;
1256 }
1257 }
1258 }
1259 }
1260 return ($ok) ? rmdir($path) : false;
1261 } elseif (is_file($path)) {
1262 return unlink($path);
1263 }
1264 return false;
1265}
1266
1267/**
1268 * Recursive chmod
1269 * @param string $path
1270 * @param int $filemode
1271 * @param int $dirmode
1272 * @return bool
1273 * @todo Will use in mass chmod
1274 */
1275function fm_rchmod($path, $filemode, $dirmode)
1276{
1277 if (is_dir($path)) {
1278 if (!chmod($path, $dirmode)) {
1279 return false;
1280 }
1281 $objects = scandir($path);
1282 if (is_array($objects)) {
1283 foreach ($objects as $file) {
1284 if ($file != '.' && $file != '..') {
1285 if (!fm_rchmod($path . '/' . $file, $filemode, $dirmode)) {
1286 return false;
1287 }
1288 }
1289 }
1290 }
1291 return true;
1292 } elseif (is_link($path)) {
1293 return true;
1294 } elseif (is_file($path)) {
1295 return chmod($path, $filemode);
1296 }
1297 return false;
1298}
1299
1300/**
1301 * Safely rename
1302 * @param string $old
1303 * @param string $new
1304 * @return bool|null
1305 */
1306function fm_rename($old, $new)
1307{
1308 return (!file_exists($new) && file_exists($old)) ? rename($old, $new) : null;
1309}
1310
1311/**
1312 * Copy file or folder (recursively).
1313 * @param string $path
1314 * @param string $dest
1315 * @param bool $upd Update files
1316 * @param bool $force Create folder with same names instead file
1317 * @return bool
1318 */
1319function fm_rcopy($path, $dest, $upd = true, $force = true)
1320{
1321 if (is_dir($path)) {
1322 if (!fm_mkdir($dest, $force)) {
1323 return false;
1324 }
1325 $objects = scandir($path);
1326 $ok = true;
1327 if (is_array($objects)) {
1328 foreach ($objects as $file) {
1329 if ($file != '.' && $file != '..') {
1330 if (!fm_rcopy($path . '/' . $file, $dest . '/' . $file)) {
1331 $ok = false;
1332 }
1333 }
1334 }
1335 }
1336 return $ok;
1337 } elseif (is_file($path)) {
1338 return fm_copy($path, $dest, $upd);
1339 }
1340 return false;
1341}
1342
1343/**
1344 * Safely create folder
1345 * @param string $dir
1346 * @param bool $force
1347 * @return bool
1348 */
1349function fm_mkdir($dir, $force)
1350{
1351 if (file_exists($dir)) {
1352 if (is_dir($dir)) {
1353 return $dir;
1354 } elseif (!$force) {
1355 return false;
1356 }
1357 unlink($dir);
1358 }
1359 return mkdir($dir, 0777, true);
1360}
1361
1362/**
1363 * Safely copy file
1364 * @param string $f1
1365 * @param string $f2
1366 * @param bool $upd
1367 * @return bool
1368 */
1369function fm_copy($f1, $f2, $upd)
1370{
1371 $time1 = filemtime($f1);
1372 if (file_exists($f2)) {
1373 $time2 = filemtime($f2);
1374 if ($time2 >= $time1 && $upd) {
1375 return false;
1376 }
1377 }
1378 $ok = copy($f1, $f2);
1379 if ($ok) {
1380 touch($f2, $time1);
1381 }
1382 return $ok;
1383}
1384
1385/**
1386 * Get mime type
1387 * @param string $file_path
1388 * @return mixed|string
1389 */
1390function fm_get_mime_type($file_path)
1391{
1392 if (function_exists('finfo_open')) {
1393 $finfo = finfo_open(FILEINFO_MIME_TYPE);
1394 $mime = finfo_file($finfo, $file_path);
1395 finfo_close($finfo);
1396 return $mime;
1397 } elseif (function_exists('mime_content_type')) {
1398 return mime_content_type($file_path);
1399 } elseif (!stristr(ini_get('disable_functions'), 'shell_exec')) {
1400 $file = escapeshellarg($file_path);
1401 $mime = shell_exec('file -bi ' . $file);
1402 return $mime;
1403 } else {
1404 return '--';
1405 }
1406}
1407
1408/**
1409 * HTTP Redirect
1410 * @param string $url
1411 * @param int $code
1412 */
1413function fm_redirect($url, $code = 302)
1414{
1415 header('Location: ' . $url, true, $code);
1416 exit;
1417}
1418
1419/**
1420 * Clean path
1421 * @param string $path
1422 * @return string
1423 */
1424function fm_clean_path($path)
1425{
1426 $path = trim($path);
1427 $path = trim($path, '\\/');
1428 $path = str_replace(array('../', '..\\'), '', $path);
1429 if ($path == '..') {
1430 $path = '';
1431 }
1432 return str_replace('\\', '/', $path);
1433}
1434
1435/**
1436 * Get parent path
1437 * @param string $path
1438 * @return bool|string
1439 */
1440function fm_get_parent_path($path)
1441{
1442 $path = fm_clean_path($path);
1443 if ($path != '') {
1444 $array = explode('/', $path);
1445 if (count($array) > 1) {
1446 $array = array_slice($array, 0, -1);
1447 return implode('/', $array);
1448 }
1449 return '';
1450 }
1451 return false;
1452}
1453
1454/**
1455 * Get nice filesize
1456 * @param int $size
1457 * @return string
1458 */
1459function fm_get_filesize($size)
1460{
1461 if ($size < 1000) {
1462 return sprintf('%s B', $size);
1463 } elseif (($size / 1024) < 1000) {
1464 return sprintf('%s KiB', round(($size / 1024), 2));
1465 } elseif (($size / 1024 / 1024) < 1000) {
1466 return sprintf('%s MiB', round(($size / 1024 / 1024), 2));
1467 } elseif (($size / 1024 / 1024 / 1024) < 1000) {
1468 return sprintf('%s GiB', round(($size / 1024 / 1024 / 1024), 2));
1469 } else {
1470 return sprintf('%s TiB', round(($size / 1024 / 1024 / 1024 / 1024), 2));
1471 }
1472}
1473
1474/**
1475 * Get info about zip archive
1476 * @param string $path
1477 * @return array|bool
1478 */
1479function fm_get_zif_info($path)
1480{
1481 if (function_exists('zip_open')) {
1482 $arch = zip_open($path);
1483 if ($arch) {
1484 $filenames = array();
1485 while ($zip_entry = zip_read($arch)) {
1486 $zip_name = zip_entry_name($zip_entry);
1487 $zip_folder = substr($zip_name, -1) == '/';
1488 $filenames[] = array(
1489 'name' => $zip_name,
1490 'filesize' => zip_entry_filesize($zip_entry),
1491 'compressed_size' => zip_entry_compressedsize($zip_entry),
1492 'folder' => $zip_folder
1493 //'compression_method' => zip_entry_compressionmethod($zip_entry),
1494 );
1495 }
1496 zip_close($arch);
1497 return $filenames;
1498 }
1499 }
1500 return false;
1501}
1502
1503/**
1504 * Encode html entities
1505 * @param string $text
1506 * @return string
1507 */
1508function fm_enc($text)
1509{
1510 return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
1511}
1512
1513/**
1514 * This function scans the files folder recursively, and builds a large array
1515 * @param string $dir
1516 * @return json
1517 */
1518function scan($dir){
1519 $files = array();
1520 $_dir = $dir;
1521 $dir = FM_ROOT_PATH.'/'.$dir;
1522 // Is there actually such a folder/file?
1523 if(file_exists($dir)){
1524 foreach(scandir($dir) as $f) {
1525 if(!$f || $f[0] == '.') {
1526 continue; // Ignore hidden files
1527 }
1528
1529 if(is_dir($dir . '/' . $f)) {
1530 // The path is a folder
1531 $files[] = array(
1532 "name" => $f,
1533 "type" => "folder",
1534 "path" => $_dir.'/'.$f,
1535 "items" => scan($dir . '/' . $f), // Recursively get the contents of the folder
1536 );
1537 } else {
1538 // It is a file
1539 $files[] = array(
1540 "name" => $f,
1541 "type" => "file",
1542 "path" => $_dir,
1543 "size" => filesize($dir . '/' . $f) // Gets the size of this file
1544 );
1545 }
1546 }
1547 }
1548 return $files;
1549}
1550
1551/**
1552 * Send email with file attached
1553 * @param string $msg, $to, $p
1554 */
1555function send_mail($path,$filename, $mailto, $message) {
1556 $file = $path.'/'.$filename;
1557 $content = file_get_contents( $file);
1558 $content = chunk_split(base64_encode($content));
1559 $uid = md5(uniqid(time()));
1560 $name = basename($file);
1561
1562 // header
1563 $header = "From: File Manager Script <filemanager@mail.com>\r\n";
1564 $header .= "Reply-To: ".$mailto."\r\n";
1565 $header .= "MIME-Version: 1.0\r\n";
1566 $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
1567
1568 // message & attachment
1569 $subject = "File has attahced";
1570 $nmessage = "--".$uid."\r\n";
1571 $nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n";
1572 $nmessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
1573 $nmessage .= $message."\r\n\r\n";
1574 $nmessage .= "--".$uid."\r\n";
1575 $nmessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
1576 $nmessage .= "Content-Transfer-Encoding: base64\r\n";
1577 $nmessage .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
1578 $nmessage .= $content."\r\n\r\n";
1579 $nmessage .= "--".$uid."--";
1580
1581 if (mail($mailto, $subject, $nmessage, $header)) {
1582 return true; // Or do something here
1583 } else {
1584 return false;
1585 }
1586}
1587
1588/**
1589 * Save message in session
1590 * @param string $msg
1591 * @param string $status
1592 */
1593function fm_set_msg($msg, $status = 'ok')
1594{
1595 $_SESSION['message'] = $msg;
1596 $_SESSION['status'] = $status;
1597}
1598
1599/**
1600 * Check if string is in UTF-8
1601 * @param string $string
1602 * @return int
1603 */
1604function fm_is_utf8($string)
1605{
1606 return preg_match('//u', $string);
1607}
1608
1609/**
1610 * Convert file name to UTF-8 in Windows
1611 * @param string $filename
1612 * @return string
1613 */
1614function fm_convert_win($filename)
1615{
1616 if (FM_IS_WIN && function_exists('iconv')) {
1617 $filename = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $filename);
1618 }
1619 return $filename;
1620}
1621
1622/**
1623 * Get translated string
1624 * @param string $str
1625 * @param string|null $lang
1626 * @return string
1627 */
1628function fm_t($str, $lang = null)
1629{
1630 if ($lang === null) {
1631 if (defined('FM_LANG')) {
1632 $lang = FM_LANG;
1633 } else {
1634 return $str;
1635 }
1636 }
1637 $strings = fm_get_strings();
1638 if (!isset($strings[$lang]) || !is_array($strings[$lang])) {
1639 return $str;
1640 }
1641 if (array_key_exists($str, $strings[$lang])) {
1642 return $strings[$lang][$str];
1643 }
1644 return $str;
1645}
1646
1647/**
1648 * Get CSS classname for file
1649 * @param string $path
1650 * @return string
1651 */
1652function fm_get_file_icon_class($path)
1653{
1654 // get extension
1655 $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
1656
1657 switch ($ext) {
1658 case 'ico': case 'gif': case 'jpg': case 'jpeg': case 'jpc': case 'jp2':
1659 case 'jpx': case 'xbm': case 'wbmp': case 'png': case 'bmp': case 'tif':
1660 case 'tiff': case 'svg':
1661 $img = 'fa fa-picture-o';
1662 break;
1663 case 'passwd': case 'ftpquota': case 'sql': case 'js': case 'json': case 'sh':
1664 case 'config': case 'twig': case 'tpl': case 'md': case 'gitignore':
1665 case 'c': case 'cpp': case 'cs': case 'py': case 'map': case 'lock': case 'dtd':
1666 $img = 'fa fa-file-code-o';
1667 break;
1668 case 'txt': case 'ini': case 'conf': case 'log': case 'htaccess':
1669 $img = 'fa fa-file-text-o';
1670 break;
1671 case 'css': case 'less': case 'sass': case 'scss':
1672 $img = 'fa fa-css3';
1673 break;
1674 case 'zip': case 'rar': case 'gz': case 'tar': case '7z':
1675 $img = 'fa fa-file-archive-o';
1676 break;
1677 case 'php': case 'php4': case 'php5': case 'phps': case 'phtml':
1678 $img = 'fa fa-code';
1679 break;
1680 case 'htm': case 'html': case 'shtml': case 'xhtml':
1681 $img = 'fa fa-html5';
1682 break;
1683 case 'xml': case 'xsl':
1684 $img = 'fa fa-file-excel-o';
1685 break;
1686 case 'wav': case 'mp3': case 'mp2': case 'm4a': case 'aac': case 'ogg':
1687 case 'oga': case 'wma': case 'mka': case 'flac': case 'ac3': case 'tds':
1688 $img = 'fa fa-music';
1689 break;
1690 case 'm3u': case 'm3u8': case 'pls': case 'cue':
1691 $img = 'fa fa-headphones';
1692 break;
1693 case 'avi': case 'mpg': case 'mpeg': case 'mp4': case 'm4v': case 'flv':
1694 case 'f4v': case 'ogm': case 'ogv': case 'mov': case 'mkv': case '3gp':
1695 case 'asf': case 'wmv':
1696 $img = 'fa fa-file-video-o';
1697 break;
1698 case 'eml': case 'msg':
1699 $img = 'fa fa-envelope-o';
1700 break;
1701 case 'xls': case 'xlsx':
1702 $img = 'fa fa-file-excel-o';
1703 break;
1704 case 'csv':
1705 $img = 'fa fa-file-text-o';
1706 break;
1707 case 'bak':
1708 $img = 'fa fa-clipboard';
1709 break;
1710 case 'doc': case 'docx':
1711 $img = 'fa fa-file-word-o';
1712 break;
1713 case 'ppt': case 'pptx':
1714 $img = 'fa fa-file-powerpoint-o';
1715 break;
1716 case 'ttf': case 'ttc': case 'otf': case 'woff':case 'woff2': case 'eot': case 'fon':
1717 $img = 'fa fa-font';
1718 break;
1719 case 'pdf':
1720 $img = 'fa fa-file-pdf-o';
1721 break;
1722 case 'psd': case 'ai': case 'eps': case 'fla': case 'swf':
1723 $img = 'fa fa-file-image-o';
1724 break;
1725 case 'exe': case 'msi':
1726 $img = 'fa fa-file-o';
1727 break;
1728 case 'bat':
1729 $img = 'fa fa-terminal';
1730 break;
1731 default:
1732 $img = 'fa fa-info-circle';
1733 }
1734
1735 return $img;
1736}
1737
1738/**
1739 * Get image files extensions
1740 * @return array
1741 */
1742function fm_get_image_exts()
1743{
1744 return array('ico', 'gif', 'jpg', 'jpeg', 'jpc', 'jp2', 'jpx', 'xbm', 'wbmp', 'png', 'bmp', 'tif', 'tiff', 'psd');
1745}
1746
1747/**
1748 * Get video files extensions
1749 * @return array
1750 */
1751function fm_get_video_exts()
1752{
1753 return array('webm', 'mp4', 'm4v', 'ogm', 'ogv', 'mov');
1754}
1755
1756/**
1757 * Get audio files extensions
1758 * @return array
1759 */
1760function fm_get_audio_exts()
1761{
1762 return array('wav', 'mp3', 'ogg', 'm4a');
1763}
1764
1765/**
1766 * Get text file extensions
1767 * @return array
1768 */
1769function fm_get_text_exts()
1770{
1771 return array(
1772 'txt', 'css', 'ini', 'conf', 'log', 'htaccess', 'passwd', 'ftpquota', 'sql', 'js', 'json', 'sh', 'config',
1773 'php', 'php4', 'php5', 'phps', 'phtml', 'htm', 'html', 'shtml', 'xhtml', 'xml', 'xsl', 'm3u', 'm3u8', 'pls', 'cue',
1774 'eml', 'msg', 'csv', 'bat', 'twig', 'tpl', 'md', 'gitignore', 'less', 'sass', 'scss', 'c', 'cpp', 'cs', 'py',
1775 'map', 'lock', 'dtd', 'svg',
1776 );
1777}
1778
1779/**
1780 * Get mime types of text files
1781 * @return array
1782 */
1783function fm_get_text_mimes()
1784{
1785 return array(
1786 'application/xml',
1787 'application/javascript',
1788 'application/x-javascript',
1789 'image/svg+xml',
1790 'message/rfc822',
1791 );
1792}
1793
1794/**
1795 * Get file names of text files w/o extensions
1796 * @return array
1797 */
1798function fm_get_text_names()
1799{
1800 return array(
1801 'license',
1802 'readme',
1803 'authors',
1804 'contributors',
1805 'changelog',
1806 );
1807}
1808
1809/**
1810 * Class to work with zip files (using ZipArchive)
1811 */
1812class FM_Zipper
1813{
1814 private $zip;
1815
1816 public function __construct()
1817 {
1818 $this->zip = new ZipArchive();
1819 }
1820
1821 /**
1822 * Create archive with name $filename and files $files (RELATIVE PATHS!)
1823 * @param string $filename
1824 * @param array|string $files
1825 * @return bool
1826 */
1827 public function create($filename, $files)
1828 {
1829 $res = $this->zip->open($filename, ZipArchive::CREATE);
1830 if ($res !== true) {
1831 return false;
1832 }
1833 if (is_array($files)) {
1834 foreach ($files as $f) {
1835 if (!$this->addFileOrDir($f)) {
1836 $this->zip->close();
1837 return false;
1838 }
1839 }
1840 $this->zip->close();
1841 return true;
1842 } else {
1843 if ($this->addFileOrDir($files)) {
1844 $this->zip->close();
1845 return true;
1846 }
1847 return false;
1848 }
1849 }
1850
1851 /**
1852 * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
1853 * @param string $filename
1854 * @param string $path
1855 * @return bool
1856 */
1857 public function unzip($filename, $path)
1858 {
1859 $res = $this->zip->open($filename);
1860 if ($res !== true) {
1861 return false;
1862 }
1863 if ($this->zip->extractTo($path)) {
1864 $this->zip->close();
1865 return true;
1866 }
1867 return false;
1868 }
1869
1870 /**
1871 * Add file/folder to archive
1872 * @param string $filename
1873 * @return bool
1874 */
1875 private function addFileOrDir($filename)
1876 {
1877 if (is_file($filename)) {
1878 return $this->zip->addFile($filename);
1879 } elseif (is_dir($filename)) {
1880 return $this->addDir($filename);
1881 }
1882 return false;
1883 }
1884
1885 /**
1886 * Add folder recursively
1887 * @param string $path
1888 * @return bool
1889 */
1890 private function addDir($path)
1891 {
1892 if (!$this->zip->addEmptyDir($path)) {
1893 return false;
1894 }
1895 $objects = scandir($path);
1896 if (is_array($objects)) {
1897 foreach ($objects as $file) {
1898 if ($file != '.' && $file != '..') {
1899 if (is_dir($path . '/' . $file)) {
1900 if (!$this->addDir($path . '/' . $file)) {
1901 return false;
1902 }
1903 } elseif (is_file($path . '/' . $file)) {
1904 if (!$this->zip->addFile($path . '/' . $file)) {
1905 return false;
1906 }
1907 }
1908 }
1909 }
1910 return true;
1911 }
1912 return false;
1913 }
1914}
1915
1916//--- templates functions
1917
1918/**
1919 * Show nav block
1920 * @param string $path
1921 */
1922function fm_show_nav_path($path)
1923{
1924 global $lang;
1925 ?>
1926<div class="path main-nav">
1927
1928 <?php
1929 $path = fm_clean_path($path);
1930 $root_url = "<a href='?p='><i class='fa fa-home' aria-hidden='true' title='" . FM_ROOT_PATH . "'></i></a>";
1931 $sep = '<i class="fa fa-caret-right"></i>';
1932 if ($path != '') {
1933 $exploded = explode('/', $path);
1934 $count = count($exploded);
1935 $array = array();
1936 $parent = '';
1937 for ($i = 0; $i < $count; $i++) {
1938 $parent = trim($parent . '/' . $exploded[$i], '/');
1939 $parent_enc = urlencode($parent);
1940 $array[] = "<a href='?p={$parent_enc}'>" . fm_convert_win($exploded[$i]) . "</a>";
1941 }
1942 $root_url .= $sep . implode($sep, $array);
1943 }
1944 echo '<div class="break-word float-left">' . $root_url . '</div>';
1945 ?>
1946
1947 <div class="float-right">
1948 <?php if (!FM_READONLY): ?>
1949 <a title="<?php echo fm_t('Search', $lang) ?>" href="javascript:showSearch('<?php echo urlencode(FM_PATH) ?>')"><i class="fa fa-search"></i></a>
1950 <a title="<?php echo fm_t('Upload files', $lang) ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&upload"><i class="fa fa-cloud-upload" aria-hidden="true"></i></a>
1951 <a title="<?php echo fm_t('New folder', $lang) ?>" href="#createNewItem" ><i class="fa fa-plus-square"></i></a>
1952 <?php endif; ?>
1953 <?php if (FM_USE_AUTH): ?><a title="<?php echo fm_t('Logout', $lang) ?>" href="?logout=1"><i class="fa fa-sign-out" aria-hidden="true"></i></a><?php endif; ?>
1954 </div>
1955</div>
1956<?php
1957}
1958
1959/**
1960 * Show message from session
1961 */
1962function fm_show_message()
1963{
1964 if (isset($_SESSION['message'])) {
1965 $class = isset($_SESSION['status']) ? $_SESSION['status'] : 'ok';
1966 echo '<p class="message ' . $class . '">' . $_SESSION['message'] . '</p>';
1967 unset($_SESSION['message']);
1968 unset($_SESSION['status']);
1969 }
1970}
1971
1972/**
1973 * Show page header
1974 */
1975function fm_show_header()
1976{
1977 $sprites_ver = '20160315';
1978 header("Content-Type: text/html; charset=utf-8");
1979 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
1980 header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
1981 header("Pragma: no-cache");
1982
1983 global $lang;
1984 ?>
1985<!DOCTYPE html>
1986<html>
1987<head>
1988<meta charset="utf-8">
1989<title>File Manager Script</title>
1990<meta name="Description" CONTENT="Manage files in easy way, lightweight and no headache.">
1991<link rel="icon" href="<?php echo FM_SELF_URL ?>?img=favicon" type="image/png">
1992<link rel="shortcut icon" href="<?php echo FM_SELF_URL ?>?img=favicon" type="image/png">
1993<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
1994<?php if (isset($_GET['view']) && FM_USE_HIGHLIGHTJS): ?>
1995<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/styles/<?php echo FM_HIGHLIGHTJS_STYLE ?>.min.css">
1996<?php endif; ?>
1997<style>
1998html,body,div,span,p,pre,a,code,em,img,small,strong,ol,ul,li,form,label,table,tr,th,td{margin:0;padding:0;vertical-align:baseline;outline:none;font-size:100%;background:transparent;border:none;text-decoration:none}
1999html{overflow-y:scroll}body{padding:0;font:13px/16px Tahoma,Arial,sans-serif;color:#222;background:#fafafa}
2000input,select,textarea,button{font-size:inherit;font-family:inherit}
2001a{color:#296ea3;text-decoration:none}a:hover{color:#b00}img{vertical-align:middle;border:none}
2002a img{border:none}span{color:#777}small{font-size:11px;color:#999}p{margin-bottom:10px}
2003ul{margin-left:2em;margin-bottom:10px}ul{list-style-type:none;margin-left:0}ul li{padding:3px 0}
2004table{border-collapse:collapse;border-spacing:0;margin-bottom:10px;width:100%}
2005th,td{padding:4px 7px;text-align:left;vertical-align:top;border:1px solid #ddd;background:#fff;white-space:nowrap}
2006th,td.gray{background-color:#eee}td.gray span{color:#222}
2007tr:hover td{background-color:#f5f5f5}tr:hover td.gray{background-color:#eee}
2008.table{width:100%;max-width:100%;margin-bottom:1rem;margin-top:4rem;}
2009.table td,.table th{padding:.55rem;vertical-align:top;border-top:1px solid #ddd}
2010.table td label input[type="checkbox"],.table th label input[type="checkbox"]{margin-top:4px;}
2011.table thead th{vertical-align:bottom;border-bottom:2px solid #eceeef}.table tbody+tbody{border-top:2px solid #eceeef}.table .table{background-color:#fff}
2012code,pre{display:block;margin-bottom:10px;font:13px/16px Consolas,'Courier New',Courier,monospace;border:1px dashed #ccc;padding:5px;overflow:auto}
2013pre.with-hljs{padding:0} .hidden {display:none;}
2014pre.with-hljs code{margin:0;border:0;overflow:visible}
2015code.maxheight,pre.maxheight{max-height:512px}input[type="checkbox"]{margin:0;padding:0}
2016.fa.fa-caret-right{font-size:1.2em;margin:0 4px;vertical-align:middle;color:#ececec}.fa.fa-home{font-size:1.2em;vertical-align:bottom;}
2017body {margin:0 30px;margin-top: 45px;}
2018#wrapper{min-width:400px;margin:0 auto}
2019.path{padding:20px;border:1px solid #ddd;background-color:#fff;margin-bottom:10px}
2020.right{text-align:right}.center{text-align:center}.float-right{float:right}.float-left{float:left}
2021.message{padding:4px 7px;border:1px solid #ddd;background-color:#fff;margin-bottom:-3rem;margin-top:3rem;}
2022.message.ok{border-color:green;color:green}
2023.message.error{border-color:red;color:red}
2024.message.alert{border-color:orange;color:orange}
2025.btn{border:0;background:none;padding:0;margin:0;font-weight:bold;color:#296ea3;cursor:pointer}.btn:hover{color:#b00}
2026.preview-img{max-width:100%;background:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAKklEQVR42mL5//8/Azbw+PFjrOJMDCSCUQ3EABZc4S0rKzsaSvTTABBgAMyfCMsY4B9iAAAAAElFTkSuQmCC") repeat 0 0}.inline-actions>a>i{font-size:1em;margin-left:5px;background:#3785c1;color:#fff;padding:3px;border-radius:2px;}
2027.preview-video{position:relative;max-width:100%;height:0;padding-bottom:62.5%;margin-bottom:10px}.preview-video video{position:absolute;width:100%;height:100%;left:0;top:0;background:#000}
2028.compact-table{border:0;width:auto}.compact-table td,.compact-table th{width:100px;border:0;text-align:center}.compact-table tr:hover td{background-color:#fff}
2029.filename{max-width:420px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
2030.break-word{word-wrap:break-word;margin-left:30px;}.break-word.float-left a{color:#fff}.break-word+.float-right{padding-right:30px;position:relative;}.break-word+.float-right>a{color:#fff;font-size:1.2em;margin-right:4px;}
2031.modal{display:none;position:fixed;z-index:1;padding-top:100px;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:#000;background-color:rgba(0,0,0,.4)}
2032.modal-content{background-color:#fefefe;margin:auto;padding:20px;border:1px solid #888;width:80%}
2033.close{color:#aaa;float:right;font-size:28px;font-weight:700}.close:focus,.close:hover{color:#000;text-decoration:none;cursor:pointer}
2034#editor {position:absolute;top:50px;right:30px;bottom:5px;left:30px;}
2035.edit-file-actions {position: absolute;top:0;right:30px;background:#585858;margin-top:5px;}
2036.edit-file-actions>button,.edit-file-actions>a{background:#f8f8fb;padding:5px 15px;border:0;cursor:pointer;color:#296ea3}
2037.group-btn{background:#fff;padding:2px 6px;border:1px solid;cursor:pointer;color:#296ea3;}
2038.main-nav{position:fixed;top:0;left:0;padding:10px 30px;padding-left:1px;width:100%;background:#585858;color:#fff;border:0;}
2039.login-form {width:320px;text-align:center;margin:0 auto;}
2040.login-form label,.path.login-form input {padding:5px;margin:10px}.footer-links{background:transparent;border:0}
2041input[type=search]{height:30px;margin-top:20px;width:80%;border:1px solid #ccc;}
2042.modalDialog{position:fixed;font-family:Arial,Helvetica,sans-serif;top:0;right:0;bottom:0;left:0;background:rgba(0,0,0,.8);z-index:99999;opacity:0;-webkit-transition:opacity .4s ease-in;-moz-transition:opacity .4s ease-in;transition:opacity .4s ease-in;pointer-events:none}.modalDialog:target{opacity:1;pointer-events:auto}.modalDialog>.model-wrapper{width:400px;position:relative;margin:10% auto;padding:5px 20px 13px;border-radius:2px;background:#fff}.close{background:#fff;color:#000;line-height:25px;position:absolute;right:0;text-align:center;top:0;width:24px;text-decoration:none;font-weight:700;border-radius:0 5px 0 0;font-size:18px}.close:hover{background:#00d9ff}.modalDialog p{line-height:30px}
2043div#searchresultWrapper{max-height:320px;overflow:auto;}div#searchresultWrapper li{margin: 8px 0; list-style:none;}
2044li.folder:before, li.file:before{font: normal normal normal 14px/1 "FontAwesome";content:"\f016";margin-right:5px;}li.folder:before{content:"\f114";}
2045</style>
2046</head>
2047<body>
2048<div id="wrapper">
2049 <div id="createNewItem" class="modalDialog"><div class="model-wrapper"><a href="#close" title="<?php echo fm_t('Close', $lang) ?>" class="close">X</a><h2><?php echo fm_t('Create New Item', $lang) ?></h2><p>
2050 <label for="newfile"><?php echo fm_t('Item Type', $lang) ?> : </label><input type="radio" name="newfile" id="newfile" value="file"><?php echo fm_t('File', $lang) ?> <input type="radio" name="newfile" value="folder" checked> <?php echo fm_t('Folder', $lang) ?><br><label for="newfilename"><?php echo fm_t('Item Name', $lang) ?> : </label><input type="text" name="newfilename" id="newfilename" value=""><br><input type="submit" name="submit" class="group-btn" value="<?php echo fm_t('Create Now', $lang) ?>" onclick="newfolder('<?php echo fm_enc(FM_PATH) ?>');return false;"></p></div></div>
2051 <div id="searchResult" class="modalDialog"><div class="model-wrapper"><a href="#close" title="<?php echo fm_t('Close', $lang) ?>" class="close">X</a>
2052 <input type="search" name="search" value="" placeholder="<?php echo fm_t('Find a item in current folder...', $lang) ?>">
2053 <h2><?php echo fm_t('Search Results', $lang) ?></h2>
2054 <div id="searchresultWrapper"></div>
2055 </div></div>
2056<?php
2057}
2058
2059/**
2060 * Show page footer
2061 */
2062function fm_show_footer()
2063{
2064 ?>
2065</div>
2066<script>
2067function newfolder(p){var n=document.getElementById("newfilename").value;var t=document.querySelector('input[name="newfile"]:checked').value;if(n!==null&&n!==''&&t){window.location.hash="#";window.location.search='p='+encodeURIComponent(p)+'&new='+encodeURIComponent(n)+'&type='+encodeURIComponent(t);}}
2068function rename(p,f){var n=prompt('<?php global $lang; echo fm_t('New name', $lang) ?>',f);if(n!==null&&n!==''&&n!=f){window.location.search='p='+encodeURIComponent(p)+'&ren='+encodeURIComponent(f)+'&to='+encodeURIComponent(n);}}
2069function change_checkboxes(l,v){for(var i=l.length-1;i>=0;i--){l[i].checked=(typeof v==='boolean')?v:!l[i].checked;}}
2070function get_checkboxes(){var i=document.getElementsByName('file[]'),a=[];for(var j=i.length-1;j>=0;j--){if(i[j].type='checkbox'){a.push(i[j]);}}return a;}
2071function select_all(){var l=get_checkboxes();change_checkboxes(l,true);}
2072function unselect_all(){var l=get_checkboxes();change_checkboxes(l,false);}
2073function invert_all(){var l=get_checkboxes();change_checkboxes(l);}
2074function mailto(p,f){var http=new XMLHttpRequest(); var params="path="+p+"&file="+f+"&type=mail&ajax=true"; http.open("POST", '', true);http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");http.onreadystatechange=function(){if(http.readyState == 4 && http.status == 200){ alert(http.responseText);}}
2075http.send(params);
2076}
2077function showSearch(u){var http=new XMLHttpRequest();var params="path="+u+"&type=search&ajax=true";http.open("POST", '', true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");http.onreadystatechange=function(){if(http.readyState == 4 && http.status == 200){ window.searchObj = http.responseText; document.getElementById('searchresultWrapper').innerHTML = "";window.location.hash="#searchResult"}}
2078http.send(params);}
2079var searchEl = document.querySelector('input[type=search]');var timeout = null;searchEl.onkeyup = function(evt) {clearTimeout(timeout);var data = JSON.parse(window.searchObj);var searchTerms = document.querySelector('input[type=search]').value;timeout = setTimeout(function () {if(searchTerms.length>=2) {var res = getSearchResult(data,searchTerms);var f1='',f2='';res.folders.forEach(function (d){f1+='<li class="'+d.type+'"><a href="?p='+ d.path+'">'+d.name+'</a></li>'; });res.files.forEach(function (d){f2+='<li class="'+d.type+'"><a href="?p='+ d.path +'&view='+ d.name +'">'+d.name+'</a></li>';});document.getElementById('searchresultWrapper').innerHTML = '<div class="model-wrapper">'+f1+f2+'</div>';}},500);};
2080function getSearchResult(data,searchTerms) {var folders=[],files=[];data.forEach(function(d){if(d.type === 'folder') { getSearchResult(d.items,searchTerms);if(d.name.toLowerCase().match(searchTerms)) {folders.push(d);}} else if(d.type === 'file') {if(d.name.toLowerCase().match(searchTerms)) {files.push(d);} }}); return {folders: folders, files: files};}
2081function checkbox_toggle(){var l=get_checkboxes();l.push(this);change_checkboxes(l);}
2082function backup(p,f){ var http=new XMLHttpRequest();var params="path="+p+"&file="+f+"&type=backup&ajax=true";http.open("POST", '', true);http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");http.onreadystatechange=function(){if(http.readyState == 4 && http.status == 200){alert(http.responseText);}}
2083http.send(params); return false; }
2084function edit_save(i,atr){var contents=(atr=="ace")?editor.getSession().getValue():document.getElementById('normal-editor').value;if(!!contents){var form=document.createElement("form");form.setAttribute("method", 'POST');form.setAttribute("action", '');var inputField=document.createElement("textarea");inputField.setAttribute("type", "textarea");inputField.setAttribute("name", 'savedata');var _temp=document.createTextNode(contents);inputField.appendChild(_temp);form.appendChild(inputField);document.body.appendChild(form);form.submit();}}
2085</script>
2086<?php if (isset($_GET['view']) && FM_USE_HIGHLIGHTJS): ?>
2087<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/highlight.min.js"></script>
2088<script>hljs.initHighlightingOnLoad();</script>
2089<?php endif; ?>
2090<?php if (isset($_GET['edit']) && isset($_GET['env']) && FM_EDIT_FILE): ?>
2091<script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.2.8/ace.js"></script>
2092<script>var editor = ace.edit("editor");editor.getSession().setMode("ace/mode/javascript");</script>
2093<?php endif; ?>
2094</body>
2095</html>
2096<?php
2097}
2098
2099/**
2100 * Show image
2101 * @param string $img
2102 */
2103function fm_show_image($img)
2104{
2105 $modified_time = gmdate('D, d M Y 00:00:00') . ' GMT';
2106 $expires_time = gmdate('D, d M Y 00:00:00', strtotime('+1 day')) . ' GMT';
2107
2108 $img = trim($img);
2109 $images = fm_get_images();
2110 $image = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEElEQVR42mL4//8/A0CAAQAI/AL+26JNFgAAAABJRU5ErkJggg==';
2111 if (isset($images[$img])) {
2112 $image = $images[$img];
2113 }
2114 $image = base64_decode($image);
2115 if (function_exists('mb_strlen')) {
2116 $size = mb_strlen($image, '8bit');
2117 } else {
2118 $size = strlen($image);
2119 }
2120
2121 if (function_exists('header_remove')) {
2122 header_remove('Cache-Control');
2123 header_remove('Pragma');
2124 } else {
2125 header('Cache-Control:');
2126 header('Pragma:');
2127 }
2128
2129 header('Last-Modified: ' . $modified_time, true, 200);
2130 header('Expires: ' . $expires_time);
2131 header('Content-Length: ' . $size);
2132 header('Content-Type: image/png');
2133 echo $image;
2134
2135 exit;
2136}
2137
2138/**
2139 * Get base64-encoded images
2140 * @return array
2141 */
2142function fm_get_images()
2143{
2144 return array(
2145 'favicon' => 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
2146bWFnZVJlYWR5ccllPAAAAZVJREFUeNqkk79Lw0AUx1+uidTQim4Waxfpnl1BcHMR6uLkIF0cpYOI
2147f4KbOFcRwbGTc0HQSVQQXCqlFIXgFkhIyvWS870LaaPYH9CDy8vdfb+fey930aSUMEvT6VHVzw8x
2148rKUX3N3Hj/8M+cZ6GcOtBPl6KY5iAA7KJzfVWrfbhUKhALZtQ6myDf1+X5nsuzjLUmUOnpa+v5r1
2149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gKfAADb
21634vb76N2au9by2I9gYGVIRkhNTE90wfXq2sh8gL8QMZ3pyn27AADr+uu1traNiIh2olTTshifodQ4
2164ZM663PH97+YeRq2GqmRjmkGjnEDnfjLVVg6W4f7s6/p/0fr98+5UVF6wz+SjxNsmVb5RUVWMrc7d
2165zrrIpWI8PD3pkwhCltZFYbNZja82wPv05NPRdXzhvna4uFdIiibPegGQXankxyxe0P7PnOhTkDGA
2166gBrbhgR9fX9bW1u8nRFamcgvVrACJIvlXV06nvtdgON4mdn3og7AagBTufkucO7snJz4b28XEhIT
2167sflynsLEvIk55kr866aewo2YuYDrnFffOTk6Li6hgAn3y8XkusCHZQbt0NP571lqRDZyMw96lZXE
2168s6qcrMmJaTmVdRW2AAAAbnRSTlMAZodsJHZocHN7hP77gnaCZWdx/ki+RfqOd/7+zc9N/szMZlf8
2169z8yeQybOzlv+tP5q/qKRbk78i/vZmf798s3MojiYjTj+/vqKbFc2/vvMzJiPXPzbs4z9++bj1XbN
2170uJxhyMBWwJbp28C9tJ6L1xTnMfMAAA79SURBVGje7Jn5b8thHMcfzLDWULXq2upqHT2kbrVSrJYx
2171NzHmviWOrCudqxhbNdZqHauKJTZHm0j0ByYkVBCTiC1+EH6YRBY/EJnjD3D84PMc3++39Z1rjp+8
2172Kn189rT5Pt/363k+3YHEDOrCSKP16t48q8U1IysLAUKZk1obLBYDKjAUoB8ziLv4vyQLQD+Lcf4Q
2173jvno90kfDaQTRhcioIv7QPk2oJqF0PsIT29RzQdOEhfKG6QW8lcoLIYxjWPQD2GXr/63BhYsWrQA
2174fYc0JSaNxa8dH4zUEYag32f009DTkNTnC4WkpcRAl4ryHTt37d5/ugxCIIEfZ0Dg4poFThIXygSp
2175hfybmhSWLS0dCpDrdFMRZubUkmJ2+d344qIU8sayN8iFQaBgMDy+FWA/wjelOmbrHUKVtQgxFqFc
2176JeE2RpmLEIlfFazzer3hcOAPCQiFasNheAo9HQ1f6FZRTgzs2bOnFwn8+AnG8d6impClTkSjCXWW
2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59F5oBJnsUI6KcDz0B0H/+7S8MwG6DR8Bhd6D4Jj9GQlqPogk/JZs9
2232K/gn5H40e7aL7oToUYAfYMvUnMw40Gkw4Q80O6XcLMRZFgYwxrKl4saJjabqjRMCf6QDdOkeldJ/
2233BfSnrvWLcWgYxGX6KfPswEKLZVL6yrgXvv6g9uMBoDic3B/9e36KLvDNS7TZ7K3sGdE/wfoqDQD9
2234NGG+9AmYL/MDRM5iLo9nqDEYAJWRx5U5o+3SaHRaplS8H+Faf78Yh4bJ8k2Vz24qgJldXj8/DkCf
2235wDy8fH/sdpujTD2KxhxM/ueA249E/wTru/Dfl05bPkeC5TI/QOAvbJjL47TnI8BDy+KlOJPV6bJM
2236yfg3wNf+r99KxafOibNu5IQvKKsv2x9lTtEFvmGlXq9/rFeL/gnWD2kB6KcwcpB+wP/IyeP2svqp
22379oeiCT9Fr1cL/gmp125aUc4P+B85iX+qJ/la0k/Ze0D0T0j93jXTpv0BYUGhQhdSooYAAAAASUVO
2238RK5CYII=',
2239 );
2240}
2241
2242/**
2243 * Get all translations
2244 * @return array
2245 */
2246function fm_get_strings()
2247{
2248 static $strings;
2249 if ($strings !== null) {
2250 return $strings;
2251 }
2252 $strings = array();
2253
2254 // get additional translations from 'filemanager-l10n.php'
2255 $l10n_path = __DIR__ . '/filemanager-l10n.php';
2256 if (is_readable($l10n_path)) {
2257 $l10n_strings = include $l10n_path;
2258 if (!empty($l10n_strings) && is_array($l10n_strings)) {
2259 $strings = array_merge($strings, $l10n_strings);
2260 }
2261 }
2262
2263 return $strings;
2264}
2265
2266/**
2267 * Get all available languages
2268 * @return array
2269 */
2270function fm_get_available_langs()
2271{
2272 $strings = fm_get_strings();
2273 $languages = array_keys($strings);
2274 $languages[] = 'en';
2275 return $languages;
2276}