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 | * Driver id |
||
| 18 | * Must be started from letter and contains [a-z0-9] |
||
| 19 | * Used as part of volume id |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | **/ |
||
| 23 | protected $driverId = 'a'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Volume id - used as prefix for files hashes |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | **/ |
||
| 30 | protected $id = ''; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Flag - volume "mounted" and available |
||
| 34 | * |
||
| 35 | * @var bool |
||
| 36 | **/ |
||
| 37 | protected $mounted = false; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Root directory path |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | **/ |
||
| 44 | protected $root = ''; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Root basename | alias |
||
| 48 | * |
||
| 49 | * @var string |
||
| 50 | **/ |
||
| 51 | protected $rootName = ''; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Default directory to open |
||
| 55 | * |
||
| 56 | * @var string |
||
| 57 | **/ |
||
| 58 | protected $startPath = ''; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Base URL |
||
| 62 | * |
||
| 63 | * @var string |
||
| 64 | **/ |
||
| 65 | protected $URL = ''; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Thumbnails dir path |
||
| 69 | * |
||
| 70 | * @var string |
||
| 71 | **/ |
||
| 72 | protected $tmbPath = ''; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Is thumbnails dir writable |
||
| 76 | * |
||
| 77 | * @var bool |
||
| 78 | **/ |
||
| 79 | protected $tmbPathWritable = false; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Thumbnails base URL |
||
| 83 | * |
||
| 84 | * @var string |
||
| 85 | **/ |
||
| 86 | protected $tmbURL = ''; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Thumbnails size in px |
||
| 90 | * |
||
| 91 | * @var int |
||
| 92 | **/ |
||
| 93 | protected $tmbSize = 48; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Image manipulation lib name |
||
| 97 | * auto|imagick|mogtify|gd |
||
| 98 | * |
||
| 99 | * @var string |
||
| 100 | **/ |
||
| 101 | protected $imgLib = 'auto'; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Library to crypt files name |
||
| 105 | * |
||
| 106 | * @var string |
||
| 107 | **/ |
||
| 108 | protected $cryptLib = ''; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Archivers config |
||
| 112 | * |
||
| 113 | * @var array |
||
| 114 | **/ |
||
| 115 | protected $archivers = array( |
||
| 116 | 'create' => array(), |
||
| 117 | 'extract' => array() |
||
| 118 | ); |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Server character encoding |
||
| 122 | * |
||
| 123 | * @var string or null |
||
| 124 | **/ |
||
| 125 | protected $encoding = null; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * How many subdirs levels return for tree |
||
| 129 | * |
||
| 130 | * @var int |
||
| 131 | **/ |
||
| 132 | protected $treeDeep = 1; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Errors from last failed action |
||
| 136 | * |
||
| 137 | * @var array |
||
| 138 | **/ |
||
| 139 | protected $error = array(); |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Today 24:00 timestamp |
||
| 143 | * |
||
| 144 | * @var int |
||
| 145 | **/ |
||
| 146 | protected $today = 0; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Yesterday 24:00 timestamp |
||
| 150 | * |
||
| 151 | * @var int |
||
| 152 | **/ |
||
| 153 | protected $yesterday = 0; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Force make dirctory on extract |
||
| 157 | * |
||
| 158 | * @var int |
||
| 159 | **/ |
||
| 160 | protected $extractToNewdir = 'auto'; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Object configuration |
||
| 164 | * |
||
| 165 | * @var array |
||
| 166 | **/ |
||
| 167 | protected $options = array( |
||
| 168 | 'id' => '', |
||
| 169 | // root directory path |
||
| 170 | 'path' => '', |
||
| 171 | // open this path on initial request instead of root path |
||
| 172 | 'startPath' => '', |
||
| 173 | // how many subdirs levels return per request |
||
| 174 | 'treeDeep' => 1, |
||
| 175 | // root url, not set to disable sending URL to client (replacement for old "fileURL" option) |
||
| 176 | 'URL' => '', |
||
| 177 | // directory separator. required by client to show paths correctly |
||
| 178 | 'separator' => DIRECTORY_SEPARATOR, |
||
| 179 | // Server character encoding (default is '': UTF-8) |
||
| 180 | 'encoding' => '', |
||
| 181 | // for convert character encoding (default is '': Not change locale) |
||
| 182 | 'locale' => '', |
||
| 183 | // URL of volume icon (16x16 pixel image file) |
||
| 184 | 'icon' => '', |
||
| 185 | // CSS Class of volume root in tree |
||
| 186 | 'rootCssClass' => '', |
||
| 187 | // library to crypt/uncrypt files names (not implemented) |
||
| 188 | 'cryptLib' => '', |
||
| 189 | // how to detect files mimetypes. (auto/internal/finfo/mime_content_type) |
||
| 190 | 'mimeDetect' => 'auto', |
||
| 191 | // mime.types file path (for mimeDetect==internal) |
||
| 192 | 'mimefile' => '', |
||
| 193 | // mime type normalize map : Array '[ext]:[detected mime type]' => '[normalized mime]' |
||
| 194 | 'mimeMap' => array( |
||
| 195 | 'md:application/x-genesis-rom' => 'text/x-markdown', |
||
| 196 | 'md:text/plain' => 'text/x-markdown', |
||
| 197 | 'markdown:text/plain' => 'text/x-markdown', |
||
| 198 | 'css:text/x-asm' => 'text/css' |
||
| 199 | ), |
||
| 200 | // directory for thumbnails |
||
| 201 | 'tmbPath' => '.tmb', |
||
| 202 | // mode to create thumbnails dir |
||
| 203 | 'tmbPathMode' => 0777, |
||
| 204 | // thumbnails dir URL. Set it if store thumbnails outside root directory |
||
| 205 | 'tmbURL' => '', |
||
| 206 | // thumbnails size (px) |
||
| 207 | 'tmbSize' => 48, |
||
| 208 | // thumbnails crop (true - crop, false - scale image to fit thumbnail size) |
||
| 209 | 'tmbCrop' => true, |
||
| 210 | // thumbnails background color (hex #rrggbb or 'transparent') |
||
| 211 | 'tmbBgColor' => '#ffffff', |
||
| 212 | // image manipulations library |
||
| 213 | 'imgLib' => 'auto', |
||
| 214 | // on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 215 | 'copyOverwrite' => true, |
||
| 216 | // if true - join new and old directories content on paste |
||
| 217 | 'copyJoin' => true, |
||
| 218 | // on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 219 | 'uploadOverwrite' => true, |
||
| 220 | // mimetypes allowed to upload |
||
| 221 | 'uploadAllow' => array(), |
||
| 222 | // mimetypes not allowed to upload |
||
| 223 | 'uploadDeny' => array(), |
||
| 224 | // order to proccess uploadAllow and uploadDeny options |
||
| 225 | 'uploadOrder' => array('deny', 'allow'), |
||
| 226 | // maximum upload file size. NOTE - this is size for every uploaded files |
||
| 227 | 'uploadMaxSize' => 0, |
||
| 228 | // files dates format |
||
| 229 | 'dateFormat' => 'j M Y H:i', |
||
| 230 | // files time format |
||
| 231 | 'timeFormat' => 'H:i', |
||
| 232 | // if true - every folder will be check for children folders, otherwise all folders will be marked as having subfolders |
||
| 233 | 'checkSubfolders' => true, |
||
| 234 | // allow to copy from this volume to other ones? |
||
| 235 | 'copyFrom' => true, |
||
| 236 | // allow to copy from other volumes to this one? |
||
| 237 | 'copyTo' => true, |
||
| 238 | // list of commands disabled on this root |
||
| 239 | 'disabled' => array(), |
||
| 240 | // enable file owner, group & mode info, `false` to inactivate "chmod" command. |
||
| 241 | 'statOwner' => false, |
||
| 242 | // allow exec chmod of read-only files |
||
| 243 | 'allowChmodReadOnly' => false, |
||
| 244 | // regexp or function name to validate new file name |
||
| 245 | 'acceptedName' => '/^[^\.].*/', //<-- DONT touch this! Use constructor options to overwrite it! |
||
| 246 | // function/class method to control files permissions |
||
| 247 | 'accessControl' => null, |
||
| 248 | // some data required by access control |
||
| 249 | 'accessControlData' => null, |
||
| 250 | // default permissions. |
||
| 251 | 'defaults' => array( |
||
| 252 | 'read' => true, |
||
| 253 | 'write' => true, |
||
| 254 | 'locked' => false, |
||
| 255 | 'hidden' => false |
||
| 256 | ), |
||
| 257 | // files attributes |
||
| 258 | 'attributes' => array(), |
||
| 259 | // Allowed archive's mimetypes to create. Leave empty for all available types. |
||
| 260 | 'archiveMimes' => array(), |
||
| 261 | // Manual config for archivers. See example below. Leave empty for auto detect |
||
| 262 | 'archivers' => array(), |
||
| 263 | // plugin settings |
||
| 264 | 'plugin' => array(), |
||
| 265 | // required to fix bug on macos |
||
| 266 | 'utf8fix' => false, |
||
| 267 | // й ё Й Ё Ø Å |
||
| 268 | 'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"), |
||
| 269 | 'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5") |
||
| 270 | ); |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Defaults permissions |
||
| 274 | * |
||
| 275 | * @var array |
||
| 276 | **/ |
||
| 277 | protected $defaults = array( |
||
| 278 | 'read' => true, |
||
| 279 | 'write' => true, |
||
| 280 | 'locked' => false, |
||
| 281 | 'hidden' => false |
||
| 282 | ); |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Access control function/class |
||
| 286 | * |
||
| 287 | * @var mixed |
||
| 288 | **/ |
||
| 289 | protected $attributes = array(); |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Access control function/class |
||
| 293 | * |
||
| 294 | * @var mixed |
||
| 295 | **/ |
||
| 296 | protected $access = null; |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Mime types allowed to upload |
||
| 300 | * |
||
| 301 | * @var array |
||
| 302 | **/ |
||
| 303 | protected $uploadAllow = array(); |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Mime types denied to upload |
||
| 307 | * |
||
| 308 | * @var array |
||
| 309 | **/ |
||
| 310 | protected $uploadDeny = array(); |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Order to validate uploadAllow and uploadDeny |
||
| 314 | * |
||
| 315 | * @var array |
||
| 316 | **/ |
||
| 317 | protected $uploadOrder = array(); |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Maximum allowed upload file size. |
||
| 321 | * Set as number or string with unit - "10M", "500K", "1G" |
||
| 322 | * |
||
| 323 | * @var int|string |
||
| 324 | **/ |
||
| 325 | protected $uploadMaxSize = 0; |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Mimetype detect method |
||
| 329 | * |
||
| 330 | * @var string |
||
| 331 | **/ |
||
| 332 | protected $mimeDetect = 'auto'; |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Flag - mimetypes from externail file was loaded |
||
| 336 | * |
||
| 337 | * @var bool |
||
| 338 | **/ |
||
| 339 | private static $mimetypesLoaded = false; |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Finfo object for mimeDetect == 'finfo' |
||
| 343 | * |
||
| 344 | * @var object |
||
| 345 | **/ |
||
| 346 | protected $finfo = null; |
||
| 347 | |||
| 348 | /** |
||
| 349 | * List of disabled client's commands |
||
| 350 | * |
||
| 351 | * @var array |
||
| 352 | **/ |
||
| 353 | protected $disabled = array(); |
||
| 354 | |||
| 355 | /** |
||
| 356 | * default extensions/mimetypes for mimeDetect == 'internal' |
||
| 357 | * |
||
| 358 | * @var array |
||
| 359 | **/ |
||
| 360 | protected static $mimetypes = array( |
||
| 361 | // applications |
||
| 362 | 'ai' => 'application/postscript', |
||
| 363 | 'eps' => 'application/postscript', |
||
| 364 | 'exe' => 'application/x-executable', |
||
| 365 | 'doc' => 'application/vnd.ms-word', |
||
| 366 | 'xls' => 'application/vnd.ms-excel', |
||
| 367 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
| 368 | 'pps' => 'application/vnd.ms-powerpoint', |
||
| 369 | 'pdf' => 'application/pdf', |
||
| 370 | 'xml' => 'application/xml', |
||
| 371 | 'swf' => 'application/x-shockwave-flash', |
||
| 372 | 'torrent' => 'application/x-bittorrent', |
||
| 373 | 'jar' => 'application/x-jar', |
||
| 374 | // open office (finfo detect as application/zip) |
||
| 375 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
| 376 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
| 377 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
| 378 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
| 379 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
| 380 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
| 381 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
| 382 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
| 383 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
| 384 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
| 385 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
| 386 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
| 387 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
| 388 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
| 389 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
| 390 | // MS office 2007 (finfo detect as application/zip) |
||
| 391 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
| 392 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
| 393 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
| 394 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
| 395 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
| 396 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
| 397 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
| 398 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
| 399 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
| 400 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
| 401 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
| 402 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
| 403 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
| 404 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
| 405 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
| 406 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
| 407 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
| 408 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
| 409 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
| 410 | // archives |
||
| 411 | 'gz' => 'application/x-gzip', |
||
| 412 | 'tgz' => 'application/x-gzip', |
||
| 413 | 'bz' => 'application/x-bzip2', |
||
| 414 | 'bz2' => 'application/x-bzip2', |
||
| 415 | 'tbz' => 'application/x-bzip2', |
||
| 416 | 'xz' => 'application/x-xz', |
||
| 417 | 'zip' => 'application/zip', |
||
| 418 | 'rar' => 'application/x-rar', |
||
| 419 | 'tar' => 'application/x-tar', |
||
| 420 | '7z' => 'application/x-7z-compressed', |
||
| 421 | // texts |
||
| 422 | 'txt' => 'text/plain', |
||
| 423 | 'php' => 'text/x-php', |
||
| 424 | 'html' => 'text/html', |
||
| 425 | 'htm' => 'text/html', |
||
| 426 | 'js' => 'text/javascript', |
||
| 427 | 'css' => 'text/css', |
||
| 428 | 'rtf' => 'text/rtf', |
||
| 429 | 'rtfd' => 'text/rtfd', |
||
| 430 | 'py' => 'text/x-python', |
||
| 431 | 'java' => 'text/x-java-source', |
||
| 432 | 'rb' => 'text/x-ruby', |
||
| 433 | 'sh' => 'text/x-shellscript', |
||
| 434 | 'pl' => 'text/x-perl', |
||
| 435 | 'xml' => 'text/xml', |
||
| 436 | 'sql' => 'text/x-sql', |
||
| 437 | 'c' => 'text/x-csrc', |
||
| 438 | 'h' => 'text/x-chdr', |
||
| 439 | 'cpp' => 'text/x-c++src', |
||
| 440 | 'hh' => 'text/x-c++hdr', |
||
| 441 | 'log' => 'text/plain', |
||
| 442 | 'csv' => 'text/x-comma-separated-values', |
||
| 443 | 'md' => 'text/x-markdown', |
||
| 444 | 'markdown' => 'text/x-markdown', |
||
| 445 | // images |
||
| 446 | 'bmp' => 'image/x-ms-bmp', |
||
| 447 | 'jpg' => 'image/jpeg', |
||
| 448 | 'jpeg' => 'image/jpeg', |
||
| 449 | 'gif' => 'image/gif', |
||
| 450 | 'png' => 'image/png', |
||
| 451 | 'tif' => 'image/tiff', |
||
| 452 | 'tiff' => 'image/tiff', |
||
| 453 | 'tga' => 'image/x-targa', |
||
| 454 | 'psd' => 'image/vnd.adobe.photoshop', |
||
| 455 | 'ai' => 'image/vnd.adobe.photoshop', |
||
| 456 | 'xbm' => 'image/xbm', |
||
| 457 | 'pxm' => 'image/pxm', |
||
| 458 | //audio |
||
| 459 | 'mp3' => 'audio/mpeg', |
||
| 460 | 'mid' => 'audio/midi', |
||
| 461 | 'ogg' => 'audio/ogg', |
||
| 462 | 'oga' => 'audio/ogg', |
||
| 463 | 'm4a' => 'audio/x-m4a', |
||
| 464 | 'wav' => 'audio/wav', |
||
| 465 | 'wma' => 'audio/x-ms-wma', |
||
| 466 | // video |
||
| 467 | 'avi' => 'video/x-msvideo', |
||
| 468 | 'dv' => 'video/x-dv', |
||
| 469 | 'mp4' => 'video/mp4', |
||
| 470 | 'mpeg' => 'video/mpeg', |
||
| 471 | 'mpg' => 'video/mpeg', |
||
| 472 | 'mov' => 'video/quicktime', |
||
| 473 | 'wm' => 'video/x-ms-wmv', |
||
| 474 | 'flv' => 'video/x-flv', |
||
| 475 | 'mkv' => 'video/x-matroska', |
||
| 476 | 'webm' => 'video/webm', |
||
| 477 | 'ogv' => 'video/ogg', |
||
| 478 | 'ogm' => 'video/ogg' |
||
| 479 | ); |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Directory separator - required by client |
||
| 483 | * |
||
| 484 | * @var string |
||
| 485 | **/ |
||
| 486 | protected $separator = DIRECTORY_SEPARATOR; |
||
| 487 | |||
| 488 | /** |
||
| 489 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...) |
||
| 490 | * |
||
| 491 | * @var string |
||
| 492 | **/ |
||
| 493 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Mimetypes allowed to display |
||
| 497 | * |
||
| 498 | * @var array |
||
| 499 | **/ |
||
| 500 | protected $onlyMimes = array(); |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Store files moved or overwrited files info |
||
| 504 | * |
||
| 505 | * @var array |
||
| 506 | **/ |
||
| 507 | protected $removed = array(); |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Cache storage |
||
| 511 | * |
||
| 512 | * @var array |
||
| 513 | **/ |
||
| 514 | protected $cache = array(); |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Cache by folders |
||
| 518 | * |
||
| 519 | * @var array |
||
| 520 | **/ |
||
| 521 | protected $dirsCache = array(); |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Cache for subdirsCE() |
||
| 525 | * |
||
| 526 | * @var array |
||
| 527 | */ |
||
| 528 | protected $subdirsCache = array(); |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Reference of $_SESSION[elFinder::$sessionCacheKey][$this->id] |
||
| 532 | * |
||
| 533 | * @var array |
||
| 534 | */ |
||
| 535 | protected $sessionCache; |
||
| 536 | |||
| 537 | /*********************************************************************/ |
||
| 538 | /* INITIALIZATION */ |
||
| 539 | /*********************************************************************/ |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Prepare driver before mount volume. |
||
| 543 | * Return true if volume is ready. |
||
| 544 | * |
||
| 545 | * @return bool |
||
| 546 | * @author Dmitry (dio) Levashov |
||
| 547 | **/ |
||
| 548 | protected function init() { |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Configure after successfull mount. |
||
| 554 | * By default set thumbnails path and image manipulation library. |
||
| 555 | * |
||
| 556 | * @return void |
||
| 557 | * @author Dmitry (dio) Levashov |
||
| 558 | **/ |
||
| 559 | protected function configure() { |
||
| 598 | |||
| 599 | |||
| 600 | /*********************************************************************/ |
||
| 601 | /* PUBLIC API */ |
||
| 602 | /*********************************************************************/ |
||
| 603 | |||
| 604 | /** |
||
| 605 | * Return driver id. Used as a part of volume id. |
||
| 606 | * |
||
| 607 | * @return string |
||
| 608 | * @author Dmitry (dio) Levashov |
||
| 609 | **/ |
||
| 610 | public function driverId() { |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Return volume id |
||
| 616 | * |
||
| 617 | * @return string |
||
| 618 | * @author Dmitry (dio) Levashov |
||
| 619 | **/ |
||
| 620 | public function id() { |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Return debug info for client |
||
| 626 | * |
||
| 627 | * @return array |
||
| 628 | * @author Dmitry (dio) Levashov |
||
| 629 | **/ |
||
| 630 | public function debug() { |
||
| 638 | |||
| 639 | /** |
||
| 640 | * chmod a file or folder |
||
| 641 | * |
||
| 642 | * @param string $hash file or folder hash to chmod |
||
| 643 | * @param string $mode octal string representing new permissions |
||
| 644 | * @return array|false |
||
| 645 | * @author David Bartle |
||
| 646 | **/ |
||
| 647 | public function chmod($hash, $mode) { |
||
| 683 | |||
| 684 | /** |
||
| 685 | * "Mount" volume. |
||
| 686 | * Return true if volume available for read or write, |
||
| 687 | * false - otherwise |
||
| 688 | * |
||
| 689 | * @return bool |
||
| 690 | * @author Dmitry (dio) Levashov |
||
| 691 | * @author Alexey Sukhotin |
||
| 692 | **/ |
||
| 693 | public function mount(array $opts) { |
||
| 956 | |||
| 957 | /** |
||
| 958 | * Some "unmount" stuffs - may be required by virtual fs |
||
| 959 | * |
||
| 960 | * @return void |
||
| 961 | * @author Dmitry (dio) Levashov |
||
| 962 | **/ |
||
| 963 | public function umount() { |
||
| 965 | |||
| 966 | /** |
||
| 967 | * Return error message from last failed action |
||
| 968 | * |
||
| 969 | * @return array |
||
| 970 | * @author Dmitry (dio) Levashov |
||
| 971 | **/ |
||
| 972 | public function error() { |
||
| 975 | |||
| 976 | /** |
||
| 977 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
| 978 | * |
||
| 979 | * @return array |
||
| 980 | * @author Naoki Sawada |
||
| 981 | */ |
||
| 982 | public function getMimeTable() { |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Set mimetypes allowed to display to client |
||
| 988 | * |
||
| 989 | * @param array $mimes |
||
| 990 | * @return void |
||
| 991 | * @author Dmitry (dio) Levashov |
||
| 992 | **/ |
||
| 993 | public function setMimesFilter($mimes) { |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * Return root folder hash |
||
| 1001 | * |
||
| 1002 | * @return string |
||
| 1003 | * @author Dmitry (dio) Levashov |
||
| 1004 | **/ |
||
| 1005 | public function root() { |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Return root or startPath hash |
||
| 1011 | * |
||
| 1012 | * @return string |
||
| 1013 | * @author Dmitry (dio) Levashov |
||
| 1014 | **/ |
||
| 1015 | public function defaultPath() { |
||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Return volume options required by client: |
||
| 1021 | * |
||
| 1022 | * @return array |
||
| 1023 | * @author Dmitry (dio) Levashov |
||
| 1024 | **/ |
||
| 1025 | public function options($hash) { |
||
| 1049 | |||
| 1050 | /** |
||
| 1051 | * Get plugin values of this options |
||
| 1052 | * |
||
| 1053 | * @param string $name Plugin name |
||
| 1054 | * @return NULL|array Plugin values |
||
| 1055 | * @author Naoki Sawada |
||
| 1056 | */ |
||
| 1057 | public function getOptionsPlugin($name = '') { |
||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * Return true if command disabled in options |
||
| 1067 | * |
||
| 1068 | * @param string $cmd command name |
||
| 1069 | * @return bool |
||
| 1070 | * @author Dmitry (dio) Levashov |
||
| 1071 | **/ |
||
| 1072 | public function commandDisabled($cmd) { |
||
| 1075 | |||
| 1076 | /** |
||
| 1077 | * Return true if mime is required mimes list |
||
| 1078 | * |
||
| 1079 | * @param string $mime mime type to check |
||
| 1080 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
| 1081 | * @param bool|null $empty what to return on empty list |
||
| 1082 | * @return bool|null |
||
| 1083 | * @author Dmitry (dio) Levashov |
||
| 1084 | * @author Troex Nevelin |
||
| 1085 | **/ |
||
| 1086 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
| 1097 | |||
| 1098 | /** |
||
| 1099 | * Return true if voume is readable. |
||
| 1100 | * |
||
| 1101 | * @return bool |
||
| 1102 | * @author Dmitry (dio) Levashov |
||
| 1103 | **/ |
||
| 1104 | public function isReadable() { |
||
| 1108 | |||
| 1109 | /** |
||
| 1110 | * Return true if copy from this volume allowed |
||
| 1111 | * |
||
| 1112 | * @return bool |
||
| 1113 | * @author Dmitry (dio) Levashov |
||
| 1114 | **/ |
||
| 1115 | public function copyFromAllowed() { |
||
| 1118 | |||
| 1119 | /** |
||
| 1120 | * Return file path related to root with convert encoging |
||
| 1121 | * |
||
| 1122 | * @param string $hash file hash |
||
| 1123 | * @return string |
||
| 1124 | * @author Dmitry (dio) Levashov |
||
| 1125 | **/ |
||
| 1126 | public function path($hash) { |
||
| 1129 | |||
| 1130 | /** |
||
| 1131 | * Return file real path if file exists |
||
| 1132 | * |
||
| 1133 | * @param string $hash file hash |
||
| 1134 | * @return string |
||
| 1135 | * @author Dmitry (dio) Levashov |
||
| 1136 | **/ |
||
| 1137 | public function realpath($hash) { |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * Return list of moved/overwrited files |
||
| 1144 | * |
||
| 1145 | * @return array |
||
| 1146 | * @author Dmitry (dio) Levashov |
||
| 1147 | **/ |
||
| 1148 | public function removed() { |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Clean removed files list |
||
| 1154 | * |
||
| 1155 | * @return void |
||
| 1156 | * @author Dmitry (dio) Levashov |
||
| 1157 | **/ |
||
| 1158 | public function resetRemoved() { |
||
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Return file/dir hash or first founded child hash with required attr == $val |
||
| 1164 | * |
||
| 1165 | * @param string $hash file hash |
||
| 1166 | * @param string $attr attribute name |
||
| 1167 | * @param bool $val attribute value |
||
| 1168 | * @return string|false |
||
| 1169 | * @author Dmitry (dio) Levashov |
||
| 1170 | **/ |
||
| 1171 | public function closest($hash, $attr, $val) { |
||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * Return file info or false on error |
||
| 1177 | * |
||
| 1178 | * @param string $hash file hash |
||
| 1179 | * @param bool $realpath add realpath field to file info |
||
| 1180 | * @return array|false |
||
| 1181 | * @author Dmitry (dio) Levashov |
||
| 1182 | **/ |
||
| 1183 | public function file($hash) { |
||
| 1195 | |||
| 1196 | /** |
||
| 1197 | * Return folder info |
||
| 1198 | * |
||
| 1199 | * @param string $hash folder hash |
||
| 1200 | * @param bool $hidden return hidden file info |
||
| 1201 | * @return array|false |
||
| 1202 | * @author Dmitry (dio) Levashov |
||
| 1203 | **/ |
||
| 1204 | public function dir($hash, $resolveLink=false) { |
||
| 1217 | |||
| 1218 | /** |
||
| 1219 | * Return directory content or false on error |
||
| 1220 | * |
||
| 1221 | * @param string $hash file hash |
||
| 1222 | * @return array|false |
||
| 1223 | * @author Dmitry (dio) Levashov |
||
| 1224 | **/ |
||
| 1225 | public function scandir($hash) { |
||
| 1234 | |||
| 1235 | /** |
||
| 1236 | * Return dir files names list |
||
| 1237 | * |
||
| 1238 | * @param string $hash file hash |
||
| 1239 | * @return array |
||
| 1240 | * @author Dmitry (dio) Levashov |
||
| 1241 | **/ |
||
| 1242 | public function ls($hash) { |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Return subfolders for required folder or false on error |
||
| 1261 | * |
||
| 1262 | * @param string $hash folder hash or empty string to get tree from root folder |
||
| 1263 | * @param int $deep subdir deep |
||
| 1264 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
| 1265 | * @return array|false |
||
| 1266 | * @author Dmitry (dio) Levashov |
||
| 1267 | **/ |
||
| 1268 | public function tree($hash='', $deep=0, $exclude='') { |
||
| 1279 | |||
| 1280 | /** |
||
| 1281 | * Return part of dirs tree from required dir up to root dir |
||
| 1282 | * |
||
| 1283 | * @param string $hash directory hash |
||
| 1284 | * @param bool|null $lineal only lineal parents |
||
| 1285 | * @return array |
||
| 1286 | * @author Dmitry (dio) Levashov |
||
| 1287 | **/ |
||
| 1288 | public function parents($hash, $lineal = false) { |
||
| 1315 | |||
| 1316 | /** |
||
| 1317 | * Create thumbnail for required file and return its name of false on failed |
||
| 1318 | * |
||
| 1319 | * @return string|false |
||
| 1320 | * @author Dmitry (dio) Levashov |
||
| 1321 | **/ |
||
| 1322 | public function tmb($hash) { |
||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Return file size / total directory size |
||
| 1334 | * |
||
| 1335 | * @param string file hash |
||
| 1336 | * @return int |
||
| 1337 | * @author Dmitry (dio) Levashov |
||
| 1338 | **/ |
||
| 1339 | public function size($hash) { |
||
| 1342 | |||
| 1343 | /** |
||
| 1344 | * Open file for reading and return file pointer |
||
| 1345 | * |
||
| 1346 | * @param string file hash |
||
| 1347 | * @return Resource |
||
| 1348 | * @author Dmitry (dio) Levashov |
||
| 1349 | **/ |
||
| 1350 | public function open($hash) { |
||
| 1358 | |||
| 1359 | /** |
||
| 1360 | * Close file pointer |
||
| 1361 | * |
||
| 1362 | * @param Resource $fp file pointer |
||
| 1363 | * @param string $hash file hash |
||
| 1364 | * @return void |
||
| 1365 | * @author Dmitry (dio) Levashov |
||
| 1366 | **/ |
||
| 1367 | public function close($fp, $hash) { |
||
| 1370 | |||
| 1371 | /** |
||
| 1372 | * Create directory and return dir info |
||
| 1373 | * |
||
| 1374 | * @param string $dsthash destination directory hash |
||
| 1375 | * @param string $name directory name |
||
| 1376 | * @return array|false |
||
| 1377 | * @author Dmitry (dio) Levashov |
||
| 1378 | **/ |
||
| 1379 | public function mkdir($dsthash, $name) { |
||
| 1406 | |||
| 1407 | /** |
||
| 1408 | * Create empty file and return its info |
||
| 1409 | * |
||
| 1410 | * @param string $dst destination directory |
||
| 1411 | * @param string $name file name |
||
| 1412 | * @return array|false |
||
| 1413 | * @author Dmitry (dio) Levashov |
||
| 1414 | **/ |
||
| 1415 | public function mkfile($dst, $name) { |
||
| 1441 | |||
| 1442 | /** |
||
| 1443 | * Rename file and return file info |
||
| 1444 | * |
||
| 1445 | * @param string $hash file hash |
||
| 1446 | * @param string $name new file name |
||
| 1447 | * @return array|false |
||
| 1448 | * @author Dmitry (dio) Levashov |
||
| 1449 | **/ |
||
| 1450 | public function rename($hash, $name) { |
||
| 1496 | |||
| 1497 | /** |
||
| 1498 | * Create file copy with suffix "copy number" and return its info |
||
| 1499 | * |
||
| 1500 | * @param string $hash file hash |
||
| 1501 | * @param string $suffix suffix to add to file name |
||
| 1502 | * @return array|false |
||
| 1503 | * @author Dmitry (dio) Levashov |
||
| 1504 | **/ |
||
| 1505 | public function duplicate($hash, $suffix='copy') { |
||
| 1526 | |||
| 1527 | /** |
||
| 1528 | * Save uploaded file. |
||
| 1529 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
| 1530 | * |
||
| 1531 | * @param Resource $fp file pointer |
||
| 1532 | * @param string $dst destination folder hash |
||
| 1533 | * @param string $src file name |
||
| 1534 | * @param string $tmpname file tmp name - required to detect mime type |
||
| 1535 | * @return array|false |
||
| 1536 | * @author Dmitry (dio) Levashov |
||
| 1537 | **/ |
||
| 1538 | public function upload($fp, $dst, $name, $tmpname) { |
||
| 1614 | |||
| 1615 | /** |
||
| 1616 | * Paste files |
||
| 1617 | * |
||
| 1618 | * @param Object $volume source volume |
||
| 1619 | * @param string $source file hash |
||
| 1620 | * @param string $dst destination dir hash |
||
| 1621 | * @param bool $rmSrc remove source after copy? |
||
| 1622 | * @return array|false |
||
| 1623 | * @author Dmitry (dio) Levashov |
||
| 1624 | **/ |
||
| 1625 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
| 1713 | |||
| 1714 | /** |
||
| 1715 | * Return file contents |
||
| 1716 | * |
||
| 1717 | * @param string $hash file hash |
||
| 1718 | * @return string|false |
||
| 1719 | * @author Dmitry (dio) Levashov |
||
| 1720 | **/ |
||
| 1721 | public function getContents($hash) { |
||
| 1738 | |||
| 1739 | /** |
||
| 1740 | * Put content in text file and return file info. |
||
| 1741 | * |
||
| 1742 | * @param string $hash file hash |
||
| 1743 | * @param string $content new file content |
||
| 1744 | * @return array |
||
| 1745 | * @author Dmitry (dio) Levashov |
||
| 1746 | **/ |
||
| 1747 | public function putContents($hash, $content) { |
||
| 1782 | |||
| 1783 | /** |
||
| 1784 | * Extract files from archive |
||
| 1785 | * |
||
| 1786 | * @param string $hash archive hash |
||
| 1787 | * @return array|bool |
||
| 1788 | * @author Dmitry (dio) Levashov, |
||
| 1789 | * @author Alexey Sukhotin |
||
| 1790 | **/ |
||
| 1791 | public function extract($hash, $makedir = null) { |
||
| 1830 | |||
| 1831 | /** |
||
| 1832 | * Add files to archive |
||
| 1833 | * |
||
| 1834 | * @return void |
||
| 1835 | **/ |
||
| 1836 | public function archive($hashes, $mime, $name = '') { |
||
| 1880 | |||
| 1881 | /** |
||
| 1882 | * Resize image |
||
| 1883 | * |
||
| 1884 | * @param string $hash image file |
||
| 1885 | * @param int $width new width |
||
| 1886 | * @param int $height new height |
||
| 1887 | * @param int $x X start poistion for crop |
||
| 1888 | * @param int $y Y start poistion for crop |
||
| 1889 | * @param string $mode action how to mainpulate image |
||
| 1890 | * @return array|false |
||
| 1891 | * @author Dmitry (dio) Levashov |
||
| 1892 | * @author Alexey Sukhotin |
||
| 1893 | * @author nao-pon |
||
| 1894 | * @author Troex Nevelin |
||
| 1895 | **/ |
||
| 1896 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0) { |
||
| 1983 | |||
| 1984 | /** |
||
| 1985 | * Remove file/dir |
||
| 1986 | * |
||
| 1987 | * @param string $hash file hash |
||
| 1988 | * @return bool |
||
| 1989 | * @author Dmitry (dio) Levashov |
||
| 1990 | **/ |
||
| 1991 | public function rm($hash) { |
||
| 1996 | |||
| 1997 | /** |
||
| 1998 | * Search files |
||
| 1999 | * |
||
| 2000 | * @param string $q search string |
||
| 2001 | * @param array $mimes |
||
| 2002 | * @return array |
||
| 2003 | * @author Dmitry (dio) Levashov |
||
| 2004 | **/ |
||
| 2005 | public function search($q, $mimes, $hash = null) { |
||
| 2024 | |||
| 2025 | /** |
||
| 2026 | * Return image dimensions |
||
| 2027 | * |
||
| 2028 | * @param string $hash file hash |
||
| 2029 | * @return array |
||
| 2030 | * @author Dmitry (dio) Levashov |
||
| 2031 | **/ |
||
| 2032 | public function dimensions($hash) { |
||
| 2039 | |||
| 2040 | /** |
||
| 2041 | * Return content URL (for netmout volume driver) |
||
| 2042 | * If file.url == 1 requests from JavaScript client with XHR |
||
| 2043 | * |
||
| 2044 | * @param string $hash file hash |
||
| 2045 | * @param array $options options array |
||
| 2046 | * @return boolean|string |
||
| 2047 | * @author Naoki Sawada |
||
| 2048 | */ |
||
| 2049 | public function getContentUrl($hash, $options = array()) { |
||
| 2055 | |||
| 2056 | /** |
||
| 2057 | * Return temp path |
||
| 2058 | * |
||
| 2059 | * @return string |
||
| 2060 | * @author Naoki Sawada |
||
| 2061 | */ |
||
| 2062 | public function getTempPath() { |
||
| 2075 | |||
| 2076 | /** |
||
| 2077 | * (Make &) Get upload taget dirctory hash |
||
| 2078 | * |
||
| 2079 | * @param string $baseTargetHash |
||
| 2080 | * @param string $path |
||
| 2081 | * @param array $result |
||
| 2082 | * @return boolean|string |
||
| 2083 | * @author Naoki Sawada |
||
| 2084 | */ |
||
| 2085 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
| 2112 | |||
| 2113 | /** |
||
| 2114 | * Return this uploadMaxSize value |
||
| 2115 | * |
||
| 2116 | * @return integer |
||
| 2117 | * @author Naoki Sawada |
||
| 2118 | */ |
||
| 2119 | public function getUploadMaxSize() { |
||
| 2122 | |||
| 2123 | /** |
||
| 2124 | * Save error message |
||
| 2125 | * |
||
| 2126 | * @param array error |
||
| 2127 | * @return false |
||
| 2128 | * @author Dmitry(dio) Levashov |
||
| 2129 | **/ |
||
| 2130 | protected function setError($error) { |
||
| 2145 | |||
| 2146 | /*********************************************************************/ |
||
| 2147 | /* FS API */ |
||
| 2148 | /*********************************************************************/ |
||
| 2149 | |||
| 2150 | /***************** server encoding support *******************/ |
||
| 2151 | |||
| 2152 | /** |
||
| 2153 | * Return parent directory path (with convert encording) |
||
| 2154 | * |
||
| 2155 | * @param string $path file path |
||
| 2156 | * @return string |
||
| 2157 | * @author Naoki Sawada |
||
| 2158 | **/ |
||
| 2159 | protected function dirnameCE($path) { |
||
| 2162 | |||
| 2163 | /** |
||
| 2164 | * Return file name (with convert encording) |
||
| 2165 | * |
||
| 2166 | * @param string $path file path |
||
| 2167 | * @return string |
||
| 2168 | * @author Naoki Sawada |
||
| 2169 | **/ |
||
| 2170 | protected function basenameCE($path) { |
||
| 2173 | |||
| 2174 | /** |
||
| 2175 | * Join dir name and file name and return full path. (with convert encording) |
||
| 2176 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 2177 | * |
||
| 2178 | * @param string $dir dir path |
||
| 2179 | * @param string $name file name |
||
| 2180 | * @return string |
||
| 2181 | * @author Naoki Sawada |
||
| 2182 | **/ |
||
| 2183 | protected function joinPathCE($dir, $name) { |
||
| 2186 | |||
| 2187 | /** |
||
| 2188 | * Return normalized path (with convert encording) |
||
| 2189 | * |
||
| 2190 | * @param string $path file path |
||
| 2191 | * @return string |
||
| 2192 | * @author Naoki Sawada |
||
| 2193 | **/ |
||
| 2194 | protected function normpathCE($path) { |
||
| 2197 | |||
| 2198 | /** |
||
| 2199 | * Return file path related to root dir (with convert encording) |
||
| 2200 | * |
||
| 2201 | * @param string $path file path |
||
| 2202 | * @return string |
||
| 2203 | * @author Naoki Sawada |
||
| 2204 | **/ |
||
| 2205 | protected function relpathCE($path) { |
||
| 2208 | |||
| 2209 | /** |
||
| 2210 | * Convert path related to root dir into real path (with convert encording) |
||
| 2211 | * |
||
| 2212 | * @param string $path rel file path |
||
| 2213 | * @return string |
||
| 2214 | * @author Naoki Sawada |
||
| 2215 | **/ |
||
| 2216 | protected function abspathCE($path) { |
||
| 2219 | |||
| 2220 | /** |
||
| 2221 | * Return true if $path is children of $parent (with convert encording) |
||
| 2222 | * |
||
| 2223 | * @param string $path path to check |
||
| 2224 | * @param string $parent parent path |
||
| 2225 | * @return bool |
||
| 2226 | * @author Naoki Sawada |
||
| 2227 | **/ |
||
| 2228 | protected function inpathCE($path, $parent) { |
||
| 2231 | |||
| 2232 | /** |
||
| 2233 | * Open file and return file pointer (with convert encording) |
||
| 2234 | * |
||
| 2235 | * @param string $path file path |
||
| 2236 | * @param bool $write open file for writing |
||
| 2237 | * @return resource|false |
||
| 2238 | * @author Naoki Sawada |
||
| 2239 | **/ |
||
| 2240 | protected function fopenCE($path, $mode='rb') { |
||
| 2243 | |||
| 2244 | /** |
||
| 2245 | * Close opened file (with convert encording) |
||
| 2246 | * |
||
| 2247 | * @param resource $fp file pointer |
||
| 2248 | * @param string $path file path |
||
| 2249 | * @return bool |
||
| 2250 | * @author Naoki Sawada |
||
| 2251 | **/ |
||
| 2252 | protected function fcloseCE($fp, $path='') { |
||
| 2255 | |||
| 2256 | /** |
||
| 2257 | * Create new file and write into it from file pointer. (with convert encording) |
||
| 2258 | * Return new file path or false on error. |
||
| 2259 | * |
||
| 2260 | * @param resource $fp file pointer |
||
| 2261 | * @param string $dir target dir path |
||
| 2262 | * @param string $name file name |
||
| 2263 | * @param array $stat file stat (required by some virtual fs) |
||
| 2264 | * @return bool|string |
||
| 2265 | * @author Naoki Sawada |
||
| 2266 | **/ |
||
| 2267 | protected function saveCE($fp, $dir, $name, $stat) { |
||
| 2270 | |||
| 2271 | /** |
||
| 2272 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
| 2273 | * |
||
| 2274 | * @param string $path dir path |
||
| 2275 | * @return bool |
||
| 2276 | * @author Naoki Sawada |
||
| 2277 | **/ |
||
| 2278 | protected function subdirsCE($path) { |
||
| 2284 | |||
| 2285 | /** |
||
| 2286 | * Return files list in directory (with convert encording) |
||
| 2287 | * |
||
| 2288 | * @param string $path dir path |
||
| 2289 | * @return array |
||
| 2290 | * @author Naoki Sawada |
||
| 2291 | **/ |
||
| 2292 | protected function scandirCE($path) { |
||
| 2295 | |||
| 2296 | /** |
||
| 2297 | * Create symlink (with convert encording) |
||
| 2298 | * |
||
| 2299 | * @param string $source file to link to |
||
| 2300 | * @param string $targetDir folder to create link in |
||
| 2301 | * @param string $name symlink name |
||
| 2302 | * @return bool |
||
| 2303 | * @author Naoki Sawada |
||
| 2304 | **/ |
||
| 2305 | protected function symlinkCE($source, $targetDir, $name) { |
||
| 2308 | |||
| 2309 | /***************** paths *******************/ |
||
| 2310 | |||
| 2311 | /** |
||
| 2312 | * Encode path into hash |
||
| 2313 | * |
||
| 2314 | * @param string file path |
||
| 2315 | * @return string |
||
| 2316 | * @author Dmitry (dio) Levashov |
||
| 2317 | * @author Troex Nevelin |
||
| 2318 | **/ |
||
| 2319 | protected function encode($path) { |
||
| 2340 | |||
| 2341 | /** |
||
| 2342 | * Decode path from hash |
||
| 2343 | * |
||
| 2344 | * @param string file hash |
||
| 2345 | * @return string |
||
| 2346 | * @author Dmitry (dio) Levashov |
||
| 2347 | * @author Troex Nevelin |
||
| 2348 | **/ |
||
| 2349 | protected function decode($hash) { |
||
| 2361 | |||
| 2362 | /** |
||
| 2363 | * Return crypted path |
||
| 2364 | * Not implemented |
||
| 2365 | * |
||
| 2366 | * @param string path |
||
| 2367 | * @return mixed |
||
| 2368 | * @author Dmitry (dio) Levashov |
||
| 2369 | **/ |
||
| 2370 | protected function crypt($path) { |
||
| 2373 | |||
| 2374 | /** |
||
| 2375 | * Return uncrypted path |
||
| 2376 | * Not implemented |
||
| 2377 | * |
||
| 2378 | * @param mixed hash |
||
| 2379 | * @return mixed |
||
| 2380 | * @author Dmitry (dio) Levashov |
||
| 2381 | **/ |
||
| 2382 | protected function uncrypt($hash) { |
||
| 2385 | |||
| 2386 | /** |
||
| 2387 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
| 2388 | * |
||
| 2389 | * @param string $name file name |
||
| 2390 | * @return bool |
||
| 2391 | * @author Dmitry (dio) Levashov |
||
| 2392 | **/ |
||
| 2393 | protected function nameAccepted($name) { |
||
| 2405 | |||
| 2406 | /** |
||
| 2407 | * Return new unique name based on file name and suffix |
||
| 2408 | * |
||
| 2409 | * @param string $path file path |
||
| 2410 | * @param string $suffix suffix append to name |
||
| 2411 | * @return string |
||
| 2412 | * @author Dmitry (dio) Levashov |
||
| 2413 | **/ |
||
| 2414 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum=true) { |
||
| 2442 | |||
| 2443 | /** |
||
| 2444 | * Converts character encoding from UTF-8 to server's one |
||
| 2445 | * |
||
| 2446 | * @param mixed $var target string or array var |
||
| 2447 | * @param bool $restoreLocale do retore global locale, default is false |
||
| 2448 | * @param string $unknown replaces character for unknown |
||
| 2449 | * @return mixed |
||
| 2450 | * @author Naoki Sawada |
||
| 2451 | */ |
||
| 2452 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
| 2455 | |||
| 2456 | /** |
||
| 2457 | * Converts character encoding from server's one to UTF-8 |
||
| 2458 | * |
||
| 2459 | * @param mixed $var target string or array var |
||
| 2460 | * @param bool $restoreLocale do retore global locale, default is true |
||
| 2461 | * @param string $unknown replaces character for unknown |
||
| 2462 | * @return mixed |
||
| 2463 | * @author Naoki Sawada |
||
| 2464 | */ |
||
| 2465 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
| 2468 | |||
| 2469 | /** |
||
| 2470 | * Converts character encoding (base function) |
||
| 2471 | * |
||
| 2472 | * @param mixed $var target string or array var |
||
| 2473 | * @param string $from from character encoding |
||
| 2474 | * @param string $to to character encoding |
||
| 2475 | * @param string $locale local locale |
||
| 2476 | * @param string $unknown replaces character for unknown |
||
| 2477 | * @return mixed |
||
| 2478 | */ |
||
| 2479 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
| 2508 | |||
| 2509 | /*********************** util mainly for inheritance class *********************/ |
||
| 2510 | |||
| 2511 | /** |
||
| 2512 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
| 2513 | * When needing the unique file to a path, give $path to parameter. |
||
| 2514 | * |
||
| 2515 | * @param string $path for get unique file to a path |
||
| 2516 | * @return string|false |
||
| 2517 | * @author Naoki Sawada |
||
| 2518 | */ |
||
| 2519 | protected function getTempFile($path = '') { |
||
| 2545 | |||
| 2546 | /** |
||
| 2547 | * File path of local server side work file path |
||
| 2548 | * |
||
| 2549 | * @param string $path path need convert encoding to server encoding |
||
| 2550 | * @return string |
||
| 2551 | * @author Naoki Sawada |
||
| 2552 | */ |
||
| 2553 | protected function getWorkFile($path) { |
||
| 2568 | |||
| 2569 | /** |
||
| 2570 | * Get image size array with `dimensions` |
||
| 2571 | * |
||
| 2572 | * @param string $path path need convert encoding to server encoding |
||
| 2573 | * @param string $mime file mime type |
||
| 2574 | * @return array|false |
||
| 2575 | */ |
||
| 2576 | public function getImageSize($path, $mime = '') { |
||
| 2588 | |||
| 2589 | /** |
||
| 2590 | * Delete dirctory trees |
||
| 2591 | * |
||
| 2592 | * @param string $localpath path need convert encoding to server encoding |
||
| 2593 | * @return boolean |
||
| 2594 | * @author Naoki Sawada |
||
| 2595 | */ |
||
| 2596 | protected function delTree($localpath) { |
||
| 2605 | |||
| 2606 | /*********************** file stat *********************/ |
||
| 2607 | |||
| 2608 | /** |
||
| 2609 | * Check file attribute |
||
| 2610 | * |
||
| 2611 | * @param string $path file path |
||
| 2612 | * @param string $name attribute name (read|write|locked|hidden) |
||
| 2613 | * @param bool $val attribute value returned by file system |
||
| 2614 | * @param bool $isDir path is directory (true: directory, false: file) |
||
| 2615 | * @return bool |
||
| 2616 | * @author Dmitry (dio) Levashov |
||
| 2617 | **/ |
||
| 2618 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
| 2652 | |||
| 2653 | /** |
||
| 2654 | * Return true if file with given name can be created in given folder. |
||
| 2655 | * |
||
| 2656 | * @param string $dir parent dir path |
||
| 2657 | * @param string $name new file name |
||
| 2658 | * @return bool |
||
| 2659 | * @author Dmitry (dio) Levashov |
||
| 2660 | **/ |
||
| 2661 | protected function allowCreate($dir, $name, $isDir = null) { |
||
| 2684 | |||
| 2685 | /** |
||
| 2686 | * Return true if file MIME type can save with check uploadOrder config. |
||
| 2687 | * |
||
| 2688 | * @param string $mime |
||
| 2689 | * @return boolean |
||
| 2690 | */ |
||
| 2691 | protected function allowPutMime($mime) { |
||
| 2709 | |||
| 2710 | /** |
||
| 2711 | * Return fileinfo |
||
| 2712 | * |
||
| 2713 | * @param string $path file cache |
||
| 2714 | * @return array |
||
| 2715 | * @author Dmitry (dio) Levashov |
||
| 2716 | **/ |
||
| 2717 | protected function stat($path) { |
||
| 2742 | |||
| 2743 | /** |
||
| 2744 | * Put file stat in cache and return it |
||
| 2745 | * |
||
| 2746 | * @param string $path file path |
||
| 2747 | * @param array $stat file stat |
||
| 2748 | * @return array |
||
| 2749 | * @author Dmitry (dio) Levashov |
||
| 2750 | **/ |
||
| 2751 | protected function updateCache($path, $stat) { |
||
| 2890 | |||
| 2891 | /** |
||
| 2892 | * Get stat for folder content and put in cache |
||
| 2893 | * |
||
| 2894 | * @param string $path |
||
| 2895 | * @return void |
||
| 2896 | * @author Dmitry (dio) Levashov |
||
| 2897 | **/ |
||
| 2898 | protected function cacheDir($path) { |
||
| 2911 | |||
| 2912 | /** |
||
| 2913 | * Clean cache |
||
| 2914 | * |
||
| 2915 | * @return void |
||
| 2916 | * @author Dmitry (dio) Levashov |
||
| 2917 | **/ |
||
| 2918 | protected function clearcache() { |
||
| 2921 | |||
| 2922 | /** |
||
| 2923 | * Return file mimetype |
||
| 2924 | * |
||
| 2925 | * @param string $path file path |
||
| 2926 | * @return string |
||
| 2927 | * @author Dmitry (dio) Levashov |
||
| 2928 | **/ |
||
| 2929 | protected function mimetype($path, $name = '') { |
||
| 2974 | |||
| 2975 | /** |
||
| 2976 | * Detect file mimetype using "internal" method |
||
| 2977 | * |
||
| 2978 | * @param string $path file path |
||
| 2979 | * @return string |
||
| 2980 | * @author Dmitry (dio) Levashov |
||
| 2981 | **/ |
||
| 2982 | static protected function mimetypeInternalDetect($path) { |
||
| 2988 | |||
| 2989 | /** |
||
| 2990 | * Return file/total directory size |
||
| 2991 | * |
||
| 2992 | * @param string $path file path |
||
| 2993 | * @return int |
||
| 2994 | * @author Dmitry (dio) Levashov |
||
| 2995 | **/ |
||
| 2996 | protected function countSize($path) { |
||
| 3021 | |||
| 3022 | /** |
||
| 3023 | * Return true if all mimes is directory or files |
||
| 3024 | * |
||
| 3025 | * @param string $mime1 mimetype |
||
| 3026 | * @param string $mime2 mimetype |
||
| 3027 | * @return bool |
||
| 3028 | * @author Dmitry (dio) Levashov |
||
| 3029 | **/ |
||
| 3030 | protected function isSameType($mime1, $mime2) { |
||
| 3033 | |||
| 3034 | /** |
||
| 3035 | * If file has required attr == $val - return file path, |
||
| 3036 | * If dir has child with has required attr == $val - return child path |
||
| 3037 | * |
||
| 3038 | * @param string $path file path |
||
| 3039 | * @param string $attr attribute name |
||
| 3040 | * @param bool $val attribute value |
||
| 3041 | * @return string|false |
||
| 3042 | * @author Dmitry (dio) Levashov |
||
| 3043 | **/ |
||
| 3044 | protected function closestByAttr($path, $attr, $val) { |
||
| 3061 | |||
| 3062 | /** |
||
| 3063 | * Return first found children with required attr == $val |
||
| 3064 | * |
||
| 3065 | * @param string $path file path |
||
| 3066 | * @param string $attr attribute name |
||
| 3067 | * @param bool $val attribute value |
||
| 3068 | * @return string|false |
||
| 3069 | * @author Dmitry (dio) Levashov |
||
| 3070 | **/ |
||
| 3071 | protected function childsByAttr($path, $attr, $val) { |
||
| 3079 | |||
| 3080 | /***************** get content *******************/ |
||
| 3081 | |||
| 3082 | /** |
||
| 3083 | * Return required dir's files info. |
||
| 3084 | * If onlyMimes is set - return only dirs and files of required mimes |
||
| 3085 | * |
||
| 3086 | * @param string $path dir path |
||
| 3087 | * @return array |
||
| 3088 | * @author Dmitry (dio) Levashov |
||
| 3089 | **/ |
||
| 3090 | protected function getScandir($path) { |
||
| 3103 | |||
| 3104 | |||
| 3105 | /** |
||
| 3106 | * Return subdirs tree |
||
| 3107 | * |
||
| 3108 | * @param string $path parent dir path |
||
| 3109 | * @param int $deep tree deep |
||
| 3110 | * @return array |
||
| 3111 | * @author Dmitry (dio) Levashov |
||
| 3112 | **/ |
||
| 3113 | protected function gettree($path, $deep, $exclude='') { |
||
| 3131 | |||
| 3132 | /** |
||
| 3133 | * Recursive files search |
||
| 3134 | * |
||
| 3135 | * @param string $path dir path |
||
| 3136 | * @param string $q search string |
||
| 3137 | * @param array $mimes |
||
| 3138 | * @return array |
||
| 3139 | * @author Dmitry (dio) Levashov |
||
| 3140 | **/ |
||
| 3141 | protected function doSearch($path, $q, $mimes) { |
||
| 3177 | |||
| 3178 | /********************** manuipulations ******************/ |
||
| 3179 | |||
| 3180 | /** |
||
| 3181 | * Copy file/recursive copy dir only in current volume. |
||
| 3182 | * Return new file path or false. |
||
| 3183 | * |
||
| 3184 | * @param string $src source path |
||
| 3185 | * @param string $dst destination dir path |
||
| 3186 | * @param string $name new file name (optionaly) |
||
| 3187 | * @return string|false |
||
| 3188 | * @author Dmitry (dio) Levashov |
||
| 3189 | **/ |
||
| 3190 | protected function copy($src, $dst, $name) { |
||
| 3232 | |||
| 3233 | /** |
||
| 3234 | * Move file |
||
| 3235 | * Return new file path or false. |
||
| 3236 | * |
||
| 3237 | * @param string $src source path |
||
| 3238 | * @param string $dst destination dir path |
||
| 3239 | * @param string $name new file name |
||
| 3240 | * @return string|false |
||
| 3241 | * @author Dmitry (dio) Levashov |
||
| 3242 | **/ |
||
| 3243 | protected function move($src, $dst, $name) { |
||
| 3257 | |||
| 3258 | /** |
||
| 3259 | * Copy file from another volume. |
||
| 3260 | * Return new file path or false. |
||
| 3261 | * |
||
| 3262 | * @param Object $volume source volume |
||
| 3263 | * @param string $src source file hash |
||
| 3264 | * @param string $destination destination dir path |
||
| 3265 | * @param string $name file name |
||
| 3266 | * @return string|false |
||
| 3267 | * @author Dmitry (dio) Levashov |
||
| 3268 | **/ |
||
| 3269 | protected function copyFrom($volume, $src, $destination, $name) { |
||
| 3327 | |||
| 3328 | /** |
||
| 3329 | * Remove file/ recursive remove dir |
||
| 3330 | * |
||
| 3331 | * @param string $path file path |
||
| 3332 | * @param bool $force try to remove even if file locked |
||
| 3333 | * @return bool |
||
| 3334 | * @author Dmitry (dio) Levashov |
||
| 3335 | **/ |
||
| 3336 | protected function remove($path, $force = false) { |
||
| 3366 | |||
| 3367 | |||
| 3368 | /************************* thumbnails **************************/ |
||
| 3369 | |||
| 3370 | /** |
||
| 3371 | * Return thumbnail file name for required file |
||
| 3372 | * |
||
| 3373 | * @param array $stat file stat |
||
| 3374 | * @return string |
||
| 3375 | * @author Dmitry (dio) Levashov |
||
| 3376 | **/ |
||
| 3377 | protected function tmbname($stat) { |
||
| 3380 | |||
| 3381 | /** |
||
| 3382 | * Return thumnbnail name if exists |
||
| 3383 | * |
||
| 3384 | * @param string $path file path |
||
| 3385 | * @param array $stat file stat |
||
| 3386 | * @return string|false |
||
| 3387 | * @author Dmitry (dio) Levashov |
||
| 3388 | **/ |
||
| 3389 | protected function gettmb($path, $stat) { |
||
| 3403 | |||
| 3404 | /** |
||
| 3405 | * Return true if thumnbnail for required file can be created |
||
| 3406 | * |
||
| 3407 | * @param string $path thumnbnail path |
||
| 3408 | * @param array $stat file stat |
||
| 3409 | * @param bool $checkTmbPath |
||
| 3410 | * @return string|bool |
||
| 3411 | * @author Dmitry (dio) Levashov |
||
| 3412 | **/ |
||
| 3413 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
| 3420 | |||
| 3421 | /** |
||
| 3422 | * Return true if required file can be resized. |
||
| 3423 | * By default - the same as canCreateTmb |
||
| 3424 | * |
||
| 3425 | * @param string $path thumnbnail path |
||
| 3426 | * @param array $stat file stat |
||
| 3427 | * @return string|bool |
||
| 3428 | * @author Dmitry (dio) Levashov |
||
| 3429 | **/ |
||
| 3430 | protected function canResize($path, $stat) { |
||
| 3433 | |||
| 3434 | /** |
||
| 3435 | * Create thumnbnail and return it's URL on success |
||
| 3436 | * |
||
| 3437 | * @param string $path file path |
||
| 3438 | * @param string $mime file mime type |
||
| 3439 | * @return string|false |
||
| 3440 | * @author Dmitry (dio) Levashov |
||
| 3441 | **/ |
||
| 3442 | protected function createTmb($path, $stat) { |
||
| 3512 | |||
| 3513 | /** |
||
| 3514 | * Resize image |
||
| 3515 | * |
||
| 3516 | * @param string $path image file |
||
| 3517 | * @param int $width new width |
||
| 3518 | * @param int $height new height |
||
| 3519 | * @param bool $keepProportions crop image |
||
| 3520 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
| 3521 | * @param string $destformat image destination format |
||
| 3522 | * @return string|false |
||
| 3523 | * @author Dmitry (dio) Levashov |
||
| 3524 | * @author Alexey Sukhotin |
||
| 3525 | **/ |
||
| 3526 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null) { |
||
| 3619 | |||
| 3620 | /** |
||
| 3621 | * Crop image |
||
| 3622 | * |
||
| 3623 | * @param string $path image file |
||
| 3624 | * @param int $width crop width |
||
| 3625 | * @param int $height crop height |
||
| 3626 | * @param bool $x crop left offset |
||
| 3627 | * @param bool $y crop top offset |
||
| 3628 | * @param string $destformat image destination format |
||
| 3629 | * @return string|false |
||
| 3630 | * @author Dmitry (dio) Levashov |
||
| 3631 | * @author Alexey Sukhotin |
||
| 3632 | **/ |
||
| 3633 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null) { |
||
| 3707 | |||
| 3708 | /** |
||
| 3709 | * Put image to square |
||
| 3710 | * |
||
| 3711 | * @param string $path image file |
||
| 3712 | * @param int $width square width |
||
| 3713 | * @param int $height square height |
||
| 3714 | * @param int $align reserved |
||
| 3715 | * @param int $valign reserved |
||
| 3716 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3717 | * @param string $destformat image destination format |
||
| 3718 | * @return string|false |
||
| 3719 | * @author Dmitry (dio) Levashov |
||
| 3720 | * @author Alexey Sukhotin |
||
| 3721 | **/ |
||
| 3722 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null) { |
||
| 3800 | |||
| 3801 | /** |
||
| 3802 | * Rotate image |
||
| 3803 | * |
||
| 3804 | * @param string $path image file |
||
| 3805 | * @param int $degree rotete degrees |
||
| 3806 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3807 | * @param string $destformat image destination format |
||
| 3808 | * @return string|false |
||
| 3809 | * @author nao-pon |
||
| 3810 | * @author Troex Nevelin |
||
| 3811 | **/ |
||
| 3812 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null) { |
||
| 3892 | |||
| 3893 | /** |
||
| 3894 | * Execute shell command |
||
| 3895 | * |
||
| 3896 | * @param string $command command line |
||
| 3897 | * @param array $output stdout strings |
||
| 3898 | * @param array $return_var process exit code |
||
| 3899 | * @param array $error_output stderr strings |
||
| 3900 | * @return int exit code |
||
| 3901 | * @author Alexey Sukhotin |
||
| 3902 | **/ |
||
| 3903 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
| 3933 | |||
| 3934 | /** |
||
| 3935 | * Remove thumbnail, also remove recursively if stat is directory |
||
| 3936 | * |
||
| 3937 | * @param string $stat file stat |
||
| 3938 | * @return void |
||
| 3939 | * @author Dmitry (dio) Levashov |
||
| 3940 | * @author Naoki Sawada |
||
| 3941 | * @author Troex Nevelin |
||
| 3942 | **/ |
||
| 3943 | protected function rmTmb($stat) { |
||
| 3956 | |||
| 3957 | /** |
||
| 3958 | * Create an gd image according to the specified mime type |
||
| 3959 | * |
||
| 3960 | * @param string $path image file |
||
| 3961 | * @param string $mime |
||
| 3962 | * @return gd image resource identifier |
||
| 3963 | */ |
||
| 3964 | protected function gdImageCreate($path,$mime){ |
||
| 3980 | |||
| 3981 | /** |
||
| 3982 | * Output gd image to file |
||
| 3983 | * |
||
| 3984 | * @param resource $image gd image resource |
||
| 3985 | * @param string $filename The path to save the file to. |
||
| 3986 | * @param string $destformat The Image type to use for $filename |
||
| 3987 | * @param string $mime The original image mime type |
||
| 3988 | */ |
||
| 3989 | protected function gdImage($image, $filename, $destformat, $mime ){ |
||
| 4001 | |||
| 4002 | /** |
||
| 4003 | * Assign the proper background to a gd image |
||
| 4004 | * |
||
| 4005 | * @param resource $image gd image resource |
||
| 4006 | * @param string $bgcolor background color in #rrggbb format |
||
| 4007 | */ |
||
| 4008 | protected function gdImageBackground($image, $bgcolor){ |
||
| 4021 | |||
| 4022 | /*********************** misc *************************/ |
||
| 4023 | |||
| 4024 | /** |
||
| 4025 | * Return smart formatted date |
||
| 4026 | * |
||
| 4027 | * @param int $ts file timestamp |
||
| 4028 | * @return string |
||
| 4029 | * @author Dmitry (dio) Levashov |
||
| 4030 | **/ |
||
| 4031 | // protected function formatDate($ts) { |
||
| 4032 | // if ($ts > $this->today) { |
||
| 4033 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
| 4034 | // } |
||
| 4035 | // |
||
| 4036 | // if ($ts > $this->yesterday) { |
||
| 4037 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
| 4038 | // } |
||
| 4039 | // |
||
| 4040 | // return date($this->options['dateFormat'], $ts); |
||
| 4041 | // } |
||
| 4042 | |||
| 4043 | /** |
||
| 4044 | * Find position of first occurrence of string in a string with multibyte support |
||
| 4045 | * |
||
| 4046 | * @param string $haystack The string being checked. |
||
| 4047 | * @param string $needle The string to find in haystack. |
||
| 4048 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
| 4049 | * @return int|bool |
||
| 4050 | * @author Alexey Sukhotin |
||
| 4051 | **/ |
||
| 4052 | protected function stripos($haystack , $needle , $offset = 0) { |
||
| 4060 | |||
| 4061 | /** |
||
| 4062 | * Get server side available archivers |
||
| 4063 | * |
||
| 4064 | * @param bool $use_cache |
||
| 4065 | * @return array |
||
| 4066 | */ |
||
| 4067 | protected function getArchivers($use_cache = true) { |
||
| 4183 | |||
| 4184 | /** |
||
| 4185 | * Resolve relative / (Unix-like)absolute path |
||
| 4186 | * |
||
| 4187 | * @param string $path target path |
||
| 4188 | * @param string $base base path |
||
| 4189 | * @return string |
||
| 4190 | */ |
||
| 4191 | protected function getFullPath($path, $base) { |
||
| 4238 | |||
| 4239 | /** |
||
| 4240 | * Remove directory recursive on local file system |
||
| 4241 | * |
||
| 4242 | * @param string $dir Target dirctory path |
||
| 4243 | * @return boolean |
||
| 4244 | * @author Naoki Sawada |
||
| 4245 | */ |
||
| 4246 | public function rmdirRecursive($dir) { |
||
| 4266 | |||
| 4267 | /** |
||
| 4268 | * Create archive and return its path |
||
| 4269 | * |
||
| 4270 | * @param string $dir target dir |
||
| 4271 | * @param array $files files names list |
||
| 4272 | * @param string $name archive name |
||
| 4273 | * @param array $arc archiver options |
||
| 4274 | * @return string|bool |
||
| 4275 | * @author Dmitry (dio) Levashov, |
||
| 4276 | * @author Alexey Sukhotin |
||
| 4277 | * @author Naoki Sawada |
||
| 4278 | **/ |
||
| 4279 | protected function makeArchive($dir, $files, $name, $arc) { |
||
| 4297 | |||
| 4298 | /** |
||
| 4299 | * Unpack archive |
||
| 4300 | * |
||
| 4301 | * @param string $path archive path |
||
| 4302 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
| 4303 | * @param bool $remove remove archive ( unlink($path) ) |
||
| 4304 | * @return void |
||
| 4305 | * @author Dmitry (dio) Levashov |
||
| 4306 | * @author Alexey Sukhotin |
||
| 4307 | * @author Naoki Sawada |
||
| 4308 | **/ |
||
| 4309 | protected function unpackArchive($path, $arc, $remove = true) { |
||
| 4324 | |||
| 4325 | /** |
||
| 4326 | * Create Zip archive using PHP class ZipArchive |
||
| 4327 | * |
||
| 4328 | * @param string $dir target dir |
||
| 4329 | * @param array $files files names list |
||
| 4330 | * @param string|object $zipPath Zip archive name |
||
| 4331 | * @return void |
||
| 4332 | * @author Naoki Sawada |
||
| 4333 | */ |
||
| 4334 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
| 4372 | |||
| 4373 | /** |
||
| 4374 | * Unpack Zip archive using PHP class ZipArchive |
||
| 4375 | * |
||
| 4376 | * @param string $zipPath Zip archive name |
||
| 4377 | * @param string $toDir Extract to path |
||
| 4378 | * @return bool |
||
| 4379 | * @author Naoki Sawada |
||
| 4380 | */ |
||
| 4381 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
| 4393 | |||
| 4394 | /**==================================* abstract methods *====================================**/ |
||
| 4395 | |||
| 4396 | /*********************** paths/urls *************************/ |
||
| 4397 | |||
| 4398 | /** |
||
| 4399 | * Return parent directory path |
||
| 4400 | * |
||
| 4401 | * @param string $path file path |
||
| 4402 | * @return string |
||
| 4403 | * @author Dmitry (dio) Levashov |
||
| 4404 | **/ |
||
| 4405 | abstract protected function _dirname($path); |
||
| 4406 | |||
| 4407 | /** |
||
| 4408 | * Return file name |
||
| 4409 | * |
||
| 4410 | * @param string $path file path |
||
| 4411 | * @return string |
||
| 4412 | * @author Dmitry (dio) Levashov |
||
| 4413 | **/ |
||
| 4414 | abstract protected function _basename($path); |
||
| 4415 | |||
| 4416 | /** |
||
| 4417 | * Join dir name and file name and return full path. |
||
| 4418 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 4419 | * |
||
| 4420 | * @param string $dir dir path |
||
| 4421 | * @param string $name file name |
||
| 4422 | * @return string |
||
| 4423 | * @author Dmitry (dio) Levashov |
||
| 4424 | **/ |
||
| 4425 | abstract protected function _joinPath($dir, $name); |
||
| 4426 | |||
| 4427 | /** |
||
| 4428 | * Return normalized path |
||
| 4429 | * |
||
| 4430 | * @param string $path file path |
||
| 4431 | * @return string |
||
| 4432 | * @author Dmitry (dio) Levashov |
||
| 4433 | **/ |
||
| 4434 | abstract protected function _normpath($path); |
||
| 4435 | |||
| 4436 | /** |
||
| 4437 | * Return file path related to root dir |
||
| 4438 | * |
||
| 4439 | * @param string $path file path |
||
| 4440 | * @return string |
||
| 4441 | * @author Dmitry (dio) Levashov |
||
| 4442 | **/ |
||
| 4443 | abstract protected function _relpath($path); |
||
| 4444 | |||
| 4445 | /** |
||
| 4446 | * Convert path related to root dir into real path |
||
| 4447 | * |
||
| 4448 | * @param string $path rel file path |
||
| 4449 | * @return string |
||
| 4450 | * @author Dmitry (dio) Levashov |
||
| 4451 | **/ |
||
| 4452 | abstract protected function _abspath($path); |
||
| 4453 | |||
| 4454 | /** |
||
| 4455 | * Return fake path started from root dir. |
||
| 4456 | * Required to show path on client side. |
||
| 4457 | * |
||
| 4458 | * @param string $path file path |
||
| 4459 | * @return string |
||
| 4460 | * @author Dmitry (dio) Levashov |
||
| 4461 | **/ |
||
| 4462 | abstract protected function _path($path); |
||
| 4463 | |||
| 4464 | /** |
||
| 4465 | * Return true if $path is children of $parent |
||
| 4466 | * |
||
| 4467 | * @param string $path path to check |
||
| 4468 | * @param string $parent parent path |
||
| 4469 | * @return bool |
||
| 4470 | * @author Dmitry (dio) Levashov |
||
| 4471 | **/ |
||
| 4472 | abstract protected function _inpath($path, $parent); |
||
| 4473 | |||
| 4474 | /** |
||
| 4475 | * Return stat for given path. |
||
| 4476 | * Stat contains following fields: |
||
| 4477 | * - (int) size file size in b. required |
||
| 4478 | * - (int) ts file modification time in unix time. required |
||
| 4479 | * - (string) mime mimetype. required for folders, others - optionally |
||
| 4480 | * - (bool) read read permissions. required |
||
| 4481 | * - (bool) write write permissions. required |
||
| 4482 | * - (bool) locked is object locked. optionally |
||
| 4483 | * - (bool) hidden is object hidden. optionally |
||
| 4484 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
| 4485 | * - (string) target for symlinks - link target path. optionally |
||
| 4486 | * |
||
| 4487 | * If file does not exists - returns empty array or false. |
||
| 4488 | * |
||
| 4489 | * @param string $path file path |
||
| 4490 | * @return array|false |
||
| 4491 | * @author Dmitry (dio) Levashov |
||
| 4492 | **/ |
||
| 4493 | abstract protected function _stat($path); |
||
| 4494 | |||
| 4495 | |||
| 4496 | /***************** file stat ********************/ |
||
| 4497 | |||
| 4498 | |||
| 4499 | /** |
||
| 4500 | * Return true if path is dir and has at least one childs directory |
||
| 4501 | * |
||
| 4502 | * @param string $path dir path |
||
| 4503 | * @return bool |
||
| 4504 | * @author Dmitry (dio) Levashov |
||
| 4505 | **/ |
||
| 4506 | abstract protected function _subdirs($path); |
||
| 4507 | |||
| 4508 | /** |
||
| 4509 | * Return object width and height |
||
| 4510 | * Ususaly used for images, but can be realize for video etc... |
||
| 4511 | * |
||
| 4512 | * @param string $path file path |
||
| 4513 | * @param string $mime file mime type |
||
| 4514 | * @return string |
||
| 4515 | * @author Dmitry (dio) Levashov |
||
| 4516 | **/ |
||
| 4517 | abstract protected function _dimensions($path, $mime); |
||
| 4518 | |||
| 4519 | /******************** file/dir content *********************/ |
||
| 4520 | |||
| 4521 | /** |
||
| 4522 | * Return files list in directory |
||
| 4523 | * |
||
| 4524 | * @param string $path dir path |
||
| 4525 | * @return array |
||
| 4526 | * @author Dmitry (dio) Levashov |
||
| 4527 | **/ |
||
| 4528 | abstract protected function _scandir($path); |
||
| 4529 | |||
| 4530 | /** |
||
| 4531 | * Open file and return file pointer |
||
| 4532 | * |
||
| 4533 | * @param string $path file path |
||
| 4534 | * @param bool $write open file for writing |
||
| 4535 | * @return resource|false |
||
| 4536 | * @author Dmitry (dio) Levashov |
||
| 4537 | **/ |
||
| 4538 | abstract protected function _fopen($path, $mode="rb"); |
||
| 4539 | |||
| 4540 | /** |
||
| 4541 | * Close opened file |
||
| 4542 | * |
||
| 4543 | * @param resource $fp file pointer |
||
| 4544 | * @param string $path file path |
||
| 4545 | * @return bool |
||
| 4546 | * @author Dmitry (dio) Levashov |
||
| 4547 | **/ |
||
| 4548 | abstract protected function _fclose($fp, $path=''); |
||
| 4549 | |||
| 4550 | /******************** file/dir manipulations *************************/ |
||
| 4551 | |||
| 4552 | /** |
||
| 4553 | * Create dir and return created dir path or false on failed |
||
| 4554 | * |
||
| 4555 | * @param string $path parent dir path |
||
| 4556 | * @param string $name new directory name |
||
| 4557 | * @return string|bool |
||
| 4558 | * @author Dmitry (dio) Levashov |
||
| 4559 | **/ |
||
| 4560 | abstract protected function _mkdir($path, $name); |
||
| 4561 | |||
| 4562 | /** |
||
| 4563 | * Create file and return it's path or false on failed |
||
| 4564 | * |
||
| 4565 | * @param string $path parent dir path |
||
| 4566 | * @param string $name new file name |
||
| 4567 | * @return string|bool |
||
| 4568 | * @author Dmitry (dio) Levashov |
||
| 4569 | **/ |
||
| 4570 | abstract protected function _mkfile($path, $name); |
||
| 4571 | |||
| 4572 | /** |
||
| 4573 | * Create symlink |
||
| 4574 | * |
||
| 4575 | * @param string $source file to link to |
||
| 4576 | * @param string $targetDir folder to create link in |
||
| 4577 | * @param string $name symlink name |
||
| 4578 | * @return bool |
||
| 4579 | * @author Dmitry (dio) Levashov |
||
| 4580 | **/ |
||
| 4581 | abstract protected function _symlink($source, $targetDir, $name); |
||
| 4582 | |||
| 4583 | /** |
||
| 4584 | * Copy file into another file (only inside one volume) |
||
| 4585 | * |
||
| 4586 | * @param string $source source file path |
||
| 4587 | * @param string $target target dir path |
||
| 4588 | * @param string $name file name |
||
| 4589 | * @return bool |
||
| 4590 | * @author Dmitry (dio) Levashov |
||
| 4591 | **/ |
||
| 4592 | abstract protected function _copy($source, $targetDir, $name); |
||
| 4593 | |||
| 4594 | /** |
||
| 4595 | * Move file into another parent dir. |
||
| 4596 | * Return new file path or false. |
||
| 4597 | * |
||
| 4598 | * @param string $source source file path |
||
| 4599 | * @param string $target target dir path |
||
| 4600 | * @param string $name file name |
||
| 4601 | * @return string|bool |
||
| 4602 | * @author Dmitry (dio) Levashov |
||
| 4603 | **/ |
||
| 4604 | abstract protected function _move($source, $targetDir, $name); |
||
| 4605 | |||
| 4606 | /** |
||
| 4607 | * Remove file |
||
| 4608 | * |
||
| 4609 | * @param string $path file path |
||
| 4610 | * @return bool |
||
| 4611 | * @author Dmitry (dio) Levashov |
||
| 4612 | **/ |
||
| 4613 | abstract protected function _unlink($path); |
||
| 4614 | |||
| 4615 | /** |
||
| 4616 | * Remove dir |
||
| 4617 | * |
||
| 4618 | * @param string $path dir path |
||
| 4619 | * @return bool |
||
| 4620 | * @author Dmitry (dio) Levashov |
||
| 4621 | **/ |
||
| 4622 | abstract protected function _rmdir($path); |
||
| 4623 | |||
| 4624 | /** |
||
| 4625 | * Create new file and write into it from file pointer. |
||
| 4626 | * Return new file path or false on error. |
||
| 4627 | * |
||
| 4628 | * @param resource $fp file pointer |
||
| 4629 | * @param string $dir target dir path |
||
| 4630 | * @param string $name file name |
||
| 4631 | * @param array $stat file stat (required by some virtual fs) |
||
| 4632 | * @return bool|string |
||
| 4633 | * @author Dmitry (dio) Levashov |
||
| 4634 | **/ |
||
| 4635 | abstract protected function _save($fp, $dir, $name, $stat); |
||
| 4636 | |||
| 4637 | /** |
||
| 4638 | * Get file contents |
||
| 4639 | * |
||
| 4640 | * @param string $path file path |
||
| 4641 | * @return string|false |
||
| 4642 | * @author Dmitry (dio) Levashov |
||
| 4643 | **/ |
||
| 4644 | abstract protected function _getContents($path); |
||
| 4645 | |||
| 4646 | /** |
||
| 4647 | * Write a string to a file |
||
| 4648 | * |
||
| 4649 | * @param string $path file path |
||
| 4650 | * @param string $content new file content |
||
| 4651 | * @return bool |
||
| 4652 | * @author Dmitry (dio) Levashov |
||
| 4653 | **/ |
||
| 4654 | abstract protected function _filePutContents($path, $content); |
||
| 4655 | |||
| 4656 | /** |
||
| 4657 | * Extract files from archive |
||
| 4658 | * |
||
| 4659 | * @param string $path file path |
||
| 4660 | * @param array $arc archiver options |
||
| 4661 | * @return bool |
||
| 4662 | * @author Dmitry (dio) Levashov, |
||
| 4663 | * @author Alexey Sukhotin |
||
| 4664 | **/ |
||
| 4665 | abstract protected function _extract($path, $arc); |
||
| 4666 | |||
| 4667 | /** |
||
| 4668 | * Create archive and return its path |
||
| 4669 | * |
||
| 4670 | * @param string $dir target dir |
||
| 4671 | * @param array $files files names list |
||
| 4672 | * @param string $name archive name |
||
| 4673 | * @param array $arc archiver options |
||
| 4674 | * @return string|bool |
||
| 4675 | * @author Dmitry (dio) Levashov, |
||
| 4676 | * @author Alexey Sukhotin |
||
| 4677 | **/ |
||
| 4678 | abstract protected function _archive($dir, $files, $name, $arc); |
||
| 4679 | |||
| 4680 | /** |
||
| 4681 | * Detect available archivers |
||
| 4682 | * |
||
| 4683 | * @return void |
||
| 4684 | * @author Dmitry (dio) Levashov, |
||
| 4685 | * @author Alexey Sukhotin |
||
| 4686 | **/ |
||
| 4687 | abstract protected function _checkArchivers(); |
||
| 4688 | |||
| 4689 | /** |
||
| 4690 | * Change file mode (chmod) |
||
| 4691 | * |
||
| 4692 | * @param string $path file path |
||
| 4693 | * @param string $mode octal string such as '0755' |
||
| 4694 | * @return bool |
||
| 4695 | * @author David Bartle, |
||
| 4696 | **/ |
||
| 4697 | abstract protected function _chmod($path, $mode); |
||
| 4698 | |||
| 4699 | |||
| 4700 | } // END class |
||
|
2 ignored issues
–
show
|
|||
| 4701 |
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.