forked from Studio-42/elFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elFinderVolumeDriver.class.php
3600 lines (3093 loc) · 96.1 KB
/
elFinderVolumeDriver.class.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Base class for elFinder volume.
* Provide 2 layers:
* 1. Public API (commands)
* 2. abstract fs API
*
* All abstract methods begin with "_"
*
* @author Dmitry (dio) Levashov
* @author Troex Nevelin
* @author Alexey Sukhotin
**/
abstract class elFinderVolumeDriver {
/**
* Driver id
* Must be started from letter and contains [a-z0-9]
* Used as part of volume id
*
* @var string
**/
protected $driverId = 'a';
/**
* Volume id - used as prefix for files hashes
*
* @var string
**/
protected $id = '';
/**
* Flag - volume "mounted" and available
*
* @var bool
**/
protected $mounted = false;
/**
* Root directory path
*
* @var string
**/
protected $root = '';
/**
* Root basename | alias
*
* @var string
**/
protected $rootName = '';
/**
* Default directory to open
*
* @var string
**/
protected $startPath = '';
/**
* Base URL
*
* @var string
**/
protected $URL = '';
/**
* Thumbnails dir path
*
* @var string
**/
protected $tmbPath = '';
/**
* Is thumbnails dir writable
*
* @var bool
**/
protected $tmbPathWritable = false;
/**
* Thumbnails base URL
*
* @var string
**/
protected $tmbURL = '';
/**
* Thumbnails size in px
*
* @var int
**/
protected $tmbSize = 48;
/**
* Image manipulation lib name
* auto|imagick|mogtify|gd
*
* @var string
**/
protected $imgLib = 'auto';
/**
* Library to crypt files name
*
* @var string
**/
protected $cryptLib = '';
/**
* Archivers config
*
* @var array
**/
protected $archivers = array(
'create' => array(),
'extract' => array()
);
/**
* How many subdirs levels return for tree
*
* @var int
**/
protected $treeDeep = 1;
/**
* Errors from last failed action
*
* @var array
**/
protected $error = array();
/**
* Today 24:00 timestamp
*
* @var int
**/
protected $today = 0;
/**
* Yesterday 24:00 timestamp
*
* @var int
**/
protected $yesterday = 0;
/**
* Object configuration
*
* @var array
**/
protected $options = array(
'id' => '',
// root directory path
'path' => '',
// open this path on initial request instead of root path
'startPath' => '',
// how many subdirs levels return per request
'treeDeep' => 1,
// root url, not set to disable sending URL to client (replacement for old "fileURL" option)
'URL' => '',
// directory separator. required by client to show paths correctly
'separator' => DIRECTORY_SEPARATOR,
// library to crypt/uncrypt files names (not implemented)
'cryptLib' => '',
// how to detect files mimetypes. (auto/internal/finfo/mime_content_type)
'mimeDetect' => 'auto',
// mime.types file path (for mimeDetect==internal)
'mimefile' => '',
// directory for thumbnails
'tmbPath' => '.tmb',
// mode to create thumbnails dir
'tmbPathMode' => 0777,
// thumbnails dir URL. Set it if store thumbnails outside root directory
'tmbURL' => '',
// thumbnails size (px)
'tmbSize' => 48,
// thumbnails crop (true - crop, false - scale image to fit thumbnail size)
'tmbCrop' => true,
// thumbnails background color (hex #rrggbb or 'transparent')
'tmbBgColor' => '#ffffff',
// image manipulations library
'imgLib' => 'auto',
// on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext
'copyOverwrite' => true,
// if true - join new and old directories content on paste
'copyJoin' => true,
// on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext
'uploadOverwrite' => true,
// mimetypes allowed to upload
'uploadAllow' => array(),
// mimetypes not allowed to upload
'uploadDeny' => array(),
// order to proccess uploadAllow and uploadDeny options
'uploadOrder' => array('deny', 'allow'),
// maximum upload file size. NOTE - this is size for every uploaded files
'uploadMaxSize' => 0,
// files dates format
'dateFormat' => 'j M Y H:i',
// files time format
'timeFormat' => 'H:i',
// if true - every folder will be check for children folders, otherwise all folders will be marked as having subfolders
'checkSubfolders' => true,
// allow to copy from this volume to other ones?
'copyFrom' => true,
// allow to copy from other volumes to this one?
'copyTo' => true,
// list of commands disabled on this root
'disabled' => array(),
// regexp or function name to validate new file name
'acceptedName' => '/^[^\.].*/', //<-- DONT touch this! Use constructor options to overwrite it!
// function/class method to control files permissions
'accessControl' => null,
// some data required by access control
'accessControlData' => null,
// default permissions.
'defaults' => array(
'read' => true,
'write' => true,
'locked' => false,
'hidden' => false
),
// files attributes
'attributes' => array(),
// Allowed archive's mimetypes to create. Leave empty for all available types.
'archiveMimes' => array(),
// Manual config for archivers. See example below. Leave empty for auto detect
'archivers' => array(),
// required to fix bug on macos
'utf8fix' => false,
// й ё Й Ё Ø Å
'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"),
'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5")
);
/**
* Defaults permissions
*
* @var array
**/
protected $defaults = array(
'read' => true,
'write' => true,
'locked' => false,
'hidden' => false
);
/**
* Access control function/class
*
* @var mixed
**/
protected $attributes = array();
/**
* Access control function/class
*
* @var mixed
**/
protected $access = null;
/**
* Mime types allowed to upload
*
* @var array
**/
protected $uploadAllow = array();
/**
* Mime types denied to upload
*
* @var array
**/
protected $uploadDeny = array();
/**
* Order to validate uploadAllow and uploadDeny
*
* @var array
**/
protected $uploadOrder = array();
/**
* Maximum allowed upload file size.
* Set as number or string with unit - "10M", "500K", "1G"
*
* @var int|string
**/
protected $uploadMaxSize = 0;
/**
* Mimetype detect method
*
* @var string
**/
protected $mimeDetect = 'auto';
/**
* Flag - mimetypes from externail file was loaded
*
* @var bool
**/
private static $mimetypesLoaded = false;
/**
* Finfo object for mimeDetect == 'finfo'
*
* @var object
**/
protected $finfo = null;
/**
* List of disabled client's commands
*
* @var array
**/
protected $disabled = array();
/**
* default extensions/mimetypes for mimeDetect == 'internal'
*
* @var array
**/
protected static $mimetypes = array(
// applications
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'exe' => 'application/x-executable',
'doc' => 'application/vnd.ms-word',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'pps' => 'application/vnd.ms-powerpoint',
'pdf' => 'application/pdf',
'xml' => 'application/xml',
'swf' => 'application/x-shockwave-flash',
'torrent' => 'application/x-bittorrent',
'jar' => 'application/x-jar',
// open office (finfo detect as application/zip)
'odt' => 'application/vnd.oasis.opendocument.text',
'ott' => 'application/vnd.oasis.opendocument.text-template',
'oth' => 'application/vnd.oasis.opendocument.text-web',
'odm' => 'application/vnd.oasis.opendocument.text-master',
'odg' => 'application/vnd.oasis.opendocument.graphics',
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
'odc' => 'application/vnd.oasis.opendocument.chart',
'odf' => 'application/vnd.oasis.opendocument.formula',
'odb' => 'application/vnd.oasis.opendocument.database',
'odi' => 'application/vnd.oasis.opendocument.image',
'oxt' => 'application/vnd.openofficeorg.extension',
// MS office 2007 (finfo detect as application/zip)
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
// archives
'gz' => 'application/x-gzip',
'tgz' => 'application/x-gzip',
'bz' => 'application/x-bzip2',
'bz2' => 'application/x-bzip2',
'tbz' => 'application/x-bzip2',
'xz' => 'application/x-xz',
'zip' => 'application/zip',
'rar' => 'application/x-rar',
'tar' => 'application/x-tar',
'7z' => 'application/x-7z-compressed',
// texts
'txt' => 'text/plain',
'php' => 'text/x-php',
'html' => 'text/html',
'htm' => 'text/html',
'js' => 'text/javascript',
'css' => 'text/css',
'rtf' => 'text/rtf',
'rtfd' => 'text/rtfd',
'py' => 'text/x-python',
'java' => 'text/x-java-source',
'rb' => 'text/x-ruby',
'sh' => 'text/x-shellscript',
'pl' => 'text/x-perl',
'xml' => 'text/xml',
'sql' => 'text/x-sql',
'c' => 'text/x-csrc',
'h' => 'text/x-chdr',
'cpp' => 'text/x-c++src',
'hh' => 'text/x-c++hdr',
'log' => 'text/plain',
'csv' => 'text/x-comma-separated-values',
// images
'bmp' => 'image/x-ms-bmp',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'tga' => 'image/x-targa',
'psd' => 'image/vnd.adobe.photoshop',
'ai' => 'image/vnd.adobe.photoshop',
'xbm' => 'image/xbm',
'pxm' => 'image/pxm',
//audio
'mp3' => 'audio/mpeg',
'mid' => 'audio/midi',
'ogg' => 'audio/ogg',
'oga' => 'audio/ogg',
'm4a' => 'audio/x-m4a',
'wav' => 'audio/wav',
'wma' => 'audio/x-ms-wma',
// video
'avi' => 'video/x-msvideo',
'dv' => 'video/x-dv',
'mp4' => 'video/mp4',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mov' => 'video/quicktime',
'wm' => 'video/x-ms-wmv',
'flv' => 'video/x-flv',
'mkv' => 'video/x-matroska',
'webm' => 'video/webm',
'ogv' => 'video/ogg',
'ogm' => 'video/ogg'
);
/**
* Directory separator - required by client
*
* @var string
**/
protected $separator = DIRECTORY_SEPARATOR;
/**
* Mimetypes allowed to display
*
* @var array
**/
protected $onlyMimes = array();
/**
* Store files moved or overwrited files info
*
* @var array
**/
protected $removed = array();
/**
* Cache storage
*
* @var array
**/
protected $cache = array();
/**
* Cache by folders
*
* @var array
**/
protected $dirsCache = array();
/*********************************************************************/
/* INITIALIZATION */
/*********************************************************************/
/**
* Prepare driver before mount volume.
* Return true if volume is ready.
*
* @return bool
* @author Dmitry (dio) Levashov
**/
protected function init() {
return true;
}
/**
* Configure after successfull mount.
* By default set thumbnails path and image manipulation library.
*
* @return void
* @author Dmitry (dio) Levashov
**/
protected function configure() {
// set thumbnails path
$path = $this->options['tmbPath'];
if ($path) {
if (!file_exists($path)) {
if (@mkdir($path)) {
chmod($path, $this->options['tmbPathMode']);
} else {
$path = '';
}
}
if (is_dir($path) && is_readable($path)) {
$this->tmbPath = $path;
$this->tmbPathWritable = is_writable($path);
}
}
// set image manipulation library
$type = preg_match('/^(imagick|gd|auto)$/i', $this->options['imgLib'])
? strtolower($this->options['imgLib'])
: 'auto';
if (($type == 'imagick' || $type == 'auto') && extension_loaded('imagick')) {
$this->imgLib = 'imagick';
} else {
$this->imgLib = function_exists('gd_info') ? 'gd' : '';
}
}
/*********************************************************************/
/* PUBLIC API */
/*********************************************************************/
/**
* Return driver id. Used as a part of volume id.
*
* @return string
* @author Dmitry (dio) Levashov
**/
public function driverId() {
return $this->driverId;
}
/**
* Return volume id
*
* @return string
* @author Dmitry (dio) Levashov
**/
public function id() {
return $this->id;
}
/**
* Return debug info for client
*
* @return array
* @author Dmitry (dio) Levashov
**/
public function debug() {
return array(
'id' => $this->id(),
'name' => strtolower(substr(get_class($this), strlen('elfinderdriver'))),
'mimeDetect' => $this->mimeDetect,
'imgLib' => $this->imgLib
);
}
/**
* "Mount" volume.
* Return true if volume available for read or write,
* false - otherwise
*
* @return bool
* @author Dmitry (dio) Levashov
* @author Alexey Sukhotin
**/
public function mount(array $opts) {
if (!isset($opts['path']) || $opts['path'] === '') {
return $this->setError('Path undefined.');;
}
$this->options = array_merge($this->options, $opts);
$this->id = $this->driverId.(!empty($this->options['id']) ? $this->options['id'] : elFinder::$volumesCnt++).'_';
$this->root = $this->_normpath($this->options['path']);
$this->separator = isset($this->options['separator']) ? $this->options['separator'] : DIRECTORY_SEPARATOR;
// default file attribute
$this->defaults = array(
'read' => isset($this->options['defaults']['read']) ? !!$this->options['defaults']['read'] : true,
'write' => isset($this->options['defaults']['write']) ? !!$this->options['defaults']['write'] : true,
'locked' => isset($this->options['defaults']['locked']) ? !!$this->options['defaults']['locked'] : false,
'hidden' => isset($this->options['defaults']['hidden']) ? !!$this->options['defaults']['hidden'] : false
);
// root attributes
$this->attributes[] = array(
'pattern' => '~^'.preg_quote(DIRECTORY_SEPARATOR).'$~',
'locked' => true,
'hidden' => false
);
// set files attributes
if (!empty($this->options['attributes']) && is_array($this->options['attributes'])) {
foreach ($this->options['attributes'] as $a) {
// attributes must contain pattern and at least one rule
if (!empty($a['pattern']) || count($a) > 1) {
$this->attributes[] = $a;
}
}
}
if (!empty($this->options['accessControl']) && is_callable($this->options['accessControl'])) {
$this->access = $this->options['accessControl'];
}
$this->today = mktime(0,0,0, date('m'), date('d'), date('Y'));
$this->yesterday = $this->today-86400;
// debug($this->attributes);
if (!$this->init()) {
return false;
}
// check some options is arrays
$this->uploadAllow = isset($this->options['uploadAllow']) && is_array($this->options['uploadAllow'])
? $this->options['uploadAllow']
: array();
$this->uploadDeny = isset($this->options['uploadDeny']) && is_array($this->options['uploadDeny'])
? $this->options['uploadDeny']
: array();
if (is_string($this->options['uploadOrder'])) { // telephat_mode on, compatibility with 1.x
$parts = explode(',', isset($this->options['uploadOrder']) ? $this->options['uploadOrder'] : 'deny,allow');
$this->uploadOrder = array(trim($parts[0]), trim($parts[1]));
} else { // telephat_mode off
$this->uploadOrder = $this->options['uploadOrder'];
}
if (!empty($this->options['uploadMaxSize'])) {
$size = ''.$this->options['uploadMaxSize'];
$unit = strtolower(substr($size, strlen($size) - 1));
$n = 1;
switch ($unit) {
case 'k':
$n = 1024;
break;
case 'm':
$n = 1048576;
break;
case 'g':
$n = 1073741824;
}
$this->uploadMaxSize = intval($size)*$n;
}
$this->disabled = isset($this->options['disabled']) && is_array($this->options['disabled'])
? $this->options['disabled']
: array();
$this->cryptLib = $this->options['cryptLib'];
$this->mimeDetect = $this->options['mimeDetect'];
// find available mimetype detect method
$type = strtolower($this->options['mimeDetect']);
$type = preg_match('/^(finfo|mime_content_type|internal|auto)$/i', $type) ? $type : 'auto';
$regexp = '/text\/x\-(php|c\+\+)/';
if (($type == 'finfo' || $type == 'auto')
&& class_exists('finfo')) {
$tmpFileInfo = @explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__));
} else {
$tmpFileInfo = false;
}
if ($tmpFileInfo && preg_match($regexp, array_shift($tmpFileInfo))) {
$type = 'finfo';
$this->finfo = finfo_open(FILEINFO_MIME);
} elseif (($type == 'mime_content_type' || $type == 'auto')
&& function_exists('mime_content_type')
&& preg_match($regexp, array_shift(explode(';', mime_content_type(__FILE__))))) {
$type = 'mime_content_type';
} else {
$type = 'internal';
}
$this->mimeDetect = $type;
// load mimes from external file for mimeDetect == 'internal'
// based on Alexey Sukhotin idea and patch: http://elrte.org/redmine/issues/163
// file must be in file directory or in parent one
if ($this->mimeDetect == 'internal' && !self::$mimetypesLoaded) {
self::$mimetypesLoaded = true;
$this->mimeDetect = 'internal';
$file = false;
if (!empty($this->options['mimefile']) && file_exists($this->options['mimefile'])) {
$file = $this->options['mimefile'];
} elseif (file_exists(dirname(__FILE__).DIRECTORY_SEPARATOR.'mime.types')) {
$file = dirname(__FILE__).DIRECTORY_SEPARATOR.'mime.types';
} elseif (file_exists(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'mime.types')) {
$file = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'mime.types';
}
if ($file && file_exists($file)) {
$mimecf = file($file);
foreach ($mimecf as $line_num => $line) {
if (!preg_match('/^\s*#/', $line)) {
$mime = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 1, $size = count($mime); $i < $size ; $i++) {
if (!isset(self::$mimetypes[$mime[$i]])) {
self::$mimetypes[$mime[$i]] = $mime[0];
}
}
}
}
}
}
$this->rootName = empty($this->options['alias']) ? $this->_basename($this->root) : $this->options['alias'];
// This get's triggered if $this->root == '/' and alias is empty.
// Maybe modify _basename instead?
if ($this->rootName === '') $this->rootName = $this->separator;
$root = $this->stat($this->root);
if (!$root) {
return $this->setError('Root folder does not exists.');
}
if (!$root['read'] && !$root['write']) {
return $this->setError('Root folder has not read and write permissions.');
}
// debug($root);
if ($root['read']) {
// check startPath - path to open by default instead of root
if ($this->options['startPath']) {
$start = $this->stat($this->options['startPath']);
if (!empty($start)
&& $start['mime'] == 'directory'
&& $start['read']
&& empty($start['hidden'])
&& $this->_inpath($this->options['startPath'], $this->root)) {
$this->startPath = $this->options['startPath'];
if (substr($this->startPath, -1, 1) == $this->options['separator']) {
$this->startPath = substr($this->startPath, 0, -1);
}
}
}
} else {
$this->options['URL'] = '';
$this->options['tmbURL'] = '';
$this->options['tmbPath'] = '';
// read only volume
array_unshift($this->attributes, array(
'pattern' => '/.*/',
'read' => false
));
}
$this->treeDeep = $this->options['treeDeep'] > 0 ? (int)$this->options['treeDeep'] : 1;
$this->tmbSize = $this->options['tmbSize'] > 0 ? (int)$this->options['tmbSize'] : 48;
$this->URL = $this->options['URL'];
if ($this->URL && preg_match("|[^/?&=]$|", $this->URL)) {
$this->URL .= '/';
}
$this->tmbURL = !empty($this->options['tmbURL']) ? $this->options['tmbURL'] : '';
if ($this->tmbURL && preg_match("|[^/?&=]$|", $this->tmbURL)) {
$this->tmbURL .= '/';
}
$this->nameValidator = !empty($this->options['acceptedName']) && (is_string($this->options['acceptedName']) || is_callable($this->options['acceptedName']))
? $this->options['acceptedName']
: '';
$this->_checkArchivers();
// manual control archive types to create
if (!empty($this->options['archiveMimes']) && is_array($this->options['archiveMimes'])) {
foreach ($this->archivers['create'] as $mime => $v) {
if (!in_array($mime, $this->options['archiveMimes'])) {
unset($this->archivers['create'][$mime]);
}
}
}
// manualy add archivers
if (!empty($this->options['archivers']['create']) && is_array($this->options['archivers']['create'])) {
foreach ($this->options['archivers']['create'] as $mime => $conf) {
if (strpos($mime, 'application/') === 0
&& !empty($conf['cmd'])
&& isset($conf['argc'])
&& !empty($conf['ext'])
&& !isset($this->archivers['create'][$mime])) {
$this->archivers['create'][$mime] = $conf;
}
}
}
if (!empty($this->options['archivers']['extract']) && is_array($this->options['archivers']['extract'])) {
foreach ($this->options['archivers']['extract'] as $mime => $conf) {
if (strpos($mime, 'application/') === 0
&& !empty($conf['cmd'])
&& isset($conf['argc'])
&& !empty($conf['ext'])
&& !isset($this->archivers['extract'][$mime])) {
$this->archivers['extract'][$mime] = $conf;
}
}
}
$this->configure();
// echo $this->uploadMaxSize;
// echo $this->options['uploadMaxSize'];
return $this->mounted = true;
}
/**
* Some "unmount" stuffs - may be required by virtual fs
*
* @return void
* @author Dmitry (dio) Levashov
**/
public function umount() {
}
/**
* Return error message from last failed action
*
* @return array
* @author Dmitry (dio) Levashov
**/
public function error() {
return $this->error;
}
/**
* Set mimetypes allowed to display to client
*
* @param array $mimes
* @return void
* @author Dmitry (dio) Levashov
**/
public function setMimesFilter($mimes) {
if (is_array($mimes)) {
$this->onlyMimes = $mimes;
}
}
/**
* Return root folder hash
*
* @return string
* @author Dmitry (dio) Levashov
**/
public function root() {
return $this->encode($this->root);
}
/**
* Return root or startPath hash
*
* @return string
* @author Dmitry (dio) Levashov
**/
public function defaultPath() {
return $this->encode($this->startPath ? $this->startPath : $this->root);
}
/**
* Return volume options required by client:
*
* @return array
* @author Dmitry (dio) Levashov
**/
public function options($hash) {
return array(
'path' => $this->_path($this->decode($hash)),
'url' => $this->URL,
'tmbUrl' => $this->tmbURL,
'disabled' => $this->disabled,
'separator' => $this->separator,
'copyOverwrite' => intval($this->options['copyOverwrite']),
'archivers' => array(
// 'create' => array_keys($this->archivers['create']),
// 'extract' => array_keys($this->archivers['extract']),
'create' => isset($this->archivers['create']) && is_array($this->archivers['create']) ? array_keys($this->archivers['create']) : array(),
'extract' => isset($this->archivers['extract']) && is_array($this->archivers['extract']) ? array_keys($this->archivers['extract']) : array()
)
);
}
/**
* Return true if command disabled in options
*
* @param string $cmd command name
* @return bool
* @author Dmitry (dio) Levashov
**/
public function commandDisabled($cmd) {
return in_array($cmd, $this->disabled);
}
/**
* Return true if mime is required mimes list
*
* @param string $mime mime type to check
* @param array $mimes allowed mime types list or not set to use client mimes list
* @param bool|null $empty what to return on empty list
* @return bool|null
* @author Dmitry (dio) Levashov
* @author Troex Nevelin
**/
public function mimeAccepted($mime, $mimes = array(), $empty = true) {
$mimes = !empty($mimes) ? $mimes : $this->onlyMimes;
if (empty($mimes)) {
return $empty;
}
return $mime == 'directory'
|| in_array('all', $mimes)
|| in_array('All', $mimes)
|| in_array($mime, $mimes)
|| in_array(substr($mime, 0, strpos($mime, '/')), $mimes);
}
/**
* Return true if voume is readable.
*
* @return bool
* @author Dmitry (dio) Levashov
**/
public function isReadable() {
$stat = $this->stat($this->root);
return $stat['read'];
}
/**
* Return true if copy from this volume allowed
*
* @return bool
* @author Dmitry (dio) Levashov
**/
public function copyFromAllowed() {
return !!$this->options['copyFrom'];
}
/**
* Return file path related to root
*
* @param string $hash file hash
* @return string
* @author Dmitry (dio) Levashov
**/
public function path($hash) {
return $this->_path($this->decode($hash));
}
/**
* Return file real path if file exists
*
* @param string $hash file hash
* @return string
* @author Dmitry (dio) Levashov
**/
public function realpath($hash) {
$path = $this->decode($hash);
return $this->stat($path) ? $path : false;
}
/**
* Return list of moved/overwrited files
*
* @return array
* @author Dmitry (dio) Levashov
**/
public function removed() {
return $this->removed;
}
/**
* Clean removed files list
*
* @return void
* @author Dmitry (dio) Levashov
**/
public function resetRemoved() {
$this->removed = array();
}
/**
* Return file/dir hash or first founded child hash with required attr == $val
*
* @param string $hash file hash
* @param string $attr attribute name
* @param bool $val attribute value
* @return string|false