Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like elFinderVolumeDriver often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use elFinderVolumeDriver, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | abstract class elFinderVolumeDriver { |
||
|
|||
15 | |||
16 | /** |
||
17 | * Request args |
||
18 | * $_POST or $_GET values |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $ARGS = array(); |
||
23 | |||
24 | /** |
||
25 | * Driver id |
||
26 | * Must be started from letter and contains [a-z0-9] |
||
27 | * Used as part of volume id |
||
28 | * |
||
29 | * @var string |
||
30 | **/ |
||
31 | protected $driverId = 'a'; |
||
32 | |||
33 | /** |
||
34 | * Volume id - used as prefix for files hashes |
||
35 | * |
||
36 | * @var string |
||
37 | **/ |
||
38 | protected $id = ''; |
||
39 | |||
40 | /** |
||
41 | * Flag - volume "mounted" and available |
||
42 | * |
||
43 | * @var bool |
||
44 | **/ |
||
45 | protected $mounted = false; |
||
46 | |||
47 | /** |
||
48 | * Root directory path |
||
49 | * |
||
50 | * @var string |
||
51 | **/ |
||
52 | protected $root = ''; |
||
53 | |||
54 | /** |
||
55 | * Root basename | alias |
||
56 | * |
||
57 | * @var string |
||
58 | **/ |
||
59 | protected $rootName = ''; |
||
60 | |||
61 | /** |
||
62 | * Default directory to open |
||
63 | * |
||
64 | * @var string |
||
65 | **/ |
||
66 | protected $startPath = ''; |
||
67 | |||
68 | /** |
||
69 | * Base URL |
||
70 | * |
||
71 | * @var string |
||
72 | **/ |
||
73 | protected $URL = ''; |
||
74 | |||
75 | /** |
||
76 | * Thumbnails dir path |
||
77 | * |
||
78 | * @var string |
||
79 | **/ |
||
80 | protected $tmbPath = ''; |
||
81 | |||
82 | /** |
||
83 | * Is thumbnails dir writable |
||
84 | * |
||
85 | * @var bool |
||
86 | **/ |
||
87 | protected $tmbPathWritable = false; |
||
88 | |||
89 | /** |
||
90 | * Thumbnails base URL |
||
91 | * |
||
92 | * @var string |
||
93 | **/ |
||
94 | protected $tmbURL = ''; |
||
95 | |||
96 | /** |
||
97 | * Thumbnails size in px |
||
98 | * |
||
99 | * @var int |
||
100 | **/ |
||
101 | protected $tmbSize = 48; |
||
102 | |||
103 | /** |
||
104 | * Image manipulation lib name |
||
105 | * auto|imagick|mogtify|gd |
||
106 | * |
||
107 | * @var string |
||
108 | **/ |
||
109 | protected $imgLib = 'auto'; |
||
110 | |||
111 | /** |
||
112 | * Library to crypt files name |
||
113 | * |
||
114 | * @var string |
||
115 | **/ |
||
116 | protected $cryptLib = ''; |
||
117 | |||
118 | /** |
||
119 | * Archivers config |
||
120 | * |
||
121 | * @var array |
||
122 | **/ |
||
123 | protected $archivers = array( |
||
124 | 'create' => array(), |
||
125 | 'extract' => array() |
||
126 | ); |
||
127 | |||
128 | /** |
||
129 | * Server character encoding |
||
130 | * |
||
131 | * @var string or null |
||
132 | **/ |
||
133 | protected $encoding = null; |
||
134 | |||
135 | /** |
||
136 | * How many subdirs levels return for tree |
||
137 | * |
||
138 | * @var int |
||
139 | **/ |
||
140 | protected $treeDeep = 1; |
||
141 | |||
142 | /** |
||
143 | * Errors from last failed action |
||
144 | * |
||
145 | * @var array |
||
146 | **/ |
||
147 | protected $error = array(); |
||
148 | |||
149 | /** |
||
150 | * Today 24:00 timestamp |
||
151 | * |
||
152 | * @var int |
||
153 | **/ |
||
154 | protected $today = 0; |
||
155 | |||
156 | /** |
||
157 | * Yesterday 24:00 timestamp |
||
158 | * |
||
159 | * @var int |
||
160 | **/ |
||
161 | protected $yesterday = 0; |
||
162 | |||
163 | /** |
||
164 | * Force make dirctory on extract |
||
165 | * |
||
166 | * @var int |
||
167 | **/ |
||
168 | protected $extractToNewdir = 'auto'; |
||
169 | |||
170 | /** |
||
171 | * Object configuration |
||
172 | * |
||
173 | * @var array |
||
174 | **/ |
||
175 | protected $options = array( |
||
176 | 'id' => '', |
||
177 | // root directory path |
||
178 | 'path' => '', |
||
179 | // open this path on initial request instead of root path |
||
180 | 'startPath' => '', |
||
181 | // how many subdirs levels return per request |
||
182 | 'treeDeep' => 1, |
||
183 | // root url, not set to disable sending URL to client (replacement for old "fileURL" option) |
||
184 | 'URL' => '', |
||
185 | // directory separator. required by client to show paths correctly |
||
186 | 'separator' => DIRECTORY_SEPARATOR, |
||
187 | // Server character encoding (default is '': UTF-8) |
||
188 | 'encoding' => '', |
||
189 | // for convert character encoding (default is '': Not change locale) |
||
190 | 'locale' => '', |
||
191 | // URL of volume icon (16x16 pixel image file) |
||
192 | 'icon' => '', |
||
193 | // CSS Class of volume root in tree |
||
194 | 'rootCssClass' => '', |
||
195 | // Search timeout (sec) |
||
196 | 'searchTimeout' => 30, |
||
197 | // library to crypt/uncrypt files names (not implemented) |
||
198 | 'cryptLib' => '', |
||
199 | // how to detect files mimetypes. (auto/internal/finfo/mime_content_type) |
||
200 | 'mimeDetect' => 'auto', |
||
201 | // mime.types file path (for mimeDetect==internal) |
||
202 | 'mimefile' => '', |
||
203 | // mime type normalize map : Array '[ext]:[detected mime type]' => '[normalized mime]' |
||
204 | 'mimeMap' => array( |
||
205 | 'md:application/x-genesis-rom' => 'text/x-markdown', |
||
206 | 'md:text/plain' => 'text/x-markdown', |
||
207 | 'markdown:text/plain' => 'text/x-markdown', |
||
208 | 'css:text/x-asm' => 'text/css' |
||
209 | ), |
||
210 | // MIME regex of send HTTP header "Content-Disposition: inline" |
||
211 | // '.' is allow inline of all of MIME types |
||
212 | // '$^' is not allow inline of all of MIME types |
||
213 | 'dispInlineRegex' => '^(?:(?:image|text)|application/x-shockwave-flash$)', |
||
214 | // directory for thumbnails |
||
215 | 'tmbPath' => '.tmb', |
||
216 | // mode to create thumbnails dir |
||
217 | 'tmbPathMode' => 0777, |
||
218 | // thumbnails dir URL. Set it if store thumbnails outside root directory |
||
219 | 'tmbURL' => '', |
||
220 | // thumbnails size (px) |
||
221 | 'tmbSize' => 48, |
||
222 | // thumbnails crop (true - crop, false - scale image to fit thumbnail size) |
||
223 | 'tmbCrop' => true, |
||
224 | // thumbnails background color (hex #rrggbb or 'transparent') |
||
225 | 'tmbBgColor' => '#ffffff', |
||
226 | // image manipulations library |
||
227 | 'imgLib' => 'auto', |
||
228 | // Jpeg image saveing quality |
||
229 | 'jpgQuality' => 100, |
||
230 | // on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
231 | 'copyOverwrite' => true, |
||
232 | // if true - join new and old directories content on paste |
||
233 | 'copyJoin' => true, |
||
234 | // on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
235 | 'uploadOverwrite' => true, |
||
236 | // mimetypes allowed to upload |
||
237 | 'uploadAllow' => array(), |
||
238 | // mimetypes not allowed to upload |
||
239 | 'uploadDeny' => array(), |
||
240 | // order to proccess uploadAllow and uploadDeny options |
||
241 | 'uploadOrder' => array('deny', 'allow'), |
||
242 | // maximum upload file size. NOTE - this is size for every uploaded files |
||
243 | 'uploadMaxSize' => 0, |
||
244 | // files dates format |
||
245 | 'dateFormat' => 'j M Y H:i', |
||
246 | // files time format |
||
247 | 'timeFormat' => 'H:i', |
||
248 | // if true - every folder will be check for children folders, otherwise all folders will be marked as having subfolders |
||
249 | 'checkSubfolders' => true, |
||
250 | // allow to copy from this volume to other ones? |
||
251 | 'copyFrom' => true, |
||
252 | // allow to copy from other volumes to this one? |
||
253 | 'copyTo' => true, |
||
254 | // list of commands disabled on this root |
||
255 | 'disabled' => array(), |
||
256 | // enable file owner, group & mode info, `false` to inactivate "chmod" command. |
||
257 | 'statOwner' => false, |
||
258 | // allow exec chmod of read-only files |
||
259 | 'allowChmodReadOnly' => false, |
||
260 | // regexp or function name to validate new file name |
||
261 | 'acceptedName' => '/^[^\.].*/', //<-- DONT touch this! Use constructor options to overwrite it! |
||
262 | // function/class method to control files permissions |
||
263 | 'accessControl' => null, |
||
264 | // some data required by access control |
||
265 | 'accessControlData' => null, |
||
266 | // default permissions. |
||
267 | 'defaults' => array( |
||
268 | 'read' => true, |
||
269 | 'write' => true, |
||
270 | 'locked' => false, |
||
271 | 'hidden' => false |
||
272 | ), |
||
273 | // files attributes |
||
274 | 'attributes' => array(), |
||
275 | // Allowed archive's mimetypes to create. Leave empty for all available types. |
||
276 | 'archiveMimes' => array(), |
||
277 | // Manual config for archivers. See example below. Leave empty for auto detect |
||
278 | 'archivers' => array(), |
||
279 | // plugin settings |
||
280 | 'plugin' => array(), |
||
281 | // Is support parent directory time stamp update on add|remove|rename item |
||
282 | // Default `null` is auto detection that is LocalFileSystem, FTP or Dropbox are `true` |
||
283 | 'syncChkAsTs' => null, |
||
284 | // Long pooling sync checker function for syncChkAsTs is true |
||
285 | // Calls with args (TARGET DIRCTORY PATH, STAND-BY(sec), OLD TIMESTAMP, VOLUME DRIVER INSTANCE, ELFINDER INSTANCE) |
||
286 | // This function must return the following values. Changed: New Timestamp or Same: Old Timestamp or Error: false |
||
287 | // Default `null` is try use elFinderVolumeLocalFileSystem::localFileSystemInotify() on LocalFileSystem driver |
||
288 | // another driver use elFinder stat() checker |
||
289 | 'syncCheckFunc'=> null, |
||
290 | // Long polling sync stand-by time (sec) |
||
291 | 'plStandby' => 30, |
||
292 | // Sleep time (sec) for elFinder stat() checker (syncChkAsTs is true) |
||
293 | 'tsPlSleep' => 10, |
||
294 | // Sleep time (sec) for elFinder ls() checker (syncChkAsTs is false) |
||
295 | 'lsPlSleep' => 30, |
||
296 | // Client side sync interval minimum (ms) |
||
297 | // Default `null` is auto set to ('tsPlSleep' or 'lsPlSleep') * 1000 |
||
298 | // `0` to disable auto sync |
||
299 | 'syncMinMs' => null, |
||
300 | // required to fix bug on macos |
||
301 | 'utf8fix' => false, |
||
302 | // й ё Й Ё Ø Å |
||
303 | 'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"), |
||
304 | 'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5") |
||
305 | ); |
||
306 | |||
307 | /** |
||
308 | * Defaults permissions |
||
309 | * |
||
310 | * @var array |
||
311 | **/ |
||
312 | protected $defaults = array( |
||
313 | 'read' => true, |
||
314 | 'write' => true, |
||
315 | 'locked' => false, |
||
316 | 'hidden' => false |
||
317 | ); |
||
318 | |||
319 | /** |
||
320 | * Access control function/class |
||
321 | * |
||
322 | * @var mixed |
||
323 | **/ |
||
324 | protected $attributes = array(); |
||
325 | |||
326 | /** |
||
327 | * Access control function/class |
||
328 | * |
||
329 | * @var mixed |
||
330 | **/ |
||
331 | protected $access = null; |
||
332 | |||
333 | /** |
||
334 | * Mime types allowed to upload |
||
335 | * |
||
336 | * @var array |
||
337 | **/ |
||
338 | protected $uploadAllow = array(); |
||
339 | |||
340 | /** |
||
341 | * Mime types denied to upload |
||
342 | * |
||
343 | * @var array |
||
344 | **/ |
||
345 | protected $uploadDeny = array(); |
||
346 | |||
347 | /** |
||
348 | * Order to validate uploadAllow and uploadDeny |
||
349 | * |
||
350 | * @var array |
||
351 | **/ |
||
352 | protected $uploadOrder = array(); |
||
353 | |||
354 | /** |
||
355 | * Maximum allowed upload file size. |
||
356 | * Set as number or string with unit - "10M", "500K", "1G" |
||
357 | * |
||
358 | * @var int|string |
||
359 | **/ |
||
360 | protected $uploadMaxSize = 0; |
||
361 | |||
362 | /** |
||
363 | * Mimetype detect method |
||
364 | * |
||
365 | * @var string |
||
366 | **/ |
||
367 | protected $mimeDetect = 'auto'; |
||
368 | |||
369 | /** |
||
370 | * Flag - mimetypes from externail file was loaded |
||
371 | * |
||
372 | * @var bool |
||
373 | **/ |
||
374 | private static $mimetypesLoaded = false; |
||
375 | |||
376 | /** |
||
377 | * Finfo object for mimeDetect == 'finfo' |
||
378 | * |
||
379 | * @var object |
||
380 | **/ |
||
381 | protected $finfo = null; |
||
382 | |||
383 | /** |
||
384 | * List of disabled client's commands |
||
385 | * |
||
386 | * @var array |
||
387 | **/ |
||
388 | protected $disabled = array(); |
||
389 | |||
390 | /** |
||
391 | * default extensions/mimetypes for mimeDetect == 'internal' |
||
392 | * |
||
393 | * @var array |
||
394 | **/ |
||
395 | protected static $mimetypes = array( |
||
396 | // applications |
||
397 | 'ai' => 'application/postscript', |
||
398 | 'eps' => 'application/postscript', |
||
399 | 'exe' => 'application/x-executable', |
||
400 | 'doc' => 'application/msword', |
||
401 | 'dot' => 'application/msword', |
||
402 | 'xls' => 'application/vnd.ms-excel', |
||
403 | 'xlt' => 'application/vnd.ms-excel', |
||
404 | 'xla' => 'application/vnd.ms-excel', |
||
405 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
406 | 'pps' => 'application/vnd.ms-powerpoint', |
||
407 | 'pdf' => 'application/pdf', |
||
408 | 'xml' => 'application/xml', |
||
409 | 'swf' => 'application/x-shockwave-flash', |
||
410 | 'torrent' => 'application/x-bittorrent', |
||
411 | 'jar' => 'application/x-jar', |
||
412 | // open office (finfo detect as application/zip) |
||
413 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
414 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
415 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
416 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
417 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
418 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
419 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
420 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
421 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
422 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
423 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
424 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
425 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
426 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
427 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
428 | // MS office 2007 (finfo detect as application/zip) |
||
429 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
430 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
431 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
432 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
433 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
434 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
435 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
436 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
437 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
438 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
439 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
440 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
441 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
442 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
443 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
444 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
445 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
446 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
447 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
448 | // archives |
||
449 | 'gz' => 'application/x-gzip', |
||
450 | 'tgz' => 'application/x-gzip', |
||
451 | 'bz' => 'application/x-bzip2', |
||
452 | 'bz2' => 'application/x-bzip2', |
||
453 | 'tbz' => 'application/x-bzip2', |
||
454 | 'xz' => 'application/x-xz', |
||
455 | 'zip' => 'application/zip', |
||
456 | 'rar' => 'application/x-rar', |
||
457 | 'tar' => 'application/x-tar', |
||
458 | '7z' => 'application/x-7z-compressed', |
||
459 | // texts |
||
460 | 'txt' => 'text/plain', |
||
461 | 'php' => 'text/x-php', |
||
462 | 'html' => 'text/html', |
||
463 | 'htm' => 'text/html', |
||
464 | 'js' => 'text/javascript', |
||
465 | 'css' => 'text/css', |
||
466 | 'rtf' => 'text/rtf', |
||
467 | 'rtfd' => 'text/rtfd', |
||
468 | 'py' => 'text/x-python', |
||
469 | 'java' => 'text/x-java-source', |
||
470 | 'rb' => 'text/x-ruby', |
||
471 | 'sh' => 'text/x-shellscript', |
||
472 | 'pl' => 'text/x-perl', |
||
473 | 'xml' => 'text/xml', |
||
474 | 'sql' => 'text/x-sql', |
||
475 | 'c' => 'text/x-csrc', |
||
476 | 'h' => 'text/x-chdr', |
||
477 | 'cpp' => 'text/x-c++src', |
||
478 | 'hh' => 'text/x-c++hdr', |
||
479 | 'log' => 'text/plain', |
||
480 | 'csv' => 'text/x-comma-separated-values', |
||
481 | 'md' => 'text/x-markdown', |
||
482 | 'markdown' => 'text/x-markdown', |
||
483 | // images |
||
484 | 'bmp' => 'image/x-ms-bmp', |
||
485 | 'jpg' => 'image/jpeg', |
||
486 | 'jpeg' => 'image/jpeg', |
||
487 | 'gif' => 'image/gif', |
||
488 | 'png' => 'image/png', |
||
489 | 'tif' => 'image/tiff', |
||
490 | 'tiff' => 'image/tiff', |
||
491 | 'tga' => 'image/x-targa', |
||
492 | 'psd' => 'image/vnd.adobe.photoshop', |
||
493 | 'ai' => 'image/vnd.adobe.photoshop', |
||
494 | 'xbm' => 'image/xbm', |
||
495 | 'pxm' => 'image/pxm', |
||
496 | //audio |
||
497 | 'mp3' => 'audio/mpeg', |
||
498 | 'mid' => 'audio/midi', |
||
499 | 'ogg' => 'audio/ogg', |
||
500 | 'oga' => 'audio/ogg', |
||
501 | 'm4a' => 'audio/x-m4a', |
||
502 | 'wav' => 'audio/wav', |
||
503 | 'wma' => 'audio/x-ms-wma', |
||
504 | // video |
||
505 | 'avi' => 'video/x-msvideo', |
||
506 | 'dv' => 'video/x-dv', |
||
507 | 'mp4' => 'video/mp4', |
||
508 | 'mpeg' => 'video/mpeg', |
||
509 | 'mpg' => 'video/mpeg', |
||
510 | 'mov' => 'video/quicktime', |
||
511 | 'wm' => 'video/x-ms-wmv', |
||
512 | 'flv' => 'video/x-flv', |
||
513 | 'mkv' => 'video/x-matroska', |
||
514 | 'webm' => 'video/webm', |
||
515 | 'ogv' => 'video/ogg', |
||
516 | 'ogm' => 'video/ogg' |
||
517 | ); |
||
518 | |||
519 | /** |
||
520 | * Directory separator - required by client |
||
521 | * |
||
522 | * @var string |
||
523 | **/ |
||
524 | protected $separator = DIRECTORY_SEPARATOR; |
||
525 | |||
526 | /** |
||
527 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...) |
||
528 | * |
||
529 | * @var string |
||
530 | **/ |
||
531 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
532 | |||
533 | /** |
||
534 | * Mimetypes allowed to display |
||
535 | * |
||
536 | * @var array |
||
537 | **/ |
||
538 | protected $onlyMimes = array(); |
||
539 | |||
540 | /** |
||
541 | * Store files moved or overwrited files info |
||
542 | * |
||
543 | * @var array |
||
544 | **/ |
||
545 | protected $removed = array(); |
||
546 | |||
547 | /** |
||
548 | * Cache storage |
||
549 | * |
||
550 | * @var array |
||
551 | **/ |
||
552 | protected $cache = array(); |
||
553 | |||
554 | /** |
||
555 | * Cache by folders |
||
556 | * |
||
557 | * @var array |
||
558 | **/ |
||
559 | protected $dirsCache = array(); |
||
560 | |||
561 | /** |
||
562 | * Cache for subdirsCE() |
||
563 | * |
||
564 | * @var array |
||
565 | */ |
||
566 | protected $subdirsCache = array(); |
||
567 | |||
568 | /** |
||
569 | * Reference of $_SESSION[elFinder::$sessionCacheKey][$this->id] |
||
570 | * |
||
571 | * @var array |
||
572 | */ |
||
573 | protected $sessionCache; |
||
574 | |||
575 | |||
576 | /** |
||
577 | * Search start time |
||
578 | * |
||
579 | * @var int |
||
580 | */ |
||
581 | protected $searchStart; |
||
582 | |||
583 | /*********************************************************************/ |
||
584 | /* INITIALIZATION */ |
||
585 | /*********************************************************************/ |
||
586 | |||
587 | /** |
||
588 | * Prepare driver before mount volume. |
||
589 | * Return true if volume is ready. |
||
590 | * |
||
591 | * @return bool |
||
592 | * @author Dmitry (dio) Levashov |
||
593 | **/ |
||
594 | protected function init() { |
||
597 | |||
598 | /** |
||
599 | * Configure after successfull mount. |
||
600 | * By default set thumbnails path and image manipulation library. |
||
601 | * |
||
602 | * @return void |
||
603 | * @author Dmitry (dio) Levashov |
||
604 | **/ |
||
605 | protected function configure() { |
||
646 | |||
647 | protected function sessionRestart() { |
||
655 | /*********************************************************************/ |
||
656 | /* PUBLIC API */ |
||
657 | /*********************************************************************/ |
||
658 | |||
659 | /** |
||
660 | * Return driver id. Used as a part of volume id. |
||
661 | * |
||
662 | * @return string |
||
663 | * @author Dmitry (dio) Levashov |
||
664 | **/ |
||
665 | public function driverId() { |
||
668 | |||
669 | /** |
||
670 | * Return volume id |
||
671 | * |
||
672 | * @return string |
||
673 | * @author Dmitry (dio) Levashov |
||
674 | **/ |
||
675 | public function id() { |
||
678 | |||
679 | /** |
||
680 | * Return debug info for client |
||
681 | * |
||
682 | * @return array |
||
683 | * @author Dmitry (dio) Levashov |
||
684 | **/ |
||
685 | public function debug() { |
||
693 | |||
694 | /** |
||
695 | * chmod a file or folder |
||
696 | * |
||
697 | * @param string $hash file or folder hash to chmod |
||
698 | * @param string $mode octal string representing new permissions |
||
699 | * @return array|false |
||
700 | * @author David Bartle |
||
701 | **/ |
||
702 | public function chmod($hash, $mode) { |
||
739 | |||
740 | /** |
||
741 | * stat a file or folder for elFinder cmd exec |
||
742 | * |
||
743 | * @param string $hash file or folder hash to chmod |
||
744 | * @return array |
||
745 | * @author Naoki Sawada |
||
746 | **/ |
||
747 | public function fstat($hash) { |
||
751 | |||
752 | |||
753 | public function clearstatcache() { |
||
757 | |||
758 | /** |
||
759 | * "Mount" volume. |
||
760 | * Return true if volume available for read or write, |
||
761 | * false - otherwise |
||
762 | * |
||
763 | * @return bool |
||
764 | * @author Dmitry (dio) Levashov |
||
765 | * @author Alexey Sukhotin |
||
766 | **/ |
||
767 | public function mount(array $opts) { |
||
1035 | |||
1036 | /** |
||
1037 | * Some "unmount" stuffs - may be required by virtual fs |
||
1038 | * |
||
1039 | * @return void |
||
1040 | * @author Dmitry (dio) Levashov |
||
1041 | **/ |
||
1042 | public function umount() { |
||
1044 | |||
1045 | /** |
||
1046 | * Return error message from last failed action |
||
1047 | * |
||
1048 | * @return array |
||
1049 | * @author Dmitry (dio) Levashov |
||
1050 | **/ |
||
1051 | public function error() { |
||
1054 | |||
1055 | /** |
||
1056 | * Return is uploadable that given file name |
||
1057 | * |
||
1058 | * @param string $name file name |
||
1059 | * @param bool $allowUnknown |
||
1060 | * @return bool |
||
1061 | * @author Naoki Sawada |
||
1062 | **/ |
||
1063 | public function isUploadableByName($name, $allowUnknown = true) { |
||
1067 | |||
1068 | /** |
||
1069 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
1070 | * |
||
1071 | * @return array |
||
1072 | * @author Naoki Sawada |
||
1073 | */ |
||
1074 | public function getMimeTable() { |
||
1077 | |||
1078 | /** |
||
1079 | * Set mimetypes allowed to display to client |
||
1080 | * |
||
1081 | * @param array $mimes |
||
1082 | * @return void |
||
1083 | * @author Dmitry (dio) Levashov |
||
1084 | **/ |
||
1085 | public function setMimesFilter($mimes) { |
||
1090 | |||
1091 | /** |
||
1092 | * Return root folder hash |
||
1093 | * |
||
1094 | * @return string |
||
1095 | * @author Dmitry (dio) Levashov |
||
1096 | **/ |
||
1097 | public function root() { |
||
1100 | |||
1101 | /** |
||
1102 | * Return target path hash |
||
1103 | * |
||
1104 | * @param string $path |
||
1105 | * @param string $name |
||
1106 | * @author Naoki Sawada |
||
1107 | */ |
||
1108 | public function getHash($path, $name = '') { |
||
1114 | |||
1115 | /** |
||
1116 | * Return root or startPath hash |
||
1117 | * |
||
1118 | * @return string |
||
1119 | * @author Dmitry (dio) Levashov |
||
1120 | **/ |
||
1121 | public function defaultPath() { |
||
1124 | |||
1125 | /** |
||
1126 | * Return volume options required by client: |
||
1127 | * |
||
1128 | * @return array |
||
1129 | * @author Dmitry (dio) Levashov |
||
1130 | **/ |
||
1131 | public function options($hash) { |
||
1160 | |||
1161 | /** |
||
1162 | * Get option value of this volume |
||
1163 | * |
||
1164 | * @param string $name target option name |
||
1165 | * @return NULL|mixed target option value |
||
1166 | * @author Naoki Sawada |
||
1167 | */ |
||
1168 | public function getOption($name) { |
||
1171 | |||
1172 | /** |
||
1173 | * Get plugin values of this options |
||
1174 | * |
||
1175 | * @param string $name Plugin name |
||
1176 | * @return NULL|array Plugin values |
||
1177 | * @author Naoki Sawada |
||
1178 | */ |
||
1179 | public function getOptionsPlugin($name = '') { |
||
1186 | |||
1187 | /** |
||
1188 | * Return true if command disabled in options |
||
1189 | * |
||
1190 | * @param string $cmd command name |
||
1191 | * @return bool |
||
1192 | * @author Dmitry (dio) Levashov |
||
1193 | **/ |
||
1194 | public function commandDisabled($cmd) { |
||
1197 | |||
1198 | /** |
||
1199 | * Return true if mime is required mimes list |
||
1200 | * |
||
1201 | * @param string $mime mime type to check |
||
1202 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
1203 | * @param bool|null $empty what to return on empty list |
||
1204 | * @return bool|null |
||
1205 | * @author Dmitry (dio) Levashov |
||
1206 | * @author Troex Nevelin |
||
1207 | **/ |
||
1208 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
1219 | |||
1220 | /** |
||
1221 | * Return true if voume is readable. |
||
1222 | * |
||
1223 | * @return bool |
||
1224 | * @author Dmitry (dio) Levashov |
||
1225 | **/ |
||
1226 | public function isReadable() { |
||
1230 | |||
1231 | /** |
||
1232 | * Return true if copy from this volume allowed |
||
1233 | * |
||
1234 | * @return bool |
||
1235 | * @author Dmitry (dio) Levashov |
||
1236 | **/ |
||
1237 | public function copyFromAllowed() { |
||
1240 | |||
1241 | /** |
||
1242 | * Return file path related to root with convert encoging |
||
1243 | * |
||
1244 | * @param string $hash file hash |
||
1245 | * @return string |
||
1246 | * @author Dmitry (dio) Levashov |
||
1247 | **/ |
||
1248 | public function path($hash) { |
||
1251 | |||
1252 | /** |
||
1253 | * Return file real path if file exists |
||
1254 | * |
||
1255 | * @param string $hash file hash |
||
1256 | * @return string |
||
1257 | * @author Dmitry (dio) Levashov |
||
1258 | **/ |
||
1259 | public function realpath($hash) { |
||
1263 | |||
1264 | /** |
||
1265 | * Return list of moved/overwrited files |
||
1266 | * |
||
1267 | * @return array |
||
1268 | * @author Dmitry (dio) Levashov |
||
1269 | **/ |
||
1270 | public function removed() { |
||
1273 | |||
1274 | /** |
||
1275 | * Clean removed files list |
||
1276 | * |
||
1277 | * @return void |
||
1278 | * @author Dmitry (dio) Levashov |
||
1279 | **/ |
||
1280 | public function resetRemoved() { |
||
1283 | |||
1284 | /** |
||
1285 | * Return file/dir hash or first founded child hash with required attr == $val |
||
1286 | * |
||
1287 | * @param string $hash file hash |
||
1288 | * @param string $attr attribute name |
||
1289 | * @param bool $val attribute value |
||
1290 | * @return string|false |
||
1291 | * @author Dmitry (dio) Levashov |
||
1292 | **/ |
||
1293 | public function closest($hash, $attr, $val) { |
||
1296 | |||
1297 | /** |
||
1298 | * Return file info or false on error |
||
1299 | * |
||
1300 | * @param string $hash file hash |
||
1301 | * @param bool $realpath add realpath field to file info |
||
1302 | * @return array|false |
||
1303 | * @author Dmitry (dio) Levashov |
||
1304 | **/ |
||
1305 | public function file($hash) { |
||
1321 | |||
1322 | /** |
||
1323 | * Return folder info |
||
1324 | * |
||
1325 | * @param string $hash folder hash |
||
1326 | * @param bool $hidden return hidden file info |
||
1327 | * @return array|false |
||
1328 | * @author Dmitry (dio) Levashov |
||
1329 | **/ |
||
1330 | public function dir($hash, $resolveLink=false) { |
||
1343 | |||
1344 | /** |
||
1345 | * Return directory content or false on error |
||
1346 | * |
||
1347 | * @param string $hash file hash |
||
1348 | * @return array|false |
||
1349 | * @author Dmitry (dio) Levashov |
||
1350 | **/ |
||
1351 | public function scandir($hash) { |
||
1360 | |||
1361 | /** |
||
1362 | * Return dir files names list |
||
1363 | * |
||
1364 | * @param string $hash file hash |
||
1365 | * @return array |
||
1366 | * @author Dmitry (dio) Levashov |
||
1367 | **/ |
||
1368 | public function ls($hash) { |
||
1384 | |||
1385 | /** |
||
1386 | * Return subfolders for required folder or false on error |
||
1387 | * |
||
1388 | * @param string $hash folder hash or empty string to get tree from root folder |
||
1389 | * @param int $deep subdir deep |
||
1390 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
1391 | * @return array|false |
||
1392 | * @author Dmitry (dio) Levashov |
||
1393 | **/ |
||
1394 | public function tree($hash='', $deep=0, $exclude='') { |
||
1405 | |||
1406 | /** |
||
1407 | * Return part of dirs tree from required dir up to root dir |
||
1408 | * |
||
1409 | * @param string $hash directory hash |
||
1410 | * @param bool|null $lineal only lineal parents |
||
1411 | * @return array |
||
1412 | * @author Dmitry (dio) Levashov |
||
1413 | **/ |
||
1414 | public function parents($hash, $lineal = false) { |
||
1441 | |||
1442 | /** |
||
1443 | * Create thumbnail for required file and return its name of false on failed |
||
1444 | * |
||
1445 | * @return string|false |
||
1446 | * @author Dmitry (dio) Levashov |
||
1447 | **/ |
||
1448 | public function tmb($hash) { |
||
1457 | |||
1458 | /** |
||
1459 | * Return file size / total directory size |
||
1460 | * |
||
1461 | * @param string file hash |
||
1462 | * @return int |
||
1463 | * @author Dmitry (dio) Levashov |
||
1464 | **/ |
||
1465 | public function size($hash) { |
||
1468 | |||
1469 | /** |
||
1470 | * Open file for reading and return file pointer |
||
1471 | * |
||
1472 | * @param string file hash |
||
1473 | * @return Resource |
||
1474 | * @author Dmitry (dio) Levashov |
||
1475 | **/ |
||
1476 | public function open($hash) { |
||
1484 | |||
1485 | /** |
||
1486 | * Close file pointer |
||
1487 | * |
||
1488 | * @param Resource $fp file pointer |
||
1489 | * @param string $hash file hash |
||
1490 | * @return void |
||
1491 | * @author Dmitry (dio) Levashov |
||
1492 | **/ |
||
1493 | public function close($fp, $hash) { |
||
1496 | |||
1497 | /** |
||
1498 | * Create directory and return dir info |
||
1499 | * |
||
1500 | * @param string $dsthash destination directory hash |
||
1501 | * @param string $name directory name |
||
1502 | * @return array|false |
||
1503 | * @author Dmitry (dio) Levashov |
||
1504 | **/ |
||
1505 | public function mkdir($dsthash, $name) { |
||
1532 | |||
1533 | /** |
||
1534 | * Create empty file and return its info |
||
1535 | * |
||
1536 | * @param string $dst destination directory |
||
1537 | * @param string $name file name |
||
1538 | * @return array|false |
||
1539 | * @author Dmitry (dio) Levashov |
||
1540 | **/ |
||
1541 | public function mkfile($dst, $name) { |
||
1567 | |||
1568 | /** |
||
1569 | * Rename file and return file info |
||
1570 | * |
||
1571 | * @param string $hash file hash |
||
1572 | * @param string $name new file name |
||
1573 | * @return array|false |
||
1574 | * @author Dmitry (dio) Levashov |
||
1575 | **/ |
||
1576 | public function rename($hash, $name) { |
||
1622 | |||
1623 | /** |
||
1624 | * Create file copy with suffix "copy number" and return its info |
||
1625 | * |
||
1626 | * @param string $hash file hash |
||
1627 | * @param string $suffix suffix to add to file name |
||
1628 | * @return array|false |
||
1629 | * @author Dmitry (dio) Levashov |
||
1630 | **/ |
||
1631 | public function duplicate($hash, $suffix='copy') { |
||
1652 | |||
1653 | /** |
||
1654 | * Save uploaded file. |
||
1655 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
1656 | * |
||
1657 | * @param Resource $fp file pointer |
||
1658 | * @param string $dst destination folder hash |
||
1659 | * @param string $src file name |
||
1660 | * @param string $tmpname file tmp name - required to detect mime type |
||
1661 | * @return array|false |
||
1662 | * @author Dmitry (dio) Levashov |
||
1663 | **/ |
||
1664 | public function upload($fp, $dst, $name, $tmpname) { |
||
1740 | |||
1741 | /** |
||
1742 | * Paste files |
||
1743 | * |
||
1744 | * @param Object $volume source volume |
||
1745 | * @param string $source file hash |
||
1746 | * @param string $dst destination dir hash |
||
1747 | * @param bool $rmSrc remove source after copy? |
||
1748 | * @return array|false |
||
1749 | * @author Dmitry (dio) Levashov |
||
1750 | **/ |
||
1751 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
1839 | |||
1840 | /** |
||
1841 | * Return file contents |
||
1842 | * |
||
1843 | * @param string $hash file hash |
||
1844 | * @return string|false |
||
1845 | * @author Dmitry (dio) Levashov |
||
1846 | **/ |
||
1847 | public function getContents($hash) { |
||
1864 | |||
1865 | /** |
||
1866 | * Put content in text file and return file info. |
||
1867 | * |
||
1868 | * @param string $hash file hash |
||
1869 | * @param string $content new file content |
||
1870 | * @return array |
||
1871 | * @author Dmitry (dio) Levashov |
||
1872 | **/ |
||
1873 | public function putContents($hash, $content) { |
||
1908 | |||
1909 | /** |
||
1910 | * Extract files from archive |
||
1911 | * |
||
1912 | * @param string $hash archive hash |
||
1913 | * @return array|bool |
||
1914 | * @author Dmitry (dio) Levashov, |
||
1915 | * @author Alexey Sukhotin |
||
1916 | **/ |
||
1917 | public function extract($hash, $makedir = null) { |
||
1956 | |||
1957 | /** |
||
1958 | * Add files to archive |
||
1959 | * |
||
1960 | * @return void |
||
1961 | **/ |
||
1962 | public function archive($hashes, $mime, $name = '') { |
||
2006 | |||
2007 | /** |
||
2008 | * Resize image |
||
2009 | * |
||
2010 | * @param string $hash image file |
||
2011 | * @param int $width new width |
||
2012 | * @param int $height new height |
||
2013 | * @param int $x X start poistion for crop |
||
2014 | * @param int $y Y start poistion for crop |
||
2015 | * @param string $mode action how to mainpulate image |
||
2016 | * @param string $bg background color |
||
2017 | * @param int $degree rotete degree |
||
2018 | * @param int $jpgQuality JEPG quality (1-100) |
||
2019 | * @return array|false |
||
2020 | * @author Dmitry (dio) Levashov |
||
2021 | * @author Alexey Sukhotin |
||
2022 | * @author nao-pon |
||
2023 | * @author Troex Nevelin |
||
2024 | **/ |
||
2025 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0, $jpgQuality = null) { |
||
2112 | |||
2113 | /** |
||
2114 | * Remove file/dir |
||
2115 | * |
||
2116 | * @param string $hash file hash |
||
2117 | * @return bool |
||
2118 | * @author Dmitry (dio) Levashov |
||
2119 | **/ |
||
2120 | public function rm($hash) { |
||
2125 | |||
2126 | /** |
||
2127 | * Search files |
||
2128 | * |
||
2129 | * @param string $q search string |
||
2130 | * @param array $mimes |
||
2131 | * @return array |
||
2132 | * @author Dmitry (dio) Levashov |
||
2133 | **/ |
||
2134 | public function search($q, $mimes, $hash = null) { |
||
2154 | |||
2155 | /** |
||
2156 | * Return image dimensions |
||
2157 | * |
||
2158 | * @param string $hash file hash |
||
2159 | * @return array |
||
2160 | * @author Dmitry (dio) Levashov |
||
2161 | **/ |
||
2162 | public function dimensions($hash) { |
||
2169 | |||
2170 | /** |
||
2171 | * Return content URL (for netmout volume driver) |
||
2172 | * If file.url == 1 requests from JavaScript client with XHR |
||
2173 | * |
||
2174 | * @param string $hash file hash |
||
2175 | * @param array $options options array |
||
2176 | * @return boolean|string |
||
2177 | * @author Naoki Sawada |
||
2178 | */ |
||
2179 | public function getContentUrl($hash, $options = array()) { |
||
2185 | |||
2186 | /** |
||
2187 | * Return temp path |
||
2188 | * |
||
2189 | * @return string |
||
2190 | * @author Naoki Sawada |
||
2191 | */ |
||
2192 | public function getTempPath() { |
||
2208 | |||
2209 | /** |
||
2210 | * (Make &) Get upload taget dirctory hash |
||
2211 | * |
||
2212 | * @param string $baseTargetHash |
||
2213 | * @param string $path |
||
2214 | * @param array $result |
||
2215 | * @return boolean|string |
||
2216 | * @author Naoki Sawada |
||
2217 | */ |
||
2218 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
2245 | |||
2246 | /** |
||
2247 | * Return this uploadMaxSize value |
||
2248 | * |
||
2249 | * @return integer |
||
2250 | * @author Naoki Sawada |
||
2251 | */ |
||
2252 | public function getUploadMaxSize() { |
||
2255 | |||
2256 | /** |
||
2257 | * Save error message |
||
2258 | * |
||
2259 | * @param array error |
||
2260 | * @return false |
||
2261 | * @author Dmitry(dio) Levashov |
||
2262 | **/ |
||
2263 | protected function setError($error) { |
||
2278 | |||
2279 | /*********************************************************************/ |
||
2280 | /* FS API */ |
||
2281 | /*********************************************************************/ |
||
2282 | |||
2283 | /***************** server encoding support *******************/ |
||
2284 | |||
2285 | /** |
||
2286 | * Return parent directory path (with convert encording) |
||
2287 | * |
||
2288 | * @param string $path file path |
||
2289 | * @return string |
||
2290 | * @author Naoki Sawada |
||
2291 | **/ |
||
2292 | protected function dirnameCE($path) { |
||
2295 | |||
2296 | /** |
||
2297 | * Return file name (with convert encording) |
||
2298 | * |
||
2299 | * @param string $path file path |
||
2300 | * @return string |
||
2301 | * @author Naoki Sawada |
||
2302 | **/ |
||
2303 | protected function basenameCE($path) { |
||
2306 | |||
2307 | /** |
||
2308 | * Join dir name and file name and return full path. (with convert encording) |
||
2309 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
2310 | * |
||
2311 | * @param string $dir dir path |
||
2312 | * @param string $name file name |
||
2313 | * @return string |
||
2314 | * @author Naoki Sawada |
||
2315 | **/ |
||
2316 | protected function joinPathCE($dir, $name) { |
||
2319 | |||
2320 | /** |
||
2321 | * Return normalized path (with convert encording) |
||
2322 | * |
||
2323 | * @param string $path file path |
||
2324 | * @return string |
||
2325 | * @author Naoki Sawada |
||
2326 | **/ |
||
2327 | protected function normpathCE($path) { |
||
2330 | |||
2331 | /** |
||
2332 | * Return file path related to root dir (with convert encording) |
||
2333 | * |
||
2334 | * @param string $path file path |
||
2335 | * @return string |
||
2336 | * @author Naoki Sawada |
||
2337 | **/ |
||
2338 | protected function relpathCE($path) { |
||
2341 | |||
2342 | /** |
||
2343 | * Convert path related to root dir into real path (with convert encording) |
||
2344 | * |
||
2345 | * @param string $path rel file path |
||
2346 | * @return string |
||
2347 | * @author Naoki Sawada |
||
2348 | **/ |
||
2349 | protected function abspathCE($path) { |
||
2352 | |||
2353 | /** |
||
2354 | * Return true if $path is children of $parent (with convert encording) |
||
2355 | * |
||
2356 | * @param string $path path to check |
||
2357 | * @param string $parent parent path |
||
2358 | * @return bool |
||
2359 | * @author Naoki Sawada |
||
2360 | **/ |
||
2361 | protected function inpathCE($path, $parent) { |
||
2364 | |||
2365 | /** |
||
2366 | * Open file and return file pointer (with convert encording) |
||
2367 | * |
||
2368 | * @param string $path file path |
||
2369 | * @param bool $write open file for writing |
||
2370 | * @return resource|false |
||
2371 | * @author Naoki Sawada |
||
2372 | **/ |
||
2373 | protected function fopenCE($path, $mode='rb') { |
||
2376 | |||
2377 | /** |
||
2378 | * Close opened file (with convert encording) |
||
2379 | * |
||
2380 | * @param resource $fp file pointer |
||
2381 | * @param string $path file path |
||
2382 | * @return bool |
||
2383 | * @author Naoki Sawada |
||
2384 | **/ |
||
2385 | protected function fcloseCE($fp, $path='') { |
||
2388 | |||
2389 | /** |
||
2390 | * Create new file and write into it from file pointer. (with convert encording) |
||
2391 | * Return new file path or false on error. |
||
2392 | * |
||
2393 | * @param resource $fp file pointer |
||
2394 | * @param string $dir target dir path |
||
2395 | * @param string $name file name |
||
2396 | * @param array $stat file stat (required by some virtual fs) |
||
2397 | * @return bool|string |
||
2398 | * @author Naoki Sawada |
||
2399 | **/ |
||
2400 | protected function saveCE($fp, $dir, $name, $stat) { |
||
2403 | |||
2404 | /** |
||
2405 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
2406 | * |
||
2407 | * @param string $path dir path |
||
2408 | * @return bool |
||
2409 | * @author Naoki Sawada |
||
2410 | **/ |
||
2411 | protected function subdirsCE($path) { |
||
2417 | |||
2418 | /** |
||
2419 | * Return files list in directory (with convert encording) |
||
2420 | * |
||
2421 | * @param string $path dir path |
||
2422 | * @return array |
||
2423 | * @author Naoki Sawada |
||
2424 | **/ |
||
2425 | protected function scandirCE($path) { |
||
2428 | |||
2429 | /** |
||
2430 | * Create symlink (with convert encording) |
||
2431 | * |
||
2432 | * @param string $source file to link to |
||
2433 | * @param string $targetDir folder to create link in |
||
2434 | * @param string $name symlink name |
||
2435 | * @return bool |
||
2436 | * @author Naoki Sawada |
||
2437 | **/ |
||
2438 | protected function symlinkCE($source, $targetDir, $name) { |
||
2441 | |||
2442 | /***************** paths *******************/ |
||
2443 | |||
2444 | /** |
||
2445 | * Encode path into hash |
||
2446 | * |
||
2447 | * @param string file path |
||
2448 | * @return string |
||
2449 | * @author Dmitry (dio) Levashov |
||
2450 | * @author Troex Nevelin |
||
2451 | **/ |
||
2452 | protected function encode($path) { |
||
2473 | |||
2474 | /** |
||
2475 | * Decode path from hash |
||
2476 | * |
||
2477 | * @param string file hash |
||
2478 | * @return string |
||
2479 | * @author Dmitry (dio) Levashov |
||
2480 | * @author Troex Nevelin |
||
2481 | **/ |
||
2482 | protected function decode($hash) { |
||
2494 | |||
2495 | /** |
||
2496 | * Return crypted path |
||
2497 | * Not implemented |
||
2498 | * |
||
2499 | * @param string path |
||
2500 | * @return mixed |
||
2501 | * @author Dmitry (dio) Levashov |
||
2502 | **/ |
||
2503 | protected function crypt($path) { |
||
2506 | |||
2507 | /** |
||
2508 | * Return uncrypted path |
||
2509 | * Not implemented |
||
2510 | * |
||
2511 | * @param mixed hash |
||
2512 | * @return mixed |
||
2513 | * @author Dmitry (dio) Levashov |
||
2514 | **/ |
||
2515 | protected function uncrypt($hash) { |
||
2518 | |||
2519 | /** |
||
2520 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
2521 | * |
||
2522 | * @param string $name file name |
||
2523 | * @return bool |
||
2524 | * @author Dmitry (dio) Levashov |
||
2525 | **/ |
||
2526 | protected function nameAccepted($name) { |
||
2541 | |||
2542 | /** |
||
2543 | * Return new unique name based on file name and suffix |
||
2544 | * |
||
2545 | * @param string $path file path |
||
2546 | * @param string $suffix suffix append to name |
||
2547 | * @return string |
||
2548 | * @author Dmitry (dio) Levashov |
||
2549 | **/ |
||
2550 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum = true, $start = 1) { |
||
2578 | |||
2579 | /** |
||
2580 | * Converts character encoding from UTF-8 to server's one |
||
2581 | * |
||
2582 | * @param mixed $var target string or array var |
||
2583 | * @param bool $restoreLocale do retore global locale, default is false |
||
2584 | * @param string $unknown replaces character for unknown |
||
2585 | * @return mixed |
||
2586 | * @author Naoki Sawada |
||
2587 | */ |
||
2588 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
2591 | |||
2592 | /** |
||
2593 | * Converts character encoding from server's one to UTF-8 |
||
2594 | * |
||
2595 | * @param mixed $var target string or array var |
||
2596 | * @param bool $restoreLocale do retore global locale, default is true |
||
2597 | * @param string $unknown replaces character for unknown |
||
2598 | * @return mixed |
||
2599 | * @author Naoki Sawada |
||
2600 | */ |
||
2601 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
2604 | |||
2605 | /** |
||
2606 | * Converts character encoding (base function) |
||
2607 | * |
||
2608 | * @param mixed $var target string or array var |
||
2609 | * @param string $from from character encoding |
||
2610 | * @param string $to to character encoding |
||
2611 | * @param string $locale local locale |
||
2612 | * @param string $unknown replaces character for unknown |
||
2613 | * @return mixed |
||
2614 | */ |
||
2615 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
2644 | |||
2645 | /*********************** util mainly for inheritance class *********************/ |
||
2646 | |||
2647 | /** |
||
2648 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
2649 | * When needing the unique file to a path, give $path to parameter. |
||
2650 | * |
||
2651 | * @param string $path for get unique file to a path |
||
2652 | * @return string|false |
||
2653 | * @author Naoki Sawada |
||
2654 | */ |
||
2655 | protected function getTempFile($path = '') { |
||
2681 | |||
2682 | /** |
||
2683 | * File path of local server side work file path |
||
2684 | * |
||
2685 | * @param string $path path need convert encoding to server encoding |
||
2686 | * @return string |
||
2687 | * @author Naoki Sawada |
||
2688 | */ |
||
2689 | protected function getWorkFile($path) { |
||
2704 | |||
2705 | /** |
||
2706 | * Get image size array with `dimensions` |
||
2707 | * |
||
2708 | * @param string $path path need convert encoding to server encoding |
||
2709 | * @param string $mime file mime type |
||
2710 | * @return array|false |
||
2711 | */ |
||
2712 | public function getImageSize($path, $mime = '') { |
||
2724 | |||
2725 | /** |
||
2726 | * Delete dirctory trees |
||
2727 | * |
||
2728 | * @param string $localpath path need convert encoding to server encoding |
||
2729 | * @return boolean |
||
2730 | * @author Naoki Sawada |
||
2731 | */ |
||
2732 | protected function delTree($localpath) { |
||
2741 | |||
2742 | /*********************** file stat *********************/ |
||
2743 | |||
2744 | /** |
||
2745 | * Check file attribute |
||
2746 | * |
||
2747 | * @param string $path file path |
||
2748 | * @param string $name attribute name (read|write|locked|hidden) |
||
2749 | * @param bool $val attribute value returned by file system |
||
2750 | * @param bool $isDir path is directory (true: directory, false: file) |
||
2751 | * @return bool |
||
2752 | * @author Dmitry (dio) Levashov |
||
2753 | **/ |
||
2754 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
2788 | |||
2789 | /** |
||
2790 | * Return true if file with given name can be created in given folder. |
||
2791 | * |
||
2792 | * @param string $dir parent dir path |
||
2793 | * @param string $name new file name |
||
2794 | * @return bool |
||
2795 | * @author Dmitry (dio) Levashov |
||
2796 | **/ |
||
2797 | protected function allowCreate($dir, $name, $isDir = null) { |
||
2820 | |||
2821 | /** |
||
2822 | * Return true if file MIME type can save with check uploadOrder config. |
||
2823 | * |
||
2824 | * @param string $mime |
||
2825 | * @return boolean |
||
2826 | */ |
||
2827 | protected function allowPutMime($mime) { |
||
2845 | |||
2846 | /** |
||
2847 | * Return fileinfo |
||
2848 | * |
||
2849 | * @param string $path file cache |
||
2850 | * @return array |
||
2851 | * @author Dmitry (dio) Levashov |
||
2852 | **/ |
||
2853 | protected function stat($path) { |
||
2881 | |||
2882 | /** |
||
2883 | * Put file stat in cache and return it |
||
2884 | * |
||
2885 | * @param string $path file path |
||
2886 | * @param array $stat file stat |
||
2887 | * @return array |
||
2888 | * @author Dmitry (dio) Levashov |
||
2889 | **/ |
||
2890 | protected function updateCache($path, $stat) { |
||
3033 | |||
3034 | /** |
||
3035 | * Get stat for folder content and put in cache |
||
3036 | * |
||
3037 | * @param string $path |
||
3038 | * @return void |
||
3039 | * @author Dmitry (dio) Levashov |
||
3040 | **/ |
||
3041 | protected function cacheDir($path) { |
||
3054 | |||
3055 | /** |
||
3056 | * Clean cache |
||
3057 | * |
||
3058 | * @return void |
||
3059 | * @author Dmitry (dio) Levashov |
||
3060 | **/ |
||
3061 | protected function clearcache() { |
||
3066 | |||
3067 | /** |
||
3068 | * Return file mimetype |
||
3069 | * |
||
3070 | * @param string $path file path |
||
3071 | * @return string |
||
3072 | * @author Dmitry (dio) Levashov |
||
3073 | **/ |
||
3074 | protected function mimetype($path, $name = '') { |
||
3119 | |||
3120 | /** |
||
3121 | * Detect file mimetype using "internal" method |
||
3122 | * |
||
3123 | * @param string $path file path |
||
3124 | * @return string |
||
3125 | * @author Dmitry (dio) Levashov |
||
3126 | **/ |
||
3127 | static protected function mimetypeInternalDetect($path) { |
||
3150 | |||
3151 | /** |
||
3152 | * Return file/total directory size |
||
3153 | * |
||
3154 | * @param string $path file path |
||
3155 | * @return int |
||
3156 | * @author Dmitry (dio) Levashov |
||
3157 | **/ |
||
3158 | protected function countSize($path) { |
||
3183 | |||
3184 | /** |
||
3185 | * Return true if all mimes is directory or files |
||
3186 | * |
||
3187 | * @param string $mime1 mimetype |
||
3188 | * @param string $mime2 mimetype |
||
3189 | * @return bool |
||
3190 | * @author Dmitry (dio) Levashov |
||
3191 | **/ |
||
3192 | protected function isSameType($mime1, $mime2) { |
||
3195 | |||
3196 | /** |
||
3197 | * If file has required attr == $val - return file path, |
||
3198 | * If dir has child with has required attr == $val - return child path |
||
3199 | * |
||
3200 | * @param string $path file path |
||
3201 | * @param string $attr attribute name |
||
3202 | * @param bool $val attribute value |
||
3203 | * @return string|false |
||
3204 | * @author Dmitry (dio) Levashov |
||
3205 | **/ |
||
3206 | protected function closestByAttr($path, $attr, $val) { |
||
3223 | |||
3224 | /** |
||
3225 | * Return first found children with required attr == $val |
||
3226 | * |
||
3227 | * @param string $path file path |
||
3228 | * @param string $attr attribute name |
||
3229 | * @param bool $val attribute value |
||
3230 | * @return string|false |
||
3231 | * @author Dmitry (dio) Levashov |
||
3232 | **/ |
||
3233 | protected function childsByAttr($path, $attr, $val) { |
||
3241 | |||
3242 | protected function isMyReload($target = '', $ARGtarget = '') { |
||
3264 | |||
3265 | /***************** get content *******************/ |
||
3266 | |||
3267 | /** |
||
3268 | * Return required dir's files info. |
||
3269 | * If onlyMimes is set - return only dirs and files of required mimes |
||
3270 | * |
||
3271 | * @param string $path dir path |
||
3272 | * @return array |
||
3273 | * @author Dmitry (dio) Levashov |
||
3274 | **/ |
||
3275 | protected function getScandir($path) { |
||
3288 | |||
3289 | |||
3290 | /** |
||
3291 | * Return subdirs tree |
||
3292 | * |
||
3293 | * @param string $path parent dir path |
||
3294 | * @param int $deep tree deep |
||
3295 | * @return array |
||
3296 | * @author Dmitry (dio) Levashov |
||
3297 | **/ |
||
3298 | protected function gettree($path, $deep, $exclude='') { |
||
3316 | |||
3317 | /** |
||
3318 | * Recursive files search |
||
3319 | * |
||
3320 | * @param string $path dir path |
||
3321 | * @param string $q search string |
||
3322 | * @param array $mimes |
||
3323 | * @return array |
||
3324 | * @author Dmitry (dio) Levashov |
||
3325 | **/ |
||
3326 | protected function doSearch($path, $q, $mimes) { |
||
3375 | |||
3376 | /********************** manuipulations ******************/ |
||
3377 | |||
3378 | /** |
||
3379 | * Copy file/recursive copy dir only in current volume. |
||
3380 | * Return new file path or false. |
||
3381 | * |
||
3382 | * @param string $src source path |
||
3383 | * @param string $dst destination dir path |
||
3384 | * @param string $name new file name (optionaly) |
||
3385 | * @return string|false |
||
3386 | * @author Dmitry (dio) Levashov |
||
3387 | **/ |
||
3388 | protected function copy($src, $dst, $name) { |
||
3430 | |||
3431 | /** |
||
3432 | * Move file |
||
3433 | * Return new file path or false. |
||
3434 | * |
||
3435 | * @param string $src source path |
||
3436 | * @param string $dst destination dir path |
||
3437 | * @param string $name new file name |
||
3438 | * @return string|false |
||
3439 | * @author Dmitry (dio) Levashov |
||
3440 | **/ |
||
3441 | protected function move($src, $dst, $name) { |
||
3455 | |||
3456 | /** |
||
3457 | * Copy file from another volume. |
||
3458 | * Return new file path or false. |
||
3459 | * |
||
3460 | * @param Object $volume source volume |
||
3461 | * @param string $src source file hash |
||
3462 | * @param string $destination destination dir path |
||
3463 | * @param string $name file name |
||
3464 | * @return string|false |
||
3465 | * @author Dmitry (dio) Levashov |
||
3466 | **/ |
||
3467 | protected function copyFrom($volume, $src, $destination, $name) { |
||
3529 | |||
3530 | /** |
||
3531 | * Remove file/ recursive remove dir |
||
3532 | * |
||
3533 | * @param string $path file path |
||
3534 | * @param bool $force try to remove even if file locked |
||
3535 | * @return bool |
||
3536 | * @author Dmitry (dio) Levashov |
||
3537 | **/ |
||
3538 | protected function remove($path, $force = false) { |
||
3568 | |||
3569 | |||
3570 | /************************* thumbnails **************************/ |
||
3571 | |||
3572 | /** |
||
3573 | * Return thumbnail file name for required file |
||
3574 | * |
||
3575 | * @param array $stat file stat |
||
3576 | * @return string |
||
3577 | * @author Dmitry (dio) Levashov |
||
3578 | **/ |
||
3579 | protected function tmbname($stat) { |
||
3582 | |||
3583 | /** |
||
3584 | * Return thumnbnail name if exists |
||
3585 | * |
||
3586 | * @param string $path file path |
||
3587 | * @param array $stat file stat |
||
3588 | * @return string|false |
||
3589 | * @author Dmitry (dio) Levashov |
||
3590 | **/ |
||
3591 | protected function gettmb($path, $stat) { |
||
3605 | |||
3606 | /** |
||
3607 | * Return true if thumnbnail for required file can be created |
||
3608 | * |
||
3609 | * @param string $path thumnbnail path |
||
3610 | * @param array $stat file stat |
||
3611 | * @param bool $checkTmbPath |
||
3612 | * @return string|bool |
||
3613 | * @author Dmitry (dio) Levashov |
||
3614 | **/ |
||
3615 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
3622 | |||
3623 | /** |
||
3624 | * Return true if required file can be resized. |
||
3625 | * By default - the same as canCreateTmb |
||
3626 | * |
||
3627 | * @param string $path thumnbnail path |
||
3628 | * @param array $stat file stat |
||
3629 | * @return string|bool |
||
3630 | * @author Dmitry (dio) Levashov |
||
3631 | **/ |
||
3632 | protected function canResize($path, $stat) { |
||
3635 | |||
3636 | /** |
||
3637 | * Create thumnbnail and return it's URL on success |
||
3638 | * |
||
3639 | * @param string $path file path |
||
3640 | * @param string $mime file mime type |
||
3641 | * @return string|false |
||
3642 | * @author Dmitry (dio) Levashov |
||
3643 | **/ |
||
3644 | protected function createTmb($path, $stat) { |
||
3714 | |||
3715 | /** |
||
3716 | * Resize image |
||
3717 | * |
||
3718 | * @param string $path image file |
||
3719 | * @param int $width new width |
||
3720 | * @param int $height new height |
||
3721 | * @param bool $keepProportions crop image |
||
3722 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
3723 | * @param string $destformat image destination format |
||
3724 | * @param int $jpgQuality JEPG quality (1-100) |
||
3725 | * @return string|false |
||
3726 | * @author Dmitry (dio) Levashov |
||
3727 | * @author Alexey Sukhotin |
||
3728 | **/ |
||
3729 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null, $jpgQuality = null) { |
||
3826 | |||
3827 | /** |
||
3828 | * Crop image |
||
3829 | * |
||
3830 | * @param string $path image file |
||
3831 | * @param int $width crop width |
||
3832 | * @param int $height crop height |
||
3833 | * @param bool $x crop left offset |
||
3834 | * @param bool $y crop top offset |
||
3835 | * @param string $destformat image destination format |
||
3836 | * @param int $jpgQuality JEPG quality (1-100) |
||
3837 | * @return string|false |
||
3838 | * @author Dmitry (dio) Levashov |
||
3839 | * @author Alexey Sukhotin |
||
3840 | **/ |
||
3841 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null, $jpgQuality = null) { |
||
3919 | |||
3920 | /** |
||
3921 | * Put image to square |
||
3922 | * |
||
3923 | * @param string $path image file |
||
3924 | * @param int $width square width |
||
3925 | * @param int $height square height |
||
3926 | * @param int $align reserved |
||
3927 | * @param int $valign reserved |
||
3928 | * @param string $bgcolor square background color in #rrggbb format |
||
3929 | * @param string $destformat image destination format |
||
3930 | * @param int $jpgQuality JEPG quality (1-100) |
||
3931 | * @return string|false |
||
3932 | * @author Dmitry (dio) Levashov |
||
3933 | * @author Alexey Sukhotin |
||
3934 | **/ |
||
3935 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null, $jpgQuality = null) { |
||
4016 | |||
4017 | /** |
||
4018 | * Rotate image |
||
4019 | * |
||
4020 | * @param string $path image file |
||
4021 | * @param int $degree rotete degrees |
||
4022 | * @param string $bgcolor square background color in #rrggbb format |
||
4023 | * @param string $destformat image destination format |
||
4024 | * @param int $jpgQuality JEPG quality (1-100) |
||
4025 | * @return string|false |
||
4026 | * @author nao-pon |
||
4027 | * @author Troex Nevelin |
||
4028 | **/ |
||
4029 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null, $jpgQuality = null) { |
||
4113 | |||
4114 | /** |
||
4115 | * Execute shell command |
||
4116 | * |
||
4117 | * @param string $command command line |
||
4118 | * @param array $output stdout strings |
||
4119 | * @param array $return_var process exit code |
||
4120 | * @param array $error_output stderr strings |
||
4121 | * @return int exit code |
||
4122 | * @author Alexey Sukhotin |
||
4123 | **/ |
||
4124 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
4154 | |||
4155 | /** |
||
4156 | * Remove thumbnail, also remove recursively if stat is directory |
||
4157 | * |
||
4158 | * @param string $stat file stat |
||
4159 | * @return void |
||
4160 | * @author Dmitry (dio) Levashov |
||
4161 | * @author Naoki Sawada |
||
4162 | * @author Troex Nevelin |
||
4163 | **/ |
||
4164 | protected function rmTmb($stat) { |
||
4177 | |||
4178 | /** |
||
4179 | * Create an gd image according to the specified mime type |
||
4180 | * |
||
4181 | * @param string $path image file |
||
4182 | * @param string $mime |
||
4183 | * @return gd image resource identifier |
||
4184 | */ |
||
4185 | protected function gdImageCreate($path,$mime){ |
||
4201 | |||
4202 | /** |
||
4203 | * Output gd image to file |
||
4204 | * |
||
4205 | * @param resource $image gd image resource |
||
4206 | * @param string $filename The path to save the file to. |
||
4207 | * @param string $destformat The Image type to use for $filename |
||
4208 | * @param string $mime The original image mime type |
||
4209 | * @param int $jpgQuality JEPG quality (1-100) |
||
4210 | */ |
||
4211 | protected function gdImage($image, $filename, $destformat, $mime, $jpgQuality = null ){ |
||
4226 | |||
4227 | /** |
||
4228 | * Output imagick image to file |
||
4229 | * |
||
4230 | * @param resource $img imagick image resource |
||
4231 | * @param string $filename The path to save the file to. |
||
4232 | * @param string $destformat The Image type to use for $filename |
||
4233 | * @param int $jpgQuality JEPG quality (1-100) |
||
4234 | */ |
||
4235 | protected function imagickImage($img, $filename, $destformat, $jpgQuality = null ){ |
||
4283 | |||
4284 | /** |
||
4285 | * Assign the proper background to a gd image |
||
4286 | * |
||
4287 | * @param resource $image gd image resource |
||
4288 | * @param string $bgcolor background color in #rrggbb format |
||
4289 | */ |
||
4290 | protected function gdImageBackground($image, $bgcolor){ |
||
4303 | |||
4304 | /*********************** misc *************************/ |
||
4305 | |||
4306 | /** |
||
4307 | * Return smart formatted date |
||
4308 | * |
||
4309 | * @param int $ts file timestamp |
||
4310 | * @return string |
||
4311 | * @author Dmitry (dio) Levashov |
||
4312 | **/ |
||
4313 | // protected function formatDate($ts) { |
||
4314 | // if ($ts > $this->today) { |
||
4315 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
4316 | // } |
||
4317 | // |
||
4318 | // if ($ts > $this->yesterday) { |
||
4319 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
4320 | // } |
||
4321 | // |
||
4322 | // return date($this->options['dateFormat'], $ts); |
||
4323 | // } |
||
4324 | |||
4325 | /** |
||
4326 | * Find position of first occurrence of string in a string with multibyte support |
||
4327 | * |
||
4328 | * @param string $haystack The string being checked. |
||
4329 | * @param string $needle The string to find in haystack. |
||
4330 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
4331 | * @return int|bool |
||
4332 | * @author Alexey Sukhotin |
||
4333 | **/ |
||
4334 | protected function stripos($haystack , $needle , $offset = 0) { |
||
4342 | |||
4343 | /** |
||
4344 | * Get server side available archivers |
||
4345 | * |
||
4346 | * @param bool $use_cache |
||
4347 | * @return array |
||
4348 | */ |
||
4349 | protected function getArchivers($use_cache = true) { |
||
4465 | |||
4466 | /** |
||
4467 | * Resolve relative / (Unix-like)absolute path |
||
4468 | * |
||
4469 | * @param string $path target path |
||
4470 | * @param string $base base path |
||
4471 | * @return string |
||
4472 | */ |
||
4473 | protected function getFullPath($path, $base) { |
||
4520 | |||
4521 | /** |
||
4522 | * Remove directory recursive on local file system |
||
4523 | * |
||
4524 | * @param string $dir Target dirctory path |
||
4525 | * @return boolean |
||
4526 | * @author Naoki Sawada |
||
4527 | */ |
||
4528 | public function rmdirRecursive($dir) { |
||
4548 | |||
4549 | /** |
||
4550 | * Create archive and return its path |
||
4551 | * |
||
4552 | * @param string $dir target dir |
||
4553 | * @param array $files files names list |
||
4554 | * @param string $name archive name |
||
4555 | * @param array $arc archiver options |
||
4556 | * @return string|bool |
||
4557 | * @author Dmitry (dio) Levashov, |
||
4558 | * @author Alexey Sukhotin |
||
4559 | * @author Naoki Sawada |
||
4560 | **/ |
||
4561 | protected function makeArchive($dir, $files, $name, $arc) { |
||
4579 | |||
4580 | /** |
||
4581 | * Unpack archive |
||
4582 | * |
||
4583 | * @param string $path archive path |
||
4584 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
4585 | * @param bool $remove remove archive ( unlink($path) ) |
||
4586 | * @return void |
||
4587 | * @author Dmitry (dio) Levashov |
||
4588 | * @author Alexey Sukhotin |
||
4589 | * @author Naoki Sawada |
||
4590 | **/ |
||
4591 | protected function unpackArchive($path, $arc, $remove = true) { |
||
4606 | |||
4607 | /** |
||
4608 | * Create Zip archive using PHP class ZipArchive |
||
4609 | * |
||
4610 | * @param string $dir target dir |
||
4611 | * @param array $files files names list |
||
4612 | * @param string|object $zipPath Zip archive name |
||
4613 | * @return void |
||
4614 | * @author Naoki Sawada |
||
4615 | */ |
||
4616 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
4654 | |||
4655 | /** |
||
4656 | * Unpack Zip archive using PHP class ZipArchive |
||
4657 | * |
||
4658 | * @param string $zipPath Zip archive name |
||
4659 | * @param string $toDir Extract to path |
||
4660 | * @return bool |
||
4661 | * @author Naoki Sawada |
||
4662 | */ |
||
4663 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
4675 | |||
4676 | /**==================================* abstract methods *====================================**/ |
||
4677 | |||
4678 | /*********************** paths/urls *************************/ |
||
4679 | |||
4680 | /** |
||
4681 | * Return parent directory path |
||
4682 | * |
||
4683 | * @param string $path file path |
||
4684 | * @return string |
||
4685 | * @author Dmitry (dio) Levashov |
||
4686 | **/ |
||
4687 | abstract protected function _dirname($path); |
||
4688 | |||
4689 | /** |
||
4690 | * Return file name |
||
4691 | * |
||
4692 | * @param string $path file path |
||
4693 | * @return string |
||
4694 | * @author Dmitry (dio) Levashov |
||
4695 | **/ |
||
4696 | abstract protected function _basename($path); |
||
4697 | |||
4698 | /** |
||
4699 | * Join dir name and file name and return full path. |
||
4700 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
4701 | * |
||
4702 | * @param string $dir dir path |
||
4703 | * @param string $name file name |
||
4704 | * @return string |
||
4705 | * @author Dmitry (dio) Levashov |
||
4706 | **/ |
||
4707 | abstract protected function _joinPath($dir, $name); |
||
4708 | |||
4709 | /** |
||
4710 | * Return normalized path |
||
4711 | * |
||
4712 | * @param string $path file path |
||
4713 | * @return string |
||
4714 | * @author Dmitry (dio) Levashov |
||
4715 | **/ |
||
4716 | abstract protected function _normpath($path); |
||
4717 | |||
4718 | /** |
||
4719 | * Return file path related to root dir |
||
4720 | * |
||
4721 | * @param string $path file path |
||
4722 | * @return string |
||
4723 | * @author Dmitry (dio) Levashov |
||
4724 | **/ |
||
4725 | abstract protected function _relpath($path); |
||
4726 | |||
4727 | /** |
||
4728 | * Convert path related to root dir into real path |
||
4729 | * |
||
4730 | * @param string $path rel file path |
||
4731 | * @return string |
||
4732 | * @author Dmitry (dio) Levashov |
||
4733 | **/ |
||
4734 | abstract protected function _abspath($path); |
||
4735 | |||
4736 | /** |
||
4737 | * Return fake path started from root dir. |
||
4738 | * Required to show path on client side. |
||
4739 | * |
||
4740 | * @param string $path file path |
||
4741 | * @return string |
||
4742 | * @author Dmitry (dio) Levashov |
||
4743 | **/ |
||
4744 | abstract protected function _path($path); |
||
4745 | |||
4746 | /** |
||
4747 | * Return true if $path is children of $parent |
||
4748 | * |
||
4749 | * @param string $path path to check |
||
4750 | * @param string $parent parent path |
||
4751 | * @return bool |
||
4752 | * @author Dmitry (dio) Levashov |
||
4753 | **/ |
||
4754 | abstract protected function _inpath($path, $parent); |
||
4755 | |||
4756 | /** |
||
4757 | * Return stat for given path. |
||
4758 | * Stat contains following fields: |
||
4759 | * - (int) size file size in b. required |
||
4760 | * - (int) ts file modification time in unix time. required |
||
4761 | * - (string) mime mimetype. required for folders, others - optionally |
||
4762 | * - (bool) read read permissions. required |
||
4763 | * - (bool) write write permissions. required |
||
4764 | * - (bool) locked is object locked. optionally |
||
4765 | * - (bool) hidden is object hidden. optionally |
||
4766 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
4767 | * - (string) target for symlinks - link target path. optionally |
||
4768 | * |
||
4769 | * If file does not exists - returns empty array or false. |
||
4770 | * |
||
4771 | * @param string $path file path |
||
4772 | * @return array|false |
||
4773 | * @author Dmitry (dio) Levashov |
||
4774 | **/ |
||
4775 | abstract protected function _stat($path); |
||
4776 | |||
4777 | |||
4778 | /***************** file stat ********************/ |
||
4779 | |||
4780 | |||
4781 | /** |
||
4782 | * Return true if path is dir and has at least one childs directory |
||
4783 | * |
||
4784 | * @param string $path dir path |
||
4785 | * @return bool |
||
4786 | * @author Dmitry (dio) Levashov |
||
4787 | **/ |
||
4788 | abstract protected function _subdirs($path); |
||
4789 | |||
4790 | /** |
||
4791 | * Return object width and height |
||
4792 | * Ususaly used for images, but can be realize for video etc... |
||
4793 | * |
||
4794 | * @param string $path file path |
||
4795 | * @param string $mime file mime type |
||
4796 | * @return string |
||
4797 | * @author Dmitry (dio) Levashov |
||
4798 | **/ |
||
4799 | abstract protected function _dimensions($path, $mime); |
||
4800 | |||
4801 | /******************** file/dir content *********************/ |
||
4802 | |||
4803 | /** |
||
4804 | * Return files list in directory |
||
4805 | * |
||
4806 | * @param string $path dir path |
||
4807 | * @return array |
||
4808 | * @author Dmitry (dio) Levashov |
||
4809 | **/ |
||
4810 | abstract protected function _scandir($path); |
||
4811 | |||
4812 | /** |
||
4813 | * Open file and return file pointer |
||
4814 | * |
||
4815 | * @param string $path file path |
||
4816 | * @param string $mode open mode |
||
4817 | * @return resource|false |
||
4818 | * @author Dmitry (dio) Levashov |
||
4819 | **/ |
||
4820 | abstract protected function _fopen($path, $mode="rb"); |
||
4821 | |||
4822 | /** |
||
4823 | * Close opened file |
||
4824 | * |
||
4825 | * @param resource $fp file pointer |
||
4826 | * @param string $path file path |
||
4827 | * @return bool |
||
4828 | * @author Dmitry (dio) Levashov |
||
4829 | **/ |
||
4830 | abstract protected function _fclose($fp, $path=''); |
||
4831 | |||
4832 | /******************** file/dir manipulations *************************/ |
||
4833 | |||
4834 | /** |
||
4835 | * Create dir and return created dir path or false on failed |
||
4836 | * |
||
4837 | * @param string $path parent dir path |
||
4838 | * @param string $name new directory name |
||
4839 | * @return string|bool |
||
4840 | * @author Dmitry (dio) Levashov |
||
4841 | **/ |
||
4842 | abstract protected function _mkdir($path, $name); |
||
4843 | |||
4844 | /** |
||
4845 | * Create file and return it's path or false on failed |
||
4846 | * |
||
4847 | * @param string $path parent dir path |
||
4848 | * @param string $name new file name |
||
4849 | * @return string|bool |
||
4850 | * @author Dmitry (dio) Levashov |
||
4851 | **/ |
||
4852 | abstract protected function _mkfile($path, $name); |
||
4853 | |||
4854 | /** |
||
4855 | * Create symlink |
||
4856 | * |
||
4857 | * @param string $source file to link to |
||
4858 | * @param string $targetDir folder to create link in |
||
4859 | * @param string $name symlink name |
||
4860 | * @return bool |
||
4861 | * @author Dmitry (dio) Levashov |
||
4862 | **/ |
||
4863 | abstract protected function _symlink($source, $targetDir, $name); |
||
4864 | |||
4865 | /** |
||
4866 | * Copy file into another file (only inside one volume) |
||
4867 | * |
||
4868 | * @param string $source source file path |
||
4869 | * @param string $target target dir path |
||
4870 | * @param string $name file name |
||
4871 | * @return bool |
||
4872 | * @author Dmitry (dio) Levashov |
||
4873 | **/ |
||
4874 | abstract protected function _copy($source, $targetDir, $name); |
||
4875 | |||
4876 | /** |
||
4877 | * Move file into another parent dir. |
||
4878 | * Return new file path or false. |
||
4879 | * |
||
4880 | * @param string $source source file path |
||
4881 | * @param string $target target dir path |
||
4882 | * @param string $name file name |
||
4883 | * @return string|bool |
||
4884 | * @author Dmitry (dio) Levashov |
||
4885 | **/ |
||
4886 | abstract protected function _move($source, $targetDir, $name); |
||
4887 | |||
4888 | /** |
||
4889 | * Remove file |
||
4890 | * |
||
4891 | * @param string $path file path |
||
4892 | * @return bool |
||
4893 | * @author Dmitry (dio) Levashov |
||
4894 | **/ |
||
4895 | abstract protected function _unlink($path); |
||
4896 | |||
4897 | /** |
||
4898 | * Remove dir |
||
4899 | * |
||
4900 | * @param string $path dir path |
||
4901 | * @return bool |
||
4902 | * @author Dmitry (dio) Levashov |
||
4903 | **/ |
||
4904 | abstract protected function _rmdir($path); |
||
4905 | |||
4906 | /** |
||
4907 | * Create new file and write into it from file pointer. |
||
4908 | * Return new file path or false on error. |
||
4909 | * |
||
4910 | * @param resource $fp file pointer |
||
4911 | * @param string $dir target dir path |
||
4912 | * @param string $name file name |
||
4913 | * @param array $stat file stat (required by some virtual fs) |
||
4914 | * @return bool|string |
||
4915 | * @author Dmitry (dio) Levashov |
||
4916 | **/ |
||
4917 | abstract protected function _save($fp, $dir, $name, $stat); |
||
4918 | |||
4919 | /** |
||
4920 | * Get file contents |
||
4921 | * |
||
4922 | * @param string $path file path |
||
4923 | * @return string|false |
||
4924 | * @author Dmitry (dio) Levashov |
||
4925 | **/ |
||
4926 | abstract protected function _getContents($path); |
||
4927 | |||
4928 | /** |
||
4929 | * Write a string to a file |
||
4930 | * |
||
4931 | * @param string $path file path |
||
4932 | * @param string $content new file content |
||
4933 | * @return bool |
||
4934 | * @author Dmitry (dio) Levashov |
||
4935 | **/ |
||
4936 | abstract protected function _filePutContents($path, $content); |
||
4937 | |||
4938 | /** |
||
4939 | * Extract files from archive |
||
4940 | * |
||
4941 | * @param string $path file path |
||
4942 | * @param array $arc archiver options |
||
4943 | * @return bool |
||
4944 | * @author Dmitry (dio) Levashov, |
||
4945 | * @author Alexey Sukhotin |
||
4946 | **/ |
||
4947 | abstract protected function _extract($path, $arc); |
||
4948 | |||
4949 | /** |
||
4950 | * Create archive and return its path |
||
4951 | * |
||
4952 | * @param string $dir target dir |
||
4953 | * @param array $files files names list |
||
4954 | * @param string $name archive name |
||
4955 | * @param array $arc archiver options |
||
4956 | * @return string|bool |
||
4957 | * @author Dmitry (dio) Levashov, |
||
4958 | * @author Alexey Sukhotin |
||
4959 | **/ |
||
4960 | abstract protected function _archive($dir, $files, $name, $arc); |
||
4961 | |||
4962 | /** |
||
4963 | * Detect available archivers |
||
4964 | * |
||
4965 | * @return void |
||
4966 | * @author Dmitry (dio) Levashov, |
||
4967 | * @author Alexey Sukhotin |
||
4968 | **/ |
||
4969 | abstract protected function _checkArchivers(); |
||
4970 | |||
4971 | /** |
||
4972 | * Change file mode (chmod) |
||
4973 | * |
||
4974 | * @param string $path file path |
||
4975 | * @param string $mode octal string such as '0755' |
||
4976 | * @return bool |
||
4977 | * @author David Bartle, |
||
4978 | **/ |
||
4979 | abstract protected function _chmod($path, $mode); |
||
4980 | |||
4981 | |||
4982 | } // END class |
||
4983 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.