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 | * Net mount key. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | **/ |
||
| 21 | public $netMountKey = ''; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Request args |
||
| 25 | * $_POST or $_GET values. |
||
| 26 | * |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | protected $ARGS = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Driver id |
||
| 33 | * Must be started from letter and contains [a-z0-9] |
||
| 34 | * Used as part of volume id. |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | **/ |
||
| 38 | protected $driverId = 'a'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Volume id - used as prefix for files hashes. |
||
| 42 | * |
||
| 43 | * @var string |
||
| 44 | **/ |
||
| 45 | protected $id = ''; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Flag - volume "mounted" and available. |
||
| 49 | * |
||
| 50 | * @var bool |
||
| 51 | **/ |
||
| 52 | protected $mounted = false; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Root directory path. |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | **/ |
||
| 59 | protected $root = ''; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Root basename | alias. |
||
| 63 | * |
||
| 64 | * @var string |
||
| 65 | **/ |
||
| 66 | protected $rootName = ''; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Default directory to open. |
||
| 70 | * |
||
| 71 | * @var string |
||
| 72 | **/ |
||
| 73 | protected $startPath = ''; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Base URL. |
||
| 77 | * |
||
| 78 | * @var string |
||
| 79 | **/ |
||
| 80 | protected $URL = ''; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * A file save destination path when a temporary content URL is required |
||
| 84 | * on a network volume or the like |
||
| 85 | * If not specified, it tries to use "Connector Path/../files/.tmb". |
||
| 86 | * |
||
| 87 | * @var string |
||
| 88 | */ |
||
| 89 | protected $tmpLinkPath = ''; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * A file save destination URL when a temporary content URL is required |
||
| 93 | * on a network volume or the like |
||
| 94 | * If not specified, it tries to use "Connector URL/../files/.tmb". |
||
| 95 | * |
||
| 96 | * @var string |
||
| 97 | */ |
||
| 98 | protected $tmpLinkUrl = ''; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Thumbnails dir path. |
||
| 102 | * |
||
| 103 | * @var string |
||
| 104 | **/ |
||
| 105 | protected $tmbPath = ''; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Is thumbnails dir writable. |
||
| 109 | * |
||
| 110 | * @var bool |
||
| 111 | **/ |
||
| 112 | protected $tmbPathWritable = false; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Thumbnails base URL. |
||
| 116 | * |
||
| 117 | * @var string |
||
| 118 | **/ |
||
| 119 | protected $tmbURL = ''; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Thumbnails size in px. |
||
| 123 | * |
||
| 124 | * @var int |
||
| 125 | **/ |
||
| 126 | protected $tmbSize = 48; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Image manipulation lib name |
||
| 130 | * auto|imagick|gd|convert. |
||
| 131 | * |
||
| 132 | * @var string |
||
| 133 | **/ |
||
| 134 | protected $imgLib = 'auto'; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Video to Image converter. |
||
| 138 | * |
||
| 139 | * @var array |
||
| 140 | */ |
||
| 141 | protected $imgConverter = []; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Library to crypt files name. |
||
| 145 | * |
||
| 146 | * @var string |
||
| 147 | **/ |
||
| 148 | protected $cryptLib = ''; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Archivers config. |
||
| 152 | * |
||
| 153 | * @var array |
||
| 154 | **/ |
||
| 155 | protected $archivers = [ |
||
| 156 | 'create' => [], |
||
| 157 | 'extract' => [], |
||
| 158 | ]; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Server character encoding. |
||
| 162 | * |
||
| 163 | * @var string or null |
||
| 164 | **/ |
||
| 165 | protected $encoding = null; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * How many subdirs levels return for tree. |
||
| 169 | * |
||
| 170 | * @var int |
||
| 171 | **/ |
||
| 172 | protected $treeDeep = 1; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Errors from last failed action. |
||
| 176 | * |
||
| 177 | * @var array |
||
| 178 | **/ |
||
| 179 | protected $error = []; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Today 24:00 timestamp. |
||
| 183 | * |
||
| 184 | * @var int |
||
| 185 | **/ |
||
| 186 | protected $today = 0; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Yesterday 24:00 timestamp. |
||
| 190 | * |
||
| 191 | * @var int |
||
| 192 | **/ |
||
| 193 | protected $yesterday = 0; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Force make dirctory on extract. |
||
| 197 | * |
||
| 198 | * @var int |
||
| 199 | **/ |
||
| 200 | protected $extractToNewdir = 'auto'; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Object configuration. |
||
| 204 | * |
||
| 205 | * @var array |
||
| 206 | **/ |
||
| 207 | protected $options = [ |
||
| 208 | // Driver ID (Prefix of volume ID), Normally, the value specified for each volume driver is used. |
||
| 209 | 'driverId' => '', |
||
| 210 | // Id (Suffix of volume ID), Normally, the number incremented according to the specified number of volumes is used. |
||
| 211 | 'id' => '', |
||
| 212 | // revision id of root directory that uses for caching control of root stat |
||
| 213 | 'rootRev' => '', |
||
| 214 | // driver type it uses volume root's CSS class name. e.g. 'group' -> Adds 'elfinder-group' to CSS class name. |
||
| 215 | 'type' => '', |
||
| 216 | // root directory path |
||
| 217 | 'path' => '', |
||
| 218 | // Folder hash value on elFinder to be the parent of this volume |
||
| 219 | 'phash' => '', |
||
| 220 | // Folder hash value on elFinder to trash bin of this volume, it require 'copyJoin' to true |
||
| 221 | 'trashHash' => '', |
||
| 222 | // open this path on initial request instead of root path |
||
| 223 | 'startPath' => '', |
||
| 224 | // how many subdirs levels return per request |
||
| 225 | 'treeDeep' => 1, |
||
| 226 | // root url, not set to disable sending URL to client (replacement for old "fileURL" option) |
||
| 227 | 'URL' => '', |
||
| 228 | // directory link url to own manager url with folder hash (`true`, `false` or default `'auto'`: URL is empty then `true` else `false`) |
||
| 229 | 'dirUrlOwn' => 'auto', |
||
| 230 | // directory separator. required by client to show paths correctly |
||
| 231 | 'separator' => DIRECTORY_SEPARATOR, |
||
| 232 | // Server character encoding (default is '': UTF-8) |
||
| 233 | 'encoding' => '', |
||
| 234 | // for convert character encoding (default is '': Not change locale) |
||
| 235 | 'locale' => '', |
||
| 236 | // URL of volume icon (16x16 pixel image file) |
||
| 237 | 'icon' => '', |
||
| 238 | // CSS Class of volume root in tree |
||
| 239 | 'rootCssClass' => '', |
||
| 240 | // Items to disable session caching |
||
| 241 | 'noSessionCache' => [], |
||
| 242 | // enable i18n folder name that convert name to elFinderInstance.messages['folder_'+name] |
||
| 243 | 'i18nFolderName' => false, |
||
| 244 | // Search timeout (sec) |
||
| 245 | 'searchTimeout' => 30, |
||
| 246 | // Search exclusion directory regex pattern (require demiliter e.g. '#/path/to/exclude_directory#i') |
||
| 247 | 'searchExDirReg' => '', |
||
| 248 | // library to crypt/uncrypt files names (not implemented) |
||
| 249 | 'cryptLib' => '', |
||
| 250 | // how to detect files mimetypes. (auto/internal/finfo/mime_content_type) |
||
| 251 | 'mimeDetect' => 'auto', |
||
| 252 | // mime.types file path (for mimeDetect==internal) |
||
| 253 | 'mimefile' => '', |
||
| 254 | // Static extension/MIME of general server side scripts to security issues |
||
| 255 | 'staticMineMap' => [ |
||
| 256 | 'php:*' => 'text/x-php', |
||
| 257 | 'php3:*' => 'text/x-php', |
||
| 258 | 'php4:*' => 'text/x-php', |
||
| 259 | 'php5:*' => 'text/x-php', |
||
| 260 | 'phtml:*' => 'text/x-php', |
||
| 261 | 'cgi:*' => 'text/x-httpd-cgi', |
||
| 262 | 'pl:*' => 'text/x-perl', |
||
| 263 | 'asp:*' => 'text/x-asap', |
||
| 264 | 'aspx:*' => 'text/x-asap', |
||
| 265 | 'py:*' => 'text/x-python', |
||
| 266 | 'rb:*' => 'text/x-ruby', |
||
| 267 | 'jsp:*' => 'text/x-jsp', |
||
| 268 | ], |
||
| 269 | // mime type normalize map : Array '[ext]:[detected mime type]' => '[normalized mime]' |
||
| 270 | 'mimeMap' => [ |
||
| 271 | 'md:application/x-genesis-rom' => 'text/x-markdown', |
||
| 272 | 'md:text/plain' => 'text/x-markdown', |
||
| 273 | 'markdown:text/plain' => 'text/x-markdown', |
||
| 274 | 'css:text/x-asm' => 'text/css', |
||
| 275 | 'ico:image/vnd.microsoft.icon' => 'image/x-icon', |
||
| 276 | 'csv:text/plain' => 'text/csv', |
||
| 277 | 'm4a:video/mp4' => 'audio/mp4', |
||
| 278 | 'oga:application/ogg' => 'audio/ogg', |
||
| 279 | 'ogv:application/ogg' => 'video/ogg', |
||
| 280 | 'zip:application/x-zip' => 'application/zip', |
||
| 281 | ], |
||
| 282 | // An option to add MimeMap to the `mimeMap` option |
||
| 283 | // Array '[ext]:[detected mime type]' => '[normalized mime]' |
||
| 284 | 'additionalMimeMap' => [], |
||
| 285 | // MIME regex of send HTTP header "Content-Disposition: inline" or allow preview in quicklook |
||
| 286 | // '.' is allow inline of all of MIME types |
||
| 287 | // '$^' is not allow inline of all of MIME types |
||
| 288 | 'dispInlineRegex' => '^(?:(?:image|video|audio)|(?:text/plain|application/pdf)$)', |
||
| 289 | // temporary content URL's base path |
||
| 290 | 'tmpLinkPath' => '', |
||
| 291 | // temporary content URL's base URL |
||
| 292 | 'tmpLinkUrl' => '', |
||
| 293 | // directory for thumbnails |
||
| 294 | 'tmbPath' => '.tmb', |
||
| 295 | // mode to create thumbnails dir |
||
| 296 | 'tmbPathMode' => 0777, |
||
| 297 | // thumbnails dir URL. Set it if store thumbnails outside root directory |
||
| 298 | 'tmbURL' => '', |
||
| 299 | // thumbnails size (px) |
||
| 300 | 'tmbSize' => 48, |
||
| 301 | // thumbnails crop (true - crop, false - scale image to fit thumbnail size) |
||
| 302 | 'tmbCrop' => true, |
||
| 303 | // thumbnails background color (hex #rrggbb or 'transparent') |
||
| 304 | 'tmbBgColor' => 'transparent', |
||
| 305 | // image rotate fallback background color (hex #rrggbb) |
||
| 306 | 'bgColorFb' => '#ffffff', |
||
| 307 | // image manipulations library |
||
| 308 | 'imgLib' => 'auto', |
||
| 309 | // Fallback self image to thumbnail (nothing imgLib) |
||
| 310 | 'tmbFbSelf' => true, |
||
| 311 | // Video to Image converters ['TYPE or MIME' => ['func' => function($file){ /* Converts $file to Image */ return true; }, 'maxlen' => (int)TransferLength]] |
||
| 312 | 'imgConverter' => [], |
||
| 313 | // Max length of transfer to image converter |
||
| 314 | 'tmbVideoConvLen' => 10000000, |
||
| 315 | // Captre point seccond |
||
| 316 | 'tmbVideoConvSec' => 6, |
||
| 317 | // Resource path of fallback icon images defailt: php/resouces |
||
| 318 | 'resourcePath' => '', |
||
| 319 | // Jpeg image saveing quality |
||
| 320 | 'jpgQuality' => 100, |
||
| 321 | // on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 322 | 'copyOverwrite' => true, |
||
| 323 | // if true - join new and old directories content on paste |
||
| 324 | 'copyJoin' => true, |
||
| 325 | // on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 326 | 'uploadOverwrite' => true, |
||
| 327 | // mimetypes allowed to upload |
||
| 328 | 'uploadAllow' => [], |
||
| 329 | // mimetypes not allowed to upload |
||
| 330 | 'uploadDeny' => [], |
||
| 331 | // order to proccess uploadAllow and uploadDeny options |
||
| 332 | 'uploadOrder' => ['deny', 'allow'], |
||
| 333 | // maximum upload file size. NOTE - this is size for every uploaded files |
||
| 334 | 'uploadMaxSize' => 0, |
||
| 335 | // maximum number of chunked upload connection. `-1` to disable chunked upload |
||
| 336 | 'uploadMaxConn' => 3, |
||
| 337 | // maximum get file size. NOTE - Maximum value is 50% of PHP memory_limit |
||
| 338 | 'getMaxSize' => 0, |
||
| 339 | // files dates format |
||
| 340 | 'dateFormat' => 'j M Y H:i', |
||
| 341 | // files time format |
||
| 342 | 'timeFormat' => 'H:i', |
||
| 343 | // if true - every folder will be check for children folders, -1 - every folder will be check asynchronously, false - all folders will be marked as having subfolders |
||
| 344 | 'checkSubfolders' => true, // true, false or -1 |
||
| 345 | // allow to copy from this volume to other ones? |
||
| 346 | 'copyFrom' => true, |
||
| 347 | // allow to copy from other volumes to this one? |
||
| 348 | 'copyTo' => true, |
||
| 349 | // cmd duplicate suffix format e.g. '_%s_' to without spaces |
||
| 350 | 'duplicateSuffix' => ' %s ', |
||
| 351 | // unique name numbar format e.g. '(%d)' to (1), (2)... |
||
| 352 | 'uniqueNumFormat' => '%d', |
||
| 353 | // list of commands disabled on this root |
||
| 354 | 'disabled' => [], |
||
| 355 | // enable file owner, group & mode info, `false` to inactivate "chmod" command. |
||
| 356 | 'statOwner' => false, |
||
| 357 | // allow exec chmod of read-only files |
||
| 358 | 'allowChmodReadOnly' => false, |
||
| 359 | // regexp or function name to validate new file name |
||
| 360 | 'acceptedName' => '/^[^\.].*/', // Notice: overwritten it in some volume drivers contractor |
||
| 361 | // regexp or function name to validate new directory name |
||
| 362 | 'acceptedDirname' => '', // used `acceptedName` if empty value |
||
| 363 | // function/class method to control files permissions |
||
| 364 | 'accessControl' => null, |
||
| 365 | // some data required by access control |
||
| 366 | 'accessControlData' => null, |
||
| 367 | // default permissions. |
||
| 368 | 'defaults' => [ |
||
| 369 | 'read' => true, |
||
| 370 | 'write' => true, |
||
| 371 | 'locked' => false, |
||
| 372 | 'hidden' => false, |
||
| 373 | ], |
||
| 374 | // files attributes |
||
| 375 | 'attributes' => [], |
||
| 376 | // max allowed archive files size (0 - no limit) |
||
| 377 | 'maxArcFilesSize' => 0, |
||
| 378 | // Allowed archive's mimetypes to create. Leave empty for all available types. |
||
| 379 | 'archiveMimes' => [], |
||
| 380 | // Manual config for archivers. See example below. Leave empty for auto detect |
||
| 381 | 'archivers' => [], |
||
| 382 | // plugin settings |
||
| 383 | 'plugin' => [], |
||
| 384 | // Is support parent directory time stamp update on add|remove|rename item |
||
| 385 | // Default `null` is auto detection that is LocalFileSystem, FTP or Dropbox are `true` |
||
| 386 | 'syncChkAsTs' => null, |
||
| 387 | // Long pooling sync checker function for syncChkAsTs is true |
||
| 388 | // Calls with args (TARGET DIRCTORY PATH, STAND-BY(sec), OLD TIMESTAMP, VOLUME DRIVER INSTANCE, ELFINDER INSTANCE) |
||
| 389 | // This function must return the following values. Changed: New Timestamp or Same: Old Timestamp or Error: false |
||
| 390 | // Default `null` is try use elFinderVolumeLocalFileSystem::localFileSystemInotify() on LocalFileSystem driver |
||
| 391 | // another driver use elFinder stat() checker |
||
| 392 | 'syncCheckFunc' => null, |
||
| 393 | // Long polling sync stand-by time (sec) |
||
| 394 | 'plStandby' => 30, |
||
| 395 | // Sleep time (sec) for elFinder stat() checker (syncChkAsTs is true) |
||
| 396 | 'tsPlSleep' => 10, |
||
| 397 | // Sleep time (sec) for elFinder ls() checker (syncChkAsTs is false) |
||
| 398 | 'lsPlSleep' => 30, |
||
| 399 | // Client side sync interval minimum (ms) |
||
| 400 | // Default `null` is auto set to ('tsPlSleep' or 'lsPlSleep') * 1000 |
||
| 401 | // `0` to disable auto sync |
||
| 402 | 'syncMinMs' => null, |
||
| 403 | // required to fix bug on macos |
||
| 404 | // However, we recommend to use the Normalizer plugin instead this option |
||
| 405 | 'utf8fix' => false, |
||
| 406 | // й ё Й Ё Ø Å |
||
| 407 | 'utf8patterns' => ["\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"], |
||
| 408 | 'utf8replace' => ["\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5"], |
||
| 409 | ]; |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Defaults permissions. |
||
| 413 | * |
||
| 414 | * @var array |
||
| 415 | **/ |
||
| 416 | protected $defaults = [ |
||
| 417 | 'read' => true, |
||
| 418 | 'write' => true, |
||
| 419 | 'locked' => false, |
||
| 420 | 'hidden' => false, |
||
| 421 | ]; |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Access control function/class. |
||
| 425 | * |
||
| 426 | * @var mixed |
||
| 427 | **/ |
||
| 428 | protected $attributes = []; |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Access control function/class. |
||
| 432 | * |
||
| 433 | * @var mixed |
||
| 434 | **/ |
||
| 435 | protected $access = null; |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Mime types allowed to upload. |
||
| 439 | * |
||
| 440 | * @var array |
||
| 441 | **/ |
||
| 442 | protected $uploadAllow = []; |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Mime types denied to upload. |
||
| 446 | * |
||
| 447 | * @var array |
||
| 448 | **/ |
||
| 449 | protected $uploadDeny = []; |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Order to validate uploadAllow and uploadDeny. |
||
| 453 | * |
||
| 454 | * @var array |
||
| 455 | **/ |
||
| 456 | protected $uploadOrder = []; |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Maximum allowed upload file size. |
||
| 460 | * Set as number or string with unit - "10M", "500K", "1G". |
||
| 461 | * |
||
| 462 | * @var int|string |
||
| 463 | **/ |
||
| 464 | protected $uploadMaxSize = 0; |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Run time setting of overwrite items on upload. |
||
| 468 | * |
||
| 469 | * @var string |
||
| 470 | */ |
||
| 471 | protected $uploadOverwrite = true; |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Maximum allowed get file size. |
||
| 475 | * Set as number or string with unit - "10M", "500K", "1G". |
||
| 476 | * |
||
| 477 | * @var int|string |
||
| 478 | **/ |
||
| 479 | protected $getMaxSize = -1; |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Mimetype detect method. |
||
| 483 | * |
||
| 484 | * @var string |
||
| 485 | **/ |
||
| 486 | protected $mimeDetect = 'auto'; |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Finfo object for mimeDetect == 'finfo'. |
||
| 490 | * |
||
| 491 | * @var object |
||
| 492 | **/ |
||
| 493 | protected $finfo = null; |
||
| 494 | |||
| 495 | /** |
||
| 496 | * List of disabled client's commands. |
||
| 497 | * |
||
| 498 | * @var array |
||
| 499 | **/ |
||
| 500 | protected $disabled = []; |
||
| 501 | |||
| 502 | /** |
||
| 503 | * default extensions/mimetypes for mimeDetect == 'internal'. |
||
| 504 | * |
||
| 505 | * @var array |
||
| 506 | **/ |
||
| 507 | protected static $mimetypes = [ |
||
| 508 | // applications |
||
| 509 | 'ai' => 'application/postscript', |
||
| 510 | 'eps' => 'application/postscript', |
||
| 511 | 'exe' => 'application/x-executable', |
||
| 512 | 'doc' => 'application/msword', |
||
| 513 | 'dot' => 'application/msword', |
||
| 514 | 'xls' => 'application/vnd.ms-excel', |
||
| 515 | 'xlt' => 'application/vnd.ms-excel', |
||
| 516 | 'xla' => 'application/vnd.ms-excel', |
||
| 517 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
| 518 | 'pps' => 'application/vnd.ms-powerpoint', |
||
| 519 | 'pdf' => 'application/pdf', |
||
| 520 | 'xml' => 'application/xml', |
||
| 521 | 'swf' => 'application/x-shockwave-flash', |
||
| 522 | 'torrent' => 'application/x-bittorrent', |
||
| 523 | 'jar' => 'application/x-jar', |
||
| 524 | // open office (finfo detect as application/zip) |
||
| 525 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
| 526 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
| 527 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
| 528 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
| 529 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
| 530 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
| 531 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
| 532 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
| 533 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
| 534 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
| 535 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
| 536 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
| 537 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
| 538 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
| 539 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
| 540 | // MS office 2007 (finfo detect as application/zip) |
||
| 541 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
| 542 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
| 543 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
| 544 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
| 545 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
| 546 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
| 547 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
| 548 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
| 549 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
| 550 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
| 551 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
| 552 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
| 553 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
| 554 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
| 555 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
| 556 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
| 557 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
| 558 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
| 559 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
| 560 | // archives |
||
| 561 | 'gz' => 'application/x-gzip', |
||
| 562 | 'tgz' => 'application/x-gzip', |
||
| 563 | 'bz' => 'application/x-bzip2', |
||
| 564 | 'bz2' => 'application/x-bzip2', |
||
| 565 | 'tbz' => 'application/x-bzip2', |
||
| 566 | 'xz' => 'application/x-xz', |
||
| 567 | 'zip' => 'application/zip', |
||
| 568 | 'rar' => 'application/x-rar', |
||
| 569 | 'tar' => 'application/x-tar', |
||
| 570 | '7z' => 'application/x-7z-compressed', |
||
| 571 | // texts |
||
| 572 | 'txt' => 'text/plain', |
||
| 573 | 'php' => 'text/x-php', |
||
| 574 | 'html' => 'text/html', |
||
| 575 | 'htm' => 'text/html', |
||
| 576 | 'js' => 'text/javascript', |
||
| 577 | 'css' => 'text/css', |
||
| 578 | 'rtf' => 'text/rtf', |
||
| 579 | 'rtfd' => 'text/rtfd', |
||
| 580 | 'py' => 'text/x-python', |
||
| 581 | 'java' => 'text/x-java-source', |
||
| 582 | 'rb' => 'text/x-ruby', |
||
| 583 | 'sh' => 'text/x-shellscript', |
||
| 584 | 'pl' => 'text/x-perl', |
||
| 585 | //'xml' => 'text/xml', |
||
| 586 | 'sql' => 'text/x-sql', |
||
| 587 | 'c' => 'text/x-csrc', |
||
| 588 | 'h' => 'text/x-chdr', |
||
| 589 | 'cpp' => 'text/x-c++src', |
||
| 590 | 'hh' => 'text/x-c++hdr', |
||
| 591 | 'log' => 'text/plain', |
||
| 592 | 'csv' => 'text/csv', |
||
| 593 | 'md' => 'text/x-markdown', |
||
| 594 | 'markdown' => 'text/x-markdown', |
||
| 595 | // images |
||
| 596 | 'bmp' => 'image/x-ms-bmp', |
||
| 597 | 'jpg' => 'image/jpeg', |
||
| 598 | 'jpeg' => 'image/jpeg', |
||
| 599 | 'gif' => 'image/gif', |
||
| 600 | 'png' => 'image/png', |
||
| 601 | 'tif' => 'image/tiff', |
||
| 602 | 'tiff' => 'image/tiff', |
||
| 603 | 'tga' => 'image/x-targa', |
||
| 604 | 'psd' => 'image/vnd.adobe.photoshop', |
||
| 605 | //'ai' => 'image/vnd.adobe.photoshop', |
||
| 606 | 'xbm' => 'image/xbm', |
||
| 607 | 'pxm' => 'image/pxm', |
||
| 608 | //audio |
||
| 609 | 'mp3' => 'audio/mpeg', |
||
| 610 | 'mid' => 'audio/midi', |
||
| 611 | 'ogg' => 'audio/ogg', |
||
| 612 | 'oga' => 'audio/ogg', |
||
| 613 | 'm4a' => 'audio/mp4', |
||
| 614 | 'wav' => 'audio/wav', |
||
| 615 | 'wma' => 'audio/x-ms-wma', |
||
| 616 | // video |
||
| 617 | 'avi' => 'video/x-msvideo', |
||
| 618 | 'dv' => 'video/x-dv', |
||
| 619 | 'mp4' => 'video/mp4', |
||
| 620 | 'mpeg' => 'video/mpeg', |
||
| 621 | 'mpg' => 'video/mpeg', |
||
| 622 | 'mov' => 'video/quicktime', |
||
| 623 | 'wm' => 'video/x-ms-wmv', |
||
| 624 | 'flv' => 'video/x-flv', |
||
| 625 | 'mkv' => 'video/x-matroska', |
||
| 626 | 'webm' => 'video/webm', |
||
| 627 | 'ogv' => 'video/ogg', |
||
| 628 | 'ogm' => 'video/ogg', |
||
| 629 | ]; |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Directory separator - required by client. |
||
| 633 | * |
||
| 634 | * @var string |
||
| 635 | **/ |
||
| 636 | protected $separator = DIRECTORY_SEPARATOR; |
||
| 637 | |||
| 638 | /** |
||
| 639 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...). |
||
| 640 | * |
||
| 641 | * @var string |
||
| 642 | **/ |
||
| 643 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Mimetypes allowed to display. |
||
| 647 | * |
||
| 648 | * @var array |
||
| 649 | **/ |
||
| 650 | protected $onlyMimes = []; |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Store files moved or overwrited files info. |
||
| 654 | * |
||
| 655 | * @var array |
||
| 656 | **/ |
||
| 657 | protected $removed = []; |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Store files added files info. |
||
| 661 | * |
||
| 662 | * @var array |
||
| 663 | **/ |
||
| 664 | protected $added = []; |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Cache storage. |
||
| 668 | * |
||
| 669 | * @var array |
||
| 670 | **/ |
||
| 671 | protected $cache = []; |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Cache by folders. |
||
| 675 | * |
||
| 676 | * @var array |
||
| 677 | **/ |
||
| 678 | protected $dirsCache = []; |
||
| 679 | |||
| 680 | /** |
||
| 681 | * You should use `$this->sessionCache['subdirs']` instead. |
||
| 682 | * |
||
| 683 | * @var array |
||
| 684 | * @deprecated |
||
| 685 | */ |
||
| 686 | protected $subdirsCache = []; |
||
| 687 | |||
| 688 | /** |
||
| 689 | * This volume session cache. |
||
| 690 | * |
||
| 691 | * @var array |
||
| 692 | */ |
||
| 693 | protected $sessionCache; |
||
| 694 | |||
| 695 | /** |
||
| 696 | * Session caching item list. |
||
| 697 | * |
||
| 698 | * @var array |
||
| 699 | */ |
||
| 700 | protected $sessionCaching = ['rootstat' => true, 'subdirs' => true]; |
||
| 701 | |||
| 702 | /** |
||
| 703 | * elFinder session wrapper object. |
||
| 704 | * |
||
| 705 | * @var elFinderSessionInterface |
||
| 706 | */ |
||
| 707 | protected $session; |
||
| 708 | |||
| 709 | /** |
||
| 710 | * Search start time. |
||
| 711 | * |
||
| 712 | * @var int |
||
| 713 | */ |
||
| 714 | protected $searchStart; |
||
| 715 | |||
| 716 | /** |
||
| 717 | * Current query word on doSearch. |
||
| 718 | * |
||
| 719 | * @var string |
||
| 720 | **/ |
||
| 721 | protected $doSearchCurrentQuery = []; |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Is root modified (for clear root stat cache). |
||
| 725 | * |
||
| 726 | * @var bool |
||
| 727 | */ |
||
| 728 | protected $rootModified = false; |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Is disable of command `url`. |
||
| 732 | * |
||
| 733 | * @var string |
||
| 734 | */ |
||
| 735 | protected $disabledGetUrl = false; |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Accepted filename validator. |
||
| 739 | * |
||
| 740 | * @var string | callable |
||
| 741 | */ |
||
| 742 | protected $nameValidator; |
||
| 743 | |||
| 744 | /** |
||
| 745 | * Accepted dirname validator. |
||
| 746 | * |
||
| 747 | * @var string | callable |
||
| 748 | */ |
||
| 749 | protected $dirnameValidator; |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Flag - mimetypes from externail file was loaded. |
||
| 753 | * |
||
| 754 | * @var bool |
||
| 755 | **/ |
||
| 756 | private static $mimetypesLoaded = false; |
||
| 757 | |||
| 758 | /*********************************************************************/ |
||
| 759 | /* PUBLIC API */ |
||
| 760 | /*********************************************************************/ |
||
| 761 | |||
| 762 | /** |
||
| 763 | * Return driver id. Used as a part of volume id. |
||
| 764 | * |
||
| 765 | * @return string |
||
| 766 | * @author Dmitry (dio) Levashov |
||
| 767 | **/ |
||
| 768 | public function driverId() |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Return volume id. |
||
| 775 | * |
||
| 776 | * @return string |
||
| 777 | * @author Dmitry (dio) Levashov |
||
| 778 | **/ |
||
| 779 | public function id() |
||
| 783 | |||
| 784 | /** |
||
| 785 | * Assign elFinder session wrapper object. |
||
| 786 | * |
||
| 787 | * @param $session elFinderSessionInterface |
||
| 788 | */ |
||
| 789 | public function setSession($session) |
||
| 793 | |||
| 794 | /** |
||
| 795 | * Save session cache data |
||
| 796 | * Calls this function before umount this volume on elFinder::exec(). |
||
| 797 | * |
||
| 798 | * @return void |
||
| 799 | */ |
||
| 800 | public function saveSessionCache() |
||
| 804 | |||
| 805 | /** |
||
| 806 | * Return debug info for client. |
||
| 807 | * |
||
| 808 | * @return array |
||
| 809 | * @author Dmitry (dio) Levashov |
||
| 810 | **/ |
||
| 811 | public function debug() |
||
| 820 | |||
| 821 | /** |
||
| 822 | * chmod a file or folder. |
||
| 823 | * |
||
| 824 | * @param string $hash file or folder hash to chmod |
||
| 825 | * @param string $mode octal string representing new permissions |
||
| 826 | * @return array|false |
||
| 827 | * @author David Bartle |
||
| 828 | **/ |
||
| 829 | public function chmod($hash, $mode) |
||
| 872 | |||
| 873 | /** |
||
| 874 | * stat a file or folder for elFinder cmd exec. |
||
| 875 | * |
||
| 876 | * @param string $hash file or folder hash to chmod |
||
| 877 | * @return array |
||
| 878 | * @author Naoki Sawada |
||
| 879 | **/ |
||
| 880 | public function fstat($hash) |
||
| 886 | |||
| 887 | /** |
||
| 888 | * Clear PHP stat cache & all of inner stat caches. |
||
| 889 | */ |
||
| 890 | public function clearstatcache() |
||
| 895 | |||
| 896 | /** |
||
| 897 | * Clear inner stat caches for target hash. |
||
| 898 | * |
||
| 899 | * @param string $hash |
||
| 900 | */ |
||
| 901 | public function clearcaches($hash = null) |
||
| 910 | |||
| 911 | /** |
||
| 912 | * "Mount" volume. |
||
| 913 | * Return true if volume available for read or write, |
||
| 914 | * false - otherwise. |
||
| 915 | * |
||
| 916 | * @param array $opts |
||
| 917 | * @return bool |
||
| 918 | * @author Dmitry (dio) Levashov |
||
| 919 | * @author Alexey Sukhotin |
||
| 920 | */ |
||
| 921 | public function mount(array $opts) |
||
| 1289 | |||
| 1290 | /** |
||
| 1291 | * Some "unmount" stuffs - may be required by virtual fs. |
||
| 1292 | * |
||
| 1293 | * @return void |
||
| 1294 | * @author Dmitry (dio) Levashov |
||
| 1295 | **/ |
||
| 1296 | public function umount() |
||
| 1299 | |||
| 1300 | /** |
||
| 1301 | * Remove session cache of this volume. |
||
| 1302 | */ |
||
| 1303 | public function clearSessionCache() |
||
| 1307 | |||
| 1308 | /** |
||
| 1309 | * Return error message from last failed action. |
||
| 1310 | * |
||
| 1311 | * @return array |
||
| 1312 | * @author Dmitry (dio) Levashov |
||
| 1313 | **/ |
||
| 1314 | public function error() |
||
| 1318 | |||
| 1319 | /** |
||
| 1320 | * Return is uploadable that given file name. |
||
| 1321 | * |
||
| 1322 | * @param string $name file name |
||
| 1323 | * @param bool $allowUnknown |
||
| 1324 | * @return bool |
||
| 1325 | * @author Naoki Sawada |
||
| 1326 | **/ |
||
| 1327 | public function isUploadableByName($name, $allowUnknown = false) |
||
| 1333 | |||
| 1334 | /** |
||
| 1335 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes). |
||
| 1336 | * |
||
| 1337 | * @return array |
||
| 1338 | * @author Naoki Sawada |
||
| 1339 | */ |
||
| 1340 | public function getMimeTable() |
||
| 1347 | |||
| 1348 | /** |
||
| 1349 | * Return file extention detected by MIME type. |
||
| 1350 | * |
||
| 1351 | * @param string $mime MIME type |
||
| 1352 | * @param string $suffix Additional suffix |
||
| 1353 | * @return string |
||
| 1354 | * @author Naoki Sawada |
||
| 1355 | */ |
||
| 1356 | public function getExtentionByMime($mime, $suffix = '') |
||
| 1376 | |||
| 1377 | /** |
||
| 1378 | * Set mimetypes allowed to display to client. |
||
| 1379 | * |
||
| 1380 | * @param array $mimes |
||
| 1381 | * @return void |
||
| 1382 | * @author Dmitry (dio) Levashov |
||
| 1383 | **/ |
||
| 1384 | public function setMimesFilter($mimes) |
||
| 1390 | |||
| 1391 | /** |
||
| 1392 | * Return root folder hash. |
||
| 1393 | * |
||
| 1394 | * @return string |
||
| 1395 | * @author Dmitry (dio) Levashov |
||
| 1396 | **/ |
||
| 1397 | public function root() |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Return target path hash. |
||
| 1404 | * |
||
| 1405 | * @param string $path |
||
| 1406 | * @param string $name |
||
| 1407 | * @author Naoki Sawada |
||
| 1408 | * @return string |
||
| 1409 | */ |
||
| 1410 | public function getHash($path, $name = '') |
||
| 1418 | |||
| 1419 | /** |
||
| 1420 | * Return decoded path of target hash |
||
| 1421 | * This method do not check the stat of target |
||
| 1422 | * Use method `realpath()` to do check of the stat of target. |
||
| 1423 | * |
||
| 1424 | * @param string $hash |
||
| 1425 | * @author Naoki Sawada |
||
| 1426 | * @return string |
||
| 1427 | */ |
||
| 1428 | public function getPath($hash) |
||
| 1432 | |||
| 1433 | /** |
||
| 1434 | * Return root or startPath hash. |
||
| 1435 | * |
||
| 1436 | * @return string |
||
| 1437 | * @author Dmitry (dio) Levashov |
||
| 1438 | **/ |
||
| 1439 | public function defaultPath() |
||
| 1443 | |||
| 1444 | /** |
||
| 1445 | * Return volume options required by client:. |
||
| 1446 | * |
||
| 1447 | * @param $hash |
||
| 1448 | * @return array |
||
| 1449 | * @author Dmitry (dio) Levashov |
||
| 1450 | */ |
||
| 1451 | public function options($hash) |
||
| 1506 | |||
| 1507 | /** |
||
| 1508 | * Get option value of this volume. |
||
| 1509 | * |
||
| 1510 | * @param string $name target option name |
||
| 1511 | * @return null|mixed target option value |
||
| 1512 | * @author Naoki Sawada |
||
| 1513 | */ |
||
| 1514 | public function getOption($name) |
||
| 1518 | |||
| 1519 | /** |
||
| 1520 | * Get plugin values of this options. |
||
| 1521 | * |
||
| 1522 | * @param string $name Plugin name |
||
| 1523 | * @return null|array Plugin values |
||
| 1524 | * @author Naoki Sawada |
||
| 1525 | */ |
||
| 1526 | public function getOptionsPlugin($name = '') |
||
| 1534 | |||
| 1535 | /** |
||
| 1536 | * Return true if command disabled in options. |
||
| 1537 | * |
||
| 1538 | * @param string $cmd command name |
||
| 1539 | * @return bool |
||
| 1540 | * @author Dmitry (dio) Levashov |
||
| 1541 | **/ |
||
| 1542 | public function commandDisabled($cmd) |
||
| 1546 | |||
| 1547 | /** |
||
| 1548 | * Return true if mime is required mimes list. |
||
| 1549 | * |
||
| 1550 | * @param string $mime mime type to check |
||
| 1551 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
| 1552 | * @param bool|null $empty what to return on empty list |
||
| 1553 | * @return bool|null |
||
| 1554 | * @author Dmitry (dio) Levashov |
||
| 1555 | * @author Troex Nevelin |
||
| 1556 | **/ |
||
| 1557 | public function mimeAccepted($mime, $mimes = null, $empty = true) |
||
| 1570 | |||
| 1571 | /** |
||
| 1572 | * Return true if voume is readable. |
||
| 1573 | * |
||
| 1574 | * @return bool |
||
| 1575 | * @author Dmitry (dio) Levashov |
||
| 1576 | **/ |
||
| 1577 | public function isReadable() |
||
| 1583 | |||
| 1584 | /** |
||
| 1585 | * Return true if copy from this volume allowed. |
||
| 1586 | * |
||
| 1587 | * @return bool |
||
| 1588 | * @author Dmitry (dio) Levashov |
||
| 1589 | **/ |
||
| 1590 | public function copyFromAllowed() |
||
| 1594 | |||
| 1595 | /** |
||
| 1596 | * Return file path related to root with convert encoging. |
||
| 1597 | * |
||
| 1598 | * @param string $hash file hash |
||
| 1599 | * @return string |
||
| 1600 | * @author Dmitry (dio) Levashov |
||
| 1601 | **/ |
||
| 1602 | public function path($hash) |
||
| 1606 | |||
| 1607 | /** |
||
| 1608 | * Return file real path if file exists. |
||
| 1609 | * |
||
| 1610 | * @param string $hash file hash |
||
| 1611 | * @return string | false |
||
| 1612 | * @author Dmitry (dio) Levashov |
||
| 1613 | **/ |
||
| 1614 | public function realpath($hash) |
||
| 1620 | |||
| 1621 | /** |
||
| 1622 | * Return list of moved/overwrited files. |
||
| 1623 | * |
||
| 1624 | * @return array |
||
| 1625 | * @author Dmitry (dio) Levashov |
||
| 1626 | **/ |
||
| 1627 | public function removed() |
||
| 1650 | |||
| 1651 | /** |
||
| 1652 | * Return list of added files. |
||
| 1653 | * |
||
| 1654 | * @deprecated |
||
| 1655 | * @return array |
||
| 1656 | * @author Naoki Sawada |
||
| 1657 | **/ |
||
| 1658 | public function added() |
||
| 1662 | |||
| 1663 | /** |
||
| 1664 | * Clean removed files list. |
||
| 1665 | * |
||
| 1666 | * @return void |
||
| 1667 | * @author Dmitry (dio) Levashov |
||
| 1668 | **/ |
||
| 1669 | public function resetRemoved() |
||
| 1673 | |||
| 1674 | /** |
||
| 1675 | * Clean added/removed files list. |
||
| 1676 | * |
||
| 1677 | * @return void |
||
| 1678 | **/ |
||
| 1679 | public function resetResultStat() |
||
| 1684 | |||
| 1685 | /** |
||
| 1686 | * Return file/dir hash or first founded child hash with required attr == $val. |
||
| 1687 | * |
||
| 1688 | * @param string $hash file hash |
||
| 1689 | * @param string $attr attribute name |
||
| 1690 | * @param bool $val attribute value |
||
| 1691 | * @return string|false |
||
| 1692 | * @author Dmitry (dio) Levashov |
||
| 1693 | **/ |
||
| 1694 | public function closest($hash, $attr, $val) |
||
| 1698 | |||
| 1699 | /** |
||
| 1700 | * Return file info or false on error. |
||
| 1701 | * |
||
| 1702 | * @param string $hash file hash |
||
| 1703 | * @return array|false |
||
| 1704 | * @internal param bool $realpath add realpath field to file info |
||
| 1705 | * @author Dmitry (dio) Levashov |
||
| 1706 | */ |
||
| 1707 | public function file($hash) |
||
| 1713 | |||
| 1714 | /** |
||
| 1715 | * Return folder info. |
||
| 1716 | * |
||
| 1717 | * @param string $hash folder hash |
||
| 1718 | * @param bool $resolveLink |
||
| 1719 | * @return array|false |
||
| 1720 | * @internal param bool $hidden return hidden file info |
||
| 1721 | * @author Dmitry (dio) Levashov |
||
| 1722 | */ |
||
| 1723 | public function dir($hash, $resolveLink = false) |
||
| 1737 | |||
| 1738 | /** |
||
| 1739 | * Return directory content or false on error. |
||
| 1740 | * |
||
| 1741 | * @param string $hash file hash |
||
| 1742 | * @return array|false |
||
| 1743 | * @author Dmitry (dio) Levashov |
||
| 1744 | **/ |
||
| 1745 | public function scandir($hash) |
||
| 1774 | |||
| 1775 | /** |
||
| 1776 | * Return dir files names list. |
||
| 1777 | * |
||
| 1778 | * @param string $hash file hash |
||
| 1779 | * @param null $intersect |
||
| 1780 | * @return array |
||
| 1781 | * @author Dmitry (dio) Levashov |
||
| 1782 | */ |
||
| 1783 | public function ls($hash, $intersect = null) |
||
| 1805 | |||
| 1806 | /** |
||
| 1807 | * Return subfolders for required folder or false on error. |
||
| 1808 | * |
||
| 1809 | * @param string $hash folder hash or empty string to get tree from root folder |
||
| 1810 | * @param int $deep subdir deep |
||
| 1811 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
| 1812 | * @return array|false |
||
| 1813 | * @author Dmitry (dio) Levashov |
||
| 1814 | **/ |
||
| 1815 | public function tree($hash = '', $deep = 0, $exclude = '') |
||
| 1828 | |||
| 1829 | /** |
||
| 1830 | * Return part of dirs tree from required dir up to root dir. |
||
| 1831 | * |
||
| 1832 | * @param string $hash directory hash |
||
| 1833 | * @param bool|null $lineal only lineal parents |
||
| 1834 | * @param string $until hash that is enough to that extent >= 2.1.24 |
||
| 1835 | * @return array |
||
| 1836 | * @author Dmitry (dio) Levashov |
||
| 1837 | **/ |
||
| 1838 | public function parents($hash, $lineal = false) |
||
| 1878 | |||
| 1879 | /** |
||
| 1880 | * Create thumbnail for required file and return its name of false on failed. |
||
| 1881 | * |
||
| 1882 | * @param $hash |
||
| 1883 | * @return false|string |
||
| 1884 | * @author Dmitry (dio) Levashov |
||
| 1885 | */ |
||
| 1886 | public function tmb($hash) |
||
| 1909 | |||
| 1910 | /** |
||
| 1911 | * Return file size / total directory size. |
||
| 1912 | * |
||
| 1913 | * @param string file hash |
||
| 1914 | * @return int |
||
| 1915 | * @author Dmitry (dio) Levashov |
||
| 1916 | **/ |
||
| 1917 | public function size($hash) |
||
| 1921 | |||
| 1922 | /** |
||
| 1923 | * Open file for reading and return file pointer. |
||
| 1924 | * |
||
| 1925 | * @param string file hash |
||
| 1926 | * @return resource |
||
| 1927 | * @author Dmitry (dio) Levashov |
||
| 1928 | **/ |
||
| 1929 | public function open($hash) |
||
| 1938 | |||
| 1939 | /** |
||
| 1940 | * Close file pointer. |
||
| 1941 | * |
||
| 1942 | * @param resource $fp file pointer |
||
| 1943 | * @param string $hash file hash |
||
| 1944 | * @return void |
||
| 1945 | * @author Dmitry (dio) Levashov |
||
| 1946 | **/ |
||
| 1947 | public function close($fp, $hash) |
||
| 1951 | |||
| 1952 | /** |
||
| 1953 | * Create directory and return dir info. |
||
| 1954 | * |
||
| 1955 | * @param string $dsthash destination directory hash |
||
| 1956 | * @param string $name directory name |
||
| 1957 | * @return array|false |
||
| 1958 | * @author Dmitry (dio) Levashov |
||
| 1959 | **/ |
||
| 1960 | public function mkdir($dsthash, $name) |
||
| 1995 | |||
| 1996 | /** |
||
| 1997 | * Create empty file and return its info. |
||
| 1998 | * |
||
| 1999 | * @param string $dst destination directory |
||
| 2000 | * @param string $name file name |
||
| 2001 | * @return array|false |
||
| 2002 | * @author Dmitry (dio) Levashov |
||
| 2003 | **/ |
||
| 2004 | public function mkfile($dst, $name) |
||
| 2037 | |||
| 2038 | /** |
||
| 2039 | * Rename file and return file info. |
||
| 2040 | * |
||
| 2041 | * @param string $hash file hash |
||
| 2042 | * @param string $name new file name |
||
| 2043 | * @return array|false |
||
| 2044 | * @author Dmitry (dio) Levashov |
||
| 2045 | **/ |
||
| 2046 | public function rename($hash, $name) |
||
| 2098 | |||
| 2099 | /** |
||
| 2100 | * Create file copy with suffix "copy number" and return its info. |
||
| 2101 | * |
||
| 2102 | * @param string $hash file hash |
||
| 2103 | * @param string $suffix suffix to add to file name |
||
| 2104 | * @return array|false |
||
| 2105 | * @author Dmitry (dio) Levashov |
||
| 2106 | **/ |
||
| 2107 | public function duplicate($hash, $suffix = 'copy') |
||
| 2129 | |||
| 2130 | /** |
||
| 2131 | * Save uploaded file. |
||
| 2132 | * On success return array with new file stat and with removed file hash (if existed file was replaced). |
||
| 2133 | * |
||
| 2134 | * @param resource $fp file pointer |
||
| 2135 | * @param string $dst destination folder hash |
||
| 2136 | * @param $name |
||
| 2137 | * @param string $tmpname file tmp name - required to detect mime type |
||
| 2138 | * @param array $hashes exists files hash array with filename as key |
||
| 2139 | * @return array|false |
||
| 2140 | * @internal param string $src file name |
||
| 2141 | * @author Dmitry (dio) Levashov |
||
| 2142 | */ |
||
| 2143 | public function upload($fp, $dst, $name, $tmpname, $hashes = []) |
||
| 2229 | |||
| 2230 | /** |
||
| 2231 | * Paste files. |
||
| 2232 | * |
||
| 2233 | * @param object $volume source volume |
||
| 2234 | * @param $src |
||
| 2235 | * @param string $dst destination dir hash |
||
| 2236 | * @param bool $rmSrc remove source after copy? |
||
| 2237 | * @param array $hashes |
||
| 2238 | * @return array|false |
||
| 2239 | * @internal param string $source file hash |
||
| 2240 | * @author Dmitry (dio) Levashov |
||
| 2241 | */ |
||
| 2242 | public function paste($volume, $src, $dst, $rmSrc = false, $hashes = []) |
||
| 2367 | |||
| 2368 | /** |
||
| 2369 | * Return path to archive of target items. |
||
| 2370 | * |
||
| 2371 | * @param array $hashes |
||
| 2372 | * @return string archive path |
||
| 2373 | * @author Naoki Sawada |
||
| 2374 | */ |
||
| 2375 | public function zipdl($hashes) |
||
| 2444 | |||
| 2445 | /** |
||
| 2446 | * Return file contents. |
||
| 2447 | * |
||
| 2448 | * @param string $hash file hash |
||
| 2449 | * @return string|false |
||
| 2450 | * @author Dmitry (dio) Levashov |
||
| 2451 | **/ |
||
| 2452 | public function getContents($hash) |
||
| 2474 | |||
| 2475 | /** |
||
| 2476 | * Put content in text file and return file info. |
||
| 2477 | * |
||
| 2478 | * @param string $hash file hash |
||
| 2479 | * @param string $content new file content |
||
| 2480 | * @return array |
||
| 2481 | * @author Dmitry (dio) Levashov |
||
| 2482 | **/ |
||
| 2483 | public function putContents($hash, $content) |
||
| 2529 | |||
| 2530 | /** |
||
| 2531 | * Extract files from archive. |
||
| 2532 | * |
||
| 2533 | * @param string $hash archive hash |
||
| 2534 | * @param null $makedir |
||
| 2535 | * @return array|bool |
||
| 2536 | * @author Dmitry (dio) Levashov, |
||
| 2537 | * @author Alexey Sukhotin |
||
| 2538 | */ |
||
| 2539 | public function extract($hash, $makedir = null) |
||
| 2580 | |||
| 2581 | /** |
||
| 2582 | * Add files to archive. |
||
| 2583 | * |
||
| 2584 | * @param $hashes |
||
| 2585 | * @param $mime |
||
| 2586 | * @param string $name |
||
| 2587 | * @return array|bool |
||
| 2588 | */ |
||
| 2589 | public function archive($hashes, $mime, $name = '') |
||
| 2639 | |||
| 2640 | /** |
||
| 2641 | * Resize image. |
||
| 2642 | * |
||
| 2643 | * @param string $hash image file |
||
| 2644 | * @param int $width new width |
||
| 2645 | * @param int $height new height |
||
| 2646 | * @param int $x X start poistion for crop |
||
| 2647 | * @param int $y Y start poistion for crop |
||
| 2648 | * @param string $mode action how to mainpulate image |
||
| 2649 | * @param string $bg background color |
||
| 2650 | * @param int $degree rotete degree |
||
| 2651 | * @param int $jpgQuality JEPG quality (1-100) |
||
| 2652 | * @return array|false |
||
| 2653 | * @author Dmitry (dio) Levashov |
||
| 2654 | * @author Alexey Sukhotin |
||
| 2655 | * @author nao-pon |
||
| 2656 | * @author Troex Nevelin |
||
| 2657 | **/ |
||
| 2658 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0, $jpgQuality = null) |
||
| 2747 | |||
| 2748 | /** |
||
| 2749 | * Remove file/dir. |
||
| 2750 | * |
||
| 2751 | * @param string $hash file hash |
||
| 2752 | * @return bool |
||
| 2753 | * @author Dmitry (dio) Levashov |
||
| 2754 | **/ |
||
| 2755 | public function rm($hash) |
||
| 2761 | |||
| 2762 | /** |
||
| 2763 | * Search files. |
||
| 2764 | * |
||
| 2765 | * @param string $q search string |
||
| 2766 | * @param array $mimes |
||
| 2767 | * @param null $hash |
||
| 2768 | * @return array |
||
| 2769 | * @author Dmitry (dio) Levashov |
||
| 2770 | */ |
||
| 2771 | public function search($q, $mimes, $hash = null) |
||
| 2824 | |||
| 2825 | /** |
||
| 2826 | * Return image dimensions. |
||
| 2827 | * |
||
| 2828 | * @param string $hash file hash |
||
| 2829 | * @return array |
||
| 2830 | * @author Dmitry (dio) Levashov |
||
| 2831 | **/ |
||
| 2832 | public function dimensions($hash) |
||
| 2840 | |||
| 2841 | /** |
||
| 2842 | * Return has subdirs. |
||
| 2843 | * |
||
| 2844 | * @param string $hash file hash |
||
| 2845 | * @return bool |
||
| 2846 | * @author Naoki Sawada |
||
| 2847 | **/ |
||
| 2848 | public function subdirs($hash) |
||
| 2852 | |||
| 2853 | /** |
||
| 2854 | * Return content URL (for netmout volume driver) |
||
| 2855 | * If file.url == 1 requests from JavaScript client with XHR. |
||
| 2856 | * |
||
| 2857 | * @param string $hash file hash |
||
| 2858 | * @param array $options options array |
||
| 2859 | * @return bool|string |
||
| 2860 | * @author Naoki Sawada |
||
| 2861 | */ |
||
| 2862 | public function getContentUrl($hash, $options = []) |
||
| 2901 | |||
| 2902 | /** |
||
| 2903 | * Return temp path. |
||
| 2904 | * |
||
| 2905 | * @return string |
||
| 2906 | * @author Naoki Sawada |
||
| 2907 | */ |
||
| 2908 | public function getTempPath() |
||
| 2926 | |||
| 2927 | /** |
||
| 2928 | * (Make &) Get upload taget dirctory hash. |
||
| 2929 | * |
||
| 2930 | * @param string $baseTargetHash |
||
| 2931 | * @param string $path |
||
| 2932 | * @param array $result |
||
| 2933 | * @return bool|string |
||
| 2934 | * @author Naoki Sawada |
||
| 2935 | */ |
||
| 2936 | public function getUploadTaget($baseTargetHash, $path, &$result) |
||
| 2965 | |||
| 2966 | /** |
||
| 2967 | * Return this uploadMaxSize value. |
||
| 2968 | * |
||
| 2969 | * @return int |
||
| 2970 | * @author Naoki Sawada |
||
| 2971 | */ |
||
| 2972 | public function getUploadMaxSize() |
||
| 2976 | |||
| 2977 | public function setUploadOverwrite($var) |
||
| 2981 | |||
| 2982 | /** |
||
| 2983 | * Image file utility. |
||
| 2984 | * |
||
| 2985 | * @param string $mode 'resize', 'rotate', 'propresize', 'crop', 'fitsquare' |
||
| 2986 | * @param string $src Image file local path |
||
| 2987 | * @param array $options excute options |
||
| 2988 | * @return bool |
||
| 2989 | * @author Naoki Sawada |
||
| 2990 | */ |
||
| 2991 | public function imageUtil($mode, $src, $options = []) |
||
| 3037 | |||
| 3038 | /** |
||
| 3039 | * Convert Video To Image by ffmpeg. |
||
| 3040 | * |
||
| 3041 | * @param $file video source file path |
||
| 3042 | * @param $stat file stat array |
||
| 3043 | * @return bool |
||
| 3044 | * @author Naoki Sawada |
||
| 3045 | */ |
||
| 3046 | public function ffmpegToImg($file, $stat) |
||
| 3068 | |||
| 3069 | /** |
||
| 3070 | * Return new unique name based on file name and suffix. |
||
| 3071 | * |
||
| 3072 | * @param $dir |
||
| 3073 | * @param $name |
||
| 3074 | * @param string $suffix suffix append to name |
||
| 3075 | * @param bool $checkNum |
||
| 3076 | * @param int $start |
||
| 3077 | * @return string |
||
| 3078 | * @internal param string $path file path |
||
| 3079 | * @author Dmitry (dio) Levashov |
||
| 3080 | */ |
||
| 3081 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum = true, $start = 1) |
||
| 3112 | |||
| 3113 | /** |
||
| 3114 | * Converts character encoding from UTF-8 to server's one. |
||
| 3115 | * |
||
| 3116 | * @param mixed $var target string or array var |
||
| 3117 | * @param bool $restoreLocale do retore global locale, default is false |
||
| 3118 | * @param string $unknown replaces character for unknown |
||
| 3119 | * @return mixed |
||
| 3120 | * @author Naoki Sawada |
||
| 3121 | */ |
||
| 3122 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') |
||
| 3126 | |||
| 3127 | /** |
||
| 3128 | * Converts character encoding from server's one to UTF-8. |
||
| 3129 | * |
||
| 3130 | * @param mixed $var target string or array var |
||
| 3131 | * @param bool $restoreLocale do retore global locale, default is true |
||
| 3132 | * @param string $unknown replaces character for unknown |
||
| 3133 | * @return mixed |
||
| 3134 | * @author Naoki Sawada |
||
| 3135 | */ |
||
| 3136 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') |
||
| 3140 | |||
| 3141 | /** |
||
| 3142 | * Get image size array with `dimensions`. |
||
| 3143 | * |
||
| 3144 | * @param string $path path need convert encoding to server encoding |
||
| 3145 | * @param string $mime file mime type |
||
| 3146 | * @return array|false |
||
| 3147 | */ |
||
| 3148 | public function getImageSize($path, $mime = '') |
||
| 3162 | |||
| 3163 | /** |
||
| 3164 | * Remove directory recursive on local file system. |
||
| 3165 | * |
||
| 3166 | * @param string $dir Target dirctory path |
||
| 3167 | * @return bool |
||
| 3168 | * @author Naoki Sawada |
||
| 3169 | */ |
||
| 3170 | public function rmdirRecursive($dir) |
||
| 3174 | |||
| 3175 | /*********************************************************************/ |
||
| 3176 | /* INITIALIZATION */ |
||
| 3177 | /*********************************************************************/ |
||
| 3178 | |||
| 3179 | /** |
||
| 3180 | * Prepare driver before mount volume. |
||
| 3181 | * Return true if volume is ready. |
||
| 3182 | * |
||
| 3183 | * @return bool |
||
| 3184 | * @author Dmitry (dio) Levashov |
||
| 3185 | **/ |
||
| 3186 | protected function init() |
||
| 3190 | |||
| 3191 | /** |
||
| 3192 | * Configure after successfull mount. |
||
| 3193 | * By default set thumbnails path and image manipulation library. |
||
| 3194 | * |
||
| 3195 | * @return void |
||
| 3196 | * @author Dmitry (dio) Levashov |
||
| 3197 | **/ |
||
| 3198 | protected function configure() |
||
| 3303 | |||
| 3304 | /** |
||
| 3305 | * @deprecated |
||
| 3306 | */ |
||
| 3307 | protected function sessionRestart() |
||
| 3313 | |||
| 3314 | /** |
||
| 3315 | * Save error message. |
||
| 3316 | * |
||
| 3317 | * @param array error |
||
| 3318 | * @return false |
||
| 3319 | * @author Naoki Sawada |
||
| 3320 | **/ |
||
| 3321 | protected function setError() |
||
| 3328 | |||
| 3329 | /** |
||
| 3330 | * Add error message. |
||
| 3331 | * |
||
| 3332 | * @param array error |
||
| 3333 | * @return false |
||
| 3334 | * @author Dmitry(dio) Levashov |
||
| 3335 | **/ |
||
| 3336 | protected function addError() |
||
| 3348 | |||
| 3349 | /*********************************************************************/ |
||
| 3350 | /* FS API */ |
||
| 3351 | /*********************************************************************/ |
||
| 3352 | |||
| 3353 | /***************** server encoding support *******************/ |
||
| 3354 | |||
| 3355 | /** |
||
| 3356 | * Return parent directory path (with convert encoding). |
||
| 3357 | * |
||
| 3358 | * @param string $path file path |
||
| 3359 | * @return string |
||
| 3360 | * @author Naoki Sawada |
||
| 3361 | **/ |
||
| 3362 | protected function dirnameCE($path) |
||
| 3368 | |||
| 3369 | /** |
||
| 3370 | * Return file name (with convert encoding). |
||
| 3371 | * |
||
| 3372 | * @param string $path file path |
||
| 3373 | * @return string |
||
| 3374 | * @author Naoki Sawada |
||
| 3375 | **/ |
||
| 3376 | protected function basenameCE($path) |
||
| 3380 | |||
| 3381 | /** |
||
| 3382 | * Join dir name and file name and return full path. (with convert encoding) |
||
| 3383 | * Some drivers (db) use int as path - so we give to concat path to driver itself. |
||
| 3384 | * |
||
| 3385 | * @param string $dir dir path |
||
| 3386 | * @param string $name file name |
||
| 3387 | * @return string |
||
| 3388 | * @author Naoki Sawada |
||
| 3389 | **/ |
||
| 3390 | protected function joinPathCE($dir, $name) |
||
| 3394 | |||
| 3395 | /** |
||
| 3396 | * Return normalized path (with convert encoding). |
||
| 3397 | * |
||
| 3398 | * @param string $path file path |
||
| 3399 | * @return string |
||
| 3400 | * @author Naoki Sawada |
||
| 3401 | **/ |
||
| 3402 | protected function normpathCE($path) |
||
| 3406 | |||
| 3407 | /** |
||
| 3408 | * Return file path related to root dir (with convert encoding). |
||
| 3409 | * |
||
| 3410 | * @param string $path file path |
||
| 3411 | * @return string |
||
| 3412 | * @author Naoki Sawada |
||
| 3413 | **/ |
||
| 3414 | protected function relpathCE($path) |
||
| 3418 | |||
| 3419 | /** |
||
| 3420 | * Convert path related to root dir into real path (with convert encoding). |
||
| 3421 | * |
||
| 3422 | * @param string $path rel file path |
||
| 3423 | * @return string |
||
| 3424 | * @author Naoki Sawada |
||
| 3425 | **/ |
||
| 3426 | protected function abspathCE($path) |
||
| 3430 | |||
| 3431 | /** |
||
| 3432 | * Return true if $path is children of $parent (with convert encoding). |
||
| 3433 | * |
||
| 3434 | * @param string $path path to check |
||
| 3435 | * @param string $parent parent path |
||
| 3436 | * @return bool |
||
| 3437 | * @author Naoki Sawada |
||
| 3438 | **/ |
||
| 3439 | protected function inpathCE($path, $parent) |
||
| 3443 | |||
| 3444 | /** |
||
| 3445 | * Open file and return file pointer (with convert encoding). |
||
| 3446 | * |
||
| 3447 | * @param string $path file path |
||
| 3448 | * @param string $mode |
||
| 3449 | * @return false|resource |
||
| 3450 | * @internal param bool $write open file for writing |
||
| 3451 | * @author Naoki Sawada |
||
| 3452 | */ |
||
| 3453 | protected function fopenCE($path, $mode = 'rb') |
||
| 3457 | |||
| 3458 | /** |
||
| 3459 | * Close opened file (with convert encoding). |
||
| 3460 | * |
||
| 3461 | * @param resource $fp file pointer |
||
| 3462 | * @param string $path file path |
||
| 3463 | * @return bool |
||
| 3464 | * @author Naoki Sawada |
||
| 3465 | **/ |
||
| 3466 | protected function fcloseCE($fp, $path = '') |
||
| 3470 | |||
| 3471 | /** |
||
| 3472 | * Create new file and write into it from file pointer. (with convert encoding) |
||
| 3473 | * Return new file path or false on error. |
||
| 3474 | * |
||
| 3475 | * @param resource $fp file pointer |
||
| 3476 | * @param string $dir target dir path |
||
| 3477 | * @param string $name file name |
||
| 3478 | * @param array $stat file stat (required by some virtual fs) |
||
| 3479 | * @return bool|string |
||
| 3480 | * @author Naoki Sawada |
||
| 3481 | **/ |
||
| 3482 | protected function saveCE($fp, $dir, $name, $stat) |
||
| 3486 | |||
| 3487 | /** |
||
| 3488 | * Return true if path is dir and has at least one childs directory (with convert encoding). |
||
| 3489 | * |
||
| 3490 | * @param string $path dir path |
||
| 3491 | * @return bool |
||
| 3492 | * @author Naoki Sawada |
||
| 3493 | **/ |
||
| 3494 | protected function subdirsCE($path) |
||
| 3506 | |||
| 3507 | /** |
||
| 3508 | * Return files list in directory (with convert encoding). |
||
| 3509 | * |
||
| 3510 | * @param string $path dir path |
||
| 3511 | * @return array |
||
| 3512 | * @author Naoki Sawada |
||
| 3513 | **/ |
||
| 3514 | protected function scandirCE($path) |
||
| 3518 | |||
| 3519 | /** |
||
| 3520 | * Create symlink (with convert encoding). |
||
| 3521 | * |
||
| 3522 | * @param string $source file to link to |
||
| 3523 | * @param string $targetDir folder to create link in |
||
| 3524 | * @param string $name symlink name |
||
| 3525 | * @return bool |
||
| 3526 | * @author Naoki Sawada |
||
| 3527 | **/ |
||
| 3528 | protected function symlinkCE($source, $targetDir, $name) |
||
| 3532 | |||
| 3533 | /***************** paths *******************/ |
||
| 3534 | |||
| 3535 | /** |
||
| 3536 | * Encode path into hash. |
||
| 3537 | * |
||
| 3538 | * @param string file path |
||
| 3539 | * @return string |
||
| 3540 | * @author Dmitry (dio) Levashov |
||
| 3541 | * @author Troex Nevelin |
||
| 3542 | **/ |
||
| 3543 | protected function encode($path) |
||
| 3566 | |||
| 3567 | /** |
||
| 3568 | * Decode path from hash. |
||
| 3569 | * |
||
| 3570 | * @param string file hash |
||
| 3571 | * @return string |
||
| 3572 | * @author Dmitry (dio) Levashov |
||
| 3573 | * @author Troex Nevelin |
||
| 3574 | **/ |
||
| 3575 | protected function decode($hash) |
||
| 3589 | |||
| 3590 | /** |
||
| 3591 | * Return crypted path |
||
| 3592 | * Not implemented. |
||
| 3593 | * |
||
| 3594 | * @param string path |
||
| 3595 | * @return mixed |
||
| 3596 | * @author Dmitry (dio) Levashov |
||
| 3597 | **/ |
||
| 3598 | protected function crypt($path) |
||
| 3602 | |||
| 3603 | /** |
||
| 3604 | * Return uncrypted path |
||
| 3605 | * Not implemented. |
||
| 3606 | * |
||
| 3607 | * @param mixed hash |
||
| 3608 | * @return mixed |
||
| 3609 | * @author Dmitry (dio) Levashov |
||
| 3610 | **/ |
||
| 3611 | protected function uncrypt($hash) |
||
| 3615 | |||
| 3616 | /** |
||
| 3617 | * Validate file name based on $this->options['acceptedName'] regexp or function. |
||
| 3618 | * |
||
| 3619 | * @param string $name file name |
||
| 3620 | * @return bool |
||
| 3621 | * @author Dmitry (dio) Levashov |
||
| 3622 | **/ |
||
| 3623 | protected function nameAccepted($name, $isDir = false) |
||
| 3642 | |||
| 3643 | /** |
||
| 3644 | * Return session rootstat cache key. |
||
| 3645 | * |
||
| 3646 | * @return string |
||
| 3647 | */ |
||
| 3648 | protected function getRootstatCachekey() |
||
| 3652 | |||
| 3653 | /** |
||
| 3654 | * Converts character encoding (base function). |
||
| 3655 | * |
||
| 3656 | * @param mixed $var target string or array var |
||
| 3657 | * @param string $from from character encoding |
||
| 3658 | * @param string $to to character encoding |
||
| 3659 | * @param string $locale local locale |
||
| 3660 | * @param $restoreLocale |
||
| 3661 | * @param string $unknown replaces character for unknown |
||
| 3662 | * @return mixed |
||
| 3663 | */ |
||
| 3664 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') |
||
| 3695 | |||
| 3696 | /*********************** util mainly for inheritance class *********************/ |
||
| 3697 | |||
| 3698 | /** |
||
| 3699 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
| 3700 | * When needing the unique file to a path, give $path to parameter. |
||
| 3701 | * |
||
| 3702 | * @param string $path for get unique file to a path |
||
| 3703 | * @return string|false |
||
| 3704 | * @author Naoki Sawada |
||
| 3705 | */ |
||
| 3706 | protected function getTempFile($path = '') |
||
| 3734 | |||
| 3735 | /** |
||
| 3736 | * File path of local server side work file path. |
||
| 3737 | * |
||
| 3738 | * @param string $path path need convert encoding to server encoding |
||
| 3739 | * @return string |
||
| 3740 | * @author Naoki Sawada |
||
| 3741 | */ |
||
| 3742 | protected function getWorkFile($path) |
||
| 3760 | |||
| 3761 | /** |
||
| 3762 | * Delete dirctory trees. |
||
| 3763 | * |
||
| 3764 | * @param string $localpath path need convert encoding to server encoding |
||
| 3765 | * @return bool |
||
| 3766 | * @author Naoki Sawada |
||
| 3767 | */ |
||
| 3768 | protected function delTree($localpath) |
||
| 3779 | |||
| 3780 | /** |
||
| 3781 | * Copy items to a new temporary directory on the local server. |
||
| 3782 | * |
||
| 3783 | * @param array $hashes target hashes |
||
| 3784 | * @param string $dir destination directory (for recurcive) |
||
| 3785 | * @param string $canLink it can use link() (for recurcive) |
||
| 3786 | * @return string|false saved path name |
||
| 3787 | * @author Naoki Sawada |
||
| 3788 | */ |
||
| 3789 | protected function getItemsInHand($hashes, $dir = null, $canLink = null) |
||
| 3863 | |||
| 3864 | /*********************** file stat *********************/ |
||
| 3865 | |||
| 3866 | /** |
||
| 3867 | * Check file attribute. |
||
| 3868 | * |
||
| 3869 | * @param string $path file path |
||
| 3870 | * @param string $name attribute name (read|write|locked|hidden) |
||
| 3871 | * @param bool $val attribute value returned by file system |
||
| 3872 | * @param bool $isDir path is directory (true: directory, false: file) |
||
| 3873 | * @return bool |
||
| 3874 | * @author Dmitry (dio) Levashov |
||
| 3875 | **/ |
||
| 3876 | protected function attr($path, $name, $val = null, $isDir = null) |
||
| 3907 | |||
| 3908 | /** |
||
| 3909 | * Return true if file with given name can be created in given folder. |
||
| 3910 | * |
||
| 3911 | * @param string $dir parent dir path |
||
| 3912 | * @param string $name new file name |
||
| 3913 | * @param null $isDir |
||
| 3914 | * @return bool |
||
| 3915 | * @author Dmitry (dio) Levashov |
||
| 3916 | */ |
||
| 3917 | protected function allowCreate($dir, $name, $isDir = null) |
||
| 3921 | |||
| 3922 | /** |
||
| 3923 | * Return true if file MIME type can save with check uploadOrder config. |
||
| 3924 | * |
||
| 3925 | * @param string $mime |
||
| 3926 | * @return bool |
||
| 3927 | */ |
||
| 3928 | protected function allowPutMime($mime) |
||
| 3948 | |||
| 3949 | /** |
||
| 3950 | * Return fileinfo. |
||
| 3951 | * |
||
| 3952 | * @param string $path file cache |
||
| 3953 | * @return array |
||
| 3954 | * @author Dmitry (dio) Levashov |
||
| 3955 | **/ |
||
| 3956 | protected function stat($path) |
||
| 4001 | |||
| 4002 | /** |
||
| 4003 | * Get root stat extra key values. |
||
| 4004 | * |
||
| 4005 | * @return array stat extras |
||
| 4006 | * @author Naoki Sawada |
||
| 4007 | */ |
||
| 4008 | protected function getRootStatExtra() |
||
| 4019 | |||
| 4020 | /** |
||
| 4021 | * Return fileinfo based on filename |
||
| 4022 | * For item ID based path file system |
||
| 4023 | * Please override if needed on each drivers. |
||
| 4024 | * |
||
| 4025 | * @param string $path file cache |
||
| 4026 | * @return array |
||
| 4027 | */ |
||
| 4028 | protected function isNameExists($path) |
||
| 4032 | |||
| 4033 | /** |
||
| 4034 | * Put file stat in cache and return it. |
||
| 4035 | * |
||
| 4036 | * @param string $path file path |
||
| 4037 | * @param array $stat file stat |
||
| 4038 | * @return array |
||
| 4039 | * @author Dmitry (dio) Levashov |
||
| 4040 | **/ |
||
| 4041 | protected function updateCache($path, $stat) |
||
| 4190 | |||
| 4191 | /** |
||
| 4192 | * Get stat for folder content and put in cache. |
||
| 4193 | * |
||
| 4194 | * @param string $path |
||
| 4195 | * @return void |
||
| 4196 | * @author Dmitry (dio) Levashov |
||
| 4197 | **/ |
||
| 4198 | protected function cacheDir($path) |
||
| 4214 | |||
| 4215 | /** |
||
| 4216 | * Clean cache. |
||
| 4217 | * |
||
| 4218 | * @return void |
||
| 4219 | * @author Dmitry (dio) Levashov |
||
| 4220 | **/ |
||
| 4221 | protected function clearcache() |
||
| 4225 | |||
| 4226 | /** |
||
| 4227 | * Return file mimetype. |
||
| 4228 | * |
||
| 4229 | * @param string $path file path |
||
| 4230 | * @param string|bool $name |
||
| 4231 | * @return string |
||
| 4232 | * @author Dmitry (dio) Levashov |
||
| 4233 | */ |
||
| 4234 | protected function mimetype($path, $name = '') |
||
| 4296 | |||
| 4297 | /** |
||
| 4298 | * Detect file mimetype using "internal" method or Loading mime.types with $path = ''. |
||
| 4299 | * |
||
| 4300 | * @param string $path file path |
||
| 4301 | * @return string |
||
| 4302 | * @author Dmitry (dio) Levashov |
||
| 4303 | **/ |
||
| 4304 | protected static function mimetypeInternalDetect($path = '') |
||
| 4335 | |||
| 4336 | /** |
||
| 4337 | * Return file/total directory size. |
||
| 4338 | * |
||
| 4339 | * @param string $path file path |
||
| 4340 | * @return int |
||
| 4341 | * @author Dmitry (dio) Levashov |
||
| 4342 | **/ |
||
| 4343 | protected function countSize($path) |
||
| 4388 | |||
| 4389 | /** |
||
| 4390 | * Return true if all mimes is directory or files. |
||
| 4391 | * |
||
| 4392 | * @param string $mime1 mimetype |
||
| 4393 | * @param string $mime2 mimetype |
||
| 4394 | * @return bool |
||
| 4395 | * @author Dmitry (dio) Levashov |
||
| 4396 | **/ |
||
| 4397 | protected function isSameType($mime1, $mime2) |
||
| 4401 | |||
| 4402 | /** |
||
| 4403 | * If file has required attr == $val - return file path, |
||
| 4404 | * If dir has child with has required attr == $val - return child path. |
||
| 4405 | * |
||
| 4406 | * @param string $path file path |
||
| 4407 | * @param string $attr attribute name |
||
| 4408 | * @param bool $val attribute value |
||
| 4409 | * @return string|false |
||
| 4410 | * @author Dmitry (dio) Levashov |
||
| 4411 | **/ |
||
| 4412 | protected function closestByAttr($path, $attr, $val) |
||
| 4430 | |||
| 4431 | /** |
||
| 4432 | * Return first found children with required attr == $val. |
||
| 4433 | * |
||
| 4434 | * @param string $path file path |
||
| 4435 | * @param string $attr attribute name |
||
| 4436 | * @param bool $val attribute value |
||
| 4437 | * @return string|false |
||
| 4438 | * @author Dmitry (dio) Levashov |
||
| 4439 | **/ |
||
| 4440 | protected function childsByAttr($path, $attr, $val) |
||
| 4450 | |||
| 4451 | protected function isMyReload($target = '', $ARGtarget = '') |
||
| 4476 | |||
| 4477 | /** |
||
| 4478 | * Update subdirs cache data. |
||
| 4479 | * |
||
| 4480 | * @param string $path |
||
| 4481 | * @param bool $subdirs |
||
| 4482 | * |
||
| 4483 | * @returnv void |
||
| 4484 | */ |
||
| 4485 | protected function updateSubdirsCache($path, $subdirs) |
||
| 4501 | |||
| 4502 | /***************** get content *******************/ |
||
| 4503 | |||
| 4504 | /** |
||
| 4505 | * Return required dir's files info. |
||
| 4506 | * If onlyMimes is set - return only dirs and files of required mimes. |
||
| 4507 | * |
||
| 4508 | * @param string $path dir path |
||
| 4509 | * @return array |
||
| 4510 | * @author Dmitry (dio) Levashov |
||
| 4511 | **/ |
||
| 4512 | protected function getScandir($path) |
||
| 4526 | |||
| 4527 | /** |
||
| 4528 | * Return subdirs tree. |
||
| 4529 | * |
||
| 4530 | * @param string $path parent dir path |
||
| 4531 | * @param int $deep tree deep |
||
| 4532 | * @param string $exclude |
||
| 4533 | * @return array |
||
| 4534 | * @author Dmitry (dio) Levashov |
||
| 4535 | */ |
||
| 4536 | protected function gettree($path, $deep, $exclude = '') |
||
| 4555 | |||
| 4556 | /** |
||
| 4557 | * Recursive files search. |
||
| 4558 | * |
||
| 4559 | * @param string $path dir path |
||
| 4560 | * @param string $q search string |
||
| 4561 | * @param array $mimes |
||
| 4562 | * @return array |
||
| 4563 | * @author Dmitry (dio) Levashov |
||
| 4564 | **/ |
||
| 4565 | protected function doSearch($path, $q, $mimes) |
||
| 4627 | |||
| 4628 | /********************** manuipulations ******************/ |
||
| 4629 | |||
| 4630 | /** |
||
| 4631 | * Copy file/recursive copy dir only in current volume. |
||
| 4632 | * Return new file path or false. |
||
| 4633 | * |
||
| 4634 | * @param string $src source path |
||
| 4635 | * @param string $dst destination dir path |
||
| 4636 | * @param string $name new file name (optionaly) |
||
| 4637 | * @return string|false |
||
| 4638 | * @author Dmitry (dio) Levashov |
||
| 4639 | **/ |
||
| 4640 | protected function copy($src, $dst, $name) |
||
| 4705 | |||
| 4706 | /** |
||
| 4707 | * Move file |
||
| 4708 | * Return new file path or false. |
||
| 4709 | * |
||
| 4710 | * @param string $src source path |
||
| 4711 | * @param string $dst destination dir path |
||
| 4712 | * @param string $name new file name |
||
| 4713 | * @return string|false |
||
| 4714 | * @author Dmitry (dio) Levashov |
||
| 4715 | **/ |
||
| 4716 | protected function move($src, $dst, $name) |
||
| 4734 | |||
| 4735 | /** |
||
| 4736 | * Copy file from another volume. |
||
| 4737 | * Return new file path or false. |
||
| 4738 | * |
||
| 4739 | * @param object $volume source volume |
||
| 4740 | * @param string $src source file hash |
||
| 4741 | * @param string $destination destination dir path |
||
| 4742 | * @param string $name file name |
||
| 4743 | * @return string|false |
||
| 4744 | * @author Dmitry (dio) Levashov |
||
| 4745 | **/ |
||
| 4746 | protected function copyFrom($volume, $src, $destination, $name) |
||
| 4814 | |||
| 4815 | /** |
||
| 4816 | * Remove file/ recursive remove dir. |
||
| 4817 | * |
||
| 4818 | * @param string $path file path |
||
| 4819 | * @param bool $force try to remove even if file locked |
||
| 4820 | * @return bool |
||
| 4821 | * @author Dmitry (dio) Levashov |
||
| 4822 | **/ |
||
| 4823 | protected function remove($path, $force = false) |
||
| 4855 | |||
| 4856 | /************************* thumbnails **************************/ |
||
| 4857 | |||
| 4858 | /** |
||
| 4859 | * Return thumbnail file name for required file. |
||
| 4860 | * |
||
| 4861 | * @param array $stat file stat |
||
| 4862 | * @return string |
||
| 4863 | * @author Dmitry (dio) Levashov |
||
| 4864 | **/ |
||
| 4865 | protected function tmbname($stat) |
||
| 4869 | |||
| 4870 | /** |
||
| 4871 | * Return thumnbnail name if exists. |
||
| 4872 | * |
||
| 4873 | * @param string $path file path |
||
| 4874 | * @param array $stat file stat |
||
| 4875 | * @return string|false |
||
| 4876 | * @author Dmitry (dio) Levashov |
||
| 4877 | **/ |
||
| 4878 | protected function gettmb($path, $stat) |
||
| 4894 | |||
| 4895 | /** |
||
| 4896 | * Return true if thumnbnail for required file can be created. |
||
| 4897 | * |
||
| 4898 | * @param string $path thumnbnail path |
||
| 4899 | * @param array $stat file stat |
||
| 4900 | * @param bool $checkTmbPath |
||
| 4901 | * @return string|bool |
||
| 4902 | * @author Dmitry (dio) Levashov |
||
| 4903 | **/ |
||
| 4904 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) |
||
| 4927 | |||
| 4928 | /** |
||
| 4929 | * Return true if required file can be resized. |
||
| 4930 | * By default - the same as canCreateTmb. |
||
| 4931 | * |
||
| 4932 | * @param string $path thumnbnail path |
||
| 4933 | * @param array $stat file stat |
||
| 4934 | * @return string|bool |
||
| 4935 | * @author Dmitry (dio) Levashov |
||
| 4936 | **/ |
||
| 4937 | protected function canResize($path, $stat) |
||
| 4941 | |||
| 4942 | /** |
||
| 4943 | * Create thumnbnail and return it's URL on success. |
||
| 4944 | * |
||
| 4945 | * @param string $path file path |
||
| 4946 | * @param $stat |
||
| 4947 | * @return false|string |
||
| 4948 | * @internal param string $mime file mime type |
||
| 4949 | * @author Dmitry (dio) Levashov |
||
| 4950 | */ |
||
| 4951 | protected function createTmb($path, $stat) |
||
| 5086 | |||
| 5087 | /** |
||
| 5088 | * Resize image. |
||
| 5089 | * |
||
| 5090 | * @param string $path image file |
||
| 5091 | * @param int $width new width |
||
| 5092 | * @param int $height new height |
||
| 5093 | * @param bool $keepProportions crop image |
||
| 5094 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
| 5095 | * @param string $destformat image destination format |
||
| 5096 | * @param int $jpgQuality JEPG quality (1-100) |
||
| 5097 | * @param array $options Other extra options |
||
| 5098 | * @return string|false |
||
| 5099 | * @author Dmitry (dio) Levashov |
||
| 5100 | * @author Alexey Sukhotin |
||
| 5101 | **/ |
||
| 5102 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null, $jpgQuality = null, $options = []) |
||
| 5249 | |||
| 5250 | /** |
||
| 5251 | * Crop image. |
||
| 5252 | * |
||
| 5253 | * @param string $path image file |
||
| 5254 | * @param int $width crop width |
||
| 5255 | * @param int $height crop height |
||
| 5256 | * @param bool $x crop left offset |
||
| 5257 | * @param bool $y crop top offset |
||
| 5258 | * @param string $destformat image destination format |
||
| 5259 | * @param int $jpgQuality JEPG quality (1-100) |
||
| 5260 | * @return string|false |
||
| 5261 | * @author Dmitry (dio) Levashov |
||
| 5262 | * @author Alexey Sukhotin |
||
| 5263 | **/ |
||
| 5264 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null, $jpgQuality = null) |
||
| 5367 | |||
| 5368 | /** |
||
| 5369 | * Put image to square. |
||
| 5370 | * |
||
| 5371 | * @param string $path image file |
||
| 5372 | * @param int $width square width |
||
| 5373 | * @param int $height square height |
||
| 5374 | * @param int|string $align reserved |
||
| 5375 | * @param int|string $valign reserved |
||
| 5376 | * @param string $bgcolor square background color in #rrggbb format |
||
| 5377 | * @param string $destformat image destination format |
||
| 5378 | * @param int $jpgQuality JEPG quality (1-100) |
||
| 5379 | * @return false|string |
||
| 5380 | * @author Dmitry (dio) Levashov |
||
| 5381 | * @author Alexey Sukhotin |
||
| 5382 | */ |
||
| 5383 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null, $jpgQuality = null) |
||
| 5489 | |||
| 5490 | /** |
||
| 5491 | * Rotate image. |
||
| 5492 | * |
||
| 5493 | * @param string $path image file |
||
| 5494 | * @param int $degree rotete degrees |
||
| 5495 | * @param string $bgcolor square background color in #rrggbb format |
||
| 5496 | * @param string $destformat image destination format |
||
| 5497 | * @param int $jpgQuality JEPG quality (1-100) |
||
| 5498 | * @return string|false |
||
| 5499 | * @author nao-pon |
||
| 5500 | * @author Troex Nevelin |
||
| 5501 | **/ |
||
| 5502 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null, $jpgQuality = null) |
||
| 5639 | |||
| 5640 | /** |
||
| 5641 | * Execute shell command. |
||
| 5642 | * |
||
| 5643 | * @param string $command command line |
||
| 5644 | * @param array $output stdout strings |
||
| 5645 | * @param array|int $return_var process exit code |
||
| 5646 | * @param array $error_output stderr strings |
||
| 5647 | * @return int exit code |
||
| 5648 | * @author Alexey Sukhotin |
||
| 5649 | */ |
||
| 5650 | protected function procExec($command, array &$output = null, &$return_var = -1, array &$error_output = null) |
||
| 5701 | |||
| 5702 | /** |
||
| 5703 | * Remove thumbnail, also remove recursively if stat is directory. |
||
| 5704 | * |
||
| 5705 | * @param string $stat file stat |
||
| 5706 | * @return void |
||
| 5707 | * @author Dmitry (dio) Levashov |
||
| 5708 | * @author Naoki Sawada |
||
| 5709 | * @author Troex Nevelin |
||
| 5710 | **/ |
||
| 5711 | protected function rmTmb($stat) |
||
| 5725 | |||
| 5726 | /** |
||
| 5727 | * Create an gd image according to the specified mime type. |
||
| 5728 | * |
||
| 5729 | * @param string $path image file |
||
| 5730 | * @param string $mime |
||
| 5731 | * @return gd image resource identifier |
||
| 5732 | */ |
||
| 5733 | protected function gdImageCreate($path, $mime) |
||
| 5761 | |||
| 5762 | /** |
||
| 5763 | * Output gd image to file. |
||
| 5764 | * |
||
| 5765 | * @param resource $image gd image resource |
||
| 5766 | * @param string $filename The path to save the file to. |
||
| 5767 | * @param string $destformat The Image type to use for $filename |
||
| 5768 | * @param string $mime The original image mime type |
||
| 5769 | * @param int $jpgQuality JEPG quality (1-100) |
||
| 5770 | * @return bool |
||
| 5771 | */ |
||
| 5772 | protected function gdImage($image, $filename, $destformat, $mime, $jpgQuality = null) |
||
| 5803 | |||
| 5804 | /** |
||
| 5805 | * Output imagick image to file. |
||
| 5806 | * |
||
| 5807 | * @param resource $img imagick image resource |
||
| 5808 | * @param string $filename The path to save the file to. |
||
| 5809 | * @param string $destformat The Image type to use for $filename |
||
| 5810 | * @param int $jpgQuality JEPG quality (1-100) |
||
| 5811 | * @return bool |
||
| 5812 | */ |
||
| 5813 | protected function imagickImage($img, $filename, $destformat, $jpgQuality = null) |
||
| 5849 | |||
| 5850 | /** |
||
| 5851 | * Assign the proper background to a gd image. |
||
| 5852 | * |
||
| 5853 | * @param resource $image gd image resource |
||
| 5854 | * @param string $bgcolor background color in #rrggbb format |
||
| 5855 | */ |
||
| 5856 | protected function gdImageBackground($image, $bgcolor) |
||
| 5867 | |||
| 5868 | /** |
||
| 5869 | * Prepare variables for exec convert of ImageMagick. |
||
| 5870 | * |
||
| 5871 | * @param string $path |
||
| 5872 | * @param string $destformat |
||
| 5873 | * @param int $jpgQuality |
||
| 5874 | * @param array $imageSize |
||
| 5875 | * @return array |
||
| 5876 | */ |
||
| 5877 | protected function imageMagickConvertPrepare($path, $destformat, $jpgQuality, $imageSize = null) |
||
| 5924 | |||
| 5925 | /*********************** misc *************************/ |
||
| 5926 | |||
| 5927 | /** |
||
| 5928 | * Return smart formatted date. |
||
| 5929 | * |
||
| 5930 | * @param int $ts file timestamp |
||
| 5931 | * @return string |
||
| 5932 | * @author Dmitry (dio) Levashov |
||
| 5933 | **/ |
||
| 5934 | // protected function formatDate($ts) { |
||
| 5935 | // if ($ts > $this->today) { |
||
| 5936 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
| 5937 | // } |
||
| 5938 | // |
||
| 5939 | // if ($ts > $this->yesterday) { |
||
| 5940 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
| 5941 | // } |
||
| 5942 | // |
||
| 5943 | // return date($this->options['dateFormat'], $ts); |
||
| 5944 | // } |
||
| 5945 | |||
| 5946 | /** |
||
| 5947 | * Find position of first occurrence of string in a string with multibyte support. |
||
| 5948 | * |
||
| 5949 | * @param string $haystack The string being checked. |
||
| 5950 | * @param string $needle The string to find in haystack. |
||
| 5951 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
| 5952 | * @return int|bool |
||
| 5953 | * @author Alexey Sukhotin |
||
| 5954 | **/ |
||
| 5955 | protected function stripos($haystack, $needle, $offset = 0) |
||
| 5965 | |||
| 5966 | /** |
||
| 5967 | * Get server side available archivers. |
||
| 5968 | * |
||
| 5969 | * @param bool $use_cache |
||
| 5970 | * @return array |
||
| 5971 | */ |
||
| 5972 | protected function getArchivers($use_cache = true) |
||
| 6088 | |||
| 6089 | /** |
||
| 6090 | * Resolve relative / (Unix-like)absolute path. |
||
| 6091 | * |
||
| 6092 | * @param string $path target path |
||
| 6093 | * @param string $base base path |
||
| 6094 | * @return string |
||
| 6095 | */ |
||
| 6096 | protected function getFullPath($path, $base) |
||
| 6141 | |||
| 6142 | /** |
||
| 6143 | * Create archive and return its path. |
||
| 6144 | * |
||
| 6145 | * @param string $dir target dir |
||
| 6146 | * @param array $files files names list |
||
| 6147 | * @param string $name archive name |
||
| 6148 | * @param array $arc archiver options |
||
| 6149 | * @return string|bool |
||
| 6150 | * @author Dmitry (dio) Levashov, |
||
| 6151 | * @author Alexey Sukhotin |
||
| 6152 | * @author Naoki Sawada |
||
| 6153 | **/ |
||
| 6154 | protected function makeArchive($dir, $files, $name, $arc) |
||
| 6179 | |||
| 6180 | /** |
||
| 6181 | * Unpack archive. |
||
| 6182 | * |
||
| 6183 | * @param string $path archive path |
||
| 6184 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
| 6185 | * @param bool|string $mode bool: remove archive ( unlink($path) ) | string: extract to directory |
||
| 6186 | * @return void |
||
| 6187 | * @author Dmitry (dio) Levashov |
||
| 6188 | * @author Alexey Sukhotin |
||
| 6189 | * @author Naoki Sawada |
||
| 6190 | **/ |
||
| 6191 | protected function unpackArchive($path, $arc, $mode = true) |
||
| 6222 | |||
| 6223 | /** |
||
| 6224 | * Check and filter the extracted items. |
||
| 6225 | * |
||
| 6226 | * @param string $path target local path |
||
| 6227 | * @param array $checks types to check default: ['symlink', 'name', 'writable', 'mime'] |
||
| 6228 | * @return array ['symlinks' => [], 'names' => [], 'writables' => [], 'mimes' => [], 'rmNames' => [], 'totalSize' => 0] |
||
| 6229 | * @author Naoki Sawada |
||
| 6230 | */ |
||
| 6231 | protected function checkExtractItems($path, $checks = null) |
||
| 6316 | |||
| 6317 | /** |
||
| 6318 | * Return files of target directory that is dotfiles excludes. |
||
| 6319 | * |
||
| 6320 | * @param string $dir target directory path |
||
| 6321 | * @return array |
||
| 6322 | * @throws Exception |
||
| 6323 | * @author Naoki Sawada |
||
| 6324 | */ |
||
| 6325 | protected static function localScandir($dir) |
||
| 6343 | |||
| 6344 | /** |
||
| 6345 | * Remove directory recursive on local file system. |
||
| 6346 | * |
||
| 6347 | * @param string $dir Target dirctory path |
||
| 6348 | * @return bool |
||
| 6349 | * @author Naoki Sawada |
||
| 6350 | */ |
||
| 6351 | protected static function localRmdirRecursive($dir) |
||
| 6381 | |||
| 6382 | /** |
||
| 6383 | * Move item recursive on local file system. |
||
| 6384 | * |
||
| 6385 | * @param string $src |
||
| 6386 | * @param string $target |
||
| 6387 | * @param string $overWrite |
||
| 6388 | * @param string $copyJoin |
||
| 6389 | * @return bool |
||
| 6390 | * @author Naoki Sawada |
||
| 6391 | */ |
||
| 6392 | protected static function localMoveRecursive($src, $target, $overWrite = true, $copyJoin = true) |
||
| 6417 | |||
| 6418 | /** |
||
| 6419 | * Create Zip archive using PHP class ZipArchive. |
||
| 6420 | * |
||
| 6421 | * @param string $dir target dir |
||
| 6422 | * @param array $files files names list |
||
| 6423 | * @param string|object $zipPath Zip archive name |
||
| 6424 | * @return bool |
||
| 6425 | * @author Naoki Sawada |
||
| 6426 | */ |
||
| 6427 | protected static function zipArchiveZip($dir, $files, $zipPath) |
||
| 6467 | |||
| 6468 | /** |
||
| 6469 | * Unpack Zip archive using PHP class ZipArchive. |
||
| 6470 | * |
||
| 6471 | * @param string $zipPath Zip archive name |
||
| 6472 | * @param string $toDir Extract to path |
||
| 6473 | * @return bool |
||
| 6474 | * @author Naoki Sawada |
||
| 6475 | */ |
||
| 6476 | protected static function zipArchiveUnzip($zipPath, $toDir) |
||
| 6490 | |||
| 6491 | /** |
||
| 6492 | * Recursive symlinks search. |
||
| 6493 | * |
||
| 6494 | * @param string $path file/dir path |
||
| 6495 | * @return bool |
||
| 6496 | * @author Dmitry (dio) Levashov |
||
| 6497 | **/ |
||
| 6498 | protected static function localFindSymlinks($path) |
||
| 6518 | |||
| 6519 | /**==================================* abstract methods *====================================**/ |
||
| 6520 | |||
| 6521 | /*********************** paths/urls *************************/ |
||
| 6522 | |||
| 6523 | /** |
||
| 6524 | * Return parent directory path. |
||
| 6525 | * |
||
| 6526 | * @param string $path file path |
||
| 6527 | * @return string |
||
| 6528 | * @author Dmitry (dio) Levashov |
||
| 6529 | **/ |
||
| 6530 | abstract protected function _dirname($path); |
||
| 6531 | |||
| 6532 | /** |
||
| 6533 | * Return file name. |
||
| 6534 | * |
||
| 6535 | * @param string $path file path |
||
| 6536 | * @return string |
||
| 6537 | * @author Dmitry (dio) Levashov |
||
| 6538 | **/ |
||
| 6539 | abstract protected function _basename($path); |
||
| 6540 | |||
| 6541 | /** |
||
| 6542 | * Join dir name and file name and return full path. |
||
| 6543 | * Some drivers (db) use int as path - so we give to concat path to driver itself. |
||
| 6544 | * |
||
| 6545 | * @param string $dir dir path |
||
| 6546 | * @param string $name file name |
||
| 6547 | * @return string |
||
| 6548 | * @author Dmitry (dio) Levashov |
||
| 6549 | **/ |
||
| 6550 | abstract protected function _joinPath($dir, $name); |
||
| 6551 | |||
| 6552 | /** |
||
| 6553 | * Return normalized path. |
||
| 6554 | * |
||
| 6555 | * @param string $path file path |
||
| 6556 | * @return string |
||
| 6557 | * @author Dmitry (dio) Levashov |
||
| 6558 | **/ |
||
| 6559 | abstract protected function _normpath($path); |
||
| 6560 | |||
| 6561 | /** |
||
| 6562 | * Return file path related to root dir. |
||
| 6563 | * |
||
| 6564 | * @param string $path file path |
||
| 6565 | * @return string |
||
| 6566 | * @author Dmitry (dio) Levashov |
||
| 6567 | **/ |
||
| 6568 | abstract protected function _relpath($path); |
||
| 6569 | |||
| 6570 | /** |
||
| 6571 | * Convert path related to root dir into real path. |
||
| 6572 | * |
||
| 6573 | * @param string $path rel file path |
||
| 6574 | * @return string |
||
| 6575 | * @author Dmitry (dio) Levashov |
||
| 6576 | **/ |
||
| 6577 | abstract protected function _abspath($path); |
||
| 6578 | |||
| 6579 | /** |
||
| 6580 | * Return fake path started from root dir. |
||
| 6581 | * Required to show path on client side. |
||
| 6582 | * |
||
| 6583 | * @param string $path file path |
||
| 6584 | * @return string |
||
| 6585 | * @author Dmitry (dio) Levashov |
||
| 6586 | **/ |
||
| 6587 | abstract protected function _path($path); |
||
| 6588 | |||
| 6589 | /** |
||
| 6590 | * Return true if $path is children of $parent. |
||
| 6591 | * |
||
| 6592 | * @param string $path path to check |
||
| 6593 | * @param string $parent parent path |
||
| 6594 | * @return bool |
||
| 6595 | * @author Dmitry (dio) Levashov |
||
| 6596 | **/ |
||
| 6597 | abstract protected function _inpath($path, $parent); |
||
| 6598 | |||
| 6599 | /** |
||
| 6600 | * Return stat for given path. |
||
| 6601 | * Stat contains following fields: |
||
| 6602 | * - (int) size file size in b. required |
||
| 6603 | * - (int) ts file modification time in unix time. required |
||
| 6604 | * - (string) mime mimetype. required for folders, others - optionally |
||
| 6605 | * - (bool) read read permissions. required |
||
| 6606 | * - (bool) write write permissions. required |
||
| 6607 | * - (bool) locked is object locked. optionally |
||
| 6608 | * - (bool) hidden is object hidden. optionally |
||
| 6609 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
| 6610 | * - (string) target for symlinks - link target path. optionally. |
||
| 6611 | * |
||
| 6612 | * If file does not exists - returns empty array or false. |
||
| 6613 | * |
||
| 6614 | * @param string $path file path |
||
| 6615 | * @return array|false |
||
| 6616 | * @author Dmitry (dio) Levashov |
||
| 6617 | **/ |
||
| 6618 | abstract protected function _stat($path); |
||
| 6619 | |||
| 6620 | /***************** file stat ********************/ |
||
| 6621 | |||
| 6622 | /** |
||
| 6623 | * Return true if path is dir and has at least one childs directory. |
||
| 6624 | * |
||
| 6625 | * @param string $path dir path |
||
| 6626 | * @return bool |
||
| 6627 | * @author Dmitry (dio) Levashov |
||
| 6628 | **/ |
||
| 6629 | abstract protected function _subdirs($path); |
||
| 6630 | |||
| 6631 | /** |
||
| 6632 | * Return object width and height |
||
| 6633 | * Ususaly used for images, but can be realize for video etc... |
||
| 6634 | * |
||
| 6635 | * @param string $path file path |
||
| 6636 | * @param string $mime file mime type |
||
| 6637 | * @return string |
||
| 6638 | * @author Dmitry (dio) Levashov |
||
| 6639 | **/ |
||
| 6640 | abstract protected function _dimensions($path, $mime); |
||
| 6641 | |||
| 6642 | /******************** file/dir content *********************/ |
||
| 6643 | |||
| 6644 | /** |
||
| 6645 | * Return files list in directory. |
||
| 6646 | * |
||
| 6647 | * @param string $path dir path |
||
| 6648 | * @return array |
||
| 6649 | * @author Dmitry (dio) Levashov |
||
| 6650 | **/ |
||
| 6651 | abstract protected function _scandir($path); |
||
| 6652 | |||
| 6653 | /** |
||
| 6654 | * Open file and return file pointer. |
||
| 6655 | * |
||
| 6656 | * @param string $path file path |
||
| 6657 | * @param string $mode open mode |
||
| 6658 | * @return resource|false |
||
| 6659 | * @author Dmitry (dio) Levashov |
||
| 6660 | **/ |
||
| 6661 | abstract protected function _fopen($path, $mode = 'rb'); |
||
| 6662 | |||
| 6663 | /** |
||
| 6664 | * Close opened file. |
||
| 6665 | * |
||
| 6666 | * @param resource $fp file pointer |
||
| 6667 | * @param string $path file path |
||
| 6668 | * @return bool |
||
| 6669 | * @author Dmitry (dio) Levashov |
||
| 6670 | **/ |
||
| 6671 | abstract protected function _fclose($fp, $path = ''); |
||
| 6672 | |||
| 6673 | /******************** file/dir manipulations *************************/ |
||
| 6674 | |||
| 6675 | /** |
||
| 6676 | * Create dir and return created dir path or false on failed. |
||
| 6677 | * |
||
| 6678 | * @param string $path parent dir path |
||
| 6679 | * @param string $name new directory name |
||
| 6680 | * @return string|bool |
||
| 6681 | * @author Dmitry (dio) Levashov |
||
| 6682 | **/ |
||
| 6683 | abstract protected function _mkdir($path, $name); |
||
| 6684 | |||
| 6685 | /** |
||
| 6686 | * Create file and return it's path or false on failed. |
||
| 6687 | * |
||
| 6688 | * @param string $path parent dir path |
||
| 6689 | * @param string $name new file name |
||
| 6690 | * @return string|bool |
||
| 6691 | * @author Dmitry (dio) Levashov |
||
| 6692 | **/ |
||
| 6693 | abstract protected function _mkfile($path, $name); |
||
| 6694 | |||
| 6695 | /** |
||
| 6696 | * Create symlink. |
||
| 6697 | * |
||
| 6698 | * @param string $source file to link to |
||
| 6699 | * @param string $targetDir folder to create link in |
||
| 6700 | * @param string $name symlink name |
||
| 6701 | * @return bool |
||
| 6702 | * @author Dmitry (dio) Levashov |
||
| 6703 | **/ |
||
| 6704 | abstract protected function _symlink($source, $targetDir, $name); |
||
| 6705 | |||
| 6706 | /** |
||
| 6707 | * Copy file into another file (only inside one volume). |
||
| 6708 | * |
||
| 6709 | * @param string $source source file path |
||
| 6710 | * @param $targetDir |
||
| 6711 | * @param string $name file name |
||
| 6712 | * @return bool|string |
||
| 6713 | * @internal param string $target target dir path |
||
| 6714 | * @author Dmitry (dio) Levashov |
||
| 6715 | */ |
||
| 6716 | abstract protected function _copy($source, $targetDir, $name); |
||
| 6717 | |||
| 6718 | /** |
||
| 6719 | * Move file into another parent dir. |
||
| 6720 | * Return new file path or false. |
||
| 6721 | * |
||
| 6722 | * @param string $source source file path |
||
| 6723 | * @param $targetDir |
||
| 6724 | * @param string $name file name |
||
| 6725 | * @return bool|string |
||
| 6726 | * @internal param string $target target dir path |
||
| 6727 | * @author Dmitry (dio) Levashov |
||
| 6728 | */ |
||
| 6729 | abstract protected function _move($source, $targetDir, $name); |
||
| 6730 | |||
| 6731 | /** |
||
| 6732 | * Remove file. |
||
| 6733 | * |
||
| 6734 | * @param string $path file path |
||
| 6735 | * @return bool |
||
| 6736 | * @author Dmitry (dio) Levashov |
||
| 6737 | **/ |
||
| 6738 | abstract protected function _unlink($path); |
||
| 6739 | |||
| 6740 | /** |
||
| 6741 | * Remove dir. |
||
| 6742 | * |
||
| 6743 | * @param string $path dir path |
||
| 6744 | * @return bool |
||
| 6745 | * @author Dmitry (dio) Levashov |
||
| 6746 | **/ |
||
| 6747 | abstract protected function _rmdir($path); |
||
| 6748 | |||
| 6749 | /** |
||
| 6750 | * Create new file and write into it from file pointer. |
||
| 6751 | * Return new file path or false on error. |
||
| 6752 | * |
||
| 6753 | * @param resource $fp file pointer |
||
| 6754 | * @param string $dir target dir path |
||
| 6755 | * @param string $name file name |
||
| 6756 | * @param array $stat file stat (required by some virtual fs) |
||
| 6757 | * @return bool|string |
||
| 6758 | * @author Dmitry (dio) Levashov |
||
| 6759 | **/ |
||
| 6760 | abstract protected function _save($fp, $dir, $name, $stat); |
||
| 6761 | |||
| 6762 | /** |
||
| 6763 | * Get file contents. |
||
| 6764 | * |
||
| 6765 | * @param string $path file path |
||
| 6766 | * @return string|false |
||
| 6767 | * @author Dmitry (dio) Levashov |
||
| 6768 | **/ |
||
| 6769 | abstract protected function _getContents($path); |
||
| 6770 | |||
| 6771 | /** |
||
| 6772 | * Write a string to a file. |
||
| 6773 | * |
||
| 6774 | * @param string $path file path |
||
| 6775 | * @param string $content new file content |
||
| 6776 | * @return bool |
||
| 6777 | * @author Dmitry (dio) Levashov |
||
| 6778 | **/ |
||
| 6779 | abstract protected function _filePutContents($path, $content); |
||
| 6780 | |||
| 6781 | /** |
||
| 6782 | * Extract files from archive. |
||
| 6783 | * |
||
| 6784 | * @param string $path file path |
||
| 6785 | * @param array $arc archiver options |
||
| 6786 | * @return bool |
||
| 6787 | * @author Dmitry (dio) Levashov, |
||
| 6788 | * @author Alexey Sukhotin |
||
| 6789 | **/ |
||
| 6790 | abstract protected function _extract($path, $arc); |
||
| 6791 | |||
| 6792 | /** |
||
| 6793 | * Create archive and return its path. |
||
| 6794 | * |
||
| 6795 | * @param string $dir target dir |
||
| 6796 | * @param array $files files names list |
||
| 6797 | * @param string $name archive name |
||
| 6798 | * @param array $arc archiver options |
||
| 6799 | * @return string|bool |
||
| 6800 | * @author Dmitry (dio) Levashov, |
||
| 6801 | * @author Alexey Sukhotin |
||
| 6802 | **/ |
||
| 6803 | abstract protected function _archive($dir, $files, $name, $arc); |
||
| 6804 | |||
| 6805 | /** |
||
| 6806 | * Detect available archivers. |
||
| 6807 | * |
||
| 6808 | * @return void |
||
| 6809 | * @author Dmitry (dio) Levashov, |
||
| 6810 | * @author Alexey Sukhotin |
||
| 6811 | **/ |
||
| 6812 | abstract protected function _checkArchivers(); |
||
| 6813 | |||
| 6814 | /** |
||
| 6815 | * Change file mode (chmod). |
||
| 6816 | * |
||
| 6817 | * @param string $path file path |
||
| 6818 | * @param string $mode octal string such as '0755' |
||
| 6819 | * @return bool |
||
| 6820 | * @author David Bartle, |
||
| 6821 | **/ |
||
| 6822 | abstract protected function _chmod($path, $mode); |
||
| 6823 | } // END class |
||
| 6824 |
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.