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 | // required to fix bug on macos |
||
280 | 'utf8fix' => false, |
||
281 | // й ё Й Ё Ø Å |
||
282 | 'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"), |
||
283 | 'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5") |
||
284 | ); |
||
285 | |||
286 | /** |
||
287 | * Defaults permissions |
||
288 | * |
||
289 | * @var array |
||
290 | **/ |
||
291 | protected $defaults = array( |
||
292 | 'read' => true, |
||
293 | 'write' => true, |
||
294 | 'locked' => false, |
||
295 | 'hidden' => false |
||
296 | ); |
||
297 | |||
298 | /** |
||
299 | * Access control function/class |
||
300 | * |
||
301 | * @var mixed |
||
302 | **/ |
||
303 | protected $attributes = array(); |
||
304 | |||
305 | /** |
||
306 | * Access control function/class |
||
307 | * |
||
308 | * @var mixed |
||
309 | **/ |
||
310 | protected $access = null; |
||
311 | |||
312 | /** |
||
313 | * Mime types allowed to upload |
||
314 | * |
||
315 | * @var array |
||
316 | **/ |
||
317 | protected $uploadAllow = array(); |
||
318 | |||
319 | /** |
||
320 | * Mime types denied to upload |
||
321 | * |
||
322 | * @var array |
||
323 | **/ |
||
324 | protected $uploadDeny = array(); |
||
325 | |||
326 | /** |
||
327 | * Order to validate uploadAllow and uploadDeny |
||
328 | * |
||
329 | * @var array |
||
330 | **/ |
||
331 | protected $uploadOrder = array(); |
||
332 | |||
333 | /** |
||
334 | * Maximum allowed upload file size. |
||
335 | * Set as number or string with unit - "10M", "500K", "1G" |
||
336 | * |
||
337 | * @var int|string |
||
338 | **/ |
||
339 | protected $uploadMaxSize = 0; |
||
340 | |||
341 | /** |
||
342 | * Mimetype detect method |
||
343 | * |
||
344 | * @var string |
||
345 | **/ |
||
346 | protected $mimeDetect = 'auto'; |
||
347 | |||
348 | /** |
||
349 | * Flag - mimetypes from externail file was loaded |
||
350 | * |
||
351 | * @var bool |
||
352 | **/ |
||
353 | private static $mimetypesLoaded = false; |
||
354 | |||
355 | /** |
||
356 | * Finfo object for mimeDetect == 'finfo' |
||
357 | * |
||
358 | * @var object |
||
359 | **/ |
||
360 | protected $finfo = null; |
||
361 | |||
362 | /** |
||
363 | * List of disabled client's commands |
||
364 | * |
||
365 | * @var array |
||
366 | **/ |
||
367 | protected $disabled = array(); |
||
368 | |||
369 | /** |
||
370 | * default extensions/mimetypes for mimeDetect == 'internal' |
||
371 | * |
||
372 | * @var array |
||
373 | **/ |
||
374 | protected static $mimetypes = array( |
||
375 | // applications |
||
376 | 'ai' => 'application/postscript', |
||
377 | 'eps' => 'application/postscript', |
||
378 | 'exe' => 'application/x-executable', |
||
379 | 'doc' => 'application/msword', |
||
380 | 'dot' => 'application/msword', |
||
381 | 'xls' => 'application/vnd.ms-excel', |
||
382 | 'xlt' => 'application/vnd.ms-excel', |
||
383 | 'xla' => 'application/vnd.ms-excel', |
||
384 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
385 | 'pps' => 'application/vnd.ms-powerpoint', |
||
386 | 'pdf' => 'application/pdf', |
||
387 | 'xml' => 'application/xml', |
||
388 | 'swf' => 'application/x-shockwave-flash', |
||
389 | 'torrent' => 'application/x-bittorrent', |
||
390 | 'jar' => 'application/x-jar', |
||
391 | // open office (finfo detect as application/zip) |
||
392 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
393 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
394 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
395 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
396 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
397 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
398 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
399 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
400 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
401 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
402 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
403 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
404 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
405 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
406 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
407 | // MS office 2007 (finfo detect as application/zip) |
||
408 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
409 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
410 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
411 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
412 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
413 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
414 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
415 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
416 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
417 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
418 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
419 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
420 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
421 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
422 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
423 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
424 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
425 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
426 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
427 | // archives |
||
428 | 'gz' => 'application/x-gzip', |
||
429 | 'tgz' => 'application/x-gzip', |
||
430 | 'bz' => 'application/x-bzip2', |
||
431 | 'bz2' => 'application/x-bzip2', |
||
432 | 'tbz' => 'application/x-bzip2', |
||
433 | 'xz' => 'application/x-xz', |
||
434 | 'zip' => 'application/zip', |
||
435 | 'rar' => 'application/x-rar', |
||
436 | 'tar' => 'application/x-tar', |
||
437 | '7z' => 'application/x-7z-compressed', |
||
438 | // texts |
||
439 | 'txt' => 'text/plain', |
||
440 | 'php' => 'text/x-php', |
||
441 | 'html' => 'text/html', |
||
442 | 'htm' => 'text/html', |
||
443 | 'js' => 'text/javascript', |
||
444 | 'css' => 'text/css', |
||
445 | 'rtf' => 'text/rtf', |
||
446 | 'rtfd' => 'text/rtfd', |
||
447 | 'py' => 'text/x-python', |
||
448 | 'java' => 'text/x-java-source', |
||
449 | 'rb' => 'text/x-ruby', |
||
450 | 'sh' => 'text/x-shellscript', |
||
451 | 'pl' => 'text/x-perl', |
||
452 | 'xml' => 'text/xml', |
||
453 | 'sql' => 'text/x-sql', |
||
454 | 'c' => 'text/x-csrc', |
||
455 | 'h' => 'text/x-chdr', |
||
456 | 'cpp' => 'text/x-c++src', |
||
457 | 'hh' => 'text/x-c++hdr', |
||
458 | 'log' => 'text/plain', |
||
459 | 'csv' => 'text/x-comma-separated-values', |
||
460 | 'md' => 'text/x-markdown', |
||
461 | 'markdown' => 'text/x-markdown', |
||
462 | // images |
||
463 | 'bmp' => 'image/x-ms-bmp', |
||
464 | 'jpg' => 'image/jpeg', |
||
465 | 'jpeg' => 'image/jpeg', |
||
466 | 'gif' => 'image/gif', |
||
467 | 'png' => 'image/png', |
||
468 | 'tif' => 'image/tiff', |
||
469 | 'tiff' => 'image/tiff', |
||
470 | 'tga' => 'image/x-targa', |
||
471 | 'psd' => 'image/vnd.adobe.photoshop', |
||
472 | 'ai' => 'image/vnd.adobe.photoshop', |
||
473 | 'xbm' => 'image/xbm', |
||
474 | 'pxm' => 'image/pxm', |
||
475 | //audio |
||
476 | 'mp3' => 'audio/mpeg', |
||
477 | 'mid' => 'audio/midi', |
||
478 | 'ogg' => 'audio/ogg', |
||
479 | 'oga' => 'audio/ogg', |
||
480 | 'm4a' => 'audio/x-m4a', |
||
481 | 'wav' => 'audio/wav', |
||
482 | 'wma' => 'audio/x-ms-wma', |
||
483 | // video |
||
484 | 'avi' => 'video/x-msvideo', |
||
485 | 'dv' => 'video/x-dv', |
||
486 | 'mp4' => 'video/mp4', |
||
487 | 'mpeg' => 'video/mpeg', |
||
488 | 'mpg' => 'video/mpeg', |
||
489 | 'mov' => 'video/quicktime', |
||
490 | 'wm' => 'video/x-ms-wmv', |
||
491 | 'flv' => 'video/x-flv', |
||
492 | 'mkv' => 'video/x-matroska', |
||
493 | 'webm' => 'video/webm', |
||
494 | 'ogv' => 'video/ogg', |
||
495 | 'ogm' => 'video/ogg' |
||
496 | ); |
||
497 | |||
498 | /** |
||
499 | * Directory separator - required by client |
||
500 | * |
||
501 | * @var string |
||
502 | **/ |
||
503 | protected $separator = DIRECTORY_SEPARATOR; |
||
504 | |||
505 | /** |
||
506 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...) |
||
507 | * |
||
508 | * @var string |
||
509 | **/ |
||
510 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
511 | |||
512 | /** |
||
513 | * Mimetypes allowed to display |
||
514 | * |
||
515 | * @var array |
||
516 | **/ |
||
517 | protected $onlyMimes = array(); |
||
518 | |||
519 | /** |
||
520 | * Store files moved or overwrited files info |
||
521 | * |
||
522 | * @var array |
||
523 | **/ |
||
524 | protected $removed = array(); |
||
525 | |||
526 | /** |
||
527 | * Cache storage |
||
528 | * |
||
529 | * @var array |
||
530 | **/ |
||
531 | protected $cache = array(); |
||
532 | |||
533 | /** |
||
534 | * Cache by folders |
||
535 | * |
||
536 | * @var array |
||
537 | **/ |
||
538 | protected $dirsCache = array(); |
||
539 | |||
540 | /** |
||
541 | * Cache for subdirsCE() |
||
542 | * |
||
543 | * @var array |
||
544 | */ |
||
545 | protected $subdirsCache = array(); |
||
546 | |||
547 | /** |
||
548 | * Reference of $_SESSION[elFinder::$sessionCacheKey][$this->id] |
||
549 | * |
||
550 | * @var array |
||
551 | */ |
||
552 | protected $sessionCache; |
||
553 | |||
554 | /*********************************************************************/ |
||
555 | /* INITIALIZATION */ |
||
556 | /*********************************************************************/ |
||
557 | |||
558 | /** |
||
559 | * Prepare driver before mount volume. |
||
560 | * Return true if volume is ready. |
||
561 | * |
||
562 | * @return bool |
||
563 | * @author Dmitry (dio) Levashov |
||
564 | **/ |
||
565 | protected function init() { |
||
568 | |||
569 | /** |
||
570 | * Configure after successfull mount. |
||
571 | * By default set thumbnails path and image manipulation library. |
||
572 | * |
||
573 | * @return void |
||
574 | * @author Dmitry (dio) Levashov |
||
575 | **/ |
||
576 | protected function configure() { |
||
617 | |||
618 | |||
619 | /*********************************************************************/ |
||
620 | /* PUBLIC API */ |
||
621 | /*********************************************************************/ |
||
622 | |||
623 | /** |
||
624 | * Return driver id. Used as a part of volume id. |
||
625 | * |
||
626 | * @return string |
||
627 | * @author Dmitry (dio) Levashov |
||
628 | **/ |
||
629 | public function driverId() { |
||
632 | |||
633 | /** |
||
634 | * Return volume id |
||
635 | * |
||
636 | * @return string |
||
637 | * @author Dmitry (dio) Levashov |
||
638 | **/ |
||
639 | public function id() { |
||
642 | |||
643 | /** |
||
644 | * Return debug info for client |
||
645 | * |
||
646 | * @return array |
||
647 | * @author Dmitry (dio) Levashov |
||
648 | **/ |
||
649 | public function debug() { |
||
657 | |||
658 | /** |
||
659 | * chmod a file or folder |
||
660 | * |
||
661 | * @param string $hash file or folder hash to chmod |
||
662 | * @param string $mode octal string representing new permissions |
||
663 | * @return array|false |
||
664 | * @author David Bartle |
||
665 | **/ |
||
666 | public function chmod($hash, $mode) { |
||
703 | |||
704 | /** |
||
705 | * "Mount" volume. |
||
706 | * Return true if volume available for read or write, |
||
707 | * false - otherwise |
||
708 | * |
||
709 | * @return bool |
||
710 | * @author Dmitry (dio) Levashov |
||
711 | * @author Alexey Sukhotin |
||
712 | **/ |
||
713 | public function mount(array $opts) { |
||
977 | |||
978 | /** |
||
979 | * Some "unmount" stuffs - may be required by virtual fs |
||
980 | * |
||
981 | * @return void |
||
982 | * @author Dmitry (dio) Levashov |
||
983 | **/ |
||
984 | public function umount() { |
||
986 | |||
987 | /** |
||
988 | * Return error message from last failed action |
||
989 | * |
||
990 | * @return array |
||
991 | * @author Dmitry (dio) Levashov |
||
992 | **/ |
||
993 | public function error() { |
||
996 | |||
997 | /** |
||
998 | * Return is uploadable that given file name |
||
999 | * |
||
1000 | * @param string $name file name |
||
1001 | * @param bool $allowUnknown |
||
1002 | * @return bool |
||
1003 | * @author Naoki Sawada |
||
1004 | **/ |
||
1005 | public function isUploadableByName($name, $allowUnknown = true) { |
||
1009 | |||
1010 | /** |
||
1011 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
1012 | * |
||
1013 | * @return array |
||
1014 | * @author Naoki Sawada |
||
1015 | */ |
||
1016 | public function getMimeTable() { |
||
1019 | |||
1020 | /** |
||
1021 | * Set mimetypes allowed to display to client |
||
1022 | * |
||
1023 | * @param array $mimes |
||
1024 | * @return void |
||
1025 | * @author Dmitry (dio) Levashov |
||
1026 | **/ |
||
1027 | public function setMimesFilter($mimes) { |
||
1032 | |||
1033 | /** |
||
1034 | * Return root folder hash |
||
1035 | * |
||
1036 | * @return string |
||
1037 | * @author Dmitry (dio) Levashov |
||
1038 | **/ |
||
1039 | public function root() { |
||
1042 | |||
1043 | /** |
||
1044 | * Return target path hash |
||
1045 | * |
||
1046 | * @param string $path |
||
1047 | * @param string $name |
||
1048 | * @author Naoki Sawada |
||
1049 | */ |
||
1050 | public function getHash($path, $name = '') { |
||
1056 | |||
1057 | /** |
||
1058 | * Return root or startPath hash |
||
1059 | * |
||
1060 | * @return string |
||
1061 | * @author Dmitry (dio) Levashov |
||
1062 | **/ |
||
1063 | public function defaultPath() { |
||
1066 | |||
1067 | /** |
||
1068 | * Return volume options required by client: |
||
1069 | * |
||
1070 | * @return array |
||
1071 | * @author Dmitry (dio) Levashov |
||
1072 | **/ |
||
1073 | public function options($hash) { |
||
1100 | |||
1101 | /** |
||
1102 | * Get option value of this volume |
||
1103 | * |
||
1104 | * @param string $name target option name |
||
1105 | * @return NULL|mixed target option value |
||
1106 | * @author Naoki Sawada |
||
1107 | */ |
||
1108 | public function getOption($name) { |
||
1111 | |||
1112 | /** |
||
1113 | * Get plugin values of this options |
||
1114 | * |
||
1115 | * @param string $name Plugin name |
||
1116 | * @return NULL|array Plugin values |
||
1117 | * @author Naoki Sawada |
||
1118 | */ |
||
1119 | public function getOptionsPlugin($name = '') { |
||
1126 | |||
1127 | /** |
||
1128 | * Return true if command disabled in options |
||
1129 | * |
||
1130 | * @param string $cmd command name |
||
1131 | * @return bool |
||
1132 | * @author Dmitry (dio) Levashov |
||
1133 | **/ |
||
1134 | public function commandDisabled($cmd) { |
||
1137 | |||
1138 | /** |
||
1139 | * Return true if mime is required mimes list |
||
1140 | * |
||
1141 | * @param string $mime mime type to check |
||
1142 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
1143 | * @param bool|null $empty what to return on empty list |
||
1144 | * @return bool|null |
||
1145 | * @author Dmitry (dio) Levashov |
||
1146 | * @author Troex Nevelin |
||
1147 | **/ |
||
1148 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
1159 | |||
1160 | /** |
||
1161 | * Return true if voume is readable. |
||
1162 | * |
||
1163 | * @return bool |
||
1164 | * @author Dmitry (dio) Levashov |
||
1165 | **/ |
||
1166 | public function isReadable() { |
||
1170 | |||
1171 | /** |
||
1172 | * Return true if copy from this volume allowed |
||
1173 | * |
||
1174 | * @return bool |
||
1175 | * @author Dmitry (dio) Levashov |
||
1176 | **/ |
||
1177 | public function copyFromAllowed() { |
||
1180 | |||
1181 | /** |
||
1182 | * Return file path related to root with convert encoging |
||
1183 | * |
||
1184 | * @param string $hash file hash |
||
1185 | * @return string |
||
1186 | * @author Dmitry (dio) Levashov |
||
1187 | **/ |
||
1188 | public function path($hash) { |
||
1191 | |||
1192 | /** |
||
1193 | * Return file real path if file exists |
||
1194 | * |
||
1195 | * @param string $hash file hash |
||
1196 | * @return string |
||
1197 | * @author Dmitry (dio) Levashov |
||
1198 | **/ |
||
1199 | public function realpath($hash) { |
||
1203 | |||
1204 | /** |
||
1205 | * Return list of moved/overwrited files |
||
1206 | * |
||
1207 | * @return array |
||
1208 | * @author Dmitry (dio) Levashov |
||
1209 | **/ |
||
1210 | public function removed() { |
||
1213 | |||
1214 | /** |
||
1215 | * Clean removed files list |
||
1216 | * |
||
1217 | * @return void |
||
1218 | * @author Dmitry (dio) Levashov |
||
1219 | **/ |
||
1220 | public function resetRemoved() { |
||
1223 | |||
1224 | /** |
||
1225 | * Return file/dir hash or first founded child hash with required attr == $val |
||
1226 | * |
||
1227 | * @param string $hash file hash |
||
1228 | * @param string $attr attribute name |
||
1229 | * @param bool $val attribute value |
||
1230 | * @return string|false |
||
1231 | * @author Dmitry (dio) Levashov |
||
1232 | **/ |
||
1233 | public function closest($hash, $attr, $val) { |
||
1236 | |||
1237 | /** |
||
1238 | * Return file info or false on error |
||
1239 | * |
||
1240 | * @param string $hash file hash |
||
1241 | * @param bool $realpath add realpath field to file info |
||
1242 | * @return array|false |
||
1243 | * @author Dmitry (dio) Levashov |
||
1244 | **/ |
||
1245 | public function file($hash) { |
||
1257 | |||
1258 | /** |
||
1259 | * Return folder info |
||
1260 | * |
||
1261 | * @param string $hash folder hash |
||
1262 | * @param bool $hidden return hidden file info |
||
1263 | * @return array|false |
||
1264 | * @author Dmitry (dio) Levashov |
||
1265 | **/ |
||
1266 | public function dir($hash, $resolveLink=false) { |
||
1279 | |||
1280 | /** |
||
1281 | * Return directory content or false on error |
||
1282 | * |
||
1283 | * @param string $hash file hash |
||
1284 | * @return array|false |
||
1285 | * @author Dmitry (dio) Levashov |
||
1286 | **/ |
||
1287 | public function scandir($hash) { |
||
1296 | |||
1297 | /** |
||
1298 | * Return dir files names list |
||
1299 | * |
||
1300 | * @param string $hash file hash |
||
1301 | * @return array |
||
1302 | * @author Dmitry (dio) Levashov |
||
1303 | **/ |
||
1304 | public function ls($hash) { |
||
1320 | |||
1321 | /** |
||
1322 | * Return subfolders for required folder or false on error |
||
1323 | * |
||
1324 | * @param string $hash folder hash or empty string to get tree from root folder |
||
1325 | * @param int $deep subdir deep |
||
1326 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
1327 | * @return array|false |
||
1328 | * @author Dmitry (dio) Levashov |
||
1329 | **/ |
||
1330 | public function tree($hash='', $deep=0, $exclude='') { |
||
1341 | |||
1342 | /** |
||
1343 | * Return part of dirs tree from required dir up to root dir |
||
1344 | * |
||
1345 | * @param string $hash directory hash |
||
1346 | * @param bool|null $lineal only lineal parents |
||
1347 | * @return array |
||
1348 | * @author Dmitry (dio) Levashov |
||
1349 | **/ |
||
1350 | public function parents($hash, $lineal = false) { |
||
1377 | |||
1378 | /** |
||
1379 | * Create thumbnail for required file and return its name of false on failed |
||
1380 | * |
||
1381 | * @return string|false |
||
1382 | * @author Dmitry (dio) Levashov |
||
1383 | **/ |
||
1384 | public function tmb($hash) { |
||
1393 | |||
1394 | /** |
||
1395 | * Return file size / total directory size |
||
1396 | * |
||
1397 | * @param string file hash |
||
1398 | * @return int |
||
1399 | * @author Dmitry (dio) Levashov |
||
1400 | **/ |
||
1401 | public function size($hash) { |
||
1404 | |||
1405 | /** |
||
1406 | * Open file for reading and return file pointer |
||
1407 | * |
||
1408 | * @param string file hash |
||
1409 | * @return Resource |
||
1410 | * @author Dmitry (dio) Levashov |
||
1411 | **/ |
||
1412 | public function open($hash) { |
||
1420 | |||
1421 | /** |
||
1422 | * Close file pointer |
||
1423 | * |
||
1424 | * @param Resource $fp file pointer |
||
1425 | * @param string $hash file hash |
||
1426 | * @return void |
||
1427 | * @author Dmitry (dio) Levashov |
||
1428 | **/ |
||
1429 | public function close($fp, $hash) { |
||
1432 | |||
1433 | /** |
||
1434 | * Create directory and return dir info |
||
1435 | * |
||
1436 | * @param string $dsthash destination directory hash |
||
1437 | * @param string $name directory name |
||
1438 | * @return array|false |
||
1439 | * @author Dmitry (dio) Levashov |
||
1440 | **/ |
||
1441 | public function mkdir($dsthash, $name) { |
||
1468 | |||
1469 | /** |
||
1470 | * Create empty file and return its info |
||
1471 | * |
||
1472 | * @param string $dst destination directory |
||
1473 | * @param string $name file name |
||
1474 | * @return array|false |
||
1475 | * @author Dmitry (dio) Levashov |
||
1476 | **/ |
||
1477 | public function mkfile($dst, $name) { |
||
1503 | |||
1504 | /** |
||
1505 | * Rename file and return file info |
||
1506 | * |
||
1507 | * @param string $hash file hash |
||
1508 | * @param string $name new file name |
||
1509 | * @return array|false |
||
1510 | * @author Dmitry (dio) Levashov |
||
1511 | **/ |
||
1512 | public function rename($hash, $name) { |
||
1558 | |||
1559 | /** |
||
1560 | * Create file copy with suffix "copy number" and return its info |
||
1561 | * |
||
1562 | * @param string $hash file hash |
||
1563 | * @param string $suffix suffix to add to file name |
||
1564 | * @return array|false |
||
1565 | * @author Dmitry (dio) Levashov |
||
1566 | **/ |
||
1567 | public function duplicate($hash, $suffix='copy') { |
||
1588 | |||
1589 | /** |
||
1590 | * Save uploaded file. |
||
1591 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
1592 | * |
||
1593 | * @param Resource $fp file pointer |
||
1594 | * @param string $dst destination folder hash |
||
1595 | * @param string $src file name |
||
1596 | * @param string $tmpname file tmp name - required to detect mime type |
||
1597 | * @return array|false |
||
1598 | * @author Dmitry (dio) Levashov |
||
1599 | **/ |
||
1600 | public function upload($fp, $dst, $name, $tmpname) { |
||
1676 | |||
1677 | /** |
||
1678 | * Paste files |
||
1679 | * |
||
1680 | * @param Object $volume source volume |
||
1681 | * @param string $source file hash |
||
1682 | * @param string $dst destination dir hash |
||
1683 | * @param bool $rmSrc remove source after copy? |
||
1684 | * @return array|false |
||
1685 | * @author Dmitry (dio) Levashov |
||
1686 | **/ |
||
1687 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
1775 | |||
1776 | /** |
||
1777 | * Return file contents |
||
1778 | * |
||
1779 | * @param string $hash file hash |
||
1780 | * @return string|false |
||
1781 | * @author Dmitry (dio) Levashov |
||
1782 | **/ |
||
1783 | public function getContents($hash) { |
||
1800 | |||
1801 | /** |
||
1802 | * Put content in text file and return file info. |
||
1803 | * |
||
1804 | * @param string $hash file hash |
||
1805 | * @param string $content new file content |
||
1806 | * @return array |
||
1807 | * @author Dmitry (dio) Levashov |
||
1808 | **/ |
||
1809 | public function putContents($hash, $content) { |
||
1844 | |||
1845 | /** |
||
1846 | * Extract files from archive |
||
1847 | * |
||
1848 | * @param string $hash archive hash |
||
1849 | * @return array|bool |
||
1850 | * @author Dmitry (dio) Levashov, |
||
1851 | * @author Alexey Sukhotin |
||
1852 | **/ |
||
1853 | public function extract($hash, $makedir = null) { |
||
1892 | |||
1893 | /** |
||
1894 | * Add files to archive |
||
1895 | * |
||
1896 | * @return void |
||
1897 | **/ |
||
1898 | public function archive($hashes, $mime, $name = '') { |
||
1942 | |||
1943 | /** |
||
1944 | * Resize image |
||
1945 | * |
||
1946 | * @param string $hash image file |
||
1947 | * @param int $width new width |
||
1948 | * @param int $height new height |
||
1949 | * @param int $x X start poistion for crop |
||
1950 | * @param int $y Y start poistion for crop |
||
1951 | * @param string $mode action how to mainpulate image |
||
1952 | * @param string $bg background color |
||
1953 | * @param int $degree rotete degree |
||
1954 | * @param int $jpgQuality JEPG quality (1-100) |
||
1955 | * @return array|false |
||
1956 | * @author Dmitry (dio) Levashov |
||
1957 | * @author Alexey Sukhotin |
||
1958 | * @author nao-pon |
||
1959 | * @author Troex Nevelin |
||
1960 | **/ |
||
1961 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0, $jpgQuality = null) { |
||
2048 | |||
2049 | /** |
||
2050 | * Remove file/dir |
||
2051 | * |
||
2052 | * @param string $hash file hash |
||
2053 | * @return bool |
||
2054 | * @author Dmitry (dio) Levashov |
||
2055 | **/ |
||
2056 | public function rm($hash) { |
||
2061 | |||
2062 | /** |
||
2063 | * Search files |
||
2064 | * |
||
2065 | * @param string $q search string |
||
2066 | * @param array $mimes |
||
2067 | * @return array |
||
2068 | * @author Dmitry (dio) Levashov |
||
2069 | **/ |
||
2070 | public function search($q, $mimes, $hash = null) { |
||
2089 | |||
2090 | /** |
||
2091 | * Return image dimensions |
||
2092 | * |
||
2093 | * @param string $hash file hash |
||
2094 | * @return array |
||
2095 | * @author Dmitry (dio) Levashov |
||
2096 | **/ |
||
2097 | public function dimensions($hash) { |
||
2104 | |||
2105 | /** |
||
2106 | * Return content URL (for netmout volume driver) |
||
2107 | * If file.url == 1 requests from JavaScript client with XHR |
||
2108 | * |
||
2109 | * @param string $hash file hash |
||
2110 | * @param array $options options array |
||
2111 | * @return boolean|string |
||
2112 | * @author Naoki Sawada |
||
2113 | */ |
||
2114 | public function getContentUrl($hash, $options = array()) { |
||
2120 | |||
2121 | /** |
||
2122 | * Return temp path |
||
2123 | * |
||
2124 | * @return string |
||
2125 | * @author Naoki Sawada |
||
2126 | */ |
||
2127 | public function getTempPath() { |
||
2143 | |||
2144 | /** |
||
2145 | * (Make &) Get upload taget dirctory hash |
||
2146 | * |
||
2147 | * @param string $baseTargetHash |
||
2148 | * @param string $path |
||
2149 | * @param array $result |
||
2150 | * @return boolean|string |
||
2151 | * @author Naoki Sawada |
||
2152 | */ |
||
2153 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
2180 | |||
2181 | /** |
||
2182 | * Return this uploadMaxSize value |
||
2183 | * |
||
2184 | * @return integer |
||
2185 | * @author Naoki Sawada |
||
2186 | */ |
||
2187 | public function getUploadMaxSize() { |
||
2190 | |||
2191 | /** |
||
2192 | * Save error message |
||
2193 | * |
||
2194 | * @param array error |
||
2195 | * @return false |
||
2196 | * @author Dmitry(dio) Levashov |
||
2197 | **/ |
||
2198 | protected function setError($error) { |
||
2213 | |||
2214 | /*********************************************************************/ |
||
2215 | /* FS API */ |
||
2216 | /*********************************************************************/ |
||
2217 | |||
2218 | /***************** server encoding support *******************/ |
||
2219 | |||
2220 | /** |
||
2221 | * Return parent directory path (with convert encording) |
||
2222 | * |
||
2223 | * @param string $path file path |
||
2224 | * @return string |
||
2225 | * @author Naoki Sawada |
||
2226 | **/ |
||
2227 | protected function dirnameCE($path) { |
||
2230 | |||
2231 | /** |
||
2232 | * Return file name (with convert encording) |
||
2233 | * |
||
2234 | * @param string $path file path |
||
2235 | * @return string |
||
2236 | * @author Naoki Sawada |
||
2237 | **/ |
||
2238 | protected function basenameCE($path) { |
||
2241 | |||
2242 | /** |
||
2243 | * Join dir name and file name and return full path. (with convert encording) |
||
2244 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
2245 | * |
||
2246 | * @param string $dir dir path |
||
2247 | * @param string $name file name |
||
2248 | * @return string |
||
2249 | * @author Naoki Sawada |
||
2250 | **/ |
||
2251 | protected function joinPathCE($dir, $name) { |
||
2254 | |||
2255 | /** |
||
2256 | * Return normalized path (with convert encording) |
||
2257 | * |
||
2258 | * @param string $path file path |
||
2259 | * @return string |
||
2260 | * @author Naoki Sawada |
||
2261 | **/ |
||
2262 | protected function normpathCE($path) { |
||
2265 | |||
2266 | /** |
||
2267 | * Return file path related to root dir (with convert encording) |
||
2268 | * |
||
2269 | * @param string $path file path |
||
2270 | * @return string |
||
2271 | * @author Naoki Sawada |
||
2272 | **/ |
||
2273 | protected function relpathCE($path) { |
||
2276 | |||
2277 | /** |
||
2278 | * Convert path related to root dir into real path (with convert encording) |
||
2279 | * |
||
2280 | * @param string $path rel file path |
||
2281 | * @return string |
||
2282 | * @author Naoki Sawada |
||
2283 | **/ |
||
2284 | protected function abspathCE($path) { |
||
2287 | |||
2288 | /** |
||
2289 | * Return true if $path is children of $parent (with convert encording) |
||
2290 | * |
||
2291 | * @param string $path path to check |
||
2292 | * @param string $parent parent path |
||
2293 | * @return bool |
||
2294 | * @author Naoki Sawada |
||
2295 | **/ |
||
2296 | protected function inpathCE($path, $parent) { |
||
2299 | |||
2300 | /** |
||
2301 | * Open file and return file pointer (with convert encording) |
||
2302 | * |
||
2303 | * @param string $path file path |
||
2304 | * @param bool $write open file for writing |
||
2305 | * @return resource|false |
||
2306 | * @author Naoki Sawada |
||
2307 | **/ |
||
2308 | protected function fopenCE($path, $mode='rb') { |
||
2311 | |||
2312 | /** |
||
2313 | * Close opened file (with convert encording) |
||
2314 | * |
||
2315 | * @param resource $fp file pointer |
||
2316 | * @param string $path file path |
||
2317 | * @return bool |
||
2318 | * @author Naoki Sawada |
||
2319 | **/ |
||
2320 | protected function fcloseCE($fp, $path='') { |
||
2323 | |||
2324 | /** |
||
2325 | * Create new file and write into it from file pointer. (with convert encording) |
||
2326 | * Return new file path or false on error. |
||
2327 | * |
||
2328 | * @param resource $fp file pointer |
||
2329 | * @param string $dir target dir path |
||
2330 | * @param string $name file name |
||
2331 | * @param array $stat file stat (required by some virtual fs) |
||
2332 | * @return bool|string |
||
2333 | * @author Naoki Sawada |
||
2334 | **/ |
||
2335 | protected function saveCE($fp, $dir, $name, $stat) { |
||
2338 | |||
2339 | /** |
||
2340 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
2341 | * |
||
2342 | * @param string $path dir path |
||
2343 | * @return bool |
||
2344 | * @author Naoki Sawada |
||
2345 | **/ |
||
2346 | protected function subdirsCE($path) { |
||
2352 | |||
2353 | /** |
||
2354 | * Return files list in directory (with convert encording) |
||
2355 | * |
||
2356 | * @param string $path dir path |
||
2357 | * @return array |
||
2358 | * @author Naoki Sawada |
||
2359 | **/ |
||
2360 | protected function scandirCE($path) { |
||
2363 | |||
2364 | /** |
||
2365 | * Create symlink (with convert encording) |
||
2366 | * |
||
2367 | * @param string $source file to link to |
||
2368 | * @param string $targetDir folder to create link in |
||
2369 | * @param string $name symlink name |
||
2370 | * @return bool |
||
2371 | * @author Naoki Sawada |
||
2372 | **/ |
||
2373 | protected function symlinkCE($source, $targetDir, $name) { |
||
2376 | |||
2377 | /***************** paths *******************/ |
||
2378 | |||
2379 | /** |
||
2380 | * Encode path into hash |
||
2381 | * |
||
2382 | * @param string file path |
||
2383 | * @return string |
||
2384 | * @author Dmitry (dio) Levashov |
||
2385 | * @author Troex Nevelin |
||
2386 | **/ |
||
2387 | protected function encode($path) { |
||
2408 | |||
2409 | /** |
||
2410 | * Decode path from hash |
||
2411 | * |
||
2412 | * @param string file hash |
||
2413 | * @return string |
||
2414 | * @author Dmitry (dio) Levashov |
||
2415 | * @author Troex Nevelin |
||
2416 | **/ |
||
2417 | protected function decode($hash) { |
||
2429 | |||
2430 | /** |
||
2431 | * Return crypted path |
||
2432 | * Not implemented |
||
2433 | * |
||
2434 | * @param string path |
||
2435 | * @return mixed |
||
2436 | * @author Dmitry (dio) Levashov |
||
2437 | **/ |
||
2438 | protected function crypt($path) { |
||
2441 | |||
2442 | /** |
||
2443 | * Return uncrypted path |
||
2444 | * Not implemented |
||
2445 | * |
||
2446 | * @param mixed hash |
||
2447 | * @return mixed |
||
2448 | * @author Dmitry (dio) Levashov |
||
2449 | **/ |
||
2450 | protected function uncrypt($hash) { |
||
2453 | |||
2454 | /** |
||
2455 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
2456 | * |
||
2457 | * @param string $name file name |
||
2458 | * @return bool |
||
2459 | * @author Dmitry (dio) Levashov |
||
2460 | **/ |
||
2461 | protected function nameAccepted($name) { |
||
2476 | |||
2477 | /** |
||
2478 | * Return new unique name based on file name and suffix |
||
2479 | * |
||
2480 | * @param string $path file path |
||
2481 | * @param string $suffix suffix append to name |
||
2482 | * @return string |
||
2483 | * @author Dmitry (dio) Levashov |
||
2484 | **/ |
||
2485 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum = true, $start = 1) { |
||
2513 | |||
2514 | /** |
||
2515 | * Converts character encoding from UTF-8 to server's one |
||
2516 | * |
||
2517 | * @param mixed $var target string or array var |
||
2518 | * @param bool $restoreLocale do retore global locale, default is false |
||
2519 | * @param string $unknown replaces character for unknown |
||
2520 | * @return mixed |
||
2521 | * @author Naoki Sawada |
||
2522 | */ |
||
2523 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
2526 | |||
2527 | /** |
||
2528 | * Converts character encoding from server's one to UTF-8 |
||
2529 | * |
||
2530 | * @param mixed $var target string or array var |
||
2531 | * @param bool $restoreLocale do retore global locale, default is true |
||
2532 | * @param string $unknown replaces character for unknown |
||
2533 | * @return mixed |
||
2534 | * @author Naoki Sawada |
||
2535 | */ |
||
2536 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
2539 | |||
2540 | /** |
||
2541 | * Converts character encoding (base function) |
||
2542 | * |
||
2543 | * @param mixed $var target string or array var |
||
2544 | * @param string $from from character encoding |
||
2545 | * @param string $to to character encoding |
||
2546 | * @param string $locale local locale |
||
2547 | * @param string $unknown replaces character for unknown |
||
2548 | * @return mixed |
||
2549 | */ |
||
2550 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
2579 | |||
2580 | /*********************** util mainly for inheritance class *********************/ |
||
2581 | |||
2582 | /** |
||
2583 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
2584 | * When needing the unique file to a path, give $path to parameter. |
||
2585 | * |
||
2586 | * @param string $path for get unique file to a path |
||
2587 | * @return string|false |
||
2588 | * @author Naoki Sawada |
||
2589 | */ |
||
2590 | protected function getTempFile($path = '') { |
||
2616 | |||
2617 | /** |
||
2618 | * File path of local server side work file path |
||
2619 | * |
||
2620 | * @param string $path path need convert encoding to server encoding |
||
2621 | * @return string |
||
2622 | * @author Naoki Sawada |
||
2623 | */ |
||
2624 | protected function getWorkFile($path) { |
||
2639 | |||
2640 | /** |
||
2641 | * Get image size array with `dimensions` |
||
2642 | * |
||
2643 | * @param string $path path need convert encoding to server encoding |
||
2644 | * @param string $mime file mime type |
||
2645 | * @return array|false |
||
2646 | */ |
||
2647 | public function getImageSize($path, $mime = '') { |
||
2659 | |||
2660 | /** |
||
2661 | * Delete dirctory trees |
||
2662 | * |
||
2663 | * @param string $localpath path need convert encoding to server encoding |
||
2664 | * @return boolean |
||
2665 | * @author Naoki Sawada |
||
2666 | */ |
||
2667 | protected function delTree($localpath) { |
||
2676 | |||
2677 | /*********************** file stat *********************/ |
||
2678 | |||
2679 | /** |
||
2680 | * Check file attribute |
||
2681 | * |
||
2682 | * @param string $path file path |
||
2683 | * @param string $name attribute name (read|write|locked|hidden) |
||
2684 | * @param bool $val attribute value returned by file system |
||
2685 | * @param bool $isDir path is directory (true: directory, false: file) |
||
2686 | * @return bool |
||
2687 | * @author Dmitry (dio) Levashov |
||
2688 | **/ |
||
2689 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
2723 | |||
2724 | /** |
||
2725 | * Return true if file with given name can be created in given folder. |
||
2726 | * |
||
2727 | * @param string $dir parent dir path |
||
2728 | * @param string $name new file name |
||
2729 | * @return bool |
||
2730 | * @author Dmitry (dio) Levashov |
||
2731 | **/ |
||
2732 | protected function allowCreate($dir, $name, $isDir = null) { |
||
2755 | |||
2756 | /** |
||
2757 | * Return true if file MIME type can save with check uploadOrder config. |
||
2758 | * |
||
2759 | * @param string $mime |
||
2760 | * @return boolean |
||
2761 | */ |
||
2762 | protected function allowPutMime($mime) { |
||
2780 | |||
2781 | /** |
||
2782 | * Return fileinfo |
||
2783 | * |
||
2784 | * @param string $path file cache |
||
2785 | * @return array |
||
2786 | * @author Dmitry (dio) Levashov |
||
2787 | **/ |
||
2788 | protected function stat($path) { |
||
2815 | |||
2816 | /** |
||
2817 | * Put file stat in cache and return it |
||
2818 | * |
||
2819 | * @param string $path file path |
||
2820 | * @param array $stat file stat |
||
2821 | * @return array |
||
2822 | * @author Dmitry (dio) Levashov |
||
2823 | **/ |
||
2824 | protected function updateCache($path, $stat) { |
||
2967 | |||
2968 | /** |
||
2969 | * Get stat for folder content and put in cache |
||
2970 | * |
||
2971 | * @param string $path |
||
2972 | * @return void |
||
2973 | * @author Dmitry (dio) Levashov |
||
2974 | **/ |
||
2975 | protected function cacheDir($path) { |
||
2988 | |||
2989 | /** |
||
2990 | * Clean cache |
||
2991 | * |
||
2992 | * @return void |
||
2993 | * @author Dmitry (dio) Levashov |
||
2994 | **/ |
||
2995 | protected function clearcache() { |
||
2999 | |||
3000 | /** |
||
3001 | * Return file mimetype |
||
3002 | * |
||
3003 | * @param string $path file path |
||
3004 | * @return string |
||
3005 | * @author Dmitry (dio) Levashov |
||
3006 | **/ |
||
3007 | protected function mimetype($path, $name = '') { |
||
3052 | |||
3053 | /** |
||
3054 | * Detect file mimetype using "internal" method |
||
3055 | * |
||
3056 | * @param string $path file path |
||
3057 | * @return string |
||
3058 | * @author Dmitry (dio) Levashov |
||
3059 | **/ |
||
3060 | static protected function mimetypeInternalDetect($path) { |
||
3083 | |||
3084 | /** |
||
3085 | * Return file/total directory size |
||
3086 | * |
||
3087 | * @param string $path file path |
||
3088 | * @return int |
||
3089 | * @author Dmitry (dio) Levashov |
||
3090 | **/ |
||
3091 | protected function countSize($path) { |
||
3116 | |||
3117 | /** |
||
3118 | * Return true if all mimes is directory or files |
||
3119 | * |
||
3120 | * @param string $mime1 mimetype |
||
3121 | * @param string $mime2 mimetype |
||
3122 | * @return bool |
||
3123 | * @author Dmitry (dio) Levashov |
||
3124 | **/ |
||
3125 | protected function isSameType($mime1, $mime2) { |
||
3128 | |||
3129 | /** |
||
3130 | * If file has required attr == $val - return file path, |
||
3131 | * If dir has child with has required attr == $val - return child path |
||
3132 | * |
||
3133 | * @param string $path file path |
||
3134 | * @param string $attr attribute name |
||
3135 | * @param bool $val attribute value |
||
3136 | * @return string|false |
||
3137 | * @author Dmitry (dio) Levashov |
||
3138 | **/ |
||
3139 | protected function closestByAttr($path, $attr, $val) { |
||
3156 | |||
3157 | /** |
||
3158 | * Return first found children with required attr == $val |
||
3159 | * |
||
3160 | * @param string $path file path |
||
3161 | * @param string $attr attribute name |
||
3162 | * @param bool $val attribute value |
||
3163 | * @return string|false |
||
3164 | * @author Dmitry (dio) Levashov |
||
3165 | **/ |
||
3166 | protected function childsByAttr($path, $attr, $val) { |
||
3174 | |||
3175 | /***************** get content *******************/ |
||
3176 | |||
3177 | /** |
||
3178 | * Return required dir's files info. |
||
3179 | * If onlyMimes is set - return only dirs and files of required mimes |
||
3180 | * |
||
3181 | * @param string $path dir path |
||
3182 | * @return array |
||
3183 | * @author Dmitry (dio) Levashov |
||
3184 | **/ |
||
3185 | protected function getScandir($path) { |
||
3198 | |||
3199 | |||
3200 | /** |
||
3201 | * Return subdirs tree |
||
3202 | * |
||
3203 | * @param string $path parent dir path |
||
3204 | * @param int $deep tree deep |
||
3205 | * @return array |
||
3206 | * @author Dmitry (dio) Levashov |
||
3207 | **/ |
||
3208 | protected function gettree($path, $deep, $exclude='') { |
||
3226 | |||
3227 | /** |
||
3228 | * Recursive files search |
||
3229 | * |
||
3230 | * @param string $path dir path |
||
3231 | * @param string $q search string |
||
3232 | * @param array $mimes |
||
3233 | * @return array |
||
3234 | * @author Dmitry (dio) Levashov |
||
3235 | **/ |
||
3236 | protected function doSearch($path, $q, $mimes) { |
||
3272 | |||
3273 | /********************** manuipulations ******************/ |
||
3274 | |||
3275 | /** |
||
3276 | * Copy file/recursive copy dir only in current volume. |
||
3277 | * Return new file path or false. |
||
3278 | * |
||
3279 | * @param string $src source path |
||
3280 | * @param string $dst destination dir path |
||
3281 | * @param string $name new file name (optionaly) |
||
3282 | * @return string|false |
||
3283 | * @author Dmitry (dio) Levashov |
||
3284 | **/ |
||
3285 | protected function copy($src, $dst, $name) { |
||
3327 | |||
3328 | /** |
||
3329 | * Move file |
||
3330 | * Return new file path or false. |
||
3331 | * |
||
3332 | * @param string $src source path |
||
3333 | * @param string $dst destination dir path |
||
3334 | * @param string $name new file name |
||
3335 | * @return string|false |
||
3336 | * @author Dmitry (dio) Levashov |
||
3337 | **/ |
||
3338 | protected function move($src, $dst, $name) { |
||
3352 | |||
3353 | /** |
||
3354 | * Copy file from another volume. |
||
3355 | * Return new file path or false. |
||
3356 | * |
||
3357 | * @param Object $volume source volume |
||
3358 | * @param string $src source file hash |
||
3359 | * @param string $destination destination dir path |
||
3360 | * @param string $name file name |
||
3361 | * @return string|false |
||
3362 | * @author Dmitry (dio) Levashov |
||
3363 | **/ |
||
3364 | protected function copyFrom($volume, $src, $destination, $name) { |
||
3426 | |||
3427 | /** |
||
3428 | * Remove file/ recursive remove dir |
||
3429 | * |
||
3430 | * @param string $path file path |
||
3431 | * @param bool $force try to remove even if file locked |
||
3432 | * @return bool |
||
3433 | * @author Dmitry (dio) Levashov |
||
3434 | **/ |
||
3435 | protected function remove($path, $force = false) { |
||
3465 | |||
3466 | |||
3467 | /************************* thumbnails **************************/ |
||
3468 | |||
3469 | /** |
||
3470 | * Return thumbnail file name for required file |
||
3471 | * |
||
3472 | * @param array $stat file stat |
||
3473 | * @return string |
||
3474 | * @author Dmitry (dio) Levashov |
||
3475 | **/ |
||
3476 | protected function tmbname($stat) { |
||
3479 | |||
3480 | /** |
||
3481 | * Return thumnbnail name if exists |
||
3482 | * |
||
3483 | * @param string $path file path |
||
3484 | * @param array $stat file stat |
||
3485 | * @return string|false |
||
3486 | * @author Dmitry (dio) Levashov |
||
3487 | **/ |
||
3488 | protected function gettmb($path, $stat) { |
||
3502 | |||
3503 | /** |
||
3504 | * Return true if thumnbnail for required file can be created |
||
3505 | * |
||
3506 | * @param string $path thumnbnail path |
||
3507 | * @param array $stat file stat |
||
3508 | * @param bool $checkTmbPath |
||
3509 | * @return string|bool |
||
3510 | * @author Dmitry (dio) Levashov |
||
3511 | **/ |
||
3512 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
3519 | |||
3520 | /** |
||
3521 | * Return true if required file can be resized. |
||
3522 | * By default - the same as canCreateTmb |
||
3523 | * |
||
3524 | * @param string $path thumnbnail path |
||
3525 | * @param array $stat file stat |
||
3526 | * @return string|bool |
||
3527 | * @author Dmitry (dio) Levashov |
||
3528 | **/ |
||
3529 | protected function canResize($path, $stat) { |
||
3532 | |||
3533 | /** |
||
3534 | * Create thumnbnail and return it's URL on success |
||
3535 | * |
||
3536 | * @param string $path file path |
||
3537 | * @param string $mime file mime type |
||
3538 | * @return string|false |
||
3539 | * @author Dmitry (dio) Levashov |
||
3540 | **/ |
||
3541 | protected function createTmb($path, $stat) { |
||
3611 | |||
3612 | /** |
||
3613 | * Resize image |
||
3614 | * |
||
3615 | * @param string $path image file |
||
3616 | * @param int $width new width |
||
3617 | * @param int $height new height |
||
3618 | * @param bool $keepProportions crop image |
||
3619 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
3620 | * @param string $destformat image destination format |
||
3621 | * @param int $jpgQuality JEPG quality (1-100) |
||
3622 | * @return string|false |
||
3623 | * @author Dmitry (dio) Levashov |
||
3624 | * @author Alexey Sukhotin |
||
3625 | **/ |
||
3626 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null, $jpgQuality = null) { |
||
3723 | |||
3724 | /** |
||
3725 | * Crop image |
||
3726 | * |
||
3727 | * @param string $path image file |
||
3728 | * @param int $width crop width |
||
3729 | * @param int $height crop height |
||
3730 | * @param bool $x crop left offset |
||
3731 | * @param bool $y crop top offset |
||
3732 | * @param string $destformat image destination format |
||
3733 | * @param int $jpgQuality JEPG quality (1-100) |
||
3734 | * @return string|false |
||
3735 | * @author Dmitry (dio) Levashov |
||
3736 | * @author Alexey Sukhotin |
||
3737 | **/ |
||
3738 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null, $jpgQuality = null) { |
||
3816 | |||
3817 | /** |
||
3818 | * Put image to square |
||
3819 | * |
||
3820 | * @param string $path image file |
||
3821 | * @param int $width square width |
||
3822 | * @param int $height square height |
||
3823 | * @param int $align reserved |
||
3824 | * @param int $valign reserved |
||
3825 | * @param string $bgcolor square background color in #rrggbb format |
||
3826 | * @param string $destformat image destination format |
||
3827 | * @param int $jpgQuality JEPG quality (1-100) |
||
3828 | * @return string|false |
||
3829 | * @author Dmitry (dio) Levashov |
||
3830 | * @author Alexey Sukhotin |
||
3831 | **/ |
||
3832 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null, $jpgQuality = null) { |
||
3913 | |||
3914 | /** |
||
3915 | * Rotate image |
||
3916 | * |
||
3917 | * @param string $path image file |
||
3918 | * @param int $degree rotete degrees |
||
3919 | * @param string $bgcolor square background color in #rrggbb format |
||
3920 | * @param string $destformat image destination format |
||
3921 | * @param int $jpgQuality JEPG quality (1-100) |
||
3922 | * @return string|false |
||
3923 | * @author nao-pon |
||
3924 | * @author Troex Nevelin |
||
3925 | **/ |
||
3926 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null, $jpgQuality = null) { |
||
4010 | |||
4011 | /** |
||
4012 | * Execute shell command |
||
4013 | * |
||
4014 | * @param string $command command line |
||
4015 | * @param array $output stdout strings |
||
4016 | * @param array $return_var process exit code |
||
4017 | * @param array $error_output stderr strings |
||
4018 | * @return int exit code |
||
4019 | * @author Alexey Sukhotin |
||
4020 | **/ |
||
4021 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
4051 | |||
4052 | /** |
||
4053 | * Remove thumbnail, also remove recursively if stat is directory |
||
4054 | * |
||
4055 | * @param string $stat file stat |
||
4056 | * @return void |
||
4057 | * @author Dmitry (dio) Levashov |
||
4058 | * @author Naoki Sawada |
||
4059 | * @author Troex Nevelin |
||
4060 | **/ |
||
4061 | protected function rmTmb($stat) { |
||
4074 | |||
4075 | /** |
||
4076 | * Create an gd image according to the specified mime type |
||
4077 | * |
||
4078 | * @param string $path image file |
||
4079 | * @param string $mime |
||
4080 | * @return gd image resource identifier |
||
4081 | */ |
||
4082 | protected function gdImageCreate($path,$mime){ |
||
4098 | |||
4099 | /** |
||
4100 | * Output gd image to file |
||
4101 | * |
||
4102 | * @param resource $image gd image resource |
||
4103 | * @param string $filename The path to save the file to. |
||
4104 | * @param string $destformat The Image type to use for $filename |
||
4105 | * @param string $mime The original image mime type |
||
4106 | * @param int $jpgQuality JEPG quality (1-100) |
||
4107 | */ |
||
4108 | protected function gdImage($image, $filename, $destformat, $mime, $jpgQuality = null ){ |
||
4123 | |||
4124 | /** |
||
4125 | * Output imagick image to file |
||
4126 | * |
||
4127 | * @param resource $img imagick image resource |
||
4128 | * @param string $filename The path to save the file to. |
||
4129 | * @param string $destformat The Image type to use for $filename |
||
4130 | * @param int $jpgQuality JEPG quality (1-100) |
||
4131 | */ |
||
4132 | protected function imagickImage($img, $filename, $destformat, $jpgQuality = null ){ |
||
4180 | |||
4181 | /** |
||
4182 | * Assign the proper background to a gd image |
||
4183 | * |
||
4184 | * @param resource $image gd image resource |
||
4185 | * @param string $bgcolor background color in #rrggbb format |
||
4186 | */ |
||
4187 | protected function gdImageBackground($image, $bgcolor){ |
||
4200 | |||
4201 | /*********************** misc *************************/ |
||
4202 | |||
4203 | /** |
||
4204 | * Return smart formatted date |
||
4205 | * |
||
4206 | * @param int $ts file timestamp |
||
4207 | * @return string |
||
4208 | * @author Dmitry (dio) Levashov |
||
4209 | **/ |
||
4210 | // protected function formatDate($ts) { |
||
4211 | // if ($ts > $this->today) { |
||
4212 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
4213 | // } |
||
4214 | // |
||
4215 | // if ($ts > $this->yesterday) { |
||
4216 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
4217 | // } |
||
4218 | // |
||
4219 | // return date($this->options['dateFormat'], $ts); |
||
4220 | // } |
||
4221 | |||
4222 | /** |
||
4223 | * Find position of first occurrence of string in a string with multibyte support |
||
4224 | * |
||
4225 | * @param string $haystack The string being checked. |
||
4226 | * @param string $needle The string to find in haystack. |
||
4227 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
4228 | * @return int|bool |
||
4229 | * @author Alexey Sukhotin |
||
4230 | **/ |
||
4231 | protected function stripos($haystack , $needle , $offset = 0) { |
||
4239 | |||
4240 | /** |
||
4241 | * Get server side available archivers |
||
4242 | * |
||
4243 | * @param bool $use_cache |
||
4244 | * @return array |
||
4245 | */ |
||
4246 | protected function getArchivers($use_cache = true) { |
||
4362 | |||
4363 | /** |
||
4364 | * Resolve relative / (Unix-like)absolute path |
||
4365 | * |
||
4366 | * @param string $path target path |
||
4367 | * @param string $base base path |
||
4368 | * @return string |
||
4369 | */ |
||
4370 | protected function getFullPath($path, $base) { |
||
4417 | |||
4418 | /** |
||
4419 | * Remove directory recursive on local file system |
||
4420 | * |
||
4421 | * @param string $dir Target dirctory path |
||
4422 | * @return boolean |
||
4423 | * @author Naoki Sawada |
||
4424 | */ |
||
4425 | public function rmdirRecursive($dir) { |
||
4445 | |||
4446 | /** |
||
4447 | * Create archive and return its path |
||
4448 | * |
||
4449 | * @param string $dir target dir |
||
4450 | * @param array $files files names list |
||
4451 | * @param string $name archive name |
||
4452 | * @param array $arc archiver options |
||
4453 | * @return string|bool |
||
4454 | * @author Dmitry (dio) Levashov, |
||
4455 | * @author Alexey Sukhotin |
||
4456 | * @author Naoki Sawada |
||
4457 | **/ |
||
4458 | protected function makeArchive($dir, $files, $name, $arc) { |
||
4476 | |||
4477 | /** |
||
4478 | * Unpack archive |
||
4479 | * |
||
4480 | * @param string $path archive path |
||
4481 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
4482 | * @param bool $remove remove archive ( unlink($path) ) |
||
4483 | * @return void |
||
4484 | * @author Dmitry (dio) Levashov |
||
4485 | * @author Alexey Sukhotin |
||
4486 | * @author Naoki Sawada |
||
4487 | **/ |
||
4488 | protected function unpackArchive($path, $arc, $remove = true) { |
||
4503 | |||
4504 | /** |
||
4505 | * Create Zip archive using PHP class ZipArchive |
||
4506 | * |
||
4507 | * @param string $dir target dir |
||
4508 | * @param array $files files names list |
||
4509 | * @param string|object $zipPath Zip archive name |
||
4510 | * @return void |
||
4511 | * @author Naoki Sawada |
||
4512 | */ |
||
4513 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
4551 | |||
4552 | /** |
||
4553 | * Unpack Zip archive using PHP class ZipArchive |
||
4554 | * |
||
4555 | * @param string $zipPath Zip archive name |
||
4556 | * @param string $toDir Extract to path |
||
4557 | * @return bool |
||
4558 | * @author Naoki Sawada |
||
4559 | */ |
||
4560 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
4572 | |||
4573 | /**==================================* abstract methods *====================================**/ |
||
4574 | |||
4575 | /*********************** paths/urls *************************/ |
||
4576 | |||
4577 | /** |
||
4578 | * Return parent directory path |
||
4579 | * |
||
4580 | * @param string $path file path |
||
4581 | * @return string |
||
4582 | * @author Dmitry (dio) Levashov |
||
4583 | **/ |
||
4584 | abstract protected function _dirname($path); |
||
4585 | |||
4586 | /** |
||
4587 | * Return file name |
||
4588 | * |
||
4589 | * @param string $path file path |
||
4590 | * @return string |
||
4591 | * @author Dmitry (dio) Levashov |
||
4592 | **/ |
||
4593 | abstract protected function _basename($path); |
||
4594 | |||
4595 | /** |
||
4596 | * Join dir name and file name and return full path. |
||
4597 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
4598 | * |
||
4599 | * @param string $dir dir path |
||
4600 | * @param string $name file name |
||
4601 | * @return string |
||
4602 | * @author Dmitry (dio) Levashov |
||
4603 | **/ |
||
4604 | abstract protected function _joinPath($dir, $name); |
||
4605 | |||
4606 | /** |
||
4607 | * Return normalized path |
||
4608 | * |
||
4609 | * @param string $path file path |
||
4610 | * @return string |
||
4611 | * @author Dmitry (dio) Levashov |
||
4612 | **/ |
||
4613 | abstract protected function _normpath($path); |
||
4614 | |||
4615 | /** |
||
4616 | * Return file path related to root dir |
||
4617 | * |
||
4618 | * @param string $path file path |
||
4619 | * @return string |
||
4620 | * @author Dmitry (dio) Levashov |
||
4621 | **/ |
||
4622 | abstract protected function _relpath($path); |
||
4623 | |||
4624 | /** |
||
4625 | * Convert path related to root dir into real path |
||
4626 | * |
||
4627 | * @param string $path rel file path |
||
4628 | * @return string |
||
4629 | * @author Dmitry (dio) Levashov |
||
4630 | **/ |
||
4631 | abstract protected function _abspath($path); |
||
4632 | |||
4633 | /** |
||
4634 | * Return fake path started from root dir. |
||
4635 | * Required to show path on client side. |
||
4636 | * |
||
4637 | * @param string $path file path |
||
4638 | * @return string |
||
4639 | * @author Dmitry (dio) Levashov |
||
4640 | **/ |
||
4641 | abstract protected function _path($path); |
||
4642 | |||
4643 | /** |
||
4644 | * Return true if $path is children of $parent |
||
4645 | * |
||
4646 | * @param string $path path to check |
||
4647 | * @param string $parent parent path |
||
4648 | * @return bool |
||
4649 | * @author Dmitry (dio) Levashov |
||
4650 | **/ |
||
4651 | abstract protected function _inpath($path, $parent); |
||
4652 | |||
4653 | /** |
||
4654 | * Return stat for given path. |
||
4655 | * Stat contains following fields: |
||
4656 | * - (int) size file size in b. required |
||
4657 | * - (int) ts file modification time in unix time. required |
||
4658 | * - (string) mime mimetype. required for folders, others - optionally |
||
4659 | * - (bool) read read permissions. required |
||
4660 | * - (bool) write write permissions. required |
||
4661 | * - (bool) locked is object locked. optionally |
||
4662 | * - (bool) hidden is object hidden. optionally |
||
4663 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
4664 | * - (string) target for symlinks - link target path. optionally |
||
4665 | * |
||
4666 | * If file does not exists - returns empty array or false. |
||
4667 | * |
||
4668 | * @param string $path file path |
||
4669 | * @return array|false |
||
4670 | * @author Dmitry (dio) Levashov |
||
4671 | **/ |
||
4672 | abstract protected function _stat($path); |
||
4673 | |||
4674 | |||
4675 | /***************** file stat ********************/ |
||
4676 | |||
4677 | |||
4678 | /** |
||
4679 | * Return true if path is dir and has at least one childs directory |
||
4680 | * |
||
4681 | * @param string $path dir path |
||
4682 | * @return bool |
||
4683 | * @author Dmitry (dio) Levashov |
||
4684 | **/ |
||
4685 | abstract protected function _subdirs($path); |
||
4686 | |||
4687 | /** |
||
4688 | * Return object width and height |
||
4689 | * Ususaly used for images, but can be realize for video etc... |
||
4690 | * |
||
4691 | * @param string $path file path |
||
4692 | * @param string $mime file mime type |
||
4693 | * @return string |
||
4694 | * @author Dmitry (dio) Levashov |
||
4695 | **/ |
||
4696 | abstract protected function _dimensions($path, $mime); |
||
4697 | |||
4698 | /******************** file/dir content *********************/ |
||
4699 | |||
4700 | /** |
||
4701 | * Return files list in directory |
||
4702 | * |
||
4703 | * @param string $path dir path |
||
4704 | * @return array |
||
4705 | * @author Dmitry (dio) Levashov |
||
4706 | **/ |
||
4707 | abstract protected function _scandir($path); |
||
4708 | |||
4709 | /** |
||
4710 | * Open file and return file pointer |
||
4711 | * |
||
4712 | * @param string $path file path |
||
4713 | * @param bool $write open file for writing |
||
4714 | * @return resource|false |
||
4715 | * @author Dmitry (dio) Levashov |
||
4716 | **/ |
||
4717 | abstract protected function _fopen($path, $mode="rb"); |
||
4718 | |||
4719 | /** |
||
4720 | * Close opened file |
||
4721 | * |
||
4722 | * @param resource $fp file pointer |
||
4723 | * @param string $path file path |
||
4724 | * @return bool |
||
4725 | * @author Dmitry (dio) Levashov |
||
4726 | **/ |
||
4727 | abstract protected function _fclose($fp, $path=''); |
||
4728 | |||
4729 | /******************** file/dir manipulations *************************/ |
||
4730 | |||
4731 | /** |
||
4732 | * Create dir and return created dir path or false on failed |
||
4733 | * |
||
4734 | * @param string $path parent dir path |
||
4735 | * @param string $name new directory name |
||
4736 | * @return string|bool |
||
4737 | * @author Dmitry (dio) Levashov |
||
4738 | **/ |
||
4739 | abstract protected function _mkdir($path, $name); |
||
4740 | |||
4741 | /** |
||
4742 | * Create file and return it's path or false on failed |
||
4743 | * |
||
4744 | * @param string $path parent dir path |
||
4745 | * @param string $name new file name |
||
4746 | * @return string|bool |
||
4747 | * @author Dmitry (dio) Levashov |
||
4748 | **/ |
||
4749 | abstract protected function _mkfile($path, $name); |
||
4750 | |||
4751 | /** |
||
4752 | * Create symlink |
||
4753 | * |
||
4754 | * @param string $source file to link to |
||
4755 | * @param string $targetDir folder to create link in |
||
4756 | * @param string $name symlink name |
||
4757 | * @return bool |
||
4758 | * @author Dmitry (dio) Levashov |
||
4759 | **/ |
||
4760 | abstract protected function _symlink($source, $targetDir, $name); |
||
4761 | |||
4762 | /** |
||
4763 | * Copy file into another file (only inside one volume) |
||
4764 | * |
||
4765 | * @param string $source source file path |
||
4766 | * @param string $target target dir path |
||
4767 | * @param string $name file name |
||
4768 | * @return bool |
||
4769 | * @author Dmitry (dio) Levashov |
||
4770 | **/ |
||
4771 | abstract protected function _copy($source, $targetDir, $name); |
||
4772 | |||
4773 | /** |
||
4774 | * Move file into another parent dir. |
||
4775 | * Return new file path or false. |
||
4776 | * |
||
4777 | * @param string $source source file path |
||
4778 | * @param string $target target dir path |
||
4779 | * @param string $name file name |
||
4780 | * @return string|bool |
||
4781 | * @author Dmitry (dio) Levashov |
||
4782 | **/ |
||
4783 | abstract protected function _move($source, $targetDir, $name); |
||
4784 | |||
4785 | /** |
||
4786 | * Remove file |
||
4787 | * |
||
4788 | * @param string $path file path |
||
4789 | * @return bool |
||
4790 | * @author Dmitry (dio) Levashov |
||
4791 | **/ |
||
4792 | abstract protected function _unlink($path); |
||
4793 | |||
4794 | /** |
||
4795 | * Remove dir |
||
4796 | * |
||
4797 | * @param string $path dir path |
||
4798 | * @return bool |
||
4799 | * @author Dmitry (dio) Levashov |
||
4800 | **/ |
||
4801 | abstract protected function _rmdir($path); |
||
4802 | |||
4803 | /** |
||
4804 | * Create new file and write into it from file pointer. |
||
4805 | * Return new file path or false on error. |
||
4806 | * |
||
4807 | * @param resource $fp file pointer |
||
4808 | * @param string $dir target dir path |
||
4809 | * @param string $name file name |
||
4810 | * @param array $stat file stat (required by some virtual fs) |
||
4811 | * @return bool|string |
||
4812 | * @author Dmitry (dio) Levashov |
||
4813 | **/ |
||
4814 | abstract protected function _save($fp, $dir, $name, $stat); |
||
4815 | |||
4816 | /** |
||
4817 | * Get file contents |
||
4818 | * |
||
4819 | * @param string $path file path |
||
4820 | * @return string|false |
||
4821 | * @author Dmitry (dio) Levashov |
||
4822 | **/ |
||
4823 | abstract protected function _getContents($path); |
||
4824 | |||
4825 | /** |
||
4826 | * Write a string to a file |
||
4827 | * |
||
4828 | * @param string $path file path |
||
4829 | * @param string $content new file content |
||
4830 | * @return bool |
||
4831 | * @author Dmitry (dio) Levashov |
||
4832 | **/ |
||
4833 | abstract protected function _filePutContents($path, $content); |
||
4834 | |||
4835 | /** |
||
4836 | * Extract files from archive |
||
4837 | * |
||
4838 | * @param string $path file path |
||
4839 | * @param array $arc archiver options |
||
4840 | * @return bool |
||
4841 | * @author Dmitry (dio) Levashov, |
||
4842 | * @author Alexey Sukhotin |
||
4843 | **/ |
||
4844 | abstract protected function _extract($path, $arc); |
||
4845 | |||
4846 | /** |
||
4847 | * Create archive and return its path |
||
4848 | * |
||
4849 | * @param string $dir target dir |
||
4850 | * @param array $files files names list |
||
4851 | * @param string $name archive name |
||
4852 | * @param array $arc archiver options |
||
4853 | * @return string|bool |
||
4854 | * @author Dmitry (dio) Levashov, |
||
4855 | * @author Alexey Sukhotin |
||
4856 | **/ |
||
4857 | abstract protected function _archive($dir, $files, $name, $arc); |
||
4858 | |||
4859 | /** |
||
4860 | * Detect available archivers |
||
4861 | * |
||
4862 | * @return void |
||
4863 | * @author Dmitry (dio) Levashov, |
||
4864 | * @author Alexey Sukhotin |
||
4865 | **/ |
||
4866 | abstract protected function _checkArchivers(); |
||
4867 | |||
4868 | /** |
||
4869 | * Change file mode (chmod) |
||
4870 | * |
||
4871 | * @param string $path file path |
||
4872 | * @param string $mode octal string such as '0755' |
||
4873 | * @return bool |
||
4874 | * @author David Bartle, |
||
4875 | **/ |
||
4876 | abstract protected function _chmod($path, $mode); |
||
4877 | |||
4878 | |||
4879 | } // END class |
||
4880 |
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.