Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like elFinderVolumeDriver often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use elFinderVolumeDriver, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | abstract class elFinderVolumeDriver { |
||
|
|
|||
| 15 | |||
| 16 | /** |
||
| 17 | * Request args |
||
| 18 | * $_POST or $_GET values |
||
| 19 | * |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | protected $ARGS = array(); |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Driver id |
||
| 26 | * Must be started from letter and contains [a-z0-9] |
||
| 27 | * Used as part of volume id |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | **/ |
||
| 31 | protected $driverId = 'a'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Volume id - used as prefix for files hashes |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | **/ |
||
| 38 | protected $id = ''; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Flag - volume "mounted" and available |
||
| 42 | * |
||
| 43 | * @var bool |
||
| 44 | **/ |
||
| 45 | protected $mounted = false; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Root directory path |
||
| 49 | * |
||
| 50 | * @var string |
||
| 51 | **/ |
||
| 52 | protected $root = ''; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Root basename | alias |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | **/ |
||
| 59 | protected $rootName = ''; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Default directory to open |
||
| 63 | * |
||
| 64 | * @var string |
||
| 65 | **/ |
||
| 66 | protected $startPath = ''; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Base URL |
||
| 70 | * |
||
| 71 | * @var string |
||
| 72 | **/ |
||
| 73 | protected $URL = ''; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Thumbnails dir path |
||
| 77 | * |
||
| 78 | * @var string |
||
| 79 | **/ |
||
| 80 | protected $tmbPath = ''; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Is thumbnails dir writable |
||
| 84 | * |
||
| 85 | * @var bool |
||
| 86 | **/ |
||
| 87 | protected $tmbPathWritable = false; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Thumbnails base URL |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | **/ |
||
| 94 | protected $tmbURL = ''; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Thumbnails size in px |
||
| 98 | * |
||
| 99 | * @var int |
||
| 100 | **/ |
||
| 101 | protected $tmbSize = 48; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Image manipulation lib name |
||
| 105 | * auto|imagick|mogtify|gd |
||
| 106 | * |
||
| 107 | * @var string |
||
| 108 | **/ |
||
| 109 | protected $imgLib = 'auto'; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Library to crypt files name |
||
| 113 | * |
||
| 114 | * @var string |
||
| 115 | **/ |
||
| 116 | protected $cryptLib = ''; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Archivers config |
||
| 120 | * |
||
| 121 | * @var array |
||
| 122 | **/ |
||
| 123 | protected $archivers = array( |
||
| 124 | 'create' => array(), |
||
| 125 | 'extract' => array() |
||
| 126 | ); |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Server character encoding |
||
| 130 | * |
||
| 131 | * @var string or null |
||
| 132 | **/ |
||
| 133 | protected $encoding = null; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * How many subdirs levels return for tree |
||
| 137 | * |
||
| 138 | * @var int |
||
| 139 | **/ |
||
| 140 | protected $treeDeep = 1; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Errors from last failed action |
||
| 144 | * |
||
| 145 | * @var array |
||
| 146 | **/ |
||
| 147 | protected $error = array(); |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Today 24:00 timestamp |
||
| 151 | * |
||
| 152 | * @var int |
||
| 153 | **/ |
||
| 154 | protected $today = 0; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Yesterday 24:00 timestamp |
||
| 158 | * |
||
| 159 | * @var int |
||
| 160 | **/ |
||
| 161 | protected $yesterday = 0; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Force make dirctory on extract |
||
| 165 | * |
||
| 166 | * @var int |
||
| 167 | **/ |
||
| 168 | protected $extractToNewdir = 'auto'; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Object configuration |
||
| 172 | * |
||
| 173 | * @var array |
||
| 174 | **/ |
||
| 175 | protected $options = array( |
||
| 176 | 'id' => '', |
||
| 177 | // root directory path |
||
| 178 | 'path' => '', |
||
| 179 | // open this path on initial request instead of root path |
||
| 180 | 'startPath' => '', |
||
| 181 | // how many subdirs levels return per request |
||
| 182 | 'treeDeep' => 1, |
||
| 183 | // root url, not set to disable sending URL to client (replacement for old "fileURL" option) |
||
| 184 | 'URL' => '', |
||
| 185 | // directory separator. required by client to show paths correctly |
||
| 186 | 'separator' => DIRECTORY_SEPARATOR, |
||
| 187 | // Server character encoding (default is '': UTF-8) |
||
| 188 | 'encoding' => '', |
||
| 189 | // for convert character encoding (default is '': Not change locale) |
||
| 190 | 'locale' => '', |
||
| 191 | // URL of volume icon (16x16 pixel image file) |
||
| 192 | 'icon' => '', |
||
| 193 | // CSS Class of volume root in tree |
||
| 194 | 'rootCssClass' => '', |
||
| 195 | // library to crypt/uncrypt files names (not implemented) |
||
| 196 | 'cryptLib' => '', |
||
| 197 | // how to detect files mimetypes. (auto/internal/finfo/mime_content_type) |
||
| 198 | 'mimeDetect' => 'auto', |
||
| 199 | // mime.types file path (for mimeDetect==internal) |
||
| 200 | 'mimefile' => '', |
||
| 201 | // mime type normalize map : Array '[ext]:[detected mime type]' => '[normalized mime]' |
||
| 202 | 'mimeMap' => array( |
||
| 203 | 'md:application/x-genesis-rom' => 'text/x-markdown', |
||
| 204 | 'md:text/plain' => 'text/x-markdown', |
||
| 205 | 'markdown:text/plain' => 'text/x-markdown', |
||
| 206 | 'css:text/x-asm' => 'text/css' |
||
| 207 | ), |
||
| 208 | // MIME regex of send HTTP header "Content-Disposition: inline" |
||
| 209 | // '.' is allow inline of all of MIME types |
||
| 210 | // '$^' is not allow inline of all of MIME types |
||
| 211 | 'dispInlineRegex' => '^(?:(?:image|text)|application/x-shockwave-flash$)', |
||
| 212 | // directory for thumbnails |
||
| 213 | 'tmbPath' => '.tmb', |
||
| 214 | // mode to create thumbnails dir |
||
| 215 | 'tmbPathMode' => 0777, |
||
| 216 | // thumbnails dir URL. Set it if store thumbnails outside root directory |
||
| 217 | 'tmbURL' => '', |
||
| 218 | // thumbnails size (px) |
||
| 219 | 'tmbSize' => 48, |
||
| 220 | // thumbnails crop (true - crop, false - scale image to fit thumbnail size) |
||
| 221 | 'tmbCrop' => true, |
||
| 222 | // thumbnails background color (hex #rrggbb or 'transparent') |
||
| 223 | 'tmbBgColor' => '#ffffff', |
||
| 224 | // image manipulations library |
||
| 225 | 'imgLib' => 'auto', |
||
| 226 | // on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 227 | 'copyOverwrite' => true, |
||
| 228 | // if true - join new and old directories content on paste |
||
| 229 | 'copyJoin' => true, |
||
| 230 | // on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 231 | 'uploadOverwrite' => true, |
||
| 232 | // mimetypes allowed to upload |
||
| 233 | 'uploadAllow' => array(), |
||
| 234 | // mimetypes not allowed to upload |
||
| 235 | 'uploadDeny' => array(), |
||
| 236 | // order to proccess uploadAllow and uploadDeny options |
||
| 237 | 'uploadOrder' => array('deny', 'allow'), |
||
| 238 | // maximum upload file size. NOTE - this is size for every uploaded files |
||
| 239 | 'uploadMaxSize' => 0, |
||
| 240 | // files dates format |
||
| 241 | 'dateFormat' => 'j M Y H:i', |
||
| 242 | // files time format |
||
| 243 | 'timeFormat' => 'H:i', |
||
| 244 | // if true - every folder will be check for children folders, otherwise all folders will be marked as having subfolders |
||
| 245 | 'checkSubfolders' => true, |
||
| 246 | // allow to copy from this volume to other ones? |
||
| 247 | 'copyFrom' => true, |
||
| 248 | // allow to copy from other volumes to this one? |
||
| 249 | 'copyTo' => true, |
||
| 250 | // list of commands disabled on this root |
||
| 251 | 'disabled' => array(), |
||
| 252 | // enable file owner, group & mode info, `false` to inactivate "chmod" command. |
||
| 253 | 'statOwner' => false, |
||
| 254 | // allow exec chmod of read-only files |
||
| 255 | 'allowChmodReadOnly' => false, |
||
| 256 | // regexp or function name to validate new file name |
||
| 257 | 'acceptedName' => '/^[^\.].*/', //<-- DONT touch this! Use constructor options to overwrite it! |
||
| 258 | // function/class method to control files permissions |
||
| 259 | 'accessControl' => null, |
||
| 260 | // some data required by access control |
||
| 261 | 'accessControlData' => null, |
||
| 262 | // default permissions. |
||
| 263 | 'defaults' => array( |
||
| 264 | 'read' => true, |
||
| 265 | 'write' => true, |
||
| 266 | 'locked' => false, |
||
| 267 | 'hidden' => false |
||
| 268 | ), |
||
| 269 | // files attributes |
||
| 270 | 'attributes' => array(), |
||
| 271 | // Allowed archive's mimetypes to create. Leave empty for all available types. |
||
| 272 | 'archiveMimes' => array(), |
||
| 273 | // Manual config for archivers. See example below. Leave empty for auto detect |
||
| 274 | 'archivers' => array(), |
||
| 275 | // plugin settings |
||
| 276 | 'plugin' => array(), |
||
| 277 | // required to fix bug on macos |
||
| 278 | 'utf8fix' => false, |
||
| 279 | // й ё Й Ё Ø Å |
||
| 280 | 'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"), |
||
| 281 | 'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5") |
||
| 282 | ); |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Defaults permissions |
||
| 286 | * |
||
| 287 | * @var array |
||
| 288 | **/ |
||
| 289 | protected $defaults = array( |
||
| 290 | 'read' => true, |
||
| 291 | 'write' => true, |
||
| 292 | 'locked' => false, |
||
| 293 | 'hidden' => false |
||
| 294 | ); |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Access control function/class |
||
| 298 | * |
||
| 299 | * @var mixed |
||
| 300 | **/ |
||
| 301 | protected $attributes = array(); |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Access control function/class |
||
| 305 | * |
||
| 306 | * @var mixed |
||
| 307 | **/ |
||
| 308 | protected $access = null; |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Mime types allowed to upload |
||
| 312 | * |
||
| 313 | * @var array |
||
| 314 | **/ |
||
| 315 | protected $uploadAllow = array(); |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Mime types denied to upload |
||
| 319 | * |
||
| 320 | * @var array |
||
| 321 | **/ |
||
| 322 | protected $uploadDeny = array(); |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Order to validate uploadAllow and uploadDeny |
||
| 326 | * |
||
| 327 | * @var array |
||
| 328 | **/ |
||
| 329 | protected $uploadOrder = array(); |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Maximum allowed upload file size. |
||
| 333 | * Set as number or string with unit - "10M", "500K", "1G" |
||
| 334 | * |
||
| 335 | * @var int|string |
||
| 336 | **/ |
||
| 337 | protected $uploadMaxSize = 0; |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Mimetype detect method |
||
| 341 | * |
||
| 342 | * @var string |
||
| 343 | **/ |
||
| 344 | protected $mimeDetect = 'auto'; |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Flag - mimetypes from externail file was loaded |
||
| 348 | * |
||
| 349 | * @var bool |
||
| 350 | **/ |
||
| 351 | private static $mimetypesLoaded = false; |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Finfo object for mimeDetect == 'finfo' |
||
| 355 | * |
||
| 356 | * @var object |
||
| 357 | **/ |
||
| 358 | protected $finfo = null; |
||
| 359 | |||
| 360 | /** |
||
| 361 | * List of disabled client's commands |
||
| 362 | * |
||
| 363 | * @var array |
||
| 364 | **/ |
||
| 365 | protected $disabled = array(); |
||
| 366 | |||
| 367 | /** |
||
| 368 | * default extensions/mimetypes for mimeDetect == 'internal' |
||
| 369 | * |
||
| 370 | * @var array |
||
| 371 | **/ |
||
| 372 | protected static $mimetypes = array( |
||
| 373 | // applications |
||
| 374 | 'ai' => 'application/postscript', |
||
| 375 | 'eps' => 'application/postscript', |
||
| 376 | 'exe' => 'application/x-executable', |
||
| 377 | 'doc' => 'application/msword', |
||
| 378 | 'dot' => 'application/msword', |
||
| 379 | 'xls' => 'application/vnd.ms-excel', |
||
| 380 | 'xlt' => 'application/vnd.ms-excel', |
||
| 381 | 'xla' => 'application/vnd.ms-excel', |
||
| 382 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
| 383 | 'pps' => 'application/vnd.ms-powerpoint', |
||
| 384 | 'pdf' => 'application/pdf', |
||
| 385 | 'xml' => 'application/xml', |
||
| 386 | 'swf' => 'application/x-shockwave-flash', |
||
| 387 | 'torrent' => 'application/x-bittorrent', |
||
| 388 | 'jar' => 'application/x-jar', |
||
| 389 | // open office (finfo detect as application/zip) |
||
| 390 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
| 391 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
| 392 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
| 393 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
| 394 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
| 395 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
| 396 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
| 397 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
| 398 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
| 399 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
| 400 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
| 401 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
| 402 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
| 403 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
| 404 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
| 405 | // MS office 2007 (finfo detect as application/zip) |
||
| 406 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
| 407 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
| 408 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
| 409 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
| 410 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
| 411 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
| 412 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
| 413 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
| 414 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
| 415 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
| 416 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
| 417 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
| 418 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
| 419 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
| 420 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
| 421 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
| 422 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
| 423 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
| 424 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
| 425 | // archives |
||
| 426 | 'gz' => 'application/x-gzip', |
||
| 427 | 'tgz' => 'application/x-gzip', |
||
| 428 | 'bz' => 'application/x-bzip2', |
||
| 429 | 'bz2' => 'application/x-bzip2', |
||
| 430 | 'tbz' => 'application/x-bzip2', |
||
| 431 | 'xz' => 'application/x-xz', |
||
| 432 | 'zip' => 'application/zip', |
||
| 433 | 'rar' => 'application/x-rar', |
||
| 434 | 'tar' => 'application/x-tar', |
||
| 435 | '7z' => 'application/x-7z-compressed', |
||
| 436 | // texts |
||
| 437 | 'txt' => 'text/plain', |
||
| 438 | 'php' => 'text/x-php', |
||
| 439 | 'html' => 'text/html', |
||
| 440 | 'htm' => 'text/html', |
||
| 441 | 'js' => 'text/javascript', |
||
| 442 | 'css' => 'text/css', |
||
| 443 | 'rtf' => 'text/rtf', |
||
| 444 | 'rtfd' => 'text/rtfd', |
||
| 445 | 'py' => 'text/x-python', |
||
| 446 | 'java' => 'text/x-java-source', |
||
| 447 | 'rb' => 'text/x-ruby', |
||
| 448 | 'sh' => 'text/x-shellscript', |
||
| 449 | 'pl' => 'text/x-perl', |
||
| 450 | 'xml' => 'text/xml', |
||
| 451 | 'sql' => 'text/x-sql', |
||
| 452 | 'c' => 'text/x-csrc', |
||
| 453 | 'h' => 'text/x-chdr', |
||
| 454 | 'cpp' => 'text/x-c++src', |
||
| 455 | 'hh' => 'text/x-c++hdr', |
||
| 456 | 'log' => 'text/plain', |
||
| 457 | 'csv' => 'text/x-comma-separated-values', |
||
| 458 | 'md' => 'text/x-markdown', |
||
| 459 | 'markdown' => 'text/x-markdown', |
||
| 460 | // images |
||
| 461 | 'bmp' => 'image/x-ms-bmp', |
||
| 462 | 'jpg' => 'image/jpeg', |
||
| 463 | 'jpeg' => 'image/jpeg', |
||
| 464 | 'gif' => 'image/gif', |
||
| 465 | 'png' => 'image/png', |
||
| 466 | 'tif' => 'image/tiff', |
||
| 467 | 'tiff' => 'image/tiff', |
||
| 468 | 'tga' => 'image/x-targa', |
||
| 469 | 'psd' => 'image/vnd.adobe.photoshop', |
||
| 470 | 'ai' => 'image/vnd.adobe.photoshop', |
||
| 471 | 'xbm' => 'image/xbm', |
||
| 472 | 'pxm' => 'image/pxm', |
||
| 473 | //audio |
||
| 474 | 'mp3' => 'audio/mpeg', |
||
| 475 | 'mid' => 'audio/midi', |
||
| 476 | 'ogg' => 'audio/ogg', |
||
| 477 | 'oga' => 'audio/ogg', |
||
| 478 | 'm4a' => 'audio/x-m4a', |
||
| 479 | 'wav' => 'audio/wav', |
||
| 480 | 'wma' => 'audio/x-ms-wma', |
||
| 481 | // video |
||
| 482 | 'avi' => 'video/x-msvideo', |
||
| 483 | 'dv' => 'video/x-dv', |
||
| 484 | 'mp4' => 'video/mp4', |
||
| 485 | 'mpeg' => 'video/mpeg', |
||
| 486 | 'mpg' => 'video/mpeg', |
||
| 487 | 'mov' => 'video/quicktime', |
||
| 488 | 'wm' => 'video/x-ms-wmv', |
||
| 489 | 'flv' => 'video/x-flv', |
||
| 490 | 'mkv' => 'video/x-matroska', |
||
| 491 | 'webm' => 'video/webm', |
||
| 492 | 'ogv' => 'video/ogg', |
||
| 493 | 'ogm' => 'video/ogg' |
||
| 494 | ); |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Directory separator - required by client |
||
| 498 | * |
||
| 499 | * @var string |
||
| 500 | **/ |
||
| 501 | protected $separator = DIRECTORY_SEPARATOR; |
||
| 502 | |||
| 503 | /** |
||
| 504 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...) |
||
| 505 | * |
||
| 506 | * @var string |
||
| 507 | **/ |
||
| 508 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Mimetypes allowed to display |
||
| 512 | * |
||
| 513 | * @var array |
||
| 514 | **/ |
||
| 515 | protected $onlyMimes = array(); |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Store files moved or overwrited files info |
||
| 519 | * |
||
| 520 | * @var array |
||
| 521 | **/ |
||
| 522 | protected $removed = array(); |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Cache storage |
||
| 526 | * |
||
| 527 | * @var array |
||
| 528 | **/ |
||
| 529 | protected $cache = array(); |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Cache by folders |
||
| 533 | * |
||
| 534 | * @var array |
||
| 535 | **/ |
||
| 536 | protected $dirsCache = array(); |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Cache for subdirsCE() |
||
| 540 | * |
||
| 541 | * @var array |
||
| 542 | */ |
||
| 543 | protected $subdirsCache = array(); |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Reference of $_SESSION[elFinder::$sessionCacheKey][$this->id] |
||
| 547 | * |
||
| 548 | * @var array |
||
| 549 | */ |
||
| 550 | protected $sessionCache; |
||
| 551 | |||
| 552 | /*********************************************************************/ |
||
| 553 | /* INITIALIZATION */ |
||
| 554 | /*********************************************************************/ |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Prepare driver before mount volume. |
||
| 558 | * Return true if volume is ready. |
||
| 559 | * |
||
| 560 | * @return bool |
||
| 561 | * @author Dmitry (dio) Levashov |
||
| 562 | **/ |
||
| 563 | protected function init() { |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Configure after successfull mount. |
||
| 569 | * By default set thumbnails path and image manipulation library. |
||
| 570 | * |
||
| 571 | * @return void |
||
| 572 | * @author Dmitry (dio) Levashov |
||
| 573 | **/ |
||
| 574 | protected function configure() { |
||
| 615 | |||
| 616 | |||
| 617 | /*********************************************************************/ |
||
| 618 | /* PUBLIC API */ |
||
| 619 | /*********************************************************************/ |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Return driver id. Used as a part of volume id. |
||
| 623 | * |
||
| 624 | * @return string |
||
| 625 | * @author Dmitry (dio) Levashov |
||
| 626 | **/ |
||
| 627 | public function driverId() { |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Return volume id |
||
| 633 | * |
||
| 634 | * @return string |
||
| 635 | * @author Dmitry (dio) Levashov |
||
| 636 | **/ |
||
| 637 | public function id() { |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Return debug info for client |
||
| 643 | * |
||
| 644 | * @return array |
||
| 645 | * @author Dmitry (dio) Levashov |
||
| 646 | **/ |
||
| 647 | public function debug() { |
||
| 655 | |||
| 656 | /** |
||
| 657 | * chmod a file or folder |
||
| 658 | * |
||
| 659 | * @param string $hash file or folder hash to chmod |
||
| 660 | * @param string $mode octal string representing new permissions |
||
| 661 | * @return array|false |
||
| 662 | * @author David Bartle |
||
| 663 | **/ |
||
| 664 | public function chmod($hash, $mode) { |
||
| 701 | |||
| 702 | /** |
||
| 703 | * "Mount" volume. |
||
| 704 | * Return true if volume available for read or write, |
||
| 705 | * false - otherwise |
||
| 706 | * |
||
| 707 | * @return bool |
||
| 708 | * @author Dmitry (dio) Levashov |
||
| 709 | * @author Alexey Sukhotin |
||
| 710 | **/ |
||
| 711 | public function mount(array $opts) { |
||
| 712 | if (!isset($opts['path']) || $opts['path'] === '') { |
||
| 713 | return $this->setError('Path undefined.');; |
||
| 714 | } |
||
| 715 | |||
| 716 | $this->options = array_merge($this->options, $opts); |
||
| 717 | $this->id = $this->driverId.(!empty($this->options['id']) ? $this->options['id'] : elFinder::$volumesCnt++).'_'; |
||
| 718 | $this->root = $this->normpathCE($this->options['path']); |
||
| 719 | $this->separator = isset($this->options['separator']) ? $this->options['separator'] : DIRECTORY_SEPARATOR; |
||
| 720 | $this->systemRoot = isset($this->options['systemRoot']) ? $this->options['systemRoot'] : $this->separator; |
||
| 721 | |||
| 722 | // set server encoding |
||
| 723 | if (!empty($this->options['encoding']) && strtoupper($this->options['encoding']) !== 'UTF-8') { |
||
| 724 | $this->encoding = $this->options['encoding']; |
||
| 725 | } else { |
||
| 726 | $this->encoding = null; |
||
| 727 | } |
||
| 728 | |||
| 729 | $argInit = !empty($this->ARGS['init']); |
||
| 730 | |||
| 731 | // session cache |
||
| 732 | if ($argInit || ! isset($_SESSION[elFinder::$sessionCacheKey][$this->id])) { |
||
| 733 | $_SESSION[elFinder::$sessionCacheKey][$this->id] = array(); |
||
| 734 | } |
||
| 735 | $this->sessionCache = &$_SESSION[elFinder::$sessionCacheKey][$this->id]; |
||
| 736 | |||
| 737 | // default file attribute |
||
| 738 | $this->defaults = array( |
||
| 739 | 'read' => isset($this->options['defaults']['read']) ? !!$this->options['defaults']['read'] : true, |
||
| 740 | 'write' => isset($this->options['defaults']['write']) ? !!$this->options['defaults']['write'] : true, |
||
| 741 | 'locked' => isset($this->options['defaults']['locked']) ? !!$this->options['defaults']['locked'] : false, |
||
| 742 | 'hidden' => isset($this->options['defaults']['hidden']) ? !!$this->options['defaults']['hidden'] : false |
||
| 743 | ); |
||
| 744 | |||
| 745 | // root attributes |
||
| 746 | $this->attributes[] = array( |
||
| 747 | 'pattern' => '~^'.preg_quote(DIRECTORY_SEPARATOR).'$~', |
||
| 748 | 'locked' => true, |
||
| 749 | 'hidden' => false |
||
| 750 | ); |
||
| 751 | // set files attributes |
||
| 752 | View Code Duplication | if (!empty($this->options['attributes']) && is_array($this->options['attributes'])) { |
|
| 753 | |||
| 754 | foreach ($this->options['attributes'] as $a) { |
||
| 755 | // attributes must contain pattern and at least one rule |
||
| 756 | if (!empty($a['pattern']) || count($a) > 1) { |
||
| 757 | $this->attributes[] = $a; |
||
| 758 | } |
||
| 759 | } |
||
| 760 | } |
||
| 761 | |||
| 762 | if (!empty($this->options['accessControl']) && is_callable($this->options['accessControl'])) { |
||
| 763 | $this->access = $this->options['accessControl']; |
||
| 764 | } |
||
| 765 | |||
| 766 | $this->today = mktime(0,0,0, date('m'), date('d'), date('Y')); |
||
| 767 | $this->yesterday = $this->today-86400; |
||
| 768 | |||
| 769 | // debug($this->attributes); |
||
| 770 | if (!$this->init()) { |
||
| 771 | return false; |
||
| 772 | } |
||
| 773 | |||
| 774 | // check some options is arrays |
||
| 775 | $this->uploadAllow = isset($this->options['uploadAllow']) && is_array($this->options['uploadAllow']) |
||
| 776 | ? $this->options['uploadAllow'] |
||
| 777 | : array(); |
||
| 778 | |||
| 779 | $this->uploadDeny = isset($this->options['uploadDeny']) && is_array($this->options['uploadDeny']) |
||
| 780 | ? $this->options['uploadDeny'] |
||
| 781 | : array(); |
||
| 782 | |||
| 783 | if (is_string($this->options['uploadOrder'])) { // telephat_mode on, compatibility with 1.x |
||
| 784 | $parts = explode(',', isset($this->options['uploadOrder']) ? $this->options['uploadOrder'] : 'deny,allow'); |
||
| 785 | $this->uploadOrder = array(trim($parts[0]), trim($parts[1])); |
||
| 786 | } else { // telephat_mode off |
||
| 787 | $this->uploadOrder = $this->options['uploadOrder']; |
||
| 788 | } |
||
| 789 | |||
| 790 | if (!empty($this->options['uploadMaxSize'])) { |
||
| 791 | $size = ''.$this->options['uploadMaxSize']; |
||
| 792 | $unit = strtolower(substr($size, strlen($size) - 1)); |
||
| 793 | $n = 1; |
||
| 794 | switch ($unit) { |
||
| 795 | case 'k': |
||
| 796 | $n = 1024; |
||
| 797 | break; |
||
| 798 | case 'm': |
||
| 799 | $n = 1048576; |
||
| 800 | break; |
||
| 801 | case 'g': |
||
| 802 | $n = 1073741824; |
||
| 803 | } |
||
| 804 | $this->uploadMaxSize = intval($size)*$n; |
||
| 805 | } |
||
| 806 | // Set maximum to PHP_INT_MAX |
||
| 807 | if (!defined('PHP_INT_MAX')) { |
||
| 808 | define('PHP_INT_MAX', 2147483647); |
||
| 809 | } |
||
| 810 | if ($this->uploadMaxSize < 1 || $this->uploadMaxSize > PHP_INT_MAX) { |
||
| 811 | $this->uploadMaxSize = PHP_INT_MAX; |
||
| 812 | } |
||
| 813 | |||
| 814 | $this->disabled = isset($this->options['disabled']) && is_array($this->options['disabled']) |
||
| 815 | ? $this->options['disabled'] |
||
| 816 | : array(); |
||
| 817 | |||
| 818 | $this->cryptLib = $this->options['cryptLib']; |
||
| 819 | $this->mimeDetect = $this->options['mimeDetect']; |
||
| 820 | |||
| 821 | // find available mimetype detect method |
||
| 822 | $type = strtolower($this->options['mimeDetect']); |
||
| 823 | $type = preg_match('/^(finfo|mime_content_type|internal|auto)$/i', $type) ? $type : 'auto'; |
||
| 824 | $regexp = '/text\/x\-(php|c\+\+)/'; |
||
| 825 | |||
| 826 | if (($type == 'finfo' || $type == 'auto') |
||
| 827 | && class_exists('finfo', false)) { |
||
| 828 | $tmpFileInfo = @explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__)); |
||
| 829 | } else { |
||
| 830 | $tmpFileInfo = false; |
||
| 831 | } |
||
| 832 | |||
| 833 | if ($tmpFileInfo && preg_match($regexp, array_shift($tmpFileInfo))) { |
||
| 834 | $type = 'finfo'; |
||
| 835 | $this->finfo = finfo_open(FILEINFO_MIME); |
||
| 836 | } elseif (($type == 'mime_content_type' || $type == 'auto') |
||
| 837 | && function_exists('mime_content_type') |
||
| 838 | && preg_match($regexp, array_shift(explode(';', mime_content_type(__FILE__))))) { |
||
| 839 | $type = 'mime_content_type'; |
||
| 840 | } else { |
||
| 841 | $type = 'internal'; |
||
| 842 | } |
||
| 843 | $this->mimeDetect = $type; |
||
| 844 | |||
| 845 | // load mimes from external file for mimeDetect == 'internal' |
||
| 846 | // based on Alexey Sukhotin idea and patch: http://elrte.org/redmine/issues/163 |
||
| 847 | // file must be in file directory or in parent one |
||
| 848 | if ($this->mimeDetect == 'internal' && !self::$mimetypesLoaded) { |
||
| 849 | self::$mimetypesLoaded = true; |
||
| 850 | $this->mimeDetect = 'internal'; |
||
| 851 | $file = false; |
||
| 852 | if (!empty($this->options['mimefile']) && file_exists($this->options['mimefile'])) { |
||
| 853 | $file = $this->options['mimefile']; |
||
| 854 | } elseif (file_exists(dirname(__FILE__).DIRECTORY_SEPARATOR.'mime.types')) { |
||
| 855 | $file = dirname(__FILE__).DIRECTORY_SEPARATOR.'mime.types'; |
||
| 856 | } elseif (file_exists(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'mime.types')) { |
||
| 857 | $file = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'mime.types'; |
||
| 858 | } |
||
| 859 | |||
| 860 | View Code Duplication | if ($file && file_exists($file)) { |
|
| 861 | $mimecf = file($file); |
||
| 862 | |||
| 863 | foreach ($mimecf as $line_num => $line) { |
||
| 864 | if (!preg_match('/^\s*#/', $line)) { |
||
| 865 | $mime = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY); |
||
| 866 | for ($i = 1, $size = count($mime); $i < $size ; $i++) { |
||
| 867 | if (!isset(self::$mimetypes[$mime[$i]])) { |
||
| 868 | self::$mimetypes[$mime[$i]] = $mime[0]; |
||
| 869 | } |
||
| 870 | } |
||
| 871 | } |
||
| 872 | } |
||
| 873 | } |
||
| 874 | } |
||
| 875 | |||
| 876 | $this->rootName = empty($this->options['alias']) ? $this->basenameCE($this->root) : $this->options['alias']; |
||
| 877 | |||
| 878 | // This get's triggered if $this->root == '/' and alias is empty. |
||
| 879 | // Maybe modify _basename instead? |
||
| 880 | if ($this->rootName === '') $this->rootName = $this->separator; |
||
| 881 | |||
| 882 | $root = $this->stat($this->root); |
||
| 883 | |||
| 884 | if (!$root) { |
||
| 885 | return $this->setError('Root folder does not exists.'); |
||
| 886 | } |
||
| 887 | if (!$root['read'] && !$root['write']) { |
||
| 888 | return $this->setError('Root folder has not read and write permissions.'); |
||
| 889 | } |
||
| 890 | |||
| 891 | // debug($root); |
||
| 892 | |||
| 893 | if ($root['read']) { |
||
| 894 | // check startPath - path to open by default instead of root |
||
| 895 | if ($this->options['startPath']) { |
||
| 896 | $start = $this->stat($this->options['startPath']); |
||
| 897 | if (!empty($start) |
||
| 898 | && $start['mime'] == 'directory' |
||
| 899 | && $start['read'] |
||
| 900 | && empty($start['hidden']) |
||
| 901 | && $this->inpathCE($this->options['startPath'], $this->root)) { |
||
| 902 | $this->startPath = $this->options['startPath']; |
||
| 903 | if (substr($this->startPath, -1, 1) == $this->options['separator']) { |
||
| 904 | $this->startPath = substr($this->startPath, 0, -1); |
||
| 905 | } |
||
| 906 | } |
||
| 907 | } |
||
| 908 | } else { |
||
| 909 | $this->options['URL'] = ''; |
||
| 910 | $this->options['tmbURL'] = ''; |
||
| 911 | $this->options['tmbPath'] = ''; |
||
| 912 | // read only volume |
||
| 913 | array_unshift($this->attributes, array( |
||
| 914 | 'pattern' => '/.*/', |
||
| 915 | 'read' => false |
||
| 916 | )); |
||
| 917 | } |
||
| 918 | $this->treeDeep = $this->options['treeDeep'] > 0 ? (int)$this->options['treeDeep'] : 1; |
||
| 919 | $this->tmbSize = $this->options['tmbSize'] > 0 ? (int)$this->options['tmbSize'] : 48; |
||
| 920 | $this->URL = $this->options['URL']; |
||
| 921 | if ($this->URL && preg_match("|[^/?&=]$|", $this->URL)) { |
||
| 922 | $this->URL .= '/'; |
||
| 923 | } |
||
| 924 | |||
| 925 | $this->tmbURL = !empty($this->options['tmbURL']) ? $this->options['tmbURL'] : ''; |
||
| 926 | if ($this->tmbURL && preg_match("|[^/?&=]$|", $this->tmbURL)) { |
||
| 927 | $this->tmbURL .= '/'; |
||
| 928 | } |
||
| 929 | |||
| 930 | $this->nameValidator = !empty($this->options['acceptedName']) && (is_string($this->options['acceptedName']) || is_callable($this->options['acceptedName'])) |
||
| 931 | ? $this->options['acceptedName'] |
||
| 932 | : ''; |
||
| 933 | |||
| 934 | $this->_checkArchivers(); |
||
| 935 | // manual control archive types to create |
||
| 936 | View Code Duplication | if (!empty($this->options['archiveMimes']) && is_array($this->options['archiveMimes'])) { |
|
| 937 | foreach ($this->archivers['create'] as $mime => $v) { |
||
| 938 | if (!in_array($mime, $this->options['archiveMimes'])) { |
||
| 939 | unset($this->archivers['create'][$mime]); |
||
| 940 | } |
||
| 941 | } |
||
| 942 | } |
||
| 943 | |||
| 944 | // manualy add archivers |
||
| 945 | View Code Duplication | if (!empty($this->options['archivers']['create']) && is_array($this->options['archivers']['create'])) { |
|
| 946 | foreach ($this->options['archivers']['create'] as $mime => $conf) { |
||
| 947 | if (strpos($mime, 'application/') === 0 |
||
| 948 | && !empty($conf['cmd']) |
||
| 949 | && isset($conf['argc']) |
||
| 950 | && !empty($conf['ext']) |
||
| 951 | && !isset($this->archivers['create'][$mime])) { |
||
| 952 | $this->archivers['create'][$mime] = $conf; |
||
| 953 | } |
||
| 954 | } |
||
| 955 | } |
||
| 956 | |||
| 957 | View Code Duplication | if (!empty($this->options['archivers']['extract']) && is_array($this->options['archivers']['extract'])) { |
|
| 958 | foreach ($this->options['archivers']['extract'] as $mime => $conf) { |
||
| 959 | if (strpos($mime, 'application/') === 0 |
||
| 960 | && !empty($conf['cmd']) |
||
| 961 | && isset($conf['argc']) |
||
| 962 | && !empty($conf['ext']) |
||
| 963 | && !isset($this->archivers['extract'][$mime])) { |
||
| 964 | $this->archivers['extract'][$mime] = $conf; |
||
| 965 | } |
||
| 966 | } |
||
| 967 | } |
||
| 968 | |||
| 969 | $this->configure(); |
||
| 970 | // echo $this->uploadMaxSize; |
||
| 971 | // echo $this->options['uploadMaxSize']; |
||
| 972 | return $this->mounted = true; |
||
| 973 | } |
||
| 974 | |||
| 975 | /** |
||
| 976 | * Some "unmount" stuffs - may be required by virtual fs |
||
| 977 | * |
||
| 978 | * @return void |
||
| 979 | * @author Dmitry (dio) Levashov |
||
| 980 | **/ |
||
| 981 | public function umount() { |
||
| 983 | |||
| 984 | /** |
||
| 985 | * Return error message from last failed action |
||
| 986 | * |
||
| 987 | * @return array |
||
| 988 | * @author Dmitry (dio) Levashov |
||
| 989 | **/ |
||
| 990 | public function error() { |
||
| 993 | |||
| 994 | /** |
||
| 995 | * Return is uploadable that given file name |
||
| 996 | * |
||
| 997 | * @param string $name file name |
||
| 998 | * @param bool $allowUnknown |
||
| 999 | * @return bool |
||
| 1000 | * @author Naoki Sawada |
||
| 1001 | **/ |
||
| 1002 | public function isUploadableByName($name, $allowUnknown = true) { |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
| 1009 | * |
||
| 1010 | * @return array |
||
| 1011 | * @author Naoki Sawada |
||
| 1012 | */ |
||
| 1013 | public function getMimeTable() { |
||
| 1016 | |||
| 1017 | /** |
||
| 1018 | * Set mimetypes allowed to display to client |
||
| 1019 | * |
||
| 1020 | * @param array $mimes |
||
| 1021 | * @return void |
||
| 1022 | * @author Dmitry (dio) Levashov |
||
| 1023 | **/ |
||
| 1024 | public function setMimesFilter($mimes) { |
||
| 1029 | |||
| 1030 | /** |
||
| 1031 | * Return root folder hash |
||
| 1032 | * |
||
| 1033 | * @return string |
||
| 1034 | * @author Dmitry (dio) Levashov |
||
| 1035 | **/ |
||
| 1036 | public function root() { |
||
| 1039 | |||
| 1040 | /** |
||
| 1041 | * Return target path hash |
||
| 1042 | * |
||
| 1043 | * @param string $path |
||
| 1044 | * @param string $name |
||
| 1045 | * @author Naoki Sawada |
||
| 1046 | */ |
||
| 1047 | public function getHash($path, $name = '') { |
||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * Return root or startPath hash |
||
| 1056 | * |
||
| 1057 | * @return string |
||
| 1058 | * @author Dmitry (dio) Levashov |
||
| 1059 | **/ |
||
| 1060 | public function defaultPath() { |
||
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Return volume options required by client: |
||
| 1066 | * |
||
| 1067 | * @return array |
||
| 1068 | * @author Dmitry (dio) Levashov |
||
| 1069 | **/ |
||
| 1070 | public function options($hash) { |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Get option value of this volume |
||
| 1099 | * |
||
| 1100 | * @param string $name target option name |
||
| 1101 | * @return NULL|mixed target option value |
||
| 1102 | * @author Naoki Sawada |
||
| 1103 | */ |
||
| 1104 | public function getOption($name) { |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Get plugin values of this options |
||
| 1110 | * |
||
| 1111 | * @param string $name Plugin name |
||
| 1112 | * @return NULL|array Plugin values |
||
| 1113 | * @author Naoki Sawada |
||
| 1114 | */ |
||
| 1115 | public function getOptionsPlugin($name = '') { |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Return true if command disabled in options |
||
| 1125 | * |
||
| 1126 | * @param string $cmd command name |
||
| 1127 | * @return bool |
||
| 1128 | * @author Dmitry (dio) Levashov |
||
| 1129 | **/ |
||
| 1130 | public function commandDisabled($cmd) { |
||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Return true if mime is required mimes list |
||
| 1136 | * |
||
| 1137 | * @param string $mime mime type to check |
||
| 1138 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
| 1139 | * @param bool|null $empty what to return on empty list |
||
| 1140 | * @return bool|null |
||
| 1141 | * @author Dmitry (dio) Levashov |
||
| 1142 | * @author Troex Nevelin |
||
| 1143 | **/ |
||
| 1144 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Return true if voume is readable. |
||
| 1158 | * |
||
| 1159 | * @return bool |
||
| 1160 | * @author Dmitry (dio) Levashov |
||
| 1161 | **/ |
||
| 1162 | public function isReadable() { |
||
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Return true if copy from this volume allowed |
||
| 1169 | * |
||
| 1170 | * @return bool |
||
| 1171 | * @author Dmitry (dio) Levashov |
||
| 1172 | **/ |
||
| 1173 | public function copyFromAllowed() { |
||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Return file path related to root with convert encoging |
||
| 1179 | * |
||
| 1180 | * @param string $hash file hash |
||
| 1181 | * @return string |
||
| 1182 | * @author Dmitry (dio) Levashov |
||
| 1183 | **/ |
||
| 1184 | public function path($hash) { |
||
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Return file real path if file exists |
||
| 1190 | * |
||
| 1191 | * @param string $hash file hash |
||
| 1192 | * @return string |
||
| 1193 | * @author Dmitry (dio) Levashov |
||
| 1194 | **/ |
||
| 1195 | public function realpath($hash) { |
||
| 1199 | |||
| 1200 | /** |
||
| 1201 | * Return list of moved/overwrited files |
||
| 1202 | * |
||
| 1203 | * @return array |
||
| 1204 | * @author Dmitry (dio) Levashov |
||
| 1205 | **/ |
||
| 1206 | public function removed() { |
||
| 1209 | |||
| 1210 | /** |
||
| 1211 | * Clean removed files list |
||
| 1212 | * |
||
| 1213 | * @return void |
||
| 1214 | * @author Dmitry (dio) Levashov |
||
| 1215 | **/ |
||
| 1216 | public function resetRemoved() { |
||
| 1219 | |||
| 1220 | /** |
||
| 1221 | * Return file/dir hash or first founded child hash with required attr == $val |
||
| 1222 | * |
||
| 1223 | * @param string $hash file hash |
||
| 1224 | * @param string $attr attribute name |
||
| 1225 | * @param bool $val attribute value |
||
| 1226 | * @return string|false |
||
| 1227 | * @author Dmitry (dio) Levashov |
||
| 1228 | **/ |
||
| 1229 | public function closest($hash, $attr, $val) { |
||
| 1232 | |||
| 1233 | /** |
||
| 1234 | * Return file info or false on error |
||
| 1235 | * |
||
| 1236 | * @param string $hash file hash |
||
| 1237 | * @param bool $realpath add realpath field to file info |
||
| 1238 | * @return array|false |
||
| 1239 | * @author Dmitry (dio) Levashov |
||
| 1240 | **/ |
||
| 1241 | public function file($hash) { |
||
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Return folder info |
||
| 1256 | * |
||
| 1257 | * @param string $hash folder hash |
||
| 1258 | * @param bool $hidden return hidden file info |
||
| 1259 | * @return array|false |
||
| 1260 | * @author Dmitry (dio) Levashov |
||
| 1261 | **/ |
||
| 1262 | public function dir($hash, $resolveLink=false) { |
||
| 1275 | |||
| 1276 | /** |
||
| 1277 | * Return directory content or false on error |
||
| 1278 | * |
||
| 1279 | * @param string $hash file hash |
||
| 1280 | * @return array|false |
||
| 1281 | * @author Dmitry (dio) Levashov |
||
| 1282 | **/ |
||
| 1283 | public function scandir($hash) { |
||
| 1292 | |||
| 1293 | /** |
||
| 1294 | * Return dir files names list |
||
| 1295 | * |
||
| 1296 | * @param string $hash file hash |
||
| 1297 | * @return array |
||
| 1298 | * @author Dmitry (dio) Levashov |
||
| 1299 | **/ |
||
| 1300 | public function ls($hash) { |
||
| 1316 | |||
| 1317 | /** |
||
| 1318 | * Return subfolders for required folder or false on error |
||
| 1319 | * |
||
| 1320 | * @param string $hash folder hash or empty string to get tree from root folder |
||
| 1321 | * @param int $deep subdir deep |
||
| 1322 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
| 1323 | * @return array|false |
||
| 1324 | * @author Dmitry (dio) Levashov |
||
| 1325 | **/ |
||
| 1326 | public function tree($hash='', $deep=0, $exclude='') { |
||
| 1337 | |||
| 1338 | /** |
||
| 1339 | * Return part of dirs tree from required dir up to root dir |
||
| 1340 | * |
||
| 1341 | * @param string $hash directory hash |
||
| 1342 | * @param bool|null $lineal only lineal parents |
||
| 1343 | * @return array |
||
| 1344 | * @author Dmitry (dio) Levashov |
||
| 1345 | **/ |
||
| 1346 | public function parents($hash, $lineal = false) { |
||
| 1373 | |||
| 1374 | /** |
||
| 1375 | * Create thumbnail for required file and return its name of false on failed |
||
| 1376 | * |
||
| 1377 | * @return string|false |
||
| 1378 | * @author Dmitry (dio) Levashov |
||
| 1379 | **/ |
||
| 1380 | public function tmb($hash) { |
||
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Return file size / total directory size |
||
| 1392 | * |
||
| 1393 | * @param string file hash |
||
| 1394 | * @return int |
||
| 1395 | * @author Dmitry (dio) Levashov |
||
| 1396 | **/ |
||
| 1397 | public function size($hash) { |
||
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Open file for reading and return file pointer |
||
| 1403 | * |
||
| 1404 | * @param string file hash |
||
| 1405 | * @return Resource |
||
| 1406 | * @author Dmitry (dio) Levashov |
||
| 1407 | **/ |
||
| 1408 | public function open($hash) { |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * Close file pointer |
||
| 1419 | * |
||
| 1420 | * @param Resource $fp file pointer |
||
| 1421 | * @param string $hash file hash |
||
| 1422 | * @return void |
||
| 1423 | * @author Dmitry (dio) Levashov |
||
| 1424 | **/ |
||
| 1425 | public function close($fp, $hash) { |
||
| 1428 | |||
| 1429 | /** |
||
| 1430 | * Create directory and return dir info |
||
| 1431 | * |
||
| 1432 | * @param string $dsthash destination directory hash |
||
| 1433 | * @param string $name directory name |
||
| 1434 | * @return array|false |
||
| 1435 | * @author Dmitry (dio) Levashov |
||
| 1436 | **/ |
||
| 1437 | public function mkdir($dsthash, $name) { |
||
| 1464 | |||
| 1465 | /** |
||
| 1466 | * Create empty file and return its info |
||
| 1467 | * |
||
| 1468 | * @param string $dst destination directory |
||
| 1469 | * @param string $name file name |
||
| 1470 | * @return array|false |
||
| 1471 | * @author Dmitry (dio) Levashov |
||
| 1472 | **/ |
||
| 1473 | public function mkfile($dst, $name) { |
||
| 1499 | |||
| 1500 | /** |
||
| 1501 | * Rename file and return file info |
||
| 1502 | * |
||
| 1503 | * @param string $hash file hash |
||
| 1504 | * @param string $name new file name |
||
| 1505 | * @return array|false |
||
| 1506 | * @author Dmitry (dio) Levashov |
||
| 1507 | **/ |
||
| 1508 | public function rename($hash, $name) { |
||
| 1554 | |||
| 1555 | /** |
||
| 1556 | * Create file copy with suffix "copy number" and return its info |
||
| 1557 | * |
||
| 1558 | * @param string $hash file hash |
||
| 1559 | * @param string $suffix suffix to add to file name |
||
| 1560 | * @return array|false |
||
| 1561 | * @author Dmitry (dio) Levashov |
||
| 1562 | **/ |
||
| 1563 | public function duplicate($hash, $suffix='copy') { |
||
| 1584 | |||
| 1585 | /** |
||
| 1586 | * Save uploaded file. |
||
| 1587 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
| 1588 | * |
||
| 1589 | * @param Resource $fp file pointer |
||
| 1590 | * @param string $dst destination folder hash |
||
| 1591 | * @param string $src file name |
||
| 1592 | * @param string $tmpname file tmp name - required to detect mime type |
||
| 1593 | * @return array|false |
||
| 1594 | * @author Dmitry (dio) Levashov |
||
| 1595 | **/ |
||
| 1596 | public function upload($fp, $dst, $name, $tmpname) { |
||
| 1672 | |||
| 1673 | /** |
||
| 1674 | * Paste files |
||
| 1675 | * |
||
| 1676 | * @param Object $volume source volume |
||
| 1677 | * @param string $source file hash |
||
| 1678 | * @param string $dst destination dir hash |
||
| 1679 | * @param bool $rmSrc remove source after copy? |
||
| 1680 | * @return array|false |
||
| 1681 | * @author Dmitry (dio) Levashov |
||
| 1682 | **/ |
||
| 1683 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
| 1771 | |||
| 1772 | /** |
||
| 1773 | * Return file contents |
||
| 1774 | * |
||
| 1775 | * @param string $hash file hash |
||
| 1776 | * @return string|false |
||
| 1777 | * @author Dmitry (dio) Levashov |
||
| 1778 | **/ |
||
| 1779 | public function getContents($hash) { |
||
| 1796 | |||
| 1797 | /** |
||
| 1798 | * Put content in text file and return file info. |
||
| 1799 | * |
||
| 1800 | * @param string $hash file hash |
||
| 1801 | * @param string $content new file content |
||
| 1802 | * @return array |
||
| 1803 | * @author Dmitry (dio) Levashov |
||
| 1804 | **/ |
||
| 1805 | public function putContents($hash, $content) { |
||
| 1840 | |||
| 1841 | /** |
||
| 1842 | * Extract files from archive |
||
| 1843 | * |
||
| 1844 | * @param string $hash archive hash |
||
| 1845 | * @return array|bool |
||
| 1846 | * @author Dmitry (dio) Levashov, |
||
| 1847 | * @author Alexey Sukhotin |
||
| 1848 | **/ |
||
| 1849 | public function extract($hash, $makedir = null) { |
||
| 1888 | |||
| 1889 | /** |
||
| 1890 | * Add files to archive |
||
| 1891 | * |
||
| 1892 | * @return void |
||
| 1893 | **/ |
||
| 1894 | public function archive($hashes, $mime, $name = '') { |
||
| 1938 | |||
| 1939 | /** |
||
| 1940 | * Resize image |
||
| 1941 | * |
||
| 1942 | * @param string $hash image file |
||
| 1943 | * @param int $width new width |
||
| 1944 | * @param int $height new height |
||
| 1945 | * @param int $x X start poistion for crop |
||
| 1946 | * @param int $y Y start poistion for crop |
||
| 1947 | * @param string $mode action how to mainpulate image |
||
| 1948 | * @return array|false |
||
| 1949 | * @author Dmitry (dio) Levashov |
||
| 1950 | * @author Alexey Sukhotin |
||
| 1951 | * @author nao-pon |
||
| 1952 | * @author Troex Nevelin |
||
| 1953 | **/ |
||
| 1954 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0) { |
||
| 2041 | |||
| 2042 | /** |
||
| 2043 | * Remove file/dir |
||
| 2044 | * |
||
| 2045 | * @param string $hash file hash |
||
| 2046 | * @return bool |
||
| 2047 | * @author Dmitry (dio) Levashov |
||
| 2048 | **/ |
||
| 2049 | public function rm($hash) { |
||
| 2054 | |||
| 2055 | /** |
||
| 2056 | * Search files |
||
| 2057 | * |
||
| 2058 | * @param string $q search string |
||
| 2059 | * @param array $mimes |
||
| 2060 | * @return array |
||
| 2061 | * @author Dmitry (dio) Levashov |
||
| 2062 | **/ |
||
| 2063 | public function search($q, $mimes, $hash = null) { |
||
| 2082 | |||
| 2083 | /** |
||
| 2084 | * Return image dimensions |
||
| 2085 | * |
||
| 2086 | * @param string $hash file hash |
||
| 2087 | * @return array |
||
| 2088 | * @author Dmitry (dio) Levashov |
||
| 2089 | **/ |
||
| 2090 | public function dimensions($hash) { |
||
| 2097 | |||
| 2098 | /** |
||
| 2099 | * Return content URL (for netmout volume driver) |
||
| 2100 | * If file.url == 1 requests from JavaScript client with XHR |
||
| 2101 | * |
||
| 2102 | * @param string $hash file hash |
||
| 2103 | * @param array $options options array |
||
| 2104 | * @return boolean|string |
||
| 2105 | * @author Naoki Sawada |
||
| 2106 | */ |
||
| 2107 | public function getContentUrl($hash, $options = array()) { |
||
| 2113 | |||
| 2114 | /** |
||
| 2115 | * Return temp path |
||
| 2116 | * |
||
| 2117 | * @return string |
||
| 2118 | * @author Naoki Sawada |
||
| 2119 | */ |
||
| 2120 | public function getTempPath() { |
||
| 2133 | |||
| 2134 | /** |
||
| 2135 | * (Make &) Get upload taget dirctory hash |
||
| 2136 | * |
||
| 2137 | * @param string $baseTargetHash |
||
| 2138 | * @param string $path |
||
| 2139 | * @param array $result |
||
| 2140 | * @return boolean|string |
||
| 2141 | * @author Naoki Sawada |
||
| 2142 | */ |
||
| 2143 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
| 2170 | |||
| 2171 | /** |
||
| 2172 | * Return this uploadMaxSize value |
||
| 2173 | * |
||
| 2174 | * @return integer |
||
| 2175 | * @author Naoki Sawada |
||
| 2176 | */ |
||
| 2177 | public function getUploadMaxSize() { |
||
| 2180 | |||
| 2181 | /** |
||
| 2182 | * Save error message |
||
| 2183 | * |
||
| 2184 | * @param array error |
||
| 2185 | * @return false |
||
| 2186 | * @author Dmitry(dio) Levashov |
||
| 2187 | **/ |
||
| 2188 | protected function setError($error) { |
||
| 2203 | |||
| 2204 | /*********************************************************************/ |
||
| 2205 | /* FS API */ |
||
| 2206 | /*********************************************************************/ |
||
| 2207 | |||
| 2208 | /***************** server encoding support *******************/ |
||
| 2209 | |||
| 2210 | /** |
||
| 2211 | * Return parent directory path (with convert encording) |
||
| 2212 | * |
||
| 2213 | * @param string $path file path |
||
| 2214 | * @return string |
||
| 2215 | * @author Naoki Sawada |
||
| 2216 | **/ |
||
| 2217 | protected function dirnameCE($path) { |
||
| 2220 | |||
| 2221 | /** |
||
| 2222 | * Return file name (with convert encording) |
||
| 2223 | * |
||
| 2224 | * @param string $path file path |
||
| 2225 | * @return string |
||
| 2226 | * @author Naoki Sawada |
||
| 2227 | **/ |
||
| 2228 | protected function basenameCE($path) { |
||
| 2231 | |||
| 2232 | /** |
||
| 2233 | * Join dir name and file name and return full path. (with convert encording) |
||
| 2234 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 2235 | * |
||
| 2236 | * @param string $dir dir path |
||
| 2237 | * @param string $name file name |
||
| 2238 | * @return string |
||
| 2239 | * @author Naoki Sawada |
||
| 2240 | **/ |
||
| 2241 | protected function joinPathCE($dir, $name) { |
||
| 2244 | |||
| 2245 | /** |
||
| 2246 | * Return normalized path (with convert encording) |
||
| 2247 | * |
||
| 2248 | * @param string $path file path |
||
| 2249 | * @return string |
||
| 2250 | * @author Naoki Sawada |
||
| 2251 | **/ |
||
| 2252 | protected function normpathCE($path) { |
||
| 2255 | |||
| 2256 | /** |
||
| 2257 | * Return file path related to root dir (with convert encording) |
||
| 2258 | * |
||
| 2259 | * @param string $path file path |
||
| 2260 | * @return string |
||
| 2261 | * @author Naoki Sawada |
||
| 2262 | **/ |
||
| 2263 | protected function relpathCE($path) { |
||
| 2266 | |||
| 2267 | /** |
||
| 2268 | * Convert path related to root dir into real path (with convert encording) |
||
| 2269 | * |
||
| 2270 | * @param string $path rel file path |
||
| 2271 | * @return string |
||
| 2272 | * @author Naoki Sawada |
||
| 2273 | **/ |
||
| 2274 | protected function abspathCE($path) { |
||
| 2277 | |||
| 2278 | /** |
||
| 2279 | * Return true if $path is children of $parent (with convert encording) |
||
| 2280 | * |
||
| 2281 | * @param string $path path to check |
||
| 2282 | * @param string $parent parent path |
||
| 2283 | * @return bool |
||
| 2284 | * @author Naoki Sawada |
||
| 2285 | **/ |
||
| 2286 | protected function inpathCE($path, $parent) { |
||
| 2289 | |||
| 2290 | /** |
||
| 2291 | * Open file and return file pointer (with convert encording) |
||
| 2292 | * |
||
| 2293 | * @param string $path file path |
||
| 2294 | * @param bool $write open file for writing |
||
| 2295 | * @return resource|false |
||
| 2296 | * @author Naoki Sawada |
||
| 2297 | **/ |
||
| 2298 | protected function fopenCE($path, $mode='rb') { |
||
| 2301 | |||
| 2302 | /** |
||
| 2303 | * Close opened file (with convert encording) |
||
| 2304 | * |
||
| 2305 | * @param resource $fp file pointer |
||
| 2306 | * @param string $path file path |
||
| 2307 | * @return bool |
||
| 2308 | * @author Naoki Sawada |
||
| 2309 | **/ |
||
| 2310 | protected function fcloseCE($fp, $path='') { |
||
| 2313 | |||
| 2314 | /** |
||
| 2315 | * Create new file and write into it from file pointer. (with convert encording) |
||
| 2316 | * Return new file path or false on error. |
||
| 2317 | * |
||
| 2318 | * @param resource $fp file pointer |
||
| 2319 | * @param string $dir target dir path |
||
| 2320 | * @param string $name file name |
||
| 2321 | * @param array $stat file stat (required by some virtual fs) |
||
| 2322 | * @return bool|string |
||
| 2323 | * @author Naoki Sawada |
||
| 2324 | **/ |
||
| 2325 | protected function saveCE($fp, $dir, $name, $stat) { |
||
| 2328 | |||
| 2329 | /** |
||
| 2330 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
| 2331 | * |
||
| 2332 | * @param string $path dir path |
||
| 2333 | * @return bool |
||
| 2334 | * @author Naoki Sawada |
||
| 2335 | **/ |
||
| 2336 | protected function subdirsCE($path) { |
||
| 2342 | |||
| 2343 | /** |
||
| 2344 | * Return files list in directory (with convert encording) |
||
| 2345 | * |
||
| 2346 | * @param string $path dir path |
||
| 2347 | * @return array |
||
| 2348 | * @author Naoki Sawada |
||
| 2349 | **/ |
||
| 2350 | protected function scandirCE($path) { |
||
| 2353 | |||
| 2354 | /** |
||
| 2355 | * Create symlink (with convert encording) |
||
| 2356 | * |
||
| 2357 | * @param string $source file to link to |
||
| 2358 | * @param string $targetDir folder to create link in |
||
| 2359 | * @param string $name symlink name |
||
| 2360 | * @return bool |
||
| 2361 | * @author Naoki Sawada |
||
| 2362 | **/ |
||
| 2363 | protected function symlinkCE($source, $targetDir, $name) { |
||
| 2366 | |||
| 2367 | /***************** paths *******************/ |
||
| 2368 | |||
| 2369 | /** |
||
| 2370 | * Encode path into hash |
||
| 2371 | * |
||
| 2372 | * @param string file path |
||
| 2373 | * @return string |
||
| 2374 | * @author Dmitry (dio) Levashov |
||
| 2375 | * @author Troex Nevelin |
||
| 2376 | **/ |
||
| 2377 | protected function encode($path) { |
||
| 2398 | |||
| 2399 | /** |
||
| 2400 | * Decode path from hash |
||
| 2401 | * |
||
| 2402 | * @param string file hash |
||
| 2403 | * @return string |
||
| 2404 | * @author Dmitry (dio) Levashov |
||
| 2405 | * @author Troex Nevelin |
||
| 2406 | **/ |
||
| 2407 | protected function decode($hash) { |
||
| 2419 | |||
| 2420 | /** |
||
| 2421 | * Return crypted path |
||
| 2422 | * Not implemented |
||
| 2423 | * |
||
| 2424 | * @param string path |
||
| 2425 | * @return mixed |
||
| 2426 | * @author Dmitry (dio) Levashov |
||
| 2427 | **/ |
||
| 2428 | protected function crypt($path) { |
||
| 2431 | |||
| 2432 | /** |
||
| 2433 | * Return uncrypted path |
||
| 2434 | * Not implemented |
||
| 2435 | * |
||
| 2436 | * @param mixed hash |
||
| 2437 | * @return mixed |
||
| 2438 | * @author Dmitry (dio) Levashov |
||
| 2439 | **/ |
||
| 2440 | protected function uncrypt($hash) { |
||
| 2443 | |||
| 2444 | /** |
||
| 2445 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
| 2446 | * |
||
| 2447 | * @param string $name file name |
||
| 2448 | * @return bool |
||
| 2449 | * @author Dmitry (dio) Levashov |
||
| 2450 | **/ |
||
| 2451 | protected function nameAccepted($name) { |
||
| 2466 | |||
| 2467 | /** |
||
| 2468 | * Return new unique name based on file name and suffix |
||
| 2469 | * |
||
| 2470 | * @param string $path file path |
||
| 2471 | * @param string $suffix suffix append to name |
||
| 2472 | * @return string |
||
| 2473 | * @author Dmitry (dio) Levashov |
||
| 2474 | **/ |
||
| 2475 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum = true, $start = 1) { |
||
| 2503 | |||
| 2504 | /** |
||
| 2505 | * Converts character encoding from UTF-8 to server's one |
||
| 2506 | * |
||
| 2507 | * @param mixed $var target string or array var |
||
| 2508 | * @param bool $restoreLocale do retore global locale, default is false |
||
| 2509 | * @param string $unknown replaces character for unknown |
||
| 2510 | * @return mixed |
||
| 2511 | * @author Naoki Sawada |
||
| 2512 | */ |
||
| 2513 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
| 2516 | |||
| 2517 | /** |
||
| 2518 | * Converts character encoding from server's one to UTF-8 |
||
| 2519 | * |
||
| 2520 | * @param mixed $var target string or array var |
||
| 2521 | * @param bool $restoreLocale do retore global locale, default is true |
||
| 2522 | * @param string $unknown replaces character for unknown |
||
| 2523 | * @return mixed |
||
| 2524 | * @author Naoki Sawada |
||
| 2525 | */ |
||
| 2526 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
| 2529 | |||
| 2530 | /** |
||
| 2531 | * Converts character encoding (base function) |
||
| 2532 | * |
||
| 2533 | * @param mixed $var target string or array var |
||
| 2534 | * @param string $from from character encoding |
||
| 2535 | * @param string $to to character encoding |
||
| 2536 | * @param string $locale local locale |
||
| 2537 | * @param string $unknown replaces character for unknown |
||
| 2538 | * @return mixed |
||
| 2539 | */ |
||
| 2540 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
| 2569 | |||
| 2570 | /*********************** util mainly for inheritance class *********************/ |
||
| 2571 | |||
| 2572 | /** |
||
| 2573 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
| 2574 | * When needing the unique file to a path, give $path to parameter. |
||
| 2575 | * |
||
| 2576 | * @param string $path for get unique file to a path |
||
| 2577 | * @return string|false |
||
| 2578 | * @author Naoki Sawada |
||
| 2579 | */ |
||
| 2580 | protected function getTempFile($path = '') { |
||
| 2606 | |||
| 2607 | /** |
||
| 2608 | * File path of local server side work file path |
||
| 2609 | * |
||
| 2610 | * @param string $path path need convert encoding to server encoding |
||
| 2611 | * @return string |
||
| 2612 | * @author Naoki Sawada |
||
| 2613 | */ |
||
| 2614 | protected function getWorkFile($path) { |
||
| 2629 | |||
| 2630 | /** |
||
| 2631 | * Get image size array with `dimensions` |
||
| 2632 | * |
||
| 2633 | * @param string $path path need convert encoding to server encoding |
||
| 2634 | * @param string $mime file mime type |
||
| 2635 | * @return array|false |
||
| 2636 | */ |
||
| 2637 | public function getImageSize($path, $mime = '') { |
||
| 2649 | |||
| 2650 | /** |
||
| 2651 | * Delete dirctory trees |
||
| 2652 | * |
||
| 2653 | * @param string $localpath path need convert encoding to server encoding |
||
| 2654 | * @return boolean |
||
| 2655 | * @author Naoki Sawada |
||
| 2656 | */ |
||
| 2657 | protected function delTree($localpath) { |
||
| 2666 | |||
| 2667 | /*********************** file stat *********************/ |
||
| 2668 | |||
| 2669 | /** |
||
| 2670 | * Check file attribute |
||
| 2671 | * |
||
| 2672 | * @param string $path file path |
||
| 2673 | * @param string $name attribute name (read|write|locked|hidden) |
||
| 2674 | * @param bool $val attribute value returned by file system |
||
| 2675 | * @param bool $isDir path is directory (true: directory, false: file) |
||
| 2676 | * @return bool |
||
| 2677 | * @author Dmitry (dio) Levashov |
||
| 2678 | **/ |
||
| 2679 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
| 2713 | |||
| 2714 | /** |
||
| 2715 | * Return true if file with given name can be created in given folder. |
||
| 2716 | * |
||
| 2717 | * @param string $dir parent dir path |
||
| 2718 | * @param string $name new file name |
||
| 2719 | * @return bool |
||
| 2720 | * @author Dmitry (dio) Levashov |
||
| 2721 | **/ |
||
| 2722 | protected function allowCreate($dir, $name, $isDir = null) { |
||
| 2745 | |||
| 2746 | /** |
||
| 2747 | * Return true if file MIME type can save with check uploadOrder config. |
||
| 2748 | * |
||
| 2749 | * @param string $mime |
||
| 2750 | * @return boolean |
||
| 2751 | */ |
||
| 2752 | protected function allowPutMime($mime) { |
||
| 2770 | |||
| 2771 | /** |
||
| 2772 | * Return fileinfo |
||
| 2773 | * |
||
| 2774 | * @param string $path file cache |
||
| 2775 | * @return array |
||
| 2776 | * @author Dmitry (dio) Levashov |
||
| 2777 | **/ |
||
| 2778 | protected function stat($path) { |
||
| 2805 | |||
| 2806 | /** |
||
| 2807 | * Put file stat in cache and return it |
||
| 2808 | * |
||
| 2809 | * @param string $path file path |
||
| 2810 | * @param array $stat file stat |
||
| 2811 | * @return array |
||
| 2812 | * @author Dmitry (dio) Levashov |
||
| 2813 | **/ |
||
| 2814 | protected function updateCache($path, $stat) { |
||
| 2957 | |||
| 2958 | /** |
||
| 2959 | * Get stat for folder content and put in cache |
||
| 2960 | * |
||
| 2961 | * @param string $path |
||
| 2962 | * @return void |
||
| 2963 | * @author Dmitry (dio) Levashov |
||
| 2964 | **/ |
||
| 2965 | protected function cacheDir($path) { |
||
| 2978 | |||
| 2979 | /** |
||
| 2980 | * Clean cache |
||
| 2981 | * |
||
| 2982 | * @return void |
||
| 2983 | * @author Dmitry (dio) Levashov |
||
| 2984 | **/ |
||
| 2985 | protected function clearcache() { |
||
| 2989 | |||
| 2990 | /** |
||
| 2991 | * Return file mimetype |
||
| 2992 | * |
||
| 2993 | * @param string $path file path |
||
| 2994 | * @return string |
||
| 2995 | * @author Dmitry (dio) Levashov |
||
| 2996 | **/ |
||
| 2997 | protected function mimetype($path, $name = '') { |
||
| 3042 | |||
| 3043 | /** |
||
| 3044 | * Detect file mimetype using "internal" method |
||
| 3045 | * |
||
| 3046 | * @param string $path file path |
||
| 3047 | * @return string |
||
| 3048 | * @author Dmitry (dio) Levashov |
||
| 3049 | **/ |
||
| 3050 | static protected function mimetypeInternalDetect($path) { |
||
| 3073 | |||
| 3074 | /** |
||
| 3075 | * Return file/total directory size |
||
| 3076 | * |
||
| 3077 | * @param string $path file path |
||
| 3078 | * @return int |
||
| 3079 | * @author Dmitry (dio) Levashov |
||
| 3080 | **/ |
||
| 3081 | protected function countSize($path) { |
||
| 3106 | |||
| 3107 | /** |
||
| 3108 | * Return true if all mimes is directory or files |
||
| 3109 | * |
||
| 3110 | * @param string $mime1 mimetype |
||
| 3111 | * @param string $mime2 mimetype |
||
| 3112 | * @return bool |
||
| 3113 | * @author Dmitry (dio) Levashov |
||
| 3114 | **/ |
||
| 3115 | protected function isSameType($mime1, $mime2) { |
||
| 3118 | |||
| 3119 | /** |
||
| 3120 | * If file has required attr == $val - return file path, |
||
| 3121 | * If dir has child with has required attr == $val - return child path |
||
| 3122 | * |
||
| 3123 | * @param string $path file path |
||
| 3124 | * @param string $attr attribute name |
||
| 3125 | * @param bool $val attribute value |
||
| 3126 | * @return string|false |
||
| 3127 | * @author Dmitry (dio) Levashov |
||
| 3128 | **/ |
||
| 3129 | protected function closestByAttr($path, $attr, $val) { |
||
| 3146 | |||
| 3147 | /** |
||
| 3148 | * Return first found children with required attr == $val |
||
| 3149 | * |
||
| 3150 | * @param string $path file path |
||
| 3151 | * @param string $attr attribute name |
||
| 3152 | * @param bool $val attribute value |
||
| 3153 | * @return string|false |
||
| 3154 | * @author Dmitry (dio) Levashov |
||
| 3155 | **/ |
||
| 3156 | protected function childsByAttr($path, $attr, $val) { |
||
| 3164 | |||
| 3165 | /***************** get content *******************/ |
||
| 3166 | |||
| 3167 | /** |
||
| 3168 | * Return required dir's files info. |
||
| 3169 | * If onlyMimes is set - return only dirs and files of required mimes |
||
| 3170 | * |
||
| 3171 | * @param string $path dir path |
||
| 3172 | * @return array |
||
| 3173 | * @author Dmitry (dio) Levashov |
||
| 3174 | **/ |
||
| 3175 | protected function getScandir($path) { |
||
| 3188 | |||
| 3189 | |||
| 3190 | /** |
||
| 3191 | * Return subdirs tree |
||
| 3192 | * |
||
| 3193 | * @param string $path parent dir path |
||
| 3194 | * @param int $deep tree deep |
||
| 3195 | * @return array |
||
| 3196 | * @author Dmitry (dio) Levashov |
||
| 3197 | **/ |
||
| 3198 | protected function gettree($path, $deep, $exclude='') { |
||
| 3216 | |||
| 3217 | /** |
||
| 3218 | * Recursive files search |
||
| 3219 | * |
||
| 3220 | * @param string $path dir path |
||
| 3221 | * @param string $q search string |
||
| 3222 | * @param array $mimes |
||
| 3223 | * @return array |
||
| 3224 | * @author Dmitry (dio) Levashov |
||
| 3225 | **/ |
||
| 3226 | protected function doSearch($path, $q, $mimes) { |
||
| 3262 | |||
| 3263 | /********************** manuipulations ******************/ |
||
| 3264 | |||
| 3265 | /** |
||
| 3266 | * Copy file/recursive copy dir only in current volume. |
||
| 3267 | * Return new file path or false. |
||
| 3268 | * |
||
| 3269 | * @param string $src source path |
||
| 3270 | * @param string $dst destination dir path |
||
| 3271 | * @param string $name new file name (optionaly) |
||
| 3272 | * @return string|false |
||
| 3273 | * @author Dmitry (dio) Levashov |
||
| 3274 | **/ |
||
| 3275 | protected function copy($src, $dst, $name) { |
||
| 3317 | |||
| 3318 | /** |
||
| 3319 | * Move file |
||
| 3320 | * Return new file path or false. |
||
| 3321 | * |
||
| 3322 | * @param string $src source path |
||
| 3323 | * @param string $dst destination dir path |
||
| 3324 | * @param string $name new file name |
||
| 3325 | * @return string|false |
||
| 3326 | * @author Dmitry (dio) Levashov |
||
| 3327 | **/ |
||
| 3328 | protected function move($src, $dst, $name) { |
||
| 3342 | |||
| 3343 | /** |
||
| 3344 | * Copy file from another volume. |
||
| 3345 | * Return new file path or false. |
||
| 3346 | * |
||
| 3347 | * @param Object $volume source volume |
||
| 3348 | * @param string $src source file hash |
||
| 3349 | * @param string $destination destination dir path |
||
| 3350 | * @param string $name file name |
||
| 3351 | * @return string|false |
||
| 3352 | * @author Dmitry (dio) Levashov |
||
| 3353 | **/ |
||
| 3354 | protected function copyFrom($volume, $src, $destination, $name) { |
||
| 3416 | |||
| 3417 | /** |
||
| 3418 | * Remove file/ recursive remove dir |
||
| 3419 | * |
||
| 3420 | * @param string $path file path |
||
| 3421 | * @param bool $force try to remove even if file locked |
||
| 3422 | * @return bool |
||
| 3423 | * @author Dmitry (dio) Levashov |
||
| 3424 | **/ |
||
| 3425 | protected function remove($path, $force = false) { |
||
| 3455 | |||
| 3456 | |||
| 3457 | /************************* thumbnails **************************/ |
||
| 3458 | |||
| 3459 | /** |
||
| 3460 | * Return thumbnail file name for required file |
||
| 3461 | * |
||
| 3462 | * @param array $stat file stat |
||
| 3463 | * @return string |
||
| 3464 | * @author Dmitry (dio) Levashov |
||
| 3465 | **/ |
||
| 3466 | protected function tmbname($stat) { |
||
| 3469 | |||
| 3470 | /** |
||
| 3471 | * Return thumnbnail name if exists |
||
| 3472 | * |
||
| 3473 | * @param string $path file path |
||
| 3474 | * @param array $stat file stat |
||
| 3475 | * @return string|false |
||
| 3476 | * @author Dmitry (dio) Levashov |
||
| 3477 | **/ |
||
| 3478 | protected function gettmb($path, $stat) { |
||
| 3492 | |||
| 3493 | /** |
||
| 3494 | * Return true if thumnbnail for required file can be created |
||
| 3495 | * |
||
| 3496 | * @param string $path thumnbnail path |
||
| 3497 | * @param array $stat file stat |
||
| 3498 | * @param bool $checkTmbPath |
||
| 3499 | * @return string|bool |
||
| 3500 | * @author Dmitry (dio) Levashov |
||
| 3501 | **/ |
||
| 3502 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
| 3509 | |||
| 3510 | /** |
||
| 3511 | * Return true if required file can be resized. |
||
| 3512 | * By default - the same as canCreateTmb |
||
| 3513 | * |
||
| 3514 | * @param string $path thumnbnail path |
||
| 3515 | * @param array $stat file stat |
||
| 3516 | * @return string|bool |
||
| 3517 | * @author Dmitry (dio) Levashov |
||
| 3518 | **/ |
||
| 3519 | protected function canResize($path, $stat) { |
||
| 3522 | |||
| 3523 | /** |
||
| 3524 | * Create thumnbnail and return it's URL on success |
||
| 3525 | * |
||
| 3526 | * @param string $path file path |
||
| 3527 | * @param string $mime file mime type |
||
| 3528 | * @return string|false |
||
| 3529 | * @author Dmitry (dio) Levashov |
||
| 3530 | **/ |
||
| 3531 | protected function createTmb($path, $stat) { |
||
| 3601 | |||
| 3602 | /** |
||
| 3603 | * Resize image |
||
| 3604 | * |
||
| 3605 | * @param string $path image file |
||
| 3606 | * @param int $width new width |
||
| 3607 | * @param int $height new height |
||
| 3608 | * @param bool $keepProportions crop image |
||
| 3609 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
| 3610 | * @param string $destformat image destination format |
||
| 3611 | * @return string|false |
||
| 3612 | * @author Dmitry (dio) Levashov |
||
| 3613 | * @author Alexey Sukhotin |
||
| 3614 | **/ |
||
| 3615 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null) { |
||
| 3708 | |||
| 3709 | /** |
||
| 3710 | * Crop image |
||
| 3711 | * |
||
| 3712 | * @param string $path image file |
||
| 3713 | * @param int $width crop width |
||
| 3714 | * @param int $height crop height |
||
| 3715 | * @param bool $x crop left offset |
||
| 3716 | * @param bool $y crop top offset |
||
| 3717 | * @param string $destformat image destination format |
||
| 3718 | * @return string|false |
||
| 3719 | * @author Dmitry (dio) Levashov |
||
| 3720 | * @author Alexey Sukhotin |
||
| 3721 | **/ |
||
| 3722 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null) { |
||
| 3796 | |||
| 3797 | /** |
||
| 3798 | * Put image to square |
||
| 3799 | * |
||
| 3800 | * @param string $path image file |
||
| 3801 | * @param int $width square width |
||
| 3802 | * @param int $height square height |
||
| 3803 | * @param int $align reserved |
||
| 3804 | * @param int $valign reserved |
||
| 3805 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3806 | * @param string $destformat image destination format |
||
| 3807 | * @return string|false |
||
| 3808 | * @author Dmitry (dio) Levashov |
||
| 3809 | * @author Alexey Sukhotin |
||
| 3810 | **/ |
||
| 3811 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null) { |
||
| 3889 | |||
| 3890 | /** |
||
| 3891 | * Rotate image |
||
| 3892 | * |
||
| 3893 | * @param string $path image file |
||
| 3894 | * @param int $degree rotete degrees |
||
| 3895 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3896 | * @param string $destformat image destination format |
||
| 3897 | * @return string|false |
||
| 3898 | * @author nao-pon |
||
| 3899 | * @author Troex Nevelin |
||
| 3900 | **/ |
||
| 3901 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null) { |
||
| 3981 | |||
| 3982 | /** |
||
| 3983 | * Execute shell command |
||
| 3984 | * |
||
| 3985 | * @param string $command command line |
||
| 3986 | * @param array $output stdout strings |
||
| 3987 | * @param array $return_var process exit code |
||
| 3988 | * @param array $error_output stderr strings |
||
| 3989 | * @return int exit code |
||
| 3990 | * @author Alexey Sukhotin |
||
| 3991 | **/ |
||
| 3992 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
| 4022 | |||
| 4023 | /** |
||
| 4024 | * Remove thumbnail, also remove recursively if stat is directory |
||
| 4025 | * |
||
| 4026 | * @param string $stat file stat |
||
| 4027 | * @return void |
||
| 4028 | * @author Dmitry (dio) Levashov |
||
| 4029 | * @author Naoki Sawada |
||
| 4030 | * @author Troex Nevelin |
||
| 4031 | **/ |
||
| 4032 | protected function rmTmb($stat) { |
||
| 4045 | |||
| 4046 | /** |
||
| 4047 | * Create an gd image according to the specified mime type |
||
| 4048 | * |
||
| 4049 | * @param string $path image file |
||
| 4050 | * @param string $mime |
||
| 4051 | * @return gd image resource identifier |
||
| 4052 | */ |
||
| 4053 | protected function gdImageCreate($path,$mime){ |
||
| 4069 | |||
| 4070 | /** |
||
| 4071 | * Output gd image to file |
||
| 4072 | * |
||
| 4073 | * @param resource $image gd image resource |
||
| 4074 | * @param string $filename The path to save the file to. |
||
| 4075 | * @param string $destformat The Image type to use for $filename |
||
| 4076 | * @param string $mime The original image mime type |
||
| 4077 | */ |
||
| 4078 | protected function gdImage($image, $filename, $destformat, $mime ){ |
||
| 4090 | |||
| 4091 | /** |
||
| 4092 | * Assign the proper background to a gd image |
||
| 4093 | * |
||
| 4094 | * @param resource $image gd image resource |
||
| 4095 | * @param string $bgcolor background color in #rrggbb format |
||
| 4096 | */ |
||
| 4097 | protected function gdImageBackground($image, $bgcolor){ |
||
| 4110 | |||
| 4111 | /*********************** misc *************************/ |
||
| 4112 | |||
| 4113 | /** |
||
| 4114 | * Return smart formatted date |
||
| 4115 | * |
||
| 4116 | * @param int $ts file timestamp |
||
| 4117 | * @return string |
||
| 4118 | * @author Dmitry (dio) Levashov |
||
| 4119 | **/ |
||
| 4120 | // protected function formatDate($ts) { |
||
| 4121 | // if ($ts > $this->today) { |
||
| 4122 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
| 4123 | // } |
||
| 4124 | // |
||
| 4125 | // if ($ts > $this->yesterday) { |
||
| 4126 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
| 4127 | // } |
||
| 4128 | // |
||
| 4129 | // return date($this->options['dateFormat'], $ts); |
||
| 4130 | // } |
||
| 4131 | |||
| 4132 | /** |
||
| 4133 | * Find position of first occurrence of string in a string with multibyte support |
||
| 4134 | * |
||
| 4135 | * @param string $haystack The string being checked. |
||
| 4136 | * @param string $needle The string to find in haystack. |
||
| 4137 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
| 4138 | * @return int|bool |
||
| 4139 | * @author Alexey Sukhotin |
||
| 4140 | **/ |
||
| 4141 | protected function stripos($haystack , $needle , $offset = 0) { |
||
| 4149 | |||
| 4150 | /** |
||
| 4151 | * Get server side available archivers |
||
| 4152 | * |
||
| 4153 | * @param bool $use_cache |
||
| 4154 | * @return array |
||
| 4155 | */ |
||
| 4156 | protected function getArchivers($use_cache = true) { |
||
| 4272 | |||
| 4273 | /** |
||
| 4274 | * Resolve relative / (Unix-like)absolute path |
||
| 4275 | * |
||
| 4276 | * @param string $path target path |
||
| 4277 | * @param string $base base path |
||
| 4278 | * @return string |
||
| 4279 | */ |
||
| 4280 | protected function getFullPath($path, $base) { |
||
| 4327 | |||
| 4328 | /** |
||
| 4329 | * Remove directory recursive on local file system |
||
| 4330 | * |
||
| 4331 | * @param string $dir Target dirctory path |
||
| 4332 | * @return boolean |
||
| 4333 | * @author Naoki Sawada |
||
| 4334 | */ |
||
| 4335 | public function rmdirRecursive($dir) { |
||
| 4355 | |||
| 4356 | /** |
||
| 4357 | * Create archive and return its path |
||
| 4358 | * |
||
| 4359 | * @param string $dir target dir |
||
| 4360 | * @param array $files files names list |
||
| 4361 | * @param string $name archive name |
||
| 4362 | * @param array $arc archiver options |
||
| 4363 | * @return string|bool |
||
| 4364 | * @author Dmitry (dio) Levashov, |
||
| 4365 | * @author Alexey Sukhotin |
||
| 4366 | * @author Naoki Sawada |
||
| 4367 | **/ |
||
| 4368 | protected function makeArchive($dir, $files, $name, $arc) { |
||
| 4386 | |||
| 4387 | /** |
||
| 4388 | * Unpack archive |
||
| 4389 | * |
||
| 4390 | * @param string $path archive path |
||
| 4391 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
| 4392 | * @param bool $remove remove archive ( unlink($path) ) |
||
| 4393 | * @return void |
||
| 4394 | * @author Dmitry (dio) Levashov |
||
| 4395 | * @author Alexey Sukhotin |
||
| 4396 | * @author Naoki Sawada |
||
| 4397 | **/ |
||
| 4398 | protected function unpackArchive($path, $arc, $remove = true) { |
||
| 4413 | |||
| 4414 | /** |
||
| 4415 | * Create Zip archive using PHP class ZipArchive |
||
| 4416 | * |
||
| 4417 | * @param string $dir target dir |
||
| 4418 | * @param array $files files names list |
||
| 4419 | * @param string|object $zipPath Zip archive name |
||
| 4420 | * @return void |
||
| 4421 | * @author Naoki Sawada |
||
| 4422 | */ |
||
| 4423 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
| 4461 | |||
| 4462 | /** |
||
| 4463 | * Unpack Zip archive using PHP class ZipArchive |
||
| 4464 | * |
||
| 4465 | * @param string $zipPath Zip archive name |
||
| 4466 | * @param string $toDir Extract to path |
||
| 4467 | * @return bool |
||
| 4468 | * @author Naoki Sawada |
||
| 4469 | */ |
||
| 4470 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
| 4482 | |||
| 4483 | /**==================================* abstract methods *====================================**/ |
||
| 4484 | |||
| 4485 | /*********************** paths/urls *************************/ |
||
| 4486 | |||
| 4487 | /** |
||
| 4488 | * Return parent directory path |
||
| 4489 | * |
||
| 4490 | * @param string $path file path |
||
| 4491 | * @return string |
||
| 4492 | * @author Dmitry (dio) Levashov |
||
| 4493 | **/ |
||
| 4494 | abstract protected function _dirname($path); |
||
| 4495 | |||
| 4496 | /** |
||
| 4497 | * Return file name |
||
| 4498 | * |
||
| 4499 | * @param string $path file path |
||
| 4500 | * @return string |
||
| 4501 | * @author Dmitry (dio) Levashov |
||
| 4502 | **/ |
||
| 4503 | abstract protected function _basename($path); |
||
| 4504 | |||
| 4505 | /** |
||
| 4506 | * Join dir name and file name and return full path. |
||
| 4507 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 4508 | * |
||
| 4509 | * @param string $dir dir path |
||
| 4510 | * @param string $name file name |
||
| 4511 | * @return string |
||
| 4512 | * @author Dmitry (dio) Levashov |
||
| 4513 | **/ |
||
| 4514 | abstract protected function _joinPath($dir, $name); |
||
| 4515 | |||
| 4516 | /** |
||
| 4517 | * Return normalized path |
||
| 4518 | * |
||
| 4519 | * @param string $path file path |
||
| 4520 | * @return string |
||
| 4521 | * @author Dmitry (dio) Levashov |
||
| 4522 | **/ |
||
| 4523 | abstract protected function _normpath($path); |
||
| 4524 | |||
| 4525 | /** |
||
| 4526 | * Return file path related to root dir |
||
| 4527 | * |
||
| 4528 | * @param string $path file path |
||
| 4529 | * @return string |
||
| 4530 | * @author Dmitry (dio) Levashov |
||
| 4531 | **/ |
||
| 4532 | abstract protected function _relpath($path); |
||
| 4533 | |||
| 4534 | /** |
||
| 4535 | * Convert path related to root dir into real path |
||
| 4536 | * |
||
| 4537 | * @param string $path rel file path |
||
| 4538 | * @return string |
||
| 4539 | * @author Dmitry (dio) Levashov |
||
| 4540 | **/ |
||
| 4541 | abstract protected function _abspath($path); |
||
| 4542 | |||
| 4543 | /** |
||
| 4544 | * Return fake path started from root dir. |
||
| 4545 | * Required to show path on client side. |
||
| 4546 | * |
||
| 4547 | * @param string $path file path |
||
| 4548 | * @return string |
||
| 4549 | * @author Dmitry (dio) Levashov |
||
| 4550 | **/ |
||
| 4551 | abstract protected function _path($path); |
||
| 4552 | |||
| 4553 | /** |
||
| 4554 | * Return true if $path is children of $parent |
||
| 4555 | * |
||
| 4556 | * @param string $path path to check |
||
| 4557 | * @param string $parent parent path |
||
| 4558 | * @return bool |
||
| 4559 | * @author Dmitry (dio) Levashov |
||
| 4560 | **/ |
||
| 4561 | abstract protected function _inpath($path, $parent); |
||
| 4562 | |||
| 4563 | /** |
||
| 4564 | * Return stat for given path. |
||
| 4565 | * Stat contains following fields: |
||
| 4566 | * - (int) size file size in b. required |
||
| 4567 | * - (int) ts file modification time in unix time. required |
||
| 4568 | * - (string) mime mimetype. required for folders, others - optionally |
||
| 4569 | * - (bool) read read permissions. required |
||
| 4570 | * - (bool) write write permissions. required |
||
| 4571 | * - (bool) locked is object locked. optionally |
||
| 4572 | * - (bool) hidden is object hidden. optionally |
||
| 4573 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
| 4574 | * - (string) target for symlinks - link target path. optionally |
||
| 4575 | * |
||
| 4576 | * If file does not exists - returns empty array or false. |
||
| 4577 | * |
||
| 4578 | * @param string $path file path |
||
| 4579 | * @return array|false |
||
| 4580 | * @author Dmitry (dio) Levashov |
||
| 4581 | **/ |
||
| 4582 | abstract protected function _stat($path); |
||
| 4583 | |||
| 4584 | |||
| 4585 | /***************** file stat ********************/ |
||
| 4586 | |||
| 4587 | |||
| 4588 | /** |
||
| 4589 | * Return true if path is dir and has at least one childs directory |
||
| 4590 | * |
||
| 4591 | * @param string $path dir path |
||
| 4592 | * @return bool |
||
| 4593 | * @author Dmitry (dio) Levashov |
||
| 4594 | **/ |
||
| 4595 | abstract protected function _subdirs($path); |
||
| 4596 | |||
| 4597 | /** |
||
| 4598 | * Return object width and height |
||
| 4599 | * Ususaly used for images, but can be realize for video etc... |
||
| 4600 | * |
||
| 4601 | * @param string $path file path |
||
| 4602 | * @param string $mime file mime type |
||
| 4603 | * @return string |
||
| 4604 | * @author Dmitry (dio) Levashov |
||
| 4605 | **/ |
||
| 4606 | abstract protected function _dimensions($path, $mime); |
||
| 4607 | |||
| 4608 | /******************** file/dir content *********************/ |
||
| 4609 | |||
| 4610 | /** |
||
| 4611 | * Return files list in directory |
||
| 4612 | * |
||
| 4613 | * @param string $path dir path |
||
| 4614 | * @return array |
||
| 4615 | * @author Dmitry (dio) Levashov |
||
| 4616 | **/ |
||
| 4617 | abstract protected function _scandir($path); |
||
| 4618 | |||
| 4619 | /** |
||
| 4620 | * Open file and return file pointer |
||
| 4621 | * |
||
| 4622 | * @param string $path file path |
||
| 4623 | * @param bool $write open file for writing |
||
| 4624 | * @return resource|false |
||
| 4625 | * @author Dmitry (dio) Levashov |
||
| 4626 | **/ |
||
| 4627 | abstract protected function _fopen($path, $mode="rb"); |
||
| 4628 | |||
| 4629 | /** |
||
| 4630 | * Close opened file |
||
| 4631 | * |
||
| 4632 | * @param resource $fp file pointer |
||
| 4633 | * @param string $path file path |
||
| 4634 | * @return bool |
||
| 4635 | * @author Dmitry (dio) Levashov |
||
| 4636 | **/ |
||
| 4637 | abstract protected function _fclose($fp, $path=''); |
||
| 4638 | |||
| 4639 | /******************** file/dir manipulations *************************/ |
||
| 4640 | |||
| 4641 | /** |
||
| 4642 | * Create dir and return created dir path or false on failed |
||
| 4643 | * |
||
| 4644 | * @param string $path parent dir path |
||
| 4645 | * @param string $name new directory name |
||
| 4646 | * @return string|bool |
||
| 4647 | * @author Dmitry (dio) Levashov |
||
| 4648 | **/ |
||
| 4649 | abstract protected function _mkdir($path, $name); |
||
| 4650 | |||
| 4651 | /** |
||
| 4652 | * Create file and return it's path or false on failed |
||
| 4653 | * |
||
| 4654 | * @param string $path parent dir path |
||
| 4655 | * @param string $name new file name |
||
| 4656 | * @return string|bool |
||
| 4657 | * @author Dmitry (dio) Levashov |
||
| 4658 | **/ |
||
| 4659 | abstract protected function _mkfile($path, $name); |
||
| 4660 | |||
| 4661 | /** |
||
| 4662 | * Create symlink |
||
| 4663 | * |
||
| 4664 | * @param string $source file to link to |
||
| 4665 | * @param string $targetDir folder to create link in |
||
| 4666 | * @param string $name symlink name |
||
| 4667 | * @return bool |
||
| 4668 | * @author Dmitry (dio) Levashov |
||
| 4669 | **/ |
||
| 4670 | abstract protected function _symlink($source, $targetDir, $name); |
||
| 4671 | |||
| 4672 | /** |
||
| 4673 | * Copy file into another file (only inside one volume) |
||
| 4674 | * |
||
| 4675 | * @param string $source source file path |
||
| 4676 | * @param string $target target dir path |
||
| 4677 | * @param string $name file name |
||
| 4678 | * @return bool |
||
| 4679 | * @author Dmitry (dio) Levashov |
||
| 4680 | **/ |
||
| 4681 | abstract protected function _copy($source, $targetDir, $name); |
||
| 4682 | |||
| 4683 | /** |
||
| 4684 | * Move file into another parent dir. |
||
| 4685 | * Return new file path or false. |
||
| 4686 | * |
||
| 4687 | * @param string $source source file path |
||
| 4688 | * @param string $target target dir path |
||
| 4689 | * @param string $name file name |
||
| 4690 | * @return string|bool |
||
| 4691 | * @author Dmitry (dio) Levashov |
||
| 4692 | **/ |
||
| 4693 | abstract protected function _move($source, $targetDir, $name); |
||
| 4694 | |||
| 4695 | /** |
||
| 4696 | * Remove file |
||
| 4697 | * |
||
| 4698 | * @param string $path file path |
||
| 4699 | * @return bool |
||
| 4700 | * @author Dmitry (dio) Levashov |
||
| 4701 | **/ |
||
| 4702 | abstract protected function _unlink($path); |
||
| 4703 | |||
| 4704 | /** |
||
| 4705 | * Remove dir |
||
| 4706 | * |
||
| 4707 | * @param string $path dir path |
||
| 4708 | * @return bool |
||
| 4709 | * @author Dmitry (dio) Levashov |
||
| 4710 | **/ |
||
| 4711 | abstract protected function _rmdir($path); |
||
| 4712 | |||
| 4713 | /** |
||
| 4714 | * Create new file and write into it from file pointer. |
||
| 4715 | * Return new file path or false on error. |
||
| 4716 | * |
||
| 4717 | * @param resource $fp file pointer |
||
| 4718 | * @param string $dir target dir path |
||
| 4719 | * @param string $name file name |
||
| 4720 | * @param array $stat file stat (required by some virtual fs) |
||
| 4721 | * @return bool|string |
||
| 4722 | * @author Dmitry (dio) Levashov |
||
| 4723 | **/ |
||
| 4724 | abstract protected function _save($fp, $dir, $name, $stat); |
||
| 4725 | |||
| 4726 | /** |
||
| 4727 | * Get file contents |
||
| 4728 | * |
||
| 4729 | * @param string $path file path |
||
| 4730 | * @return string|false |
||
| 4731 | * @author Dmitry (dio) Levashov |
||
| 4732 | **/ |
||
| 4733 | abstract protected function _getContents($path); |
||
| 4734 | |||
| 4735 | /** |
||
| 4736 | * Write a string to a file |
||
| 4737 | * |
||
| 4738 | * @param string $path file path |
||
| 4739 | * @param string $content new file content |
||
| 4740 | * @return bool |
||
| 4741 | * @author Dmitry (dio) Levashov |
||
| 4742 | **/ |
||
| 4743 | abstract protected function _filePutContents($path, $content); |
||
| 4744 | |||
| 4745 | /** |
||
| 4746 | * Extract files from archive |
||
| 4747 | * |
||
| 4748 | * @param string $path file path |
||
| 4749 | * @param array $arc archiver options |
||
| 4750 | * @return bool |
||
| 4751 | * @author Dmitry (dio) Levashov, |
||
| 4752 | * @author Alexey Sukhotin |
||
| 4753 | **/ |
||
| 4754 | abstract protected function _extract($path, $arc); |
||
| 4755 | |||
| 4756 | /** |
||
| 4757 | * Create archive and return its path |
||
| 4758 | * |
||
| 4759 | * @param string $dir target dir |
||
| 4760 | * @param array $files files names list |
||
| 4761 | * @param string $name archive name |
||
| 4762 | * @param array $arc archiver options |
||
| 4763 | * @return string|bool |
||
| 4764 | * @author Dmitry (dio) Levashov, |
||
| 4765 | * @author Alexey Sukhotin |
||
| 4766 | **/ |
||
| 4767 | abstract protected function _archive($dir, $files, $name, $arc); |
||
| 4768 | |||
| 4769 | /** |
||
| 4770 | * Detect available archivers |
||
| 4771 | * |
||
| 4772 | * @return void |
||
| 4773 | * @author Dmitry (dio) Levashov, |
||
| 4774 | * @author Alexey Sukhotin |
||
| 4775 | **/ |
||
| 4776 | abstract protected function _checkArchivers(); |
||
| 4777 | |||
| 4778 | /** |
||
| 4779 | * Change file mode (chmod) |
||
| 4780 | * |
||
| 4781 | * @param string $path file path |
||
| 4782 | * @param string $mode octal string such as '0755' |
||
| 4783 | * @return bool |
||
| 4784 | * @author David Bartle, |
||
| 4785 | **/ |
||
| 4786 | abstract protected function _chmod($path, $mode); |
||
| 4787 | |||
| 4788 | |||
| 4789 | } // END class |
||
| 4790 |
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.