Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like elFinderVolumeDriver often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use elFinderVolumeDriver, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | abstract class elFinderVolumeDriver { |
||
|
|
|||
| 15 | |||
| 16 | /** |
||
| 17 | * Request args |
||
| 18 | * $_POST or $_GET values |
||
| 19 | * |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | protected $ARGS = array(); |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Driver id |
||
| 26 | * Must be started from letter and contains [a-z0-9] |
||
| 27 | * Used as part of volume id |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | **/ |
||
| 31 | protected $driverId = 'a'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Volume id - used as prefix for files hashes |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | **/ |
||
| 38 | protected $id = ''; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Flag - volume "mounted" and available |
||
| 42 | * |
||
| 43 | * @var bool |
||
| 44 | **/ |
||
| 45 | protected $mounted = false; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Root directory path |
||
| 49 | * |
||
| 50 | * @var string |
||
| 51 | **/ |
||
| 52 | protected $root = ''; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Root basename | alias |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | **/ |
||
| 59 | protected $rootName = ''; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Default directory to open |
||
| 63 | * |
||
| 64 | * @var string |
||
| 65 | **/ |
||
| 66 | protected $startPath = ''; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Base URL |
||
| 70 | * |
||
| 71 | * @var string |
||
| 72 | **/ |
||
| 73 | protected $URL = ''; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Thumbnails dir path |
||
| 77 | * |
||
| 78 | * @var string |
||
| 79 | **/ |
||
| 80 | protected $tmbPath = ''; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Is thumbnails dir writable |
||
| 84 | * |
||
| 85 | * @var bool |
||
| 86 | **/ |
||
| 87 | protected $tmbPathWritable = false; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Thumbnails base URL |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | **/ |
||
| 94 | protected $tmbURL = ''; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Thumbnails size in px |
||
| 98 | * |
||
| 99 | * @var int |
||
| 100 | **/ |
||
| 101 | protected $tmbSize = 48; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Image manipulation lib name |
||
| 105 | * auto|imagick|mogtify|gd |
||
| 106 | * |
||
| 107 | * @var string |
||
| 108 | **/ |
||
| 109 | protected $imgLib = 'auto'; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Library to crypt files name |
||
| 113 | * |
||
| 114 | * @var string |
||
| 115 | **/ |
||
| 116 | protected $cryptLib = ''; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Archivers config |
||
| 120 | * |
||
| 121 | * @var array |
||
| 122 | **/ |
||
| 123 | protected $archivers = array( |
||
| 124 | 'create' => array(), |
||
| 125 | 'extract' => array() |
||
| 126 | ); |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Server character encoding |
||
| 130 | * |
||
| 131 | * @var string or null |
||
| 132 | **/ |
||
| 133 | protected $encoding = null; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * How many subdirs levels return for tree |
||
| 137 | * |
||
| 138 | * @var int |
||
| 139 | **/ |
||
| 140 | protected $treeDeep = 1; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Errors from last failed action |
||
| 144 | * |
||
| 145 | * @var array |
||
| 146 | **/ |
||
| 147 | protected $error = array(); |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Today 24:00 timestamp |
||
| 151 | * |
||
| 152 | * @var int |
||
| 153 | **/ |
||
| 154 | protected $today = 0; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Yesterday 24:00 timestamp |
||
| 158 | * |
||
| 159 | * @var int |
||
| 160 | **/ |
||
| 161 | protected $yesterday = 0; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Force make dirctory on extract |
||
| 165 | * |
||
| 166 | * @var int |
||
| 167 | **/ |
||
| 168 | protected $extractToNewdir = 'auto'; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Object configuration |
||
| 172 | * |
||
| 173 | * @var array |
||
| 174 | **/ |
||
| 175 | protected $options = array( |
||
| 176 | 'id' => '', |
||
| 177 | // root directory path |
||
| 178 | 'path' => '', |
||
| 179 | // open this path on initial request instead of root path |
||
| 180 | 'startPath' => '', |
||
| 181 | // how many subdirs levels return per request |
||
| 182 | 'treeDeep' => 1, |
||
| 183 | // root url, not set to disable sending URL to client (replacement for old "fileURL" option) |
||
| 184 | 'URL' => '', |
||
| 185 | // directory separator. required by client to show paths correctly |
||
| 186 | 'separator' => DIRECTORY_SEPARATOR, |
||
| 187 | // Server character encoding (default is '': UTF-8) |
||
| 188 | 'encoding' => '', |
||
| 189 | // for convert character encoding (default is '': Not change locale) |
||
| 190 | 'locale' => '', |
||
| 191 | // URL of volume icon (16x16 pixel image file) |
||
| 192 | 'icon' => '', |
||
| 193 | // CSS Class of volume root in tree |
||
| 194 | 'rootCssClass' => '', |
||
| 195 | // library to crypt/uncrypt files names (not implemented) |
||
| 196 | 'cryptLib' => '', |
||
| 197 | // how to detect files mimetypes. (auto/internal/finfo/mime_content_type) |
||
| 198 | 'mimeDetect' => 'auto', |
||
| 199 | // mime.types file path (for mimeDetect==internal) |
||
| 200 | 'mimefile' => '', |
||
| 201 | // mime type normalize map : Array '[ext]:[detected mime type]' => '[normalized mime]' |
||
| 202 | 'mimeMap' => array( |
||
| 203 | 'md:application/x-genesis-rom' => 'text/x-markdown', |
||
| 204 | 'md:text/plain' => 'text/x-markdown', |
||
| 205 | 'markdown:text/plain' => 'text/x-markdown', |
||
| 206 | 'css:text/x-asm' => 'text/css' |
||
| 207 | ), |
||
| 208 | // MIME regex of send HTTP header "Content-Disposition: inline" |
||
| 209 | // '.' is allow inline of all of MIME types |
||
| 210 | // '$^' is not allow inline of all of MIME types |
||
| 211 | 'dispInlineRegex' => '^(?:(?:image|text)|application/x-shockwave-flash$)', |
||
| 212 | // directory for thumbnails |
||
| 213 | 'tmbPath' => '.tmb', |
||
| 214 | // mode to create thumbnails dir |
||
| 215 | 'tmbPathMode' => 0777, |
||
| 216 | // thumbnails dir URL. Set it if store thumbnails outside root directory |
||
| 217 | 'tmbURL' => '', |
||
| 218 | // thumbnails size (px) |
||
| 219 | 'tmbSize' => 48, |
||
| 220 | // thumbnails crop (true - crop, false - scale image to fit thumbnail size) |
||
| 221 | 'tmbCrop' => true, |
||
| 222 | // thumbnails background color (hex #rrggbb or 'transparent') |
||
| 223 | 'tmbBgColor' => '#ffffff', |
||
| 224 | // image manipulations library |
||
| 225 | 'imgLib' => 'auto', |
||
| 226 | // on paste file - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 227 | 'copyOverwrite' => true, |
||
| 228 | // if true - join new and old directories content on paste |
||
| 229 | 'copyJoin' => true, |
||
| 230 | // on upload - if true - old file will be replaced with new one, if false new file get name - original_name-number.ext |
||
| 231 | 'uploadOverwrite' => true, |
||
| 232 | // mimetypes allowed to upload |
||
| 233 | 'uploadAllow' => array(), |
||
| 234 | // mimetypes not allowed to upload |
||
| 235 | 'uploadDeny' => array(), |
||
| 236 | // order to proccess uploadAllow and uploadDeny options |
||
| 237 | 'uploadOrder' => array('deny', 'allow'), |
||
| 238 | // maximum upload file size. NOTE - this is size for every uploaded files |
||
| 239 | 'uploadMaxSize' => 0, |
||
| 240 | // files dates format |
||
| 241 | 'dateFormat' => 'j M Y H:i', |
||
| 242 | // files time format |
||
| 243 | 'timeFormat' => 'H:i', |
||
| 244 | // if true - every folder will be check for children folders, otherwise all folders will be marked as having subfolders |
||
| 245 | 'checkSubfolders' => true, |
||
| 246 | // allow to copy from this volume to other ones? |
||
| 247 | 'copyFrom' => true, |
||
| 248 | // allow to copy from other volumes to this one? |
||
| 249 | 'copyTo' => true, |
||
| 250 | // list of commands disabled on this root |
||
| 251 | 'disabled' => array(), |
||
| 252 | // enable file owner, group & mode info, `false` to inactivate "chmod" command. |
||
| 253 | 'statOwner' => false, |
||
| 254 | // allow exec chmod of read-only files |
||
| 255 | 'allowChmodReadOnly' => false, |
||
| 256 | // regexp or function name to validate new file name |
||
| 257 | 'acceptedName' => '/^[^\.].*/', //<-- DONT touch this! Use constructor options to overwrite it! |
||
| 258 | // function/class method to control files permissions |
||
| 259 | 'accessControl' => null, |
||
| 260 | // some data required by access control |
||
| 261 | 'accessControlData' => null, |
||
| 262 | // default permissions. |
||
| 263 | 'defaults' => array( |
||
| 264 | 'read' => true, |
||
| 265 | 'write' => true, |
||
| 266 | 'locked' => false, |
||
| 267 | 'hidden' => false |
||
| 268 | ), |
||
| 269 | // files attributes |
||
| 270 | 'attributes' => array(), |
||
| 271 | // Allowed archive's mimetypes to create. Leave empty for all available types. |
||
| 272 | 'archiveMimes' => array(), |
||
| 273 | // Manual config for archivers. See example below. Leave empty for auto detect |
||
| 274 | 'archivers' => array(), |
||
| 275 | // plugin settings |
||
| 276 | 'plugin' => array(), |
||
| 277 | // required to fix bug on macos |
||
| 278 | 'utf8fix' => false, |
||
| 279 | // й ё Й Ё Ø Å |
||
| 280 | 'utf8patterns' => array("\u0438\u0306", "\u0435\u0308", "\u0418\u0306", "\u0415\u0308", "\u00d8A", "\u030a"), |
||
| 281 | 'utf8replace' => array("\u0439", "\u0451", "\u0419", "\u0401", "\u00d8", "\u00c5") |
||
| 282 | ); |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Defaults permissions |
||
| 286 | * |
||
| 287 | * @var array |
||
| 288 | **/ |
||
| 289 | protected $defaults = array( |
||
| 290 | 'read' => true, |
||
| 291 | 'write' => true, |
||
| 292 | 'locked' => false, |
||
| 293 | 'hidden' => false |
||
| 294 | ); |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Access control function/class |
||
| 298 | * |
||
| 299 | * @var mixed |
||
| 300 | **/ |
||
| 301 | protected $attributes = array(); |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Access control function/class |
||
| 305 | * |
||
| 306 | * @var mixed |
||
| 307 | **/ |
||
| 308 | protected $access = null; |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Mime types allowed to upload |
||
| 312 | * |
||
| 313 | * @var array |
||
| 314 | **/ |
||
| 315 | protected $uploadAllow = array(); |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Mime types denied to upload |
||
| 319 | * |
||
| 320 | * @var array |
||
| 321 | **/ |
||
| 322 | protected $uploadDeny = array(); |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Order to validate uploadAllow and uploadDeny |
||
| 326 | * |
||
| 327 | * @var array |
||
| 328 | **/ |
||
| 329 | protected $uploadOrder = array(); |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Maximum allowed upload file size. |
||
| 333 | * Set as number or string with unit - "10M", "500K", "1G" |
||
| 334 | * |
||
| 335 | * @var int|string |
||
| 336 | **/ |
||
| 337 | protected $uploadMaxSize = 0; |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Mimetype detect method |
||
| 341 | * |
||
| 342 | * @var string |
||
| 343 | **/ |
||
| 344 | protected $mimeDetect = 'auto'; |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Flag - mimetypes from externail file was loaded |
||
| 348 | * |
||
| 349 | * @var bool |
||
| 350 | **/ |
||
| 351 | private static $mimetypesLoaded = false; |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Finfo object for mimeDetect == 'finfo' |
||
| 355 | * |
||
| 356 | * @var object |
||
| 357 | **/ |
||
| 358 | protected $finfo = null; |
||
| 359 | |||
| 360 | /** |
||
| 361 | * List of disabled client's commands |
||
| 362 | * |
||
| 363 | * @var array |
||
| 364 | **/ |
||
| 365 | protected $disabled = array(); |
||
| 366 | |||
| 367 | /** |
||
| 368 | * default extensions/mimetypes for mimeDetect == 'internal' |
||
| 369 | * |
||
| 370 | * @var array |
||
| 371 | **/ |
||
| 372 | protected static $mimetypes = array( |
||
| 373 | // applications |
||
| 374 | 'ai' => 'application/postscript', |
||
| 375 | 'eps' => 'application/postscript', |
||
| 376 | 'exe' => 'application/x-executable', |
||
| 377 | 'doc' => 'application/msword', |
||
| 378 | 'dot' => 'application/msword', |
||
| 379 | 'xls' => 'application/vnd.ms-excel', |
||
| 380 | 'xlt' => 'application/vnd.ms-excel', |
||
| 381 | 'xla' => 'application/vnd.ms-excel', |
||
| 382 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
| 383 | 'pps' => 'application/vnd.ms-powerpoint', |
||
| 384 | 'pdf' => 'application/pdf', |
||
| 385 | 'xml' => 'application/xml', |
||
| 386 | 'swf' => 'application/x-shockwave-flash', |
||
| 387 | 'torrent' => 'application/x-bittorrent', |
||
| 388 | 'jar' => 'application/x-jar', |
||
| 389 | // open office (finfo detect as application/zip) |
||
| 390 | 'odt' => 'application/vnd.oasis.opendocument.text', |
||
| 391 | 'ott' => 'application/vnd.oasis.opendocument.text-template', |
||
| 392 | 'oth' => 'application/vnd.oasis.opendocument.text-web', |
||
| 393 | 'odm' => 'application/vnd.oasis.opendocument.text-master', |
||
| 394 | 'odg' => 'application/vnd.oasis.opendocument.graphics', |
||
| 395 | 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
||
| 396 | 'odp' => 'application/vnd.oasis.opendocument.presentation', |
||
| 397 | 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
||
| 398 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
||
| 399 | 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
||
| 400 | 'odc' => 'application/vnd.oasis.opendocument.chart', |
||
| 401 | 'odf' => 'application/vnd.oasis.opendocument.formula', |
||
| 402 | 'odb' => 'application/vnd.oasis.opendocument.database', |
||
| 403 | 'odi' => 'application/vnd.oasis.opendocument.image', |
||
| 404 | 'oxt' => 'application/vnd.openofficeorg.extension', |
||
| 405 | // MS office 2007 (finfo detect as application/zip) |
||
| 406 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
||
| 407 | 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
||
| 408 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
||
| 409 | 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
||
| 410 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
||
| 411 | 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
||
| 412 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
||
| 413 | 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
||
| 414 | 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
||
| 415 | 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
||
| 416 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
||
| 417 | 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
||
| 418 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
||
| 419 | 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
||
| 420 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
||
| 421 | 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
||
| 422 | 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
||
| 423 | 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
||
| 424 | 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
||
| 425 | // archives |
||
| 426 | 'gz' => 'application/x-gzip', |
||
| 427 | 'tgz' => 'application/x-gzip', |
||
| 428 | 'bz' => 'application/x-bzip2', |
||
| 429 | 'bz2' => 'application/x-bzip2', |
||
| 430 | 'tbz' => 'application/x-bzip2', |
||
| 431 | 'xz' => 'application/x-xz', |
||
| 432 | 'zip' => 'application/zip', |
||
| 433 | 'rar' => 'application/x-rar', |
||
| 434 | 'tar' => 'application/x-tar', |
||
| 435 | '7z' => 'application/x-7z-compressed', |
||
| 436 | // texts |
||
| 437 | 'txt' => 'text/plain', |
||
| 438 | 'php' => 'text/x-php', |
||
| 439 | 'html' => 'text/html', |
||
| 440 | 'htm' => 'text/html', |
||
| 441 | 'js' => 'text/javascript', |
||
| 442 | 'css' => 'text/css', |
||
| 443 | 'rtf' => 'text/rtf', |
||
| 444 | 'rtfd' => 'text/rtfd', |
||
| 445 | 'py' => 'text/x-python', |
||
| 446 | 'java' => 'text/x-java-source', |
||
| 447 | 'rb' => 'text/x-ruby', |
||
| 448 | 'sh' => 'text/x-shellscript', |
||
| 449 | 'pl' => 'text/x-perl', |
||
| 450 | 'xml' => 'text/xml', |
||
| 451 | 'sql' => 'text/x-sql', |
||
| 452 | 'c' => 'text/x-csrc', |
||
| 453 | 'h' => 'text/x-chdr', |
||
| 454 | 'cpp' => 'text/x-c++src', |
||
| 455 | 'hh' => 'text/x-c++hdr', |
||
| 456 | 'log' => 'text/plain', |
||
| 457 | 'csv' => 'text/x-comma-separated-values', |
||
| 458 | 'md' => 'text/x-markdown', |
||
| 459 | 'markdown' => 'text/x-markdown', |
||
| 460 | // images |
||
| 461 | 'bmp' => 'image/x-ms-bmp', |
||
| 462 | 'jpg' => 'image/jpeg', |
||
| 463 | 'jpeg' => 'image/jpeg', |
||
| 464 | 'gif' => 'image/gif', |
||
| 465 | 'png' => 'image/png', |
||
| 466 | 'tif' => 'image/tiff', |
||
| 467 | 'tiff' => 'image/tiff', |
||
| 468 | 'tga' => 'image/x-targa', |
||
| 469 | 'psd' => 'image/vnd.adobe.photoshop', |
||
| 470 | 'ai' => 'image/vnd.adobe.photoshop', |
||
| 471 | 'xbm' => 'image/xbm', |
||
| 472 | 'pxm' => 'image/pxm', |
||
| 473 | //audio |
||
| 474 | 'mp3' => 'audio/mpeg', |
||
| 475 | 'mid' => 'audio/midi', |
||
| 476 | 'ogg' => 'audio/ogg', |
||
| 477 | 'oga' => 'audio/ogg', |
||
| 478 | 'm4a' => 'audio/x-m4a', |
||
| 479 | 'wav' => 'audio/wav', |
||
| 480 | 'wma' => 'audio/x-ms-wma', |
||
| 481 | // video |
||
| 482 | 'avi' => 'video/x-msvideo', |
||
| 483 | 'dv' => 'video/x-dv', |
||
| 484 | 'mp4' => 'video/mp4', |
||
| 485 | 'mpeg' => 'video/mpeg', |
||
| 486 | 'mpg' => 'video/mpeg', |
||
| 487 | 'mov' => 'video/quicktime', |
||
| 488 | 'wm' => 'video/x-ms-wmv', |
||
| 489 | 'flv' => 'video/x-flv', |
||
| 490 | 'mkv' => 'video/x-matroska', |
||
| 491 | 'webm' => 'video/webm', |
||
| 492 | 'ogv' => 'video/ogg', |
||
| 493 | 'ogm' => 'video/ogg' |
||
| 494 | ); |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Directory separator - required by client |
||
| 498 | * |
||
| 499 | * @var string |
||
| 500 | **/ |
||
| 501 | protected $separator = DIRECTORY_SEPARATOR; |
||
| 502 | |||
| 503 | /** |
||
| 504 | * System Root path (Unix like: '/', Windows: '\', 'C:\' or 'D:\'...) |
||
| 505 | * |
||
| 506 | * @var string |
||
| 507 | **/ |
||
| 508 | protected $systemRoot = DIRECTORY_SEPARATOR; |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Mimetypes allowed to display |
||
| 512 | * |
||
| 513 | * @var array |
||
| 514 | **/ |
||
| 515 | protected $onlyMimes = array(); |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Store files moved or overwrited files info |
||
| 519 | * |
||
| 520 | * @var array |
||
| 521 | **/ |
||
| 522 | protected $removed = array(); |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Cache storage |
||
| 526 | * |
||
| 527 | * @var array |
||
| 528 | **/ |
||
| 529 | protected $cache = array(); |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Cache by folders |
||
| 533 | * |
||
| 534 | * @var array |
||
| 535 | **/ |
||
| 536 | protected $dirsCache = array(); |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Cache for subdirsCE() |
||
| 540 | * |
||
| 541 | * @var array |
||
| 542 | */ |
||
| 543 | protected $subdirsCache = array(); |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Reference of $_SESSION[elFinder::$sessionCacheKey][$this->id] |
||
| 547 | * |
||
| 548 | * @var array |
||
| 549 | */ |
||
| 550 | protected $sessionCache; |
||
| 551 | |||
| 552 | /*********************************************************************/ |
||
| 553 | /* INITIALIZATION */ |
||
| 554 | /*********************************************************************/ |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Prepare driver before mount volume. |
||
| 558 | * Return true if volume is ready. |
||
| 559 | * |
||
| 560 | * @return bool |
||
| 561 | * @author Dmitry (dio) Levashov |
||
| 562 | **/ |
||
| 563 | protected function init() { |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Configure after successfull mount. |
||
| 569 | * By default set thumbnails path and image manipulation library. |
||
| 570 | * |
||
| 571 | * @return void |
||
| 572 | * @author Dmitry (dio) Levashov |
||
| 573 | **/ |
||
| 574 | protected function configure() { |
||
| 615 | |||
| 616 | |||
| 617 | /*********************************************************************/ |
||
| 618 | /* PUBLIC API */ |
||
| 619 | /*********************************************************************/ |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Return driver id. Used as a part of volume id. |
||
| 623 | * |
||
| 624 | * @return string |
||
| 625 | * @author Dmitry (dio) Levashov |
||
| 626 | **/ |
||
| 627 | public function driverId() { |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Return volume id |
||
| 633 | * |
||
| 634 | * @return string |
||
| 635 | * @author Dmitry (dio) Levashov |
||
| 636 | **/ |
||
| 637 | public function id() { |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Return debug info for client |
||
| 643 | * |
||
| 644 | * @return array |
||
| 645 | * @author Dmitry (dio) Levashov |
||
| 646 | **/ |
||
| 647 | public function debug() { |
||
| 655 | |||
| 656 | /** |
||
| 657 | * chmod a file or folder |
||
| 658 | * |
||
| 659 | * @param string $hash file or folder hash to chmod |
||
| 660 | * @param string $mode octal string representing new permissions |
||
| 661 | * @return array|false |
||
| 662 | * @author David Bartle |
||
| 663 | **/ |
||
| 664 | public function chmod($hash, $mode) { |
||
| 701 | |||
| 702 | /** |
||
| 703 | * "Mount" volume. |
||
| 704 | * Return true if volume available for read or write, |
||
| 705 | * false - otherwise |
||
| 706 | * |
||
| 707 | * @return bool |
||
| 708 | * @author Dmitry (dio) Levashov |
||
| 709 | * @author Alexey Sukhotin |
||
| 710 | **/ |
||
| 711 | public function mount(array $opts) { |
||
| 974 | |||
| 975 | /** |
||
| 976 | * Some "unmount" stuffs - may be required by virtual fs |
||
| 977 | * |
||
| 978 | * @return void |
||
| 979 | * @author Dmitry (dio) Levashov |
||
| 980 | **/ |
||
| 981 | public function umount() { |
||
| 983 | |||
| 984 | /** |
||
| 985 | * Return error message from last failed action |
||
| 986 | * |
||
| 987 | * @return array |
||
| 988 | * @author Dmitry (dio) Levashov |
||
| 989 | **/ |
||
| 990 | public function error() { |
||
| 993 | |||
| 994 | /** |
||
| 995 | * Return Extention/MIME Table (elFinderVolumeDriver::$mimetypes) |
||
| 996 | * |
||
| 997 | * @return array |
||
| 998 | * @author Naoki Sawada |
||
| 999 | */ |
||
| 1000 | public function getMimeTable() { |
||
| 1003 | |||
| 1004 | /** |
||
| 1005 | * Set mimetypes allowed to display to client |
||
| 1006 | * |
||
| 1007 | * @param array $mimes |
||
| 1008 | * @return void |
||
| 1009 | * @author Dmitry (dio) Levashov |
||
| 1010 | **/ |
||
| 1011 | public function setMimesFilter($mimes) { |
||
| 1016 | |||
| 1017 | /** |
||
| 1018 | * Return root folder hash |
||
| 1019 | * |
||
| 1020 | * @return string |
||
| 1021 | * @author Dmitry (dio) Levashov |
||
| 1022 | **/ |
||
| 1023 | public function root() { |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * Return target path hash |
||
| 1029 | * |
||
| 1030 | * @param string $path |
||
| 1031 | * @param string $name |
||
| 1032 | * @author Naoki Sawada |
||
| 1033 | */ |
||
| 1034 | public function getHash($path, $name = '') { |
||
| 1040 | |||
| 1041 | /** |
||
| 1042 | * Return root or startPath hash |
||
| 1043 | * |
||
| 1044 | * @return string |
||
| 1045 | * @author Dmitry (dio) Levashov |
||
| 1046 | **/ |
||
| 1047 | public function defaultPath() { |
||
| 1050 | |||
| 1051 | /** |
||
| 1052 | * Return volume options required by client: |
||
| 1053 | * |
||
| 1054 | * @return array |
||
| 1055 | * @author Dmitry (dio) Levashov |
||
| 1056 | **/ |
||
| 1057 | public function options($hash) { |
||
| 1083 | |||
| 1084 | /** |
||
| 1085 | * Get option value of this volume |
||
| 1086 | * |
||
| 1087 | * @param string $name target option name |
||
| 1088 | * @return NULL|mixed target option value |
||
| 1089 | * @author Naoki Sawada |
||
| 1090 | */ |
||
| 1091 | public function getOption($name) { |
||
| 1094 | |||
| 1095 | /** |
||
| 1096 | * Get plugin values of this options |
||
| 1097 | * |
||
| 1098 | * @param string $name Plugin name |
||
| 1099 | * @return NULL|array Plugin values |
||
| 1100 | * @author Naoki Sawada |
||
| 1101 | */ |
||
| 1102 | public function getOptionsPlugin($name = '') { |
||
| 1109 | |||
| 1110 | /** |
||
| 1111 | * Return true if command disabled in options |
||
| 1112 | * |
||
| 1113 | * @param string $cmd command name |
||
| 1114 | * @return bool |
||
| 1115 | * @author Dmitry (dio) Levashov |
||
| 1116 | **/ |
||
| 1117 | public function commandDisabled($cmd) { |
||
| 1120 | |||
| 1121 | /** |
||
| 1122 | * Return true if mime is required mimes list |
||
| 1123 | * |
||
| 1124 | * @param string $mime mime type to check |
||
| 1125 | * @param array $mimes allowed mime types list or not set to use client mimes list |
||
| 1126 | * @param bool|null $empty what to return on empty list |
||
| 1127 | * @return bool|null |
||
| 1128 | * @author Dmitry (dio) Levashov |
||
| 1129 | * @author Troex Nevelin |
||
| 1130 | **/ |
||
| 1131 | public function mimeAccepted($mime, $mimes = null, $empty = true) { |
||
| 1142 | |||
| 1143 | /** |
||
| 1144 | * Return true if voume is readable. |
||
| 1145 | * |
||
| 1146 | * @return bool |
||
| 1147 | * @author Dmitry (dio) Levashov |
||
| 1148 | **/ |
||
| 1149 | public function isReadable() { |
||
| 1153 | |||
| 1154 | /** |
||
| 1155 | * Return true if copy from this volume allowed |
||
| 1156 | * |
||
| 1157 | * @return bool |
||
| 1158 | * @author Dmitry (dio) Levashov |
||
| 1159 | **/ |
||
| 1160 | public function copyFromAllowed() { |
||
| 1163 | |||
| 1164 | /** |
||
| 1165 | * Return file path related to root with convert encoging |
||
| 1166 | * |
||
| 1167 | * @param string $hash file hash |
||
| 1168 | * @return string |
||
| 1169 | * @author Dmitry (dio) Levashov |
||
| 1170 | **/ |
||
| 1171 | public function path($hash) { |
||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * Return file real path if file exists |
||
| 1177 | * |
||
| 1178 | * @param string $hash file hash |
||
| 1179 | * @return string |
||
| 1180 | * @author Dmitry (dio) Levashov |
||
| 1181 | **/ |
||
| 1182 | public function realpath($hash) { |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Return list of moved/overwrited files |
||
| 1189 | * |
||
| 1190 | * @return array |
||
| 1191 | * @author Dmitry (dio) Levashov |
||
| 1192 | **/ |
||
| 1193 | public function removed() { |
||
| 1196 | |||
| 1197 | /** |
||
| 1198 | * Clean removed files list |
||
| 1199 | * |
||
| 1200 | * @return void |
||
| 1201 | * @author Dmitry (dio) Levashov |
||
| 1202 | **/ |
||
| 1203 | public function resetRemoved() { |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Return file/dir hash or first founded child hash with required attr == $val |
||
| 1209 | * |
||
| 1210 | * @param string $hash file hash |
||
| 1211 | * @param string $attr attribute name |
||
| 1212 | * @param bool $val attribute value |
||
| 1213 | * @return string|false |
||
| 1214 | * @author Dmitry (dio) Levashov |
||
| 1215 | **/ |
||
| 1216 | public function closest($hash, $attr, $val) { |
||
| 1219 | |||
| 1220 | /** |
||
| 1221 | * Return file info or false on error |
||
| 1222 | * |
||
| 1223 | * @param string $hash file hash |
||
| 1224 | * @param bool $realpath add realpath field to file info |
||
| 1225 | * @return array|false |
||
| 1226 | * @author Dmitry (dio) Levashov |
||
| 1227 | **/ |
||
| 1228 | public function file($hash) { |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Return folder info |
||
| 1243 | * |
||
| 1244 | * @param string $hash folder hash |
||
| 1245 | * @param bool $hidden return hidden file info |
||
| 1246 | * @return array|false |
||
| 1247 | * @author Dmitry (dio) Levashov |
||
| 1248 | **/ |
||
| 1249 | public function dir($hash, $resolveLink=false) { |
||
| 1262 | |||
| 1263 | /** |
||
| 1264 | * Return directory content or false on error |
||
| 1265 | * |
||
| 1266 | * @param string $hash file hash |
||
| 1267 | * @return array|false |
||
| 1268 | * @author Dmitry (dio) Levashov |
||
| 1269 | **/ |
||
| 1270 | public function scandir($hash) { |
||
| 1279 | |||
| 1280 | /** |
||
| 1281 | * Return dir files names list |
||
| 1282 | * |
||
| 1283 | * @param string $hash file hash |
||
| 1284 | * @return array |
||
| 1285 | * @author Dmitry (dio) Levashov |
||
| 1286 | **/ |
||
| 1287 | public function ls($hash) { |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Return subfolders for required folder or false on error |
||
| 1306 | * |
||
| 1307 | * @param string $hash folder hash or empty string to get tree from root folder |
||
| 1308 | * @param int $deep subdir deep |
||
| 1309 | * @param string $exclude dir hash which subfolders must be exluded from result, required to not get stat twice on cwd subfolders |
||
| 1310 | * @return array|false |
||
| 1311 | * @author Dmitry (dio) Levashov |
||
| 1312 | **/ |
||
| 1313 | public function tree($hash='', $deep=0, $exclude='') { |
||
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Return part of dirs tree from required dir up to root dir |
||
| 1327 | * |
||
| 1328 | * @param string $hash directory hash |
||
| 1329 | * @param bool|null $lineal only lineal parents |
||
| 1330 | * @return array |
||
| 1331 | * @author Dmitry (dio) Levashov |
||
| 1332 | **/ |
||
| 1333 | public function parents($hash, $lineal = false) { |
||
| 1360 | |||
| 1361 | /** |
||
| 1362 | * Create thumbnail for required file and return its name of false on failed |
||
| 1363 | * |
||
| 1364 | * @return string|false |
||
| 1365 | * @author Dmitry (dio) Levashov |
||
| 1366 | **/ |
||
| 1367 | public function tmb($hash) { |
||
| 1376 | |||
| 1377 | /** |
||
| 1378 | * Return file size / total directory size |
||
| 1379 | * |
||
| 1380 | * @param string file hash |
||
| 1381 | * @return int |
||
| 1382 | * @author Dmitry (dio) Levashov |
||
| 1383 | **/ |
||
| 1384 | public function size($hash) { |
||
| 1387 | |||
| 1388 | /** |
||
| 1389 | * Open file for reading and return file pointer |
||
| 1390 | * |
||
| 1391 | * @param string file hash |
||
| 1392 | * @return Resource |
||
| 1393 | * @author Dmitry (dio) Levashov |
||
| 1394 | **/ |
||
| 1395 | public function open($hash) { |
||
| 1403 | |||
| 1404 | /** |
||
| 1405 | * Close file pointer |
||
| 1406 | * |
||
| 1407 | * @param Resource $fp file pointer |
||
| 1408 | * @param string $hash file hash |
||
| 1409 | * @return void |
||
| 1410 | * @author Dmitry (dio) Levashov |
||
| 1411 | **/ |
||
| 1412 | public function close($fp, $hash) { |
||
| 1415 | |||
| 1416 | /** |
||
| 1417 | * Create directory and return dir info |
||
| 1418 | * |
||
| 1419 | * @param string $dsthash destination directory hash |
||
| 1420 | * @param string $name directory name |
||
| 1421 | * @return array|false |
||
| 1422 | * @author Dmitry (dio) Levashov |
||
| 1423 | **/ |
||
| 1424 | public function mkdir($dsthash, $name) { |
||
| 1451 | |||
| 1452 | /** |
||
| 1453 | * Create empty file and return its info |
||
| 1454 | * |
||
| 1455 | * @param string $dst destination directory |
||
| 1456 | * @param string $name file name |
||
| 1457 | * @return array|false |
||
| 1458 | * @author Dmitry (dio) Levashov |
||
| 1459 | **/ |
||
| 1460 | public function mkfile($dst, $name) { |
||
| 1486 | |||
| 1487 | /** |
||
| 1488 | * Rename file and return file info |
||
| 1489 | * |
||
| 1490 | * @param string $hash file hash |
||
| 1491 | * @param string $name new file name |
||
| 1492 | * @return array|false |
||
| 1493 | * @author Dmitry (dio) Levashov |
||
| 1494 | **/ |
||
| 1495 | public function rename($hash, $name) { |
||
| 1541 | |||
| 1542 | /** |
||
| 1543 | * Create file copy with suffix "copy number" and return its info |
||
| 1544 | * |
||
| 1545 | * @param string $hash file hash |
||
| 1546 | * @param string $suffix suffix to add to file name |
||
| 1547 | * @return array|false |
||
| 1548 | * @author Dmitry (dio) Levashov |
||
| 1549 | **/ |
||
| 1550 | public function duplicate($hash, $suffix='copy') { |
||
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Save uploaded file. |
||
| 1574 | * On success return array with new file stat and with removed file hash (if existed file was replaced) |
||
| 1575 | * |
||
| 1576 | * @param Resource $fp file pointer |
||
| 1577 | * @param string $dst destination folder hash |
||
| 1578 | * @param string $src file name |
||
| 1579 | * @param string $tmpname file tmp name - required to detect mime type |
||
| 1580 | * @return array|false |
||
| 1581 | * @author Dmitry (dio) Levashov |
||
| 1582 | **/ |
||
| 1583 | public function upload($fp, $dst, $name, $tmpname) { |
||
| 1659 | |||
| 1660 | /** |
||
| 1661 | * Paste files |
||
| 1662 | * |
||
| 1663 | * @param Object $volume source volume |
||
| 1664 | * @param string $source file hash |
||
| 1665 | * @param string $dst destination dir hash |
||
| 1666 | * @param bool $rmSrc remove source after copy? |
||
| 1667 | * @return array|false |
||
| 1668 | * @author Dmitry (dio) Levashov |
||
| 1669 | **/ |
||
| 1670 | public function paste($volume, $src, $dst, $rmSrc = false) { |
||
| 1758 | |||
| 1759 | /** |
||
| 1760 | * Return file contents |
||
| 1761 | * |
||
| 1762 | * @param string $hash file hash |
||
| 1763 | * @return string|false |
||
| 1764 | * @author Dmitry (dio) Levashov |
||
| 1765 | **/ |
||
| 1766 | public function getContents($hash) { |
||
| 1783 | |||
| 1784 | /** |
||
| 1785 | * Put content in text file and return file info. |
||
| 1786 | * |
||
| 1787 | * @param string $hash file hash |
||
| 1788 | * @param string $content new file content |
||
| 1789 | * @return array |
||
| 1790 | * @author Dmitry (dio) Levashov |
||
| 1791 | **/ |
||
| 1792 | public function putContents($hash, $content) { |
||
| 1827 | |||
| 1828 | /** |
||
| 1829 | * Extract files from archive |
||
| 1830 | * |
||
| 1831 | * @param string $hash archive hash |
||
| 1832 | * @return array|bool |
||
| 1833 | * @author Dmitry (dio) Levashov, |
||
| 1834 | * @author Alexey Sukhotin |
||
| 1835 | **/ |
||
| 1836 | public function extract($hash, $makedir = null) { |
||
| 1875 | |||
| 1876 | /** |
||
| 1877 | * Add files to archive |
||
| 1878 | * |
||
| 1879 | * @return void |
||
| 1880 | **/ |
||
| 1881 | public function archive($hashes, $mime, $name = '') { |
||
| 1925 | |||
| 1926 | /** |
||
| 1927 | * Resize image |
||
| 1928 | * |
||
| 1929 | * @param string $hash image file |
||
| 1930 | * @param int $width new width |
||
| 1931 | * @param int $height new height |
||
| 1932 | * @param int $x X start poistion for crop |
||
| 1933 | * @param int $y Y start poistion for crop |
||
| 1934 | * @param string $mode action how to mainpulate image |
||
| 1935 | * @return array|false |
||
| 1936 | * @author Dmitry (dio) Levashov |
||
| 1937 | * @author Alexey Sukhotin |
||
| 1938 | * @author nao-pon |
||
| 1939 | * @author Troex Nevelin |
||
| 1940 | **/ |
||
| 1941 | public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0) { |
||
| 2028 | |||
| 2029 | /** |
||
| 2030 | * Remove file/dir |
||
| 2031 | * |
||
| 2032 | * @param string $hash file hash |
||
| 2033 | * @return bool |
||
| 2034 | * @author Dmitry (dio) Levashov |
||
| 2035 | **/ |
||
| 2036 | public function rm($hash) { |
||
| 2041 | |||
| 2042 | /** |
||
| 2043 | * Search files |
||
| 2044 | * |
||
| 2045 | * @param string $q search string |
||
| 2046 | * @param array $mimes |
||
| 2047 | * @return array |
||
| 2048 | * @author Dmitry (dio) Levashov |
||
| 2049 | **/ |
||
| 2050 | public function search($q, $mimes, $hash = null) { |
||
| 2069 | |||
| 2070 | /** |
||
| 2071 | * Return image dimensions |
||
| 2072 | * |
||
| 2073 | * @param string $hash file hash |
||
| 2074 | * @return array |
||
| 2075 | * @author Dmitry (dio) Levashov |
||
| 2076 | **/ |
||
| 2077 | public function dimensions($hash) { |
||
| 2084 | |||
| 2085 | /** |
||
| 2086 | * Return content URL (for netmout volume driver) |
||
| 2087 | * If file.url == 1 requests from JavaScript client with XHR |
||
| 2088 | * |
||
| 2089 | * @param string $hash file hash |
||
| 2090 | * @param array $options options array |
||
| 2091 | * @return boolean|string |
||
| 2092 | * @author Naoki Sawada |
||
| 2093 | */ |
||
| 2094 | public function getContentUrl($hash, $options = array()) { |
||
| 2100 | |||
| 2101 | /** |
||
| 2102 | * Return temp path |
||
| 2103 | * |
||
| 2104 | * @return string |
||
| 2105 | * @author Naoki Sawada |
||
| 2106 | */ |
||
| 2107 | public function getTempPath() { |
||
| 2120 | |||
| 2121 | /** |
||
| 2122 | * (Make &) Get upload taget dirctory hash |
||
| 2123 | * |
||
| 2124 | * @param string $baseTargetHash |
||
| 2125 | * @param string $path |
||
| 2126 | * @param array $result |
||
| 2127 | * @return boolean|string |
||
| 2128 | * @author Naoki Sawada |
||
| 2129 | */ |
||
| 2130 | public function getUploadTaget($baseTargetHash, $path, & $result) { |
||
| 2157 | |||
| 2158 | /** |
||
| 2159 | * Return this uploadMaxSize value |
||
| 2160 | * |
||
| 2161 | * @return integer |
||
| 2162 | * @author Naoki Sawada |
||
| 2163 | */ |
||
| 2164 | public function getUploadMaxSize() { |
||
| 2167 | |||
| 2168 | /** |
||
| 2169 | * Save error message |
||
| 2170 | * |
||
| 2171 | * @param array error |
||
| 2172 | * @return false |
||
| 2173 | * @author Dmitry(dio) Levashov |
||
| 2174 | **/ |
||
| 2175 | protected function setError($error) { |
||
| 2190 | |||
| 2191 | /*********************************************************************/ |
||
| 2192 | /* FS API */ |
||
| 2193 | /*********************************************************************/ |
||
| 2194 | |||
| 2195 | /***************** server encoding support *******************/ |
||
| 2196 | |||
| 2197 | /** |
||
| 2198 | * Return parent directory path (with convert encording) |
||
| 2199 | * |
||
| 2200 | * @param string $path file path |
||
| 2201 | * @return string |
||
| 2202 | * @author Naoki Sawada |
||
| 2203 | **/ |
||
| 2204 | protected function dirnameCE($path) { |
||
| 2207 | |||
| 2208 | /** |
||
| 2209 | * Return file name (with convert encording) |
||
| 2210 | * |
||
| 2211 | * @param string $path file path |
||
| 2212 | * @return string |
||
| 2213 | * @author Naoki Sawada |
||
| 2214 | **/ |
||
| 2215 | protected function basenameCE($path) { |
||
| 2218 | |||
| 2219 | /** |
||
| 2220 | * Join dir name and file name and return full path. (with convert encording) |
||
| 2221 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 2222 | * |
||
| 2223 | * @param string $dir dir path |
||
| 2224 | * @param string $name file name |
||
| 2225 | * @return string |
||
| 2226 | * @author Naoki Sawada |
||
| 2227 | **/ |
||
| 2228 | protected function joinPathCE($dir, $name) { |
||
| 2231 | |||
| 2232 | /** |
||
| 2233 | * Return normalized path (with convert encording) |
||
| 2234 | * |
||
| 2235 | * @param string $path file path |
||
| 2236 | * @return string |
||
| 2237 | * @author Naoki Sawada |
||
| 2238 | **/ |
||
| 2239 | protected function normpathCE($path) { |
||
| 2242 | |||
| 2243 | /** |
||
| 2244 | * Return file path related to root dir (with convert encording) |
||
| 2245 | * |
||
| 2246 | * @param string $path file path |
||
| 2247 | * @return string |
||
| 2248 | * @author Naoki Sawada |
||
| 2249 | **/ |
||
| 2250 | protected function relpathCE($path) { |
||
| 2253 | |||
| 2254 | /** |
||
| 2255 | * Convert path related to root dir into real path (with convert encording) |
||
| 2256 | * |
||
| 2257 | * @param string $path rel file path |
||
| 2258 | * @return string |
||
| 2259 | * @author Naoki Sawada |
||
| 2260 | **/ |
||
| 2261 | protected function abspathCE($path) { |
||
| 2264 | |||
| 2265 | /** |
||
| 2266 | * Return true if $path is children of $parent (with convert encording) |
||
| 2267 | * |
||
| 2268 | * @param string $path path to check |
||
| 2269 | * @param string $parent parent path |
||
| 2270 | * @return bool |
||
| 2271 | * @author Naoki Sawada |
||
| 2272 | **/ |
||
| 2273 | protected function inpathCE($path, $parent) { |
||
| 2276 | |||
| 2277 | /** |
||
| 2278 | * Open file and return file pointer (with convert encording) |
||
| 2279 | * |
||
| 2280 | * @param string $path file path |
||
| 2281 | * @param bool $write open file for writing |
||
| 2282 | * @return resource|false |
||
| 2283 | * @author Naoki Sawada |
||
| 2284 | **/ |
||
| 2285 | protected function fopenCE($path, $mode='rb') { |
||
| 2288 | |||
| 2289 | /** |
||
| 2290 | * Close opened file (with convert encording) |
||
| 2291 | * |
||
| 2292 | * @param resource $fp file pointer |
||
| 2293 | * @param string $path file path |
||
| 2294 | * @return bool |
||
| 2295 | * @author Naoki Sawada |
||
| 2296 | **/ |
||
| 2297 | protected function fcloseCE($fp, $path='') { |
||
| 2300 | |||
| 2301 | /** |
||
| 2302 | * Create new file and write into it from file pointer. (with convert encording) |
||
| 2303 | * Return new file path or false on error. |
||
| 2304 | * |
||
| 2305 | * @param resource $fp file pointer |
||
| 2306 | * @param string $dir target dir path |
||
| 2307 | * @param string $name file name |
||
| 2308 | * @param array $stat file stat (required by some virtual fs) |
||
| 2309 | * @return bool|string |
||
| 2310 | * @author Naoki Sawada |
||
| 2311 | **/ |
||
| 2312 | protected function saveCE($fp, $dir, $name, $stat) { |
||
| 2315 | |||
| 2316 | /** |
||
| 2317 | * Return true if path is dir and has at least one childs directory (with convert encording) |
||
| 2318 | * |
||
| 2319 | * @param string $path dir path |
||
| 2320 | * @return bool |
||
| 2321 | * @author Naoki Sawada |
||
| 2322 | **/ |
||
| 2323 | protected function subdirsCE($path) { |
||
| 2329 | |||
| 2330 | /** |
||
| 2331 | * Return files list in directory (with convert encording) |
||
| 2332 | * |
||
| 2333 | * @param string $path dir path |
||
| 2334 | * @return array |
||
| 2335 | * @author Naoki Sawada |
||
| 2336 | **/ |
||
| 2337 | protected function scandirCE($path) { |
||
| 2340 | |||
| 2341 | /** |
||
| 2342 | * Create symlink (with convert encording) |
||
| 2343 | * |
||
| 2344 | * @param string $source file to link to |
||
| 2345 | * @param string $targetDir folder to create link in |
||
| 2346 | * @param string $name symlink name |
||
| 2347 | * @return bool |
||
| 2348 | * @author Naoki Sawada |
||
| 2349 | **/ |
||
| 2350 | protected function symlinkCE($source, $targetDir, $name) { |
||
| 2353 | |||
| 2354 | /***************** paths *******************/ |
||
| 2355 | |||
| 2356 | /** |
||
| 2357 | * Encode path into hash |
||
| 2358 | * |
||
| 2359 | * @param string file path |
||
| 2360 | * @return string |
||
| 2361 | * @author Dmitry (dio) Levashov |
||
| 2362 | * @author Troex Nevelin |
||
| 2363 | **/ |
||
| 2364 | protected function encode($path) { |
||
| 2385 | |||
| 2386 | /** |
||
| 2387 | * Decode path from hash |
||
| 2388 | * |
||
| 2389 | * @param string file hash |
||
| 2390 | * @return string |
||
| 2391 | * @author Dmitry (dio) Levashov |
||
| 2392 | * @author Troex Nevelin |
||
| 2393 | **/ |
||
| 2394 | protected function decode($hash) { |
||
| 2406 | |||
| 2407 | /** |
||
| 2408 | * Return crypted path |
||
| 2409 | * Not implemented |
||
| 2410 | * |
||
| 2411 | * @param string path |
||
| 2412 | * @return mixed |
||
| 2413 | * @author Dmitry (dio) Levashov |
||
| 2414 | **/ |
||
| 2415 | protected function crypt($path) { |
||
| 2418 | |||
| 2419 | /** |
||
| 2420 | * Return uncrypted path |
||
| 2421 | * Not implemented |
||
| 2422 | * |
||
| 2423 | * @param mixed hash |
||
| 2424 | * @return mixed |
||
| 2425 | * @author Dmitry (dio) Levashov |
||
| 2426 | **/ |
||
| 2427 | protected function uncrypt($hash) { |
||
| 2430 | |||
| 2431 | /** |
||
| 2432 | * Validate file name based on $this->options['acceptedName'] regexp or function |
||
| 2433 | * |
||
| 2434 | * @param string $name file name |
||
| 2435 | * @return bool |
||
| 2436 | * @author Dmitry (dio) Levashov |
||
| 2437 | **/ |
||
| 2438 | protected function nameAccepted($name) { |
||
| 2453 | |||
| 2454 | /** |
||
| 2455 | * Return new unique name based on file name and suffix |
||
| 2456 | * |
||
| 2457 | * @param string $path file path |
||
| 2458 | * @param string $suffix suffix append to name |
||
| 2459 | * @return string |
||
| 2460 | * @author Dmitry (dio) Levashov |
||
| 2461 | **/ |
||
| 2462 | public function uniqueName($dir, $name, $suffix = ' copy', $checkNum = true, $start = 1) { |
||
| 2490 | |||
| 2491 | /** |
||
| 2492 | * Converts character encoding from UTF-8 to server's one |
||
| 2493 | * |
||
| 2494 | * @param mixed $var target string or array var |
||
| 2495 | * @param bool $restoreLocale do retore global locale, default is false |
||
| 2496 | * @param string $unknown replaces character for unknown |
||
| 2497 | * @return mixed |
||
| 2498 | * @author Naoki Sawada |
||
| 2499 | */ |
||
| 2500 | public function convEncIn($var = null, $restoreLocale = false, $unknown = '_') { |
||
| 2503 | |||
| 2504 | /** |
||
| 2505 | * Converts character encoding from server's one to UTF-8 |
||
| 2506 | * |
||
| 2507 | * @param mixed $var target string or array var |
||
| 2508 | * @param bool $restoreLocale do retore global locale, default is true |
||
| 2509 | * @param string $unknown replaces character for unknown |
||
| 2510 | * @return mixed |
||
| 2511 | * @author Naoki Sawada |
||
| 2512 | */ |
||
| 2513 | public function convEncOut($var = null, $restoreLocale = true, $unknown = '_') { |
||
| 2516 | |||
| 2517 | /** |
||
| 2518 | * Converts character encoding (base function) |
||
| 2519 | * |
||
| 2520 | * @param mixed $var target string or array var |
||
| 2521 | * @param string $from from character encoding |
||
| 2522 | * @param string $to to character encoding |
||
| 2523 | * @param string $locale local locale |
||
| 2524 | * @param string $unknown replaces character for unknown |
||
| 2525 | * @return mixed |
||
| 2526 | */ |
||
| 2527 | protected function convEnc($var, $from, $to, $locale, $restoreLocale, $unknown = '_') { |
||
| 2556 | |||
| 2557 | /*********************** util mainly for inheritance class *********************/ |
||
| 2558 | |||
| 2559 | /** |
||
| 2560 | * Get temporary filename. Tempfile will be removed when after script execution finishes or exit() is called. |
||
| 2561 | * When needing the unique file to a path, give $path to parameter. |
||
| 2562 | * |
||
| 2563 | * @param string $path for get unique file to a path |
||
| 2564 | * @return string|false |
||
| 2565 | * @author Naoki Sawada |
||
| 2566 | */ |
||
| 2567 | protected function getTempFile($path = '') { |
||
| 2593 | |||
| 2594 | /** |
||
| 2595 | * File path of local server side work file path |
||
| 2596 | * |
||
| 2597 | * @param string $path path need convert encoding to server encoding |
||
| 2598 | * @return string |
||
| 2599 | * @author Naoki Sawada |
||
| 2600 | */ |
||
| 2601 | protected function getWorkFile($path) { |
||
| 2616 | |||
| 2617 | /** |
||
| 2618 | * Get image size array with `dimensions` |
||
| 2619 | * |
||
| 2620 | * @param string $path path need convert encoding to server encoding |
||
| 2621 | * @param string $mime file mime type |
||
| 2622 | * @return array|false |
||
| 2623 | */ |
||
| 2624 | public function getImageSize($path, $mime = '') { |
||
| 2636 | |||
| 2637 | /** |
||
| 2638 | * Delete dirctory trees |
||
| 2639 | * |
||
| 2640 | * @param string $localpath path need convert encoding to server encoding |
||
| 2641 | * @return boolean |
||
| 2642 | * @author Naoki Sawada |
||
| 2643 | */ |
||
| 2644 | protected function delTree($localpath) { |
||
| 2653 | |||
| 2654 | /*********************** file stat *********************/ |
||
| 2655 | |||
| 2656 | /** |
||
| 2657 | * Check file attribute |
||
| 2658 | * |
||
| 2659 | * @param string $path file path |
||
| 2660 | * @param string $name attribute name (read|write|locked|hidden) |
||
| 2661 | * @param bool $val attribute value returned by file system |
||
| 2662 | * @param bool $isDir path is directory (true: directory, false: file) |
||
| 2663 | * @return bool |
||
| 2664 | * @author Dmitry (dio) Levashov |
||
| 2665 | **/ |
||
| 2666 | protected function attr($path, $name, $val=null, $isDir=null) { |
||
| 2700 | |||
| 2701 | /** |
||
| 2702 | * Return true if file with given name can be created in given folder. |
||
| 2703 | * |
||
| 2704 | * @param string $dir parent dir path |
||
| 2705 | * @param string $name new file name |
||
| 2706 | * @return bool |
||
| 2707 | * @author Dmitry (dio) Levashov |
||
| 2708 | **/ |
||
| 2709 | protected function allowCreate($dir, $name, $isDir = null) { |
||
| 2732 | |||
| 2733 | /** |
||
| 2734 | * Return true if file MIME type can save with check uploadOrder config. |
||
| 2735 | * |
||
| 2736 | * @param string $mime |
||
| 2737 | * @return boolean |
||
| 2738 | */ |
||
| 2739 | protected function allowPutMime($mime) { |
||
| 2757 | |||
| 2758 | /** |
||
| 2759 | * Return fileinfo |
||
| 2760 | * |
||
| 2761 | * @param string $path file cache |
||
| 2762 | * @return array |
||
| 2763 | * @author Dmitry (dio) Levashov |
||
| 2764 | **/ |
||
| 2765 | protected function stat($path) { |
||
| 2792 | |||
| 2793 | /** |
||
| 2794 | * Put file stat in cache and return it |
||
| 2795 | * |
||
| 2796 | * @param string $path file path |
||
| 2797 | * @param array $stat file stat |
||
| 2798 | * @return array |
||
| 2799 | * @author Dmitry (dio) Levashov |
||
| 2800 | **/ |
||
| 2801 | protected function updateCache($path, $stat) { |
||
| 2944 | |||
| 2945 | /** |
||
| 2946 | * Get stat for folder content and put in cache |
||
| 2947 | * |
||
| 2948 | * @param string $path |
||
| 2949 | * @return void |
||
| 2950 | * @author Dmitry (dio) Levashov |
||
| 2951 | **/ |
||
| 2952 | protected function cacheDir($path) { |
||
| 2965 | |||
| 2966 | /** |
||
| 2967 | * Clean cache |
||
| 2968 | * |
||
| 2969 | * @return void |
||
| 2970 | * @author Dmitry (dio) Levashov |
||
| 2971 | **/ |
||
| 2972 | protected function clearcache() { |
||
| 2976 | |||
| 2977 | /** |
||
| 2978 | * Return file mimetype |
||
| 2979 | * |
||
| 2980 | * @param string $path file path |
||
| 2981 | * @return string |
||
| 2982 | * @author Dmitry (dio) Levashov |
||
| 2983 | **/ |
||
| 2984 | protected function mimetype($path, $name = '') { |
||
| 3029 | |||
| 3030 | /** |
||
| 3031 | * Detect file mimetype using "internal" method |
||
| 3032 | * |
||
| 3033 | * @param string $path file path |
||
| 3034 | * @return string |
||
| 3035 | * @author Dmitry (dio) Levashov |
||
| 3036 | **/ |
||
| 3037 | static protected function mimetypeInternalDetect($path) { |
||
| 3043 | |||
| 3044 | /** |
||
| 3045 | * Return file/total directory size |
||
| 3046 | * |
||
| 3047 | * @param string $path file path |
||
| 3048 | * @return int |
||
| 3049 | * @author Dmitry (dio) Levashov |
||
| 3050 | **/ |
||
| 3051 | protected function countSize($path) { |
||
| 3076 | |||
| 3077 | /** |
||
| 3078 | * Return true if all mimes is directory or files |
||
| 3079 | * |
||
| 3080 | * @param string $mime1 mimetype |
||
| 3081 | * @param string $mime2 mimetype |
||
| 3082 | * @return bool |
||
| 3083 | * @author Dmitry (dio) Levashov |
||
| 3084 | **/ |
||
| 3085 | protected function isSameType($mime1, $mime2) { |
||
| 3088 | |||
| 3089 | /** |
||
| 3090 | * If file has required attr == $val - return file path, |
||
| 3091 | * If dir has child with has required attr == $val - return child path |
||
| 3092 | * |
||
| 3093 | * @param string $path file path |
||
| 3094 | * @param string $attr attribute name |
||
| 3095 | * @param bool $val attribute value |
||
| 3096 | * @return string|false |
||
| 3097 | * @author Dmitry (dio) Levashov |
||
| 3098 | **/ |
||
| 3099 | protected function closestByAttr($path, $attr, $val) { |
||
| 3116 | |||
| 3117 | /** |
||
| 3118 | * Return first found children with required attr == $val |
||
| 3119 | * |
||
| 3120 | * @param string $path file path |
||
| 3121 | * @param string $attr attribute name |
||
| 3122 | * @param bool $val attribute value |
||
| 3123 | * @return string|false |
||
| 3124 | * @author Dmitry (dio) Levashov |
||
| 3125 | **/ |
||
| 3126 | protected function childsByAttr($path, $attr, $val) { |
||
| 3134 | |||
| 3135 | /***************** get content *******************/ |
||
| 3136 | |||
| 3137 | /** |
||
| 3138 | * Return required dir's files info. |
||
| 3139 | * If onlyMimes is set - return only dirs and files of required mimes |
||
| 3140 | * |
||
| 3141 | * @param string $path dir path |
||
| 3142 | * @return array |
||
| 3143 | * @author Dmitry (dio) Levashov |
||
| 3144 | **/ |
||
| 3145 | protected function getScandir($path) { |
||
| 3158 | |||
| 3159 | |||
| 3160 | /** |
||
| 3161 | * Return subdirs tree |
||
| 3162 | * |
||
| 3163 | * @param string $path parent dir path |
||
| 3164 | * @param int $deep tree deep |
||
| 3165 | * @return array |
||
| 3166 | * @author Dmitry (dio) Levashov |
||
| 3167 | **/ |
||
| 3168 | protected function gettree($path, $deep, $exclude='') { |
||
| 3186 | |||
| 3187 | /** |
||
| 3188 | * Recursive files search |
||
| 3189 | * |
||
| 3190 | * @param string $path dir path |
||
| 3191 | * @param string $q search string |
||
| 3192 | * @param array $mimes |
||
| 3193 | * @return array |
||
| 3194 | * @author Dmitry (dio) Levashov |
||
| 3195 | **/ |
||
| 3196 | protected function doSearch($path, $q, $mimes) { |
||
| 3232 | |||
| 3233 | /********************** manuipulations ******************/ |
||
| 3234 | |||
| 3235 | /** |
||
| 3236 | * Copy file/recursive copy dir only in current volume. |
||
| 3237 | * Return new file path or false. |
||
| 3238 | * |
||
| 3239 | * @param string $src source path |
||
| 3240 | * @param string $dst destination dir path |
||
| 3241 | * @param string $name new file name (optionaly) |
||
| 3242 | * @return string|false |
||
| 3243 | * @author Dmitry (dio) Levashov |
||
| 3244 | **/ |
||
| 3245 | protected function copy($src, $dst, $name) { |
||
| 3287 | |||
| 3288 | /** |
||
| 3289 | * Move file |
||
| 3290 | * Return new file path or false. |
||
| 3291 | * |
||
| 3292 | * @param string $src source path |
||
| 3293 | * @param string $dst destination dir path |
||
| 3294 | * @param string $name new file name |
||
| 3295 | * @return string|false |
||
| 3296 | * @author Dmitry (dio) Levashov |
||
| 3297 | **/ |
||
| 3298 | protected function move($src, $dst, $name) { |
||
| 3312 | |||
| 3313 | /** |
||
| 3314 | * Copy file from another volume. |
||
| 3315 | * Return new file path or false. |
||
| 3316 | * |
||
| 3317 | * @param Object $volume source volume |
||
| 3318 | * @param string $src source file hash |
||
| 3319 | * @param string $destination destination dir path |
||
| 3320 | * @param string $name file name |
||
| 3321 | * @return string|false |
||
| 3322 | * @author Dmitry (dio) Levashov |
||
| 3323 | **/ |
||
| 3324 | protected function copyFrom($volume, $src, $destination, $name) { |
||
| 3386 | |||
| 3387 | /** |
||
| 3388 | * Remove file/ recursive remove dir |
||
| 3389 | * |
||
| 3390 | * @param string $path file path |
||
| 3391 | * @param bool $force try to remove even if file locked |
||
| 3392 | * @return bool |
||
| 3393 | * @author Dmitry (dio) Levashov |
||
| 3394 | **/ |
||
| 3395 | protected function remove($path, $force = false) { |
||
| 3425 | |||
| 3426 | |||
| 3427 | /************************* thumbnails **************************/ |
||
| 3428 | |||
| 3429 | /** |
||
| 3430 | * Return thumbnail file name for required file |
||
| 3431 | * |
||
| 3432 | * @param array $stat file stat |
||
| 3433 | * @return string |
||
| 3434 | * @author Dmitry (dio) Levashov |
||
| 3435 | **/ |
||
| 3436 | protected function tmbname($stat) { |
||
| 3439 | |||
| 3440 | /** |
||
| 3441 | * Return thumnbnail name if exists |
||
| 3442 | * |
||
| 3443 | * @param string $path file path |
||
| 3444 | * @param array $stat file stat |
||
| 3445 | * @return string|false |
||
| 3446 | * @author Dmitry (dio) Levashov |
||
| 3447 | **/ |
||
| 3448 | protected function gettmb($path, $stat) { |
||
| 3462 | |||
| 3463 | /** |
||
| 3464 | * Return true if thumnbnail for required file can be created |
||
| 3465 | * |
||
| 3466 | * @param string $path thumnbnail path |
||
| 3467 | * @param array $stat file stat |
||
| 3468 | * @param bool $checkTmbPath |
||
| 3469 | * @return string|bool |
||
| 3470 | * @author Dmitry (dio) Levashov |
||
| 3471 | **/ |
||
| 3472 | protected function canCreateTmb($path, $stat, $checkTmbPath = true) { |
||
| 3479 | |||
| 3480 | /** |
||
| 3481 | * Return true if required file can be resized. |
||
| 3482 | * By default - the same as canCreateTmb |
||
| 3483 | * |
||
| 3484 | * @param string $path thumnbnail path |
||
| 3485 | * @param array $stat file stat |
||
| 3486 | * @return string|bool |
||
| 3487 | * @author Dmitry (dio) Levashov |
||
| 3488 | **/ |
||
| 3489 | protected function canResize($path, $stat) { |
||
| 3492 | |||
| 3493 | /** |
||
| 3494 | * Create thumnbnail and return it's URL on success |
||
| 3495 | * |
||
| 3496 | * @param string $path file path |
||
| 3497 | * @param string $mime file mime type |
||
| 3498 | * @return string|false |
||
| 3499 | * @author Dmitry (dio) Levashov |
||
| 3500 | **/ |
||
| 3501 | protected function createTmb($path, $stat) { |
||
| 3571 | |||
| 3572 | /** |
||
| 3573 | * Resize image |
||
| 3574 | * |
||
| 3575 | * @param string $path image file |
||
| 3576 | * @param int $width new width |
||
| 3577 | * @param int $height new height |
||
| 3578 | * @param bool $keepProportions crop image |
||
| 3579 | * @param bool $resizeByBiggerSide resize image based on bigger side if true |
||
| 3580 | * @param string $destformat image destination format |
||
| 3581 | * @return string|false |
||
| 3582 | * @author Dmitry (dio) Levashov |
||
| 3583 | * @author Alexey Sukhotin |
||
| 3584 | **/ |
||
| 3585 | protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null) { |
||
| 3678 | |||
| 3679 | /** |
||
| 3680 | * Crop image |
||
| 3681 | * |
||
| 3682 | * @param string $path image file |
||
| 3683 | * @param int $width crop width |
||
| 3684 | * @param int $height crop height |
||
| 3685 | * @param bool $x crop left offset |
||
| 3686 | * @param bool $y crop top offset |
||
| 3687 | * @param string $destformat image destination format |
||
| 3688 | * @return string|false |
||
| 3689 | * @author Dmitry (dio) Levashov |
||
| 3690 | * @author Alexey Sukhotin |
||
| 3691 | **/ |
||
| 3692 | protected function imgCrop($path, $width, $height, $x, $y, $destformat = null) { |
||
| 3766 | |||
| 3767 | /** |
||
| 3768 | * Put image to square |
||
| 3769 | * |
||
| 3770 | * @param string $path image file |
||
| 3771 | * @param int $width square width |
||
| 3772 | * @param int $height square height |
||
| 3773 | * @param int $align reserved |
||
| 3774 | * @param int $valign reserved |
||
| 3775 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3776 | * @param string $destformat image destination format |
||
| 3777 | * @return string|false |
||
| 3778 | * @author Dmitry (dio) Levashov |
||
| 3779 | * @author Alexey Sukhotin |
||
| 3780 | **/ |
||
| 3781 | protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null) { |
||
| 3859 | |||
| 3860 | /** |
||
| 3861 | * Rotate image |
||
| 3862 | * |
||
| 3863 | * @param string $path image file |
||
| 3864 | * @param int $degree rotete degrees |
||
| 3865 | * @param string $bgcolor square background color in #rrggbb format |
||
| 3866 | * @param string $destformat image destination format |
||
| 3867 | * @return string|false |
||
| 3868 | * @author nao-pon |
||
| 3869 | * @author Troex Nevelin |
||
| 3870 | **/ |
||
| 3871 | protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null) { |
||
| 3951 | |||
| 3952 | /** |
||
| 3953 | * Execute shell command |
||
| 3954 | * |
||
| 3955 | * @param string $command command line |
||
| 3956 | * @param array $output stdout strings |
||
| 3957 | * @param array $return_var process exit code |
||
| 3958 | * @param array $error_output stderr strings |
||
| 3959 | * @return int exit code |
||
| 3960 | * @author Alexey Sukhotin |
||
| 3961 | **/ |
||
| 3962 | protected function procExec($command , array &$output = null, &$return_var = -1, array &$error_output = null) { |
||
| 3992 | |||
| 3993 | /** |
||
| 3994 | * Remove thumbnail, also remove recursively if stat is directory |
||
| 3995 | * |
||
| 3996 | * @param string $stat file stat |
||
| 3997 | * @return void |
||
| 3998 | * @author Dmitry (dio) Levashov |
||
| 3999 | * @author Naoki Sawada |
||
| 4000 | * @author Troex Nevelin |
||
| 4001 | **/ |
||
| 4002 | protected function rmTmb($stat) { |
||
| 4015 | |||
| 4016 | /** |
||
| 4017 | * Create an gd image according to the specified mime type |
||
| 4018 | * |
||
| 4019 | * @param string $path image file |
||
| 4020 | * @param string $mime |
||
| 4021 | * @return gd image resource identifier |
||
| 4022 | */ |
||
| 4023 | protected function gdImageCreate($path,$mime){ |
||
| 4039 | |||
| 4040 | /** |
||
| 4041 | * Output gd image to file |
||
| 4042 | * |
||
| 4043 | * @param resource $image gd image resource |
||
| 4044 | * @param string $filename The path to save the file to. |
||
| 4045 | * @param string $destformat The Image type to use for $filename |
||
| 4046 | * @param string $mime The original image mime type |
||
| 4047 | */ |
||
| 4048 | protected function gdImage($image, $filename, $destformat, $mime ){ |
||
| 4060 | |||
| 4061 | /** |
||
| 4062 | * Assign the proper background to a gd image |
||
| 4063 | * |
||
| 4064 | * @param resource $image gd image resource |
||
| 4065 | * @param string $bgcolor background color in #rrggbb format |
||
| 4066 | */ |
||
| 4067 | protected function gdImageBackground($image, $bgcolor){ |
||
| 4080 | |||
| 4081 | /*********************** misc *************************/ |
||
| 4082 | |||
| 4083 | /** |
||
| 4084 | * Return smart formatted date |
||
| 4085 | * |
||
| 4086 | * @param int $ts file timestamp |
||
| 4087 | * @return string |
||
| 4088 | * @author Dmitry (dio) Levashov |
||
| 4089 | **/ |
||
| 4090 | // protected function formatDate($ts) { |
||
| 4091 | // if ($ts > $this->today) { |
||
| 4092 | // return 'Today '.date($this->options['timeFormat'], $ts); |
||
| 4093 | // } |
||
| 4094 | // |
||
| 4095 | // if ($ts > $this->yesterday) { |
||
| 4096 | // return 'Yesterday '.date($this->options['timeFormat'], $ts); |
||
| 4097 | // } |
||
| 4098 | // |
||
| 4099 | // return date($this->options['dateFormat'], $ts); |
||
| 4100 | // } |
||
| 4101 | |||
| 4102 | /** |
||
| 4103 | * Find position of first occurrence of string in a string with multibyte support |
||
| 4104 | * |
||
| 4105 | * @param string $haystack The string being checked. |
||
| 4106 | * @param string $needle The string to find in haystack. |
||
| 4107 | * @param int $offset The search offset. If it is not specified, 0 is used. |
||
| 4108 | * @return int|bool |
||
| 4109 | * @author Alexey Sukhotin |
||
| 4110 | **/ |
||
| 4111 | protected function stripos($haystack , $needle , $offset = 0) { |
||
| 4119 | |||
| 4120 | /** |
||
| 4121 | * Get server side available archivers |
||
| 4122 | * |
||
| 4123 | * @param bool $use_cache |
||
| 4124 | * @return array |
||
| 4125 | */ |
||
| 4126 | protected function getArchivers($use_cache = true) { |
||
| 4242 | |||
| 4243 | /** |
||
| 4244 | * Resolve relative / (Unix-like)absolute path |
||
| 4245 | * |
||
| 4246 | * @param string $path target path |
||
| 4247 | * @param string $base base path |
||
| 4248 | * @return string |
||
| 4249 | */ |
||
| 4250 | protected function getFullPath($path, $base) { |
||
| 4297 | |||
| 4298 | /** |
||
| 4299 | * Remove directory recursive on local file system |
||
| 4300 | * |
||
| 4301 | * @param string $dir Target dirctory path |
||
| 4302 | * @return boolean |
||
| 4303 | * @author Naoki Sawada |
||
| 4304 | */ |
||
| 4305 | public function rmdirRecursive($dir) { |
||
| 4325 | |||
| 4326 | /** |
||
| 4327 | * Create archive and return its path |
||
| 4328 | * |
||
| 4329 | * @param string $dir target dir |
||
| 4330 | * @param array $files files names list |
||
| 4331 | * @param string $name archive name |
||
| 4332 | * @param array $arc archiver options |
||
| 4333 | * @return string|bool |
||
| 4334 | * @author Dmitry (dio) Levashov, |
||
| 4335 | * @author Alexey Sukhotin |
||
| 4336 | * @author Naoki Sawada |
||
| 4337 | **/ |
||
| 4338 | protected function makeArchive($dir, $files, $name, $arc) { |
||
| 4356 | |||
| 4357 | /** |
||
| 4358 | * Unpack archive |
||
| 4359 | * |
||
| 4360 | * @param string $path archive path |
||
| 4361 | * @param array $arc archiver command and arguments (same as in $this->archivers) |
||
| 4362 | * @param bool $remove remove archive ( unlink($path) ) |
||
| 4363 | * @return void |
||
| 4364 | * @author Dmitry (dio) Levashov |
||
| 4365 | * @author Alexey Sukhotin |
||
| 4366 | * @author Naoki Sawada |
||
| 4367 | **/ |
||
| 4368 | protected function unpackArchive($path, $arc, $remove = true) { |
||
| 4383 | |||
| 4384 | /** |
||
| 4385 | * Create Zip archive using PHP class ZipArchive |
||
| 4386 | * |
||
| 4387 | * @param string $dir target dir |
||
| 4388 | * @param array $files files names list |
||
| 4389 | * @param string|object $zipPath Zip archive name |
||
| 4390 | * @return void |
||
| 4391 | * @author Naoki Sawada |
||
| 4392 | */ |
||
| 4393 | protected static function zipArchiveZip($dir, $files, $zipPath) { |
||
| 4431 | |||
| 4432 | /** |
||
| 4433 | * Unpack Zip archive using PHP class ZipArchive |
||
| 4434 | * |
||
| 4435 | * @param string $zipPath Zip archive name |
||
| 4436 | * @param string $toDir Extract to path |
||
| 4437 | * @return bool |
||
| 4438 | * @author Naoki Sawada |
||
| 4439 | */ |
||
| 4440 | protected static function zipArchiveUnzip($zipPath, $toDir) { |
||
| 4452 | |||
| 4453 | /**==================================* abstract methods *====================================**/ |
||
| 4454 | |||
| 4455 | /*********************** paths/urls *************************/ |
||
| 4456 | |||
| 4457 | /** |
||
| 4458 | * Return parent directory path |
||
| 4459 | * |
||
| 4460 | * @param string $path file path |
||
| 4461 | * @return string |
||
| 4462 | * @author Dmitry (dio) Levashov |
||
| 4463 | **/ |
||
| 4464 | abstract protected function _dirname($path); |
||
| 4465 | |||
| 4466 | /** |
||
| 4467 | * Return file name |
||
| 4468 | * |
||
| 4469 | * @param string $path file path |
||
| 4470 | * @return string |
||
| 4471 | * @author Dmitry (dio) Levashov |
||
| 4472 | **/ |
||
| 4473 | abstract protected function _basename($path); |
||
| 4474 | |||
| 4475 | /** |
||
| 4476 | * Join dir name and file name and return full path. |
||
| 4477 | * Some drivers (db) use int as path - so we give to concat path to driver itself |
||
| 4478 | * |
||
| 4479 | * @param string $dir dir path |
||
| 4480 | * @param string $name file name |
||
| 4481 | * @return string |
||
| 4482 | * @author Dmitry (dio) Levashov |
||
| 4483 | **/ |
||
| 4484 | abstract protected function _joinPath($dir, $name); |
||
| 4485 | |||
| 4486 | /** |
||
| 4487 | * Return normalized path |
||
| 4488 | * |
||
| 4489 | * @param string $path file path |
||
| 4490 | * @return string |
||
| 4491 | * @author Dmitry (dio) Levashov |
||
| 4492 | **/ |
||
| 4493 | abstract protected function _normpath($path); |
||
| 4494 | |||
| 4495 | /** |
||
| 4496 | * Return file path related to root dir |
||
| 4497 | * |
||
| 4498 | * @param string $path file path |
||
| 4499 | * @return string |
||
| 4500 | * @author Dmitry (dio) Levashov |
||
| 4501 | **/ |
||
| 4502 | abstract protected function _relpath($path); |
||
| 4503 | |||
| 4504 | /** |
||
| 4505 | * Convert path related to root dir into real path |
||
| 4506 | * |
||
| 4507 | * @param string $path rel file path |
||
| 4508 | * @return string |
||
| 4509 | * @author Dmitry (dio) Levashov |
||
| 4510 | **/ |
||
| 4511 | abstract protected function _abspath($path); |
||
| 4512 | |||
| 4513 | /** |
||
| 4514 | * Return fake path started from root dir. |
||
| 4515 | * Required to show path on client side. |
||
| 4516 | * |
||
| 4517 | * @param string $path file path |
||
| 4518 | * @return string |
||
| 4519 | * @author Dmitry (dio) Levashov |
||
| 4520 | **/ |
||
| 4521 | abstract protected function _path($path); |
||
| 4522 | |||
| 4523 | /** |
||
| 4524 | * Return true if $path is children of $parent |
||
| 4525 | * |
||
| 4526 | * @param string $path path to check |
||
| 4527 | * @param string $parent parent path |
||
| 4528 | * @return bool |
||
| 4529 | * @author Dmitry (dio) Levashov |
||
| 4530 | **/ |
||
| 4531 | abstract protected function _inpath($path, $parent); |
||
| 4532 | |||
| 4533 | /** |
||
| 4534 | * Return stat for given path. |
||
| 4535 | * Stat contains following fields: |
||
| 4536 | * - (int) size file size in b. required |
||
| 4537 | * - (int) ts file modification time in unix time. required |
||
| 4538 | * - (string) mime mimetype. required for folders, others - optionally |
||
| 4539 | * - (bool) read read permissions. required |
||
| 4540 | * - (bool) write write permissions. required |
||
| 4541 | * - (bool) locked is object locked. optionally |
||
| 4542 | * - (bool) hidden is object hidden. optionally |
||
| 4543 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
| 4544 | * - (string) target for symlinks - link target path. optionally |
||
| 4545 | * |
||
| 4546 | * If file does not exists - returns empty array or false. |
||
| 4547 | * |
||
| 4548 | * @param string $path file path |
||
| 4549 | * @return array|false |
||
| 4550 | * @author Dmitry (dio) Levashov |
||
| 4551 | **/ |
||
| 4552 | abstract protected function _stat($path); |
||
| 4553 | |||
| 4554 | |||
| 4555 | /***************** file stat ********************/ |
||
| 4556 | |||
| 4557 | |||
| 4558 | /** |
||
| 4559 | * Return true if path is dir and has at least one childs directory |
||
| 4560 | * |
||
| 4561 | * @param string $path dir path |
||
| 4562 | * @return bool |
||
| 4563 | * @author Dmitry (dio) Levashov |
||
| 4564 | **/ |
||
| 4565 | abstract protected function _subdirs($path); |
||
| 4566 | |||
| 4567 | /** |
||
| 4568 | * Return object width and height |
||
| 4569 | * Ususaly used for images, but can be realize for video etc... |
||
| 4570 | * |
||
| 4571 | * @param string $path file path |
||
| 4572 | * @param string $mime file mime type |
||
| 4573 | * @return string |
||
| 4574 | * @author Dmitry (dio) Levashov |
||
| 4575 | **/ |
||
| 4576 | abstract protected function _dimensions($path, $mime); |
||
| 4577 | |||
| 4578 | /******************** file/dir content *********************/ |
||
| 4579 | |||
| 4580 | /** |
||
| 4581 | * Return files list in directory |
||
| 4582 | * |
||
| 4583 | * @param string $path dir path |
||
| 4584 | * @return array |
||
| 4585 | * @author Dmitry (dio) Levashov |
||
| 4586 | **/ |
||
| 4587 | abstract protected function _scandir($path); |
||
| 4588 | |||
| 4589 | /** |
||
| 4590 | * Open file and return file pointer |
||
| 4591 | * |
||
| 4592 | * @param string $path file path |
||
| 4593 | * @param bool $write open file for writing |
||
| 4594 | * @return resource|false |
||
| 4595 | * @author Dmitry (dio) Levashov |
||
| 4596 | **/ |
||
| 4597 | abstract protected function _fopen($path, $mode="rb"); |
||
| 4598 | |||
| 4599 | /** |
||
| 4600 | * Close opened file |
||
| 4601 | * |
||
| 4602 | * @param resource $fp file pointer |
||
| 4603 | * @param string $path file path |
||
| 4604 | * @return bool |
||
| 4605 | * @author Dmitry (dio) Levashov |
||
| 4606 | **/ |
||
| 4607 | abstract protected function _fclose($fp, $path=''); |
||
| 4608 | |||
| 4609 | /******************** file/dir manipulations *************************/ |
||
| 4610 | |||
| 4611 | /** |
||
| 4612 | * Create dir and return created dir path or false on failed |
||
| 4613 | * |
||
| 4614 | * @param string $path parent dir path |
||
| 4615 | * @param string $name new directory name |
||
| 4616 | * @return string|bool |
||
| 4617 | * @author Dmitry (dio) Levashov |
||
| 4618 | **/ |
||
| 4619 | abstract protected function _mkdir($path, $name); |
||
| 4620 | |||
| 4621 | /** |
||
| 4622 | * Create file and return it's path or false on failed |
||
| 4623 | * |
||
| 4624 | * @param string $path parent dir path |
||
| 4625 | * @param string $name new file name |
||
| 4626 | * @return string|bool |
||
| 4627 | * @author Dmitry (dio) Levashov |
||
| 4628 | **/ |
||
| 4629 | abstract protected function _mkfile($path, $name); |
||
| 4630 | |||
| 4631 | /** |
||
| 4632 | * Create symlink |
||
| 4633 | * |
||
| 4634 | * @param string $source file to link to |
||
| 4635 | * @param string $targetDir folder to create link in |
||
| 4636 | * @param string $name symlink name |
||
| 4637 | * @return bool |
||
| 4638 | * @author Dmitry (dio) Levashov |
||
| 4639 | **/ |
||
| 4640 | abstract protected function _symlink($source, $targetDir, $name); |
||
| 4641 | |||
| 4642 | /** |
||
| 4643 | * Copy file into another file (only inside one volume) |
||
| 4644 | * |
||
| 4645 | * @param string $source source file path |
||
| 4646 | * @param string $target target dir path |
||
| 4647 | * @param string $name file name |
||
| 4648 | * @return bool |
||
| 4649 | * @author Dmitry (dio) Levashov |
||
| 4650 | **/ |
||
| 4651 | abstract protected function _copy($source, $targetDir, $name); |
||
| 4652 | |||
| 4653 | /** |
||
| 4654 | * Move file into another parent dir. |
||
| 4655 | * Return new file path or false. |
||
| 4656 | * |
||
| 4657 | * @param string $source source file path |
||
| 4658 | * @param string $target target dir path |
||
| 4659 | * @param string $name file name |
||
| 4660 | * @return string|bool |
||
| 4661 | * @author Dmitry (dio) Levashov |
||
| 4662 | **/ |
||
| 4663 | abstract protected function _move($source, $targetDir, $name); |
||
| 4664 | |||
| 4665 | /** |
||
| 4666 | * Remove file |
||
| 4667 | * |
||
| 4668 | * @param string $path file path |
||
| 4669 | * @return bool |
||
| 4670 | * @author Dmitry (dio) Levashov |
||
| 4671 | **/ |
||
| 4672 | abstract protected function _unlink($path); |
||
| 4673 | |||
| 4674 | /** |
||
| 4675 | * Remove dir |
||
| 4676 | * |
||
| 4677 | * @param string $path dir path |
||
| 4678 | * @return bool |
||
| 4679 | * @author Dmitry (dio) Levashov |
||
| 4680 | **/ |
||
| 4681 | abstract protected function _rmdir($path); |
||
| 4682 | |||
| 4683 | /** |
||
| 4684 | * Create new file and write into it from file pointer. |
||
| 4685 | * Return new file path or false on error. |
||
| 4686 | * |
||
| 4687 | * @param resource $fp file pointer |
||
| 4688 | * @param string $dir target dir path |
||
| 4689 | * @param string $name file name |
||
| 4690 | * @param array $stat file stat (required by some virtual fs) |
||
| 4691 | * @return bool|string |
||
| 4692 | * @author Dmitry (dio) Levashov |
||
| 4693 | **/ |
||
| 4694 | abstract protected function _save($fp, $dir, $name, $stat); |
||
| 4695 | |||
| 4696 | /** |
||
| 4697 | * Get file contents |
||
| 4698 | * |
||
| 4699 | * @param string $path file path |
||
| 4700 | * @return string|false |
||
| 4701 | * @author Dmitry (dio) Levashov |
||
| 4702 | **/ |
||
| 4703 | abstract protected function _getContents($path); |
||
| 4704 | |||
| 4705 | /** |
||
| 4706 | * Write a string to a file |
||
| 4707 | * |
||
| 4708 | * @param string $path file path |
||
| 4709 | * @param string $content new file content |
||
| 4710 | * @return bool |
||
| 4711 | * @author Dmitry (dio) Levashov |
||
| 4712 | **/ |
||
| 4713 | abstract protected function _filePutContents($path, $content); |
||
| 4714 | |||
| 4715 | /** |
||
| 4716 | * Extract files from archive |
||
| 4717 | * |
||
| 4718 | * @param string $path file path |
||
| 4719 | * @param array $arc archiver options |
||
| 4720 | * @return bool |
||
| 4721 | * @author Dmitry (dio) Levashov, |
||
| 4722 | * @author Alexey Sukhotin |
||
| 4723 | **/ |
||
| 4724 | abstract protected function _extract($path, $arc); |
||
| 4725 | |||
| 4726 | /** |
||
| 4727 | * Create archive and return its path |
||
| 4728 | * |
||
| 4729 | * @param string $dir target dir |
||
| 4730 | * @param array $files files names list |
||
| 4731 | * @param string $name archive name |
||
| 4732 | * @param array $arc archiver options |
||
| 4733 | * @return string|bool |
||
| 4734 | * @author Dmitry (dio) Levashov, |
||
| 4735 | * @author Alexey Sukhotin |
||
| 4736 | **/ |
||
| 4737 | abstract protected function _archive($dir, $files, $name, $arc); |
||
| 4738 | |||
| 4739 | /** |
||
| 4740 | * Detect available archivers |
||
| 4741 | * |
||
| 4742 | * @return void |
||
| 4743 | * @author Dmitry (dio) Levashov, |
||
| 4744 | * @author Alexey Sukhotin |
||
| 4745 | **/ |
||
| 4746 | abstract protected function _checkArchivers(); |
||
| 4747 | |||
| 4748 | /** |
||
| 4749 | * Change file mode (chmod) |
||
| 4750 | * |
||
| 4751 | * @param string $path file path |
||
| 4752 | * @param string $mode octal string such as '0755' |
||
| 4753 | * @return bool |
||
| 4754 | * @author David Bartle, |
||
| 4755 | **/ |
||
| 4756 | abstract protected function _chmod($path, $mode); |
||
| 4757 | |||
| 4758 | |||
| 4759 | } // END class |
||
| 4760 |
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.