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 | // directory for thumbnails |
||
| 209 | 'tmbPath' => '.tmb', |
||
| 210 | // mode to create thumbnails dir |
||
| 211 | 'tmbPathMode' => 0777, |
||
| 212 | // thumbnails dir URL. Set it if store thumbnails outside root directory |
||
| 213 | 'tmbURL' => '', |
||
| 214 | // thumbnails size (px) |
||
| 215 | 'tmbSize' => 48, |
||
| 216 | // thumbnails crop (true - crop, false - scale image to fit thumbnail size) |
||
| 217 | 'tmbCrop' => true, |
||
| 218 | // thumbnails background color (hex #rrggbb or 'transparent') |
||
| 219 | 'tmbBgColor' => '#ffffff', |
||
| 220 | // image manipulations library |
||
| 221 | 'imgLib' => 'auto', |
||
| 222 | // on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 223 | 'copyOverwrite' => true, |
||
| 224 | // if true - join new and old directories content on paste |
||
| 225 | 'copyJoin' => true, |
||
| 226 | // on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 227 | 'uploadOverwrite' => true, |
||
| 228 | // mimetypes allowed to upload |
||
| 229 | 'uploadAllow' => array(), |
||
| 230 | // mimetypes not allowed to upload |
||
| 231 | 'uploadDeny' => array(), |
||
| 232 | // order to proccess uploadAllow and uploadDeny options |
||
| 233 | 'uploadOrder' => array('deny', 'allow'), |
||
| 234 | // maximum upload file size. NOTE - this is size for every uploaded files |
||
| 235 | 'uploadMaxSize' => 0, |
||
| 236 | // files dates format |
||
| 237 | 'dateFormat' => 'j M Y H:i', |
||
| 238 | // files time format |
||
| 239 | 'timeFormat' => 'H:i', |
||
| 240 | // if true - every folder will be check for children folders, otherwise all folders will be marked as having subfolders |
||
| 241 | 'checkSubfolders' => true, |
||
| 242 | // allow to copy from this volume to other ones? |
||
| 243 | 'copyFrom' => true, |
||
| 244 | // allow to copy from other volumes to this one? |
||
| 245 | 'copyTo' => true, |
||
| 246 | // list of commands disabled on this root |
||
| 247 | 'disabled' => array(), |
||
| 248 | // enable file owner, group & mode info, `false` to inactivate "chmod" command. |
||
| 249 | 'statOwner' => false, |
||
| 250 | // allow exec chmod of read-only files |
||
| 251 | 'allowChmodReadOnly' => false, |
||
| 252 | // regexp or function name to validate new file name |
||
| 253 | 'acceptedName' => '/^[^\.].*/', //<-- DONT touch this! Use constructor options to overwrite it! |
||
| 254 | // function/class method to control files permissions |
||
| 255 | 'accessControl' => null, |
||
| 256 | // some data required by access control |
||
| 257 | 'accessControlData' => null, |
||
| 258 | // default permissions. |
||
| 259 | 'defaults' => array( |
||
| 260 | 'read' => true, |
||
| 261 | 'write' => true, |
||
| 262 | 'locked' => false, |
||
| 263 | 'hidden' => false |
||
| 264 | ), |
||
| 265 | // files attributes |
||
| 266 | 'attributes' => array(), |
||
| 267 | // Allowed archive's mimetypes to create. Leave empty for all available types. |
||
| 268 | 'archiveMimes' => array(), |
||
| 269 | // Manual config for archivers. See example below. Leave empty for auto detect |
||
| 270 | 'archivers' => array(), |
||
| 271 | // plugin settings |
||
| 272 | 'plugin' => array(), |
||
| 273 | // required to fix bug on macos |
||
| 274 | 'utf8fix' => false, |
||
| 275 | // й ё Й Ё Ø Å |
||
| 276 | 'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"), |
||
| 277 | 'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5") |
||
| 278 | ); |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Defaults permissions |
||
| 282 | * |
||
| 283 | * @var array |
||
| 284 | **/ |
||
| 285 | protected $defaults = array( |
||
| 286 | 'read' => true, |
||
| 287 | 'write' => true, |
||
| 288 | 'locked' => false, |
||
| 289 | 'hidden' => false |
||
| 290 | ); |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Access control function/class |
||
| 294 | * |
||
| 295 | * @var mixed |
||
| 296 | **/ |
||
| 297 | protected $attributes = array(); |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Access control function/class |
||
| 301 | * |
||
| 302 | * @var mixed |
||
| 303 | **/ |
||
| 304 | protected $access = null; |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Mime types allowed to upload |
||
| 308 | * |
||
| 309 | * @var array |
||
| 310 | **/ |
||
| 311 | protected $uploadAllow = array(); |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Mime types denied to upload |
||
| 315 | * |
||
| 316 | * @var array |
||
| 317 | **/ |
||
| 318 | protected $uploadDeny = array(); |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Order to validate uploadAllow and uploadDeny |
||
| 322 | * |
||
| 323 | * @var array |
||
| 324 | **/ |
||
| 325 | protected $uploadOrder = array(); |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Maximum allowed upload file size. |
||
| 329 | * Set as number or string with unit - "10M", "500K", "1G" |
||
| 330 | * |
||
| 331 | * @var int|string |
||
| 332 | **/ |
||
| 333 | protected $uploadMaxSize = 0; |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Mimetype detect method |
||
| 337 | * |
||
| 338 | * @var string |
||
| 339 | **/ |
||
| 340 | protected $mimeDetect = 'auto'; |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Flag - mimetypes from externail file was loaded |
||
| 344 | * |
||
| 345 | * @var bool |
||
| 346 | **/ |
||
| 347 | private static $mimetypesLoaded = false; |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Finfo object for mimeDetect == 'finfo' |
||
| 351 | * |
||
| 352 | * @var object |
||
| 353 | **/ |
||
| 354 | protected $finfo = null; |
||
| 355 | |||
| 356 | /** |
||
| 357 | * List of disabled client's commands |
||
| 358 | * |
||
| 359 | * @var array |
||
| 360 | **/ |
||
| 361 | protected $disabled = array(); |
||
| 362 | |||
| 363 | /** |
||
| 364 | * default extensions/mimetypes for mimeDetect == 'internal' |
||
| 365 | * |
||
| 366 | * @var array |
||
| 367 | **/ |
||
| 368 | protected static $mimetypes = array( |
||
| 369 | // applications |
||
| 370 | 'ai' => 'application/postscript', |
||
| 371 | 'eps' => 'application/postscript', |
||
| 372 | 'exe' => 'application/x-executable', |
||
| 373 | 'doc' => 'application/vnd.ms-word', |
||
| 374 | 'xls' => 'application/vnd.ms-excel', |
||
| 375 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
| 376 | 'pps' => 'application/vnd.ms-powerpoint', |
||
| 377 | 'pdf' => 'application/pdf', |
||
| 378 | 'xml' => 'application/xml', |
||
| 379 | 'swf' => 'application/x-shockwave-flash', |
||
| 380 | 'torrent' => 'application/x-bittorrent', |
||
| 381 | 'jar' => 'application/x-jar', |
||
| 382 | // open office (finfo detect as application/zip) |
||
| 383 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
| 384 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
| 385 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
| 386 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
| 387 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
| 388 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
| 389 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
| 390 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
| 391 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
| 392 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
| 393 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
| 394 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
| 395 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
| 396 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
| 397 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
| 398 | // MS office 2007 (finfo detect as application/zip) |
||
| 399 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
| 400 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
| 401 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
| 402 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
| 403 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
| 404 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
| 405 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
| 406 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
| 407 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
| 408 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
| 409 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
| 410 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
| 411 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
| 412 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
| 413 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
| 414 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
| 415 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
| 416 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
| 417 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
| 418 | // archives |
||
| 419 | 'gz' => 'application/x-gzip', |
||
| 420 | 'tgz' => 'application/x-gzip', |
||
| 421 | 'bz' => 'application/x-bzip2', |
||
| 422 | 'bz2' => 'application/x-bzip2', |
||
| 423 | 'tbz' => 'application/x-bzip2', |
||
| 424 | 'xz' => 'application/x-xz', |
||
| 425 | 'zip' => 'application/zip', |
||
| 426 | 'rar' => 'application/x-rar', |
||
| 427 | 'tar' => 'application/x-tar', |
||
| 428 | '7z' => 'application/x-7z-compressed', |
||
| 429 | // texts |
||
| 430 | 'txt' => 'text/plain', |
||
| 431 | 'php' => 'text/x-php', |
||
| 432 | 'html' => 'text/html', |
||
| 433 | 'htm' => 'text/html', |
||
| 434 | 'js' => 'text/javascript', |
||
| 435 | 'css' => 'text/css', |
||
| 436 | 'rtf' => 'text/rtf', |
||
| 437 | 'rtfd' => 'text/rtfd', |
||
| 438 | 'py' => 'text/x-python', |
||
| 439 | 'java' => 'text/x-java-source', |
||
| 440 | 'rb' => 'text/x-ruby', |
||
| 441 | 'sh' => 'text/x-shellscript', |
||
| 442 | 'pl' => 'text/x-perl', |
||
| 443 | 'xml' => 'text/xml', |
||
| 444 | 'sql' => 'text/x-sql', |
||
| 445 | 'c' => 'text/x-csrc', |
||
| 446 | 'h' => 'text/x-chdr', |
||
| 447 | 'cpp' => 'text/x-c++src', |
||
| 448 | 'hh' => 'text/x-c++hdr', |
||
| 449 | 'log' => 'text/plain', |
||
| 450 | 'csv' => 'text/x-comma-separated-values', |
||
| 451 | 'md' => 'text/x-markdown', |
||
| 452 | 'markdown' => 'text/x-markdown', |
||
| 453 | // images |
||
| 454 | 'bmp' => 'image/x-ms-bmp', |
||
| 455 | 'jpg' => 'image/jpeg', |
||
| 456 | 'jpeg' => 'image/jpeg', |
||
| 457 | 'gif' => 'image/gif', |
||
| 458 | 'png' => 'image/png', |
||
| 459 | 'tif' => 'image/tiff', |
||
| 460 | 'tiff' => 'image/tiff', |
||
| 461 | 'tga' => 'image/x-targa', |
||
| 462 | 'psd' => 'image/vnd.adobe.photoshop', |
||
| 463 | 'ai' => 'image/vnd.adobe.photoshop', |
||
| 464 | 'xbm' => 'image/xbm', |
||
| 465 | 'pxm' => 'image/pxm', |
||
| 466 | //audio |
||
| 467 | 'mp3' => 'audio/mpeg', |
||
| 468 | 'mid' => 'audio/midi', |
||
| 469 | 'ogg' => 'audio/ogg', |
||
| 470 | 'oga' => 'audio/ogg', |
||
| 471 | 'm4a' => 'audio/x-m4a', |
||
| 472 | 'wav' => 'audio/wav', |
||
| 473 | 'wma' => 'audio/x-ms-wma', |
||
| 474 | // video |
||
| 475 | 'avi' => 'video/x-msvideo', |
||
| 476 | 'dv' => 'video/x-dv', |
||
| 477 | 'mp4' => 'video/mp4', |
||
| 478 | 'mpeg' => 'video/mpeg', |
||
| 479 | 'mpg' => 'video/mpeg', |
||
| 480 | 'mov' => 'video/quicktime', |
||
| 481 | 'wm' => 'video/x-ms-wmv', |
||
| 482 | 'flv' => 'video/x-flv', |
||
| 483 | 'mkv' => 'video/x-matroska', |
||
| 484 | 'webm' => 'video/webm', |
||
| 485 | 'ogv' => 'video/ogg', |
||
| 486 | 'ogm' => 'video/ogg' |
||
| 487 | ); |
||
| 488 | |||
| 489 | /** |
||
| 490 | * Directory separator - required by client |
||
| 491 | * |
||
| 492 | * @var string |
||
| 493 | **/ |
||
| 494 | protected $separator = DIRECTORY_SEPARATOR; |
||
| 495 | |||
| 496 | /** |
||
| 497 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...) |
||
| 498 | * |
||
| 499 | * @var string |
||
| 500 | **/ |
||
| 501 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Mimetypes allowed to display |
||
| 505 | * |
||
| 506 | * @var array |
||
| 507 | **/ |
||
| 508 | protected $onlyMimes = array(); |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Store files moved or overwrited files info |
||
| 512 | * |
||
| 513 | * @var array |
||
| 514 | **/ |
||
| 515 | protected $removed = array(); |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Cache storage |
||
| 519 | * |
||
| 520 | * @var array |
||
| 521 | **/ |
||
| 522 | protected $cache = array(); |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Cache by folders |
||
| 526 | * |
||
| 527 | * @var array |
||
| 528 | **/ |
||
| 529 | protected $dirsCache = array(); |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Cache for subdirsCE() |
||
| 533 | * |
||
| 534 | * @var array |
||
| 535 | */ |
||
| 536 | protected $subdirsCache = array(); |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Reference of $_SESSION[elFinder::$sessionCacheKey][$this->id] |
||
| 540 | * |
||
| 541 | * @var array |
||
| 542 | */ |
||
| 543 | protected $sessionCache; |
||
| 544 | |||
| 545 | /*********************************************************************/ |
||
| 546 | /* INITIALIZATION */ |
||
| 547 | /*********************************************************************/ |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Prepare driver before mount volume. |
||
| 551 | * Return true if volume is ready. |
||
| 552 | * |
||
| 553 | * @return bool |
||
| 554 | * @author Dmitry (dio) Levashov |
||
| 555 | **/ |
||
| 556 | protected function init() { |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Configure after successfull mount. |
||
| 562 | * By default set thumbnails path and image manipulation library. |
||
| 563 | * |
||
| 564 | * @return void |
||
| 565 | * @author Dmitry (dio) Levashov |
||
| 566 | **/ |
||
| 567 | protected function configure() { |
||
| 608 | |||
| 609 | |||
| 610 | /*********************************************************************/ |
||
| 611 | /* PUBLIC API */ |
||
| 612 | /*********************************************************************/ |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Return driver id. Used as a part of volume id. |
||
| 616 | * |
||
| 617 | * @return string |
||
| 618 | * @author Dmitry (dio) Levashov |
||
| 619 | **/ |
||
| 620 | public function driverId() { |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Return volume id |
||
| 626 | * |
||
| 627 | * @return string |
||
| 628 | * @author Dmitry (dio) Levashov |
||
| 629 | **/ |
||
| 630 | public function id() { |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Return debug info for client |
||
| 636 | * |
||
| 637 | * @return array |
||
| 638 | * @author Dmitry (dio) Levashov |
||
| 639 | **/ |
||
| 640 | public function debug() { |
||
| 648 | |||
| 649 | /** |
||
| 650 | * chmod a file or folder |
||
| 651 | * |
||
| 652 | * @param string $hash file or folder hash to chmod |
||
| 653 | * @param string $mode octal string representing new permissions |
||
| 654 | * @return array|false |
||
| 655 | * @author David Bartle |
||
| 656 | **/ |
||
| 657 | public function chmod($hash, $mode) { |
||
| 693 | |||
| 694 | /** |
||
| 695 | * "Mount" volume. |
||
| 696 | * Return true if volume available for read or write, |
||
| 697 | * false - otherwise |
||
| 698 | * |
||
| 699 | * @return bool |
||
| 700 | * @author Dmitry (dio) Levashov |
||
| 701 | * @author Alexey Sukhotin |
||
| 702 | **/ |
||
| 703 | public function mount(array $opts) { |
||
| 966 | |||
| 967 | /** |
||
| 968 | * Some "unmount" stuffs - may be required by virtual fs |
||
| 969 | * |
||
| 970 | * @return void |
||
| 971 | * @author Dmitry (dio) Levashov |
||
| 972 | **/ |
||
| 973 | public function umount() { |
||
| 975 | |||
| 976 | /** |
||
| 977 | * Return error message from last failed action |
||
| 978 | * |
||
| 979 | * @return array |
||
| 980 | * @author Dmitry (dio) Levashov |
||
| 981 | **/ |
||
| 982 | public function error() { |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
| 988 | * |
||
| 989 | * @return array |
||
| 990 | * @author Naoki Sawada |
||
| 991 | */ |
||
| 992 | public function getMimeTable() { |
||
| 995 | |||
| 996 | /** |
||
| 997 | * Set mimetypes allowed to display to client |
||
| 998 | * |
||
| 999 | * @param array $mimes |
||
| 1000 | * @return void |
||
| 1001 | * @author Dmitry (dio) Levashov |
||
| 1002 | **/ |
||
| 1003 | public function setMimesFilter($mimes) { |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Return root folder hash |
||
| 1011 | * |
||
| 1012 | * @return string |
||
| 1013 | * @author Dmitry (dio) Levashov |
||
| 1014 | **/ |
||
| 1015 | public function root() { |
||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Return root or startPath hash |
||
| 1021 | * |
||
| 1022 | * @return string |
||
| 1023 | * @author Dmitry (dio) Levashov |
||
| 1024 | **/ |
||
| 1025 | public function defaultPath() { |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * Return volume options required by client: |
||
| 1031 | * |
||
| 1032 | * @return array |
||
| 1033 | * @author Dmitry (dio) Levashov |
||
| 1034 | **/ |
||
| 1035 | public function options($hash) { |
||
| 1059 | |||
| 1060 | /** |
||
| 1061 | * Get plugin values of this options |
||
| 1062 | * |
||
| 1063 | * @param string $name Plugin name |
||
| 1064 | * @return NULL|array Plugin values |
||
| 1065 | * @author Naoki Sawada |
||
| 1066 | */ |
||
| 1067 | public function getOptionsPlugin($name = '') { |
||
| 1074 | |||
| 1075 | /** |
||
| 1076 | * Return true if command disabled in options |
||
| 1077 | * |
||
| 1078 | * @param string $cmd command name |
||
| 1079 | * @return bool |
||
| 1080 | * @author Dmitry (dio) Levashov |
||
| 1081 | **/ |
||
| 1082 | public function commandDisabled($cmd) { |
||
| 1085 | |||
| 1086 | /** |
||
| 1087 | * Return true if mime is required mimes list |
||
| 1088 | * |
||
| 1089 | * @param string $mime mime type to check |
||
| 1090 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
| 1091 | * @param bool|null $empty what to return on empty list |
||
| 1092 | * @return bool|null |
||
| 1093 | * @author Dmitry (dio) Levashov |
||
| 1094 | * @author Troex Nevelin |
||
| 1095 | **/ |
||
| 1096 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Return true if voume is readable. |
||
| 1110 | * |
||
| 1111 | * @return bool |
||
| 1112 | * @author Dmitry (dio) Levashov |
||
| 1113 | **/ |
||
| 1114 | public function isReadable() { |
||
| 1118 | |||
| 1119 | /** |
||
| 1120 | * Return true if copy from this volume allowed |
||
| 1121 | * |
||
| 1122 | * @return bool |
||
| 1123 | * @author Dmitry (dio) Levashov |
||
| 1124 | **/ |
||
| 1125 | public function copyFromAllowed() { |
||
| 1128 | |||
| 1129 | /** |
||
| 1130 | * Return file path related to root with convert encoging |
||
| 1131 | * |
||
| 1132 | * @param string $hash file hash |
||
| 1133 | * @return string |
||
| 1134 | * @author Dmitry (dio) Levashov |
||
| 1135 | **/ |
||
| 1136 | public function path($hash) { |
||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Return file real path if file exists |
||
| 1142 | * |
||
| 1143 | * @param string $hash file hash |
||
| 1144 | * @return string |
||
| 1145 | * @author Dmitry (dio) Levashov |
||
| 1146 | **/ |
||
| 1147 | public function realpath($hash) { |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Return list of moved/overwrited files |
||
| 1154 | * |
||
| 1155 | * @return array |
||
| 1156 | * @author Dmitry (dio) Levashov |
||
| 1157 | **/ |
||
| 1158 | public function removed() { |
||
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Clean removed files list |
||
| 1164 | * |
||
| 1165 | * @return void |
||
| 1166 | * @author Dmitry (dio) Levashov |
||
| 1167 | **/ |
||
| 1168 | public function resetRemoved() { |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Return file/dir hash or first founded child hash with required attr == $val |
||
| 1174 | * |
||
| 1175 | * @param string $hash file hash |
||
| 1176 | * @param string $attr attribute name |
||
| 1177 | * @param bool $val attribute value |
||
| 1178 | * @return string|false |
||
| 1179 | * @author Dmitry (dio) Levashov |
||
| 1180 | **/ |
||
| 1181 | public function closest($hash, $attr, $val) { |
||
| 1184 | |||
| 1185 | /** |
||
| 1186 | * Return file info or false on error |
||
| 1187 | * |
||
| 1188 | * @param string $hash file hash |
||
| 1189 | * @param bool $realpath add realpath field to file info |
||
| 1190 | * @return array|false |
||
| 1191 | * @author Dmitry (dio) Levashov |
||
| 1192 | **/ |
||
| 1193 | public function file($hash) { |
||
| 1205 | |||
| 1206 | /** |
||
| 1207 | * Return folder info |
||
| 1208 | * |
||
| 1209 | * @param string $hash folder hash |
||
| 1210 | * @param bool $hidden return hidden file info |
||
| 1211 | * @return array|false |
||
| 1212 | * @author Dmitry (dio) Levashov |
||
| 1213 | **/ |
||
| 1214 | public function dir($hash, $resolveLink=false) { |
||
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Return directory content or false on error |
||
| 1230 | * |
||
| 1231 | * @param string $hash file hash |
||
| 1232 | * @return array|false |
||
| 1233 | * @author Dmitry (dio) Levashov |
||
| 1234 | **/ |
||
| 1235 | public function scandir($hash) { |
||
| 1244 | |||
| 1245 | /** |
||
| 1246 | * Return dir files names list |
||
| 1247 | * |
||
| 1248 | * @param string $hash file hash |
||
| 1249 | * @return array |
||
| 1250 | * @author Dmitry (dio) Levashov |
||
| 1251 | **/ |
||
| 1252 | public function ls($hash) { |
||
| 1268 | |||
| 1269 | /** |
||
| 1270 | * Return subfolders for required folder or false on error |
||
| 1271 | * |
||
| 1272 | * @param string $hash folder hash or empty string to get tree from root folder |
||
| 1273 | * @param int $deep subdir deep |
||
| 1274 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
| 1275 | * @return array|false |
||
| 1276 | * @author Dmitry (dio) Levashov |
||
| 1277 | **/ |
||
| 1278 | public function tree($hash='', $deep=0, $exclude='') { |
||
| 1289 | |||
| 1290 | /** |
||
| 1291 | * Return part of dirs tree from required dir up to root dir |
||
| 1292 | * |
||
| 1293 | * @param string $hash directory hash |
||
| 1294 | * @param bool|null $lineal only lineal parents |
||
| 1295 | * @return array |
||
| 1296 | * @author Dmitry (dio) Levashov |
||
| 1297 | **/ |
||
| 1298 | public function parents($hash, $lineal = false) { |
||
| 1325 | |||
| 1326 | /** |
||
| 1327 | * Create thumbnail for required file and return its name of false on failed |
||
| 1328 | * |
||
| 1329 | * @return string|false |
||
| 1330 | * @author Dmitry (dio) Levashov |
||
| 1331 | **/ |
||
| 1332 | public function tmb($hash) { |
||
| 1341 | |||
| 1342 | /** |
||
| 1343 | * Return file size / total directory size |
||
| 1344 | * |
||
| 1345 | * @param string file hash |
||
| 1346 | * @return int |
||
| 1347 | * @author Dmitry (dio) Levashov |
||
| 1348 | **/ |
||
| 1349 | public function size($hash) { |
||
| 1352 | |||
| 1353 | /** |
||
| 1354 | * Open file for reading and return file pointer |
||
| 1355 | * |
||
| 1356 | * @param string file hash |
||
| 1357 | * @return Resource |
||
| 1358 | * @author Dmitry (dio) Levashov |
||
| 1359 | **/ |
||
| 1360 | public function open($hash) { |
||
| 1368 | |||
| 1369 | /** |
||
| 1370 | * Close file pointer |
||
| 1371 | * |
||
| 1372 | * @param Resource $fp file pointer |
||
| 1373 | * @param string $hash file hash |
||
| 1374 | * @return void |
||
| 1375 | * @author Dmitry (dio) Levashov |
||
| 1376 | **/ |
||
| 1377 | public function close($fp, $hash) { |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * Create directory and return dir info |
||
| 1383 | * |
||
| 1384 | * @param string $dsthash destination directory hash |
||
| 1385 | * @param string $name directory name |
||
| 1386 | * @return array|false |
||
| 1387 | * @author Dmitry (dio) Levashov |
||
| 1388 | **/ |
||
| 1389 | public function mkdir($dsthash, $name) { |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * Create empty file and return its info |
||
| 1419 | * |
||
| 1420 | * @param string $dst destination directory |
||
| 1421 | * @param string $name file name |
||
| 1422 | * @return array|false |
||
| 1423 | * @author Dmitry (dio) Levashov |
||
| 1424 | **/ |
||
| 1425 | public function mkfile($dst, $name) { |
||
| 1451 | |||
| 1452 | /** |
||
| 1453 | * Rename file and return file info |
||
| 1454 | * |
||
| 1455 | * @param string $hash file hash |
||
| 1456 | * @param string $name new file name |
||
| 1457 | * @return array|false |
||
| 1458 | * @author Dmitry (dio) Levashov |
||
| 1459 | **/ |
||
| 1460 | public function rename($hash, $name) { |
||
| 1506 | |||
| 1507 | /** |
||
| 1508 | * Create file copy with suffix "copy number" and return its info |
||
| 1509 | * |
||
| 1510 | * @param string $hash file hash |
||
| 1511 | * @param string $suffix suffix to add to file name |
||
| 1512 | * @return array|false |
||
| 1513 | * @author Dmitry (dio) Levashov |
||
| 1514 | **/ |
||
| 1515 | public function duplicate($hash, $suffix='copy') { |
||
| 1536 | |||
| 1537 | /** |
||
| 1538 | * Save uploaded file. |
||
| 1539 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
| 1540 | * |
||
| 1541 | * @param Resource $fp file pointer |
||
| 1542 | * @param string $dst destination folder hash |
||
| 1543 | * @param string $src file name |
||
| 1544 | * @param string $tmpname file tmp name - required to detect mime type |
||
| 1545 | * @return array|false |
||
| 1546 | * @author Dmitry (dio) Levashov |
||
| 1547 | **/ |
||
| 1548 | public function upload($fp, $dst, $name, $tmpname) { |
||
| 1624 | |||
| 1625 | /** |
||
| 1626 | * Paste files |
||
| 1627 | * |
||
| 1628 | * @param Object $volume source volume |
||
| 1629 | * @param string $source file hash |
||
| 1630 | * @param string $dst destination dir hash |
||
| 1631 | * @param bool $rmSrc remove source after copy? |
||
| 1632 | * @return array|false |
||
| 1633 | * @author Dmitry (dio) Levashov |
||
| 1634 | **/ |
||
| 1635 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
| 1723 | |||
| 1724 | /** |
||
| 1725 | * Return file contents |
||
| 1726 | * |
||
| 1727 | * @param string $hash file hash |
||
| 1728 | * @return string|false |
||
| 1729 | * @author Dmitry (dio) Levashov |
||
| 1730 | **/ |
||
| 1731 | public function getContents($hash) { |
||
| 1748 | |||
| 1749 | /** |
||
| 1750 | * Put content in text file and return file info. |
||
| 1751 | * |
||
| 1752 | * @param string $hash file hash |
||
| 1753 | * @param string $content new file content |
||
| 1754 | * @return array |
||
| 1755 | * @author Dmitry (dio) Levashov |
||
| 1756 | **/ |
||
| 1757 | public function putContents($hash, $content) { |
||
| 1792 | |||
| 1793 | /** |
||
| 1794 | * Extract files from archive |
||
| 1795 | * |
||
| 1796 | * @param string $hash archive hash |
||
| 1797 | * @return array|bool |
||
| 1798 | * @author Dmitry (dio) Levashov, |
||
| 1799 | * @author Alexey Sukhotin |
||
| 1800 | **/ |
||
| 1801 | public function extract($hash, $makedir = null) { |
||
| 1840 | |||
| 1841 | /** |
||
| 1842 | * Add files to archive |
||
| 1843 | * |
||
| 1844 | * @return void |
||
| 1845 | **/ |
||
| 1846 | public function archive($hashes, $mime, $name = '') { |
||
| 1890 | |||
| 1891 | /** |
||
| 1892 | * Resize image |
||
| 1893 | * |
||
| 1894 | * @param string $hash image file |
||
| 1895 | * @param int $width new width |
||
| 1896 | * @param int $height new height |
||
| 1897 | * @param int $x X start poistion for crop |
||
| 1898 | * @param int $y Y start poistion for crop |
||
| 1899 | * @param string $mode action how to mainpulate image |
||
| 1900 | * @return array|false |
||
| 1901 | * @author Dmitry (dio) Levashov |
||
| 1902 | * @author Alexey Sukhotin |
||
| 1903 | * @author nao-pon |
||
| 1904 | * @author Troex Nevelin |
||
| 1905 | **/ |
||
| 1906 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0) { |
||
| 1993 | |||
| 1994 | /** |
||
| 1995 | * Remove file/dir |
||
| 1996 | * |
||
| 1997 | * @param string $hash file hash |
||
| 1998 | * @return bool |
||
| 1999 | * @author Dmitry (dio) Levashov |
||
| 2000 | **/ |
||
| 2001 | public function rm($hash) { |
||
| 2006 | |||
| 2007 | /** |
||
| 2008 | * Search files |
||
| 2009 | * |
||
| 2010 | * @param string $q search string |
||
| 2011 | * @param array $mimes |
||
| 2012 | * @return array |
||
| 2013 | * @author Dmitry (dio) Levashov |
||
| 2014 | **/ |
||
| 2015 | public function search($q, $mimes, $hash = null) { |
||
| 2034 | |||
| 2035 | /** |
||
| 2036 | * Return image dimensions |
||
| 2037 | * |
||
| 2038 | * @param string $hash file hash |
||
| 2039 | * @return array |
||
| 2040 | * @author Dmitry (dio) Levashov |
||
| 2041 | **/ |
||
| 2042 | public function dimensions($hash) { |
||
| 2049 | |||
| 2050 | /** |
||
| 2051 | * Return content URL (for netmout volume driver) |
||
| 2052 | * If file.url == 1 requests from JavaScript client with XHR |
||
| 2053 | * |
||
| 2054 | * @param string $hash file hash |
||
| 2055 | * @param array $options options array |
||
| 2056 | * @return boolean|string |
||
| 2057 | * @author Naoki Sawada |
||
| 2058 | */ |
||
| 2059 | public function getContentUrl($hash, $options = array()) { |
||
| 2065 | |||
| 2066 | /** |
||
| 2067 | * Return temp path |
||
| 2068 | * |
||
| 2069 | * @return string |
||
| 2070 | * @author Naoki Sawada |
||
| 2071 | */ |
||
| 2072 | public function getTempPath() { |
||
| 2085 | |||
| 2086 | /** |
||
| 2087 | * (Make &) Get upload taget dirctory hash |
||
| 2088 | * |
||
| 2089 | * @param string $baseTargetHash |
||
| 2090 | * @param string $path |
||
| 2091 | * @param array $result |
||
| 2092 | * @return boolean|string |
||
| 2093 | * @author Naoki Sawada |
||
| 2094 | */ |
||
| 2095 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
| 2122 | |||
| 2123 | /** |
||
| 2124 | * Return this uploadMaxSize value |
||
| 2125 | * |
||
| 2126 | * @return integer |
||
| 2127 | * @author Naoki Sawada |
||
| 2128 | */ |
||
| 2129 | public function getUploadMaxSize() { |
||
| 2132 | |||
| 2133 | /** |
||
| 2134 | * Save error message |
||
| 2135 | * |
||
| 2136 | * @param array error |
||
| 2137 | * @return false |
||
| 2138 | * @author Dmitry(dio) Levashov |
||
| 2139 | **/ |
||
| 2140 | protected function setError($error) { |
||
| 2155 | |||
| 2156 | /*********************************************************************/ |
||
| 2157 | /* FS API */ |
||
| 2158 | /*********************************************************************/ |
||
| 2159 | |||
| 2160 | /***************** server encoding support *******************/ |
||
| 2161 | |||
| 2162 | /** |
||
| 2163 | * Return parent directory path (with convert encording) |
||
| 2164 | * |
||
| 2165 | * @param string $path file path |
||
| 2166 | * @return string |
||
| 2167 | * @author Naoki Sawada |
||
| 2168 | **/ |
||
| 2169 | protected function dirnameCE($path) { |
||
| 2172 | |||
| 2173 | /** |
||
| 2174 | * Return file name (with convert encording) |
||
| 2175 | * |
||
| 2176 | * @param string $path file path |
||
| 2177 | * @return string |
||
| 2178 | * @author Naoki Sawada |
||
| 2179 | **/ |
||
| 2180 | protected function basenameCE($path) { |
||
| 2183 | |||
| 2184 | /** |
||
| 2185 | * Join dir name and file name and return full path. (with convert encording) |
||
| 2186 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 2187 | * |
||
| 2188 | * @param string $dir dir path |
||
| 2189 | * @param string $name file name |
||
| 2190 | * @return string |
||
| 2191 | * @author Naoki Sawada |
||
| 2192 | **/ |
||
| 2193 | protected function joinPathCE($dir, $name) { |
||
| 2196 | |||
| 2197 | /** |
||
| 2198 | * Return normalized path (with convert encording) |
||
| 2199 | * |
||
| 2200 | * @param string $path file path |
||
| 2201 | * @return string |
||
| 2202 | * @author Naoki Sawada |
||
| 2203 | **/ |
||
| 2204 | protected function normpathCE($path) { |
||
| 2207 | |||
| 2208 | /** |
||
| 2209 | * Return file path related to root dir (with convert encording) |
||
| 2210 | * |
||
| 2211 | * @param string $path file path |
||
| 2212 | * @return string |
||
| 2213 | * @author Naoki Sawada |
||
| 2214 | **/ |
||
| 2215 | protected function relpathCE($path) { |
||
| 2218 | |||
| 2219 | /** |
||
| 2220 | * Convert path related to root dir into real path (with convert encording) |
||
| 2221 | * |
||
| 2222 | * @param string $path rel file path |
||
| 2223 | * @return string |
||
| 2224 | * @author Naoki Sawada |
||
| 2225 | **/ |
||
| 2226 | protected function abspathCE($path) { |
||
| 2229 | |||
| 2230 | /** |
||
| 2231 | * Return true if $path is children of $parent (with convert encording) |
||
| 2232 | * |
||
| 2233 | * @param string $path path to check |
||
| 2234 | * @param string $parent parent path |
||
| 2235 | * @return bool |
||
| 2236 | * @author Naoki Sawada |
||
| 2237 | **/ |
||
| 2238 | protected function inpathCE($path, $parent) { |
||
| 2241 | |||
| 2242 | /** |
||
| 2243 | * Open file and return file pointer (with convert encording) |
||
| 2244 | * |
||
| 2245 | * @param string $path file path |
||
| 2246 | * @param bool $write open file for writing |
||
| 2247 | * @return resource|false |
||
| 2248 | * @author Naoki Sawada |
||
| 2249 | **/ |
||
| 2250 | protected function fopenCE($path, $mode='rb') { |
||
| 2253 | |||
| 2254 | /** |
||
| 2255 | * Close opened file (with convert encording) |
||
| 2256 | * |
||
| 2257 | * @param resource $fp file pointer |
||
| 2258 | * @param string $path file path |
||
| 2259 | * @return bool |
||
| 2260 | * @author Naoki Sawada |
||
| 2261 | **/ |
||
| 2262 | protected function fcloseCE($fp, $path='') { |
||
| 2265 | |||
| 2266 | /** |
||
| 2267 | * Create new file and write into it from file pointer. (with convert encording) |
||
| 2268 | * Return new file path or false on error. |
||
| 2269 | * |
||
| 2270 | * @param resource $fp file pointer |
||
| 2271 | * @param string $dir target dir path |
||
| 2272 | * @param string $name file name |
||
| 2273 | * @param array $stat file stat (required by some virtual fs) |
||
| 2274 | * @return bool|string |
||
| 2275 | * @author Naoki Sawada |
||
| 2276 | **/ |
||
| 2277 | protected function saveCE($fp, $dir, $name, $stat) { |
||
| 2280 | |||
| 2281 | /** |
||
| 2282 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
| 2283 | * |
||
| 2284 | * @param string $path dir path |
||
| 2285 | * @return bool |
||
| 2286 | * @author Naoki Sawada |
||
| 2287 | **/ |
||
| 2288 | protected function subdirsCE($path) { |
||
| 2294 | |||
| 2295 | /** |
||
| 2296 | * Return files list in directory (with convert encording) |
||
| 2297 | * |
||
| 2298 | * @param string $path dir path |
||
| 2299 | * @return array |
||
| 2300 | * @author Naoki Sawada |
||
| 2301 | **/ |
||
| 2302 | protected function scandirCE($path) { |
||
| 2305 | |||
| 2306 | /** |
||
| 2307 | * Create symlink (with convert encording) |
||
| 2308 | * |
||
| 2309 | * @param string $source file to link to |
||
| 2310 | * @param string $targetDir folder to create link in |
||
| 2311 | * @param string $name symlink name |
||
| 2312 | * @return bool |
||
| 2313 | * @author Naoki Sawada |
||
| 2314 | **/ |
||
| 2315 | protected function symlinkCE($source, $targetDir, $name) { |
||
| 2318 | |||
| 2319 | /***************** paths *******************/ |
||
| 2320 | |||
| 2321 | /** |
||
| 2322 | * Encode path into hash |
||
| 2323 | * |
||
| 2324 | * @param string file path |
||
| 2325 | * @return string |
||
| 2326 | * @author Dmitry (dio) Levashov |
||
| 2327 | * @author Troex Nevelin |
||
| 2328 | **/ |
||
| 2329 | protected function encode($path) { |
||
| 2350 | |||
| 2351 | /** |
||
| 2352 | * Decode path from hash |
||
| 2353 | * |
||
| 2354 | * @param string file hash |
||
| 2355 | * @return string |
||
| 2356 | * @author Dmitry (dio) Levashov |
||
| 2357 | * @author Troex Nevelin |
||
| 2358 | **/ |
||
| 2359 | protected function decode($hash) { |
||
| 2371 | |||
| 2372 | /** |
||
| 2373 | * Return crypted path |
||
| 2374 | * Not implemented |
||
| 2375 | * |
||
| 2376 | * @param string path |
||
| 2377 | * @return mixed |
||
| 2378 | * @author Dmitry (dio) Levashov |
||
| 2379 | **/ |
||
| 2380 | protected function crypt($path) { |
||
| 2383 | |||
| 2384 | /** |
||
| 2385 | * Return uncrypted path |
||
| 2386 | * Not implemented |
||
| 2387 | * |
||
| 2388 | * @param mixed hash |
||
| 2389 | * @return mixed |
||
| 2390 | * @author Dmitry (dio) Levashov |
||
| 2391 | **/ |
||
| 2392 | protected function uncrypt($hash) { |
||
| 2395 | |||
| 2396 | /** |
||
| 2397 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
| 2398 | * |
||
| 2399 | * @param string $name file name |
||
| 2400 | * @return bool |
||
| 2401 | * @author Dmitry (dio) Levashov |
||
| 2402 | **/ |
||
| 2403 | protected function nameAccepted($name) { |
||
| 2415 | |||
| 2416 | /** |
||
| 2417 | * Return new unique name based on file name and suffix |
||
| 2418 | * |
||
| 2419 | * @param string $path file path |
||
| 2420 | * @param string $suffix suffix append to name |
||
| 2421 | * @return string |
||
| 2422 | * @author Dmitry (dio) Levashov |
||
| 2423 | **/ |
||
| 2424 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum=true) { |
||
| 2452 | |||
| 2453 | /** |
||
| 2454 | * Converts character encoding from UTF-8 to server's one |
||
| 2455 | * |
||
| 2456 | * @param mixed $var target string or array var |
||
| 2457 | * @param bool $restoreLocale do retore global locale, default is false |
||
| 2458 | * @param string $unknown replaces character for unknown |
||
| 2459 | * @return mixed |
||
| 2460 | * @author Naoki Sawada |
||
| 2461 | */ |
||
| 2462 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
| 2465 | |||
| 2466 | /** |
||
| 2467 | * Converts character encoding from server's one to UTF-8 |
||
| 2468 | * |
||
| 2469 | * @param mixed $var target string or array var |
||
| 2470 | * @param bool $restoreLocale do retore global locale, default is true |
||
| 2471 | * @param string $unknown replaces character for unknown |
||
| 2472 | * @return mixed |
||
| 2473 | * @author Naoki Sawada |
||
| 2474 | */ |
||
| 2475 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
| 2478 | |||
| 2479 | /** |
||
| 2480 | * Converts character encoding (base function) |
||
| 2481 | * |
||
| 2482 | * @param mixed $var target string or array var |
||
| 2483 | * @param string $from from character encoding |
||
| 2484 | * @param string $to to character encoding |
||
| 2485 | * @param string $locale local locale |
||
| 2486 | * @param string $unknown replaces character for unknown |
||
| 2487 | * @return mixed |
||
| 2488 | */ |
||
| 2489 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
| 2518 | |||
| 2519 | /*********************** util mainly for inheritance class *********************/ |
||
| 2520 | |||
| 2521 | /** |
||
| 2522 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
| 2523 | * When needing the unique file to a path, give $path to parameter. |
||
| 2524 | * |
||
| 2525 | * @param string $path for get unique file to a path |
||
| 2526 | * @return string|false |
||
| 2527 | * @author Naoki Sawada |
||
| 2528 | */ |
||
| 2529 | protected function getTempFile($path = '') { |
||
| 2555 | |||
| 2556 | /** |
||
| 2557 | * File path of local server side work file path |
||
| 2558 | * |
||
| 2559 | * @param string $path path need convert encoding to server encoding |
||
| 2560 | * @return string |
||
| 2561 | * @author Naoki Sawada |
||
| 2562 | */ |
||
| 2563 | protected function getWorkFile($path) { |
||
| 2578 | |||
| 2579 | /** |
||
| 2580 | * Get image size array with `dimensions` |
||
| 2581 | * |
||
| 2582 | * @param string $path path need convert encoding to server encoding |
||
| 2583 | * @param string $mime file mime type |
||
| 2584 | * @return array|false |
||
| 2585 | */ |
||
| 2586 | public function getImageSize($path, $mime = '') { |
||
| 2598 | |||
| 2599 | /** |
||
| 2600 | * Delete dirctory trees |
||
| 2601 | * |
||
| 2602 | * @param string $localpath path need convert encoding to server encoding |
||
| 2603 | * @return boolean |
||
| 2604 | * @author Naoki Sawada |
||
| 2605 | */ |
||
| 2606 | protected function delTree($localpath) { |
||
| 2615 | |||
| 2616 | /*********************** file stat *********************/ |
||
| 2617 | |||
| 2618 | /** |
||
| 2619 | * Check file attribute |
||
| 2620 | * |
||
| 2621 | * @param string $path file path |
||
| 2622 | * @param string $name attribute name (read|write|locked|hidden) |
||
| 2623 | * @param bool $val attribute value returned by file system |
||
| 2624 | * @param bool $isDir path is directory (true: directory, false: file) |
||
| 2625 | * @return bool |
||
| 2626 | * @author Dmitry (dio) Levashov |
||
| 2627 | **/ |
||
| 2628 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
| 2662 | |||
| 2663 | /** |
||
| 2664 | * Return true if file with given name can be created in given folder. |
||
| 2665 | * |
||
| 2666 | * @param string $dir parent dir path |
||
| 2667 | * @param string $name new file name |
||
| 2668 | * @return bool |
||
| 2669 | * @author Dmitry (dio) Levashov |
||
| 2670 | **/ |
||
| 2671 | protected function allowCreate($dir, $name, $isDir = null) { |
||
| 2694 | |||
| 2695 | /** |
||
| 2696 | * Return true if file MIME type can save with check uploadOrder config. |
||
| 2697 | * |
||
| 2698 | * @param string $mime |
||
| 2699 | * @return boolean |
||
| 2700 | */ |
||
| 2701 | protected function allowPutMime($mime) { |
||
| 2719 | |||
| 2720 | /** |
||
| 2721 | * Return fileinfo |
||
| 2722 | * |
||
| 2723 | * @param string $path file cache |
||
| 2724 | * @return array |
||
| 2725 | * @author Dmitry (dio) Levashov |
||
| 2726 | **/ |
||
| 2727 | protected function stat($path) { |
||
| 2752 | |||
| 2753 | /** |
||
| 2754 | * Put file stat in cache and return it |
||
| 2755 | * |
||
| 2756 | * @param string $path file path |
||
| 2757 | * @param array $stat file stat |
||
| 2758 | * @return array |
||
| 2759 | * @author Dmitry (dio) Levashov |
||
| 2760 | **/ |
||
| 2761 | protected function updateCache($path, $stat) { |
||
| 2900 | |||
| 2901 | /** |
||
| 2902 | * Get stat for folder content and put in cache |
||
| 2903 | * |
||
| 2904 | * @param string $path |
||
| 2905 | * @return void |
||
| 2906 | * @author Dmitry (dio) Levashov |
||
| 2907 | **/ |
||
| 2908 | protected function cacheDir($path) { |
||
| 2921 | |||
| 2922 | /** |
||
| 2923 | * Clean cache |
||
| 2924 | * |
||
| 2925 | * @return void |
||
| 2926 | * @author Dmitry (dio) Levashov |
||
| 2927 | **/ |
||
| 2928 | protected function clearcache() { |
||
| 2931 | |||
| 2932 | /** |
||
| 2933 | * Return file mimetype |
||
| 2934 | * |
||
| 2935 | * @param string $path file path |
||
| 2936 | * @return string |
||
| 2937 | * @author Dmitry (dio) Levashov |
||
| 2938 | **/ |
||
| 2939 | protected function mimetype($path, $name = '') { |
||
| 2984 | |||
| 2985 | /** |
||
| 2986 | * Detect file mimetype using "internal" method |
||
| 2987 | * |
||
| 2988 | * @param string $path file path |
||
| 2989 | * @return string |
||
| 2990 | * @author Dmitry (dio) Levashov |
||
| 2991 | **/ |
||
| 2992 | static protected function mimetypeInternalDetect($path) { |
||
| 2998 | |||
| 2999 | /** |
||
| 3000 | * Return file/total directory size |
||
| 3001 | * |
||
| 3002 | * @param string $path file path |
||
| 3003 | * @return int |
||
| 3004 | * @author Dmitry (dio) Levashov |
||
| 3005 | **/ |
||
| 3006 | protected function countSize($path) { |
||
| 3031 | |||
| 3032 | /** |
||
| 3033 | * Return true if all mimes is directory or files |
||
| 3034 | * |
||
| 3035 | * @param string $mime1 mimetype |
||
| 3036 | * @param string $mime2 mimetype |
||
| 3037 | * @return bool |
||
| 3038 | * @author Dmitry (dio) Levashov |
||
| 3039 | **/ |
||
| 3040 | protected function isSameType($mime1, $mime2) { |
||
| 3043 | |||
| 3044 | /** |
||
| 3045 | * If file has required attr == $val - return file path, |
||
| 3046 | * If dir has child with has required attr == $val - return child path |
||
| 3047 | * |
||
| 3048 | * @param string $path file path |
||
| 3049 | * @param string $attr attribute name |
||
| 3050 | * @param bool $val attribute value |
||
| 3051 | * @return string|false |
||
| 3052 | * @author Dmitry (dio) Levashov |
||
| 3053 | **/ |
||
| 3054 | protected function closestByAttr($path, $attr, $val) { |
||
| 3071 | |||
| 3072 | /** |
||
| 3073 | * Return first found children with required attr == $val |
||
| 3074 | * |
||
| 3075 | * @param string $path file path |
||
| 3076 | * @param string $attr attribute name |
||
| 3077 | * @param bool $val attribute value |
||
| 3078 | * @return string|false |
||
| 3079 | * @author Dmitry (dio) Levashov |
||
| 3080 | **/ |
||
| 3081 | protected function childsByAttr($path, $attr, $val) { |
||
| 3089 | |||
| 3090 | /***************** get content *******************/ |
||
| 3091 | |||
| 3092 | /** |
||
| 3093 | * Return required dir's files info. |
||
| 3094 | * If onlyMimes is set - return only dirs and files of required mimes |
||
| 3095 | * |
||
| 3096 | * @param string $path dir path |
||
| 3097 | * @return array |
||
| 3098 | * @author Dmitry (dio) Levashov |
||
| 3099 | **/ |
||
| 3100 | protected function getScandir($path) { |
||
| 3113 | |||
| 3114 | |||
| 3115 | /** |
||
| 3116 | * Return subdirs tree |
||
| 3117 | * |
||
| 3118 | * @param string $path parent dir path |
||
| 3119 | * @param int $deep tree deep |
||
| 3120 | * @return array |
||
| 3121 | * @author Dmitry (dio) Levashov |
||
| 3122 | **/ |
||
| 3123 | protected function gettree($path, $deep, $exclude='') { |
||
| 3141 | |||
| 3142 | /** |
||
| 3143 | * Recursive files search |
||
| 3144 | * |
||
| 3145 | * @param string $path dir path |
||
| 3146 | * @param string $q search string |
||
| 3147 | * @param array $mimes |
||
| 3148 | * @return array |
||
| 3149 | * @author Dmitry (dio) Levashov |
||
| 3150 | **/ |
||
| 3151 | protected function doSearch($path, $q, $mimes) { |
||
| 3187 | |||
| 3188 | /********************** manuipulations ******************/ |
||
| 3189 | |||
| 3190 | /** |
||
| 3191 | * Copy file/recursive copy dir only in current volume. |
||
| 3192 | * Return new file path or false. |
||
| 3193 | * |
||
| 3194 | * @param string $src source path |
||
| 3195 | * @param string $dst destination dir path |
||
| 3196 | * @param string $name new file name (optionaly) |
||
| 3197 | * @return string|false |
||
| 3198 | * @author Dmitry (dio) Levashov |
||
| 3199 | **/ |
||
| 3200 | protected function copy($src, $dst, $name) { |
||
| 3242 | |||
| 3243 | /** |
||
| 3244 | * Move file |
||
| 3245 | * Return new file path or false. |
||
| 3246 | * |
||
| 3247 | * @param string $src source path |
||
| 3248 | * @param string $dst destination dir path |
||
| 3249 | * @param string $name new file name |
||
| 3250 | * @return string|false |
||
| 3251 | * @author Dmitry (dio) Levashov |
||
| 3252 | **/ |
||
| 3253 | protected function move($src, $dst, $name) { |
||
| 3267 | |||
| 3268 | /** |
||
| 3269 | * Copy file from another volume. |
||
| 3270 | * Return new file path or false. |
||
| 3271 | * |
||
| 3272 | * @param Object $volume source volume |
||
| 3273 | * @param string $src source file hash |
||
| 3274 | * @param string $destination destination dir path |
||
| 3275 | * @param string $name file name |
||
| 3276 | * @return string|false |
||
| 3277 | * @author Dmitry (dio) Levashov |
||
| 3278 | **/ |
||
| 3279 | protected function copyFrom($volume, $src, $destination, $name) { |
||
| 3337 | |||
| 3338 | /** |
||
| 3339 | * Remove file/ recursive remove dir |
||
| 3340 | * |
||
| 3341 | * @param string $path file path |
||
| 3342 | * @param bool $force try to remove even if file locked |
||
| 3343 | * @return bool |
||
| 3344 | * @author Dmitry (dio) Levashov |
||
| 3345 | **/ |
||
| 3346 | protected function remove($path, $force = false) { |
||
| 3376 | |||
| 3377 | |||
| 3378 | /************************* thumbnails **************************/ |
||
| 3379 | |||
| 3380 | /** |
||
| 3381 | * Return thumbnail file name for required file |
||
| 3382 | * |
||
| 3383 | * @param array $stat file stat |
||
| 3384 | * @return string |
||
| 3385 | * @author Dmitry (dio) Levashov |
||
| 3386 | **/ |
||
| 3387 | protected function tmbname($stat) { |
||
| 3390 | |||
| 3391 | /** |
||
| 3392 | * Return thumnbnail name if exists |
||
| 3393 | * |
||
| 3394 | * @param string $path file path |
||
| 3395 | * @param array $stat file stat |
||
| 3396 | * @return string|false |
||
| 3397 | * @author Dmitry (dio) Levashov |
||
| 3398 | **/ |
||
| 3399 | protected function gettmb($path, $stat) { |
||
| 3413 | |||
| 3414 | /** |
||
| 3415 | * Return true if thumnbnail for required file can be created |
||
| 3416 | * |
||
| 3417 | * @param string $path thumnbnail path |
||
| 3418 | * @param array $stat file stat |
||
| 3419 | * @param bool $checkTmbPath |
||
| 3420 | * @return string|bool |
||
| 3421 | * @author Dmitry (dio) Levashov |
||
| 3422 | **/ |
||
| 3423 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
| 3430 | |||
| 3431 | /** |
||
| 3432 | * Return true if required file can be resized. |
||
| 3433 | * By default - the same as canCreateTmb |
||
| 3434 | * |
||
| 3435 | * @param string $path thumnbnail path |
||
| 3436 | * @param array $stat file stat |
||
| 3437 | * @return string|bool |
||
| 3438 | * @author Dmitry (dio) Levashov |
||
| 3439 | **/ |
||
| 3440 | protected function canResize($path, $stat) { |
||
| 3443 | |||
| 3444 | /** |
||
| 3445 | * Create thumnbnail and return it's URL on success |
||
| 3446 | * |
||
| 3447 | * @param string $path file path |
||
| 3448 | * @param string $mime file mime type |
||
| 3449 | * @return string|false |
||
| 3450 | * @author Dmitry (dio) Levashov |
||
| 3451 | **/ |
||
| 3452 | protected function createTmb($path, $stat) { |
||
| 3522 | |||
| 3523 | /** |
||
| 3524 | * Resize image |
||
| 3525 | * |
||
| 3526 | * @param string $path image file |
||
| 3527 | * @param int $width new width |
||
| 3528 | * @param int $height new height |
||
| 3529 | * @param bool $keepProportions crop image |
||
| 3530 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
| 3531 | * @param string $destformat image destination format |
||
| 3532 | * @return string|false |
||
| 3533 | * @author Dmitry (dio) Levashov |
||
| 3534 | * @author Alexey Sukhotin |
||
| 3535 | **/ |
||
| 3536 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null) { |
||
| 3629 | |||
| 3630 | /** |
||
| 3631 | * Crop image |
||
| 3632 | * |
||
| 3633 | * @param string $path image file |
||
| 3634 | * @param int $width crop width |
||
| 3635 | * @param int $height crop height |
||
| 3636 | * @param bool $x crop left offset |
||
| 3637 | * @param bool $y crop top offset |
||
| 3638 | * @param string $destformat image destination format |
||
| 3639 | * @return string|false |
||
| 3640 | * @author Dmitry (dio) Levashov |
||
| 3641 | * @author Alexey Sukhotin |
||
| 3642 | **/ |
||
| 3643 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null) { |
||
| 3717 | |||
| 3718 | /** |
||
| 3719 | * Put image to square |
||
| 3720 | * |
||
| 3721 | * @param string $path image file |
||
| 3722 | * @param int $width square width |
||
| 3723 | * @param int $height square height |
||
| 3724 | * @param int $align reserved |
||
| 3725 | * @param int $valign reserved |
||
| 3726 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3727 | * @param string $destformat image destination format |
||
| 3728 | * @return string|false |
||
| 3729 | * @author Dmitry (dio) Levashov |
||
| 3730 | * @author Alexey Sukhotin |
||
| 3731 | **/ |
||
| 3732 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null) { |
||
| 3810 | |||
| 3811 | /** |
||
| 3812 | * Rotate image |
||
| 3813 | * |
||
| 3814 | * @param string $path image file |
||
| 3815 | * @param int $degree rotete degrees |
||
| 3816 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3817 | * @param string $destformat image destination format |
||
| 3818 | * @return string|false |
||
| 3819 | * @author nao-pon |
||
| 3820 | * @author Troex Nevelin |
||
| 3821 | **/ |
||
| 3822 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null) { |
||
| 3902 | |||
| 3903 | /** |
||
| 3904 | * Execute shell command |
||
| 3905 | * |
||
| 3906 | * @param string $command command line |
||
| 3907 | * @param array $output stdout strings |
||
| 3908 | * @param array $return_var process exit code |
||
| 3909 | * @param array $error_output stderr strings |
||
| 3910 | * @return int exit code |
||
| 3911 | * @author Alexey Sukhotin |
||
| 3912 | **/ |
||
| 3913 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
| 3943 | |||
| 3944 | /** |
||
| 3945 | * Remove thumbnail, also remove recursively if stat is directory |
||
| 3946 | * |
||
| 3947 | * @param string $stat file stat |
||
| 3948 | * @return void |
||
| 3949 | * @author Dmitry (dio) Levashov |
||
| 3950 | * @author Naoki Sawada |
||
| 3951 | * @author Troex Nevelin |
||
| 3952 | **/ |
||
| 3953 | protected function rmTmb($stat) { |
||
| 3966 | |||
| 3967 | /** |
||
| 3968 | * Create an gd image according to the specified mime type |
||
| 3969 | * |
||
| 3970 | * @param string $path image file |
||
| 3971 | * @param string $mime |
||
| 3972 | * @return gd image resource identifier |
||
| 3973 | */ |
||
| 3974 | protected function gdImageCreate($path,$mime){ |
||
| 3990 | |||
| 3991 | /** |
||
| 3992 | * Output gd image to file |
||
| 3993 | * |
||
| 3994 | * @param resource $image gd image resource |
||
| 3995 | * @param string $filename The path to save the file to. |
||
| 3996 | * @param string $destformat The Image type to use for $filename |
||
| 3997 | * @param string $mime The original image mime type |
||
| 3998 | */ |
||
| 3999 | protected function gdImage($image, $filename, $destformat, $mime ){ |
||
| 4011 | |||
| 4012 | /** |
||
| 4013 | * Assign the proper background to a gd image |
||
| 4014 | * |
||
| 4015 | * @param resource $image gd image resource |
||
| 4016 | * @param string $bgcolor background color in #rrggbb format |
||
| 4017 | */ |
||
| 4018 | protected function gdImageBackground($image, $bgcolor){ |
||
| 4031 | |||
| 4032 | /*********************** misc *************************/ |
||
| 4033 | |||
| 4034 | /** |
||
| 4035 | * Return smart formatted date |
||
| 4036 | * |
||
| 4037 | * @param int $ts file timestamp |
||
| 4038 | * @return string |
||
| 4039 | * @author Dmitry (dio) Levashov |
||
| 4040 | **/ |
||
| 4041 | // protected function formatDate($ts) { |
||
| 4042 | // if ($ts > $this->today) { |
||
| 4043 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
| 4044 | // } |
||
| 4045 | // |
||
| 4046 | // if ($ts > $this->yesterday) { |
||
| 4047 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
| 4048 | // } |
||
| 4049 | // |
||
| 4050 | // return date($this->options['dateFormat'], $ts); |
||
| 4051 | // } |
||
| 4052 | |||
| 4053 | /** |
||
| 4054 | * Find position of first occurrence of string in a string with multibyte support |
||
| 4055 | * |
||
| 4056 | * @param string $haystack The string being checked. |
||
| 4057 | * @param string $needle The string to find in haystack. |
||
| 4058 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
| 4059 | * @return int|bool |
||
| 4060 | * @author Alexey Sukhotin |
||
| 4061 | **/ |
||
| 4062 | protected function stripos($haystack , $needle , $offset = 0) { |
||
| 4070 | |||
| 4071 | /** |
||
| 4072 | * Get server side available archivers |
||
| 4073 | * |
||
| 4074 | * @param bool $use_cache |
||
| 4075 | * @return array |
||
| 4076 | */ |
||
| 4077 | protected function getArchivers($use_cache = true) { |
||
| 4193 | |||
| 4194 | /** |
||
| 4195 | * Resolve relative / (Unix-like)absolute path |
||
| 4196 | * |
||
| 4197 | * @param string $path target path |
||
| 4198 | * @param string $base base path |
||
| 4199 | * @return string |
||
| 4200 | */ |
||
| 4201 | protected function getFullPath($path, $base) { |
||
| 4248 | |||
| 4249 | /** |
||
| 4250 | * Remove directory recursive on local file system |
||
| 4251 | * |
||
| 4252 | * @param string $dir Target dirctory path |
||
| 4253 | * @return boolean |
||
| 4254 | * @author Naoki Sawada |
||
| 4255 | */ |
||
| 4256 | public function rmdirRecursive($dir) { |
||
| 4276 | |||
| 4277 | /** |
||
| 4278 | * Create archive and return its path |
||
| 4279 | * |
||
| 4280 | * @param string $dir target dir |
||
| 4281 | * @param array $files files names list |
||
| 4282 | * @param string $name archive name |
||
| 4283 | * @param array $arc archiver options |
||
| 4284 | * @return string|bool |
||
| 4285 | * @author Dmitry (dio) Levashov, |
||
| 4286 | * @author Alexey Sukhotin |
||
| 4287 | * @author Naoki Sawada |
||
| 4288 | **/ |
||
| 4289 | protected function makeArchive($dir, $files, $name, $arc) { |
||
| 4307 | |||
| 4308 | /** |
||
| 4309 | * Unpack archive |
||
| 4310 | * |
||
| 4311 | * @param string $path archive path |
||
| 4312 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
| 4313 | * @param bool $remove remove archive ( unlink($path) ) |
||
| 4314 | * @return void |
||
| 4315 | * @author Dmitry (dio) Levashov |
||
| 4316 | * @author Alexey Sukhotin |
||
| 4317 | * @author Naoki Sawada |
||
| 4318 | **/ |
||
| 4319 | protected function unpackArchive($path, $arc, $remove = true) { |
||
| 4334 | |||
| 4335 | /** |
||
| 4336 | * Create Zip archive using PHP class ZipArchive |
||
| 4337 | * |
||
| 4338 | * @param string $dir target dir |
||
| 4339 | * @param array $files files names list |
||
| 4340 | * @param string|object $zipPath Zip archive name |
||
| 4341 | * @return void |
||
| 4342 | * @author Naoki Sawada |
||
| 4343 | */ |
||
| 4344 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
| 4382 | |||
| 4383 | /** |
||
| 4384 | * Unpack Zip archive using PHP class ZipArchive |
||
| 4385 | * |
||
| 4386 | * @param string $zipPath Zip archive name |
||
| 4387 | * @param string $toDir Extract to path |
||
| 4388 | * @return bool |
||
| 4389 | * @author Naoki Sawada |
||
| 4390 | */ |
||
| 4391 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
| 4403 | |||
| 4404 | /**==================================* abstract methods *====================================**/ |
||
| 4405 | |||
| 4406 | /*********************** paths/urls *************************/ |
||
| 4407 | |||
| 4408 | /** |
||
| 4409 | * Return parent directory path |
||
| 4410 | * |
||
| 4411 | * @param string $path file path |
||
| 4412 | * @return string |
||
| 4413 | * @author Dmitry (dio) Levashov |
||
| 4414 | **/ |
||
| 4415 | abstract protected function _dirname($path); |
||
| 4416 | |||
| 4417 | /** |
||
| 4418 | * Return file name |
||
| 4419 | * |
||
| 4420 | * @param string $path file path |
||
| 4421 | * @return string |
||
| 4422 | * @author Dmitry (dio) Levashov |
||
| 4423 | **/ |
||
| 4424 | abstract protected function _basename($path); |
||
| 4425 | |||
| 4426 | /** |
||
| 4427 | * Join dir name and file name and return full path. |
||
| 4428 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 4429 | * |
||
| 4430 | * @param string $dir dir path |
||
| 4431 | * @param string $name file name |
||
| 4432 | * @return string |
||
| 4433 | * @author Dmitry (dio) Levashov |
||
| 4434 | **/ |
||
| 4435 | abstract protected function _joinPath($dir, $name); |
||
| 4436 | |||
| 4437 | /** |
||
| 4438 | * Return normalized path |
||
| 4439 | * |
||
| 4440 | * @param string $path file path |
||
| 4441 | * @return string |
||
| 4442 | * @author Dmitry (dio) Levashov |
||
| 4443 | **/ |
||
| 4444 | abstract protected function _normpath($path); |
||
| 4445 | |||
| 4446 | /** |
||
| 4447 | * Return file path related to root dir |
||
| 4448 | * |
||
| 4449 | * @param string $path file path |
||
| 4450 | * @return string |
||
| 4451 | * @author Dmitry (dio) Levashov |
||
| 4452 | **/ |
||
| 4453 | abstract protected function _relpath($path); |
||
| 4454 | |||
| 4455 | /** |
||
| 4456 | * Convert path related to root dir into real path |
||
| 4457 | * |
||
| 4458 | * @param string $path rel file path |
||
| 4459 | * @return string |
||
| 4460 | * @author Dmitry (dio) Levashov |
||
| 4461 | **/ |
||
| 4462 | abstract protected function _abspath($path); |
||
| 4463 | |||
| 4464 | /** |
||
| 4465 | * Return fake path started from root dir. |
||
| 4466 | * Required to show path on client side. |
||
| 4467 | * |
||
| 4468 | * @param string $path file path |
||
| 4469 | * @return string |
||
| 4470 | * @author Dmitry (dio) Levashov |
||
| 4471 | **/ |
||
| 4472 | abstract protected function _path($path); |
||
| 4473 | |||
| 4474 | /** |
||
| 4475 | * Return true if $path is children of $parent |
||
| 4476 | * |
||
| 4477 | * @param string $path path to check |
||
| 4478 | * @param string $parent parent path |
||
| 4479 | * @return bool |
||
| 4480 | * @author Dmitry (dio) Levashov |
||
| 4481 | **/ |
||
| 4482 | abstract protected function _inpath($path, $parent); |
||
| 4483 | |||
| 4484 | /** |
||
| 4485 | * Return stat for given path. |
||
| 4486 | * Stat contains following fields: |
||
| 4487 | * - (int) size file size in b. required |
||
| 4488 | * - (int) ts file modification time in unix time. required |
||
| 4489 | * - (string) mime mimetype. required for folders, others - optionally |
||
| 4490 | * - (bool) read read permissions. required |
||
| 4491 | * - (bool) write write permissions. required |
||
| 4492 | * - (bool) locked is object locked. optionally |
||
| 4493 | * - (bool) hidden is object hidden. optionally |
||
| 4494 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
| 4495 | * - (string) target for symlinks - link target path. optionally |
||
| 4496 | * |
||
| 4497 | * If file does not exists - returns empty array or false. |
||
| 4498 | * |
||
| 4499 | * @param string $path file path |
||
| 4500 | * @return array|false |
||
| 4501 | * @author Dmitry (dio) Levashov |
||
| 4502 | **/ |
||
| 4503 | abstract protected function _stat($path); |
||
| 4504 | |||
| 4505 | |||
| 4506 | /***************** file stat ********************/ |
||
| 4507 | |||
| 4508 | |||
| 4509 | /** |
||
| 4510 | * Return true if path is dir and has at least one childs directory |
||
| 4511 | * |
||
| 4512 | * @param string $path dir path |
||
| 4513 | * @return bool |
||
| 4514 | * @author Dmitry (dio) Levashov |
||
| 4515 | **/ |
||
| 4516 | abstract protected function _subdirs($path); |
||
| 4517 | |||
| 4518 | /** |
||
| 4519 | * Return object width and height |
||
| 4520 | * Ususaly used for images, but can be realize for video etc... |
||
| 4521 | * |
||
| 4522 | * @param string $path file path |
||
| 4523 | * @param string $mime file mime type |
||
| 4524 | * @return string |
||
| 4525 | * @author Dmitry (dio) Levashov |
||
| 4526 | **/ |
||
| 4527 | abstract protected function _dimensions($path, $mime); |
||
| 4528 | |||
| 4529 | /******************** file/dir content *********************/ |
||
| 4530 | |||
| 4531 | /** |
||
| 4532 | * Return files list in directory |
||
| 4533 | * |
||
| 4534 | * @param string $path dir path |
||
| 4535 | * @return array |
||
| 4536 | * @author Dmitry (dio) Levashov |
||
| 4537 | **/ |
||
| 4538 | abstract protected function _scandir($path); |
||
| 4539 | |||
| 4540 | /** |
||
| 4541 | * Open file and return file pointer |
||
| 4542 | * |
||
| 4543 | * @param string $path file path |
||
| 4544 | * @param bool $write open file for writing |
||
| 4545 | * @return resource|false |
||
| 4546 | * @author Dmitry (dio) Levashov |
||
| 4547 | **/ |
||
| 4548 | abstract protected function _fopen($path, $mode="rb"); |
||
| 4549 | |||
| 4550 | /** |
||
| 4551 | * Close opened file |
||
| 4552 | * |
||
| 4553 | * @param resource $fp file pointer |
||
| 4554 | * @param string $path file path |
||
| 4555 | * @return bool |
||
| 4556 | * @author Dmitry (dio) Levashov |
||
| 4557 | **/ |
||
| 4558 | abstract protected function _fclose($fp, $path=''); |
||
| 4559 | |||
| 4560 | /******************** file/dir manipulations *************************/ |
||
| 4561 | |||
| 4562 | /** |
||
| 4563 | * Create dir and return created dir path or false on failed |
||
| 4564 | * |
||
| 4565 | * @param string $path parent dir path |
||
| 4566 | * @param string $name new directory name |
||
| 4567 | * @return string|bool |
||
| 4568 | * @author Dmitry (dio) Levashov |
||
| 4569 | **/ |
||
| 4570 | abstract protected function _mkdir($path, $name); |
||
| 4571 | |||
| 4572 | /** |
||
| 4573 | * Create file and return it's path or false on failed |
||
| 4574 | * |
||
| 4575 | * @param string $path parent dir path |
||
| 4576 | * @param string $name new file name |
||
| 4577 | * @return string|bool |
||
| 4578 | * @author Dmitry (dio) Levashov |
||
| 4579 | **/ |
||
| 4580 | abstract protected function _mkfile($path, $name); |
||
| 4581 | |||
| 4582 | /** |
||
| 4583 | * Create symlink |
||
| 4584 | * |
||
| 4585 | * @param string $source file to link to |
||
| 4586 | * @param string $targetDir folder to create link in |
||
| 4587 | * @param string $name symlink name |
||
| 4588 | * @return bool |
||
| 4589 | * @author Dmitry (dio) Levashov |
||
| 4590 | **/ |
||
| 4591 | abstract protected function _symlink($source, $targetDir, $name); |
||
| 4592 | |||
| 4593 | /** |
||
| 4594 | * Copy file into another file (only inside one volume) |
||
| 4595 | * |
||
| 4596 | * @param string $source source file path |
||
| 4597 | * @param string $target target dir path |
||
| 4598 | * @param string $name file name |
||
| 4599 | * @return bool |
||
| 4600 | * @author Dmitry (dio) Levashov |
||
| 4601 | **/ |
||
| 4602 | abstract protected function _copy($source, $targetDir, $name); |
||
| 4603 | |||
| 4604 | /** |
||
| 4605 | * Move file into another parent dir. |
||
| 4606 | * Return new file path or false. |
||
| 4607 | * |
||
| 4608 | * @param string $source source file path |
||
| 4609 | * @param string $target target dir path |
||
| 4610 | * @param string $name file name |
||
| 4611 | * @return string|bool |
||
| 4612 | * @author Dmitry (dio) Levashov |
||
| 4613 | **/ |
||
| 4614 | abstract protected function _move($source, $targetDir, $name); |
||
| 4615 | |||
| 4616 | /** |
||
| 4617 | * Remove file |
||
| 4618 | * |
||
| 4619 | * @param string $path file path |
||
| 4620 | * @return bool |
||
| 4621 | * @author Dmitry (dio) Levashov |
||
| 4622 | **/ |
||
| 4623 | abstract protected function _unlink($path); |
||
| 4624 | |||
| 4625 | /** |
||
| 4626 | * Remove dir |
||
| 4627 | * |
||
| 4628 | * @param string $path dir path |
||
| 4629 | * @return bool |
||
| 4630 | * @author Dmitry (dio) Levashov |
||
| 4631 | **/ |
||
| 4632 | abstract protected function _rmdir($path); |
||
| 4633 | |||
| 4634 | /** |
||
| 4635 | * Create new file and write into it from file pointer. |
||
| 4636 | * Return new file path or false on error. |
||
| 4637 | * |
||
| 4638 | * @param resource $fp file pointer |
||
| 4639 | * @param string $dir target dir path |
||
| 4640 | * @param string $name file name |
||
| 4641 | * @param array $stat file stat (required by some virtual fs) |
||
| 4642 | * @return bool|string |
||
| 4643 | * @author Dmitry (dio) Levashov |
||
| 4644 | **/ |
||
| 4645 | abstract protected function _save($fp, $dir, $name, $stat); |
||
| 4646 | |||
| 4647 | /** |
||
| 4648 | * Get file contents |
||
| 4649 | * |
||
| 4650 | * @param string $path file path |
||
| 4651 | * @return string|false |
||
| 4652 | * @author Dmitry (dio) Levashov |
||
| 4653 | **/ |
||
| 4654 | abstract protected function _getContents($path); |
||
| 4655 | |||
| 4656 | /** |
||
| 4657 | * Write a string to a file |
||
| 4658 | * |
||
| 4659 | * @param string $path file path |
||
| 4660 | * @param string $content new file content |
||
| 4661 | * @return bool |
||
| 4662 | * @author Dmitry (dio) Levashov |
||
| 4663 | **/ |
||
| 4664 | abstract protected function _filePutContents($path, $content); |
||
| 4665 | |||
| 4666 | /** |
||
| 4667 | * Extract files from archive |
||
| 4668 | * |
||
| 4669 | * @param string $path file path |
||
| 4670 | * @param array $arc archiver options |
||
| 4671 | * @return bool |
||
| 4672 | * @author Dmitry (dio) Levashov, |
||
| 4673 | * @author Alexey Sukhotin |
||
| 4674 | **/ |
||
| 4675 | abstract protected function _extract($path, $arc); |
||
| 4676 | |||
| 4677 | /** |
||
| 4678 | * Create archive and return its path |
||
| 4679 | * |
||
| 4680 | * @param string $dir target dir |
||
| 4681 | * @param array $files files names list |
||
| 4682 | * @param string $name archive name |
||
| 4683 | * @param array $arc archiver options |
||
| 4684 | * @return string|bool |
||
| 4685 | * @author Dmitry (dio) Levashov, |
||
| 4686 | * @author Alexey Sukhotin |
||
| 4687 | **/ |
||
| 4688 | abstract protected function _archive($dir, $files, $name, $arc); |
||
| 4689 | |||
| 4690 | /** |
||
| 4691 | * Detect available archivers |
||
| 4692 | * |
||
| 4693 | * @return void |
||
| 4694 | * @author Dmitry (dio) Levashov, |
||
| 4695 | * @author Alexey Sukhotin |
||
| 4696 | **/ |
||
| 4697 | abstract protected function _checkArchivers(); |
||
| 4698 | |||
| 4699 | /** |
||
| 4700 | * Change file mode (chmod) |
||
| 4701 | * |
||
| 4702 | * @param string $path file path |
||
| 4703 | * @param string $mode octal string such as '0755' |
||
| 4704 | * @return bool |
||
| 4705 | * @author David Bartle, |
||
| 4706 | **/ |
||
| 4707 | abstract protected function _chmod($path, $mode); |
||
| 4708 | |||
| 4709 | |||
| 4710 | } // END class |
||
|
2 ignored issues
–
show
|
|||
| 4711 |
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.