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 | // library to crypt/uncrypt files names (not implemented) |
||
196 | 'cryptLib' => '', |
||
197 | // how to detect files mimetypes. (auto/internal/finfo/mime_content_type) |
||
198 | 'mimeDetect' => 'auto', |
||
199 | // mime.types file path (for mimeDetect==internal) |
||
200 | 'mimefile' => '', |
||
201 | // mime type normalize map : Array '[ext]:[detected mime type]' => '[normalized mime]' |
||
202 | 'mimeMap' => array( |
||
203 | 'md:application/x-genesis-rom' => 'text/x-markdown', |
||
204 | 'md:text/plain' => 'text/x-markdown', |
||
205 | 'markdown:text/plain' => 'text/x-markdown', |
||
206 | 'css:text/x-asm' => 'text/css' |
||
207 | ), |
||
208 | // MIME regex of send HTTP header "Content-Disposition: inline" |
||
209 | // '.' is allow inline of all of MIME types |
||
210 | // '$^' is not allow inline of all of MIME types |
||
211 | 'dispInlineRegex' => '^(?:(?:image|text)|application/x-shockwave-flash$)', |
||
212 | // directory for thumbnails |
||
213 | 'tmbPath' => '.tmb', |
||
214 | // mode to create thumbnails dir |
||
215 | 'tmbPathMode' => 0777, |
||
216 | // thumbnails dir URL. Set it if store thumbnails outside root directory |
||
217 | 'tmbURL' => '', |
||
218 | // thumbnails size (px) |
||
219 | 'tmbSize' => 48, |
||
220 | // thumbnails crop (true - crop, false - scale image to fit thumbnail size) |
||
221 | 'tmbCrop' => true, |
||
222 | // thumbnails background color (hex #rrggbb or 'transparent') |
||
223 | 'tmbBgColor' => '#ffffff', |
||
224 | // image manipulations library |
||
225 | 'imgLib' => 'auto', |
||
226 | // Jpeg image saveing quality |
||
227 | 'jpgQuality' => 100, |
||
228 | // on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
229 | 'copyOverwrite' => true, |
||
230 | // if true - join new and old directories content on paste |
||
231 | 'copyJoin' => true, |
||
232 | // on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
233 | 'uploadOverwrite' => true, |
||
234 | // mimetypes allowed to upload |
||
235 | 'uploadAllow' => array(), |
||
236 | // mimetypes not allowed to upload |
||
237 | 'uploadDeny' => array(), |
||
238 | // order to proccess uploadAllow and uploadDeny options |
||
239 | 'uploadOrder' => array('deny', 'allow'), |
||
240 | // maximum upload file size. NOTE - this is size for every uploaded files |
||
241 | 'uploadMaxSize' => 0, |
||
242 | // files dates format |
||
243 | 'dateFormat' => 'j M Y H:i', |
||
244 | // files time format |
||
245 | 'timeFormat' => 'H:i', |
||
246 | // if true - every folder will be check for children folders, otherwise all folders will be marked as having subfolders |
||
247 | 'checkSubfolders' => true, |
||
248 | // allow to copy from this volume to other ones? |
||
249 | 'copyFrom' => true, |
||
250 | // allow to copy from other volumes to this one? |
||
251 | 'copyTo' => true, |
||
252 | // list of commands disabled on this root |
||
253 | 'disabled' => array(), |
||
254 | // enable file owner, group & mode info, `false` to inactivate "chmod" command. |
||
255 | 'statOwner' => false, |
||
256 | // allow exec chmod of read-only files |
||
257 | 'allowChmodReadOnly' => false, |
||
258 | // regexp or function name to validate new file name |
||
259 | 'acceptedName' => '/^[^\.].*/', //<-- DONT touch this! Use constructor options to overwrite it! |
||
260 | // function/class method to control files permissions |
||
261 | 'accessControl' => null, |
||
262 | // some data required by access control |
||
263 | 'accessControlData' => null, |
||
264 | // default permissions. |
||
265 | 'defaults' => array( |
||
266 | 'read' => true, |
||
267 | 'write' => true, |
||
268 | 'locked' => false, |
||
269 | 'hidden' => false |
||
270 | ), |
||
271 | // files attributes |
||
272 | 'attributes' => array(), |
||
273 | // Allowed archive's mimetypes to create. Leave empty for all available types. |
||
274 | 'archiveMimes' => array(), |
||
275 | // Manual config for archivers. See example below. Leave empty for auto detect |
||
276 | 'archivers' => array(), |
||
277 | // plugin settings |
||
278 | 'plugin' => array(), |
||
279 | // Is support parent directory time stamp update on add|remove|rename item |
||
280 | // Default `null` is auto detection that is LocalFileSystem, FTP or Dropbox are `true` |
||
281 | 'syncChkAsTs' => null, |
||
282 | // Long pooling sync checker function for syncChkAsTs is true |
||
283 | // Calls with args (TARGET DIRCTORY PATH, STAND-BY(sec), OLD TIMESTAMP, VOLUME DRIVER INSTANCE, ELFINDER INSTANCE) |
||
284 | // This function must return the following values. Changed: New Timestamp or Same: Old Timestamp or Error: false |
||
285 | // Default `null` is try use elFinderVolumeLocalFileSystem::localFileSystemInotify() on LocalFileSystem driver |
||
286 | // another driver use elFinder stat() checker |
||
287 | 'syncCheckFunc'=> null, |
||
288 | // Long polling sync stand-by time (sec) |
||
289 | 'plStandby' => 30, |
||
290 | // Sleep time (sec) for elFinder stat() checker (syncChkAsTs is true) |
||
291 | 'tsPlSleep' => 10, |
||
292 | // Sleep time (sec) for elFinder ls() checker (syncChkAsTs is false) |
||
293 | 'lsPlSleep' => 30, |
||
294 | // Client side sync interval minimum (ms) |
||
295 | // Default `null` is auto set to ('tsPlSleep' or 'lsPlSleep') * 1000 |
||
296 | 'syncMinMs' => null, |
||
297 | // required to fix bug on macos |
||
298 | 'utf8fix' => false, |
||
299 | // й ё Й Ё Ø Å |
||
300 | 'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"), |
||
301 | 'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5") |
||
302 | ); |
||
303 | |||
304 | /** |
||
305 | * Defaults permissions |
||
306 | * |
||
307 | * @var array |
||
308 | **/ |
||
309 | protected $defaults = array( |
||
310 | 'read' => true, |
||
311 | 'write' => true, |
||
312 | 'locked' => false, |
||
313 | 'hidden' => false |
||
314 | ); |
||
315 | |||
316 | /** |
||
317 | * Access control function/class |
||
318 | * |
||
319 | * @var mixed |
||
320 | **/ |
||
321 | protected $attributes = array(); |
||
322 | |||
323 | /** |
||
324 | * Access control function/class |
||
325 | * |
||
326 | * @var mixed |
||
327 | **/ |
||
328 | protected $access = null; |
||
329 | |||
330 | /** |
||
331 | * Mime types allowed to upload |
||
332 | * |
||
333 | * @var array |
||
334 | **/ |
||
335 | protected $uploadAllow = array(); |
||
336 | |||
337 | /** |
||
338 | * Mime types denied to upload |
||
339 | * |
||
340 | * @var array |
||
341 | **/ |
||
342 | protected $uploadDeny = array(); |
||
343 | |||
344 | /** |
||
345 | * Order to validate uploadAllow and uploadDeny |
||
346 | * |
||
347 | * @var array |
||
348 | **/ |
||
349 | protected $uploadOrder = array(); |
||
350 | |||
351 | /** |
||
352 | * Maximum allowed upload file size. |
||
353 | * Set as number or string with unit - "10M", "500K", "1G" |
||
354 | * |
||
355 | * @var int|string |
||
356 | **/ |
||
357 | protected $uploadMaxSize = 0; |
||
358 | |||
359 | /** |
||
360 | * Mimetype detect method |
||
361 | * |
||
362 | * @var string |
||
363 | **/ |
||
364 | protected $mimeDetect = 'auto'; |
||
365 | |||
366 | /** |
||
367 | * Flag - mimetypes from externail file was loaded |
||
368 | * |
||
369 | * @var bool |
||
370 | **/ |
||
371 | private static $mimetypesLoaded = false; |
||
372 | |||
373 | /** |
||
374 | * Finfo object for mimeDetect == 'finfo' |
||
375 | * |
||
376 | * @var object |
||
377 | **/ |
||
378 | protected $finfo = null; |
||
379 | |||
380 | /** |
||
381 | * List of disabled client's commands |
||
382 | * |
||
383 | * @var array |
||
384 | **/ |
||
385 | protected $disabled = array(); |
||
386 | |||
387 | /** |
||
388 | * default extensions/mimetypes for mimeDetect == 'internal' |
||
389 | * |
||
390 | * @var array |
||
391 | **/ |
||
392 | protected static $mimetypes = array( |
||
393 | // applications |
||
394 | 'ai' => 'application/postscript', |
||
395 | 'eps' => 'application/postscript', |
||
396 | 'exe' => 'application/x-executable', |
||
397 | 'doc' => 'application/msword', |
||
398 | 'dot' => 'application/msword', |
||
399 | 'xls' => 'application/vnd.ms-excel', |
||
400 | 'xlt' => 'application/vnd.ms-excel', |
||
401 | 'xla' => 'application/vnd.ms-excel', |
||
402 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
403 | 'pps' => 'application/vnd.ms-powerpoint', |
||
404 | 'pdf' => 'application/pdf', |
||
405 | 'xml' => 'application/xml', |
||
406 | 'swf' => 'application/x-shockwave-flash', |
||
407 | 'torrent' => 'application/x-bittorrent', |
||
408 | 'jar' => 'application/x-jar', |
||
409 | // open office (finfo detect as application/zip) |
||
410 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
411 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
412 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
413 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
414 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
415 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
416 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
417 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
418 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
419 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
420 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
421 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
422 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
423 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
424 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
425 | // MS office 2007 (finfo detect as application/zip) |
||
426 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
427 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
428 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
429 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
430 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
431 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
432 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
433 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
434 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
435 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
436 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
437 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
438 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
439 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
440 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
441 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
442 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
443 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
444 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
445 | // archives |
||
446 | 'gz' => 'application/x-gzip', |
||
447 | 'tgz' => 'application/x-gzip', |
||
448 | 'bz' => 'application/x-bzip2', |
||
449 | 'bz2' => 'application/x-bzip2', |
||
450 | 'tbz' => 'application/x-bzip2', |
||
451 | 'xz' => 'application/x-xz', |
||
452 | 'zip' => 'application/zip', |
||
453 | 'rar' => 'application/x-rar', |
||
454 | 'tar' => 'application/x-tar', |
||
455 | '7z' => 'application/x-7z-compressed', |
||
456 | // texts |
||
457 | 'txt' => 'text/plain', |
||
458 | 'php' => 'text/x-php', |
||
459 | 'html' => 'text/html', |
||
460 | 'htm' => 'text/html', |
||
461 | 'js' => 'text/javascript', |
||
462 | 'css' => 'text/css', |
||
463 | 'rtf' => 'text/rtf', |
||
464 | 'rtfd' => 'text/rtfd', |
||
465 | 'py' => 'text/x-python', |
||
466 | 'java' => 'text/x-java-source', |
||
467 | 'rb' => 'text/x-ruby', |
||
468 | 'sh' => 'text/x-shellscript', |
||
469 | 'pl' => 'text/x-perl', |
||
470 | 'xml' => 'text/xml', |
||
471 | 'sql' => 'text/x-sql', |
||
472 | 'c' => 'text/x-csrc', |
||
473 | 'h' => 'text/x-chdr', |
||
474 | 'cpp' => 'text/x-c++src', |
||
475 | 'hh' => 'text/x-c++hdr', |
||
476 | 'log' => 'text/plain', |
||
477 | 'csv' => 'text/x-comma-separated-values', |
||
478 | 'md' => 'text/x-markdown', |
||
479 | 'markdown' => 'text/x-markdown', |
||
480 | // images |
||
481 | 'bmp' => 'image/x-ms-bmp', |
||
482 | 'jpg' => 'image/jpeg', |
||
483 | 'jpeg' => 'image/jpeg', |
||
484 | 'gif' => 'image/gif', |
||
485 | 'png' => 'image/png', |
||
486 | 'tif' => 'image/tiff', |
||
487 | 'tiff' => 'image/tiff', |
||
488 | 'tga' => 'image/x-targa', |
||
489 | 'psd' => 'image/vnd.adobe.photoshop', |
||
490 | 'ai' => 'image/vnd.adobe.photoshop', |
||
491 | 'xbm' => 'image/xbm', |
||
492 | 'pxm' => 'image/pxm', |
||
493 | //audio |
||
494 | 'mp3' => 'audio/mpeg', |
||
495 | 'mid' => 'audio/midi', |
||
496 | 'ogg' => 'audio/ogg', |
||
497 | 'oga' => 'audio/ogg', |
||
498 | 'm4a' => 'audio/x-m4a', |
||
499 | 'wav' => 'audio/wav', |
||
500 | 'wma' => 'audio/x-ms-wma', |
||
501 | // video |
||
502 | 'avi' => 'video/x-msvideo', |
||
503 | 'dv' => 'video/x-dv', |
||
504 | 'mp4' => 'video/mp4', |
||
505 | 'mpeg' => 'video/mpeg', |
||
506 | 'mpg' => 'video/mpeg', |
||
507 | 'mov' => 'video/quicktime', |
||
508 | 'wm' => 'video/x-ms-wmv', |
||
509 | 'flv' => 'video/x-flv', |
||
510 | 'mkv' => 'video/x-matroska', |
||
511 | 'webm' => 'video/webm', |
||
512 | 'ogv' => 'video/ogg', |
||
513 | 'ogm' => 'video/ogg' |
||
514 | ); |
||
515 | |||
516 | /** |
||
517 | * Directory separator - required by client |
||
518 | * |
||
519 | * @var string |
||
520 | **/ |
||
521 | protected $separator = DIRECTORY_SEPARATOR; |
||
522 | |||
523 | /** |
||
524 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...) |
||
525 | * |
||
526 | * @var string |
||
527 | **/ |
||
528 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
529 | |||
530 | /** |
||
531 | * Mimetypes allowed to display |
||
532 | * |
||
533 | * @var array |
||
534 | **/ |
||
535 | protected $onlyMimes = array(); |
||
536 | |||
537 | /** |
||
538 | * Store files moved or overwrited files info |
||
539 | * |
||
540 | * @var array |
||
541 | **/ |
||
542 | protected $removed = array(); |
||
543 | |||
544 | /** |
||
545 | * Cache storage |
||
546 | * |
||
547 | * @var array |
||
548 | **/ |
||
549 | protected $cache = array(); |
||
550 | |||
551 | /** |
||
552 | * Cache by folders |
||
553 | * |
||
554 | * @var array |
||
555 | **/ |
||
556 | protected $dirsCache = array(); |
||
557 | |||
558 | /** |
||
559 | * Cache for subdirsCE() |
||
560 | * |
||
561 | * @var array |
||
562 | */ |
||
563 | protected $subdirsCache = array(); |
||
564 | |||
565 | /** |
||
566 | * Reference of $_SESSION[elFinder::$sessionCacheKey][$this->id] |
||
567 | * |
||
568 | * @var array |
||
569 | */ |
||
570 | protected $sessionCache; |
||
571 | |||
572 | /*********************************************************************/ |
||
573 | /* INITIALIZATION */ |
||
574 | /*********************************************************************/ |
||
575 | |||
576 | /** |
||
577 | * Prepare driver before mount volume. |
||
578 | * Return true if volume is ready. |
||
579 | * |
||
580 | * @return bool |
||
581 | * @author Dmitry (dio) Levashov |
||
582 | **/ |
||
583 | protected function init() { |
||
586 | |||
587 | /** |
||
588 | * Configure after successfull mount. |
||
589 | * By default set thumbnails path and image manipulation library. |
||
590 | * |
||
591 | * @return void |
||
592 | * @author Dmitry (dio) Levashov |
||
593 | **/ |
||
594 | protected function configure() { |
||
635 | |||
636 | |||
637 | /*********************************************************************/ |
||
638 | /* PUBLIC API */ |
||
639 | /*********************************************************************/ |
||
640 | |||
641 | /** |
||
642 | * Return driver id. Used as a part of volume id. |
||
643 | * |
||
644 | * @return string |
||
645 | * @author Dmitry (dio) Levashov |
||
646 | **/ |
||
647 | public function driverId() { |
||
650 | |||
651 | /** |
||
652 | * Return volume id |
||
653 | * |
||
654 | * @return string |
||
655 | * @author Dmitry (dio) Levashov |
||
656 | **/ |
||
657 | public function id() { |
||
660 | |||
661 | /** |
||
662 | * Return debug info for client |
||
663 | * |
||
664 | * @return array |
||
665 | * @author Dmitry (dio) Levashov |
||
666 | **/ |
||
667 | public function debug() { |
||
675 | |||
676 | /** |
||
677 | * chmod a file or folder |
||
678 | * |
||
679 | * @param string $hash file or folder hash to chmod |
||
680 | * @param string $mode octal string representing new permissions |
||
681 | * @return array|false |
||
682 | * @author David Bartle |
||
683 | **/ |
||
684 | public function chmod($hash, $mode) { |
||
721 | |||
722 | /** |
||
723 | * stat a file or folder for elFinder cmd exec |
||
724 | * |
||
725 | * @param string $hash file or folder hash to chmod |
||
726 | * @return array |
||
727 | * @author Naoki Sawada |
||
728 | **/ |
||
729 | public function fstat($hash) { |
||
733 | |||
734 | |||
735 | public function clearstatcache() { |
||
739 | |||
740 | /** |
||
741 | * "Mount" volume. |
||
742 | * Return true if volume available for read or write, |
||
743 | * false - otherwise |
||
744 | * |
||
745 | * @return bool |
||
746 | * @author Dmitry (dio) Levashov |
||
747 | * @author Alexey Sukhotin |
||
748 | **/ |
||
749 | public function mount(array $opts) { |
||
1015 | |||
1016 | /** |
||
1017 | * Some "unmount" stuffs - may be required by virtual fs |
||
1018 | * |
||
1019 | * @return void |
||
1020 | * @author Dmitry (dio) Levashov |
||
1021 | **/ |
||
1022 | public function umount() { |
||
1024 | |||
1025 | /** |
||
1026 | * Return error message from last failed action |
||
1027 | * |
||
1028 | * @return array |
||
1029 | * @author Dmitry (dio) Levashov |
||
1030 | **/ |
||
1031 | public function error() { |
||
1034 | |||
1035 | /** |
||
1036 | * Return is uploadable that given file name |
||
1037 | * |
||
1038 | * @param string $name file name |
||
1039 | * @param bool $allowUnknown |
||
1040 | * @return bool |
||
1041 | * @author Naoki Sawada |
||
1042 | **/ |
||
1043 | public function isUploadableByName($name, $allowUnknown = true) { |
||
1047 | |||
1048 | /** |
||
1049 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
1050 | * |
||
1051 | * @return array |
||
1052 | * @author Naoki Sawada |
||
1053 | */ |
||
1054 | public function getMimeTable() { |
||
1057 | |||
1058 | /** |
||
1059 | * Set mimetypes allowed to display to client |
||
1060 | * |
||
1061 | * @param array $mimes |
||
1062 | * @return void |
||
1063 | * @author Dmitry (dio) Levashov |
||
1064 | **/ |
||
1065 | public function setMimesFilter($mimes) { |
||
1070 | |||
1071 | /** |
||
1072 | * Return root folder hash |
||
1073 | * |
||
1074 | * @return string |
||
1075 | * @author Dmitry (dio) Levashov |
||
1076 | **/ |
||
1077 | public function root() { |
||
1080 | |||
1081 | /** |
||
1082 | * Return target path hash |
||
1083 | * |
||
1084 | * @param string $path |
||
1085 | * @param string $name |
||
1086 | * @author Naoki Sawada |
||
1087 | */ |
||
1088 | public function getHash($path, $name = '') { |
||
1094 | |||
1095 | /** |
||
1096 | * Return root or startPath hash |
||
1097 | * |
||
1098 | * @return string |
||
1099 | * @author Dmitry (dio) Levashov |
||
1100 | **/ |
||
1101 | public function defaultPath() { |
||
1104 | |||
1105 | /** |
||
1106 | * Return volume options required by client: |
||
1107 | * |
||
1108 | * @return array |
||
1109 | * @author Dmitry (dio) Levashov |
||
1110 | **/ |
||
1111 | public function options($hash) { |
||
1140 | |||
1141 | /** |
||
1142 | * Get option value of this volume |
||
1143 | * |
||
1144 | * @param string $name target option name |
||
1145 | * @return NULL|mixed target option value |
||
1146 | * @author Naoki Sawada |
||
1147 | */ |
||
1148 | public function getOption($name) { |
||
1151 | |||
1152 | /** |
||
1153 | * Get plugin values of this options |
||
1154 | * |
||
1155 | * @param string $name Plugin name |
||
1156 | * @return NULL|array Plugin values |
||
1157 | * @author Naoki Sawada |
||
1158 | */ |
||
1159 | public function getOptionsPlugin($name = '') { |
||
1166 | |||
1167 | /** |
||
1168 | * Return true if command disabled in options |
||
1169 | * |
||
1170 | * @param string $cmd command name |
||
1171 | * @return bool |
||
1172 | * @author Dmitry (dio) Levashov |
||
1173 | **/ |
||
1174 | public function commandDisabled($cmd) { |
||
1177 | |||
1178 | /** |
||
1179 | * Return true if mime is required mimes list |
||
1180 | * |
||
1181 | * @param string $mime mime type to check |
||
1182 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
1183 | * @param bool|null $empty what to return on empty list |
||
1184 | * @return bool|null |
||
1185 | * @author Dmitry (dio) Levashov |
||
1186 | * @author Troex Nevelin |
||
1187 | **/ |
||
1188 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
1199 | |||
1200 | /** |
||
1201 | * Return true if voume is readable. |
||
1202 | * |
||
1203 | * @return bool |
||
1204 | * @author Dmitry (dio) Levashov |
||
1205 | **/ |
||
1206 | public function isReadable() { |
||
1210 | |||
1211 | /** |
||
1212 | * Return true if copy from this volume allowed |
||
1213 | * |
||
1214 | * @return bool |
||
1215 | * @author Dmitry (dio) Levashov |
||
1216 | **/ |
||
1217 | public function copyFromAllowed() { |
||
1220 | |||
1221 | /** |
||
1222 | * Return file path related to root with convert encoging |
||
1223 | * |
||
1224 | * @param string $hash file hash |
||
1225 | * @return string |
||
1226 | * @author Dmitry (dio) Levashov |
||
1227 | **/ |
||
1228 | public function path($hash) { |
||
1231 | |||
1232 | /** |
||
1233 | * Return file real path if file exists |
||
1234 | * |
||
1235 | * @param string $hash file hash |
||
1236 | * @return string |
||
1237 | * @author Dmitry (dio) Levashov |
||
1238 | **/ |
||
1239 | public function realpath($hash) { |
||
1243 | |||
1244 | /** |
||
1245 | * Return list of moved/overwrited files |
||
1246 | * |
||
1247 | * @return array |
||
1248 | * @author Dmitry (dio) Levashov |
||
1249 | **/ |
||
1250 | public function removed() { |
||
1253 | |||
1254 | /** |
||
1255 | * Clean removed files list |
||
1256 | * |
||
1257 | * @return void |
||
1258 | * @author Dmitry (dio) Levashov |
||
1259 | **/ |
||
1260 | public function resetRemoved() { |
||
1263 | |||
1264 | /** |
||
1265 | * Return file/dir hash or first founded child hash with required attr == $val |
||
1266 | * |
||
1267 | * @param string $hash file hash |
||
1268 | * @param string $attr attribute name |
||
1269 | * @param bool $val attribute value |
||
1270 | * @return string|false |
||
1271 | * @author Dmitry (dio) Levashov |
||
1272 | **/ |
||
1273 | public function closest($hash, $attr, $val) { |
||
1276 | |||
1277 | /** |
||
1278 | * Return file info or false on error |
||
1279 | * |
||
1280 | * @param string $hash file hash |
||
1281 | * @param bool $realpath add realpath field to file info |
||
1282 | * @return array|false |
||
1283 | * @author Dmitry (dio) Levashov |
||
1284 | **/ |
||
1285 | public function file($hash) { |
||
1301 | |||
1302 | /** |
||
1303 | * Return folder info |
||
1304 | * |
||
1305 | * @param string $hash folder hash |
||
1306 | * @param bool $hidden return hidden file info |
||
1307 | * @return array|false |
||
1308 | * @author Dmitry (dio) Levashov |
||
1309 | **/ |
||
1310 | public function dir($hash, $resolveLink=false) { |
||
1323 | |||
1324 | /** |
||
1325 | * Return directory content or false on error |
||
1326 | * |
||
1327 | * @param string $hash file hash |
||
1328 | * @return array|false |
||
1329 | * @author Dmitry (dio) Levashov |
||
1330 | **/ |
||
1331 | public function scandir($hash) { |
||
1340 | |||
1341 | /** |
||
1342 | * Return dir files names list |
||
1343 | * |
||
1344 | * @param string $hash file hash |
||
1345 | * @return array |
||
1346 | * @author Dmitry (dio) Levashov |
||
1347 | **/ |
||
1348 | public function ls($hash) { |
||
1364 | |||
1365 | /** |
||
1366 | * Return subfolders for required folder or false on error |
||
1367 | * |
||
1368 | * @param string $hash folder hash or empty string to get tree from root folder |
||
1369 | * @param int $deep subdir deep |
||
1370 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
1371 | * @return array|false |
||
1372 | * @author Dmitry (dio) Levashov |
||
1373 | **/ |
||
1374 | public function tree($hash='', $deep=0, $exclude='') { |
||
1385 | |||
1386 | /** |
||
1387 | * Return part of dirs tree from required dir up to root dir |
||
1388 | * |
||
1389 | * @param string $hash directory hash |
||
1390 | * @param bool|null $lineal only lineal parents |
||
1391 | * @return array |
||
1392 | * @author Dmitry (dio) Levashov |
||
1393 | **/ |
||
1394 | public function parents($hash, $lineal = false) { |
||
1421 | |||
1422 | /** |
||
1423 | * Create thumbnail for required file and return its name of false on failed |
||
1424 | * |
||
1425 | * @return string|false |
||
1426 | * @author Dmitry (dio) Levashov |
||
1427 | **/ |
||
1428 | public function tmb($hash) { |
||
1437 | |||
1438 | /** |
||
1439 | * Return file size / total directory size |
||
1440 | * |
||
1441 | * @param string file hash |
||
1442 | * @return int |
||
1443 | * @author Dmitry (dio) Levashov |
||
1444 | **/ |
||
1445 | public function size($hash) { |
||
1448 | |||
1449 | /** |
||
1450 | * Open file for reading and return file pointer |
||
1451 | * |
||
1452 | * @param string file hash |
||
1453 | * @return Resource |
||
1454 | * @author Dmitry (dio) Levashov |
||
1455 | **/ |
||
1456 | public function open($hash) { |
||
1464 | |||
1465 | /** |
||
1466 | * Close file pointer |
||
1467 | * |
||
1468 | * @param Resource $fp file pointer |
||
1469 | * @param string $hash file hash |
||
1470 | * @return void |
||
1471 | * @author Dmitry (dio) Levashov |
||
1472 | **/ |
||
1473 | public function close($fp, $hash) { |
||
1476 | |||
1477 | /** |
||
1478 | * Create directory and return dir info |
||
1479 | * |
||
1480 | * @param string $dsthash destination directory hash |
||
1481 | * @param string $name directory name |
||
1482 | * @return array|false |
||
1483 | * @author Dmitry (dio) Levashov |
||
1484 | **/ |
||
1485 | public function mkdir($dsthash, $name) { |
||
1512 | |||
1513 | /** |
||
1514 | * Create empty file and return its info |
||
1515 | * |
||
1516 | * @param string $dst destination directory |
||
1517 | * @param string $name file name |
||
1518 | * @return array|false |
||
1519 | * @author Dmitry (dio) Levashov |
||
1520 | **/ |
||
1521 | public function mkfile($dst, $name) { |
||
1547 | |||
1548 | /** |
||
1549 | * Rename file and return file info |
||
1550 | * |
||
1551 | * @param string $hash file hash |
||
1552 | * @param string $name new file name |
||
1553 | * @return array|false |
||
1554 | * @author Dmitry (dio) Levashov |
||
1555 | **/ |
||
1556 | public function rename($hash, $name) { |
||
1602 | |||
1603 | /** |
||
1604 | * Create file copy with suffix "copy number" and return its info |
||
1605 | * |
||
1606 | * @param string $hash file hash |
||
1607 | * @param string $suffix suffix to add to file name |
||
1608 | * @return array|false |
||
1609 | * @author Dmitry (dio) Levashov |
||
1610 | **/ |
||
1611 | public function duplicate($hash, $suffix='copy') { |
||
1632 | |||
1633 | /** |
||
1634 | * Save uploaded file. |
||
1635 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
1636 | * |
||
1637 | * @param Resource $fp file pointer |
||
1638 | * @param string $dst destination folder hash |
||
1639 | * @param string $src file name |
||
1640 | * @param string $tmpname file tmp name - required to detect mime type |
||
1641 | * @return array|false |
||
1642 | * @author Dmitry (dio) Levashov |
||
1643 | **/ |
||
1644 | public function upload($fp, $dst, $name, $tmpname) { |
||
1720 | |||
1721 | /** |
||
1722 | * Paste files |
||
1723 | * |
||
1724 | * @param Object $volume source volume |
||
1725 | * @param string $source file hash |
||
1726 | * @param string $dst destination dir hash |
||
1727 | * @param bool $rmSrc remove source after copy? |
||
1728 | * @return array|false |
||
1729 | * @author Dmitry (dio) Levashov |
||
1730 | **/ |
||
1731 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
1819 | |||
1820 | /** |
||
1821 | * Return file contents |
||
1822 | * |
||
1823 | * @param string $hash file hash |
||
1824 | * @return string|false |
||
1825 | * @author Dmitry (dio) Levashov |
||
1826 | **/ |
||
1827 | public function getContents($hash) { |
||
1844 | |||
1845 | /** |
||
1846 | * Put content in text file and return file info. |
||
1847 | * |
||
1848 | * @param string $hash file hash |
||
1849 | * @param string $content new file content |
||
1850 | * @return array |
||
1851 | * @author Dmitry (dio) Levashov |
||
1852 | **/ |
||
1853 | public function putContents($hash, $content) { |
||
1888 | |||
1889 | /** |
||
1890 | * Extract files from archive |
||
1891 | * |
||
1892 | * @param string $hash archive hash |
||
1893 | * @return array|bool |
||
1894 | * @author Dmitry (dio) Levashov, |
||
1895 | * @author Alexey Sukhotin |
||
1896 | **/ |
||
1897 | public function extract($hash, $makedir = null) { |
||
1936 | |||
1937 | /** |
||
1938 | * Add files to archive |
||
1939 | * |
||
1940 | * @return void |
||
1941 | **/ |
||
1942 | public function archive($hashes, $mime, $name = '') { |
||
1986 | |||
1987 | /** |
||
1988 | * Resize image |
||
1989 | * |
||
1990 | * @param string $hash image file |
||
1991 | * @param int $width new width |
||
1992 | * @param int $height new height |
||
1993 | * @param int $x X start poistion for crop |
||
1994 | * @param int $y Y start poistion for crop |
||
1995 | * @param string $mode action how to mainpulate image |
||
1996 | * @param string $bg background color |
||
1997 | * @param int $degree rotete degree |
||
1998 | * @param int $jpgQuality JEPG quality (1-100) |
||
1999 | * @return array|false |
||
2000 | * @author Dmitry (dio) Levashov |
||
2001 | * @author Alexey Sukhotin |
||
2002 | * @author nao-pon |
||
2003 | * @author Troex Nevelin |
||
2004 | **/ |
||
2005 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0, $jpgQuality = null) { |
||
2092 | |||
2093 | /** |
||
2094 | * Remove file/dir |
||
2095 | * |
||
2096 | * @param string $hash file hash |
||
2097 | * @return bool |
||
2098 | * @author Dmitry (dio) Levashov |
||
2099 | **/ |
||
2100 | public function rm($hash) { |
||
2105 | |||
2106 | /** |
||
2107 | * Search files |
||
2108 | * |
||
2109 | * @param string $q search string |
||
2110 | * @param array $mimes |
||
2111 | * @return array |
||
2112 | * @author Dmitry (dio) Levashov |
||
2113 | **/ |
||
2114 | public function search($q, $mimes, $hash = null) { |
||
2133 | |||
2134 | /** |
||
2135 | * Return image dimensions |
||
2136 | * |
||
2137 | * @param string $hash file hash |
||
2138 | * @return array |
||
2139 | * @author Dmitry (dio) Levashov |
||
2140 | **/ |
||
2141 | public function dimensions($hash) { |
||
2148 | |||
2149 | /** |
||
2150 | * Return content URL (for netmout volume driver) |
||
2151 | * If file.url == 1 requests from JavaScript client with XHR |
||
2152 | * |
||
2153 | * @param string $hash file hash |
||
2154 | * @param array $options options array |
||
2155 | * @return boolean|string |
||
2156 | * @author Naoki Sawada |
||
2157 | */ |
||
2158 | public function getContentUrl($hash, $options = array()) { |
||
2164 | |||
2165 | /** |
||
2166 | * Return temp path |
||
2167 | * |
||
2168 | * @return string |
||
2169 | * @author Naoki Sawada |
||
2170 | */ |
||
2171 | public function getTempPath() { |
||
2187 | |||
2188 | /** |
||
2189 | * (Make &) Get upload taget dirctory hash |
||
2190 | * |
||
2191 | * @param string $baseTargetHash |
||
2192 | * @param string $path |
||
2193 | * @param array $result |
||
2194 | * @return boolean|string |
||
2195 | * @author Naoki Sawada |
||
2196 | */ |
||
2197 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
2224 | |||
2225 | /** |
||
2226 | * Return this uploadMaxSize value |
||
2227 | * |
||
2228 | * @return integer |
||
2229 | * @author Naoki Sawada |
||
2230 | */ |
||
2231 | public function getUploadMaxSize() { |
||
2234 | |||
2235 | /** |
||
2236 | * Save error message |
||
2237 | * |
||
2238 | * @param array error |
||
2239 | * @return false |
||
2240 | * @author Dmitry(dio) Levashov |
||
2241 | **/ |
||
2242 | protected function setError($error) { |
||
2257 | |||
2258 | /*********************************************************************/ |
||
2259 | /* FS API */ |
||
2260 | /*********************************************************************/ |
||
2261 | |||
2262 | /***************** server encoding support *******************/ |
||
2263 | |||
2264 | /** |
||
2265 | * Return parent directory path (with convert encording) |
||
2266 | * |
||
2267 | * @param string $path file path |
||
2268 | * @return string |
||
2269 | * @author Naoki Sawada |
||
2270 | **/ |
||
2271 | protected function dirnameCE($path) { |
||
2274 | |||
2275 | /** |
||
2276 | * Return file name (with convert encording) |
||
2277 | * |
||
2278 | * @param string $path file path |
||
2279 | * @return string |
||
2280 | * @author Naoki Sawada |
||
2281 | **/ |
||
2282 | protected function basenameCE($path) { |
||
2285 | |||
2286 | /** |
||
2287 | * Join dir name and file name and return full path. (with convert encording) |
||
2288 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
2289 | * |
||
2290 | * @param string $dir dir path |
||
2291 | * @param string $name file name |
||
2292 | * @return string |
||
2293 | * @author Naoki Sawada |
||
2294 | **/ |
||
2295 | protected function joinPathCE($dir, $name) { |
||
2298 | |||
2299 | /** |
||
2300 | * Return normalized path (with convert encording) |
||
2301 | * |
||
2302 | * @param string $path file path |
||
2303 | * @return string |
||
2304 | * @author Naoki Sawada |
||
2305 | **/ |
||
2306 | protected function normpathCE($path) { |
||
2309 | |||
2310 | /** |
||
2311 | * Return file path related to root dir (with convert encording) |
||
2312 | * |
||
2313 | * @param string $path file path |
||
2314 | * @return string |
||
2315 | * @author Naoki Sawada |
||
2316 | **/ |
||
2317 | protected function relpathCE($path) { |
||
2320 | |||
2321 | /** |
||
2322 | * Convert path related to root dir into real path (with convert encording) |
||
2323 | * |
||
2324 | * @param string $path rel file path |
||
2325 | * @return string |
||
2326 | * @author Naoki Sawada |
||
2327 | **/ |
||
2328 | protected function abspathCE($path) { |
||
2331 | |||
2332 | /** |
||
2333 | * Return true if $path is children of $parent (with convert encording) |
||
2334 | * |
||
2335 | * @param string $path path to check |
||
2336 | * @param string $parent parent path |
||
2337 | * @return bool |
||
2338 | * @author Naoki Sawada |
||
2339 | **/ |
||
2340 | protected function inpathCE($path, $parent) { |
||
2343 | |||
2344 | /** |
||
2345 | * Open file and return file pointer (with convert encording) |
||
2346 | * |
||
2347 | * @param string $path file path |
||
2348 | * @param bool $write open file for writing |
||
2349 | * @return resource|false |
||
2350 | * @author Naoki Sawada |
||
2351 | **/ |
||
2352 | protected function fopenCE($path, $mode='rb') { |
||
2355 | |||
2356 | /** |
||
2357 | * Close opened file (with convert encording) |
||
2358 | * |
||
2359 | * @param resource $fp file pointer |
||
2360 | * @param string $path file path |
||
2361 | * @return bool |
||
2362 | * @author Naoki Sawada |
||
2363 | **/ |
||
2364 | protected function fcloseCE($fp, $path='') { |
||
2367 | |||
2368 | /** |
||
2369 | * Create new file and write into it from file pointer. (with convert encording) |
||
2370 | * Return new file path or false on error. |
||
2371 | * |
||
2372 | * @param resource $fp file pointer |
||
2373 | * @param string $dir target dir path |
||
2374 | * @param string $name file name |
||
2375 | * @param array $stat file stat (required by some virtual fs) |
||
2376 | * @return bool|string |
||
2377 | * @author Naoki Sawada |
||
2378 | **/ |
||
2379 | protected function saveCE($fp, $dir, $name, $stat) { |
||
2382 | |||
2383 | /** |
||
2384 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
2385 | * |
||
2386 | * @param string $path dir path |
||
2387 | * @return bool |
||
2388 | * @author Naoki Sawada |
||
2389 | **/ |
||
2390 | protected function subdirsCE($path) { |
||
2396 | |||
2397 | /** |
||
2398 | * Return files list in directory (with convert encording) |
||
2399 | * |
||
2400 | * @param string $path dir path |
||
2401 | * @return array |
||
2402 | * @author Naoki Sawada |
||
2403 | **/ |
||
2404 | protected function scandirCE($path) { |
||
2407 | |||
2408 | /** |
||
2409 | * Create symlink (with convert encording) |
||
2410 | * |
||
2411 | * @param string $source file to link to |
||
2412 | * @param string $targetDir folder to create link in |
||
2413 | * @param string $name symlink name |
||
2414 | * @return bool |
||
2415 | * @author Naoki Sawada |
||
2416 | **/ |
||
2417 | protected function symlinkCE($source, $targetDir, $name) { |
||
2420 | |||
2421 | /***************** paths *******************/ |
||
2422 | |||
2423 | /** |
||
2424 | * Encode path into hash |
||
2425 | * |
||
2426 | * @param string file path |
||
2427 | * @return string |
||
2428 | * @author Dmitry (dio) Levashov |
||
2429 | * @author Troex Nevelin |
||
2430 | **/ |
||
2431 | protected function encode($path) { |
||
2452 | |||
2453 | /** |
||
2454 | * Decode path from hash |
||
2455 | * |
||
2456 | * @param string file hash |
||
2457 | * @return string |
||
2458 | * @author Dmitry (dio) Levashov |
||
2459 | * @author Troex Nevelin |
||
2460 | **/ |
||
2461 | protected function decode($hash) { |
||
2473 | |||
2474 | /** |
||
2475 | * Return crypted path |
||
2476 | * Not implemented |
||
2477 | * |
||
2478 | * @param string path |
||
2479 | * @return mixed |
||
2480 | * @author Dmitry (dio) Levashov |
||
2481 | **/ |
||
2482 | protected function crypt($path) { |
||
2485 | |||
2486 | /** |
||
2487 | * Return uncrypted path |
||
2488 | * Not implemented |
||
2489 | * |
||
2490 | * @param mixed hash |
||
2491 | * @return mixed |
||
2492 | * @author Dmitry (dio) Levashov |
||
2493 | **/ |
||
2494 | protected function uncrypt($hash) { |
||
2497 | |||
2498 | /** |
||
2499 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
2500 | * |
||
2501 | * @param string $name file name |
||
2502 | * @return bool |
||
2503 | * @author Dmitry (dio) Levashov |
||
2504 | **/ |
||
2505 | protected function nameAccepted($name) { |
||
2520 | |||
2521 | /** |
||
2522 | * Return new unique name based on file name and suffix |
||
2523 | * |
||
2524 | * @param string $path file path |
||
2525 | * @param string $suffix suffix append to name |
||
2526 | * @return string |
||
2527 | * @author Dmitry (dio) Levashov |
||
2528 | **/ |
||
2529 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum = true, $start = 1) { |
||
2557 | |||
2558 | /** |
||
2559 | * Converts character encoding from UTF-8 to server's one |
||
2560 | * |
||
2561 | * @param mixed $var target string or array var |
||
2562 | * @param bool $restoreLocale do retore global locale, default is false |
||
2563 | * @param string $unknown replaces character for unknown |
||
2564 | * @return mixed |
||
2565 | * @author Naoki Sawada |
||
2566 | */ |
||
2567 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
2570 | |||
2571 | /** |
||
2572 | * Converts character encoding from server's one to UTF-8 |
||
2573 | * |
||
2574 | * @param mixed $var target string or array var |
||
2575 | * @param bool $restoreLocale do retore global locale, default is true |
||
2576 | * @param string $unknown replaces character for unknown |
||
2577 | * @return mixed |
||
2578 | * @author Naoki Sawada |
||
2579 | */ |
||
2580 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
2583 | |||
2584 | /** |
||
2585 | * Converts character encoding (base function) |
||
2586 | * |
||
2587 | * @param mixed $var target string or array var |
||
2588 | * @param string $from from character encoding |
||
2589 | * @param string $to to character encoding |
||
2590 | * @param string $locale local locale |
||
2591 | * @param string $unknown replaces character for unknown |
||
2592 | * @return mixed |
||
2593 | */ |
||
2594 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
2623 | |||
2624 | /*********************** util mainly for inheritance class *********************/ |
||
2625 | |||
2626 | /** |
||
2627 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
2628 | * When needing the unique file to a path, give $path to parameter. |
||
2629 | * |
||
2630 | * @param string $path for get unique file to a path |
||
2631 | * @return string|false |
||
2632 | * @author Naoki Sawada |
||
2633 | */ |
||
2634 | protected function getTempFile($path = '') { |
||
2660 | |||
2661 | /** |
||
2662 | * File path of local server side work file path |
||
2663 | * |
||
2664 | * @param string $path path need convert encoding to server encoding |
||
2665 | * @return string |
||
2666 | * @author Naoki Sawada |
||
2667 | */ |
||
2668 | protected function getWorkFile($path) { |
||
2683 | |||
2684 | /** |
||
2685 | * Get image size array with `dimensions` |
||
2686 | * |
||
2687 | * @param string $path path need convert encoding to server encoding |
||
2688 | * @param string $mime file mime type |
||
2689 | * @return array|false |
||
2690 | */ |
||
2691 | public function getImageSize($path, $mime = '') { |
||
2703 | |||
2704 | /** |
||
2705 | * Delete dirctory trees |
||
2706 | * |
||
2707 | * @param string $localpath path need convert encoding to server encoding |
||
2708 | * @return boolean |
||
2709 | * @author Naoki Sawada |
||
2710 | */ |
||
2711 | protected function delTree($localpath) { |
||
2720 | |||
2721 | /*********************** file stat *********************/ |
||
2722 | |||
2723 | /** |
||
2724 | * Check file attribute |
||
2725 | * |
||
2726 | * @param string $path file path |
||
2727 | * @param string $name attribute name (read|write|locked|hidden) |
||
2728 | * @param bool $val attribute value returned by file system |
||
2729 | * @param bool $isDir path is directory (true: directory, false: file) |
||
2730 | * @return bool |
||
2731 | * @author Dmitry (dio) Levashov |
||
2732 | **/ |
||
2733 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
2767 | |||
2768 | /** |
||
2769 | * Return true if file with given name can be created in given folder. |
||
2770 | * |
||
2771 | * @param string $dir parent dir path |
||
2772 | * @param string $name new file name |
||
2773 | * @return bool |
||
2774 | * @author Dmitry (dio) Levashov |
||
2775 | **/ |
||
2776 | protected function allowCreate($dir, $name, $isDir = null) { |
||
2799 | |||
2800 | /** |
||
2801 | * Return true if file MIME type can save with check uploadOrder config. |
||
2802 | * |
||
2803 | * @param string $mime |
||
2804 | * @return boolean |
||
2805 | */ |
||
2806 | protected function allowPutMime($mime) { |
||
2824 | |||
2825 | /** |
||
2826 | * Return fileinfo |
||
2827 | * |
||
2828 | * @param string $path file cache |
||
2829 | * @return array |
||
2830 | * @author Dmitry (dio) Levashov |
||
2831 | **/ |
||
2832 | protected function stat($path) { |
||
2860 | |||
2861 | /** |
||
2862 | * Put file stat in cache and return it |
||
2863 | * |
||
2864 | * @param string $path file path |
||
2865 | * @param array $stat file stat |
||
2866 | * @return array |
||
2867 | * @author Dmitry (dio) Levashov |
||
2868 | **/ |
||
2869 | protected function updateCache($path, $stat) { |
||
3012 | |||
3013 | /** |
||
3014 | * Get stat for folder content and put in cache |
||
3015 | * |
||
3016 | * @param string $path |
||
3017 | * @return void |
||
3018 | * @author Dmitry (dio) Levashov |
||
3019 | **/ |
||
3020 | protected function cacheDir($path) { |
||
3033 | |||
3034 | /** |
||
3035 | * Clean cache |
||
3036 | * |
||
3037 | * @return void |
||
3038 | * @author Dmitry (dio) Levashov |
||
3039 | **/ |
||
3040 | protected function clearcache() { |
||
3044 | |||
3045 | /** |
||
3046 | * Return file mimetype |
||
3047 | * |
||
3048 | * @param string $path file path |
||
3049 | * @return string |
||
3050 | * @author Dmitry (dio) Levashov |
||
3051 | **/ |
||
3052 | protected function mimetype($path, $name = '') { |
||
3097 | |||
3098 | /** |
||
3099 | * Detect file mimetype using "internal" method |
||
3100 | * |
||
3101 | * @param string $path file path |
||
3102 | * @return string |
||
3103 | * @author Dmitry (dio) Levashov |
||
3104 | **/ |
||
3105 | static protected function mimetypeInternalDetect($path) { |
||
3128 | |||
3129 | /** |
||
3130 | * Return file/total directory size |
||
3131 | * |
||
3132 | * @param string $path file path |
||
3133 | * @return int |
||
3134 | * @author Dmitry (dio) Levashov |
||
3135 | **/ |
||
3136 | protected function countSize($path) { |
||
3161 | |||
3162 | /** |
||
3163 | * Return true if all mimes is directory or files |
||
3164 | * |
||
3165 | * @param string $mime1 mimetype |
||
3166 | * @param string $mime2 mimetype |
||
3167 | * @return bool |
||
3168 | * @author Dmitry (dio) Levashov |
||
3169 | **/ |
||
3170 | protected function isSameType($mime1, $mime2) { |
||
3173 | |||
3174 | /** |
||
3175 | * If file has required attr == $val - return file path, |
||
3176 | * If dir has child with has required attr == $val - return child path |
||
3177 | * |
||
3178 | * @param string $path file path |
||
3179 | * @param string $attr attribute name |
||
3180 | * @param bool $val attribute value |
||
3181 | * @return string|false |
||
3182 | * @author Dmitry (dio) Levashov |
||
3183 | **/ |
||
3184 | protected function closestByAttr($path, $attr, $val) { |
||
3201 | |||
3202 | /** |
||
3203 | * Return first found children with required attr == $val |
||
3204 | * |
||
3205 | * @param string $path file path |
||
3206 | * @param string $attr attribute name |
||
3207 | * @param bool $val attribute value |
||
3208 | * @return string|false |
||
3209 | * @author Dmitry (dio) Levashov |
||
3210 | **/ |
||
3211 | protected function childsByAttr($path, $attr, $val) { |
||
3219 | |||
3220 | protected function isMyReload($target = '', $ARGtarget = '') { |
||
3239 | |||
3240 | /***************** get content *******************/ |
||
3241 | |||
3242 | /** |
||
3243 | * Return required dir's files info. |
||
3244 | * If onlyMimes is set - return only dirs and files of required mimes |
||
3245 | * |
||
3246 | * @param string $path dir path |
||
3247 | * @return array |
||
3248 | * @author Dmitry (dio) Levashov |
||
3249 | **/ |
||
3250 | protected function getScandir($path) { |
||
3263 | |||
3264 | |||
3265 | /** |
||
3266 | * Return subdirs tree |
||
3267 | * |
||
3268 | * @param string $path parent dir path |
||
3269 | * @param int $deep tree deep |
||
3270 | * @return array |
||
3271 | * @author Dmitry (dio) Levashov |
||
3272 | **/ |
||
3273 | protected function gettree($path, $deep, $exclude='') { |
||
3291 | |||
3292 | /** |
||
3293 | * Recursive files search |
||
3294 | * |
||
3295 | * @param string $path dir path |
||
3296 | * @param string $q search string |
||
3297 | * @param array $mimes |
||
3298 | * @return array |
||
3299 | * @author Dmitry (dio) Levashov |
||
3300 | **/ |
||
3301 | protected function doSearch($path, $q, $mimes) { |
||
3337 | |||
3338 | /********************** manuipulations ******************/ |
||
3339 | |||
3340 | /** |
||
3341 | * Copy file/recursive copy dir only in current volume. |
||
3342 | * Return new file path or false. |
||
3343 | * |
||
3344 | * @param string $src source path |
||
3345 | * @param string $dst destination dir path |
||
3346 | * @param string $name new file name (optionaly) |
||
3347 | * @return string|false |
||
3348 | * @author Dmitry (dio) Levashov |
||
3349 | **/ |
||
3350 | protected function copy($src, $dst, $name) { |
||
3392 | |||
3393 | /** |
||
3394 | * Move file |
||
3395 | * Return new file path or false. |
||
3396 | * |
||
3397 | * @param string $src source path |
||
3398 | * @param string $dst destination dir path |
||
3399 | * @param string $name new file name |
||
3400 | * @return string|false |
||
3401 | * @author Dmitry (dio) Levashov |
||
3402 | **/ |
||
3403 | protected function move($src, $dst, $name) { |
||
3417 | |||
3418 | /** |
||
3419 | * Copy file from another volume. |
||
3420 | * Return new file path or false. |
||
3421 | * |
||
3422 | * @param Object $volume source volume |
||
3423 | * @param string $src source file hash |
||
3424 | * @param string $destination destination dir path |
||
3425 | * @param string $name file name |
||
3426 | * @return string|false |
||
3427 | * @author Dmitry (dio) Levashov |
||
3428 | **/ |
||
3429 | protected function copyFrom($volume, $src, $destination, $name) { |
||
3491 | |||
3492 | /** |
||
3493 | * Remove file/ recursive remove dir |
||
3494 | * |
||
3495 | * @param string $path file path |
||
3496 | * @param bool $force try to remove even if file locked |
||
3497 | * @return bool |
||
3498 | * @author Dmitry (dio) Levashov |
||
3499 | **/ |
||
3500 | protected function remove($path, $force = false) { |
||
3530 | |||
3531 | |||
3532 | /************************* thumbnails **************************/ |
||
3533 | |||
3534 | /** |
||
3535 | * Return thumbnail file name for required file |
||
3536 | * |
||
3537 | * @param array $stat file stat |
||
3538 | * @return string |
||
3539 | * @author Dmitry (dio) Levashov |
||
3540 | **/ |
||
3541 | protected function tmbname($stat) { |
||
3544 | |||
3545 | /** |
||
3546 | * Return thumnbnail name if exists |
||
3547 | * |
||
3548 | * @param string $path file path |
||
3549 | * @param array $stat file stat |
||
3550 | * @return string|false |
||
3551 | * @author Dmitry (dio) Levashov |
||
3552 | **/ |
||
3553 | protected function gettmb($path, $stat) { |
||
3567 | |||
3568 | /** |
||
3569 | * Return true if thumnbnail for required file can be created |
||
3570 | * |
||
3571 | * @param string $path thumnbnail path |
||
3572 | * @param array $stat file stat |
||
3573 | * @param bool $checkTmbPath |
||
3574 | * @return string|bool |
||
3575 | * @author Dmitry (dio) Levashov |
||
3576 | **/ |
||
3577 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
3584 | |||
3585 | /** |
||
3586 | * Return true if required file can be resized. |
||
3587 | * By default - the same as canCreateTmb |
||
3588 | * |
||
3589 | * @param string $path thumnbnail path |
||
3590 | * @param array $stat file stat |
||
3591 | * @return string|bool |
||
3592 | * @author Dmitry (dio) Levashov |
||
3593 | **/ |
||
3594 | protected function canResize($path, $stat) { |
||
3597 | |||
3598 | /** |
||
3599 | * Create thumnbnail and return it's URL on success |
||
3600 | * |
||
3601 | * @param string $path file path |
||
3602 | * @param string $mime file mime type |
||
3603 | * @return string|false |
||
3604 | * @author Dmitry (dio) Levashov |
||
3605 | **/ |
||
3606 | protected function createTmb($path, $stat) { |
||
3676 | |||
3677 | /** |
||
3678 | * Resize image |
||
3679 | * |
||
3680 | * @param string $path image file |
||
3681 | * @param int $width new width |
||
3682 | * @param int $height new height |
||
3683 | * @param bool $keepProportions crop image |
||
3684 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
3685 | * @param string $destformat image destination format |
||
3686 | * @param int $jpgQuality JEPG quality (1-100) |
||
3687 | * @return string|false |
||
3688 | * @author Dmitry (dio) Levashov |
||
3689 | * @author Alexey Sukhotin |
||
3690 | **/ |
||
3691 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null, $jpgQuality = null) { |
||
3788 | |||
3789 | /** |
||
3790 | * Crop image |
||
3791 | * |
||
3792 | * @param string $path image file |
||
3793 | * @param int $width crop width |
||
3794 | * @param int $height crop height |
||
3795 | * @param bool $x crop left offset |
||
3796 | * @param bool $y crop top offset |
||
3797 | * @param string $destformat image destination format |
||
3798 | * @param int $jpgQuality JEPG quality (1-100) |
||
3799 | * @return string|false |
||
3800 | * @author Dmitry (dio) Levashov |
||
3801 | * @author Alexey Sukhotin |
||
3802 | **/ |
||
3803 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null, $jpgQuality = null) { |
||
3881 | |||
3882 | /** |
||
3883 | * Put image to square |
||
3884 | * |
||
3885 | * @param string $path image file |
||
3886 | * @param int $width square width |
||
3887 | * @param int $height square height |
||
3888 | * @param int $align reserved |
||
3889 | * @param int $valign reserved |
||
3890 | * @param string $bgcolor square background color in #rrggbb format |
||
3891 | * @param string $destformat image destination format |
||
3892 | * @param int $jpgQuality JEPG quality (1-100) |
||
3893 | * @return string|false |
||
3894 | * @author Dmitry (dio) Levashov |
||
3895 | * @author Alexey Sukhotin |
||
3896 | **/ |
||
3897 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null, $jpgQuality = null) { |
||
3978 | |||
3979 | /** |
||
3980 | * Rotate image |
||
3981 | * |
||
3982 | * @param string $path image file |
||
3983 | * @param int $degree rotete degrees |
||
3984 | * @param string $bgcolor square background color in #rrggbb format |
||
3985 | * @param string $destformat image destination format |
||
3986 | * @param int $jpgQuality JEPG quality (1-100) |
||
3987 | * @return string|false |
||
3988 | * @author nao-pon |
||
3989 | * @author Troex Nevelin |
||
3990 | **/ |
||
3991 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null, $jpgQuality = null) { |
||
4075 | |||
4076 | /** |
||
4077 | * Execute shell command |
||
4078 | * |
||
4079 | * @param string $command command line |
||
4080 | * @param array $output stdout strings |
||
4081 | * @param array $return_var process exit code |
||
4082 | * @param array $error_output stderr strings |
||
4083 | * @return int exit code |
||
4084 | * @author Alexey Sukhotin |
||
4085 | **/ |
||
4086 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
4116 | |||
4117 | /** |
||
4118 | * Remove thumbnail, also remove recursively if stat is directory |
||
4119 | * |
||
4120 | * @param string $stat file stat |
||
4121 | * @return void |
||
4122 | * @author Dmitry (dio) Levashov |
||
4123 | * @author Naoki Sawada |
||
4124 | * @author Troex Nevelin |
||
4125 | **/ |
||
4126 | protected function rmTmb($stat) { |
||
4139 | |||
4140 | /** |
||
4141 | * Create an gd image according to the specified mime type |
||
4142 | * |
||
4143 | * @param string $path image file |
||
4144 | * @param string $mime |
||
4145 | * @return gd image resource identifier |
||
4146 | */ |
||
4147 | protected function gdImageCreate($path,$mime){ |
||
4163 | |||
4164 | /** |
||
4165 | * Output gd image to file |
||
4166 | * |
||
4167 | * @param resource $image gd image resource |
||
4168 | * @param string $filename The path to save the file to. |
||
4169 | * @param string $destformat The Image type to use for $filename |
||
4170 | * @param string $mime The original image mime type |
||
4171 | * @param int $jpgQuality JEPG quality (1-100) |
||
4172 | */ |
||
4173 | protected function gdImage($image, $filename, $destformat, $mime, $jpgQuality = null ){ |
||
4188 | |||
4189 | /** |
||
4190 | * Output imagick image to file |
||
4191 | * |
||
4192 | * @param resource $img imagick image resource |
||
4193 | * @param string $filename The path to save the file to. |
||
4194 | * @param string $destformat The Image type to use for $filename |
||
4195 | * @param int $jpgQuality JEPG quality (1-100) |
||
4196 | */ |
||
4197 | protected function imagickImage($img, $filename, $destformat, $jpgQuality = null ){ |
||
4245 | |||
4246 | /** |
||
4247 | * Assign the proper background to a gd image |
||
4248 | * |
||
4249 | * @param resource $image gd image resource |
||
4250 | * @param string $bgcolor background color in #rrggbb format |
||
4251 | */ |
||
4252 | protected function gdImageBackground($image, $bgcolor){ |
||
4265 | |||
4266 | /*********************** misc *************************/ |
||
4267 | |||
4268 | /** |
||
4269 | * Return smart formatted date |
||
4270 | * |
||
4271 | * @param int $ts file timestamp |
||
4272 | * @return string |
||
4273 | * @author Dmitry (dio) Levashov |
||
4274 | **/ |
||
4275 | // protected function formatDate($ts) { |
||
4276 | // if ($ts > $this->today) { |
||
4277 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
4278 | // } |
||
4279 | // |
||
4280 | // if ($ts > $this->yesterday) { |
||
4281 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
4282 | // } |
||
4283 | // |
||
4284 | // return date($this->options['dateFormat'], $ts); |
||
4285 | // } |
||
4286 | |||
4287 | /** |
||
4288 | * Find position of first occurrence of string in a string with multibyte support |
||
4289 | * |
||
4290 | * @param string $haystack The string being checked. |
||
4291 | * @param string $needle The string to find in haystack. |
||
4292 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
4293 | * @return int|bool |
||
4294 | * @author Alexey Sukhotin |
||
4295 | **/ |
||
4296 | protected function stripos($haystack , $needle , $offset = 0) { |
||
4304 | |||
4305 | /** |
||
4306 | * Get server side available archivers |
||
4307 | * |
||
4308 | * @param bool $use_cache |
||
4309 | * @return array |
||
4310 | */ |
||
4311 | protected function getArchivers($use_cache = true) { |
||
4427 | |||
4428 | /** |
||
4429 | * Resolve relative / (Unix-like)absolute path |
||
4430 | * |
||
4431 | * @param string $path target path |
||
4432 | * @param string $base base path |
||
4433 | * @return string |
||
4434 | */ |
||
4435 | protected function getFullPath($path, $base) { |
||
4482 | |||
4483 | /** |
||
4484 | * Remove directory recursive on local file system |
||
4485 | * |
||
4486 | * @param string $dir Target dirctory path |
||
4487 | * @return boolean |
||
4488 | * @author Naoki Sawada |
||
4489 | */ |
||
4490 | public function rmdirRecursive($dir) { |
||
4510 | |||
4511 | /** |
||
4512 | * Create archive and return its path |
||
4513 | * |
||
4514 | * @param string $dir target dir |
||
4515 | * @param array $files files names list |
||
4516 | * @param string $name archive name |
||
4517 | * @param array $arc archiver options |
||
4518 | * @return string|bool |
||
4519 | * @author Dmitry (dio) Levashov, |
||
4520 | * @author Alexey Sukhotin |
||
4521 | * @author Naoki Sawada |
||
4522 | **/ |
||
4523 | protected function makeArchive($dir, $files, $name, $arc) { |
||
4541 | |||
4542 | /** |
||
4543 | * Unpack archive |
||
4544 | * |
||
4545 | * @param string $path archive path |
||
4546 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
4547 | * @param bool $remove remove archive ( unlink($path) ) |
||
4548 | * @return void |
||
4549 | * @author Dmitry (dio) Levashov |
||
4550 | * @author Alexey Sukhotin |
||
4551 | * @author Naoki Sawada |
||
4552 | **/ |
||
4553 | protected function unpackArchive($path, $arc, $remove = true) { |
||
4568 | |||
4569 | /** |
||
4570 | * Create Zip archive using PHP class ZipArchive |
||
4571 | * |
||
4572 | * @param string $dir target dir |
||
4573 | * @param array $files files names list |
||
4574 | * @param string|object $zipPath Zip archive name |
||
4575 | * @return void |
||
4576 | * @author Naoki Sawada |
||
4577 | */ |
||
4578 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
4616 | |||
4617 | /** |
||
4618 | * Unpack Zip archive using PHP class ZipArchive |
||
4619 | * |
||
4620 | * @param string $zipPath Zip archive name |
||
4621 | * @param string $toDir Extract to path |
||
4622 | * @return bool |
||
4623 | * @author Naoki Sawada |
||
4624 | */ |
||
4625 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
4637 | |||
4638 | /**==================================* abstract methods *====================================**/ |
||
4639 | |||
4640 | /*********************** paths/urls *************************/ |
||
4641 | |||
4642 | /** |
||
4643 | * Return parent directory path |
||
4644 | * |
||
4645 | * @param string $path file path |
||
4646 | * @return string |
||
4647 | * @author Dmitry (dio) Levashov |
||
4648 | **/ |
||
4649 | abstract protected function _dirname($path); |
||
4650 | |||
4651 | /** |
||
4652 | * Return file name |
||
4653 | * |
||
4654 | * @param string $path file path |
||
4655 | * @return string |
||
4656 | * @author Dmitry (dio) Levashov |
||
4657 | **/ |
||
4658 | abstract protected function _basename($path); |
||
4659 | |||
4660 | /** |
||
4661 | * Join dir name and file name and return full path. |
||
4662 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
4663 | * |
||
4664 | * @param string $dir dir path |
||
4665 | * @param string $name file name |
||
4666 | * @return string |
||
4667 | * @author Dmitry (dio) Levashov |
||
4668 | **/ |
||
4669 | abstract protected function _joinPath($dir, $name); |
||
4670 | |||
4671 | /** |
||
4672 | * Return normalized path |
||
4673 | * |
||
4674 | * @param string $path file path |
||
4675 | * @return string |
||
4676 | * @author Dmitry (dio) Levashov |
||
4677 | **/ |
||
4678 | abstract protected function _normpath($path); |
||
4679 | |||
4680 | /** |
||
4681 | * Return file path related to root dir |
||
4682 | * |
||
4683 | * @param string $path file path |
||
4684 | * @return string |
||
4685 | * @author Dmitry (dio) Levashov |
||
4686 | **/ |
||
4687 | abstract protected function _relpath($path); |
||
4688 | |||
4689 | /** |
||
4690 | * Convert path related to root dir into real path |
||
4691 | * |
||
4692 | * @param string $path rel file path |
||
4693 | * @return string |
||
4694 | * @author Dmitry (dio) Levashov |
||
4695 | **/ |
||
4696 | abstract protected function _abspath($path); |
||
4697 | |||
4698 | /** |
||
4699 | * Return fake path started from root dir. |
||
4700 | * Required to show path on client side. |
||
4701 | * |
||
4702 | * @param string $path file path |
||
4703 | * @return string |
||
4704 | * @author Dmitry (dio) Levashov |
||
4705 | **/ |
||
4706 | abstract protected function _path($path); |
||
4707 | |||
4708 | /** |
||
4709 | * Return true if $path is children of $parent |
||
4710 | * |
||
4711 | * @param string $path path to check |
||
4712 | * @param string $parent parent path |
||
4713 | * @return bool |
||
4714 | * @author Dmitry (dio) Levashov |
||
4715 | **/ |
||
4716 | abstract protected function _inpath($path, $parent); |
||
4717 | |||
4718 | /** |
||
4719 | * Return stat for given path. |
||
4720 | * Stat contains following fields: |
||
4721 | * - (int) size file size in b. required |
||
4722 | * - (int) ts file modification time in unix time. required |
||
4723 | * - (string) mime mimetype. required for folders, others - optionally |
||
4724 | * - (bool) read read permissions. required |
||
4725 | * - (bool) write write permissions. required |
||
4726 | * - (bool) locked is object locked. optionally |
||
4727 | * - (bool) hidden is object hidden. optionally |
||
4728 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
4729 | * - (string) target for symlinks - link target path. optionally |
||
4730 | * |
||
4731 | * If file does not exists - returns empty array or false. |
||
4732 | * |
||
4733 | * @param string $path file path |
||
4734 | * @return array|false |
||
4735 | * @author Dmitry (dio) Levashov |
||
4736 | **/ |
||
4737 | abstract protected function _stat($path); |
||
4738 | |||
4739 | |||
4740 | /***************** file stat ********************/ |
||
4741 | |||
4742 | |||
4743 | /** |
||
4744 | * Return true if path is dir and has at least one childs directory |
||
4745 | * |
||
4746 | * @param string $path dir path |
||
4747 | * @return bool |
||
4748 | * @author Dmitry (dio) Levashov |
||
4749 | **/ |
||
4750 | abstract protected function _subdirs($path); |
||
4751 | |||
4752 | /** |
||
4753 | * Return object width and height |
||
4754 | * Ususaly used for images, but can be realize for video etc... |
||
4755 | * |
||
4756 | * @param string $path file path |
||
4757 | * @param string $mime file mime type |
||
4758 | * @return string |
||
4759 | * @author Dmitry (dio) Levashov |
||
4760 | **/ |
||
4761 | abstract protected function _dimensions($path, $mime); |
||
4762 | |||
4763 | /******************** file/dir content *********************/ |
||
4764 | |||
4765 | /** |
||
4766 | * Return files list in directory |
||
4767 | * |
||
4768 | * @param string $path dir path |
||
4769 | * @return array |
||
4770 | * @author Dmitry (dio) Levashov |
||
4771 | **/ |
||
4772 | abstract protected function _scandir($path); |
||
4773 | |||
4774 | /** |
||
4775 | * Open file and return file pointer |
||
4776 | * |
||
4777 | * @param string $path file path |
||
4778 | * @param string $mode open mode |
||
4779 | * @return resource|false |
||
4780 | * @author Dmitry (dio) Levashov |
||
4781 | **/ |
||
4782 | abstract protected function _fopen($path, $mode="rb"); |
||
4783 | |||
4784 | /** |
||
4785 | * Close opened file |
||
4786 | * |
||
4787 | * @param resource $fp file pointer |
||
4788 | * @param string $path file path |
||
4789 | * @return bool |
||
4790 | * @author Dmitry (dio) Levashov |
||
4791 | **/ |
||
4792 | abstract protected function _fclose($fp, $path=''); |
||
4793 | |||
4794 | /******************** file/dir manipulations *************************/ |
||
4795 | |||
4796 | /** |
||
4797 | * Create dir and return created dir path or false on failed |
||
4798 | * |
||
4799 | * @param string $path parent dir path |
||
4800 | * @param string $name new directory name |
||
4801 | * @return string|bool |
||
4802 | * @author Dmitry (dio) Levashov |
||
4803 | **/ |
||
4804 | abstract protected function _mkdir($path, $name); |
||
4805 | |||
4806 | /** |
||
4807 | * Create file and return it's path or false on failed |
||
4808 | * |
||
4809 | * @param string $path parent dir path |
||
4810 | * @param string $name new file name |
||
4811 | * @return string|bool |
||
4812 | * @author Dmitry (dio) Levashov |
||
4813 | **/ |
||
4814 | abstract protected function _mkfile($path, $name); |
||
4815 | |||
4816 | /** |
||
4817 | * Create symlink |
||
4818 | * |
||
4819 | * @param string $source file to link to |
||
4820 | * @param string $targetDir folder to create link in |
||
4821 | * @param string $name symlink name |
||
4822 | * @return bool |
||
4823 | * @author Dmitry (dio) Levashov |
||
4824 | **/ |
||
4825 | abstract protected function _symlink($source, $targetDir, $name); |
||
4826 | |||
4827 | /** |
||
4828 | * Copy file into another file (only inside one volume) |
||
4829 | * |
||
4830 | * @param string $source source file path |
||
4831 | * @param string $target target dir path |
||
4832 | * @param string $name file name |
||
4833 | * @return bool |
||
4834 | * @author Dmitry (dio) Levashov |
||
4835 | **/ |
||
4836 | abstract protected function _copy($source, $targetDir, $name); |
||
4837 | |||
4838 | /** |
||
4839 | * Move file into another parent dir. |
||
4840 | * Return new file path or false. |
||
4841 | * |
||
4842 | * @param string $source source file path |
||
4843 | * @param string $target target dir path |
||
4844 | * @param string $name file name |
||
4845 | * @return string|bool |
||
4846 | * @author Dmitry (dio) Levashov |
||
4847 | **/ |
||
4848 | abstract protected function _move($source, $targetDir, $name); |
||
4849 | |||
4850 | /** |
||
4851 | * Remove file |
||
4852 | * |
||
4853 | * @param string $path file path |
||
4854 | * @return bool |
||
4855 | * @author Dmitry (dio) Levashov |
||
4856 | **/ |
||
4857 | abstract protected function _unlink($path); |
||
4858 | |||
4859 | /** |
||
4860 | * Remove dir |
||
4861 | * |
||
4862 | * @param string $path dir path |
||
4863 | * @return bool |
||
4864 | * @author Dmitry (dio) Levashov |
||
4865 | **/ |
||
4866 | abstract protected function _rmdir($path); |
||
4867 | |||
4868 | /** |
||
4869 | * Create new file and write into it from file pointer. |
||
4870 | * Return new file path or false on error. |
||
4871 | * |
||
4872 | * @param resource $fp file pointer |
||
4873 | * @param string $dir target dir path |
||
4874 | * @param string $name file name |
||
4875 | * @param array $stat file stat (required by some virtual fs) |
||
4876 | * @return bool|string |
||
4877 | * @author Dmitry (dio) Levashov |
||
4878 | **/ |
||
4879 | abstract protected function _save($fp, $dir, $name, $stat); |
||
4880 | |||
4881 | /** |
||
4882 | * Get file contents |
||
4883 | * |
||
4884 | * @param string $path file path |
||
4885 | * @return string|false |
||
4886 | * @author Dmitry (dio) Levashov |
||
4887 | **/ |
||
4888 | abstract protected function _getContents($path); |
||
4889 | |||
4890 | /** |
||
4891 | * Write a string to a file |
||
4892 | * |
||
4893 | * @param string $path file path |
||
4894 | * @param string $content new file content |
||
4895 | * @return bool |
||
4896 | * @author Dmitry (dio) Levashov |
||
4897 | **/ |
||
4898 | abstract protected function _filePutContents($path, $content); |
||
4899 | |||
4900 | /** |
||
4901 | * Extract files from archive |
||
4902 | * |
||
4903 | * @param string $path file path |
||
4904 | * @param array $arc archiver options |
||
4905 | * @return bool |
||
4906 | * @author Dmitry (dio) Levashov, |
||
4907 | * @author Alexey Sukhotin |
||
4908 | **/ |
||
4909 | abstract protected function _extract($path, $arc); |
||
4910 | |||
4911 | /** |
||
4912 | * Create archive and return its path |
||
4913 | * |
||
4914 | * @param string $dir target dir |
||
4915 | * @param array $files files names list |
||
4916 | * @param string $name archive name |
||
4917 | * @param array $arc archiver options |
||
4918 | * @return string|bool |
||
4919 | * @author Dmitry (dio) Levashov, |
||
4920 | * @author Alexey Sukhotin |
||
4921 | **/ |
||
4922 | abstract protected function _archive($dir, $files, $name, $arc); |
||
4923 | |||
4924 | /** |
||
4925 | * Detect available archivers |
||
4926 | * |
||
4927 | * @return void |
||
4928 | * @author Dmitry (dio) Levashov, |
||
4929 | * @author Alexey Sukhotin |
||
4930 | **/ |
||
4931 | abstract protected function _checkArchivers(); |
||
4932 | |||
4933 | /** |
||
4934 | * Change file mode (chmod) |
||
4935 | * |
||
4936 | * @param string $path file path |
||
4937 | * @param string $mode octal string such as '0755' |
||
4938 | * @return bool |
||
4939 | * @author David Bartle, |
||
4940 | **/ |
||
4941 | abstract protected function _chmod($path, $mode); |
||
4942 | |||
4943 | |||
4944 | } // END class |
||
4945 |
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.