-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
elFinderVolumeDriver.class.php
7668 lines (6938 loc) · 256 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
* @method netmountPrepare(array $options)
* @method postNetmount(array $options)
*/
abstract class elFinderVolumeDriver
{
/**
* Net mount key
*
* @var string
**/
public $netMountKey = '';
/**
* Request args
* $_POST or $_GET values
*
* @var array
*/
protected $ARGS = array();
/**
* 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 = '';
/**
* Path to temporary directory
*
* @var string
*/
protected $tmp;
/**
* A file save destination path when a temporary content URL is required
* on a network volume or the like
* If not specified, it tries to use "Connector Path/../files/.tmb".
*
* @var string
*/
protected $tmpLinkPath = '';
/**
* A file save destination URL when a temporary content URL is required
* on a network volume or the like
* If not specified, it tries to use "Connector URL/../files/.tmb".
*
* @var string
*/
protected $tmpLinkUrl = '';
/**
* 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|gd|convert
*
* @var string
**/
protected $imgLib = 'auto';
/**
* Video to Image converter
*
* @var array
*/
protected $imgConverter = array();
/**
* Library to crypt files name
*
* @var string
**/
protected $cryptLib = '';
/**
* Archivers config
*
* @var array
**/
protected $archivers = array(
'create' => array(),
'extract' => array()
);
/**
* Static var of $this->options['maxArcFilesSize']
*
* @var int|string
*/
protected static $maxArcFilesSize;
/**
* Server character encoding
*
* @var string or null
**/
protected $encoding = null;
/**
* 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;
/**
* Force make dirctory on extract
*
* @var int
**/
protected $extractToNewdir = 'auto';
/**
* Object configuration
*
* @var array
**/
protected $options = array(
// Driver ID (Prefix of volume ID), Normally, the value specified for each volume driver is used.
'driverId' => '',
// Id (Suffix of volume ID), Normally, the number incremented according to the specified number of volumes is used.
'id' => '',
// revision id of root directory that uses for caching control of root stat
'rootRev' => '',
// driver type it uses volume root's CSS class name. e.g. 'group' -> Adds 'elfinder-group' to CSS class name.
'type' => '',
// root directory path
'path' => '',
// Folder hash value on elFinder to be the parent of this volume
'phash' => '',
// Folder hash value on elFinder to trash bin of this volume, it require 'copyJoin' to true
'trashHash' => '',
// 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 URL via the connector. If you want to hide the file URL, do not set this value. (replacement for old "fileURL" option)
'URL' => '',
// enable onetime URL to a file - (true, false, 'auto' (true if a temporary directory is available) or callable (A function that return onetime URL))
'onetimeUrl' => 'auto',
// directory link url to own manager url with folder hash (`true`, `false`, `'hide'`(No show) or default `'auto'`: URL is empty then `true` else `false`)
'dirUrlOwn' => 'auto',
// directory separator. required by client to show paths correctly
'separator' => DIRECTORY_SEPARATOR,
// Use '/' as directory separator when the path hash encode/decode on the Windows server too
'winHashFix' => false,
// Server character encoding (default is '': UTF-8)
'encoding' => '',
// for convert character encoding (default is '': Not change locale)
'locale' => '',
// URL of volume icon image
'icon' => '',
// CSS Class of volume root in tree
'rootCssClass' => '',
// Items to disable session caching
'noSessionCache' => array(),
// enable i18n folder name that convert name to elFinderInstance.messages['folder_'+name]
'i18nFolderName' => false,
// Search timeout (sec)
'searchTimeout' => 30,
// Search exclusion directory regex pattern (require demiliter e.g. '#/path/to/exclude_directory#i')
'searchExDirReg' => '',
// 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' => '',
// Static extension/MIME of general server side scripts to security issues
'staticMineMap' => array(
'php:*' => 'text/x-php',
'pht:*' => 'text/x-php',
'php3:*' => 'text/x-php',
'php4:*' => 'text/x-php',
'php5:*' => 'text/x-php',
'php7:*' => 'text/x-php',
'php8:*' => 'text/x-php',
'php9:*' => 'text/x-php',
'phtml:*' => 'text/x-php',
'phar:*' => 'text/x-php',
'cgi:*' => 'text/x-httpd-cgi',
'pl:*' => 'text/x-perl',
'asp:*' => 'text/x-asap',
'aspx:*' => 'text/x-asap',
'py:*' => 'text/x-python',
'rb:*' => 'text/x-ruby',
'jsp:*' => 'text/x-jsp'
),
// mime type normalize map : Array '[ext]:[detected mime type]' => '[normalized mime]'
'mimeMap' => array(
'md:application/x-genesis-rom' => 'text/x-markdown',
'md:text/plain' => 'text/x-markdown',
'markdown:text/plain' => 'text/x-markdown',
'css:text/x-asm' => 'text/css',
'css:text/plain' => 'text/css',
'csv:text/plain' => 'text/csv',
'java:text/x-c' => 'text/x-java-source',
'json:text/plain' => 'application/json',
'sql:text/plain' => 'text/x-sql',
'rtf:text/rtf' => 'application/rtf',
'rtfd:text/rtfd' => 'application/rtfd',
'ico:image/vnd.microsoft.icon' => 'image/x-icon',
'svg:text/plain' => 'image/svg+xml',
'pxd:application/octet-stream' => 'image/x-pixlr-data',
'dng:image/tiff' => 'image/x-adobe-dng',
'sketch:application/zip' => 'image/x-sketch',
'sketch:application/octet-stream' => 'image/x-sketch',
'xcf:application/octet-stream' => 'image/x-xcf',
'amr:application/octet-stream' => 'audio/amr',
'm4a:video/mp4' => 'audio/mp4',
'oga:application/ogg' => 'audio/ogg',
'ogv:application/ogg' => 'video/ogg',
'zip:application/x-zip' => 'application/zip',
'm3u8:text/plain' => 'application/x-mpegURL',
'mpd:text/plain' => 'application/dash+xml',
'mpd:application/xml' => 'application/dash+xml',
'*:application/x-dosexec' => 'application/x-executable',
'doc:application/vnd.ms-office' => 'application/msword',
'xls:application/vnd.ms-office' => 'application/vnd.ms-excel',
'ppt:application/vnd.ms-office' => 'application/vnd.ms-powerpoint',
'yml:text/plain' => 'text/x-yaml',
'ai:application/pdf' => 'application/postscript',
'cgm:text/plain' => 'image/cgm',
'dxf:text/plain' => 'image/vnd.dxf',
'dds:application/octet-stream' => 'image/vnd-ms.dds',
'hpgl:text/plain' => 'application/vnd.hp-hpgl',
'igs:text/plain' => 'model/iges',
'iges:text/plain' => 'model/iges',
'plt:application/octet-stream' => 'application/plt',
'plt:text/plain' => 'application/plt',
'sat:text/plain' => 'application/sat',
'step:text/plain' => 'application/step',
'stp:text/plain' => 'application/step'
),
// An option to add MimeMap to the `mimeMap` option
// Array '[ext]:[detected mime type]' => '[normalized mime]'
'additionalMimeMap' => array(),
// MIME-Type of filetype detected as unknown
'mimeTypeUnknown' => 'application/octet-stream',
// MIME regex of send HTTP header "Content-Disposition: inline" or allow preview in quicklook
// '.' is allow inline of all of MIME types
// '$^' is not allow inline of all of MIME types
'dispInlineRegex' => '^(?:(?:video|audio)|image/(?!.+\+xml)|application/(?:ogg|x-mpegURL|dash\+xml)|(?:text/plain|application/pdf)$)',
// temporary content URL's base path
'tmpLinkPath' => '',
// temporary content URL's base URL
'tmpLinkUrl' => '',
// 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,
// thumbnail URL require custom data as the GET query
'tmbReqCustomData' => false,
// thumbnails background color (hex #rrggbb or 'transparent')
'tmbBgColor' => 'transparent',
// image rotate fallback background color (hex #rrggbb)
'bgColorFb' => '#ffffff',
// image manipulations library (imagick|gd|convert|auto|none, none - Does not check the image library at all.)
'imgLib' => 'auto',
// Fallback self image to thumbnail (nothing imgLib)
'tmbFbSelf' => true,
// Video to Image converters ['TYPE or MIME' => ['func' => function($file){ /* Converts $file to Image */ return true; }, 'maxlen' => (int)TransferLength]]
'imgConverter' => array(),
// Max length of transfer to image converter
'tmbVideoConvLen' => 10000000,
// Captre point seccond
'tmbVideoConvSec' => 6,
// Life time (hour) for thumbnail garbage collection ("0" means no GC)
'tmbGcMaxlifeHour' => 0,
// Percentage of garbage collection executed for thumbnail creation command ("1" means "1%")
'tmbGcPercentage' => 1,
// Resource path of fallback icon images defailt: php/resouces
'resourcePath' => '',
// Jpeg image saveing quality
'jpgQuality' => 100,
// Save as progressive JPEG on image editing
'jpgProgressive' => true,
// enable to get substitute image with command `dim`
'substituteImg' => true,
// 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 process uploadAllow and uploadDeny options
'uploadOrder' => array('deny', 'allow'),
// maximum upload file size. NOTE - this is size for every uploaded files
'uploadMaxSize' => 0,
// Maximum number of folders that can be created at one time. (0: unlimited)
'uploadMaxMkdirs' => 0,
// maximum number of chunked upload connection. `-1` to disable chunked upload
'uploadMaxConn' => 3,
// maximum get file size. NOTE - Maximum value is 50% of PHP memory_limit
'getMaxSize' => 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, -1 - every folder will be check asynchronously, false - all folders will be marked as having subfolders
'checkSubfolders' => true, // true, false or -1
// allow to copy from this volume to other ones?
'copyFrom' => true,
// allow to copy from other volumes to this one?
'copyTo' => true,
// cmd duplicate suffix format e.g. '_%s_' to without spaces
'duplicateSuffix' => ' %s ',
// unique name numbar format e.g. '(%d)' to (1), (2)...
'uniqueNumFormat' => '%d',
// list of commands disabled on this root
'disabled' => array(),
// enable file owner, group & mode info, `false` to inactivate "chmod" command.
'statOwner' => false,
// allow exec chmod of read-only files
'allowChmodReadOnly' => false,
// regexp or function name to validate new file name
'acceptedName' => '/^[^\.].*/', // Notice: overwritten it in some volume drivers contractor
// regexp or function name to validate new directory name
'acceptedDirname' => '', // used `acceptedName` if empty value
// function/class method to control files permissions
'accessControl' => null,
// some data required by access control
'accessControlData' => null,
// root stat that return without asking the system when mounted and not the current volume. Query to the system with false. array|false
'rapidRootStat' => array(
'read' => true,
'write' => true,
'locked' => false,
'hidden' => false,
'size' => 0, // Unknown
'ts' => 0, // Unknown
'dirs' => -1, // Check on demand for subdirectories
'mime' => 'directory'
),
// default permissions.
'defaults' => array(
'read' => true,
'write' => true,
'locked' => false,
'hidden' => false
),
// files attributes
'attributes' => array(),
// max allowed archive files size (0 - no limit)
'maxArcFilesSize' => '2G',
// 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(),
// Use Archive function for remote volume
'useRemoteArchive' => false,
// plugin settings
'plugin' => array(),
// Is support parent directory time stamp update on add|remove|rename item
// Default `null` is auto detection that is LocalFileSystem, FTP or Dropbox are `true`
'syncChkAsTs' => null,
// Long pooling sync checker function for syncChkAsTs is true
// Calls with args (TARGET DIRCTORY PATH, STAND-BY(sec), OLD TIMESTAMP, VOLUME DRIVER INSTANCE, ELFINDER INSTANCE)
// This function must return the following values. Changed: New Timestamp or Same: Old Timestamp or Error: false
// Default `null` is try use elFinderVolumeLocalFileSystem::localFileSystemInotify() on LocalFileSystem driver
// another driver use elFinder stat() checker
'syncCheckFunc' => null,
// Long polling sync stand-by time (sec)
'plStandby' => 30,
// Sleep time (sec) for elFinder stat() checker (syncChkAsTs is true)
'tsPlSleep' => 10,
// Sleep time (sec) for elFinder ls() checker (syncChkAsTs is false)
'lsPlSleep' => 30,
// Client side sync interval minimum (ms)
// Default `null` is auto set to ('tsPlSleep' or 'lsPlSleep') * 1000
// `0` to disable auto sync
'syncMinMs' => null,
// required to fix bug on macos
// However, we recommend to use the Normalizer plugin instead this option
'utf8fix' => false,
// й ё Й Ё Ø Å
'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"),
'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5"),
// cache control HTTP headers for commands `file` and `get`
'cacheHeaders' => array(
'Cache-Control: max-age=3600',
'Expires:',
'Pragma:'
),
// Header to use to accelerate sending local files to clients (e.g. 'X-Sendfile', 'X-Accel-Redirect')
'xsendfile' => '',
// Root path to xsendfile target. Probably, this is required for 'X-Accel-Redirect' on Nginx.
'xsendfilePath' => ''
);
/**
* 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;
/**
* Run time setting of overwrite items on upload
*
* @var string
*/
protected $uploadOverwrite = true;
/**
* Maximum allowed get file size.
* Set as number or string with unit - "10M", "500K", "1G"
*
* @var int|string
**/
protected $getMaxSize = -1;
/**
* Mimetype detect method
*
* @var string
**/
protected $mimeDetect = 'auto';
/**
* Flag - mimetypes from externail file was loaded
*
* @var bool
**/
private static $mimetypesLoaded = false;
/**
* Finfo resource for mimeDetect == 'finfo'
*
* @var resource
**/
protected $finfo = null;
/**
* List of disabled client's commands
*
* @var array
**/
protected $disabled = array();
/**
* overwrite extensions/mimetypes to mime.types
*
* @var array
**/
protected static $mimetypes = array(
// applications
'exe' => 'application/x-executable',
'jar' => 'application/x-jar',
// archives
'gz' => 'application/x-gzip',
'tgz' => 'application/x-gzip',
'tbz' => 'application/x-bzip2',
'rar' => 'application/x-rar',
// texts
'php' => 'text/x-php',
'js' => 'text/javascript',
'rtfd' => 'application/rtfd',
'py' => 'text/x-python',
'rb' => 'text/x-ruby',
'sh' => 'text/x-shellscript',
'pl' => 'text/x-perl',
'xml' => 'text/xml',
'c' => 'text/x-csrc',
'h' => 'text/x-chdr',
'cpp' => 'text/x-c++src',
'hh' => 'text/x-c++hdr',
'md' => 'text/x-markdown',
'markdown' => 'text/x-markdown',
'yml' => 'text/x-yaml',
// images
'bmp' => 'image/x-ms-bmp',
'tga' => 'image/x-targa',
'xbm' => 'image/xbm',
'pxm' => 'image/pxm',
//audio
'wav' => 'audio/wav',
// video
'dv' => 'video/x-dv',
'wm' => 'video/x-ms-wmv',
'ogm' => 'video/ogg',
'm2ts' => 'video/MP2T',
'mts' => 'video/MP2T',
'ts' => 'video/MP2T',
'm3u8' => 'application/x-mpegURL',
'mpd' => 'application/dash+xml'
);
/**
* Directory separator - required by client
*
* @var string
**/
protected $separator = DIRECTORY_SEPARATOR;
/**
* Directory separator for decode/encode hash
*
* @var string
**/
protected $separatorForHash = '';
/**
* System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...)
*
* @var string
**/
protected $systemRoot = DIRECTORY_SEPARATOR;
/**
* Mimetypes allowed to display
*
* @var array
**/
protected $onlyMimes = array();
/**
* Store files moved or overwrited files info
*
* @var array
**/
protected $removed = array();
/**
* Store files added files info
*
* @var array
**/
protected $added = array();
/**
* Cache storage
*
* @var array
**/
protected $cache = array();
/**
* Cache by folders
*
* @var array
**/
protected $dirsCache = array();
/**
* You should use `$this->sessionCache['subdirs']` instead
*
* @var array
* @deprecated
*/
protected $subdirsCache = array();
/**
* This volume session cache
*
* @var array
*/
protected $sessionCache;
/**
* Session caching item list
*
* @var array
*/
protected $sessionCaching = array('rootstat' => true, 'subdirs' => true);
/**
* elFinder session wrapper object
*
* @var elFinderSessionInterface
*/
protected $session;
/**
* Search start time
*
* @var int
*/
protected $searchStart;
/**
* Current query word on doSearch
*
* @var array
**/
protected $doSearchCurrentQuery = array();
/**
* Is root modified (for clear root stat cache)
*
* @var bool
*/
protected $rootModified = false;
/**
* Is disable of command `url`
*
* @var string
*/
protected $disabledGetUrl = false;
/**
* Accepted filename validator
*
* @var string | callable
*/
protected $nameValidator;
/**
* Accepted dirname validator
*
* @var string | callable
*/
protected $dirnameValidator;
/**
* This request require online state
*
* @var boolean
*/
protected $needOnline;
/*********************************************************************/
/* INITIALIZATION */
/*********************************************************************/
/**
* Sets the need online.
*
* @param boolean $state The state
*/
public function setNeedOnline($state = null)
{
if ($state !== null) {
$this->needOnline = (bool)$state;
return;
}
$need = false;
$arg = $this->ARGS;
$id = $this->id;
$target = !empty($arg['target'])? $arg['target'] : (!empty($arg['dst'])? $arg['dst'] : '');
$targets = !empty($arg['targets'])? $arg['targets'] : array();
if (!is_array($targets)) {
$targets = array($targets);
}
if ($target && strpos($target, $id) === 0) {
$need = true;
} else if ($targets) {
foreach($targets as $t) {
if ($t && strpos($t, $id) === 0) {
$need = true;
break;
}
}
}
$this->needOnline = $need;
}
/**
* 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
* @throws elFinderAbortException
* @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 resouce path
if (!is_dir($this->options['resourcePath'])) {
$this->options['resourcePath'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'resources';
}
// set image manipulation library
$type = preg_match('/^(imagick|gd|convert|auto|none)$/i', $this->options['imgLib'])
? strtolower($this->options['imgLib'])
: 'auto';
if ($type === 'none') {
$this->imgLib = '';
} else {
if (($type === 'imagick' || $type === 'auto') && extension_loaded('imagick')) {
$this->imgLib = 'imagick';
} else if (($type === 'gd' || $type === 'auto') && function_exists('gd_info')) {
$this->imgLib = 'gd';
} else {
$convertCache = 'imgLibConvert';
if (($convertCmd = $this->session->get($convertCache, false)) !== false) {
$this->imgLib = $convertCmd;
} else {
$this->imgLib = ($this->procExec(ELFINDER_CONVERT_PATH . ' -version') === 0) ? 'convert' : '';
$this->session->set($convertCache, $this->imgLib);
}
}
if ($type !== 'auto' && $this->imgLib === '') {
// fallback
$this->imgLib = extension_loaded('imagick') ? 'imagick' : (function_exists('gd_info') ? 'gd' : '');
}
}
// check video to img converter
if (!empty($this->options['imgConverter']) && is_array($this->options['imgConverter'])) {
foreach ($this->options['imgConverter'] as $_type => $_converter) {
if (isset($_converter['func'])) {
$this->imgConverter[strtolower($_type)] = $_converter;
}
}
}
if (!isset($this->imgConverter['video'])) {
$videoLibCache = 'videoLib';
if (($videoLibCmd = $this->session->get($videoLibCache, false)) === false) {
$videoLibCmd = ($this->procExec(ELFINDER_FFMPEG_PATH . ' -version') === 0) ? 'ffmpeg' : '';
$this->session->set($videoLibCache, $videoLibCmd);
}
if ($videoLibCmd) {
$this->imgConverter['video'] = array(
'func' => array($this, $videoLibCmd . 'ToImg'),
'maxlen' => $this->options['tmbVideoConvLen']
);
}
}
// check onetimeUrl
if (strtolower($this->options['onetimeUrl']) === 'auto') {
$this->options['onetimeUrl'] = elFinder::getStaticVar('commonTempPath')? true : false;
}
// check archivers
if (empty($this->archivers['create'])) {
$this->disabled[] = 'archive';
}
if (empty($this->archivers['extract'])) {
$this->disabled[] = 'extract';
}
$_arc = $this->getArchivers();
if (empty($_arc['create'])) {
$this->disabled[] = 'zipdl';
}
if ($this->options['maxArcFilesSize']) {
$this->options['maxArcFilesSize'] = elFinder::getIniBytes('', $this->options['maxArcFilesSize']);
}
self::$maxArcFilesSize = $this->options['maxArcFilesSize'];
// check 'statOwner' for command `chmod`
if (empty($this->options['statOwner'])) {
$this->disabled[] = 'chmod';
}
// check 'mimeMap'
if (!is_array($this->options['mimeMap'])) {
$this->options['mimeMap'] = array();
}
if (is_array($this->options['staticMineMap']) && $this->options['staticMineMap']) {
$this->options['mimeMap'] = array_merge($this->options['mimeMap'], $this->options['staticMineMap']);
}
if (is_array($this->options['additionalMimeMap']) && $this->options['additionalMimeMap']) {
$this->options['mimeMap'] = array_merge($this->options['mimeMap'], $this->options['additionalMimeMap']);
}
// check 'url' in disabled commands
if (in_array('url', $this->disabled)) {
$this->disabledGetUrl = true;
}
// set run time setting uploadOverwrite
$this->uploadOverwrite = $this->options['uploadOverwrite'];
}
/**
* @deprecated
*/
protected function sessionRestart()
{
$this->sessionCache = $this->session->start()->get($this->id, array());
return true;
}
/*********************************************************************/
/* 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;
}